FeedForAll Forum Index ?
?Home?????FAQ????? Search ?????Memberlist ?????Register ?????Profile? ????Log in
?Cache Feed View next topic
View previous topic
Post new topicReply to topic
Author Message
siemprelisto



Joined: 15 Mar 2005
Posts: 4

PostPosted: Tue Mar 15, 2005 5:59 am Reply with quoteBack to top

Have everything set up using a SSI into a Template within an existing web page...works Great! I would like to have the RSS Feed cached for several reasons. First, less calls on the feed provider, reduce bandwidth, with RSS cache our pages will load quicker if there is no new content. One of the other scripts I tried had this already included and it worked nice but the overall script was not as nice nor does not compare to rss2html

I have made several direct inquires with no response...will someone Help??

Thanks & Best Regards!
View user's profileSend private message
Tech Support



Joined: 27 Aug 2004
Posts: 693

PostPosted: Tue Mar 15, 2005 4:14 pm Reply with quoteBack to top

Is it that you want your RSS feed file cached (the .xml file)

or

the webpage generated from the feed (using rss2html.php) cached?

_________________
FeedForAll Support
View user's profileSend private message
siemprelisto



Joined: 15 Mar 2005
Posts: 4

PostPosted: Tue Mar 15, 2005 5:04 pm Reply with quoteBack to top

I just want the Feed file cached, not the entire page. This way rss2html.php would look in the file I named rss_cache first prior to making a call on the feed provider.

This is an example from one of the other scripts I have tried.

// parameters used for caching

$use_cache=true;
$cache_folder="rss_cache";
$cache_valid=60; // minutes
$display_channel_name=false; // set to false to hide channel name & link

$channel[]=array("","","","","","");

// ***********************************


You can turn cache on or off with, $use_cache=true; or $use_cache=false;

You can set the refresh time for the cached file, in minutes.


