- s and such.
if (!$phpns['script_link']) {
$url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']);
$url = 'http://'.$_SERVER['SERVER_NAME'].$phpns['sef_slash'].$phpns['sef_override'];
if (strstr($_SERVER['PHP_SELF'], 'etc.php')) {
$url = $url.'/article.php?do=edit&id='.$item['id'].'';
$rss_link = $url;
} else {
if ($phpns['sef_override']) {
$rss_link = $url.''.$item['article_sef_title'].'';
} else {
$rss_link = $url.'?a='.$item['id'].'';
}
}
} else {
$rss_link = $phpns['script_link'].'?'.$item['id'].'';
}
$item['timestamp'] = date(DATE_RSS, $item['timestamp']);
$template = '
-
'.$item['article_title'].'
'.$item['article_author'].'
'.$item['article_cat'].'
'.$item['timestamp'].'
'.$rss_link.'
'.$item['article_text'].'
';
return $template; //return template
} elseif ($type == "atom") {
if (!$phpns['script_link']) {
$url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']);
$url = 'http://'.$_SERVER['SERVER_NAME'].$phpns['sef_slash'].$phpns['sef_override'];
if (strstr($_SERVER['PHP_SELF'], 'etc.php')) {
$url = $url.'/article.php?do=edit&id='.$item['id'].'';
$rss_link = $url;
} else {
if ($phpns['sef_override']) {
$rss_link = $url.''.$item['article_sef_title'].'';
} else {
$rss_link = $url.'?a='.$item['id'].'';
}
}
} else {
$rss_link = $phpns['script_link'].'?'.$item['id'].'';
}
$item['timestamp'] = date(DATE_ATOM, $item['timestamp']);
$template = '
'.$item['article_title'].'
'.$item['article_author'].'
'.$item['timestamp'].'
'.$item['id'].'
'.$item['timestamp'].'
'.$item['article_text'].'
';
return $template;
}
}
}
//check to see if the system is online. If yes, we continue, if no, well... no. ;)
$phpns['siteonline'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='line'",1,FALSE);
if ($phpns['siteonline']['v1'] == 'no') {
die('The administrator has disabled the news system.
');
}
$phpns['banned'] = db_fetch("SELECT ip, reason FROM ".$databaseinfo['prefix']."banlist",0);
while ($phpns['ip'] = mysql_fetch_assoc($phpns['banned'])) {
if ($phpns['ip']['ip'] == $_SERVER['REMOTE_ADDR']) {
die("You have been banned from viewing this article system.
Reason: ".$phpns['ip']['reason']."
");
}
}
//timestamp format fetch
$phpns['timestamp_format'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='timestamp_format'",1,FALSE);
//fetch template. :)
$phpns['template'] = fetch_template();
//before anything else, we're going to detect if there is post data, and if there is, we'll insert the db. If there is no post data, just pass over this.
if ($_POST && $phpns['static'] != TRUE) {
//IF THERE IS POST DATA, then we're submitting the form. We need to clean data.
$phpns['comment'] = clean_data($_POST);
//set the continue to yes.
$phpns['comment_continue'] = TRUE;
//validate data (regex for email)
if (!$phpns['comment']['name'] || !$phpns['comment']['email'] || !$phpns['comment']['comment'] || !preg_match("/^[A-Za-z0-9_-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)$/", $phpns['comment']['email'])) {
$phpns['comment_error'] = 'You need to enter all required fields, and a valid email. Press back to try again.';
$phpns['comment_continue'] = FALSE;
}
if (!$phpns['def_comlimit']) { $phpns['def_comlimit'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_comlimit'",1); $phpns['def_comlimit'] = $phpns['def_comlimit']['v3']; }
if (strlen($phpns['comment']['comment']) >= $phpns['def_comlimit']) {
$phpns['comment_continue'] = FALSE;
$phpns['comment_error'] .= 'Your comment exceeded the character limit ('.$phpns['def_comlimit'].').';
}
if ($phpns['comment']['captcha'] != base64_decode($phpns['comment']['captcha_answer'])-(60-20) || !$phpns['comment']['captcha']) {
$phpns['comment_continue'] = FALSE;
$phpns['comment_error'] .= ' The captcha answer was incorrect. Press "back" on your browser to try again.';
}
if ($phpns['sef_override'] == TRUE) {
$phpns['sef']['title_id'] = str_replace('-', ' ', $phpns['comment']['id']);
$article_id = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."articles WHERE article_title='".$phpns['sef']['title_id']."'",1);
$article_id = $article_id['id'];
} else {
$article_id = $phpns['comment']['id'];
}
//if comment_id is not numeric, kill with message
if (!is_numeric($phpns['comment']['id']) && $phpns['sef_override'] == FALSE) { die("non-numeric form id, invalid information."); }
if ($phpns['comment_continue'] == TRUE) {
$phpns['ip'] = $_SERVER['REMOTE_ADDR'];
$insert = db_insert('INSERT INTO '.$databaseinfo['prefix'].'comments (article_id,comment_text,comment_author,website,timestamp,approved,ip) VALUES ("'.$article_id.'","'.$phpns['comment']['comment'].'","'.$phpns['comment']['name'].'","'.$phpns['comment']['website'].'","'.$phpns['time'].'","1","'.$phpns['ip'].'")');
} else {
$phpns['content'] .= ''.$phpns['comment_error'].'
';
}
}
/*
ACTUAL CONTENT GENERATION.
If there is no $phpns['do'], we're not using RSS or ATOM, and there is no specific $phpns['id'], we display the list.
*/
if (((!$phpns['do'] || $phpns['do'] == 'rss') && (!$phpns['id'] || $phpns['id'] == 'do=rss')) || $phpns['static'] == TRUE) { //if no defined action, show news as it is meant to be displayed.
//gather some important variables from db.
if ($phpns['category']) { $phpns['category'] = 'WHERE article_cat IN ('.$phpns['category'].',\'all\') &&'; } else { $phpns['category'] = "WHERE"; }
if (!$phpns['offset']) { $phpns['offset'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_offset'",1); $phpns['offset'] = $phpns['offset']['v1']; } $phpns['original_offset'] = $phpns['offset']; //to be used later...
if (!$phpns['limit']) { $phpns['limit'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_limit'",1); $phpns['limit'] = $phpns['limit']['v1']; }
if (!$phpns['order']) { $phpns['order'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_order'",1); $phpns['order'] = $phpns['order']['v1']; }
if (!$phpns['items_per_page']) { $phpns['items_per_page'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_items_per_page'",1); $phpns['items_per_page'] = $phpns['items_per_page']['v1']; }
/* Pagination management:
phpns works by using QUERY_STRING like this: filename.php?page:1
So, if no page is defined, we're going to default to 1. */
if (strstr($_GET['a'], "page:") && $phpns['static'] != TRUE) {
//get the current page from the URI.
$phpns['current_page'] = str_replace('page:','', $_GET['a']);
}
//if the string is empty, we assume page 1.
if (!is_numeric($phpns['current_page']) && !$phpns['current_page']) {
$phpns['current_page'] = 1;
}
//added this to balance problems in dealing with larger items_per_page than the limit itself. Works so far. =)
if ($phpns['items_per_page'] > $phpns['limit']) {
$phpns['items_per_page'] = $phpns['limit'];
}
if ($phpns['current_page'] == 1) {
//determine offset
$phpns['offset'] = ($phpns['current_page'] * $phpns['items_per_page'] - ($phpns['items_per_page'])) + $phpns['offset'];
} else {
$phpns['offset'] = ($phpns['current_page'] * $phpns['items_per_page'] - ($phpns['items_per_page']));
}
//MODE MODIFICATION
if ($phpns['mode'] == "rss" || $phpns['mode'] == "atom") {
//rss online?
$phpns['enabled'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_rssenabled'",1);
$phpns['enabled'] = $phpns['enabled']['v1'];
if ($phpns['enabled'] == FALSE) {
die("RSS is not enabled.");
}
//fetch rss limit
$phpns['limit'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_rsslimit'",1);
$phpns['limit'] = $phpns['limit']['v3'];
//fetch rss order
$phpns['order'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_rssorder'",1);
$phpns['order'] = $phpns['order']['v1'];
$phpns['items_per_page'] = $phpns['limit'];
}
if ($phpns['mode'] == NULL) {
//form count query, then figure out the total amount of rows in the news generation (including all pages)
$phpns['fetch_news_count'] = db_fetch("
SELECT * FROM ".$databaseinfo['prefix']."articles
".$phpns['category']."
active='1' AND approved='1'
LIMIT ".$phpns['original_offset'].",".$phpns['limit']."
", 0);
$phpns['total_news_count'] = mysql_num_rows($phpns['fetch_news_count']);
}
//forming actual news query.
$phpns['fetch_news'] = db_fetch("
SELECT * FROM ".$databaseinfo['prefix']."articles
".$phpns['category']."
active='1' AND approved='1'
ORDER BY timestamp ".$phpns['order']."
LIMIT ".$phpns['offset'].",".$phpns['items_per_page']."
", 0);
//pagination determinaion continuation =)
while ($phpns['row'] = mysql_fetch_assoc($phpns['fetch_news'])) { //start fetch loop
//if start time is greater than current time, and end time is less than current time, show.
if (($phpns['row']['start_date'] <= $phpns['time'] || $phpns['row']['start_date'] == NULL) && ($phpns['row']['end_date'] >= $phpns['time'] || $phpns['row']['end_date'] == NULL)) {
//put into $phpns['items'] if rss mode, else just $phpns['content']
if ($phpns['mode'] == 'rss' || $phpns['mode'] == 'atom') {
$phpns['returned_data'] = translate_item($phpns['row'], $phpns['template']['html_article'], ''.$phpns['mode'].''); //translate into template
$phpns['items'] .= $phpns['returned_data'];
} else {
$phpns['returned_data'] = translate_item($phpns['row'], $phpns['template']['html_article'], 'html_article'); //translate into template
$phpns['content'] .= $phpns['returned_data'];////////////////////
}
}
}
if (!$phpns['mode'] && $phpns['disable_pagination'] != TRUE) {
//find the total number of pages
$phpns['pages']['page_num'] = ceil($phpns['total_news_count'] / $phpns['items_per_page']);
//generate previous page link
if ($phpns['current_page'] > 1) {
$phpns['page']['previous'] = $phpns['current_page'] - 1;
}
//generate next page link
if ($phpns['current_page'] < $phpns['pages']['page_num']) {
$phpns['page']['next'] = $phpns['current_page'] + 1;
}
//generate middle pages
for($phpns['i'] = 1; $phpns['i'] <= $phpns['pages']['page_num']; $phpns['i']++){
if ($phpns['i'] == $phpns['current_page']) {
$phpns['page']['middle'] = $phpns['page']['middle'] . "\n".' ';
} else {
$phpns['page']['middle'] = $phpns['page']['middle'] . "\n".' ';
}
}
//add pagination links to content
$phpns['content'] .= translate_item($phpns['page'], $phpns['template']['html_pagination'], 'html_pagination');
}
} elseif ($phpns['id'] && !$phpns['mode'] && $phpns['static'] != TRUE) { //if we're dealing with singles, and the admin wants single articles to be displayed....
if (!$phpns['comment_override']) { $phpns['allow_com'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_comenabled'",1); } else { $phpns['allow_com'] = TRUE; }
//if SEF URLs are enabled, we need to change a few things, and make it search for titles instead of id
if ($phpns['sef_override'] == TRUE) {
$phpns['sef']['title_id'] = str_replace('-', ' ', $phpns['id']);
$phpns['where_spec'] = "article_title='".$phpns['sef']['title_id']."'";
} else {
$phpns['where_spec'] = "id='".$phpns['id']."'";
}
//forming actual news query.
$phpns['fetch_news'] = db_fetch("
SELECT * FROM ".$databaseinfo['prefix']."articles
WHERE
active='1' AND approved='1' AND ".$phpns['where_spec']." LIMIT 1
", 0);
//we're checking how many results were retrieved. If none, we set an error message and display it.
if (mysql_num_rows($phpns['fetch_news']) == 0) {
//set the error message, and display it.
$phpns['error_message'] = 'The article/page requested ('.$phpns['id'].' | '.$phpns['sef']['title_id'].') does not exist.
';
$phpns['content'] .= $phpns['error_message'];
} else { //if there IS an article, we proceed. =)
while ($phpns['row'] = mysql_fetch_assoc($phpns['fetch_news'])) { //start fetch loop
if ($phpns['time'] >= $phpns['row']['start_date'] || $phpns['time'] <= $phpns['row']['end_date'] || $phpns['row']['start_date'] == NULL || $phpns['row']['end_date'] == NULL) { //if we're set for time landings
$phpns['allow_com']['article_specific'] = $phpns['row']['allow_comments'];
$phpns['returned_data'] = translate_item($phpns['row'], $phpns['template']['html_article'], 'html_article'); //translate into template
$phpns['content'] .= $phpns['returned_data'];
//if rss, we have to write it to $phpns['items']
}
}
//echo var_dump($phpns['allow_com']); //debug
//now, we generate comments for this specific article IF they are enabled
if ($phpns['allow_com']['v1'] == TRUE) {
//get order preference from db
$phpns['def_comorder'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_comorder'",1);
if ($phpns['sef_override'] == TRUE) {
$phpns['sef']['title_id'] = str_replace('-', ' ', $phpns['id']);
$phpns['sef_article_id'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."articles WHERE article_title='".$phpns['sef']['title_id']."'",1);
$phpns['fetch_com_res'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."comments WHERE article_id='".$article_id['id']."' AND approved='1' ORDER BY id ".$phpns['def_comorder']['v1']."", 0);
} else {
$phpns['fetch_com_res'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."comments WHERE article_id='".$phpns['id']."' AND approved='1' ORDER BY id ".$phpns['def_comorder']['v1']."", 0);
}
//define refer_id as 0
$phpns['row']['refer_id'] = 0;
//for each row (or comment) generated, we translate the item and assign it to $phpns['content']
while ($phpns['row'] = mysql_fetch_assoc($phpns['fetch_com_res'])) {
$phpns['row']['refer_id'] = $phpns['row']['refer_id'] + 1;
$phpns['comment_list'] .= translate_item($phpns['row'], $phpns['template']['html_comment'], 'html_comment');
}
}
//assign $phpns['comment_list'] to $phpns['content']
$phpns['content'] .= $phpns['comment_list'];
//translate html comment form, then add it to the end of $phpns['content'], if comments are enabled
if (($phpns['allow_com']['v1'] == TRUE && $phpns['allow_com']['article_specific'] == 1 && $phpns['static'] != TRUE) || $phpns['comment_override'] == TRUE && $phpns['static'] != TRUE) {
$phpns['form_template'] = translate_item('', $phpns['template']['html_form'], 'html_form');
} else {
$phpns['form_template'] = '';
}
//add it to $phpns['content'] ($phpns['form_template'] will be empty if comments are not enabled)
$phpns['content'] .= '
'.$phpns['form_template'];
} //end of the ELSEIF of mysql_num_rows (there were results...)
} //end main if
//if we have a mode enabled (rss or atom....) then lets fetch some global data
if ($phpns['mode']) {
$rss['title'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_rsstitle'",1);
$rss['desc'] = db_fetch("SELECT * FROM ".$databaseinfo['prefix']."gconfig WHERE name='def_rssdesc'",1);
}
if ($phpns['mode'] == 'rss') { //we generate the header information
header('Content-Type: text/xml; charset=utf-8');
$phpns['content'] .= '
'.$rss['title']['v3'].'
http://'.$_SERVER['SERVER_NAME'].'
'.$rss['desc']['v3'].'
'.$phpns['items'].'
';
} elseif ($phpns['mode'] == "atom") {
header('Content-Type: text/xml; charset=utf-8');
$phpns['content'] .= '
'.$_SERVER['SERVER_NAME'].'
'.date(DATE_ATOM).'
'.$phpns['items'].'
';
}
//if viewing shownews.php directly
if (strstr($_SERVER['PHP_SELF'], "shownews.php")) {
echo "You are viewing the shownews.php file directly! You probably want to include this file, instead of just directly linking to it. For a HOWTO, see the help/manual file.
";
}
echo $phpns['content']; //and... finally post the content
//if no $phpns['content'], something was wrong. Just display a friendly message....
if (!$phpns['content']) {
echo "Blank.
For some reason, there was no output in the shownews.php file. Either (a) no articles are active, or (b) the template that is being used is empty.
";
}
} //end everything (this is the end to the freeze file if)
//unset the $phpns variable, swiping all data.
unset($phpns);
?>