-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss.php
100 lines (91 loc) · 2.7 KB
/
rss.php
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
<?php
/**
* RSS输出
* @copyright (c) Emlog All Rights Reserved
*/
require_once './init.php';
header('Content-type: application/xml');
$sort = isset($_GET['sort']) ? intval($_GET['sort']) : '';
$URL = BLOG_URL;
$blog = getBlog($sort);
echo '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title><![CDATA['.Option::get('blogname').']]></title>
<description><![CDATA['.Option::get('bloginfo').']]></description>
<link>'.$URL.'</link>
<language>zh-cn</language>
<generator>www.emlog.net</generator>';
if (!empty($blog)) {
$user_cache = $CACHE->readCache('user');
foreach($blog as $value){
$link = Url::log($value['id']);
$abstract = str_replace('[break]','',$value['content']);
$pubdate = gmdate('r',$value['date']);
$author = $user_cache[$value['author']]['name'];
doAction('rss_display');
echo <<< END
<item>
<title>{$value['title']}</title>
<link>$link</link>
<description><![CDATA[{$abstract}]]></description>
<pubDate>$pubdate</pubDate>
<author>$author</author>
<guid>$link</guid>
</item>
END;
}
}
echo <<< END
</channel>
</rss>
END;
/**
* 获取文章信息
*
* @return array
*/
function getBlog($sortid = null) {
$rss_output_num = Option::get('rss_output_num');
if ($rss_output_num == 0) {
return array();
}
$DB = Database::getInstance();
$sorts = Cache::getInstance()->readCache('sort');
if (isset($sorts[$sortid])) {
$sort = $sorts[$sortid];
if ($sort['pid'] != 0 || empty($sort['children'])) {
$subsql = "and sortid=$sortid";
} else {
$sortids = array_merge(array($sortid), $sort['children']);
$subsql = "and sortid in (" . implode(',', $sortids) . ")";
}
} else {
$subsql = $sortid ? "and sortid=$sortid" : '';
}
$sql = "SELECT * FROM ".DB_PREFIX."blog WHERE hide='n' and type='blog' $subsql ORDER BY date DESC limit 0," . $rss_output_num;
$result = $DB->query($sql);
$blog = array();
while ($re = $DB->fetch_array($result))
{
$re['id'] = $re['gid'];
$re['title'] = htmlspecialchars($re['title']);
$re['date'] = $re['date'];
$re['content'] = $re['content'];
if(!empty($re['password']))
{
$re['content'] = '<p>[该文章已设置加密]</p>';
}
elseif(Option::get('rss_output_fulltext') == 'n')
{
if (!empty($re['excerpt'])) {
$re['content'] = $re['excerpt'];
}else {
$re['content'] = extractHtmlData($re['content'], 330);
}
$re['content'] .= ' <a href="'.Url::log($re['id']).'">阅读全文>></a>';
}
$blog[] = $re;
}
return $blog;
}