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. @link     http://pear.php.net/package/Services_Blogging
  16. */
  17. {
  18.     /**
  19.     * Array with property values.
  20.     *
  21.     * @var array 
  22.     */
  23.     protected $values = array(
  24.         'id'    => null
  25.     );
  26.  
  27.     /**
  28.     * The driver that will be used (optional).
  29.     * If set, the __set and __get methods can check if the
  30.     * properties are allowed or not.
  31.     *
  32.     * @var Services_Blogging_Driver 
  33.     */
  34.     protected $driver = null;
  35.  
  36.  
  37.  
  38.     /**
  39.     * Class constants that help define the post.
  40.     */
  41.  
  42.     /**
  43.     * Title of the blog post entry.
  44.     * string
  45.     */
  46.     const TITLE = 'title';
  47.  
  48.     /**
  49.     * Text/content for the entry.
  50.     */
  51.     const CONTENT = 'content';
  52.  
  53.     /**
  54.     * Date at which the post shall be published.
  55.     * If set, it has to be a unix timestamp (int)
  56.     */
  57.     const PUBDATE = 'publishdate';
  58.  
  59.     /**
  60.     * Date at which the post has been written.
  61.     * If set, it has to be a unix timestamp (int)
  62.     */
  63.     const DATE = 'date';
  64.  
  65.     /**
  66.     * Where to find the entry. Read-only because
  67.     * the blogging service determines it.
  68.     */
  69.     const URL = 'url';
  70.  
  71.     /**
  72.     * Array of categories (tags) to use.
  73.     */
  74.     const CATEGORIES = 'categories';
  75.  
  76.     /**
  77.      * String (url) when you post a link.
  78.      */
  79.     const LINK = 'link';
  80.  
  81.     /**
  82.      * String (e.g. url of a picture, or a source of a quote)
  83.      */
  84.     const SOURCE = 'source';
  85.     
  86.     /**
  87.      * String binary of a file upload.
  88.      */
  89.     const DATA = 'data';
  90.     
  91.     /**
  92.      * String.
  93.      */
  94.     const CAPTION = 'caption';
  95.  
  96.     /**
  97.     * Not used yet
  98.     */
  99.     const AUTHOR    = 'author';
  100.     const CATEGORY  = 'categories';
  101.     const COMMENTS  = 'comments';
  102.     const ENCLOSURE = 'enclosure';
  103.     const GUID      = 'guid';
  104.  
  105.  
  106.     /**
  107.     *  The property isn't supported by the driver.
  108.     */
  109.     const ERROR_UNSUPPORTED_PROPERTY = 401;
  110.  
  111.  
  112.  
  113.     /**
  114.     * Services_Blogging_Post constructor.
  115.     *
  116.     * @param Services_Blogging_Driver $driver Optional driver object
  117.     *                                           for further checks
  118.     */
  119.     public function __construct($driver = null)
  120.     {
  121.         $this->driver = $driver;
  122.     }//public function __construct($driver = null)
  123.  
  124.  
  125.  
  126.     /**
  127.     * Sets an object property
  128.     *
  129.     * @param string $strProperty Name of property
  130.     * @param mixed  $value       New value
  131.     *
  132.     * @return void 
  133.     */
  134.     public function __set($strProperty$value)
  135.     {
  136.         if ($strProperty == 'id'{
  137.             require_once 'Services/Blogging/Exception.php';
  138.             throw new Services_Blogging_Exception(
  139.                 '"id" may be set via setId() only'
  140.             );
  141.         else if ($this->driver !== null
  142.             && !$this->driver->isPostPropertySupported($strProperty)) {
  143.             require_once 'Services/Blogging/Exception.php';
  144.             throw new Services_Blogging_Exception(
  145.                 'Post property "' $strProperty
  146.                  . '" is not supported by this driver',
  147.                 self::ERROR_UNSUPPORTED_PROPERTY
  148.             );
  149.         }
  150.  
  151.         $this->values[$strProperty$value;
  152.     }//public function __set($strProperty, $value)
  153.  
  154.  
  155.  
  156.     /**
  157.     * Retrieves an object property
  158.     *
  159.     * @param string $strProperty Name of property
  160.     *
  161.     * @return mixed Property value
  162.     */
  163.     public function __get($strProperty)
  164.     {
  165.         if ($strProperty == 'id'{
  166.             return $this->values['id'];
  167.         else if ($this->driver !== null
  168.             && !$this->driver->isPostPropertySupported($strProperty)) {
  169.             require_once 'Services/Blogging/Exception.php';
  170.             throw new Services_Blogging_Exception(
  171.                 'Post property "' $strProperty
  172.                  . '" is not supported by this driver',
  173.                 self::ERROR_UNSUPPORTED_PROPERTY
  174.             );
  175.         else if (!isset($this->values[$strProperty])) {
  176.             return null;
  177.         }
  178.         return $this->values[$strProperty];
  179.     }//public function __get($strProperty)
  180.  
  181.  
  182.  
  183.     /**
  184.     * Sets the post id. This method should only be
  185.     * used by the driver implementations that just uploaded
  186.     * a post to the blog, and it got an id now.
  187.     *
  188.     * @param int $id The blog post id
  189.     *
  190.     * @return void 
  191.     */
  192.     public function setId($id)
  193.     {
  194.         $this->values['id'$id;
  195.     }//public function setId($id)
  196.  
  197.  
  198.  
  199.     /**
  200.     * Set the driver object
  201.     *
  202.     * @param Services_Blogging_Driver $driver Driver object that is used
  203.     *                                           with this blog post
  204.     *
  205.     * @return void 
  206.     */
  207.     public function setDriver($driver)
  208.     {
  209.         $this->driver = $driver;
  210.     }//public function setDriver($driver)
  211.  
  212. }//class Services_Blogging_Post
  213. ?>

Documentation generated on Mon, 11 Mar 2019 15:25:12 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.