增加对空间支持的判断,获取feed方法更强大

This commit is contained in:
2012-10-18 13:51:08 +08:00
parent 510e6adcc6
commit 5849e9cdd0
4 changed files with 365 additions and 335 deletions

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
Plugin Name: Rss订阅 Plugin Name: Rss订阅
Version: 1.3.2 Version: 1.3.3
Plugin URL: http://xiaosong.org/tech/the-official-releas-of-rss-subscribe-plugin Plugin URL: http://xiaosong.org/tech/the-official-releas-of-rss-subscribe-plugin
Description: 订阅朋友的博客feed显示在自己博客~ Description: 订阅朋友的博客feed显示在自己博客~
Author: 小松 Author: 小松
@@ -93,15 +93,15 @@ function updateFeed($id, $url, $title){
} }
function getTitle($rss_url){ function getTitle($rss_url){
global $rssparser; global $rssparser;
$rss = $rssparser->get($rss_url); $rss = $rssparser->Get($rss_url);
return $rss['title']; return $rss['title'];
} }
function updateLogs(){ function updateLogs(){
global $rssparser, $DB, $lastRSS_is_urlshort, $lastRSS_is_blank; global $rssparser, $DB, $lastRSS_is_urlshort, $lastRSS_is_blank;
$feeds = getRssFeeds(); $feeds = getRssFeeds();
while ($item = $DB->fetch_array($feeds)) { while ($item = $DB->fetch_array($feeds)) {
$rss = $rssparser->get($item['url']); $rss = $rssparser->Get($item['url']);
if(!empty($rss['items'])) if(!empty($rss['items'])) {
foreach ($rss['items'] as $key => $data) { foreach ($rss['items'] as $key => $data) {
$rssid = $item['id']; $rssid = $item['id'];
$hash = md5($data['title']); $hash = md5($data['title']);
@@ -116,6 +116,7 @@ function updateLogs(){
} }
} }
} }
}
} }
function displayLog(){ function displayLog(){
global $DB, $lastRSS_item_num; global $DB, $lastRSS_item_num;

View File

@@ -1,5 +1,6 @@
<?php <?php
function callback_init(){ 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(); $DB = MySql::getInstance();
$is_exist_rssfeeds_query = $DB->query('show tables like "'.DB_PREFIX.'rssfeeds"'); $is_exist_rssfeeds_query = $DB->query('show tables like "'.DB_PREFIX.'rssfeeds"');
$is_exist_rsslogs_query = $DB->query('show tables like "'.DB_PREFIX.'rsslogs"'); $is_exist_rsslogs_query = $DB->query('show tables like "'.DB_PREFIX.'rsslogs"');

View File

@@ -126,18 +126,44 @@ class lastRSS {
return strtr ($string, $trans_tbl); 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. // 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. // Don't use Parse() in your scripts - use Get($rss_file) instead.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function Parse ($rss_url) { function Parse ($rss_url) {
// Open and load RSS file // Open and load RSS file
if ($f = @fopen($rss_url, 'r')) { $rss_content = $this->getRemoteFile($rss_url);
$rss_content = ''; if (!empty($rss_content)) {
while (!feof($f)) {
$rss_content .= fgets($f, 4096);
}
fclose($f);
// Parse document encoding // Parse document encoding
$result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si", $rss_content); $result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si", $rss_content);

View File

@@ -61,6 +61,66 @@ function plugin_setting_view(){
endif; 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> </ol>
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function(){
@@ -88,61 +148,3 @@ function plugin_setting_view(){
}) })
}) })
</script> </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");
}
?>