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.     public function __set($strProperty$value)
  108.     {
  109.         if ($strProperty == 'id'{
  110.             require_once 'Services/Blogging/Exception.php';
  111.             throw new Services_Blogging_Exception('"id" may be set via setId() only');
  112.  
  113.         else if ($this->driver !== null
  114.             && !$this->driver->isPostPropertySupported($strProperty)) {
  115.             require_once 'Services/Blogging/Exception.php';
  116.             throw new Services_Blogging_Exception(
  117.                 'Post property "' $strProperty '" is not supported by this driver',
  118.                 self::ERROR_UNSUPPORTED_PROPERTY
  119.             );
  120.         }
  121.  
  122.         $this->values[$strProperty$value;
  123.     }//public function __set($strProperty, $value)
  124.  
  125.  
  126.  
  127.     public function __get($strProperty)
  128.     {
  129.         if ($strProperty == 'id'{
  130.             return $this->values['id'];
  131.         else if ($this->driver !== null
  132.             && !$this->driver->isPostPropertySupported($strProperty)) {
  133.             require_once 'Services/Blogging/Exception.php';
  134.             throw new Services_Blogging_Exception(
  135.                 'Post property "' $strProperty '" is not supported by this driver',
  136.                 self::ERROR_UNSUPPORTED_PROPERTY
  137.             );
  138.         else if (!isset($this->values[$strProperty])) {
  139.             return null;
  140.         }
  141.         return $this->values[$strProperty];
  142.     }//public function __get($strProperty)
  143.  
  144.  
  145.  
  146.     /**
  147.     *   Sets the post id. This method should only be
  148.     *   used by the driver implementations that just uploaded
  149.     *   a post to the blog, and it got an id now.
  150.     *
  151.     *   @param int  The blog post id
  152.     */
  153.     public function setId($id)
  154.     {
  155.         $this->values['id'$id;
  156.     }//public function setId($id)
  157.  
  158.  
  159.  
  160.     /**
  161.     *   Set the driver object
  162.     */
  163.     public function setDriver($driver)
  164.     {
  165.         $this->driver = $driver;
  166.     }//public function setDriver($driver)
  167.  
  168. }//class Services_Blogging_Post
  169. ?>

Documentation generated on Mon, 11 Mar 2019 14:57:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.