home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Services / Blogging / Post.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.0 KB  |  214 lines

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