Location: PHPKode > projects > Blite > blite-0.1-beta6/blite/list.php
<?php
/*
 *      Copyright 2012 Douglas Robbins <hide@address.com>
 *      
 *      This file is part of Blite, a blogging application, available at
 *      <http://blite.ca/>.
 * 
 *      Blite is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

require('configure.php');

if (!$authuser) {
	echo $lang['permdenied'];
	exit;
}
if ($_GET['s'] == '2') {
	$status = 2;
	$page['pagetitle'] = $lang['draftposts'];
	$noposts = $lang['nodrafts'];
}
elseif ($_GET['s'] == '3') {
	$status = 3;
	$page['pagetitle'] = $lang['retractedposts'];
	$noposts = $lang['noretracted'];
}
else {
	exit;
}

// Build the category array.

$query_params = '';
$results = db_query("SELECT id, catname FROM categories");
$queries++;

while ($row = db_getdata($results)) {
	$catid = $row['id'];
	$catname = $row['catname'];
	$catarray[$catid] = $catname;
}

// Build a nonce.

$noncestamp = time();
$nonce = sha1( $noncestamp . $_SERVER['REMOTE_ADDR'] . $cfg['noncesalt'] );

$query_params = array( 'status' => 'int' );
$results = db_query("SELECT id,stamp,categories,title FROM posts WHERE status=? ORDER BY stamp DESC");

$page['list'] = "<tr><th>" . $lang['title'] . "</th><th>" . $lang['datetime'] . "</th><th>" . $lang['category'] . "</th><th>" . $lang['actions'] . "</th></tr>\n";
$cnt = 0;

while ($row = db_getdata($results)) {
	$id = $row['id'];
	$title = "<a href='./?t=${id}'>" . $row['title'] . "</a>";
	$categories = '';
	$cats = explode(' ', $row['categories']);
	foreach ($cats as $catid) {
		$categories .= "<i>" . $catarray[$catid] . '</i>, ';
	}
	$categories = substr($categories, 0, -2);
	$postdate = date("d M Y, g:i a", $row['stamp']+$timeoffset);
	$actions  = "<form method='post' action='post.php' class='inline'>\n";
	$actions .= "<input type='submit' name='edit' value='" . $lang['admineditpost'] . "' class='blink'>\n";
	$actions .= " &nbsp;&middot;&nbsp; <input type='submit' name='publish' value='" . $lang['adminpubpost'] . "' class='blink' onClick=\"return confirm('" . $lang['pubpostcfrm'] . "')\">\n";
	$actions .= "<input type='hidden' name='postid' value='${id}'>\n";
	$actions .= "<input type='hidden' name='nonce' value='${nonce}'>\n";
	$actions .= "<input type='hidden' name='stamp' value='${noncestamp}'>\n";
	$actions .= "</form>\n</div>\n";
	$actions .= "</form>";
	$page['list'] .= "<tr><td>$title</td><td nowrap>$postdate</td><td>$categories</td><td nowrap>${actions}</td></tr>\n";
	$cnt++;
}

if ($cnt == 0) {
	$page['list'] = "<div style='text-align:center'>$noposts</div>";
}
else {
	$page['list'] = "<table cellspacing=0 cellpadding=0 border=0 class='list'>\n" . $page['list'] . "</table>";
}
$page['cssfile'] = 'themes/' . $cfg['theme'] . '/admin.css';
$page['infobar'] = "<div class='infobar'>" . $page['pagetitle'] . "</div>";
$page['contentclass'] = '';
$page['navbottom'] = "<ul class='adminnav'><li><a href='./'>Home</a></li>\n$adminnav</ul>\n";
$subtemplate = file_get_contents('themes/' . $cfg['theme'] . '/templates/sub_list.tpl');
$template = file_get_contents('themes/' . $cfg['theme'] . '/templates/main.tpl');
$template = str_replace("#maincontent#", $subtemplate, $template);
foreach ($page as $key => $val) {
	$template = str_replace("#${key}#",$val,$template);
}
echo $template;
exit;
?>
Return current item: Blite