[pLog-svn] r1236 - plog/trunk/class/xml/rssparser

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sun Feb 27 23:48:17 GMT 2005


Author: oscar
Date: 2005-02-27 23:48:16 +0000 (Sun, 27 Feb 2005)
New Revision: 1236

Modified:
   plog/trunk/class/xml/rssparser/rssitem.class.php
   plog/trunk/class/xml/rssparser/rssparser.class.php
Log:
added support for rss 2.0 enclosures. Please keep in mind when upgrading the MagpieRSS library that support for enclosures is only provided by a patched on top of the current latest version!

Modified: plog/trunk/class/xml/rssparser/rssitem.class.php
===================================================================
--- plog/trunk/class/xml/rssparser/rssitem.class.php	2005-02-27 22:44:43 UTC (rev 1235)
+++ plog/trunk/class/xml/rssparser/rssitem.class.php	2005-02-27 23:48:16 UTC (rev 1236)
@@ -1,6 +1,7 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+	include_once( PLOG_CLASS_PATH."class/xml/rssparser/rssenclosure.class.php" );
 
     /**
      * <p>Provides information about an RSS item, fetched from an RSS resource.</p>
@@ -11,13 +12,15 @@
      * The array is an associative array where the keys are the name of the attribute/tag and the values are
      * the value of the attribute/tag.</p>
      */
-	class RSSItem extends Object {
+	class RSSItem extends Object 
+	{
 
 		var $_link;
 		var $_title;
 		var $_image;
 		var $_description;
 		var $_item;
+		var $_enclosures;
 
         /**
          * Creates an RSSItem object from the output given by the MagpieRSS parser
@@ -30,6 +33,12 @@
 			$this->_title = $item["title"];
 			$this->_image = $item["image"];
 			$this->_description = $item["description"];
+			
+			// process the enclosures, if any
+			$this->_enclosures = Array();
+			foreach( $item["enclosure"] as $enclosure ) {
+				array_push( $this->_enclosures, new RssEnclosure( $enclosure ));
+			}
 
 			// also keep the item just in case
 			$this->_item = $item;
@@ -96,5 +105,46 @@
 		{
 			return( md5( $this->getLink().$this->getTitle().$this->getDescription()));
 		}
+		
+		/**
+		 * returns one enclosure. If there is more than one, it will only return the first
+		 * one
+		 *
+		 * @return an RssEnclosure object
+		 */
+		function getEnclosure()
+		{
+			return( $this->_enclosures[0] );
+		}
+		
+		/**
+		 * retursn an array of RssEnclosure objects
+		 *
+		 * @return an array of RssEnclosure objects, or an empty array if there was none
+		 */
+		function getEnclosures()
+		{
+			return( $this->_enclosures );
+		}
+		
+		/**
+		 * returns true if the feed has enclosures or false if not
+		 *
+		 * @return boolean
+		 */
+		function hasEnclosures()
+		{
+			return( $this->getNumEnclosures() > 0 );
+		}
+		
+		/**
+		 * returns the number of enclosures that this item has
+		 *
+		 * @return an integer
+		 */
+		function getNumEnclosures()
+		{
+			return( count( $this->_enclosures ));
+		}
 	}
 ?>

Modified: plog/trunk/class/xml/rssparser/rssparser.class.php
===================================================================
--- plog/trunk/class/xml/rssparser/rssparser.class.php	2005-02-27 22:44:43 UTC (rev 1235)
+++ plog/trunk/class/xml/rssparser/rssparser.class.php	2005-02-27 23:48:16 UTC (rev 1236)
@@ -34,7 +34,8 @@
      * <p>If the RSS parser has been disabled via the configuration file, then the constructor will not do
      * anything and the parse method will return false.</p>
      */
-	class RSSParser extends Object {
+	class RSSParser extends Object 
+	{
 
 		var $_items;
 		var $_channel;
@@ -46,6 +47,9 @@
 		function RSSParser()
 		{
 			$this->_channel = "";
+			
+			$config =& Config::getConfig();
+			define( 'MAGPIE_CACHE_DIR', $config->getTempFolder());
 		}
 
         /**




More information about the pLog-svn mailing list