forked from cynial/STBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.php
More file actions
178 lines (145 loc) · 4.45 KB
/
posts.php
File metadata and controls
178 lines (145 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* STBlog Blogging System
*
* 基于Codeigniter的单用户多权限开源博客系统
*
* STBlog is an open source multi-privilege blogging System built on the
* well-known PHP framework Codeigniter.
*
* @package STBLOG
* @author Saturn <[email protected]>
* @copyright Copyright (c) 2009 - 2010, cnsaturn.com.
* @license GNU General Public License 2.0
* @link http://code.google.com/p/stblog/
* @version 0.1.0
*/
// ------------------------------------------------------------------------
/**
* STBlog Posts控制器
*
* 主要用于控制日志显示的功能表现
*
* @package STBLOG
* @subpackage Controllers
* @category Front-controllers
* @author Saturn <[email protected]>
* @link http://code.google.com/p/stblog/
*/
class Posts extends ST_Controller {
/**
* 构造函数
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 默认执行函数, 处理流程
*
* @access public
* @return void
*/
function index($slug = '')
{
/** 如为空,则跳转 */
if(empty($slug))
{
redirect(site_url());
}
/** 获取日志内容 */
$post = $this->posts_mdl->get_post_by_id('slug', $slug);
/** 不存在? */
if(!$post)
{
show_404();
}
/** 内容显示格式化 */
$post = $this->_prepare_post($post);
/** 是否存在评论? */
$comments = $this->comments_mdl->get_cmts($post->pid, '', 'approved', 0, 0, 'ASC');
/** 评论显示格式化 */
if($comments->num_rows() >0)
{
$comments = $this->_prepare_comments($post, $comments);
}
/** 页面初始化 */
$data['page_title'] = $post->title;
$data['page_description'] = Common::subStr(strip_tags($post->content), 0, 100, '...');
$data['page_keywords'] = Common::format_metas($post->tags, ',', FALSE);
$data['parsed_feed'] = Common::render_feed_meta('post', $post->slug, $post->title);
$data['post'] = $post;
$data['comments'] = $comments;
$this->load_theme_view('post', $data);
}
/**
* 内容格式化
*
* @access private
* @param stdClass $post
* @return stdClass
*/
private function _prepare_post($post)
{
/** 日志发表日期 */
$post->published = setting_item('post_date_format')
? date(setting_item('post_date_format'), $post->created)
: date('Y-m-d', $post->created);
$post->modified = setting_item('post_date_format')
? date(setting_item('post_date_format'), $post->modified)
: date('Y-m-d', $post->modified);
$this->metas_mdl->get_metas($post->pid);
/** 日志分类 */
$post->categories = $this->metas_mdl->metas['category'];
/** 日志标签 */
$post->tags = $this->metas_mdl->metas['tag'];
$post->content = Common::get_content($post->text);
$post->comment_allowed = (0 == $post->allowComment || Common::auto_closed($post->created, now())) ? FALSE : TRUE;
$post->ping_allowed = (1 == $post->allowPing) ? TRUE : FALSE;
$post->comment_post_url = site_url('comment/' . $post->pid);
unset($post->text);
return $post;
}
/**
* 评论格式化
*
* @access private
* @param stdClass $post
* @param array $comments
* @return array
*/
private function _prepare_comments($post, $comments)
{
foreach($comments->result() as $comment)
{
$comment->published = setting_item('comments_date_format')
? date(setting_item('comments_date_format'), $comment->created)
: date('Y-m-d', $comment->created);
$comment->permalink = site_url('posts/'. $post->slug . '#comment-' . $comment->cid);
$comment->author_link = $comment->author;
if(!empty($comment->url))
{
$nofollow = array();
if('1' == setting_item('comments_url_no_follow'))
{
$nofollow = array('rel' => 'external nofollow');
}
$comment->author_link = anchor($comment->url, $comment->author, $nofollow);
}
if('trackback' == $comment->type)
{
$text = unserialize($comment->text);
$comment->author_link = '来自' . $comment->author_link .'在文章'. anchor($comment->url, $text['title']) .'中的引用';
$comment->text = $text['excerpt'];
}
$comment->content = Common::cut_paragraph($comment->text);
unset($comment->text);
}
return $comments;
}
}
/* End of file posts.php */
/* Location: ./application/controllers/posts.php */