1.3版
This commit is contained in:
22
.gitattributes
vendored
Normal file
22
.gitattributes
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
163
.gitignore
vendored
Normal file
163
.gitignore
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.project
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.classpath
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.vspscc
|
||||
.builds
|
||||
*.dotCover
|
||||
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
||||
#packages/
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish
|
||||
|
||||
# Others
|
||||
[Bb]in
|
||||
[Oo]bj
|
||||
sql
|
||||
TestResults
|
||||
*.Cache
|
||||
ClientBin
|
||||
stylecop.*
|
||||
~$*
|
||||
*.dbmdl
|
||||
Generated_Code #added for RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
|
||||
|
||||
|
||||
############
|
||||
## Windows
|
||||
############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[co]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
1
css/lastRSS.css
Normal file
1
css/lastRSS.css
Normal file
@@ -0,0 +1 @@
|
||||
.lastRSS_loding{background:url(loading.gif) no-repeat center center}#lastRSS{padding:1px 5px;height:25px;line-height:25px;overflow:hidden}#lastRSS ul{padding:0;margin:0}#lastRSS ul li{overflow:hidden;height:25px}
|
||||
BIN
css/loading.gif
Normal file
BIN
css/loading.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
1
js/jquery-autoscroll.js
vendored
Normal file
1
js/jquery-autoscroll.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
;(function(e){e.fn.extend({autoScroll:function(t){function s(){var t=r.find("ul:first"),n=t.find("li:first");if(i.type==="H"){var s=-n.outerWidth(!0)+"px";t.animate({marginLeft:s},800,function(){e(this).css({marginLeft:"0px"}).find("li:first").appendTo(this)})}else{var o=-n.outerHeight(!0)+"px";t.animate({marginTop:o},800,function(){e(this).css({marginTop:"0px"}).find("li:first").appendTo(this)})}}var n=null,r=this,i={type:"V",timer:5e3};return t=t||{},e.extend(i,t),n=setInterval(s,i.timer),r.each(function(){e(this).hover(function(){clearInterval(n)},function(){n=setInterval(s,i.timer)})})}})})(jQuery)
|
||||
166
lastRSS.php
Normal file
166
lastRSS.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Rss订阅
|
||||
Version: 1.3
|
||||
Plugin URL: http://xiaosong.org/tech/the-official-releas-of-rss-subscribe-plugin
|
||||
Description: 订阅朋友的博客feed,显示在自己博客~
|
||||
Author: 小松
|
||||
Author Email: sahala_2007@126.com
|
||||
Author URL: http://xiaosong.org/
|
||||
*/
|
||||
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||
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->items_limit = $lastRSS_item_num > 3 ? 3 : $lastRSS_item_num;
|
||||
$rssparser->CDATA = 'content';
|
||||
$rssparser->cp = 'UTF-8';
|
||||
$rssparser->channeltags = array ('title');
|
||||
$rssparser->itemtags = array ('title','link');
|
||||
$rssparser->imagetags = array ();
|
||||
$rssparser->textinputtags = array ();
|
||||
$DB = MySql::getInstance();
|
||||
|
||||
function urlShort($url){
|
||||
global $lastRSS_urlshort_domain;
|
||||
if (!extension_loaded('curl')) {
|
||||
return $url;
|
||||
} else {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://json.so/api/short.htm?d='.$lastRSS_urlshort_domain.'&u='.$url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Curl/xiaosong.org 1.0 BETA');
|
||||
$results = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$results = json_decode($results, true);
|
||||
if(isset($results['state']) && $results['state'] == 'success'){
|
||||
return $results['msg'];
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
function getRssFeeds(){
|
||||
global $DB;
|
||||
$sql = "SELECT * FROM ".DB_PREFIX."rssfeeds ORDER BY id ASC";
|
||||
$result = $DB->query($sql);
|
||||
return $result;
|
||||
}
|
||||
function isLogExists($rssid, $hash){
|
||||
global $DB;
|
||||
$sql = "SELECT id FROM ".DB_PREFIX."rsslogs WHERE rssid = $rssid AND hash = '$hash'";
|
||||
$result = $DB->query($sql);
|
||||
$rows = $DB->num_rows($result);
|
||||
return $rows;
|
||||
}
|
||||
function isFeedExists($url){
|
||||
global $DB;
|
||||
$sql = "SELECT id FROM ".DB_PREFIX."rssfeeds WHERE url = '$url'";
|
||||
$result = $DB->query($sql);
|
||||
$rows = $DB->num_rows($result);
|
||||
return $rows;
|
||||
}
|
||||
function insertLog($rssid, $log ,$hash){
|
||||
global $DB;
|
||||
if (isLogExists($rssid, $hash) == 0) {
|
||||
$DB->query("INSERT INTO ".DB_PREFIX."rsslogs (rssid, log, hash) VALUES($rssid, '$log', '$hash')");
|
||||
}
|
||||
}
|
||||
function insertFeed($url, $title){
|
||||
global $DB;
|
||||
if (isFeedExists($url) == 0) {
|
||||
$DB->query("INSERT INTO ".DB_PREFIX."rssfeeds (url, title) VALUES('$url', '$title')");
|
||||
} elseif (!getTitle($url)) {
|
||||
formMsg("RSS导入失败,RSS地址{$url}解析失败,请确定RSS地址及XML文件格式正确",'./plugin.php?plugin=lastRSS',0);
|
||||
} else {
|
||||
formMsg("RSS导入失败,数据库中已存在{$url}",'./plugin.php?plugin=lastRSS',0);
|
||||
}
|
||||
}
|
||||
function deleteFeed($id){
|
||||
global $DB;
|
||||
$rssurl = $DB->fetch_array($DB->query("SELECT url FROM ".DB_PREFIX."rssfeeds WHERE id = $id"));
|
||||
$rssurl = $rssurl['url'];
|
||||
$cache_file = EMLOG_ROOT.'/content/cache/rsscache_'.md5($rssurl);
|
||||
$DB->query("DELETE FROM ".DB_PREFIX."rssfeeds WHERE id = $id");
|
||||
$DB->query("DELETE FROM ".DB_PREFIX."rsslogs WHERE rssid = $id");
|
||||
@unlink($cache_file);
|
||||
}
|
||||
function updateFeed($id, $url, $title){
|
||||
global $DB;
|
||||
$DB->query("UPDATE ".DB_PREFIX."rssfeeds SET url = '$url', title = '$title' WHERE id = $id");
|
||||
}
|
||||
function getTitle($rss_url){
|
||||
global $rssparser;
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function displayLog(){
|
||||
global $DB, $lastRSS_item_num;
|
||||
$sql = "SELECT rssid,log FROM ".DB_PREFIX."rsslogs ORDER BY id DESC limit $lastRSS_item_num";
|
||||
$result = $DB->query($sql);
|
||||
$output = '';
|
||||
while ($row = $DB->fetch_array($result)) {
|
||||
$rssid = $row['rssid'];
|
||||
$log = $row['log'];
|
||||
$_sql = "SELECT title FROM ".DB_PREFIX."rssfeeds WHERE id = $rssid";
|
||||
$title = $DB->fetch_array($DB->query($_sql));
|
||||
$output .= '<li>'.$log.' 来自 《'.$title["title"].'》</li>';
|
||||
}
|
||||
$output = empty($output) ? '<li>暂无Rss文章 ^_^' : $output;
|
||||
$output = '<ul class="rsslogs">'.$output.'</ul>';
|
||||
return $output;
|
||||
}
|
||||
function displayLogIndex(){
|
||||
echo '<div id="lastRSS" class="lastRSS_loding"></div>';
|
||||
}
|
||||
function lastRSS_css(){
|
||||
echo '<link rel="stylesheet" href="'.BLOG_URL.'content/plugins/lastRSS/css/lastRSS.css" />'."\n";
|
||||
}
|
||||
function lastRSS_ajax(){
|
||||
emLoadJQuery();
|
||||
echo '<script type="text/javascript" src="'.BLOG_URL.'content/plugins/lastRSS/js/jquery-autoscroll.js"></script>'."\n";
|
||||
echo '<script type="text/javascript">$(function(){$.get("'.BLOG_URL.'index.php?plugin=lastRSS&action=update&r="+Math.random());$("#lastRSS").load("'.BLOG_URL.'indx.php?plugin=lastRSS&action=ajaxshow&r="+Math.random(),function(){$(this).removeClass("lastRSS_loding").autoScroll()})})</script>'."\n";
|
||||
}
|
||||
function lastRSS_adminUpdate(){
|
||||
echo '<script type="text/javascript">$(function(){$.get("'.BLOG_URL.'index.php?plugin=lastRSS&action=update&r="+Math.random());})</script>'."\n";
|
||||
}
|
||||
function lastRSS_menu(){
|
||||
echo '<div class="sidebarsubmenu" id="lastRSS"><a href="./plugin.php?plugin=lastRSS">Rss订阅</a></div>';
|
||||
}
|
||||
function lastRSS_backup(){
|
||||
global $DB, $tables;
|
||||
$is_exist_rssfeeds_query = $DB->query('show tables like "'.DB_PREFIX.'rssfeeds"');
|
||||
$is_exist_rsslogs_query = $DB->query('show tables like "'.DB_PREFIX.'rsslogs"');
|
||||
if($DB->num_rows($is_exist_rssfeeds_query) != 0) array_push($tables, 'rssfeeds');
|
||||
if($DB->num_rows($is_exist_rsslogs_query) != 0) array_push($tables, 'rsslogs');
|
||||
}
|
||||
addAction('data_prebakup', 'lastRSS_backup');
|
||||
addAction('index_head', 'lastRSS_css');
|
||||
addAction('index_loglist_top', 'displayLogIndex');
|
||||
addAction('index_footer', 'lastRSS_ajax');
|
||||
addAction('adm_head', 'lastRSS_adminUpdate');
|
||||
addAction('adm_sidebar_ext', 'lastRSS_menu');
|
||||
?>
|
||||
44
lastRSS_callback.php
Normal file
44
lastRSS_callback.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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");
|
||||
}
|
||||
?>
|
||||
220
lastRSS_class.php
Normal file
220
lastRSS_class.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
7
lastRSS_config.php
Normal file
7
lastRSS_config.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$lastRSS_cache_time = 3600;
|
||||
$lastRSS_item_num = 5;
|
||||
$lastRSS_is_urlshort = 0;
|
||||
$lastRSS_urlshort_domain = 't.cn';
|
||||
$lastRSS_is_blank = 1;
|
||||
?>
|
||||
148
lastRSS_setting.php
Normal file
148
lastRSS_setting.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||
$DB = MySql::getInstance();
|
||||
require_once(EMLOG_ROOT.'/content/plugins/lastRSS/lastRSS_config.php');
|
||||
function plugin_setting_view(){
|
||||
global $DB, $lastRSS_cache_time, $lastRSS_item_num, $lastRSS_is_urlshort, $lastRSS_is_blank, $lastRSS_urlshort_domain;
|
||||
?>
|
||||
<style type="text/css">
|
||||
#lastRSS_form_config p, #lastRSS_form_input p, #lastRSS_form_modify p {font-size:14px;}
|
||||
ol {margin:0;padding:0;}
|
||||
.entry {overflow:hidden;zoom:1;list-style: decimal inside none;font-size:14px;padding:8px;background:#DFE1E3;border-top:1px solid #E9EAEB;border-bottom:1px solid #C7CCD1;}
|
||||
.right {float:right;display:inline;}
|
||||
#lastRSS_form_modify {display:none;}
|
||||
</style>
|
||||
<div class="containertitle"><b>Rss订阅 参数设置</b>
|
||||
<?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<form action="?plugin=lastRSS&action=setting&do=config" method="post" id="lastRSS_form_config">
|
||||
<p>缓存时间:<input type="text" name="lastRSS_cache_time" value="<?php echo $lastRSS_cache_time; ?>" size="20" /> 单位为秒,留空或“0”表示不缓存,推荐设置大于“1200”</p>
|
||||
<p>显示条数:<input type="text" name="lastRSS_item_num" value="<?php echo $lastRSS_item_num; ?>" size="20" /> 前台轮播显示的条数,推荐大于“1”</p>
|
||||
<p><input type="checkbox" value="1" name="lastRSS_is_urlshort"<?php if($lastRSS_is_urlshort == 1):?> checked<?php endif;?> /> 使用网址缩短服务来缩短RSS日志的链接(已存入数据库的链接不变),需服务器开启curl,开启会增加程序运行时间</p>
|
||||
<p><label for="lastRSS_urlshort_domain">短网址服务商:</label>
|
||||
<select name="lastRSS_urlshort_domain" id="lastRSS_urlshort_domain">
|
||||
<option value="t.cn"<?php if($lastRSS_urlshort_domain == 't.cn'):?> selected<?php endif;?>>t.cn</option>
|
||||
<option value="bit.ly"<?php if($lastRSS_urlshort_domain == 'bit.ly'):?> selected<?php endif;?>>bit.ly</option>
|
||||
<option value="j.mp"<?php if($lastRSS_urlshort_domain == 'j.mp'):?> selected<?php endif;?>>j.mp</option>
|
||||
<option value="goo.gl"<?php if($lastRSS_urlshort_domain == 'goo.gl'):?> selected<?php endif;?>>goo.gl</option>
|
||||
</select>
|
||||
</p>
|
||||
<p><input type="checkbox" value="1" name="lastRSS_is_blank"<?php if($lastRSS_is_blank == 1):?> checked<?php endif;?> /> 新窗口打开前台显示的RSS日志链接 <input type="submit" value="保存参数" class="submit" /></p>
|
||||
</form>
|
||||
<div class="containertitle"><b>RSS 导入</b></div>
|
||||
<div class="line"></div>
|
||||
<form action="?plugin=lastRSS&action=setting&do=add" method="post" id="lastRSS_form_input">
|
||||
<p>RSS URL: <input type="text" name="url" style="width: 270px;" /> 标题(不填则插件自动获取): <input type="text" name="title" style="width: 200px;" /> <input type="submit" value="添加 RSS" class="submit" /></p>
|
||||
</form>
|
||||
<?php
|
||||
$feeds = getRssFeeds();
|
||||
if ($DB->num_rows($feeds) != 0):
|
||||
?>
|
||||
<div class="containertitle"><b>管理:(双击单行可对应修改该RSS的URL和标题)</b></div>
|
||||
<div class="line"></div>
|
||||
<form action="?plugin=lastRSS&action=setting&do=update" method="post" id="lastRSS_form_modify">
|
||||
<p>RSS URL: <input type="text" name="url" id="modify_url" style="width: 270px;" /> 标题: <input type="text" name="title" id="modify_title" style="width: 200px;" /> <input type="hidden" name="id" id="modify_id" /> <input type="submit" value="更新 RSS" class="submit" /> <input type="submit" id="cancel_update" value="取消更新" /></p>
|
||||
</form>
|
||||
<ol>
|
||||
<?php
|
||||
while ($item = $DB->fetch_array($feeds)) {
|
||||
?>
|
||||
<li class="entry">
|
||||
<span class="right" id="data-id" data="<?php echo $item['id']; ?>"><a href="?plugin=lastRSS&do=del&id=<?php echo $item['id']; ?>" onclick="javascript:if (!confirm('确认删除这个 RSS 数据源?')) { return false }">删除</a></span>
|
||||
《<span id="data-title" data="<?php echo $item['title']; ?>"><?php echo $item['title']; ?></span>》 URL:<span style="color:#666; font-size: 12px;" id="data-url" data="<?php echo $item['url']; ?>"><?php echo $item['url']; ?></span>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
else:
|
||||
?>
|
||||
<div class="containertitle"><b>暂无RSS地址,请导入</b></div>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
?>
|
||||
</ol>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $("html") : $("body")) : $("html,body");
|
||||
$("#lastRSS").addClass('sidebarsubmenu1');
|
||||
$(".entry").dblclick(function(){
|
||||
var feedUrl = $(this).children("#data-url").attr("data"),
|
||||
feedId = $(this).children("#data-id").attr("data"),
|
||||
feedTitle = $(this).children("#data-title").attr("data");
|
||||
$("#modify_url").val(feedUrl);
|
||||
$("#modify_title").val(feedTitle);
|
||||
$("#modify_id").val(feedId);
|
||||
$("#lastRSS_form_modify").slideDown(400,function(){
|
||||
$body.animate({
|
||||
scrollTop: $(this).offset().top - 40
|
||||
}, 500);
|
||||
$("#modify_url").focus();
|
||||
});
|
||||
});
|
||||
$("#cancel_update").click(function(){
|
||||
$("#lastRSS_form_modify").slideUp(200,function(){
|
||||
$("#modify_url").blur();
|
||||
});
|
||||
return false;
|
||||
})
|
||||
})
|
||||
</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 {
|
||||
formMsg("RSS修改失败,插件无法获取{$url}的标题,请自行添加标题再添加该RSS",'./plugin.php?plugin=lastRSS',0);
|
||||
}
|
||||
} else {
|
||||
formMsg("RSS修改失败,RSS地址不能为空",'./plugin.php?plugin=lastRSS',0);
|
||||
}
|
||||
} 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 {
|
||||
formMsg("RSS导入失败,插件无法获取{$url}的标题,请自行添加标题再导入该RSS",'./plugin.php?plugin=lastRSS',0);
|
||||
}
|
||||
} else {
|
||||
formMsg("RSS导入失败,RSS地址不能为空",'./plugin.php?plugin=lastRSS',0);
|
||||
}
|
||||
} 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");
|
||||
}
|
||||
?>
|
||||
13
lastRSS_show.php
Normal file
13
lastRSS_show.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
if ($action == 'update') {
|
||||
updateLogs();
|
||||
exit;
|
||||
} elseif ($action == 'ajaxshow') {
|
||||
header('Content-type: application/x-javascript');
|
||||
echo displayLog();
|
||||
exit;
|
||||
}
|
||||
echo 'access deined!';
|
||||
?>
|
||||
Reference in New Issue
Block a user