//****GET PAGE NUMBER********************************************************************
if(isset($_GET['pg'])){$page = $_GET['pg'];}else{$page=1;} //finds the page number from the URL
$ePage = $page * $perPage; //tells the last posting on the page. (eg. 7 per page, page 2 the last posting is number 14)
$bPage = $ePage - $perPage; //counts back to the first listing on each page
//store the prev and next page numbers for use in the pagination nav later
$pPage = $page -1; // previous page
$nPage = $page +1; // next page
//****************************************************************************************
//****GET COUNT OF ENTRIES****************************************************************
// Query the database.
$query = "SELECT uid FROM $TABLENAME";
$result = mysql_query ($query);
$totally = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$totally += 1; //loop runs to count the total number of posts. This sets the page forward and back links. It knows the last page and first page.
}
//****************************************************************************************
//****GET ENTRIES FROM DATABASE***********************************************************
//function for securing GET data
function cleanEntry($_entry_str){
$_bad_chars = array(' ', 'select', 'insert', 'delete', 'update', ';', ',');
$_remove_chars = str_replace($_bad_chars, '', strtolower($_entry_str));
$_remove_html = strip_tags($_remove_chars);
if(is_numeric($_remove_html)){
return $_remove_html;
}else{
die('You must refer to entries using integers only');
}
}
//if the GET var 'entry' is set, this is a permalink and we will only ask for 1 entry
if(isset($_GET['entry'])){
//set a var to check if we are in teh entry page view later
$_entryview = true;
//clean the entry number to remove possible security issues
$_perma_entry = cleanEntry($_GET['entry']);
$query = "SELECT comment, image, title, DATE_FORMAT(time, '%M %d, %Y %h:%i%p') AS time, uid, comments, postedBy, time AS ts FROM $TABLENAME WHERE uid = '$_perma_entry' LIMIT 1";
}else{
$query = "SELECT comment, image, title, DATE_FORMAT(time, '%M %d, %Y %h:%i%p') AS time, uid, comments, postedBy, time AS ts FROM $TABLENAME ORDER BY ts DESC LIMIT $bPage,$perPage ";
}
$result = mysql_query ($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$dateTime = strtolower($row[3]); //makes the AM PM lowercase. CSS is set to Capitalize the date later
echo "
$dateTime
"; //anchor tag set for easier linking
echo "
{$row[2]}
\n";
$ima = split(", ", $row[1]); //build array out of images list
for($i=0; $i
\n";
}else{ //handle PDFs
echo "
$ima[$i]";
}
}
}
}
//****************************************************************************************
//****DISPLAY COMMENT*********************************************************************
$com = nl2br($row[0]);
for($i=0; $i
\n", $com);
}else{ //handle PDFs
$com = str_replace("[$j]", "
$ima[$i]\n", $com);
}
}
}
echo "";
//****************************************************************************************
//****DISPLAY POSTED BY******************************************************************
//if multiUsers is turned on in settings.php, display the username that wrote the entry
if($MULTIUSERS){
echo "
Posted By: $row[6]
";
}
//***************************************************************************************
//****DISPLAY COMMENTS*******************************************************************
//you must have comments turned on (in settings.php) for this to display
if($COMMENTS){
if($row[5] != 0){
echo "";
}else{
echo "";
}
}
//***************************************************************************************
echo "
"; //this is the break line. set it's appearance in the CSS file.
}
echo "";
?>
mysql_close(); // Close the database connection. ?>