From d526decc4884710ae7fafe7aa5171e7f59b24292 Mon Sep 17 00:00:00 2001 From: jhunkeler Date: Sun, 27 Dec 2009 15:44:57 +0000 Subject: MySQL -> MySQLi Fixed memory leaks after Fetching arrays Removed all while loops that interfaced with $db->Fetch() Rewrote RSS module Fixed syntax error in donations module Fixed link structure for news module Reverting to old page display method git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@402 c5b2fb0a-d05d-0410-98c8-828840a80ff6 --- blocks/rss_agw/index.php | 175 +++++++++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 74 deletions(-) (limited to 'blocks/rss_agw/index.php') diff --git a/blocks/rss_agw/index.php b/blocks/rss_agw/index.php index 1ecad83..8649582 100644 --- a/blocks/rss_agw/index.php +++ b/blocks/rss_agw/index.php @@ -1,80 +1,107 @@ -load($cacheFile); - - $items = $rss->getItems(); #returns all rss items - - $numFeeds = 0; - echo "
"; - foreach($items as $story){ - if($story['category']=="Tournament Announcements"){ - $numFeeds++; - //$text = $story['description']; - //$text = strip_tags($text); - //$text = preg_replace("(\[font(.+?)...)","", $text); - //$text = stripBBCode($text); - - echo "{$story['title']}
- {$story['pubDate']}
"; - //echo "{$text}

"; - echo "

"; - } +// {{{ constants + +/** + * Armed Global Warfare Feed + */ +define('AGW_FEED', 'http://www.armedglobalwarfare.com/index.php?type=rss;action=.xml;limit=150'); + +/** + * Cache File + */ +define('AGW_CACHE', dirname(__FILE__) . '/rss_cache.xml'); +define('AGW_AGE_CACHE', time() - 3600); + +/** + * Feed Variables + */ +$agwFeed = array(); +$agwXml = null; +$agwProcess = true; + +// }}} + +// {{{ main + +/** + * Check existance of cache + */ +if (file_exists(AGW_CACHE) && (filectime(AGW_CACHE) > AGW_AGE_CACHE)) { + $agwFeed = simplexml_load_file(AGW_CACHE); + $agwProcess = false; +} + +/** + * If we don't have a cache then we'll need to build one + */ +if ($agwProcess === true) { + /** + * Set up global options for cURL to utilize for the transfer. + */ + $options = array(CURLOPT_FORBID_REUSE => true, + CURLOPT_POST => false, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 15, + CURLOPT_USERAGENT => 'Mozilla/5.0 (Compatible; libCURL)', + CURLOPT_VERBOSE => false); + + /** + * Initialize cURL + */ + $agwFeedSource = curl_init(AGW_FEED); + curl_setopt_array($agwFeedSource, $options); + + /** + * Execute cURL container and store the output + */ + $agwFeedOutput = curl_exec($agwFeedSource); + + /** + * Parse the received data + */ + + if (!curl_errno($agwFeedSource)) { + $agwFeed = simplexml_load_string($agwFeedOutput); + $agwXml = new SimpleXMLElement($agwFeedOutput); + + file_put_contents(AGW_CACHE, $agwXml->asXML(), LOCK_EX); + curl_close($agwFeedSource); } - if(!$numFeeds){ - echo "No new updates for this news feed."; + else { + curl_close($agwFeedSource); } - echo "
"; - // echo "
";
-  //print_r($items);
-   // echo "
"; -?> + + /** + * Check to make sure the results are not empty before proceeding. + */ + if (empty($agwFeed) || !is_object($agwFeed)) $agwFeed = array(); +} + +/** + * Process output + */ +foreach ($agwFeed->channel->item as $item) { + if ($item->category != 'Tournament Announcements') continue; + + echo '' . + '' . $item->title . '
' . + '' . $item->pubDate . '


' . PHP_EOL; +} +// }}} +?> -- cgit