diff options
author | jhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6> | 2009-12-20 20:04:41 -0500 |
---|---|---|
committer | jhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6> | 2009-12-20 20:04:41 -0500 |
commit | bbb612eabf761ca4ad7dc45f4057aeef0b92506d (patch) | |
tree | c3e41a3cb4e373cdcf23b7e509ae34dfd62fec8b /blocks | |
parent | 8347bdd445b646ea77c43228253ce9aefa6a8c88 (diff) | |
download | bayonetcms-bbb612eabf761ca4ad7dc45f4057aeef0b92506d.tar.gz |
Added caching support to the rss aggregator block.
git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@383 c5b2fb0a-d05d-0410-98c8-828840a80ff6
Diffstat (limited to 'blocks')
-rw-r--r-- | blocks/rss_agw/index.php | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/blocks/rss_agw/index.php b/blocks/rss_agw/index.php index c811ecc..0c90e7c 100644 --- a/blocks/rss_agw/index.php +++ b/blocks/rss_agw/index.php @@ -1,18 +1,55 @@ <link rel="stylesheet" type="text/css" href="blocks/rss_agw/style.css" media="screen"/> <?php - +/* function stripBBCode($text_to_search) { $pattern = '|[[\/\!]*?[^\[\]]*?]|si'; $replace = ''; return preg_replace($pattern, $replace, $text_to_search); -} +} */ include 'rssreader.php'; - + $rss = new rss_php; + $cacheReadLength = 1024; + $cacheFile = dirname(__FILE__) . "/rss.cache"; + $url = 'http://www.armedglobalwarfare.com/index.php?type=rss;action=.xml;limit=150'; + + + if(!file_exists($cacheFile)) + { + decho("creating cache<br/>"); + $fp = fopen($cacheRead, "x+"); + fclose($fp); + } + + decho("reading internal cache state<br/>"); + $internal = fopen($cacheFile, "r"); + $cacheRead = fread($internal, $cacheReadLength); + fclose($internal); + + decho("reading inbound cache data<br/>"); + $inbound = fopen($url, "r+"); + $cacheTempRead = fread($inbound, $cacheReadLength); + fclose($inbound); + + decho("comparing<br/>"); + if((strncmp($cacheTempRead, $cacheRead, $cacheReadLength)) == 0) + { + $cacheTemp = implode('', file($url)); + decho("Length of cached RSS is " . strlen($cacheTemp) . "<br/>"); + decho("Writing cached data to file <br/>"); + $cachefp = fopen($cacheFile, "w+"); + $cacheWritten = fwrite($cachefp, $cacheTemp, strlen($cacheTemp)); + fclose($cachefp); + decho("$cacheWritten bytes written to cache.<br/>"); + } + else + { + decho("cache matches external source, using internal<br/>"); + } - $rss->load('http://www.armedglobalwarfare.com/index.php?type=rss;action=.xml;limit=150'); - + $rss->load($cacheFile); + $items = $rss->getItems(); #returns all rss items $numFeeds = 0; @@ -21,10 +58,12 @@ function stripBBCode($text_to_search) { if($story['category']=="Tournament Announcements"){ $numFeeds++; // $text = $story['description']; + // $text = stripBBCode($text); // $text = preg_replace("(\[font(.+?)...)","",$text); echo "<a href=\"{$story['link']}\" target=\"_blank\"><span class=\"title\">{$story['title']}</span></a><br /> <span class=\"date\">{$story['pubDate']}</span><br />"; - echo "{$text}<br /><br />"; + //echo "{$text}<br /><br />"; + echo "<br /><hr />"; } } if(!$numFeeds){ |