forked from cynial/STBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.php
More file actions
295 lines (250 loc) · 7.94 KB
/
Copy pathfeed.php
File metadata and controls
295 lines (250 loc) · 7.94 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?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 <huyanggang@gmail.com>
* @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 Feed控制器
*
* 主要用于控制Feed的功能表现
*
* @package STBLOG
* @subpackage Controllers
* @category Front-controllers
* @author Saturn <huyanggang@gmail.com>
* @link http://code.google.com/p/stblog/
*/
class Feed extends ST_Controller {
/**
* 是否输出全文
*
* @access private
* @var int
*/
private $_feed_full_text = 1;
/**
* 构造函数
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
$this->load->library('feedwriter', RSS2);
$this->_feed_full_text = intval(setting_item('feed_full_text'));
}
/**
* 请求分发
*
* @access public
* @param string $key 类别
* @param string $value slug
* @return void
*/
public function index($key = '', $value = '')
{
switch ($key)
{
case 'category':
$this->generate_category_feed($value);
break;
case 'tag':
$this->generate_tag_feed($value);
break;
case 'post':
$this->generate_post_feed($value);
break;
case 'comments':
$this->generate_comments_feed();
break;
default:
$this->generate_feed();
break;
}
}
/**
* 生成所有日志feed
*
* @access public
* @return void
*/
public function generate_feed()
{
$posts = $this->posts_mdl->get_posts('post', 'publish', NULL, 10, 0, 0, '', TRUE);
/** init */
$this->feedwriter->setTitle(setting_item('blog_title'));
$this->feedwriter->setLink(site_url());
$this->feedwriter->setDescription(setting_item('blog_description'));
$this->feedwriter->setChannelElement('language', 'zh-CN');
$this->feedwriter->setChannelElement('pubDate', date(DATE_RSS, now()));
$this->_generate($posts);
}
/**
* 生成所有评论feed
*
* @access public
* @return void
*/
public function generate_comments_feed()
{
$comments = $this->comments_mdl->get_cmts(0, 'comment', 'approved', 100, 0, 'DESC', '');
/** init */
$this->feedwriter->setTitle(setting_item('blog_title') .'所有评论');
$this->feedwriter->setLink(site_url());
$this->feedwriter->setDescription(setting_item('blog_description'));
$this->feedwriter->setChannelElement('language', 'zh-CN');
$this->feedwriter->setChannelElement('pubDate', date(DATE_RSS, now()));
if($comments->num_rows() > 0)
{
foreach($comments->result() as $comment)
{
$parent_post = $this->posts_mdl->get_post_by_id('pid', $comment->pid);
if(!$parent_post)
{
continue;
}
$title = $comment->author . '评论:' . $parent_post->title;
$permalink = site_url('posts/'. $parent_post->slug .'#comment-'. $comment->cid);
$newItem = $this->feedwriter->createNewItem();
$newItem->setTitle($title);
$newItem->setLink($permalink);
$newItem->setDate($comment->created);
$newItem->setDescription($comment->text);
$newItem->addElement('author', $comment->author);
$newItem->addElement('guid', $permalink,array('isPermaLink'=>'true'));
$this->feedwriter->addItem($newItem);
}
}
$this->feedwriter->genarateFeed();
}
/**
* 生成指定日志feed
*
* @access public
* @param string $slug
* @return void
*/
public function generate_post_feed($slug)
{
$post = $this->posts_mdl->get_post_by_id('slug', $slug);
if(empty($post))
{
show_error('发生错误:内容不存在或已被删除');
exit();
}
/** init */
$this->feedwriter->setTitle(setting_item('blog_title') .' - '. $post->title .' 的评论');
$this->feedwriter->setLink(site_url('posts/' . $post->slug));
$this->feedwriter->setDescription(Common::subStr(strip_tags(Common::get_content($post->text)), 0, 200, '...'));
$this->feedwriter->setChannelElement('language', 'zh-CN');
$this->feedwriter->setChannelElement('pubDate', date(DATE_RSS, now()));
$comments = $this->comments_mdl->get_cmts($post->pid, 'comment', 'approved', 0, 0, 'DESC', '');
if($comments->num_rows() > 0)
{
foreach($comments->result() as $comment)
{
$title = $comment->author . ' 评';
$permalink = site_url('posts/'. $post->slug .'#comment-'. $comment->cid);
$newItem = $this->feedwriter->createNewItem();
$newItem->setTitle($title);
$newItem->setLink($permalink);
$newItem->setDate($comment->created);
$newItem->setDescription($comment->text);
$newItem->addElement('author', $comment->author);
$newItem->addElement('guid', $permalink,array('isPermaLink'=>'true'));
$this->feedwriter->addItem($newItem);
}
}
$this->feedwriter->genarateFeed();
}
/**
* 生成分类中的日志feed
*
* @access public
* @param string $slug
* @return void
*/
public function generate_category_feed($slug)
{
$category = $this->metas_mdl->get_meta_by_slug($slug);
if(empty($category))
{
show_error('发生错误:分类不存在或已被删除');
exit();
}
/** init */
$this->feedwriter->setTitle(setting_item('blog_title') . ' - 分类:' .$category->name);
$this->feedwriter->setLink(site_url('category/'. $category->slug));
$this->feedwriter->setDescription($category->description);
$this->feedwriter->setChannelElement('language', 'zh-CN');
$this->feedwriter->setChannelElement('pubDate', date(DATE_RSS, now()));
$posts = $this->posts_mdl->get_posts_by_meta($slug, 'category', 'post', 'publish', 'posts.*', 10, 0, TRUE);
$this->_generate($posts);
}
/**
* 生成tag中的日志feed
*
* @access public
* @param string $slug
* @return void
*/
public function generate_tag_feed($slug)
{
$tag = $this->metas_mdl->get_meta_by_slug($slug);
if(empty($tag))
{
show_error('发生错误:标签不存在或已被删除');
exit();
}
/** init */
$this->feedwriter->setTitle(setting_item('blog_title') . ' - 标签:' .$tag->name);
$this->feedwriter->setLink(site_url('tag/'. $tag->slug));
$this->feedwriter->setDescription(setting_item('blog_description'));
$this->feedwriter->setChannelElement('language', 'zh-CN');
$this->feedwriter->setChannelElement('pubDate', date(DATE_RSS, now()));
$posts = $this->posts_mdl->get_posts_by_meta($slug, 'tag', 'post', 'publish', 'posts.*', 10, 0, TRUE);
$this->_generate($posts);
}
/**
* 处理item节点,并生成xml文档
*
* @access public
* @param string $slug
* @return void
*/
private function _generate($posts)
{
if($posts->num_rows() >0)
{
foreach($posts->result() as $post)
{
$permalink = site_url('posts/'. $post->slug);
$description = (1 == $this->_feed_full_text) ? Common::get_content($post->text) : Common::get_excerpt($post->text);
$newItem = $this->feedwriter->createNewItem();
$newItem->setTitle(htmlspecialchars($post->title));
$newItem->setLink($permalink);
$newItem->setDate($post->created);
$newItem->setDescription($description);
$newItem->addElement('author', $post->screenName);
$newItem->addElement('guid', $permalink,array('isPermaLink'=>'true'));
$this->feedwriter->addItem($newItem);
}
}
$this->feedwriter->genarateFeed();
}
}
/* End of file feed.php */
/* Location: ./application/controllers/feed.php */