Source for file entry.php

Documentation is available at entry.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Feed
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Class to encapsulate a feed entry for the Joomla Platform.
  14.  *
  15.  * @property  JFeedPerson  $author         Person responsible for feed entry content.
  16.  * @property  array        $categories     Categories to which the feed entry belongs.
  17.  * @property  string       $content        The content of the feed entry.
  18.  * @property  array        $contributors   People who contributed to the feed entry content.
  19.  * @property  string       $copyright      Information about rights, e.g. copyrights, held in and over the feed entry.
  20.  * @property  array        $links          Links associated with the feed entry.
  21.  * @property  JDate        $publishedDate  The publication date for the feed entry.
  22.  * @property  JFeed        $source         The feed from which the entry is sourced.
  23.  * @property  string       $title          A human readable title for the feed entry.
  24.  * @property  JDate        $updatedDate    The last time the content of the feed entry changed.
  25.  * @property  string       $uri            Universal, permanent identifier for the feed entry.
  26.  *
  27.  * @package     Joomla.Platform
  28.  * @subpackage  Feed
  29.  * @since       12.3
  30.  */
  31. class JFeedEntry
  32. {
  33.     /**
  34.      * @var    array  The entry properties.
  35.      * @since  12.3
  36.      */
  37.     protected $properties = array(
  38.         'uri'  => '',
  39.         'title' => '',
  40.         'updatedDate' => '',
  41.         'content' => '',
  42.         'categories' => array(),
  43.         'contributors' => array(),
  44.         'links' => array()
  45.     );
  46.  
  47.     /**
  48.      * Magic method to return values for feed entry properties.
  49.      *
  50.      * @param   string  $name  The name of the property.
  51.      *
  52.      * @return  mixed 
  53.      *
  54.      * @since   12.3
  55.      */
  56.     public function __get($name)
  57.     {
  58.         return (isset($this->properties[$name])) $this->properties[$namenull;
  59.     }
  60.  
  61.     /**
  62.      * Magic method to set values for feed properties.
  63.      *
  64.      * @param   string  $name   The name of the property.
  65.      * @param   mixed   $value  The value to set for the property.
  66.      *
  67.      * @return  void 
  68.      *
  69.      * @since   12.3
  70.      */
  71.     public function __set($name$value)
  72.     {
  73.         // Ensure that setting a date always sets a JDate instance.
  74.         if ((($name == 'updatedDate'|| ($name == 'publishedDate')) && !($value instanceof JDate))
  75.         {
  76.             $value new JDate($value);
  77.         }
  78.  
  79.         // Validate that any authors that are set are instances of JFeedPerson or null.
  80.         if (($name == 'author'&& (!($value instanceof JFeedPerson|| ($value === null)))
  81.         {
  82.             throw new InvalidArgumentException('JFeedEntry "author" must be of type JFeedPerson. ' gettype($value'given.');
  83.         }
  84.  
  85.         // Validate that any sources that are set are instances of JFeed or null.
  86.         if (($name == 'source'&& (!($value instanceof JFeed|| ($value === null)))
  87.         {
  88.             throw new InvalidArgumentException('JFeedEntry "source" must be of type JFeed. ' gettype($value'given.');
  89.         }
  90.  
  91.         // Disallow setting categories, contributors, or links directly.
  92.         if (($name == 'categories'|| ($name == 'contributors'|| ($name == 'links'))
  93.         {
  94.             throw new InvalidArgumentException('Cannot directly set JFeedEntry property "' $name '".');
  95.         }
  96.  
  97.         $this->properties[$name$value;
  98.     }
  99.  
  100.     /**
  101.      * Method to add a category to the feed entry object.
  102.      *
  103.      * @param   string  $name  The name of the category to add.
  104.      * @param   string  $uri   The optional URI for the category to add.
  105.      *
  106.      * @return  JFeedEntry 
  107.      *
  108.      * @since   12.3
  109.      */
  110.     public function addCategory($name$uri '')
  111.     {
  112.         $this->properties['categories'][$name$uri;
  113.  
  114.         return $this;
  115.     }
  116.  
  117.     /**
  118.      * Method to add a contributor to the feed entry object.
  119.      *
  120.      * @param   string  $name   The full name of the person to add.
  121.      * @param   string  $email  The email address of the person to add.
  122.      * @param   string  $uri    The optional URI for the person to add.
  123.      * @param   string  $type   The optional type of person to add.
  124.      *
  125.      * @return  JFeedEntry 
  126.      *
  127.      * @since   12.3
  128.      */
  129.     public function addContributor($name$email$uri null$type null)
  130.     {
  131.         $contributor new JFeedPerson($name$email$uri$type);
  132.  
  133.         // If the new contributor already exists then there is nothing to do, so just return.
  134.         foreach ($this->properties['contributors'as $c)
  135.         {
  136.             if ($c == $contributor)
  137.             {
  138.                 return $this;
  139.             }
  140.         }
  141.  
  142.         // Add the new contributor.
  143.         $this->properties['contributors'][$contributor;
  144.  
  145.         return $this;
  146.     }
  147.  
  148.     /**
  149.      * Method to add a link to the feed entry object.
  150.      *
  151.      * @param   JFeedLink  $link  The link object to add.
  152.      *
  153.      * @return  JFeedEntry 
  154.      *
  155.      * @since   12.3
  156.      */
  157.     public function addLink(JFeedLink $link)
  158.     {
  159.         // If the new link already exists then there is nothing to do, so just return.
  160.         foreach ($this->properties['links'as $l)
  161.         {
  162.             if ($l == $link)
  163.             {
  164.                 return $this;
  165.             }
  166.         }
  167.  
  168.         // Add the new link.
  169.         $this->properties['links'][$link;
  170.  
  171.         return $this;
  172.     }
  173.  
  174.     /**
  175.      * Method to remove a category from the feed entry object.
  176.      *
  177.      * @param   string  $name  The name of the category to remove.
  178.      *
  179.      * @return  JFeedEntry 
  180.      *
  181.      * @since   12.3
  182.      */
  183.     public function removeCategory($name)
  184.     {
  185.         unset($this->properties['categories'][$name]);
  186.  
  187.         return $this;
  188.     }
  189.  
  190.     /**
  191.      * Method to remove a contributor from the feed entry object.
  192.      *
  193.      * @param   JFeedPerson  $contributor  The person object to remove.
  194.      *
  195.      * @return  JFeedEntry 
  196.      *
  197.      * @since   12.3
  198.      */
  199.     public function removeContributor(JFeedPerson $contributor)
  200.     {
  201.         // If the contributor exists remove it.
  202.         foreach ($this->properties['contributors'as $k => $c)
  203.         {
  204.             if ($c == $contributor)
  205.             {
  206.                 unset($this->properties['contributors'][$k]);
  207.                 $this->properties['contributors'array_values($this->properties['contributors']);
  208.  
  209.                 return $this;
  210.             }
  211.         }
  212.  
  213.         return $this;
  214.     }
  215.  
  216.     /**
  217.      * Method to remove a link from the feed entry object.
  218.      *
  219.      * @param   JFeedLink  $link  The link object to remove.
  220.      *
  221.      * @return  JFeedEntry 
  222.      *
  223.      * @since   12.3
  224.      */
  225.     public function removeLink(JFeedLink $link)
  226.     {
  227.         // If the link exists remove it.
  228.         foreach ($this->properties['links'as $k => $l)
  229.         {
  230.             if ($l == $link)
  231.             {
  232.                 unset($this->properties['links'][$k]);
  233.                 $this->properties['links'array_values($this->properties['links']);
  234.  
  235.                 return $this;
  236.             }
  237.         }
  238.  
  239.         return $this;
  240.     }
  241.  
  242.     /**
  243.      * Shortcut method to set the author for the feed entry object.
  244.      *
  245.      * @param   string  $name   The full name of the person to set.
  246.      * @param   string  $email  The email address of the person to set.
  247.      * @param   string  $uri    The optional URI for the person to set.
  248.      * @param   string  $type   The optional type of person to set.
  249.      *
  250.      * @return  JFeedEntry 
  251.      *
  252.      * @since   12.3
  253.      */
  254.     public function setAuthor($name$email$uri null$type null)
  255.     {
  256.         $author new JFeedPerson($name$email$uri$type);
  257.  
  258.         $this->properties['author'$author;
  259.  
  260.         return $this;
  261.     }
  262. }

Documentation generated on Tue, 19 Nov 2013 15:02:30 +0100 by phpDocumentor 1.4.3