1 Star 0 Fork 8

kohunglee/emlog

forked from emlog/emlog 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rss.php 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
emlog 提交于 2022-03-19 00:20 . fix:rss
<?php
/**
* RSS
* @package EMLOG (www.emlog.net)
*/
require_once './init.php';
header('Content-type: application/xml');
$sort = isset($_GET['sort']) ? (int)$_GET['sort'] : '';
$URL = BLOG_URL;
$blog = getArticleList($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 = date('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;
function getArticleList($sortid = null) {
$parsedown = new Parsedown();
$parsedown->setBreaksEnabled(true); //automatic line wrapping
$rss_output_num = Option::get('rss_output_num');
if ($rss_output_num <= 0) {
return [];
}
$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);
$d = [];
while ($re = $DB->fetch_array($result)) {
$re['id'] = $re['gid'];
$re['title'] = htmlspecialchars($re['title']);
$re['content'] = $parsedown->text($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']) . '">阅读全文&gt;&gt;</a>';
}
$d[] = $re;
}
return $d;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/kohunglee/emlog.git
[email protected]:kohunglee/emlog.git
kohunglee
emlog
emlog
master

搜索帮助