aboutsummaryrefslogtreecommitdiff
path: root/blocks/rss_agw
diff options
context:
space:
mode:
authorjhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6>2009-12-20 13:38:08 -0500
committerjhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6>2009-12-20 13:38:08 -0500
commitbe4f83cd2a17a0ec05f5bce50c91befaafaa6e0c (patch)
tree6f20672cf5df66044b3fa9dd71fc3bcdc484abe6 /blocks/rss_agw
parent1a619f2638a4f77fb8ea9557edeefb883d8c06f8 (diff)
downloadbayonetcms-be4f83cd2a17a0ec05f5bce50c91befaafaa6e0c.tar.gz
Test.
git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@376 c5b2fb0a-d05d-0410-98c8-828840a80ff6
Diffstat (limited to 'blocks/rss_agw')
-rw-r--r--blocks/rss_agw/index.php29
-rw-r--r--blocks/rss_agw/rssreader.php161
-rw-r--r--blocks/rss_agw/style.css17
3 files changed, 207 insertions, 0 deletions
diff --git a/blocks/rss_agw/index.php b/blocks/rss_agw/index.php
new file mode 100644
index 0000000..83c3ff1
--- /dev/null
+++ b/blocks/rss_agw/index.php
@@ -0,0 +1,29 @@
+<link rel="stylesheet" type="text/css" href="blocks/rss_agw/style.css" media="screen"/>
+<?php
+
+ include 'rssreader.php';
+
+ $rss = new rss_php;
+
+ $rss->load('http://www.armedglobalwarfare.com/index.php?type=rss;action=.xml;limit=30');
+
+ $items = $rss->getItems(); #returns all rss items
+
+ $numFeeds = 0;
+ echo "<div class=\"rss\" >";
+ foreach($items as $story){
+ if($story['category']=="Tournament Announcements"){
+ $numFeeds++;
+ echo "<a href=\"{$story['link']}\" target=\"_blank\"><span class=\"title\">{$story['title']}</span></a><br />
+ <span class=\"date\">{$story['pubDate']}</span><br />
+ {$story['description']}<br /><br />";
+ }
+ }
+ if(!$numFeeds){
+ echo "No new updates for this news feed.";
+ }
+ echo "</div>";
+ // echo "<pre>";
+ //print_r($items);
+ // echo "</pre>";
+?>
diff --git a/blocks/rss_agw/rssreader.php b/blocks/rss_agw/rssreader.php
new file mode 100644
index 0000000..41fa238
--- /dev/null
+++ b/blocks/rss_agw/rssreader.php
@@ -0,0 +1,161 @@
+<?php
+/*
+ RSS_PHP - the PHP DOM based RSS Parser
+ Author: <rssphp.net>
+ Published: 200801 :: blacknet :: via rssphp.net
+
+ RSS_PHP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
+
+ Usage:
+ See the documentation at http://rssphp.net/documentation
+ Examples:
+ Can be found online at http://rssphp.net/examples
+*/
+
+class rss_php {
+
+ public $document;
+ public $channel;
+ public $items;
+
+/****************************
+ public load methods
+***/
+ # load RSS by URL
+ public function load($url=false, $unblock=true) {
+ if($url) {
+ if($unblock) {
+ $this->loadParser(file_get_contents($url, false, $this->randomContext()));
+ } else {
+ $this->loadParser(file_get_contents($url));
+ }
+ }
+ }
+ # load raw RSS data
+ public function loadRSS($rawxml=false) {
+ if($rawxml) {
+ $this->loadParser($rawxml);
+ }
+ }
+
+/****************************
+ public load methods
+ @param $includeAttributes BOOLEAN
+ return array;
+***/
+ # return full rss array
+ public function getRSS($includeAttributes=false) {
+ if($includeAttributes) {
+ return $this->document;
+ }
+ return $this->valueReturner();
+ }
+ # return channel data
+ public function getChannel($includeAttributes=false) {
+ if($includeAttributes) {
+ return $this->channel;
+ }
+ return $this->valueReturner($this->channel);
+ }
+ # return rss items
+ public function getItems($includeAttributes=false) {
+ if($includeAttributes) {
+ return $this->items;
+ }
+ return $this->valueReturner($this->items);
+ }
+
+/****************************
+ internal methods
+***/
+ private function loadParser($rss=false) {
+ if($rss) {
+ $this->document = array();
+ $this->channel = array();
+ $this->items = array();
+ $DOMDocument = new DOMDocument;
+ $DOMDocument->strictErrorChecking = false;
+ $DOMDocument->loadXML($rss);
+ $this->document = $this->extractDOM($DOMDocument->childNodes);
+ }
+ }
+
+ private function valueReturner($valueBlock=false) {
+ if(!$valueBlock) {
+ $valueBlock = $this->document;
+ }
+ foreach($valueBlock as $valueName => $values) {
+ if(isset($values['value'])) {
+ $values = $values['value'];
+ }
+ if(is_array($values)) {
+ $valueBlock[$valueName] = $this->valueReturner($values);
+ } else {
+ $valueBlock[$valueName] = $values;
+ }
+ }
+ return $valueBlock;
+ }
+
+ private function extractDOM($nodeList,$parentNodeName=false) {
+ $itemCounter = 0;
+ foreach($nodeList as $values) {
+ if(substr($values->nodeName,0,1) != '#') {
+ if($values->nodeName == 'item') {
+ $nodeName = $values->nodeName.':'.$itemCounter;
+ $itemCounter++;
+ } else {
+ $nodeName = $values->nodeName;
+ }
+ $tempNode[$nodeName] = array();
+ if($values->attributes) {
+ for($i=0;$values->attributes->item($i);$i++) {
+ $tempNode[$nodeName]['properties'][$values->attributes->item($i)->nodeName] = $values->attributes->item($i)->nodeValue;
+ }
+ }
+ if(!$values->firstChild) {
+ $tempNode[$nodeName]['value'] = $values->textContent;
+ } else {
+ $tempNode[$nodeName]['value'] = $this->extractDOM($values->childNodes, $values->nodeName);
+ }
+ if(in_array($parentNodeName, array('channel','rdf:RDF'))) {
+ if($values->nodeName == 'item') {
+ $this->items[] = $tempNode[$nodeName]['value'];
+ } elseif(!in_array($values->nodeName, array('rss','channel'))) {
+ $this->channel[$values->nodeName] = $tempNode[$nodeName];
+ }
+ }
+ } elseif(substr($values->nodeName,1) == 'text') {
+
+ $tempValue = trim(preg_replace('/\s\s+/',' ',str_replace("\n",' ', $values->textContent)));
+ if($tempValue) {
+ $tempNode = $tempValue;
+ }
+ } elseif(substr($values->nodeName,1) == 'cdata-section'){
+ $tempNode = $values->textContent;
+ }
+ }
+ return $tempNode;
+ }
+
+ private function randomContext() {
+ $headerstrings = array();
+ $headerstrings['User-Agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.'.rand(0,2).'; en-US; rv:1.'.rand(2,9).'.'.rand(0,4).'.'.rand(1,9).') Gecko/2007'.rand(10,12).rand(10,30).' Firefox/2.0.'.rand(0,1).'.'.rand(1,9);
+ $headerstrings['Accept-Charset'] = rand(0,1) ? 'en-gb,en;q=0.'.rand(3,8) : 'en-us,en;q=0.'.rand(3,8);
+ $headerstrings['Accept-Language'] = 'en-us,en;q=0.'.rand(4,6);
+ $setHeaders = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'."\r\n".
+ 'Accept-Charset: '.$headerstrings['Accept-Charset']."\r\n".
+ 'Accept-Language: '.$headerstrings['Accept-Language']."\r\n".
+ 'User-Agent: '.$headerstrings['User-Agent']."\r\n";
+ $contextOptions = array(
+ 'http'=>array(
+ 'method'=>"GET",
+ 'header'=>$setHeaders
+ )
+ );
+ return stream_context_create($contextOptions);
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/blocks/rss_agw/style.css b/blocks/rss_agw/style.css
new file mode 100644
index 0000000..0bc6e81
--- /dev/null
+++ b/blocks/rss_agw/style.css
@@ -0,0 +1,17 @@
+ .rss img {
+ display: none;
+ }
+ .rss span.title{
+ font-size: 16px;
+ font-weight: bold;
+ /* text-decoration:underline; */
+ }
+
+ .rss span.date{
+ font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif;
+ font-size: 11px;
+ text-transform: uppercase;
+ font-weight:bold;
+ text-align: center;
+ letter-spacing: 2px;
+ } \ No newline at end of file