function getrss($url) {
global $channel,$items;
global $use_cache,$cache_folder,$cache_valid;

if($use_cache) {
$cache_filename=$cache_folder."/".md5($url).".rss";
if(file_exists($cache_filename)) {
$t=filemtime($cache_filename);
$cache_create=((!$t)||($t else
$cache_create=true;

if($cache_create) {
//cache not valid - create it again
$simple = file($url);
$f=fopen($cache_filename,"w");
for($i=0;$i fwrite($f,$simple[$i]);
fclose($f);
$simple=implode('',$simple);
}
else
$simple = implode('',file($cache_filename));
}
else
$simple = implode('',file($url));


I would like rss2html.php to run Just like it does now, with the exception of checking the rss_cache file prior to calling on the rss feed provider.

Thanks for your help!
View user's profileSend private message
Tech Support



Joined: 27 Aug 2004
Posts: 693

PostPosted: Tue Mar 15, 2005 10:43 pm Reply with quoteBack to top

I have added caching to the feature request list for future versions of the rss2html.php script.

I will post again if I can find out more info about if/when it will be available.

_________________
FeedForAll Support
View user's profileSend private message
siemprelisto



Joined: 15 Mar 2005
Posts: 4

PostPosted: Wed Mar 16, 2005 4:17 pm Reply with quoteBack to top

Thank you for your attention and response to my question. Maybe someone viewing this post will know how to tweak the script above to have it work with rss2html.php?? I look forward to having this feature included...hope it's soon. Again, Thanks for the response and for the Great product!!
View user's profileSend private message
siemprelisto



Joined: 15 Mar 2005
Posts: 4

PostPosted: Tue Aug 09, 2005 7:32 pm Reply with quoteBack to top

What is the status of adding caching?

Thank You!
View user's profileSend private message
JedOi



Joined: 25 Jul 2005
Posts: 22

PostPosted: Wed Aug 10, 2005 1:36 am Reply with quoteBack to top

You could try setting up a cron job or (if you don't have cron jobs) use Pseudo-Cron ( http://www.bitfolge.de/pseudocron-en.html ) to run this simple script however often you require the local cache to be updated ...


$feed = 'http://today.reuters.com/rss/topNews';
$cache = 'Local.XML';

if (!copy($feed, $cache)) {
echo "failed to copy $file...\n";
}

?>


Change feed & local filename as you wish.
View user's profileSend private message
OPS



Joined: 24 Nov 2005
Posts: 3

PostPosted: Thu Nov 24, 2005 1:18 am Reply with quoteBack to top

Is there any word on caching feeds. This feature should be classed as an important update as some feed suppliers will ban people for accessing feeds too often.
View user's profileSend private messageVisit poster's website
OPS



Joined: 24 Nov 2005
Posts: 3

PostPosted: Thu Nov 24, 2005 4:22 am Reply with quoteBack to top

Its butchered but it works if you want to cache your rss feeds.
It took me all of 15 minutes to copy some code from one script to another, at some later time I will go through and make sure it is secure.
Be sure to remove lines 83 and 84 if not needed and change lines 87, 89 and 346
Code:
//
// rss2html.php RSS feed to HTML webpage script
//
// Copyright 2004,205 NotePage, Inc.
// http://www.feedforall.com
// This script may be used freely for business or personal use
// This script may not be resold in any form
//
// $Id: rss2html.php,v 2.7 2005/10/16 17:54:10 housley Exp $
//
// $Log: rss2html.php,v $
// Revision 2.7? 2005/10/16 17:54:10? housley
// Improvements when using CURL:
// - Use the requested file as the REFERER, for sites that might require one
// - Allow to follow up to 10 redirects, some sites redirect to real content
//
// Revision 2.6? 2005/10/16 17:32:27? housley
// Use lastBuildDate as another possible source if pubDate is empty at the
// level.
//
// Revision 2.5? 2005/09/28 02:08:15? housley
// Fix the storage of pubDate at the feed level
//
// Revision 2.4? 2005/09/12 18:56:31? housley
// Set a user agent for both fopen and curl transerfers
//
// Revision 2.3? 2005/09/06 22:55:27? housley
// GUID doesn't need urlencode()
//
// Revision 2.2? 2005/08/16 19:53:15? housley
// Add the ~~~ItemAuthor~~~ subsitution that uses first and then
// for its contents
//
// Revision 2.1? 2005/08/15 14:49:24? housley
// Convert ' to ' since ' is not HTML
//
// Revision 2.0? 2005/07/30 14:09:38? housley
// Allow "allow_url_fopen" to be sellected, incase CURL is not available.
//
// Revision 1.33? 2005/07/20 00:53:35? housley
// Fix it so the this PHP script can be used as a PHP include many time on the same page
//
// Revision 1.32? 2005/07/20 00:36:27? housley
// Don't set allow_url_fopen any more
//
// Revision 1.31? 2005/07/20 00:35:28? housley
// Use CURL to open URLs instead of fopen()
//
// Revision 1.30? 2005/05/08 01:47:27? housley
// Add NoFutureItems
//
// Revision 1.29? 2005/05/06 01:04:56? housley
// Make sure FeedMaxItems is not larger then the number of items.
//
// Revision 1.28? 2005/04/30 18:08:41? housley
// ~~~SortByPubDate~~~ will force the sorting of the items by pubDate, with the newest being first.
//
// Revision 1.27? 2005/04/30 17:49:17? housley
// Allow FeedMaxItems to be negative.? A negative number will grab the last
// items
//
// Revision 1.26? 2005/03/28 14:48:45? housley
// * Remove debug print statement
// * Fix the creation of the putDate for cases when the feed didn't have them, bad feed...bad feed.
//
// Revision 1.25? 2005/03/23 23:22:48? housley
// Handle dc:date in RSS 2.0 feeds.? If both pubData and dc:date exist, pubDate has priority
//
// Revision 1.24? 2005/03/11 12:44:44? housley
// Exit with short message if a file can't be opened.
//
// Revision 1.23? 2005/03/09 15:15:41? housley
// Add copyright header
//
// Revision 1.22? 2005/03/08 15:25:04? housley
// * Add ID for full version number
// * Add Log to show change logs
// * Add support for and ~~~FeedContentEncoded~~~ and ~~~ ItemContentEncoded~~~
//
//
//--------------------------------------------------------------------------------------
? $parent = $_GET[parent];
if(!$_GET[parent]) $parent = 0;
? ?$update_interval = 1;? ?? ?// Time between updates
? $do_update = TRUE;? ?? ?? ?? ?? ?// Allow updates
? $data_directory = "rss"; ? ?// directory to save the file in needs to chmod to 777
? ? ?
? $rss_url = "http://www.buyaphoto.net/rss/rss_gen3.php?&parent=".$parent."";
?
//no idea what all this stuff does, but it works
? ? $url_parts = parse_url($rss_url);

? ? $filename = $url_parts['host'] . str_replace("/", ",", $url_parts['path']) . "_" . @$url_parts['query'];
? ? if(file_exists($data_directory . "/$filename")) {
? ? ? $last = filemtime($data_directory . "/$filename");
? ? ? if(time() - $last > $update_interval * 60 || $update_interval == 0) {
? ? ? ? $update = 1;
? ? ? }
? ? } else {
? ? ? ? $create= 1;
? ? }

? ? if($create == 1 || ($do_update == TRUE && $update == 1)) {
? ? ? $fp = @fsockopen($url_parts['host'], 80, $errno, $errstr, 5);
? ? ? if (!$fp) {
? ? ? ? echo "Couldn't open rss feed in {$_SERVER['PHP_SELF']}
\n";
? ? ? ? return;
? ? ? }

? ? ? fputs($fp, "GET " . $url_parts['path'] . "?" . @$url_parts['query'] . " HTTP/1.0\r\n"
? ? ? ? ? ? ? ? ."Host: " . $url_parts['host'] . "\r\n"
? ? ? ? ? ? ? ? ."User-Agent: It's an RSS reader dude\r\n"
? ? ? ? ? ? ? ? ."Connection: Close\r\n\r\n");

? ? ? while(!feof($fp)) {
? ? ? ? $rss_data .= @fgets($fp, 1024);
? ? ? }

? ? ? list(, $rss_data) = explode("\r\n\r\n", $rss_data, 2);

? ? ? $output = @fopen($data_directory . "/$filename", "w+");
? ? ? if(!$output) {
? ? ? ? return $rss_data;
? ? ? } else {
? ? ? ? flock($output, LOCK_EX);
? ? ? ? fputs($output, $rss_data);
? ? ? ? flock($output, LOCK_UN);
? ? ? ? fclose($output);
? ? ? }
? ? }
? ?
// Set the following variable useFopenURL to one if you want/need to use fopen instead of CURL
//$useFopenURL = 0;

//if ($useFopenURL) {
//? ini_set("allow_url_fopen", "1");
?// ini_set("user_agent", 'FeedForAll rss2html.php v2');
//}

//
// If XLMfile is passed as part of the REQUEST_URI, then it will be used
// otherwise the the file below is used.
//$XMLfilename = "http://examlple.com/sample.xml";

$XMLfilename = $data_directory . "/$filename";

//
// If TEMPLATE is passed as part of the REQUEST_URI, then it will be used
// otherwise the the file below is used.
$TEMPLATEfilename = "new_page_11.htm";
if (isset($_REQUEST["TEMPLATE"])) {
? if (stristr($_REQUEST["TEMPLATE"], "file://")) {
? ? // Not allowed
? ? ;
? }
? elseif (stristr($_REQUEST["TEMPLATE"], "://")) {
? ? // URL files are allowed
? ? $TEMPLATEfilename = $_REQUEST["TEMPLATE"];
? } else {
? ? // It is local and must be in the same directory
? ? $TEMPLATEfilename = basename($_REQUEST["TEMPLATE"]);
? }
}

//
// date() function documented http://www.php.net/manual/en/function.date.php
//

$LongDateFormat = "F jS, Y";? ? // ie, "Jan 21st, 2004"

$ShortDateFormat = "m/d/Y";? ? ?// ie, "1/21/2004"
//$ShortDateFormat = "d/m/Y";? ? ?// ie, "21/1/2004"

$LongTimeFormat = "H:i:s T O";? // ie, "13:24:30 EDT -0400"

$ShortTimeFormat = "h:i A";? ? ?// ie, "1:24 PM"

//
// Maximum number of items to be displayed
//

$FeedMaxItems = 10000;
if (isset($_REQUEST["MAXITEMS"])) {
? $FeedMaxItems = $_REQUEST["MAXITEMS"];
}
$NoFutureItems = FALSE;
if (isset($_REQUEST["NOFUTUREITEMS"])) {
? $NoFutureItems = TRUE;
}

//
// As much as I hate globals, they are needed due to the
// recusive nature of the parser
$insidechannel = FALSE;
$level_channel = 0;
$insidechannelimage = FALSE;
$level_channelimage = 0;
$insideitem = FALSE;
$level_item = 0;

if (function_exists("FeedForAll_rss2html_getRFDdate") === FALSE) {
? Function FeedForAll_rss2html_getRFDdate($datestring) {
? ? $year = substr($datestring, 0, 4);
? ? $month = substr($datestring, 5, 2);
? ? $day = substr($datestring, 8, 2);
? ? $hour = substr($datestring, 11, 2);
? ? $minute = substr($datestring, 14, 2);
? ? $second = substr($datestring, 17, 2);
? ? if (substr($datestring, 19, 1) == "Z") {
? ? ? $offset_hour = 0;
? ? ? $offset_minute = 0;
? ? } else {
? ? ? if (substr($datestring, 19, 1) == "+") {
? ? ? ? $offset_hour = substr($datestring, 20, 2);
? ? ? ? $offset_minute = substr($datestring, 23, 2);
? ? ? } else {
? ? ? ? $offset_hour = -1*substr($datestring, 20, 2);
? ? ? ? $offset_minute = -1*substr($datestring, 23, 2);
? ? ? }
? ? }
? ? return gmmktime($hour+$offset_hour, $minute+$offset_minute, $second, $month, $day, $year);
? }

? class FeedForAll_rss2html_RSSParser {
? ? var $gotROOT = 0;
? ? var $feedTYPE = "RSS";
? ? var $level = 0;
? ? var $tag = "";
? ? var $title = "";
? ? var $description = "";
? ? var $contentEncoded = "";
? ? var $link = "";
? ? var $guid = "";
? ? var $enclosureURL = "";
? ? var $pubdate = "";
? ? var $pubdateDC = "";
? ? var $fimageURL = "";
? ? var $fimageTitle = "";
? ? var $fimageLink = "";
? ? var $author = "";
? ? var $DcCreator = "";

? ? var $FeedTitle = "";
? ? var $FeedDescription = "";
? ? var $FeedContentEncoded = "";
? ? var $FeedLink = "";
? ? var $FeedPubDate = "";
? ? var $FeedPubDateDC = "";
? ? var $FeedPubDate_t = "";
? ? var $FeedLastBuildDate = "";
? ? var $FeedImageURL = "";
? ? var $FeedImageTitle = "";
? ? var $FeedImageLink = "";
? ? // When adding new Item elements, be sure to update the sort below
? ? var $ItemTitle = "";
? ? var $ItemDescription = "";
? ? var $ItemContentEncoded = "";
? ? var $ItemLink = "";
? ? var $ItemGuid = "";
? ? var $ItemPubDate = "";
? ? var $ItemPubDate_t = "";
? ? var $ItemEnclosureURL = "";
? ? var $ItemAuthor = "";

? ? function startElement($parser, $tagName, $attrs) {
? ? ? GLOBAL $insidechannel;
? ? ? GLOBAL $level_channel;
? ? ? GLOBAL $insidechannelimage;
? ? ? GLOBAL $level_channelimage;
? ? ? GLOBAL $insideitem;
? ? ? GLOBAL $level_item;

? ? ? $this->level++;
? ? ? $this->tag = $tagName;
? ? ? if ($this->gotROOT == 0) {
? ? ? ? $this->gotROOT = 1;
? ? ? ? if (strstr($tagName, "RSS")) {
? ? ? ? ? $this->feedTYPE = "RSS";
? ? ? ? }
? ? ? ? elseif (strstr($tagName, "RDF")) {
? ? ? ? ? $this->feedTYPE = "RDF";
? ? ? ? }
? ? ? ? elseif (strstr($tagName, "FEE")) {
? ? ? ? ? $this->feedTYPE = "FEE";
? ? ? ? ? $insidechannel = TRUE;
? ? ? ? ? $level_channel = 1;
? ? ? ? }
? ? ? }
? ? ? elseif ((($tagName == "ITEM") && ($this->feedTYPE != "FEE")) || (($tagName == "ENTRY") && ($this->feedTYPE == "FEE"))) {
? ? ? ? $insideitem = TRUE;
? ? ? ? $level_item = $this->level;
? ? ? }
? ? ? elseif (($insideitem) && ($tagName == "ENCLOSURE")) {
? ? ? ? $this->enclosureURL = $attrs["URL"];
? ? ? }
? ? ? elseif (($tagName == "LINK") && ($this->feedTYPE == "FEE")) {
? ? ? ? $this->link = $attrs["HREF"];
? ? ? }
? ? ? elseif ($tagName == "CHANNEL") {
? ? ? ? $insidechannel = TRUE;
? ? ? ? $level_channel = $this->level;
? ? ? }
? ? ? elseif (($tagName == "IMAGE") && ($insidechannel = TRUE)) {
? ? ? ? $insidechannelimage = TRUE;
? ? ? ? $level_channelimage = $this->level;
? ? ? }
? ? ? if ($parser);
? ? }

? ? function endElement($parser, $tagName) {
? ? ? GLOBAL $insidechannel;
? ? ? GLOBAL $level_channel;
? ? ? GLOBAL $insidechannelimage;
? ? ? GLOBAL $level_channelimage;
? ? ? GLOBAL $insideitem;
? ? ? GLOBAL $level_item;
? ? ? GLOBAL $NoFutureItems;

? ? ? $this->level--;
? ? ? if ((($tagName == "ITEM") && ($this->feedTYPE != "FEE")) || (($tagName == "ENTRY") && ($this->feedTYPE == "FEE"))) {
? ? ? ? $UseItem = TRUE;

? ? ? ? if ($NoFutureItems) {
? ? ? ? ? $noon = strtotime("today at 12:00");
? ? ? ? ? if (trim($this->pubdate) != "") {
? ? ? ? ? ? $ItemPubDate = strtotime($this->pubdate);
? ? ? ? ? }
? ? ? ? ? else if (trim($this->pubdateDC) != "") {
? ? ? ? ? ? $ItemPubDate = FeedForAll_rss2html_getRFDdate($this->pubdateDC);
? ? ? ? ? } else {
? ? ? ? ? ? $ItemPubDate = time();
? ? ? ? ? }
? ? ? ? ? if (($ItemPubDate - $noon) > 43200) {
? ? ? ? ? ? $UseItem = FALSE;
? ? ? ? ? }
? ? ? ? }

? ? ? ? if ($UseItem) {
? ? ? ? ? $this->ItemTitle[] = trim($this->title);
? ? ? ? ? $this->ItemDescription[] = trim($this->description);
? ? ? ? ? $this->ItemContentEncoded[] = trim($this->contentEncoded);
? ? ? ? ? if (trim($this->contentEncoded) == "") {
? ? ? ? ? ? $this->ItemContentEncoded[] = $this->description;
? ? ? ? ? }
? ? ? ? ? $this->ItemLink[] = "rss2html5.php".trim($this->link)." \"";
? ? ? ? ? //
? ? ? ? ? // Get the pubDate from pubDate first and then dc:date
? ? ? ? ? if (trim($this->pubdate) != "") {
? ? ? ? ? ? $this->ItemPubDate[] = trim($this->pubdate);
? ? ? ? ? ? $this->ItemPubDate_t[] = strtotime($this->pubdate);
? ? ? ? ? }
? ? ? ? ? else if (trim($this->pubdateDC) != "") {
? ? ? ? ? ? $this->ItemPubDate[] = trim($this->pubdateDC);
? ? ? ? ? ? $this->ItemPubDate_t[] = FeedForAll_rss2html_getRFDdate($this->pubdateDC);
? ? ? ? ? } else {
? ? ? ? ? ? $this->ItemPubDate[] = date("D, d M Y H:i:s +0000");
? ? ? ? ? ? $this->ItemPubDate_t[] = time();
? ? ? ? ? }
? ? ? ? ? $this->ItemGuid[] = trim($this->guid);
? ? ? ? ? $this->ItemEnclosureURL[] = trim($this->enclosureURL);
? ? ? ? ? if ($this->author == "") {
? ? ? ? ? ? $this->ItemAuthor[] = $this->DcCreator;
? ? ? ? ? } else {
? ? ? ? ? ? $this->ItemAuthor[] = $this->author;
? ? ? ? ? }
? ? ? ? }
? ? ? ? $this->title = "";
? ? ? ? $this->description = "";
? ? ? ? $this->contentEncoded = "";
? ? ? ? $this->link = "";
? ? ? ? $this->pubdate = "";
? ? ? ? $this->pubdateDC = "";
? ? ? ? $this->guid = "";
? ? ? ? $this->enclosureURL = "";
? ? ? ? $this->author = "";
? ? ? ? $this->DcCreator = "";
? ? ? ? $insideitem = FALSE;
? ? ? ? $level_item = 0;
? ? ? }
? ? ? elseif (($tagName == "IMAGE") && ($insidechannelimage)) {
? ? ? ? $this->FeedImageURL = trim($this->fimageURL);
? ? ? ? $this->FeedImageTitle = trim($this->fimageTitle);
? ? ? ? $this->FeedImageLink = trim($this->fimageLink);
? ? ? ? $this->fimageURL = "";
? ? ? ? $this->fimageTitle = "";
? ? ? ? $this->fimageLink = "";
? ? ? ? $insidechannelimage = FALSE;
? ? ? ? $level_channelimage = 0;
? ? ? }
? ? ? elseif ($tagName == "CHANNEL") {
? ? ? ? //
? ? ? ? // Get the pubDate from pubDate first and then dc:date
? ? ? ? if (trim($this->FeedPubDate) != "") {
? ? ? ? ? $this->FeedPubDate_t = strtotime($this->FeedPubDate);
? ? ? ? }
? ? ? ? else if (trim($this->FeedPubDateDC) != "") {
? ? ? ? ? $this->FeedPubDate_t = FeedForAll_rss2html_getRFDdate($this->FeedPubDateDC);
? ? ? ? }
? ? ? ? else if (trim($this->FeedLastBuildDate) != "") {
? ? ? ? ? $this->FeedPubDate_t = strtotime($this->FeedLastBuildDate);
? ? ? ? } else {
? ? ? ? ? $this->FeedPubDate = date("D, d M Y H:i:s +0000");
? ? ? ? ? $this->FeedPubDate_t = time();
? ? ? ? }
? ? ? ? $insidechannel = FALSE;
? ? ? ? $level_channel = 0;
? ? ? }
? ? ? elseif ($this->level == $level_channel) {
? ? ? ? if ($tagName == "TITLE") {
? ? ? ? ? $this->FeedTitle = trim($this->title);
? ? ? ? ? $this->title = "";
? ? ? ? }
? ? ? ? elseif (($tagName == "DESCRIPTION") || ($tagName == "TAGLINE")) {
? ? ? ? ? $this->FeedDescription = trim($this->description);
? ? ? ? ? $this->description = "";
? ? ? ? }
? ? ? ? elseif ($tagName == "CONTENT:ENCODED") {
? ? ? ? ? $this->FeedContentEncoded = trim($this->contentEncoded);
? ? ? ? ? $this->contentEncoded = "";
? ? ? ? }
? ? ? ? elseif ($tagName == "LINK") {
? ? ? ? ? $this->FeedLink = trim($this->link);
? ? ? ? ? $this->link = "";
? ? ? ? }
? ? ? }
? ? ? if ($parser);
? ? }

? ? function characterData($parser, $data) {
? ? ? GLOBAL $insidechannel;
? ? ? GLOBAL $level_channel;
? ? ? GLOBAL $insidechannelimage;
? ? ? GLOBAL $level_channelimage;
? ? ? GLOBAL $insideitem;
? ? ? GLOBAL $level_item;

? ? ? if (($data == "") || ($data == NULL)) {
? ? ? } else {
? ? ? ? if (($insideitem) && ($this->level == $level_item+1)) {
? ? ? ? ? switch ($this->tag) {
? ? ? ? ? ? case "TITLE":
? ? ? ? ? ? $this->title .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "DESCRIPTION":
? ? ? ? ? ? $this->description .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "CONTENT:ENCODED":
? ? ? ? ? ? $this->contentEncoded .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "SUMMARY":
? ? ? ? ? ? $this->description .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "LINK":
? ? ? ? ? ? $this->link .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "PUBDATE":
? ? ? ? ? ? $this->pubdate .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "DC:DATE":
? ? ? ? ? ? $this->pubdateDC .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "MODIFIED":
? ? ? ? ? ? $this->pubdateDC .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "GUID":
? ? ? ? ? ? $this->guid .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "AUTHOR":
? ? ? ? ? ? $this->author .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "DC:CREATOR":
? ? ? ? ? ? $this->DcCreator .= $data;
? ? ? ? ? ? break;
? ? ? ? ? }
? ? ? ? }
? ? ? ? elseif ($insidechannelimage) {
? ? ? ? ? switch ($this->tag) {
? ? ? ? ? ? case "TITLE":
? ? ? ? ? ? $this->fimageTitle .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "URL":
? ? ? ? ? ? $this->fimageURL .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "LINK":
? ? ? ? ? ? $this->fimageLink .= $data;
? ? ? ? ? ? break;
? ? ? ? ? }
? ? ? ? }
? ? ? ? elseif (($insidechannel) && ($this->level == $level_channel+1)) {
? ? ? ? ? switch ($this->tag) {
? ? ? ? ? ? case "TITLE":
? ? ? ? ? ? $this->title .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "DESCRIPTION":
? ? ? ? ? ? $this->description .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "CONTENT:ENCODED":
? ? ? ? ? ? $this->contentEncoded .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "TAGLINE":
? ? ? ? ? ? $this->description .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "LINK":
? ? ? ? ? ? $this->link .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "PUBDATE":
? ? ? ? ? ? $this->FeedPubDate .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "DC:DATE":
? ? ? ? ? ? $this->FeedPubDateDC .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "MODIFIED":
? ? ? ? ? ? $this->FeedPubDateDC .= $data;
? ? ? ? ? ? break;

? ? ? ? ? ? case "LASTBUILDDATE":
? ? ? ? ? ? $this->FeedLastBuildDate .= $data;
? ? ? ? ? ? break;
? ? ? ? ? }
? ? ? ? }
? ? ? }
? ? ? if ($parser);
? ? }
? }
}

if (stristr($TEMPLATEfilename, "://")) {
? if ($useFopenURL) {
? ? if (($fd = @fopen($TEMPLATEfilename, "rb")) === FALSE) {
? ? ? echo "Unable to open template $TEMPLATEfilename, exiting\n";
? ? ? exit -1;
? ? }
? ? $template = NULL;
? ? while (($data = fread($fd, 4096)) != "") {
? ? ? $template .= $data;
? ? }
? ? fclose($fd);
? } else {
? ? // This is a URL so use CURL
? ? $curlHandle = curl_init();
? ? curl_setopt($curlHandle, CURLOPT_URL, $TEMPLATEfilename);
? ? curl_setopt($curlHandle, CURLOPT_HEADER, 0);
? ? curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
? ? curl_setopt($curlHandle, CURLOPT_USERAGENT, "FeedForAll rss2html.php v2");
//? ? curl_setopt($curlHandle, CURLOPT_AUTOREFERER, 1);
? ? curl_setopt($curlHandle, CURLOPT_REFERER, $TEMPLATEfilename);
? ? curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, 1);
? ? curl_setopt($curlHandle, CURLOPT_MAXREDIRS, 10);
? ? $template = curl_exec($curlHandle);
? ? if (curl_errno($curlHandle)) {
? ? ? curl_close($curlHandle);
? ? ? echo "Unable to open template $TEMPLATEfilename, exiting\n";
? ? ? exit -1;
? ? }
? ? curl_close($curlHandle);
? }
} else {
? // This is a local file, so use fopen
? if (($fd = @fopen($TEMPLATEfilename, "rb")) === FALSE) {
? ? echo "Unable to open template $TEMPLATEfilename, exiting\n";
? ? exit -1;
? }
? $template = NULL;
? while (($data = fread($fd, 4096)) != "") {
? ? $template .= $data;
? }
? fclose($fd);
}

if (strstr($template, "~~~NoFutureItems~~~")) {
? $NoFutureItems = TRUE;
}

$xml_parser = xml_parser_create('');
$rss_parser = new FeedForAll_rss2html_RSSParser();
xml_set_object($xml_parser,$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,1);
if (stristr($XMLfilename, "://")) {
? if ($useFopenURL) {
? ? if (($fd = @fopen($XMLfilename, "rb")) === FALSE) {
? ? ? echo "Unable to open RSS Feed $XMLfilename, exiting\n";
? ? ? exit -1;
? ? }
? ? // Read the whole file 4k at a time so remote files can be read
? ? while (($XML = fread($fd, 4096)) != "") {
? ? ? xml_parse($xml_parser,$XML);
? ? }
? ? fclose($fd);
? } else {
? ? // This is a URL so use CURL
? ? $curlHandle = curl_init();
? ? curl_setopt($curlHandle, CURLOPT_URL, $XMLfilename);
? ? curl_setopt($curlHandle, CURLOPT_HEADER, 0);
? ? curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
? ? curl_setopt($curlHandle, CURLOPT_USERAGENT, "FeedForAll rss2html.php v2");
//? ? curl_setopt($curlHandle, CURLOPT_AUTOREFERER, 1);
? ? curl_setopt($curlHandle, CURLOPT_REFERER, $XMLfilename);
? ? curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, 1);
? ? curl_setopt($curlHandle, CURLOPT_MAXREDIRS, 10);
? ? $XML = curl_exec($curlHandle);
? ? if (curl_errno($curlHandle)) {
? ? ? curl_close($curlHandle);
? ? ? echo "Unable to open template $XMLfilename, exiting\n";
? ? ? exit -1;
? ? }
? ? curl_close($curlHandle);
? ? xml_parse($xml_parser,$XML);
? }
} else {
? // This is a local file, so use fopen
? if (($fd = @fopen($XMLfilename, "rb")) === FALSE) {
? ? echo "Unable to open RSS Feed $XMLfilename, exiting\n";
? ? exit -1;
? }
? // Read the whole file 4k at a time so remote files can be read
? while (($XML = fread($fd, 4096)) != "") {
? ? xml_parse($xml_parser,$XML);
? }
? fclose($fd);
}
xml_parser_free($xml_parser);

// make sure the channel contentEncoded is not blank
if ($rss_parser->FeedContentEncoded == "") {
?// $rss_parser->FeedContentEncoded = $rss_parser->FeedDescription;
}
$template = str_replace("~~~FeedTitle~~~", $rss_parser->FeedTitle, $template);
$template = str_replace("~~~FeedDescription~~~", $rss_parser->FeedDescription, $template);
$template = str_replace("~~~FeedContentEncoded~~~", $rss_parser->FeedContentEncoded, $template);
$template = str_replace("~~~FeedLink~~~", $rss_parser->FeedLink, $template);
$template = str_replace("~~~FeedPubDate~~~", $rss_parser->FeedPubDate, $template);
$template = str_replace("~~~FeedPubLongDate~~~", date($LongDateFormat, $rss_parser->FeedPubDate_t), $template);
$template = str_replace("~~~FeedPubShortDate~~~", date($ShortDateFormat, $rss_parser->FeedPubDate_t), $template);
$template = str_replace("~~~FeedPubLongTime~~~", date($LongTimeFormat, $rss_parser->FeedPubDate_t), $template);
$template = str_replace("~~~FeedPubShortTime~~~", date($ShortTimeFormat, $rss_parser->FeedPubDate_t), $template);
$template = str_replace("~~~FeedImageUrl~~~", $rss_parser->FeedImageURL, $template);
$template = str_replace("~~~FeedImageTitle~~~", $rss_parser->FeedImageTitle, $template);
$template = str_replace("~~~FeedImageLink~~~", $rss_parser->FeedImageLink, $template);
$match = NULL;

$template = str_replace("~~~NoFutureItems~~~", "", $template);

// Sort by PubDate if requested
if (strstr($template, "~~~SortByPubDate~~~")) {
? $template = str_replace("~~~SortByPubDate~~~", "", $template);
?
? for ($x = 0; $x < count($rss_parser->ItemTitle)-1; $x++)
? {
? ? for ($y = $x+1; $y < count($rss_parser->ItemTitle); $y++)
? ? {
? ? ? if ($rss_parser->ItemPubDate_t[$x] < $rss_parser->ItemPubDate_t[$y])
? ? ? {
? ? ? ? // Swap them
? ? ? ? $swapTemp = $rss_parser->ItemTitle[$x]; $rss_parser->ItemTitle[$x] = $rss_parser->ItemTitle[$y]; $rss_parser->ItemTitle[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemDescription[$x]; $rss_parser->ItemDescription[$x] = $rss_parser->ItemDescription[$y]; $rss_parser->ItemDescription[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemContentEncoded[$x]; $rss_parser->ItemContentEncoded[$x] = $rss_parser->ItemContentEncoded[$y]; $rss_parser->ItemContentEncoded[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemLink[$x]; $rss_parser->ItemLink[$x] = $rss_parser->ItemLink[$y]; $rss_parser->ItemLink[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemGuid[$x]; $rss_parser->ItemGuid[$x] = $rss_parser->ItemGuid[$y]; $rss_parser->ItemGuid[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemPubDate[$x]; $rss_parser->ItemPubDate[$x] = $rss_parser->ItemPubDate[$y]; $rss_parser->ItemPubDate[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemPubDate_t[$x]; $rss_parser->ItemPubDate_t[$x] = $rss_parser->ItemPubDate_t[$y]; $rss_parser->ItemPubDate_t[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemEnclosureURL[$x]; $rss_parser->ItemEnclosureURL[$x] = $rss_parser->ItemEnclosureURL[$y]; $rss_parser->ItemEnclosureURL[$y] = $swapTemp;
? ? ? ? $swapTemp = $rss_parser->ItemAuthor[$x]; $rss_parser->ItemAuthor[$x] = $rss_parser->ItemAuthor[$y]; $rss_parser->ItemAuthor[$y] = $swapTemp;
? ? ? }
? ? }
? }
}

// The the maximum items requested
if (strstr($template, "~~~FeedMaxItems=")) {
? // Limit the maximun number of items displayed
? if (preg_match("/~~~FeedMaxItems=([0-9-]*)~~~/", $template, $match) !== FALSE) {
? ? if (($match[0] != "") && ($match[1] != "")) {
? ? ? $FeedMaxItems = $match[1];
? ? ? $template = str_replace("~~~FeedMaxItems=$match[1]~~~", "", $template);
? ? ? if (abs($FeedMaxItems) > count($rss_parser->ItemTitle)) {
? ? ? ? if ($FeedMaxItems > 0) {
? ? ? ? ? $FeedMaxItems = count($rss_parser->ItemTitle);
? ? ? ? } else {
? ? ? ? ? $FeedMaxItems = -count($rss_parser->ItemTitle);
? ? ? ? }
? ? ? }
? ? }
? }
}

//
// Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~
//
while ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) {
? $match = NULL;
? $allitems = NULL;
? $loop_limit = min(abs($FeedMaxItems), count($rss_parser->ItemTitle));
? if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) {
? ? if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) {
? ? ? $WholeBlock = $parts[0];
? ? ? //
? ? ? // Check for ~~~BeginAlternateItemsRecord~~~
? ? ? //
? ? ? if (strstr($WholeBlock, "~~~BeginAlternateItemsRecord~~~")) {
? ? ? ? $parts = split("~~~BeginAlternateItemsRecord~~~", $WholeBlock);
? ? ? ? $block1 = $parts[0];
? ? ? ? $block2 = $parts[1];
? ? ? } else {
? ? ? ? $block1 = $WholeBlock;
? ? ? ? $block2 = $WholeBlock;
? ? ? }
? ? ? if ($FeedMaxItems < 0) {
? ? ? ? for ($x = count($rss_parser->ItemTitle)-1; $x >= count($rss_parser->ItemTitle) + $FeedMaxItems; $x--) {
? ? ? ? ? $item = str_replace("~~~ItemTitle~~~", $rss_parser->ItemTitle[$x], $block1);
? ? ? ? ? $item = str_replace("~~~ItemDescription~~~", $rss_parser->ItemDescription[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemContentEncoded~~~", $rss_parser->ItemContentEncoded[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemLink~~~", $rss_parser->ItemLink[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemPubDate~~~", $rss_parser->ItemPubDate[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemGuid~~~", $rss_parser->ItemGuid[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemEnclosureUrl~~~", $rss_parser->ItemEnclosureURL[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemAuthor~~~", $rss_parser->ItemAuthor[$x], $item);
? ? ? ? ? $allitems .= $item;
? ? ? ? ? $x--;
? ? ? ? ? if ($x >= count($rss_parser->ItemTitle) + $FeedMaxItems) {
? ? ? ? ? ? //
? ? ? ? ? ? // This is at least one more item so use the Alternate definition
? ? ? ? ? ? //
? ? ? ? ? ? $item = str_replace("~~~ItemTitle~~~", $rss_parser->ItemTitle[$x], $block2);
? ? ? ? ? ? $item = str_replace("~~~ItemDescription~~~", $rss_parser->ItemDescription[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemContentEncoded~~~", $rss_parser->ItemContentEncoded[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemLink~~~", $rss_parser->ItemLink[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubDate~~~", $rss_parser->ItemPubDate[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemGuid~~~", $rss_parser->ItemGuid[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemEnclosureUrl~~~", $rss_parser->ItemEnclosureURL[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemAuthor~~~", $rss_parser->ItemAuthor[$x], $item);
? ? ? ? ? ? $allitems .= $item;
? ? ? ? ? }
? ? ? ? }
? ? ? } else {
? ? ? ? for ($x = 0; $x < $loop_limit; $x++) {
? ? ? ? ? $item = str_replace("~~~ItemTitle~~~", $rss_parser->ItemTitle[$x], $block1);
? ? ? ? ? $item = str_replace("~~~ItemDescription~~~", $rss_parser->ItemDescription[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemContentEncoded~~~", $rss_parser->ItemContentEncoded[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemLink~~~", $rss_parser->ItemLink[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemPubDate~~~", $rss_parser->ItemPubDate[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemGuid~~~", $rss_parser->ItemGuid[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? $item = str_replace("~~~ItemEnclosureUrl~~~", $rss_parser->ItemEnclosureURL[$x], $item);
? ? ? ? ? $item = str_replace("~~~ItemAuthor~~~", $rss_parser->ItemAuthor[$x], $item);
? ? ? ? ? $allitems .= $item;
? ? ? ? ? $x++;
? ? ? ? ? if ($x < $loop_limit) {
? ? ? ? ? ? //
? ? ? ? ? ? // This is at least one more item so use the Alternate definition
? ? ? ? ? ? //
? ? ? ? ? ? $item = str_replace("~~~ItemTitle~~~", $rss_parser->ItemTitle[$x], $block2);
? ? ? ? ? ? $item = str_replace("~~~ItemDescription~~~", $rss_parser->ItemDescription[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemContentEncoded~~~", $rss_parser->ItemContentEncoded[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemLink~~~", $rss_parser->ItemLink[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubDate~~~", $rss_parser->ItemPubDate[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemGuid~~~", $rss_parser->ItemGuid[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item);
? ? ? ? ? ? $item = str_replace("~~~ItemEnclosureUrl~~~", $rss_parser->ItemEnclosureURL[$x], $item);
? ? ? ? ? ? $item = str_replace("~~~ItemAuthor~~~", $rss_parser->ItemAuthor[$x], $item);
? ? ? ? ? ? $allitems .= $item;
? ? ? ? ? }
? ? ? ? }
? ? ? }
? ? ? $template = str_replace("~~~BeginItemsRecord~~~".$WholeBlock."~~~EndItemsRecord~~~", $allitems, $template);
? ? }
? }
}

// Since ' is not HTML, but is XML convert.
$template = str_replace("'", "'", $template);

echo $template;

?>
View user's profileSend private messageVisit poster's website
Display posts from previous:?? ? ?
Post new topicReply to topic


?Jump to:? ?



View next topic
View previous topic


Powered by phpBB ? 2001, 2002 phpBB Group :: FI Theme