web/lib/Zend/Feed/Writer/Deleted.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Feed_Writer
    16  * @package    Zend_Feed_Writer
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Deleted.php 22662 2010-07-24 17:37:36Z mabe $
    19  * @version    $Id: Deleted.php 25160 2012-12-18 15:17:16Z matthew $
    20  */
    20  */
    21 
    21 
    22 require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php';
    22 require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php';
    23  
    23 
    24  /**
    24  /**
    25  * @category   Zend
    25  * @category   Zend
    26  * @package    Zend_Feed_Writer
    26  * @package    Zend_Feed_Writer
    27  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    27  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    28  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    28  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    29  */
    29  */
    30 class Zend_Feed_Writer_Deleted
    30 class Zend_Feed_Writer_Deleted
    31 {
    31 {
    32 
    32 
    34      * Internal array containing all data associated with this entry or item.
    34      * Internal array containing all data associated with this entry or item.
    35      *
    35      *
    36      * @var array
    36      * @var array
    37      */
    37      */
    38     protected $_data = array();
    38     protected $_data = array();
    39     
    39 
    40     /**
    40     /**
    41      * Holds the value "atom" or "rss" depending on the feed type set when
    41      * Holds the value "atom" or "rss" depending on the feed type set when
    42      * when last exported.
    42      * when last exported.
    43      *
    43      *
    44      * @var string
    44      * @var string
    45      */
    45      */
    46     protected $_type = null;
    46     protected $_type = null;
    47     
    47 
    48     /**
    48     /**
    49      * Set the feed character encoding
    49      * Set the feed character encoding
    50      *
    50      *
    51      * @return string|null
    51      * @return string|null
    52      */
    52      */
    69         if (!array_key_exists('encoding', $this->_data)) {
    69         if (!array_key_exists('encoding', $this->_data)) {
    70             return 'UTF-8';
    70             return 'UTF-8';
    71         }
    71         }
    72         return $this->_data['encoding'];
    72         return $this->_data['encoding'];
    73     }
    73     }
    74     
    74 
    75     /**
    75     /**
    76      * Unset a specific data point
    76      * Unset a specific data point
    77      *
    77      *
    78      * @param string $name
    78      * @param string $name
    79      */
    79      */
    81     {
    81     {
    82         if (isset($this->_data[$name])) {
    82         if (isset($this->_data[$name])) {
    83             unset($this->_data[$name]);
    83             unset($this->_data[$name]);
    84         }
    84         }
    85     }
    85     }
    86     
    86 
    87     /**
    87     /**
    88      * Set the current feed type being exported to "rss" or "atom". This allows
    88      * Set the current feed type being exported to "rss" or "atom". This allows
    89      * other objects to gracefully choose whether to execute or not, depending
    89      * other objects to gracefully choose whether to execute or not, depending
    90      * on their appropriateness for the current type, e.g. renderers.
    90      * on their appropriateness for the current type, e.g. renderers.
    91      *
    91      *
    93      */
    93      */
    94     public function setType($type)
    94     public function setType($type)
    95     {
    95     {
    96         $this->_type = $type;
    96         $this->_type = $type;
    97     }
    97     }
    98     
    98 
    99     /**
    99     /**
   100      * Retrieve the current or last feed type exported.
   100      * Retrieve the current or last feed type exported.
   101      *
   101      *
   102      * @return string Value will be "rss" or "atom"
   102      * @return string Value will be "rss" or "atom"
   103      */
   103      */
   104     public function getType()
   104     public function getType()
   105     {
   105     {
   106         return $this->_type;
   106         return $this->_type;
   107     }
   107     }
   108     
   108 
   109     public function setReference($reference)
   109     public function setReference($reference)
   110     {
   110     {
   111         if (empty($reference) || !is_string($reference)) {
   111         if (empty($reference) || !is_string($reference)) {
   112             require_once 'Zend/Feed/Exception.php';
   112             require_once 'Zend/Feed/Exception.php';
   113             throw new Zend_Feed_Exception('Invalid parameter: reference must be a non-empty string');
   113             throw new Zend_Feed_Exception('Invalid parameter: reference must be a non-empty string');
   114         }
   114         }
   115         $this->_data['reference'] = $reference;
   115         $this->_data['reference'] = $reference;
   116     }
   116     }
   117     
   117 
   118     public function getReference()
   118     public function getReference()
   119     {
   119     {
   120         if (!array_key_exists('reference', $this->_data)) {
   120         if (!array_key_exists('reference', $this->_data)) {
   121             return null;
   121             return null;
   122         }
   122         }
   123         return $this->_data['reference'];
   123         return $this->_data['reference'];
   124     }
   124     }
   125     
   125 
   126     public function setWhen($date = null)
   126     public function setWhen($date = null)
   127     {
   127     {
   128         $zdate = null;
   128         $zdate = null;
   129         if ($date === null) {
   129         if ($date === null) {
   130             $zdate = new Zend_Date;
   130             $zdate = new Zend_Date;
   131         } elseif (ctype_digit($date) && strlen($date) == 10) {
       
   132             $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
       
   133         } elseif ($date instanceof Zend_Date) {
   131         } elseif ($date instanceof Zend_Date) {
   134             $zdate = $date;
   132             $zdate = $date;
       
   133         } elseif (ctype_digit((string)$date)) {
       
   134             $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
   135         } else {
   135         } else {
   136             require_once 'Zend/Feed/Exception.php';
   136             require_once 'Zend/Feed/Exception.php';
   137             throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
   137             throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
   138         }
   138         }
   139         $this->_data['when'] = $zdate;
   139         $this->_data['when'] = $zdate;
   140     }
   140     }
   141     
   141 
   142     public function getWhen()
   142     public function getWhen()
   143     {
   143     {
   144         if (!array_key_exists('when', $this->_data)) {
   144         if (!array_key_exists('when', $this->_data)) {
   145             return null;
   145             return null;
   146         }
   146         }
   147         return $this->_data['when'];
   147         return $this->_data['when'];
   148     }
   148     }
   149     
   149 
   150     public function setBy(array $by)
   150     public function setBy(array $by)
   151     {
   151     {
   152         $author = array();
   152         $author = array();
   153         if (!array_key_exists('name', $by) 
   153         if (!array_key_exists('name', $by)
   154             || empty($by['name']) 
   154             || empty($by['name'])
   155             || !is_string($by['name'])
   155             || !is_string($by['name'])
   156         ) {
   156         ) {
   157             require_once 'Zend/Feed/Exception.php';
   157             require_once 'Zend/Feed/Exception.php';
   158             throw new Zend_Feed_Exception('Invalid parameter: author array must include a "name" key with a non-empty string value');
   158             throw new Zend_Feed_Exception('Invalid parameter: author array must include a "name" key with a non-empty string value');
   159         }
   159         }
   164                 throw new Zend_Feed_Exception('Invalid parameter: "email" array value must be a non-empty string');
   164                 throw new Zend_Feed_Exception('Invalid parameter: "email" array value must be a non-empty string');
   165             }
   165             }
   166             $author['email'] = $by['email'];
   166             $author['email'] = $by['email'];
   167         }
   167         }
   168         if (isset($by['uri'])) {
   168         if (isset($by['uri'])) {
   169             if (empty($by['uri']) 
   169             if (empty($by['uri'])
   170                 || !is_string($by['uri']) 
   170                 || !is_string($by['uri'])
   171                 || !Zend_Uri::check($by['uri'])
   171                 || !Zend_Uri::check($by['uri'])
   172             ) {
   172             ) {
   173                 require_once 'Zend/Feed/Exception.php';
   173                 require_once 'Zend/Feed/Exception.php';
   174                 throw new Zend_Feed_Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
   174                 throw new Zend_Feed_Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
   175             }
   175             }
   176             $author['uri'] = $by['uri'];
   176             $author['uri'] = $by['uri'];
   177         }
   177         }
   178         $this->_data['by'] = $author;
   178         $this->_data['by'] = $author;
   179     }
   179     }
   180     
   180 
   181     public function getBy()
   181     public function getBy()
   182     {
   182     {
   183         if (!array_key_exists('by', $this->_data)) {
   183         if (!array_key_exists('by', $this->_data)) {
   184             return null;
   184             return null;
   185         }
   185         }
   186         return $this->_data['by'];
   186         return $this->_data['by'];
   187     }
   187     }
   188     
   188 
   189     public function setComment($comment)
   189     public function setComment($comment)
   190     {
   190     {
   191         $this->_data['comment'] = $comment;
   191         $this->_data['comment'] = $comment;
   192     }
   192     }
   193     
   193 
   194     public function getComment()
   194     public function getComment()
   195     {
   195     {
   196         if (!array_key_exists('comment', $this->_data)) {
   196         if (!array_key_exists('comment', $this->_data)) {
   197             return null;
   197             return null;
   198         }
   198         }