ponyfish的那个通配符很难设,于是自己用PHP写了一个
两个订阅地址,择一即可:
http://www.JerryHong.com/SSE_RSS/
这个反应比较慢(其实是定位到index.php的),但肯定是最新的
http://www.JerryHong.com/SSE_RSS/index.xml
这个反应很快(xml文件嘛),但要有人访问了上面那个地址这个xml文件才会被更新
改进空间:
1.让index.php也直接返回xml中的内容,而从sse官方获取最新通知的动作由ajax或IFrame来触发,但是rss阅读器应该不会支持这两种……
2.怎么才能统计订阅数?是不是统计每天有阅读活动的读者数量?在统计每天有阅读活动的读者数量时要不要记录IP来判断是不是今天已经阅读过了?
- <?php
- /**
- * Class name: RSS
- * Author : LeadStar Team
- * website : http://www.leadstar.com.cn/
- * CopyRight : LeadStar Team
- */
- if (defined('_CLASS_RSS_PHP')) return;
- define('_CLASS_RSS_PHP',1);
- define('REFRESH_TIME',3*60*60);//刷新时间,单位秒
- class RSS {
- //public
- var $rss_ver = "2.0";
- var $channel_title = 'Tongji SSE RSS';
- var $channel_link = 'http://www.JerryHong.com/SSE_RSS';
- var $channel_description = '';
- var $language = 'zh_CN';
- var $copyright = '';
- var $webMaster = '';
- var $pubDate = '';
- var $lastBuildDate = '';
- var $generator = 'JerryHong RSS Generator';
- var $content = '';
- var $items = array();
- /**************************************************************************/
- // 函数名: RSS
- // 功能: 构造函数
- // 参数: $title
- // $link
- // $description
- /**************************************************************************/
- function RSS($title, $link, $description) {
- $this->channel_title = $title;
- $this->channel_link = $link;
- $this->channel_description = $description;
- $this->pubDate = Date('Y-m-d H:i:s',time());
- $this->lastBuildDate = Date('Y-m-d H:i:s',time());
- }
- /**************************************************************************/
- // 函数名: AddItem
- // 功能: 添加一个节点
- // 参数: $title
- // $link
- // $description $pubDate
- /**************************************************************************/
- function AddItem($title, $link, $description ,$pubDate) {
- $this->items[] = array('title' => $title ,
- 'link' => $link,
- 'description' => $description,
- 'pubDate' => $pubDate);
- }
- /**************************************************************************/
- // 函数名: BuildRSS
- // 功能: 生成rss xml文件内容
- /**************************************************************************/
- function BuildRSS() {
- $s = "<?xml version=\"1.0\" encoding=\"gb2312\" ?>
- <rss version=\"2.0\"\n
- xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
- xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\"
- xmlns:dc=\"http://purl.org/dc/elements/1.1/\">";
- // start channel
- $s .= "<channel>\n";
- $s .= "<title>$this->channel_title</title>\n";
- $s .= "<link>$this->channel_link</link>\n";
- $s .= "<description>$this->channel_description</description>\n";
- $s .= "<language>{$this->language}</language>\n";
- if (!empty($this->copyright)) {
- $s .= "<copyright>$this->copyright</copyright>\n";
- }
- if (!empty($this->webMaster)) {
- $s .= "<webMaster>$this->webMaster</webMaster>\n";
- }
- if (!empty($this->pubDate)) {
- $s .= "<pubDate>{$this->pubDate}</pubDate>\n";
- }
- if (!empty($this->lastBuildDate)) {
- $s .= "<lastBuildDate>{$this->lastBuildDate}</lastBuildDate>\n";
- }
- if (!empty($this->generator)) {
- $s .= "<generator>{$this->generator}</generator>\n";
- }
- // start items
- for ($i=0;$i<count($this->items);$i++) {
- $s .= "<item>\n";
- $s .= "<title>{$this->items[$i]['title']}</title>\n";
- $s .= "<link>{$this->items[$i]['link']}</link>\n";
- $s .= "<description>{$this->items[$i]['description']}</description>\n";
- $s .= "<pubDate>{$this->items[$i]['pubDate']}</pubDate>\n";
- $s .= "</item>\n";
- }
- // close channel
- $s .= "</channel>\n</rss>";
- $this->content = $s;
- }
- /**************************************************************************/
- // 函数名: Show
- // 功能: 将产生的rss内容直接打印输出
- /**************************************************************************/
- function Show() {
- if (empty($this->content)) $this->BuildRSS();
- echo($this->content);
- }
- /**************************************************************************/
- // 函数名: SaveToFile
- // 功能: 将产生的rss内容保存到文件
- // 参数: $fname 要保存的文件名
- /**************************************************************************/
- function SaveToFile($fname) {
- $handle = fopen($fname, 'wb');
- if ($handle === false) return false;
- fwrite($handle, $this->content);
- fclose($handle);
- }
- }
- header('Content-Type: text/xml');
- //http://www.ponyfish.com/feeds/28267doyQWCrC
- //http://sse.tongji.edu.cn
- //(.*)<td width=\"70\">(.*)</td>
- function getContent($url) {
- $file = fopen($url, 'r');
- if(!$file)
- {
- return 0;
- }
- $content = "";
- while (!feof ($file)) {
- $content.= fgets ($file, 1024);
- }
- return $content;
- }
- //流程开始
- $needRefresh = false;
- $xmlContent = getContent('index.xml');
- if(!$xmlContent)
- {
- $needRefresh = true;
- }
- //取得访问次数
- else
- {
- preg_match('/已被访问(\d*)次/s', $xmlContent, $countt);
- $count = $countt[1];
- if(!$count)
- $count=1;
- $count++;
- $xmlContent = preg_replace('/已被访问(\d*)次/i', '已被访问'.$count.'次', $xmlContent);
- //取得上次刷新时间
- preg_match('/<lastBuildDate>(.*?)<\/lastBuildDate>/s', $xmlContent, $lastRefreshh);
- $lastRefresh = strtotime($lastRefreshh[1]);
- $now = time();
- if($now-$lastRefresh>=REFRESH_TIME)
- $needRefresh = true;
- else
- $needRefresh = false;
- }
- //如果离上次刷新时间不超过REFRESH_TIME,就把xml文件的内容呈现出去,并更新xml文件(目的是更新访问次数……)
- if(!$needRefresh)
- {
- echo $xmlContent;
- $file = fopen('index.xml', 'w');
- fwrite($file, $xmlContent);
- fclose($file);
- exit();
- }
- else
- {
- //否则从远端获取资料并刷新xml文件
- $lastRefresh = Date('Y-m-d H:i:s',time());
- $rss = new RSS('sseRSS', 'http://www.JerryHong.com/SSE_RSS', '软院新闻订阅源 by www.JerryHong.com 已被访问'.$count.'次 上次更新时间'.$lastRefresh);
- $line = getContent('http://sse.tongji.edu.cn/');
- if (preg_match ('/<!--学院通知-->(.*?)<!--学术报告-->/s', $line, $newsPart)) {
- $newses = $newsPart[1];
- }
- //get each news from $newses
- preg_match_all ('/<td width=\"270\">.*?<\/td>.*?<td width=\"70\">.*?<\/td>/s', $newses, $everynews);
- foreach($everynews[0] as $news)
- {
- preg_match('/(\/web.*?)\"/s', $news, $linkk);
- $link = $linkk[1];
- $link = "http://sse.tongji.edu.cn".$link;
- $link = htmlspecialchars($link);
- preg_match('/none\">(.*)<\/a>/s', $news, $titlee);
- $title = $titlee[1];
- $title = trim($title);
- $title = htmlspecialchars($title);
- $title = substr($title, 0, strrpos($title, '['));
- /*
- $description = getContent($link);
- preg_match('/TEXT-ALIGN: left\">(.*)<\/Textarea>/', $description, $descriptionn);
- $description = $descriptionn[1];
- */
- preg_match('/\d\d-\d-\d\d|
- \d\d-\d\d-\d\d|
- \d\d-\d-\d|
- \d\d-\d-\d\d/', $news, $datee);
- $date = $datee[0];
- $rss->AddItem($title, $link, $description, $date);
- }
- $rss->BuildRSS();
- $rss->Show();
- $rss->SaveToFile('index.xml');
- }
- ?>






瑞仔你好帅~~
@怪怪
这个世界就你有爱了……