其實魔盒的源代碼還是挺簡單的,如下就是全部代碼:
<?phprequire?'./libs/Smarty.class.php';
$smarty?=?new?Smarty();
$smarty->assign('title',?'博客正文');
if(!isset($_GET["blogid"])?||?!is_numeric($_GET["blogid"]))
{
$smarty->assign('info',?'您所查看的文章不存在或已經被刪除。');
$smarty->display('wrong.html');
exit();
}
$blogid?=?$_GET["blogid"];
$mysqli?=?new?mysqli("localhost","root","","herblog");
$sql?=?"select?id,datecreate,readcnt,commentcnt,title,blog?from?blog?where?id='"?.?$blogid?.?"'";
$rst?=?$mysqli->query($sql);
if(!$rst)
{
//數據查詢出錯?
$smarty->assign('info',?'服務器忙,請稍後重試');
$smarty->display('wrong.html');
$mysqli->close();
exit();
}
if($row?=?$rst->fetch_array())
{
$smarty->assign('blog',?array(
'id'?=>?$row[0],
'date'?=>?$row[1],
'readcnt'?=>?$row[2],
'commentcnt'?=>?$row[3],
'title'?=>?$row[4],
'blog'?=>?$row[5],
));
$hasComment?=?0;
$sql?=?"select?`id`,`date`,`ip`,`user`,`text`?from?comment?where?`blogid`='"?.?$blogid?.?"'";
$rst?=?$mysqli->query($sql);
if($rst)
{
$comments?=?array();
while($row?=?$rst->fetch_array())
{
$comments[]?=?array(
'date'?=>?$row[1],
'user'?=>?$row[3],
'text'?=>?$row[4]
);
$hasComment++;
}
$smarty->assign('comments',?$comments);
}
$smarty->assign('hasComment',?$hasComment);
$smarty->display('blog.html');
}
else
{
$smarty->assign('info',?'您所查看的文章不存在或已經被刪除。');
$smarty->display('wrong.html');
}
if($rst)
{
$rst->free();
}
$mysqli->close();
>