[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/xml/rssparser/ -> rssparser.class.php (source)

   1  <?php    
   2      /**
   3       * \ingroup XML
   4       *
   5       * <p>This parser is a wrapper around the functionality provided by the MagpieRSS parser, which
   6       * can be found at http://magpierss.sourceforge.net/. The RSS parser is compatible with
   7       * RSS 0.9, 1.0 and almost all the modules of the 1.0 specification.</p>
   8       * <p>This object is exported to all templates so that we can easily incorporate the headlines
   9       * and/or the content of other pages in our journal. To do so, this object is exported with
  10       * "rss" as its identifier, so a simple operation to fetch the headlines from Slashdot would
  11       * look like:</p>
  12       *
  13       * <pre>
  14       * {if $rss->parse("http://slashdot.org/slashdot.rdf")}
  15       *  {foreach from=$rss->getItems() item=rssItem}
  16       *    <a href="{$rssItem->getLink()}">{$rssItem->getTitle()}</a>
  17       *  {/foreach}
  18       * {/if}
  19       * </pre>
  20       *
  21       * <p>The parse() method takes a url as a parameter, and it will return true if the url
  22       * was correctly fetched. If so, we can then ask the parser to gives us an array of
  23       * RSSItem objects which contain information about all the different &lt;item&gt; tags that were
  24       * found in the RSS feed. So, the only thing we have to do now is iterate through the array using
  25       * Smarty's <i>{foreach ...}</i> construction and call the appropiate methods on the RSSItem object.</p>
  26       * <p>To get more information about the channel (whatever was found between the &lt;channel&gt; opening
  27       * and closing tag) we can call the getChannel() function and we will get a nice and ready RSSChannel
  28       * information that we need to know.</p>
  29       * <p>If the RSS parser has been disabled via the configuration file, then the constructor will not do
  30       * anything and the parse method will return false.</p>
  31       */
  32      class RSSParser  
  33      {
  34  
  35          var $_items;
  36          var $_channel;
  37  
  38          /***
  39           * The constructor checks if the RSS parser is enabled in the configuration file. If it is
  40           * not, it simply quits.
  41           */
  42  		function RSSParser()
  43          {
  44              $this->_channel = "";
  45              
  46              $config =& Config::getConfig();
  47              define( 'MAGPIE_CACHE_DIR', $config->getTempFolder());
  48          }
  49  
  50          /**
  51           * Parses an RSS feed
  52           *
  53           * @param rssFeed The URL of the RSS feed.
  54           * @return Returns true if the parsing was successful.
  55           */
  56  		function parse( $rssFeed )
  57          {
  58              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/rsschannel.class.php" );
  59              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/magpierss/rss_fetch.inc" );    
  60              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/magpierss/rss_cache.inc" );
  61              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/magpierss/rss_parse.inc" );
  62              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/magpierss/rss_utils.inc" );
  63              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/rssitem.class.php" );
  64  
  65              $rss = fetch_rss( $rssFeed );
  66  
  67              if( !$rss )
  68                  return false;
  69  
  70              $this->_channel = new RSSChannel( $rss->channel );
  71  
  72              $this->_items = Array();
  73              foreach ($rss->items as $item ) {
  74                  $itemObject = new RSSItem( $item );
  75                  array_push( $this->_items, $itemObject );
  76              }
  77  
  78              return true;
  79          }
  80  
  81          /**
  82           * Returns the items obtained from parsing the last RSS source specified
  83           *
  84           * @return An array of RSSItem objects
  85           */
  86  		function getItems()
  87          {
  88              return $this->_items;
  89          }
  90  
  91          /**
  92           * Returns information about the channel parsed.
  93           *
  94           * @return An RSSChannel object containing information about the last RSS
  95           * source parsed.
  96           */
  97  		function getChannel()
  98          {
  99              return $this->_channel;
 100          }
 101      }
 102  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics