📄 future-rss.php
字号:
<?php
//
// future-rss.php Delayed RSS Item Publisher
// Version 1.0.1
//
// Copyright 2005,2006 NotePage, Inc. all rights reserved
// http://www.feedforall.com
// NotePage, Inc. grants registerd users of our FeedForAll and/or
// FeedForAll Mac product(s) the right to install and use the
// future-rss.php script free of charge. Please refer to the EULA
// included in the download for full license terms and conditions.
//
#-------------------------------------------
# Script setup area
#-------------------------------------------
# $cfg["rss_feed"]='http://www.mydomain.com/myfeed.xml';
$cfg["rss_feed"]='myfeed.xml';
$cfg['fetch_method'] = "fopen"; // fopen, curl
$cfg['url_override'] = true; // Warning! security unsafe!
// use "url" parameter to pass RSS feed to script
// example: http://localhost/rss_proxy.php?url=<url>
$cfg["filter_method"] = "time"; // time - display item if ITEM_TIME <= CURRENT_TIME // date - display item if ITEM_TIME <= endOfDay(CURRENT_TIME)
#-------------------------------------------
# Script
# plz, do not change anything below this line
#-------------------------------------------
# override RSS feed location from URL param
if ($cfg['url_override'] && $_REQUEST["url"] ) $cfg["rss_feed"] = $_REQUEST["url"];
# fetch
$rss = rss_fetch();
# check
if (!rss_isValid($rss)) rss_error("Not a valid RSS feed");
# filter
$rss = rss_filter($rss);
# output
Header("Content-Type: text/xml");
echo $rss;
exit;
function rss_fetch() {
global $cfg;
// DO NOT allow use file:// if (substr($cfg["rss_feed"],0, 7) == 'file://') { if (!$result) rss_error("file:// not allowed");
} // fallback to fopen if NOT remote file if (substr($cfg["rss_feed"],0, 4) != 'http') { $cfg["fetch_method"] = 'fopen'; // security check: file must be in current path or lower
$root = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
$feed_path = dirname(realpath($_SERVER["DOCUMENT_ROOT"]."/".$cfg ["rss_feed"]));
if (substr_count($feed_path, $root) != 1) {
if (file_exists($_SERVER["DOCUMENT_ROOT"]."/".$cfg["rss_feed"]))
rss_error("Security violation");
else
rss_error("Feed not found");
}
} if ($cfg["fetch_method"] == 'fopen') {
$result = @file($cfg["rss_feed"]);
if (!$result) rss_error("Could not open RSS feed at ".$cfg["rss_feed"]);
return join("",$result);
}
if ($cfg["fetch_method"] == 'curl') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $cfg["rss_feed"]);
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$result = ob_get_contents(); ob_end_clean();
if (curl_errno($ch)) { rss_error("CURL Error: ".curl_error($ch)); }
curl_close($ch);
return $result;
}
}
function rss_isValid($rss) {
if (substr_count($rss,"<rss") ==0) return false;
if (substr_count($rss,"<?xml") ==0) return false;
if (substr_count($rss,"<channel") ==0) return false;
if (substr_count($rss,"<title") ==0) return false;
return true;
}
/*
Filter rss items
*/
function rss_filter($rss) {
function make_seed(){list($usec, $sec) = explode(' ', microtime());return (float) $sec + ((float) $usec * 100000);}
srand(make_seed());
# Preserve CDATA fields $cdata_array=array(); preg_match_all('/<\!\[CDATA\[(.*?)\]\]/is', $rss, $tmp); foreach($tmp[0] as $k => $v) {
$id = "CDATA".rand(1, 10000000)."CDATA";
$rss = str_replace($v, $id, $rss);
$cdata_array[ $id ] = $v;
}
# Extract all RSS items
preg_match_all('/<item>(.*?)<\/item>/is', $rss, $tmp);
$rss_array = $tmp[0];
# Replace all items with ID
$rss_array2 = array();
foreach($rss_array as $k => $v) {
$id = "RSS".rand(1, 10000000)."RSS";
$rss = str_replace($v, $id, $rss);
$rss_array2[ $id ] = $v;
}
$rss_array = $rss_array2;
# Filter RSS News
foreach($rss_array as $k => $v) {
if (rss_filter2($v)) $rss_array[$k] = '';
}
# Replace back
foreach($rss_array as $k => $v) {
$rss = str_replace($k, $v, $rss);
}
# Restore CDATA foreach($cdata_array as $k => $v) {
$rss = str_replace($k, $v, $rss);
}
return $rss;
}
/*
returns true if RSS Item should NOT be visible
*/
function rss_filter2($rss) {
global $cfg; # Extract pubDate
if (!preg_match('/<pubDate>(.*?)<\/pubDate>/is', $rss, $out)) return false;
$pubDate = $out[1]; $pubDate_unix = strtotime($pubDate); $filterDate = time(); // If filter=date display all today items if ($cfg["filter_method"] == 'date') $filterDate = mktime( 23, 59, 59, date("m",$filterDate), date("d",$filterDate), date("Y",$filterDate) ); if ( $pubDate_unix > $filterDate) return true;
return false;
}
function rss_error($error) {
$now = date("r");
$error_text=<<<EOF
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>RSS Proxy</title>
<description>Error</description>
<language>en</language>
<item>
<link>http://</link>
<pubDate>$now</pubDate>
<title>Error in RSS Feed</title>
<description>$error</description>
</item>
</channel>
</rss>
EOF;
die($error_text);
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -