Created
July 15, 2012 10:52
-
-
Save netputer/3116246 to your computer and use it in GitHub Desktop.
通过 PHP 实现定期提醒更换订阅的 RSS Feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('./wp-load.php'); | |
// 加载 WordPress 库,用于获取博客标题等信息 | |
define('DONOTCACHEPAGE', TRUE); | |
// 禁止 WP Super Cache 对该页面进行缓存 | |
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true); | |
// 设置页面类型 | |
$feed_title = '博客更换域名,请更换订阅地址'; | |
// 文章标题 | |
$feed_link = 'http://netputer.me/subscribe/'; | |
// 文章链接 | |
$feed_desc = '最近把博客旧域名 OrzDream.com 更换为新域名 NetPuter.me 。虽然已经对旧域名设置了重定向,但这并非长久之策,同时也打算统一订阅地址,所以请各位订阅新的 RSS Feed 吧: http://Feed.NetPuter.me/'; | |
// 文章摘要 | |
$feed_content = '<p>最近把博客旧域名 <a href="http://OrzDream.com/">OrzDream.com</a> 更换为新域名 <a href="http://NetPuter.me/">NetPuter.me</a> 。虽然已经对旧域名设置了重定向,但这并非长久之策,同时也打算统一订阅地址,所以请各位订阅新的 RSS Feed 吧:</p><p><a href="http://Feed.NetPuter.me/" style="font-size:2em;font-weight:bold;color:#1982D1;">http://Feed.NetPuter.me/</a></p><p>或者:</p><ul><li><a href="http://www.google.com/reader/view/feed/http%3A%2F%2Ffeed.netputer.me%2F" title="订阅到 Google Reader" target="_blank">订阅到 Google Reader</a></li><li><a href="http://xianguo.com/subscribe?url=http%3A%2F%2Ffeed.netputer.me%2F" title="订阅到鲜果" target="_blank">订阅到鲜果</a></li><li><a href="http://reader.youdao.com/b.do?keyfrom=bookmarklet&url=http%3A%2F%2Ffeed.netputer.me%2F" title="订阅到有道" target="_blank">订阅到有道</a></li></ul><p>而原来的这个 Feed ,将成为「周经机器人」,每周提醒「更换订阅」……如果被打扰了,请果断退订吧,谢谢~</p>'; | |
// 文章内容 | |
$weekday = intval(gmdate('w', time())); | |
// 获取今天周几 | |
$is_wed = ($weekday + 7) % 10 ? FALSE : TRUE; | |
// 是否为周三 | |
if ($is_wed) { | |
$feed_ts = strtotime('Wednesday', time()); | |
// 使用本周三的时间戳 | |
} else { | |
$feed_ts = strtotime('last Wednesday', time()); | |
// 使用上周三的时间戳 | |
} | |
$feed_time = gmdate('D, d M Y 00:00:00 +0000', $feed_ts); | |
// 将时间戳转换为格式化文本 | |
// $feed_ts = gmdate('YmdH', time()); | |
// $feed_time = gmdate('D, d M Y H:00:00 +0000', time()); | |
// 每小时更新一次,仅用于调试 | |
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; | |
?> | |
<rss version="2.0" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:atom="http://www.w3.org/2005/Atom" | |
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" | |
> | |
<channel> | |
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title> | |
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> | |
<link><?php bloginfo_rss('url') ?></link> | |
<description><?php bloginfo_rss("description") ?></description> | |
<pubDate><?php echo $feed_time; ?></pubDate> | |
<lastBuildDate><?php echo $feed_time; ?></lastBuildDate> | |
<language>zh</language> | |
<sy:updatePeriod><?php echo apply_filters('rss_update_period', 'weekly'); ?></sy:updatePeriod> | |
<sy:updateFrequency><?php echo apply_filters('rss_update_frequency', '1'); ?></sy:updateFrequency> | |
<sy:updateBase><?php echo gmdate('Y-m-d\T00:00:00+00:00', $feed_ts); ?></sy:updateBase> | |
<?php do_action('rss2_head'); ?> | |
<item> | |
<title><?php echo $feed_title; ?></title> | |
<link><?php echo $feed_link; ?></link> | |
<pubDate><?php echo $feed_time; ?></pubDate> | |
<guid isPermaLink="false"><?php echo $feed_link.'?'.$feed_ts; ?></guid> | |
<description><![CDATA[<?php echo $feed_desc; ?>]]></description> | |
<content:encoded><![CDATA[<?php echo $feed_content; ?>]]></content:encoded> | |
</item> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment