增加对空间支持的判断,获取feed方法更强大
This commit is contained in:
29
lastRSS.php
29
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: 小松
|
||||
@@ -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,5 +1,6 @@
|
||||
<?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"');
|
||||
|
||||
@@ -126,18 +126,44 @@ class lastRSS {
|
||||
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
|
||||
if ($f = @fopen($rss_url, 'r')) {
|
||||
$rss_content = '';
|
||||
while (!feof($f)) {
|
||||
$rss_content .= fgets($f, 4096);
|
||||
}
|
||||
fclose($f);
|
||||
$rss_content = $this->getRemoteFile($rss_url);
|
||||
if (!empty($rss_content)) {
|
||||
|
||||
// Parse document encoding
|
||||
$result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si", $rss_content);
|
||||
|
||||
@@ -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