Location: PHPKode > projects > ZompLog > admin/functions_menu.php
<?php

	/* These functions fetch the content for the menu from the database, and prepare it before it is sent to the template */
	

	
	function displayPages($spacer){
	global $table_pages, $link, $page;
	$query = "SELECT * FROM $table_pages ORDER BY pageorder ASC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$pages = arrayMaker($result,MYSQL_ASSOC);
	foreach($pages as $page){
	if(ROOT){
	echo "<a href='".ROOT."pages/$page[id]'>$page[title]</a>$spacer";
	}
	else
	{
	echo "<a href='?content=page&amp;id=$page[id]'>$page[title]</a>$spacer";
	}
	}
	}
	
		function displayPagesList($spacer){
	global $table_pages, $link, $page, $content;
	$query = "SELECT * FROM $table_pages ORDER BY pageorder ASC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$pages = arrayMaker($result,MYSQL_ASSOC);
	foreach($pages as $page){
	
	// mark the current page
	if (($_GET['id'] == $page['id']) and ($content == 'page')) {
	$current = 'class=\'current_page_item\'';
	}
	else
	{
	$current = '';
	}
	
	if(ROOT){
	echo "<li $current><a href='".ROOT."pages/$page[id]'>$page[title]</a></li>$spacer";
	}
	else
	{
	echo "<li $current><a href='?content=page&amp;id=$page[id]'>$page[title]</a></li>$spacer";
	}
	}
	}
	
	function displaylatestEntries($spacer){
	global $table, $settings, $link, $entry;
	//  obtain current date in order to select out not-yet-published and expired posts
	$rev_datetime = date('YmdHis');
	$query = "SELECT * FROM $table WHERE (date <= $rev_datetime) AND (expirydate >= $rev_datetime) ORDER BY id DESC LIMIT $settings[nr_entries]";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$entries = arrayMaker($result,MYSQL_ASSOC);
	foreach($entries as $entry){
	if(ROOT){
	echo "<a href='".ROOT."posts/$entry[id]'>$entry[title]</a>$spacer";
	}
	else
	{
	echo "<a href='?content=detail&amp;id=$entry[id]'>$entry[title]</a>$spacer";
	}
	}
	}
	
		function displaylatestEntriesList($spacer){
	global $table, $settings, $link, $entry;
	//  obtain current date in order to select out not-yet-published and expired posts
	$rev_datetime = date('YmdHis');
	$query = "SELECT * FROM $table WHERE (date <= $rev_datetime) AND (expirydate >= $rev_datetime) ORDER BY id DESC LIMIT $settings[nr_entries]";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$entries = arrayMaker($result,MYSQL_ASSOC);
	foreach($entries as $entry){
	if(ROOT){
	echo "<li><a href='".ROOT."posts/$entry[id]'>$entry[title]</a></li>$spacer";
	}
	else
	{
	echo "<li><a href='?content=detail&amp;id=$entry[id]'>$entry[title]</a></li>$spacer";
	}
	}
	}
	

