Source for file rss.class.php

Documentation is available at rss.class.php

  1. <?php
  2. /**
  3.  * TPLN Rss Plugin
  4.  * @package Template Engine
  5.  */
  6. class Rss extends Image
  7. {
  8. /**
  9. * This method allows to create a Rss 2.0 feeds
  10. *
  11. * @param array $rss 
  12. * @param array $items 
  13. * @param string $charset 
  14. * @param bool $write 
  15. * 
  16. * @return string $xml
  17. * @since 2.9.2
  18. * @author H2LSOFT */
  19. public function rssWrite($rss, $items, $charset='iso-8859-1', $write = true)
  20. {
  21.     if(empty($charset))$charset = 'iso-8859-1';
  22.  
  23.     @header("content-type: application/xml");
  24.     $rss['description'] = str_replace(array("&","<",">"), array('&amp;', "&lt;", "&gt;"), $rss['description']);
  25.  
  26.     $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n";
  27.     $xml .= '<rss version="2.0">'."\n";
  28.     $xml .= '<channel>'."\n";
  29.     $xml .= '<title>'.$rss['title'].'</title>'."\n";
  30.     $xml .= '<link>'.$rss['link'].'</link>'."\n";
  31.     $xml .= '<description>'.$rss['description'].'</description>'."\n";
  32.     $xml .= '<copyright>'.$rss['copyright'].'</copyright>'."\n";
  33.     $xml .= '<generator>'.'TPLN Php Template v'.TPLN_VERSION.'</generator>'."\n";
  34.  
  35.     // image
  36.     $xml .= '        <image>'."\n";
  37.     $xml .= '            <title>'.$rss['title'].'</title>'."\n";
  38.     $xml .= '            <url>'.$rss['image_url'].'</url>'."\n";
  39.     $xml .= '            <link>'.$rss['link'].'</link>'."\n";
  40.     $xml .= '        </image>'."\n";
  41.  
  42.     // items
  43.     foreach($items as $item)
  44.     {
  45.             $item['description'] = str_replace(array("&","<",">"), array('&amp;', "&lt;", "&gt;"), $item['description']);
  46.             $xml .= '        <item>'."\n";
  47.             $xml .= '            <title>'.$item['title'].'</title>'."\n";
  48.             $xml .= '            <link>'.$item['link'].'</link>'."\n";
  49.             $xml .= '            <pubDate>'.$item['pubDate'].'</pubDate>'."\n";
  50.             $xml .= '            <description>'.$item['description'].'</description>'."\n";
  51.             $xml .= '        </item>'."\n";
  52.     }
  53.  
  54.     $xml .= '    </channel>'."\n";
  55.     $xml .= '</rss>'."\n";
  56.  
  57.     // exit or not ?
  58.     if($write)
  59.         echo $xml;
  60.     else
  61.         return $xml;
  62. }
  63.         
  64. }
  65.  
  66.  
  67. ?>

Documentation generated on Sat, 06 Mar 2010 21:34:00 +0100 by phpDocumentor 1.4.3