|
这段代码是phpchina的版主phzzy写的,原帖还附带了对本站的简单介绍,鉴于本站是CI中国主站,就不转贴phzzy的原贴了,只把代码奉上:PHP复制代码 <?php
class Blog extends Controller
{
// construction
function Blog ()
{
parent ::Controller();
$this->load->helper('url');
$this->load->helper('date');
$this->load->script('ubb');
}
// public functions
function index ()
{
$this->viewtopic();
}
function viewtopic ()
{
$topic_list = $this->_topic_list ();
$data['body'] = $topic_list;
$this->load->view('main' , $data);
}
function viewblog ()
{
$blog = $this->_show_blog ();
$comment_list = $this->_show_comment_list ();
$comment_form = $this->_show_comment_form ();
$data['body'] = $blog . "\n\n" . $comment_list . "\n\n" . $comment_form;
$this->load->view('main' , $data);
}
function comment ()
{
$blog_id = $_POST['blog_id'] + 0;
if( $blog_id <= 0 )
{
show_error ('Error');
}
switch($this->uri->segment(3))
{
case 'insert':
$this->_comment_insert ();
break;
case 'delete':
//do delete the comment
break;
case 'edit':
//do edit the comment
break;
default:
redirect (base_url ());
break;
}
}
// private functions
function _topic_list ()
{
$catalog_id = $this->uri->segment(3) + 0;
if( $catalog_id < 0 )
{
redirect ();
}
$sql_add = '';
if( $catalog_id > 0 )
{
$sql_add = ' WHERE b.`catalog_id` = ' . $catalog_id;
}
$topic['title'] = 'My Blog';
$sql = "SELECT b.* , c.`name` as `catalog_name` FROM `blogs` AS `b` LEFT JOIN `catalogs` AS `c` ON c.`id` = b.`catalog_id`{$sql_add} ORDER BY `id` DESC";
$topic['blog_array'] = $this->db->query($sql);
return $this->load->view('viewtopic' , $topic , true);
}
function _show_blog ()
{
$blog_id = $this->uri->segment(3) + 0;
if( $blog_id <= 0 )
{
redirect ();
}
$sql = "SELECT b.* , c.`name` as `catalog_name` FROM `blogs` AS `b` LEFT JOIN `catalogs` AS `c` ON c.`id` = b.`catalog_id` WHERE b.`id` = {$blog_id} LIMIT 1";
$topic['blog_array'] = $this->db->query($sql);
return $this->load->view('viewblog' , $topic , true);
}
function _show_comment_list ()
{
$blog_id = $this->uri->segment(3) + 0;
if( $blog_id <= 0 )
{
redirect ();
}
$sql = "SELECT * FROM `comments` WHERE `blog_id` = {$blog_id} ORDER BY `id` DESC";
$comment['comment_array'] = $this->db->query($sql);
return $this->load->view('comment_list' , $comment , true);
}
function _show_comment_form ()
{
$this->load->helper('form');
return $this->load->view('comment_form' , '' , true);
}
function _comment_insert ()
{
$blog_id = $_POST['blog_id'];
$username = $_POST['username'];
$comment = $_POST['comment'];
$time = now ();
if(empty($comment) || empty($username))
{
show_error ('Some field is blank!
Please <a href="javascript:history.back();">return</a>..');
}
$sql = "INSERT INTO `comments` (`blog_id` , `username` , `comment` , `time`) VALUES({$blog_id} , '{$username}' , '{$comment}' , {$time})";
$this->db->query($sql);
$sql = "UPDATE `blogs` SET `comment_times` = `comment_times` + 1 WHERE `id` = {$blog_id} LIMIT 1";
$this->db->query($sql);
redirect ('blog/viewblog/' . $blog_id);
}
}
?> 复制代码 由于phzzy原始地址 “全没了……….全被丫删了”,所以目前暂时只能从本站下载。
本站下载地址:
blog.zip
(255.6 KB, 下载次数: 657)
或者访问phzzy的原始帖子,也带有附件。
///////////////////////////////////////////////////////////////
PS.20071129:经过测试发现此代码使用的CI是另外一个版本,但是同现在的版本使用同一个版本号,作者也相同,但是版权声明确是不一样的,phzzy的这个使用的版权是pMachine, Inc. ,而目前下载到的版本版权是EllisLab, Inc. ,所以使用时最好上传所有压缩包里的内容,否则会出错。 |
评分
-
查看全部评分
|