function displaylatestComments($spacer){
global $table,$settings, $table_comments, $link, $entry;
//  obtain current date and time in order to select out not-yet-published and expired posts
$rev_datetime = date('YmdHis');
// query ALL comments (at this point we do not yet know which comments must be printed)
$query = "SELECT * FROM $table_comments ORDER BY id DESC";
$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$entries = arrayMaker($result,MYSQL_ASSOC);
$display_counter = 0;  // set a counter for displayed comments
// read first comment and display, but only when the original post still exists and is within publishing range
$curr_comment = current($entries);
if ($curr_comment) {
$query2 = "SELECT * FROM $table WHERE (id = $curr_comment[entry_id]) AND (date <= $rev_datetime) AND (expirydate >= $rev_datetime)";
$result2 = mysql_query ($query2, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$entries2 = arrayMaker($result2,MYSQL_ASSOC);
if (count($entries2) > 0) {  // when > 0, the original post still exists and is within range
	$comment = substr($curr_comment[comment], 0, 25);
	if(ROOT)
	{echo "<a href='".ROOT."posts/$curr_comment[entry_id]'>$comment (...)</a>$spacer";}
	else
	{echo "<a href='?content=detail&amp;id=$curr_comment[entry_id]'>$comment (...)</a>$spacer";}
	$display_counter++;
}
}
// then print the next comment and so forth, untill end of comments is reached,
// or maximum number of comments to be displayed is reached
while (($curr_comment = next($entries)) AND ($display_counter < $settings[nr_comments])) {   // max. number of comments to be displayed
$query2 = "SELECT * FROM $table WHERE (id = $curr_comment[entry_id]) AND (date <= $rev_datetime) AND (expirydate >= $rev_datetime)";
$result2 = mysql_query ($query2, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$entries2 = arrayMaker($result2,MYSQL_ASSOC);
if (count($entries2) > 0) {
	$comment = substr($curr_comment[comment], 0, 25);
	if(ROOT)
	{echo "<a href='".ROOT."posts/$curr_comment[entry_id]'>$curr_comment[entry_id]$comment (...)</a>$spacer";}
	else
	{echo "<a href='?content=detail&amp;id=$curr_comment[entry_id]'>$comment (...)</a>$spacer";}
	$display_counter++;
}
}
}
	
function displaylatestCommentsList($spacer){
global $table,$settings,$table_comments, $link, $entry;
//  obtain current date and time in order to select out not-yet-published and expired posts
$rev_datetime = date('YmdHis');
// query ALL comments (at this point we do not yet know which comments must be printed)
$query = "SELECT * FROM $table_comments ORDER BY id DESC";
$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$entries = arrayMaker($result,MYSQL_ASSOC);
$display_counter = 0;  // set a counter for displayed comments
// read first comment and display, but only when the original post still exists and is within publishing range
$curr_comment = current($entries);
if ($curr_comment) {
$query2 = "SELECT * FROM $table WHERE (id = $curr_comment[entry_id]) AND (date <= $rev_datetime) AND (expirydate >= $rev_datetime)";
$result2 = mysql_query ($query2, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$entries2 = arrayMaker($result2,MYSQL_ASSOC);
if (count($entries2) > 0) {  // when > 0, the original post still exists and is within range
	$comment = substr($curr_comment[comment], 0, 25);
	if(ROOT)
	{echo "<li><a href='".ROOT."posts/$curr_comment[entry_id]'>$comment (...)</a></li>$spacer";}
	else
	{echo "<li><a href='?content=detail&amp;id=$curr_comment[entry_id]'>$comment (...)</a></li>$spacer";}
	$display_counter++;
}
}
// then print the next comment and so forth, untill end of comments is reached,
// or maximum number of comments to be displayed is reached
while (($curr_comment = next($entries)) AND ($display_counter < $settings[nr_comments])) {   // max. number of comments to be displayed
$query2 = "SELECT * FROM $table WHERE (id = $curr_comment[entry_id]) AND (date <= $rev_datetime) AND (expirydate >= $rev_datetime)";
$result2 = mysql_query ($query2, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$entries2 = arrayMaker($result2,MYSQL_ASSOC);
if (count($entries2) > 0) {
	$comment = substr($curr_comment[comment], 0, 25);
	if(ROOT)
	{echo "<li><a href='".ROOT."posts/$curr_comment[entry_id]'>$comment (...)</a></li>$spacer";}
	else
	{echo "<li><a href='?content=detail&amp;id=$curr_comment[entry_id]'>$comment (...)</a></li>$spacer";}
	$display_counter++;
}
}
}



	function displayCategories($spacer){
	global $table_cat, $table, $link, $cat, $numcat;
	//  obtain current date in order to select out not-yet-published and expired posts
	$rev_datetime = date('YmdHis');
	$query = "SELECT * FROM $table_cat ORDER BY catorder ASC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$categories = arrayMaker($result,MYSQL_ASSOC);
	foreach($categories as $cat){
	$query = "SELECT * FROM $table WHERE (date <= $rev_datetime) AND (expirydate >= $rev_datetime) AND catid = $cat[id]";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$numcat = mysql_num_rows ($result);
	if(ROOT){
/*	echo "<a href='".ROOT."categories/$cat[id]'>$cat[name]</a> ($numcat)$spacer"; */
	echo "<a href='".ROOT."categories/$cat[id]'>$cat[name]</a>$spacer";   // leave out number of posts for better layout
	}
	else
	{
/*	echo "<a href='?catid=$cat[id]'>$cat[name]</a> ($numcat)$spacer"; */
	echo "<a href='?catid=$cat[id]'>$cat[name]</a>$spacer";   // leave out number of posts for better layout
	}
	}
	}
	
		function displayCategoriesList($spacer){
	//  obtain current date in order to select out not-yet-published and expired posts
	$rev_datetime = date('YmdHis');
	global $table_cat, $table, $link, $cat, $numcat;
	$query = "SELECT * FROM $table_cat ORDER BY catorder ASC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$categories = arrayMaker($result,MYSQL_ASSOC);
	foreach($categories as $cat){
	$query = "SELECT * FROM $table WHERE (date <= $rev_datetime) AND (expirydate >= $rev_datetime) AND catid = $cat[id]";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$numcat = mysql_num_rows ($result);
	
	// mark the current page
	if($_GET['catid'] == $cat['id']){
	$current = 'class=\'current_page_item\'';
	}
	else
	{
	$current = '';
	}
	
	if(ROOT){
/*	echo "<li><a href='".ROOT."categories/$cat[id]'>$cat[name]</a> ($numcat)</li>$spacer"; */
	echo "<li $current><a href='".ROOT."categories/$cat[id]'>$cat[name]</a></li>$spacer";   // leave out $numcat for better layout
	}
	else
	{
/*	echo "<li><a href='?catid=$cat[id]'>$cat[name]</a> ($numcat)</li>$spacer"; */
	echo "<li $current><a href='?catid=$cat[id]'>$cat[name]</a></li>$spacer";   // leave out $numcat for better layout
	}
	}
	}
	
	function displayAuthors($spacer){
	global $table_users, $link, $user;
	$query = "SELECT * FROM $table_users ORDER BY id DESC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$users = arrayMaker($result,MYSQL_ASSOC);
	foreach($users as $user){
	if(ROOT){
	if($user[name]){
	echo "<a href='".ROOT."profile/$user[id]'>$user[name]</a>$spacer";
	}
	else
	{
	echo "<a href='".ROOT."profile/$user[id]'>$user[login]</a>$spacer";
	}
	}
	else // if no root has been defined, that is
	{
	if($user[name]){
	echo "<a href='?content=profile&id=$user[id]'>$user[name]</a>$spacer";
	}
	else
	{
	echo "<a href='?content=profile&id=$user[id]'>$user[login]</a>$spacer";
	}
	}
	}
	}
	
	
	
		function displayAuthorsList($spacer){
	global $table_users, $link, $user;
	$query = "SELECT * FROM $table_users ORDER BY id DESC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$users = arrayMaker($result,MYSQL_ASSOC);
	foreach($users as $user){
	if(ROOT){
	if($user[name]){
	echo "<li><a href='".ROOT."profile/$user[id]'>$user[name]</a></li>$spacer";
	}
	else
	{
	echo "<li><a href='".ROOT."profile/$user[id]'>$user[login]</a></li>$spacer";
	}
	}
	else // if no root has been defined, that is
	{
	if($user[name]){
	echo "<li><a href='?content=profile&id=$user[id]'>$user[name]</a></li>$spacer";
	}
	else
	{
	echo "<li><a href='?content=profile&id=$user[id]'>$user[login]</a></li>$spacer";
	}
	}
	}
	}
	
		function displayTeasers($spacer){
	global $table, $link, $user;
	//  obtain current date in order to select out not-yet-published and expired posts
	$rev_datetime = date('YmdHis');
	$query = "SELECT * FROM $table WHERE (date <= $rev_datetime) AND (expirydate >= $rev_datetime) AND teaser = '1' ORDER BY id DESC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$teasers = arrayMaker($result,MYSQL_ASSOC);
	foreach($teasers as $teaser){
	if(ROOT){
	echo "<a href='".ROOT."posts/$teaser[id]'>$teaser[title]</a>$spacer";
	}
	else
	{
	echo "<a href='?content=detail&amp;id=$teaser[id]'>$teaser[title]</a>$spacer";
	}
	}
	}
	
			function displayTeasersList($spacer){
	global $table, $link, $user;
	//  obtain current date in order to select out not-yet-published and expired posts
	$rev_datetime = date('YmdHis');
	$query = "SELECT * FROM $table WHERE (date <= $rev_datetime) AND (expirydate >= $rev_datetime) AND teaser = '1' ORDER BY id DESC";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$teasers = arrayMaker($result,MYSQL_ASSOC);
	foreach($teasers as $teaser){
	if(ROOT){
	echo "<li><a href='".ROOT."posts/$teaser[id]'>$teaser[title]</a></li>$spacer";
	}
	else
	{
	echo "<li><a href='?content=detail&amp;id=$teaser[id]'>$teaser[title]</a></li>$spacer";
	}
	}
	}
	
	function about($spacer){
	global $table_users, $settings, $link, $user;
	if(!$_GET[username]){
	echo "$settings[about]$spacer";
	}
	else
	{
		$query = "SELECT * FROM $table_users WHERE login = '$_GET[username]' LIMIT 1";
	$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
	$user = mysql_fetch_array($result);
	echo "$user[about]$spacer";
	}
	return $user;
	}
	
	


// This script calculates the load time

$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$start = $time;

// Place this part at the very end of your page

$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$finish = $time;
$totaltime = ($finish - $start);

?>
Return current item: ZompLog