增加对空间支持的判断,获取feed方法更强大
This commit is contained in:
31
lastRSS.php
31
lastRSS.php
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Rss订阅
|
||||
Version: 1.3.2
|
||||
Version: 1.3.3
|
||||
Plugin URL: http://xiaosong.org/tech/the-official-releas-of-rss-subscribe-plugin
|
||||
Description: 订阅朋友的博客feed,显示在自己博客~
|
||||
Author: 小松
|
||||
@@ -13,7 +13,7 @@ require_once(EMLOG_ROOT.'/content/plugins/lastRSS/lastRSS_config.php');
|
||||
require_once(EMLOG_ROOT.'/content/plugins/lastRSS/lastRSS_class.php');
|
||||
$rssparser = new lastRSS;
|
||||
$rssparser->cache_dir = EMLOG_ROOT.'/content/cache/';
|
||||
$rssparser->cache_time = $lastRSS_cache_time;
|
||||
$rssparser->cache_time = $lastRSS_cache_time;
|
||||
$rssparser->items_limit = $lastRSS_item_num > 3 ? 3 : $lastRSS_item_num;
|
||||
$rssparser->CDATA = 'content';
|
||||
$rssparser->cp = 'UTF-8';
|
||||
@@ -93,25 +93,26 @@ function updateFeed($id, $url, $title){
|
||||
}
|
||||
function getTitle($rss_url){
|
||||
global $rssparser;
|
||||
$rss = $rssparser->get($rss_url);
|
||||
$rss = $rssparser->Get($rss_url);
|
||||
return $rss['title'];
|
||||
}
|
||||
function updateLogs(){
|
||||
global $rssparser, $DB, $lastRSS_is_urlshort, $lastRSS_is_blank;
|
||||
$feeds = getRssFeeds();
|
||||
while ($item = $DB->fetch_array($feeds)) {
|
||||
$rss = $rssparser->get($item['url']);
|
||||
if(!empty($rss['items']))
|
||||
foreach ($rss['items'] as $key => $data) {
|
||||
$rssid = $item['id'];
|
||||
$hash = md5($data['title']);
|
||||
$checklog = isLogExists($rssid, $hash);
|
||||
if ($checklog == 0) {
|
||||
if (trim($data['title']) != '') {
|
||||
$link = $lastRSS_is_urlshort ? urlShort($data['link']) : $data['link'];
|
||||
$target = $lastRSS_is_blank ? ' target="_blank"' : '';
|
||||
$log = '<a href="'.$link.'"'.$target.'>'.strip_tags($data['title']).'</a>';
|
||||
insertLog($rssid, $log ,$hash);
|
||||
$rss = $rssparser->Get($item['url']);
|
||||
if(!empty($rss['items'])) {
|
||||
foreach ($rss['items'] as $key => $data) {
|
||||
$rssid = $item['id'];
|
||||
$hash = md5($data['title']);
|
||||
$checklog = isLogExists($rssid, $hash);
|
||||
if ($checklog == 0) {
|
||||
if (trim($data['title']) != '') {
|
||||
$link = $lastRSS_is_urlshort ? urlShort($data['link']) : $data['link'];
|
||||
$target = $lastRSS_is_blank ? ' target="_blank"' : '';
|
||||
$log = '<a href="'.$link.'"'.$target.'>'.strip_tags($data['title']).'</a>';
|
||||
insertLog($rssid, $log ,$hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,45 @@
|
||||
<?php
|
||||
function callback_init(){
|
||||
$DB = MySql::getInstance();
|
||||
$is_exist_rssfeeds_query = $DB->query('show tables like "'.DB_PREFIX.'rssfeeds"');
|
||||
$is_exist_rsslogs_query = $DB->query('show tables like "'.DB_PREFIX.'rsslogs"');
|
||||
$dbcharset = 'utf8';
|
||||
$type = 'MYISAM';
|
||||
$add = $DB->getMysqlVersion() > '4.1' ? "ENGINE=".$type." DEFAULT CHARSET=".$dbcharset.";":"TYPE=".$type.";";
|
||||
$addone = "INSERT INTO ".DB_PREFIX."rssfeeds (url, title) VALUES('http://xiaosong.org/rss.php', '快乐忆站')";
|
||||
if($DB->num_rows($is_exist_rssfeeds_query) == 0){
|
||||
$sql_rssfeeds = "
|
||||
CREATE TABLE `".DB_PREFIX."rssfeeds` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`url` text NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)".$add;
|
||||
$DB->query($sql_rssfeeds);
|
||||
$DB->query($addone);
|
||||
|
||||
}
|
||||
if($DB->num_rows($is_exist_rsslogs_query) == 0){
|
||||
$sql_rsslogs = "
|
||||
CREATE TABLE `".DB_PREFIX."rsslogs` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`rssid` int(10) NOT NULL,
|
||||
`log` text NOT NULL,
|
||||
`hash` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)".$add;
|
||||
$DB->query($sql_rsslogs);
|
||||
}
|
||||
}
|
||||
|
||||
function callback_rm(){
|
||||
$DB = MySql::getInstance();
|
||||
$feeds = getRssFeeds();
|
||||
while ($item = $DB->fetch_array($feeds)) {
|
||||
deleteFeed($item['id']);
|
||||
}
|
||||
$DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."rssfeeds");
|
||||
$DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."rsslogs");
|
||||
}
|
||||
<?php
|
||||
function callback_init(){
|
||||
if (!get_cfg_var("allow_url_fopen") && !extension_loaded('curl') && !function_exists('file_get_contents')) emMsg('该插件需要开启“allow_url_fopen”或“curl”或“file_get_contents”。请联系空间商开启!');
|
||||
$DB = MySql::getInstance();
|
||||
$is_exist_rssfeeds_query = $DB->query('show tables like "'.DB_PREFIX.'rssfeeds"');
|
||||
$is_exist_rsslogs_query = $DB->query('show tables like "'.DB_PREFIX.'rsslogs"');
|
||||
$dbcharset = 'utf8';
|
||||
$type = 'MYISAM';
|
||||
$add = $DB->getMysqlVersion() > '4.1' ? "ENGINE=".$type." DEFAULT CHARSET=".$dbcharset.";":"TYPE=".$type.";";
|
||||
$addone = "INSERT INTO ".DB_PREFIX."rssfeeds (url, title) VALUES('http://xiaosong.org/rss.php', '快乐忆站')";
|
||||
if($DB->num_rows($is_exist_rssfeeds_query) == 0){
|
||||
$sql_rssfeeds = "
|
||||
CREATE TABLE `".DB_PREFIX."rssfeeds` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`url` text NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)".$add;
|
||||
$DB->query($sql_rssfeeds);
|
||||
$DB->query($addone);
|
||||
|
||||
}
|
||||
if($DB->num_rows($is_exist_rsslogs_query) == 0){
|
||||
$sql_rsslogs = "
|
||||
CREATE TABLE `".DB_PREFIX."rsslogs` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`rssid` int(10) NOT NULL,
|
||||
`log` text NOT NULL,
|
||||
`hash` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)".$add;
|
||||
$DB->query($sql_rsslogs);
|
||||
}
|
||||
}
|
||||
|
||||
function callback_rm(){
|
||||
$DB = MySql::getInstance();
|
||||
$feeds = getRssFeeds();
|
||||
while ($item = $DB->fetch_array($feeds)) {
|
||||
deleteFeed($item['id']);
|
||||
}
|
||||
$DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."rssfeeds");
|
||||
$DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."rsslogs");
|
||||
}
|
||||
?>
|
||||
@@ -1,220 +1,246 @@
|
||||
<?php
|
||||
/*
|
||||
======================================================================
|
||||
lastRSS 0.9.1
|
||||
|
||||
Simple yet powerfull PHP class to parse RSS files.
|
||||
|
||||
by Vojtech Semecky, webmaster @ webdot . cz
|
||||
|
||||
Latest version, features, manual and examples:
|
||||
http://lastrss.webdot.cz/
|
||||
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
======================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* lastRSS
|
||||
* Simple yet powerfull PHP class to parse RSS files.
|
||||
*/
|
||||
class lastRSS {
|
||||
// -------------------------------------------------------------------
|
||||
// Public properties
|
||||
// -------------------------------------------------------------------
|
||||
var $default_cp = 'UTF-8';
|
||||
var $CDATA = 'nochange';
|
||||
var $cp = '';
|
||||
var $items_limit = 0;
|
||||
var $stripHTML = False;
|
||||
var $date_format = '';
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Private variables
|
||||
// -------------------------------------------------------------------
|
||||
var $channeltags = array ('title', 'link', 'description', 'language', 'copyright', 'managingEditor', 'webMaster', 'lastBuildDate', 'rating', 'docs');
|
||||
var $itemtags = array('title', 'link', 'description', 'author', 'category', 'comments', 'enclosure', 'guid', 'pubDate', 'source');
|
||||
var $imagetags = array('title', 'url', 'link', 'width', 'height');
|
||||
var $textinputtags = array('title', 'description', 'name', 'link');
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Parse RSS file and returns associative array.
|
||||
// -------------------------------------------------------------------
|
||||
function Get ($rss_url) {
|
||||
// If CACHE ENABLED
|
||||
if ($this->cache_dir != '') {
|
||||
$cache_file = $this->cache_dir . '/rsscache_' . md5($rss_url);
|
||||
$timedif = @(time() - filemtime($cache_file));
|
||||
if ($timedif < $this->cache_time) {
|
||||
// cached file is fresh enough, return cached array
|
||||
$result = unserialize(join('', file($cache_file)));
|
||||
// set 'cached' to 1 only if cached file is correct
|
||||
if ($result) $result['cached'] = 1;
|
||||
} else {
|
||||
// cached file is too old, create new
|
||||
$result = $this->Parse($rss_url);
|
||||
$serialized = serialize($result);
|
||||
if ($f = @fopen($cache_file, 'w')) {
|
||||
fwrite ($f, $serialized, strlen($serialized));
|
||||
fclose($f);
|
||||
}
|
||||
if ($result) $result['cached'] = 0;
|
||||
}
|
||||
}
|
||||
// If CACHE DISABLED >> load and parse the file directly
|
||||
else {
|
||||
$result = $this->Parse($rss_url);
|
||||
if ($result) $result['cached'] = 0;
|
||||
}
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Modification of preg_match(); return trimed field with index 1
|
||||
// from 'classic' preg_match() array output
|
||||
// -------------------------------------------------------------------
|
||||
function my_preg_match ($pattern, $subject) {
|
||||
// start regullar expression
|
||||
preg_match($pattern, $subject, $out);
|
||||
|
||||
// if there is some result... process it and return it
|
||||
if(isset($out[1])) {
|
||||
// Process CDATA (if present)
|
||||
if ($this->CDATA == 'content') { // Get CDATA content (without CDATA tag)
|
||||
$out[1] = strtr($out[1], array('<![CDATA['=>'', ']]>'=>''));
|
||||
} elseif ($this->CDATA == 'strip') { // Strip CDATA
|
||||
$out[1] = strtr($out[1], array('<![CDATA['=>'', ']]>'=>''));
|
||||
}
|
||||
|
||||
// If code page is set convert character encoding to required
|
||||
if ($this->cp != '')
|
||||
//$out[1] = $this->MyConvertEncoding($this->rsscp, $this->cp, $out[1]);
|
||||
$out[1] = iconv($this->rsscp, $this->cp.'//TRANSLIT', $out[1]);
|
||||
// Return result
|
||||
return trim($out[1]);
|
||||
} else {
|
||||
// if there is NO result, return empty string
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Replace HTML entities &something; by real characters
|
||||
// -------------------------------------------------------------------
|
||||
function unhtmlentities ($string) {
|
||||
// Get HTML entities table
|
||||
$trans_tbl = get_html_translation_table (HTML_ENTITIES, ENT_QUOTES);
|
||||
// Flip keys<==>values
|
||||
$trans_tbl = array_flip ($trans_tbl);
|
||||
// Add support for ' entity (missing in HTML_ENTITIES)
|
||||
$trans_tbl += array(''' => "'");
|
||||
// Replace entities by values
|
||||
return strtr ($string, $trans_tbl);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Parse() is private method used by Get() to load and parse RSS file.
|
||||
// Don't use Parse() in your scripts - use Get($rss_file) instead.
|
||||
// -------------------------------------------------------------------
|
||||
function Parse ($rss_url) {
|
||||
// Open and load RSS file
|
||||
if ($f = @fopen($rss_url, 'r')) {
|
||||
$rss_content = '';
|
||||
while (!feof($f)) {
|
||||
$rss_content .= fgets($f, 4096);
|
||||
}
|
||||
fclose($f);
|
||||
|
||||
// Parse document encoding
|
||||
$result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si", $rss_content);
|
||||
// if document codepage is specified, use it
|
||||
if ($result['encoding'] != '')
|
||||
{ $this->rsscp = $result['encoding']; } // This is used in my_preg_match()
|
||||
// otherwise use the default codepage
|
||||
else
|
||||
{ $this->rsscp = $this->default_cp; } // This is used in my_preg_match()
|
||||
|
||||
// Parse CHANNEL info
|
||||
preg_match("'<channel.*?>(.*?)</channel>'si", $rss_content, $out_channel);
|
||||
foreach($this->channeltags as $channeltag)
|
||||
{
|
||||
$temp = $this->my_preg_match("'<$channeltag.*?>(.*?)</$channeltag>'si", $out_channel[1]);
|
||||
if ($temp != '') $result[$channeltag] = $temp; // Set only if not empty
|
||||
}
|
||||
// If date_format is specified and lastBuildDate is valid
|
||||
if ($this->date_format != '' && ($timestamp = strtotime($result['lastBuildDate'])) !==-1) {
|
||||
// convert lastBuildDate to specified date format
|
||||
$result['lastBuildDate'] = date($this->date_format, $timestamp);
|
||||
}
|
||||
|
||||
// Parse TEXTINPUT info
|
||||
preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si", $rss_content, $out_textinfo);
|
||||
// This a little strange regexp means:
|
||||
// Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beggining tag)
|
||||
if (isset($out_textinfo[2])) {
|
||||
foreach($this->textinputtags as $textinputtag) {
|
||||
$temp = $this->my_preg_match("'<$textinputtag.*?>(.*?)</$textinputtag>'si", $out_textinfo[2]);
|
||||
if ($temp != '') $result['textinput_'.$textinputtag] = $temp; // Set only if not empty
|
||||
}
|
||||
}
|
||||
// Parse IMAGE info
|
||||
preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);
|
||||
if (isset($out_imageinfo[1])) {
|
||||
foreach($this->imagetags as $imagetag) {
|
||||
$temp = $this->my_preg_match("'<$imagetag.*?>(.*?)</$imagetag>'si", $out_imageinfo[1]);
|
||||
if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty
|
||||
}
|
||||
}
|
||||
// Parse ITEMS
|
||||
preg_match_all("'<item(| .*?)>(.*?)</item>'si", $rss_content, $items);
|
||||
$rss_items = $items[2];
|
||||
$i = 0;
|
||||
$result['items'] = array(); // create array even if there are no items
|
||||
foreach($rss_items as $rss_item) {
|
||||
// If number of items is lower then limit: Parse one item
|
||||
if ($i < $this->items_limit || $this->items_limit == 0) {
|
||||
foreach($this->itemtags as $itemtag) {
|
||||
$temp = $this->my_preg_match("'<$itemtag.*?>(.*?)</$itemtag>'si", $rss_item);
|
||||
if ($temp != '') $result['items'][$i][$itemtag] = $temp; // Set only if not empty
|
||||
}
|
||||
// Strip HTML tags and other bullshit from DESCRIPTION
|
||||
if ($this->stripHTML && $result['items'][$i]['description'])
|
||||
$result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));
|
||||
// Strip HTML tags and other bullshit from TITLE
|
||||
if ($this->stripHTML && $result['items'][$i]['title'])
|
||||
$result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));
|
||||
// If date_format is specified and pubDate is valid
|
||||
if ($this->date_format != '' && ($timestamp = strtotime($result['items'][$i]['pubDate'])) !==-1) {
|
||||
// convert pubDate to specified date format
|
||||
$result['items'][$i]['pubDate'] = date($this->date_format, $timestamp);
|
||||
}
|
||||
// Item counter
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$result['items_count'] = $i;
|
||||
return $result;
|
||||
}
|
||||
else // Error in opening return False
|
||||
{
|
||||
return False;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
/*
|
||||
======================================================================
|
||||
lastRSS 0.9.1
|
||||
|
||||
Simple yet powerfull PHP class to parse RSS files.
|
||||
|
||||
by Vojtech Semecky, webmaster @ webdot . cz
|
||||
|
||||
Latest version, features, manual and examples:
|
||||
http://lastrss.webdot.cz/
|
||||
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
======================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* lastRSS
|
||||
* Simple yet powerfull PHP class to parse RSS files.
|
||||
*/
|
||||
class lastRSS {
|
||||
// -------------------------------------------------------------------
|
||||
// Public properties
|
||||
// -------------------------------------------------------------------
|
||||
var $default_cp = 'UTF-8';
|
||||
var $CDATA = 'nochange';
|
||||
var $cp = '';
|
||||
var $items_limit = 0;
|
||||
var $stripHTML = False;
|
||||
var $date_format = '';
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Private variables
|
||||
// -------------------------------------------------------------------
|
||||
var $channeltags = array ('title', 'link', 'description', 'language', 'copyright', 'managingEditor', 'webMaster', 'lastBuildDate', 'rating', 'docs');
|
||||
var $itemtags = array('title', 'link', 'description', 'author', 'category', 'comments', 'enclosure', 'guid', 'pubDate', 'source');
|
||||
var $imagetags = array('title', 'url', 'link', 'width', 'height');
|
||||
var $textinputtags = array('title', 'description', 'name', 'link');
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Parse RSS file and returns associative array.
|
||||
// -------------------------------------------------------------------
|
||||
function Get ($rss_url) {
|
||||
// If CACHE ENABLED
|
||||
if ($this->cache_dir != '') {
|
||||
$cache_file = $this->cache_dir . '/rsscache_' . md5($rss_url);
|
||||
$timedif = @(time() - filemtime($cache_file));
|
||||
if ($timedif < $this->cache_time) {
|
||||
// cached file is fresh enough, return cached array
|
||||
$result = unserialize(join('', file($cache_file)));
|
||||
// set 'cached' to 1 only if cached file is correct
|
||||
if ($result) $result['cached'] = 1;
|
||||
} else {
|
||||
// cached file is too old, create new
|
||||
$result = $this->Parse($rss_url);
|
||||
$serialized = serialize($result);
|
||||
if ($f = @fopen($cache_file, 'w')) {
|
||||
fwrite ($f, $serialized, strlen($serialized));
|
||||
fclose($f);
|
||||
}
|
||||
if ($result) $result['cached'] = 0;
|
||||
}
|
||||
}
|
||||
// If CACHE DISABLED >> load and parse the file directly
|
||||
else {
|
||||
$result = $this->Parse($rss_url);
|
||||
if ($result) $result['cached'] = 0;
|
||||
}
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Modification of preg_match(); return trimed field with index 1
|
||||
// from 'classic' preg_match() array output
|
||||
// -------------------------------------------------------------------
|
||||
function my_preg_match ($pattern, $subject) {
|
||||
// start regullar expression
|
||||
preg_match($pattern, $subject, $out);
|
||||
|
||||
// if there is some result... process it and return it
|
||||
if(isset($out[1])) {
|
||||
// Process CDATA (if present)
|
||||
if ($this->CDATA == 'content') { // Get CDATA content (without CDATA tag)
|
||||
$out[1] = strtr($out[1], array('<![CDATA['=>'', ']]>'=>''));
|
||||
} elseif ($this->CDATA == 'strip') { // Strip CDATA
|
||||
$out[1] = strtr($out[1], array('<![CDATA['=>'', ']]>'=>''));
|
||||
}
|
||||
|
||||
// If code page is set convert character encoding to required
|
||||
if ($this->cp != '')
|
||||
//$out[1] = $this->MyConvertEncoding($this->rsscp, $this->cp, $out[1]);
|
||||
$out[1] = iconv($this->rsscp, $this->cp.'//TRANSLIT', $out[1]);
|
||||
// Return result
|
||||
return trim($out[1]);
|
||||
} else {
|
||||
// if there is NO result, return empty string
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Replace HTML entities &something; by real characters
|
||||
// -------------------------------------------------------------------
|
||||
function unhtmlentities ($string) {
|
||||
// Get HTML entities table
|
||||
$trans_tbl = get_html_translation_table (HTML_ENTITIES, ENT_QUOTES);
|
||||
// Flip keys<==>values
|
||||
$trans_tbl = array_flip ($trans_tbl);
|
||||
// Add support for ' entity (missing in HTML_ENTITIES)
|
||||
$trans_tbl += array(''' => "'");
|
||||
// Replace entities by values
|
||||
return strtr ($string, $trans_tbl);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Get remote file or open url
|
||||
// -------------------------------------------------------------------
|
||||
function getRemoteFile ($url){
|
||||
$results = '';
|
||||
$context = stream_context_create(array(
|
||||
'http' => array(
|
||||
'timeout' => 3
|
||||
)
|
||||
));
|
||||
if (get_cfg_var('allow_url_fopen')) {
|
||||
$f = fopen($url, 'r');
|
||||
while (!feof($f)) {
|
||||
$results .= fgets($f, 4096);
|
||||
}
|
||||
fclose($f);
|
||||
} else if (extension_loaded('curl')) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Curl/emlog Rss订阅插件');
|
||||
$results = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
} else {
|
||||
$results = file_get_contents($url, 0, $context);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Parse() is private method used by Get() to load and parse RSS file.
|
||||
// Don't use Parse() in your scripts - use Get($rss_file) instead.
|
||||
// -------------------------------------------------------------------
|
||||
function Parse ($rss_url) {
|
||||
// Open and load RSS file
|
||||
$rss_content = $this->getRemoteFile($rss_url);
|
||||
if (!empty($rss_content)) {
|
||||
|
||||
// Parse document encoding
|
||||
$result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si", $rss_content);
|
||||
// if document codepage is specified, use it
|
||||
if ($result['encoding'] != '')
|
||||
{ $this->rsscp = $result['encoding']; } // This is used in my_preg_match()
|
||||
// otherwise use the default codepage
|
||||
else
|
||||
{ $this->rsscp = $this->default_cp; } // This is used in my_preg_match()
|
||||
|
||||
// Parse CHANNEL info
|
||||
preg_match("'<channel.*?>(.*?)</channel>'si", $rss_content, $out_channel);
|
||||
foreach($this->channeltags as $channeltag)
|
||||
{
|
||||
$temp = $this->my_preg_match("'<$channeltag.*?>(.*?)</$channeltag>'si", $out_channel[1]);
|
||||
if ($temp != '') $result[$channeltag] = $temp; // Set only if not empty
|
||||
}
|
||||
// If date_format is specified and lastBuildDate is valid
|
||||
if ($this->date_format != '' && ($timestamp = strtotime($result['lastBuildDate'])) !==-1) {
|
||||
// convert lastBuildDate to specified date format
|
||||
$result['lastBuildDate'] = date($this->date_format, $timestamp);
|
||||
}
|
||||
|
||||
// Parse TEXTINPUT info
|
||||
preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si", $rss_content, $out_textinfo);
|
||||
// This a little strange regexp means:
|
||||
// Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beggining tag)
|
||||
if (isset($out_textinfo[2])) {
|
||||
foreach($this->textinputtags as $textinputtag) {
|
||||
$temp = $this->my_preg_match("'<$textinputtag.*?>(.*?)</$textinputtag>'si", $out_textinfo[2]);
|
||||
if ($temp != '') $result['textinput_'.$textinputtag] = $temp; // Set only if not empty
|
||||
}
|
||||
}
|
||||
// Parse IMAGE info
|
||||
preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);
|
||||
if (isset($out_imageinfo[1])) {
|
||||
foreach($this->imagetags as $imagetag) {
|
||||
$temp = $this->my_preg_match("'<$imagetag.*?>(.*?)</$imagetag>'si", $out_imageinfo[1]);
|
||||
if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty
|
||||
}
|
||||
}
|
||||
// Parse ITEMS
|
||||
preg_match_all("'<item(| .*?)>(.*?)</item>'si", $rss_content, $items);
|
||||
$rss_items = $items[2];
|
||||
$i = 0;
|
||||
$result['items'] = array(); // create array even if there are no items
|
||||
foreach($rss_items as $rss_item) {
|
||||
// If number of items is lower then limit: Parse one item
|
||||
if ($i < $this->items_limit || $this->items_limit == 0) {
|
||||
foreach($this->itemtags as $itemtag) {
|
||||
$temp = $this->my_preg_match("'<$itemtag.*?>(.*?)</$itemtag>'si", $rss_item);
|
||||
if ($temp != '') $result['items'][$i][$itemtag] = $temp; // Set only if not empty
|
||||
}
|
||||
// Strip HTML tags and other bullshit from DESCRIPTION
|
||||
if ($this->stripHTML && $result['items'][$i]['description'])
|
||||
$result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));
|
||||
// Strip HTML tags and other bullshit from TITLE
|
||||
if ($this->stripHTML && $result['items'][$i]['title'])
|
||||
$result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));
|
||||
// If date_format is specified and pubDate is valid
|
||||
if ($this->date_format != '' && ($timestamp = strtotime($result['items'][$i]['pubDate'])) !==-1) {
|
||||
// convert pubDate to specified date format
|
||||
$result['items'][$i]['pubDate'] = date($this->date_format, $timestamp);
|
||||
}
|
||||
// Item counter
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$result['items_count'] = $i;
|
||||
return $result;
|
||||
}
|
||||
else // Error in opening return False
|
||||
{
|
||||
return False;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -61,6 +61,66 @@ function plugin_setting_view(){
|
||||
endif;
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
function plugin_setting(){
|
||||
$do = isset($_GET['do']) ? addslashes($_GET['do']) : '';
|
||||
if ($do == 'del') {
|
||||
$id = intval($_GET['id']);
|
||||
if ($id != 0) {
|
||||
deleteFeed($id);
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
}
|
||||
} elseif ($do == 'update') {
|
||||
$id = intval($_POST['id']);
|
||||
$url = isset($_POST['url']) ? trim($_POST['url']) : '';
|
||||
if (!empty($url)) {
|
||||
$title = (isset($_POST['title']) && trim($_POST['title']) !='') ? $_POST['title'] : getTitle($url);
|
||||
$title = addslashes($title);
|
||||
if (!empty($title)) {
|
||||
updateFeed($id, $url, $title);
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
} else {
|
||||
emMsg("RSS修改失败,插件无法获取{$url}的标题,请自行添加标题再添加该RSS");
|
||||
}
|
||||
} else {
|
||||
emMsg("RSS修改失败,RSS地址不能为空");
|
||||
}
|
||||
} elseif ($do == 'add') {
|
||||
$url = isset($_POST['url']) ? trim($_POST['url']) : '';
|
||||
if (!empty($url)) {
|
||||
$title = (isset($_POST['title']) && trim($_POST['title']) !='') ? $_POST['title'] : getTitle($url);
|
||||
$title = addslashes($title);
|
||||
if (!empty($title)) {
|
||||
insertFeed($url, $title);
|
||||
updateLogs();
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
} else {
|
||||
emMsg("RSS导入失败,插件无法获取{$url}的标题,请自行添加标题再导入该RSS");
|
||||
}
|
||||
} else {
|
||||
emMsg("RSS导入失败,RSS地址不能为空");
|
||||
}
|
||||
} elseif ($do == 'config') {
|
||||
$lastRSS_cache_time = isset($_POST['lastRSS_cache_time']) ? intval($_POST['lastRSS_cache_time']) : 0;
|
||||
$lastRSS_item_num = isset($_POST['lastRSS_item_num']) ? intval($_POST['lastRSS_item_num']) : 2;
|
||||
$lastRSS_is_urlshort = isset($_POST['lastRSS_is_urlshort']) ? intval($_POST['lastRSS_is_urlshort']) : 0;
|
||||
$lastRSS_urlshort_domain = isset($_POST['lastRSS_urlshort_domain']) ? trim($_POST['lastRSS_urlshort_domain']) : 't.cn';
|
||||
$lastRSS_is_blank = isset($_POST['lastRSS_is_blank']) ? intval($_POST['lastRSS_is_blank']) : 0;
|
||||
$data = "<?php
|
||||
\$lastRSS_cache_time = ".$lastRSS_cache_time.";
|
||||
\$lastRSS_item_num = ".$lastRSS_item_num.";
|
||||
\$lastRSS_is_urlshort = ".$lastRSS_is_urlshort.";
|
||||
\$lastRSS_urlshort_domain = '".$lastRSS_urlshort_domain."';
|
||||
\$lastRSS_is_blank = ".$lastRSS_is_blank.";
|
||||
?>";
|
||||
$file = EMLOG_ROOT.'/content/plugins/lastRSS/lastRSS_config.php';
|
||||
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/lastRSS/lastRSS_config.php的权限为777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/lastRSS/lastRSS_config.php的权限为777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||
fclose($fp);
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ol>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
@@ -88,61 +148,3 @@ function plugin_setting_view(){
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<?php
|
||||
$do = isset($_GET['do']) ? addslashes($_GET['do']) : '';
|
||||
if ($do == 'del') {
|
||||
$id = intval($_GET['id']);
|
||||
if ($id != 0) {
|
||||
deleteFeed($id);
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
}
|
||||
} elseif ($do == 'update') {
|
||||
$id = intval($_POST['id']);
|
||||
$url = isset($_POST['url']) ? trim($_POST['url']) : '';
|
||||
if (!empty($url)) {
|
||||
$title = (isset($_POST['title']) && trim($_POST['title']) !='') ? $_POST['title'] : getTitle($url);
|
||||
$title = addslashes($title);
|
||||
if (!empty($title)) {
|
||||
updateFeed($id, $url, $title);
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
} else {
|
||||
emMsg("RSS修改失败,插件无法获取{$url}的标题,请自行添加标题再添加该RSS");
|
||||
}
|
||||
} else {
|
||||
emMsg("RSS修改失败,RSS地址不能为空");
|
||||
}
|
||||
} elseif ($do == 'add') {
|
||||
$url = isset($_POST['url']) ? trim($_POST['url']) : '';
|
||||
if (!empty($url)) {
|
||||
$title = (isset($_POST['title']) && trim($_POST['title']) !='') ? $_POST['title'] : getTitle($url);
|
||||
$title = addslashes($title);
|
||||
if (!empty($title)) {
|
||||
insertFeed($url, $title);
|
||||
updateLogs();
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
} else {
|
||||
emMsg("RSS导入失败,插件无法获取{$url}的标题,请自行添加标题再导入该RSS");
|
||||
}
|
||||
} else {
|
||||
emMsg("RSS导入失败,RSS地址不能为空");
|
||||
}
|
||||
} elseif ($do == 'config') {
|
||||
$lastRSS_cache_time = isset($_POST['lastRSS_cache_time']) ? intval($_POST['lastRSS_cache_time']) : 0;
|
||||
$lastRSS_item_num = isset($_POST['lastRSS_item_num']) ? intval($_POST['lastRSS_item_num']) : 2;
|
||||
$lastRSS_is_urlshort = isset($_POST['lastRSS_is_urlshort']) ? intval($_POST['lastRSS_is_urlshort']) : 0;
|
||||
$lastRSS_urlshort_domain = isset($_POST['lastRSS_urlshort_domain']) ? trim($_POST['lastRSS_urlshort_domain']) : 't.cn';
|
||||
$lastRSS_is_blank = isset($_POST['lastRSS_is_blank']) ? intval($_POST['lastRSS_is_blank']) : 0;
|
||||
$data = "<?php
|
||||
\$lastRSS_cache_time = ".$lastRSS_cache_time.";
|
||||
\$lastRSS_item_num = ".$lastRSS_item_num.";
|
||||
\$lastRSS_is_urlshort = ".$lastRSS_is_urlshort.";
|
||||
\$lastRSS_urlshort_domain = '".$lastRSS_urlshort_domain."';
|
||||
\$lastRSS_is_blank = ".$lastRSS_is_blank.";
|
||||
?>";
|
||||
$file = EMLOG_ROOT.'/content/plugins/lastRSS/lastRSS_config.php';
|
||||
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/lastRSS/lastRSS_config.php的权限为777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/lastRSS/lastRSS_config.php的权限为777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||
fclose($fp);
|
||||
header("Location:plugin.php?plugin=lastRSS&setting=true");
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user