RSSReader.class.php
gehe zur Dokumentation dieser Datei00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00036 class RSSReader extends Dynamic
00037 {
00042 var $parameters = Array(
00043 'url'=>'URL from which the RSS is fetched'
00044 );
00045
00050 var $description = 'Reads a RSS-Feed and displays its content as a html list';
00051
00052 var $url = 'http://www.heise.de/newsticker/heise.rdf';
00053
00054
00055
00056 function execute()
00057 {
00058
00059 $sessVar = 'RSSReader_'.crc32($this->url);
00060 $cache = $this->getSessionVar( $sessVar );
00061
00062 if ( !empty($cache) )
00063 {
00064
00065 $this->output( $cache );
00066 }
00067 else
00068 {
00069
00070 $this->create();
00071 $this->setSessionVar( $sessVar,$this->getOutput() );
00072 }
00073 }
00074
00075
00076
00077
00078 function create()
00079 {
00080 $rss = $this->parse( implode('',file($this->url)) );
00081 $out = array();
00082
00083 $this->output('<ul>');
00084
00085
00086 foreach( $rss['items'] as $item )
00087 {
00088 $this->output('<li>');
00089 $this->output('<a href="'.$item['link'].'">'.$item['title'].'</a><br/>'.$item['description']);
00090 $this->output('</li>');
00091 }
00092
00093 $this->output('</ul>');
00094 }
00095
00096
00097
00098 function parse( $feed )
00099 {
00100
00101 $arr = array();
00102
00103 preg_match('/<\?xml version="1\.0" encoding="(.*)"\?>/i', $feed, $sarr);
00104 if ( !empty($sarr[1]))
00105 $arr["encoding"] = $sarr[1];
00106
00107 preg_match('/<title>(.*)<\/title>/i', $feed, $sarr);
00108 if ( !empty($sarr[1]))
00109 $arr["title"] = $sarr[1];
00110
00111 preg_match('/<title>(.*)<\/title>/i', $feed, $sarr);
00112 if ( !empty($sarr[1]))
00113 $arr["title"] = $sarr[1];
00114
00115 preg_match('/<description>(.*)<\/description>/i', $feed, $sarr);
00116 if ( !empty($sarr[1]))
00117 $arr["description"] = $sarr[1];
00118
00119 preg_match('/<link>(.*)<\/link>/i', $feed, $sarr);
00120 if ( !empty($sarr[1]))
00121 $arr["link"] = $sarr[1];
00122
00123 preg_match('/<language>(.*)<\/language>/i', $feed, $sarr);
00124 if ( !empty($sarr[1]))
00125 $arr["language"] = $sarr[1];
00126
00127 preg_match('/<generator>(.*)<\/generator>/i', $feed, $sarr);
00128 if ( !empty($sarr[1]))
00129 $arr["generator"] = $sarr[1];
00130
00131 $parts = explode("<item>", $feed);
00132 foreach($parts as $part)
00133 {
00134 $item = substr($part, 0, strpos($part, "</item>"));
00135 if ( !empty($item) )
00136 $items[] = $item;
00137 }
00138
00139 $arr["items"] = array();
00140 foreach($items as $item)
00141 {
00142 $i = array();
00143
00144
00145 preg_match('/<title>(.*)<\/title>/i', $item, $title);
00146 if ( !empty($title[1]))
00147 $i['title'] = $title[1];
00148 else
00149 $i['title'] = '';
00150
00151
00152 preg_match('/<pubDate>(.*)<\/pubDate>/i', $item, $pubdate);
00153 if ( !empty($pubdate[1]))
00154 $i['pubDate'] = strtotime($pubdate[1]);
00155 else
00156 $i['pubDate'] = '';
00157
00158
00159 preg_match('/<link>(.*)<\/link>/i', $item, $link);
00160 if ( !empty($link[1]))
00161 $i['link'] = $link[1];
00162 else
00163 $i['link'] = '';
00164
00165
00166 if(stristr($item, '<![CDATA['))
00167 preg_match('/<description><!\[CDATA\[(.*)\]\]><\/description>/is', $item, $description);
00168 else
00169 preg_match('/<description>(.*)<\/description>/is', $item, $description);
00170
00171 if ( !empty($description[1]))
00172 $i['description'] = $description[1];
00173 else
00174 $i['description'] = '';
00175
00176 $arr["items"][] = $i;
00177 }
00178 return $arr;
00179 }
00180 }