[ 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/ -> rssitem.class.php (source)

   1  <?php
   2  
   3      
   4      lt_include( PLOG_CLASS_PATH."class/xml/rssparser/rssenclosure.class.php" );
   5  
   6      /**
   7       * \ingroup XML
   8       *
   9       * <p>Provides information about an RSS item, fetched from an RSS resource.</p>
  10       * <p>This class provides methods to get the value of some of the attributes and possible child
  11       * tags of the &lt;item&lt; tag. In case we need to know about any other value that is not available
  12       * via one of the 'getter' functions (getTitle(), getImage(), getDescription(), getLink()), we can then get
  13       * values from the resulting array as generated by the underlying RSS parser using the get() function.
  14       * The array is an associative array where the keys are the name of the attribute/tag and the values are
  15       * the value of the attribute/tag.</p>
  16       */
  17      class RSSItem  
  18      {
  19  
  20          var $_link;
  21          var $_title;
  22          var $_image;
  23          var $_description;
  24          var $_item;
  25          var $_enclosures;
  26  
  27          /**
  28           * Creates an RSSItem object from the output given by the MagpieRSS parser
  29           *
  30           * @param item The RSS item.
  31           */
  32  		function RSSItem( $item )
  33          {
  34              $this->_link = isset( $item["link"] ) ? $item["link"] : "";
  35              $this->_title = isset( $item["title"] ) ? $item["title"] : "";
  36              $this->_image = isset( $item["image"] ) ? $item["image"] : "";
  37              $this->_description = isset( $item["description"] ) ? $item["description"] : "";
  38              
  39              // process the enclosures, if any
  40              $this->_enclosures = Array();
  41              if( isset( $item["enclosure"] )) {
  42                  if( is_array( $item["enclosure"] )) {
  43                      foreach( $item["enclosure"] as $enclosure ) {
  44                          array_push( $this->_enclosures, new RssEnclosure( $enclosure ));
  45                      }
  46                  }
  47              }
  48  
  49              // also keep the item just in case
  50              $this->_item = $item;
  51          }
  52  
  53          /**
  54           * Returns the link assigned to the item.
  55           *
  56           * @return The link assigned to the item.
  57           */
  58  		function getLink()
  59          {
  60              return $this->_link;
  61          }
  62  
  63          /**
  64           * Returns the title assigned to the link.
  65           *
  66           * @return Title assigned to the link.
  67           */
  68  		function getTitle()
  69          {
  70              return $this->_title;
  71          }
  72  
  73          /**
  74           * Image assigned to the item
  75           *
  76           * @return URI of the image assigned to this item
  77           */
  78  		function getImage()
  79          {
  80              return $this->_image;
  81          }
  82  
  83          /**
  84           * Description assigned to this item.
  85           *
  86           * @param Description assigned to the item.
  87           */
  88  		function getDescription()
  89          {
  90              return $this->_description;
  91          }
  92  
  93          /**
  94           * Even though we provide convenience methods for the most used fields of the
  95           * object, might be good to provide one to access the 'item' array generically
  96           *
  97           * @param key Name assigned to the item
  98           * @return The value of the item.
  99           */
 100  		function get( $key )
 101          {
 102              return $this->_item[$key];
 103          }
 104          
 105          /**
 106           * returns a unique id for this item
 107           *
 108           * @return a unique id
 109           */
 110  		function getUniqueId()
 111          {
 112              return( md5( $this->getLink().$this->getTitle().$this->getDescription()));
 113          }
 114          
 115          /**
 116           * returns one enclosure. If there is more than one, it will only return the first
 117           * one
 118           *
 119           * @return an RssEnclosure object
 120           */
 121  		function getEnclosure()
 122          {
 123              return( $this->_enclosures[0] );
 124          }
 125          
 126          /**
 127           * retursn an array of RssEnclosure objects
 128           *
 129           * @return an array of RssEnclosure objects, or an empty array if there was none
 130           */
 131  		function getEnclosures()
 132          {
 133              return( $this->_enclosures );
 134          }
 135          
 136          /**
 137           * returns true if the feed has enclosures or false if not
 138           *
 139           * @return boolean
 140           */
 141  		function hasEnclosures()
 142          {
 143              return( $this->getNumEnclosures() > 0 );
 144          }
 145          
 146          /**
 147           * returns the number of enclosures that this item has
 148           *
 149           * @return an integer
 150           */
 151  		function getNumEnclosures()
 152          {
 153              return( count( $this->_enclosures ));
 154          }
 155      }
 156  ?>


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