Services_Blogging
[ class tree: Services_Blogging ] [ index: Services_Blogging ] [ all elements ]

Source for file Post.php

Documentation is available at Post.php

  1. <?php
  2. require_once 'Services/Blogging/Driver.php';
  3.  
  4. /**
  5. *   Generic blog post object.
  6. *
  7. *   This class defines a generic post object that may be used
  8. *   to send or receive data in a common format to blogs.
  9. *
  10. *   @category    Services
  11. *   @package     Services_Blogging
  12. *   @author      Anant Narayanan <anant@php.net>
  13. *   @author      Christian Weiske <cweiske@php.net>
  14. *   @license     http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  15. */
  16. {
  17.     /**
  18.     *   Array with property values.
  19.     *
  20.     *   @var array 
  21.     */
  22.     protected $values = array(
  23.         'id'    => null
  24.     );
  25.  
  26.     /**
  27.     *   The driver that will be used (optional).
  28.     *   If set, the __set and __get methods can check if the
  29.     *   properties are allowed or not.
  30.     *
  31.     *   @var Services_Blogging_Driver 
  32.     */
  33.     protected $driver = null;
  34.  
  35.  
  36.  
  37.     /**
  38.     * Class constants that help define the post.
  39.     */
  40.  
  41.     /**
  42.     *   Title of the blog post entry.
  43.     *   string
  44.     */
  45.     const TITLE      = 'title';
  46.  
  47.     /**
  48.     *   Text/content for the entry.
  49.     */
  50.     const CONTENT    = 'content';
  51.  
  52.     /**
  53.     *   Date at which the post shall be published.
  54.     *   If set, it has to be a unix timestamp (int)
  55.     */
  56.     const PUBDATE    = 'publishdate';
  57.  
  58.     /**
  59.     *   Date at which the post has been written.
  60.     *   If set, it has to be a unix timestamp (int)
  61.     */
  62.     const DATE       = 'date';
  63.  
  64.     /**
  65.     *   Where to find the entry. Read-only because
  66.     *   the blogging service determines it.
  67.     */
  68.     const URL        = 'url';
  69.  
  70.     /**
  71.     *   Array of categories (tags) to use.
  72.     */
  73.     const CATEGORIES = 'categories';
  74.  
  75.     /**
  76.     *   Not used yet
  77.     */
  78.     const LINK       = 'link';
  79.     const AUTHOR     = 'author';
  80.     const CATEGORY   = 'categories';
  81.     const COMMENTS   = 'comments';
  82.     const ENCLOSURE  = 'enclosure';
  83.     const GUID       = 'guid';
  84.     const SOURCE     = 'source';
  85.  
  86.  
  87.  
  88.     /**
  89.     *  The property isn't supported by the driver.
  90.     */
  91.     const ERROR_UNSUPPORTED_PROPERTY = 401;
  92.  
  93.  
  94.  
  95.     /**
  96.     *   Services_Blogging_Post constructor.
  97.     *
  98.     *   @param Services_Blogging_Driver $driver  Optional driver object for further checks
  99.     */
  100.     public function __construct($driver = null)
  101.     {
  102.         $this->driver $driver;
  103.     }//public function __construct($driver = null)
  104.  
  105.  
  106.  
  107.     
  108.     public function __set($strProperty$value)
  109.     {
  110.         if ($strProperty == 'id'{
  111.             require_once 'Services/Blogging/Exception.php';
  112.             throw new Services_Blogging_Exception('"id" may be set via setId() only');
  113.  
  114.         else if ($this->driver !== null
  115.             && !$this->driver->isPostPropertySupported($strProperty)) {
  116.             require_once 'Services/Blogging/Exception.php';
  117.             throw new Services_Blogging_Exception(
  118.                 'Post property "' $strProperty '" is not supported by this driver',
  119.                 self::ERROR_UNSUPPORTED_PROPERTY
  120.             );
  121.         }
  122.  
  123.         $this->values[$strProperty$value;
  124.     }//public function __set($strProperty, $value)
  125.  
  126.  
  127.  
  128.     
  129.     public function __get($strProperty)
  130.     {
  131.         if ($strProperty == 'id'{
  132.             return $this->values['id'];
  133.         else if ($this->driver !== null
  134.             && !$this->driver->isPostPropertySupported($strProperty)) {
  135.             require_once 'Services/Blogging/Exception.php';
  136.             throw new Services_Blogging_Exception(
  137.                 'Post property "' $strProperty '" is not supported by this driver',
  138.                 self::ERROR_UNSUPPORTED_PROPERTY
  139.             );
  140.         else if (!isset($this->values[$strProperty])) {
  141.             return null;
  142.         }
  143.         return $this->values[$strProperty];
  144.     }//public function __get($strProperty)
  145.  
  146.  
  147.  
  148.     
  149.     /**
  150.     *   Sets the post id. This method should only be
  151.     *   used by the driver implementations that just uploaded
  152.     *   a post to the blog, and it got an id now.
  153.     *
  154.     *   @param int  The blog post id
  155.     */
  156.     public function setId($id)
  157.     {
  158.         $this->values['id'$id;
  159.     }//public function setId($id)
  160.  
  161.  
  162.  
  163.     
  164.     /**
  165.     *   Set the driver object
  166.     */
  167.     public function setDriver($driver)
  168.     {
  169.         $this->driver $driver;
  170.     }//public function setDriver($driver)
  171.  
  172. }//class Services_Blogging_Post
  173. ?>

Documentation generated on Sat, 27 Jan 2007 12:00:11 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.