web/enmi/Zend/Feed/Builder/Header.php
changeset 19 1c2f13fd785c
parent 0 4eba9c11703f
equal deleted inserted replaced
18:bd595ad770fc 19:1c2f13fd785c
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Zend Framework
       
     5  *
       
     6  * LICENSE
       
     7  *
       
     8  * This source file is subject to the new BSD license that is bundled
       
     9  * with this package in the file LICENSE.txt.
       
    10  * It is also available through the world-wide-web at this URL:
       
    11  * http://framework.zend.com/license/new-bsd
       
    12  * If you did not receive a copy of the license and are unable to
       
    13  * obtain it through the world-wide-web, please send an email
       
    14  * to license@zend.com so we can send you a copy immediately.
       
    15  *
       
    16  * @category   Zend
       
    17  * @package    Zend_Feed
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Header.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Feed_Builder_Header_Itunes
       
    25  */
       
    26 require_once 'Zend/Feed/Builder/Header/Itunes.php';
       
    27 
       
    28 /**
       
    29  * @see Zend_Uri
       
    30  */
       
    31 require_once 'Zend/Uri.php';
       
    32 
       
    33 
       
    34 /**
       
    35  * Header of a custom build feed
       
    36  *
       
    37  * Classes implementing the Zend_Feed_Builder_Interface interface
       
    38  * uses this class to describe the header of a feed
       
    39  *
       
    40  * @category   Zend
       
    41  * @package    Zend_Feed
       
    42  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    43  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    44  */
       
    45 class Zend_Feed_Builder_Header extends ArrayObject
       
    46 {
       
    47     /**
       
    48      * Constructor
       
    49      *
       
    50      * @param  string $title title of the feed
       
    51      * @param  string $link canonical url of the feed
       
    52      * @param  string $charset charset of the textual data
       
    53      * @return void
       
    54      */
       
    55     public function __construct($title, $link, $charset = 'utf-8')
       
    56     {
       
    57         $this->offsetSet('title', $title);
       
    58         $this->offsetSet('link', $link);
       
    59         $this->offsetSet('charset', $charset);
       
    60         $this->setLastUpdate(time())
       
    61              ->setGenerator('Zend_Feed');
       
    62     }
       
    63 
       
    64     /**
       
    65      * Read only properties accessor
       
    66      *
       
    67      * @param  string $name property to read
       
    68      * @return mixed
       
    69      */
       
    70     public function __get($name)
       
    71     {
       
    72         if (!$this->offsetExists($name)) {
       
    73             return NULL;
       
    74         }
       
    75 
       
    76         return $this->offsetGet($name);
       
    77     }
       
    78 
       
    79     /**
       
    80      * Write properties accessor
       
    81      *
       
    82      * @param string $name  name of the property to set
       
    83      * @param mixed  $value value to set
       
    84      * @return void
       
    85      */
       
    86     public function __set($name, $value)
       
    87     {
       
    88         $this->offsetSet($name, $value);
       
    89     }
       
    90 
       
    91     /**
       
    92      * Isset accessor
       
    93      *
       
    94      * @param  string $key
       
    95      * @return boolean
       
    96      */
       
    97     public function __isset($key)
       
    98     {
       
    99         return $this->offsetExists($key);
       
   100     }
       
   101 
       
   102     /**
       
   103      * Unset accessor
       
   104      *
       
   105      * @param  string $key
       
   106      * @return void
       
   107      */
       
   108     public function __unset($key)
       
   109     {
       
   110         if ($this->offsetExists($key)) {
       
   111             $this->offsetUnset($key);
       
   112         }
       
   113     }
       
   114 
       
   115     /**
       
   116      * Timestamp of the update date
       
   117      *
       
   118      * @param  int $lastUpdate
       
   119      * @return Zend_Feed_Builder_Header
       
   120      */
       
   121     public function setLastUpdate($lastUpdate)
       
   122     {
       
   123         $this->offsetSet('lastUpdate', $lastUpdate);
       
   124         return $this;
       
   125     }
       
   126 
       
   127     /**
       
   128      * Timestamp of the publication date
       
   129      *
       
   130      * @param  int $published
       
   131      * @return Zend_Feed_Builder_Header
       
   132      */
       
   133     public function setPublishedDate($published)
       
   134     {
       
   135         $this->offsetSet('published', $published);
       
   136         return $this;
       
   137     }
       
   138 
       
   139     /**
       
   140      * Short description of the feed
       
   141      *
       
   142      * @param  string $description
       
   143      * @return Zend_Feed_Builder_Header
       
   144      */
       
   145     public function setDescription($description)
       
   146     {
       
   147         $this->offsetSet('description', $description);
       
   148         return $this;
       
   149     }
       
   150 
       
   151     /**
       
   152      * Sets the author of the feed
       
   153      *
       
   154      * @param  string $author
       
   155      * @return Zend_Feed_Builder_Header
       
   156      */
       
   157     public function setAuthor($author)
       
   158     {
       
   159         $this->offsetSet('author', $author);
       
   160         return $this;
       
   161     }
       
   162 
       
   163     /**
       
   164      * Sets the author's email
       
   165      *
       
   166      * @param  string $email
       
   167      * @return Zend_Feed_Builder_Header
       
   168      * @throws Zend_Feed_Builder_Exception
       
   169      */
       
   170     public function setEmail($email)
       
   171     {
       
   172         /**
       
   173          * @see Zend_Validate_EmailAddress
       
   174          */
       
   175         require_once 'Zend/Validate/EmailAddress.php';
       
   176         $validate = new Zend_Validate_EmailAddress();
       
   177         if (!$validate->isValid($email)) {
       
   178             /**
       
   179              * @see Zend_Feed_Builder_Exception
       
   180              */
       
   181             require_once 'Zend/Feed/Builder/Exception.php';
       
   182             throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property");
       
   183         }
       
   184         $this->offsetSet('email', $email);
       
   185         return $this;
       
   186     }
       
   187 
       
   188     /**
       
   189      * Sets the copyright notice
       
   190      *
       
   191      * @param  string $copyright
       
   192      * @return Zend_Feed_Builder_Header
       
   193      */
       
   194     public function setCopyright($copyright)
       
   195     {
       
   196         $this->offsetSet('copyright', $copyright);
       
   197         return $this;
       
   198     }
       
   199 
       
   200     /**
       
   201      * Sets the image of the feed
       
   202      *
       
   203      * @param  string $image
       
   204      * @return Zend_Feed_Builder_Header
       
   205      */
       
   206     public function setImage($image)
       
   207     {
       
   208         $this->offsetSet('image', $image);
       
   209         return $this;
       
   210     }
       
   211 
       
   212     /**
       
   213      * Sets the generator of the feed
       
   214      *
       
   215      * @param  string $generator
       
   216      * @return Zend_Feed_Builder_Header
       
   217      */
       
   218     public function setGenerator($generator)
       
   219     {
       
   220         $this->offsetSet('generator', $generator);
       
   221         return $this;
       
   222     }
       
   223 
       
   224     /**
       
   225      * Sets the language of the feed
       
   226      *
       
   227      * @param  string $language
       
   228      * @return Zend_Feed_Builder_Header
       
   229      */
       
   230     public function setLanguage($language)
       
   231     {
       
   232         $this->offsetSet('language', $language);
       
   233         return $this;
       
   234     }
       
   235 
       
   236     /**
       
   237      * Email address for person responsible for technical issues
       
   238      * Ignored if atom is used
       
   239      *
       
   240      * @param  string $webmaster
       
   241      * @return Zend_Feed_Builder_Header
       
   242      * @throws Zend_Feed_Builder_Exception
       
   243      */
       
   244     public function setWebmaster($webmaster)
       
   245     {
       
   246         /**
       
   247          * @see Zend_Validate_EmailAddress
       
   248          */
       
   249         require_once 'Zend/Validate/EmailAddress.php';
       
   250         $validate = new Zend_Validate_EmailAddress();
       
   251         if (!$validate->isValid($webmaster)) {
       
   252             /**
       
   253              * @see Zend_Feed_Builder_Exception
       
   254              */
       
   255             require_once 'Zend/Feed/Builder/Exception.php';
       
   256             throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property");
       
   257         }
       
   258         $this->offsetSet('webmaster', $webmaster);
       
   259         return $this;
       
   260     }
       
   261 
       
   262     /**
       
   263      * How long in minutes a feed can be cached before refreshing
       
   264      * Ignored if atom is used
       
   265      *
       
   266      * @param  int $ttl
       
   267      * @return Zend_Feed_Builder_Header
       
   268      * @throws Zend_Feed_Builder_Exception
       
   269      */
       
   270     public function setTtl($ttl)
       
   271     {
       
   272         /**
       
   273          * @see Zend_Validate_Int
       
   274          */
       
   275         require_once 'Zend/Validate/Int.php';
       
   276         $validate = new Zend_Validate_Int();
       
   277         if (!$validate->isValid($ttl)) {
       
   278             /**
       
   279              * @see Zend_Feed_Builder_Exception
       
   280              */
       
   281             require_once 'Zend/Feed/Builder/Exception.php';
       
   282             throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property");
       
   283         }
       
   284         $this->offsetSet('ttl', $ttl);
       
   285         return $this;
       
   286     }
       
   287 
       
   288     /**
       
   289      * PICS rating for the feed
       
   290      * Ignored if atom is used
       
   291      *
       
   292      * @param  string $rating
       
   293      * @return Zend_Feed_Builder_Header
       
   294      */
       
   295     public function setRating($rating)
       
   296     {
       
   297         $this->offsetSet('rating', $rating);
       
   298         return $this;
       
   299     }
       
   300 
       
   301     /**
       
   302      * Cloud to be notified of updates of the feed
       
   303      * Ignored if atom is used
       
   304      *
       
   305      * @param  string|Zend_Uri_Http $uri
       
   306      * @param  string               $procedure procedure to call, e.g. myCloud.rssPleaseNotify
       
   307      * @param  string               $protocol  protocol to use, e.g. soap or xml-rpc
       
   308      * @return Zend_Feed_Builder_Header
       
   309      * @throws Zend_Feed_Builder_Exception
       
   310      */
       
   311     public function setCloud($uri, $procedure, $protocol)
       
   312     {
       
   313         if (is_string($uri) && Zend_Uri_Http::check($uri)) {
       
   314             $uri = Zend_Uri::factory($uri);
       
   315         }
       
   316         if (!$uri instanceof Zend_Uri_Http) {
       
   317             /**
       
   318              * @see Zend_Feed_Builder_Exception
       
   319              */
       
   320             require_once 'Zend/Feed/Builder/Exception.php';
       
   321             throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI');
       
   322         }
       
   323         if (!$uri->getPort()) {
       
   324             $uri->setPort(80);
       
   325         }
       
   326         $this->offsetSet('cloud', array('uri' => $uri,
       
   327                                         'procedure' => $procedure,
       
   328                                         'protocol' => $protocol));
       
   329         return $this;
       
   330     }
       
   331 
       
   332     /**
       
   333      * A text input box that can be displayed with the feed
       
   334      * Ignored if atom is used
       
   335      *
       
   336      * @param  string $title       the label of the Submit button in the text input area
       
   337      * @param  string $description explains the text input area
       
   338      * @param  string $name        the name of the text object in the text input area
       
   339      * @param  string $link        the URL of the CGI script that processes text input requests
       
   340      * @return Zend_Feed_Builder_Header
       
   341      */
       
   342     public function setTextInput($title, $description, $name, $link)
       
   343     {
       
   344         $this->offsetSet('textInput', array('title' => $title,
       
   345                                             'description' => $description,
       
   346                                             'name' => $name,
       
   347                                             'link' => $link));
       
   348         return $this;
       
   349     }
       
   350 
       
   351     /**
       
   352      * Hint telling aggregators which hours they can skip
       
   353      * Ignored if atom is used
       
   354      *
       
   355      * @param  array $hours list of hours in 24 format
       
   356      * @return Zend_Feed_Builder_Header
       
   357      * @throws Zend_Feed_Builder_Exception
       
   358      */
       
   359     public function setSkipHours(array $hours)
       
   360     {
       
   361         if (count($hours) > 24) {
       
   362             /**
       
   363              * @see Zend_Feed_Builder_Exception
       
   364              */
       
   365             require_once 'Zend/Feed/Builder/Exception.php';
       
   366             throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property");
       
   367         }
       
   368         foreach ($hours as $hour) {
       
   369             if ($hour < 0 || $hour > 23) {
       
   370                 /**
       
   371                  * @see Zend_Feed_Builder_Exception
       
   372                  */
       
   373                 require_once 'Zend/Feed/Builder/Exception.php';
       
   374                 throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23");
       
   375             }
       
   376         }
       
   377         $this->offsetSet('skipHours', $hours);
       
   378         return $this;
       
   379     }
       
   380 
       
   381     /**
       
   382      * Hint telling aggregators which days they can skip
       
   383      * Ignored if atom is used
       
   384      *
       
   385      * @param  array $days list of days to skip, e.g. Monday
       
   386      * @return Zend_Feed_Builder_Header
       
   387      * @throws Zend_Feed_Builder_Exception
       
   388      */
       
   389     public function setSkipDays(array $days)
       
   390     {
       
   391         if (count($days) > 7) {
       
   392             /**
       
   393              * @see Zend_Feed_Builder_Exception
       
   394              */
       
   395             require_once 'Zend/Feed/Builder/Exception.php';
       
   396             throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property");
       
   397         }
       
   398         $valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
       
   399         foreach ($days as $day) {
       
   400             if (!in_array(strtolower($day), $valid)) {
       
   401                 /**
       
   402                  * @see Zend_Feed_Builder_Exception
       
   403                  */
       
   404                 require_once 'Zend/Feed/Builder/Exception.php';
       
   405                 throw new Zend_Feed_Builder_Exception("$day is not a valid day");
       
   406             }
       
   407         }
       
   408         $this->offsetSet('skipDays', $days);
       
   409         return $this;
       
   410     }
       
   411 
       
   412     /**
       
   413      * Sets the iTunes rss extension
       
   414      *
       
   415      * @param  Zend_Feed_Builder_Header_Itunes $itunes
       
   416      * @return Zend_Feed_Builder_Header
       
   417      */
       
   418     public function setITunes(Zend_Feed_Builder_Header_Itunes $itunes)
       
   419     {
       
   420         $this->offsetSet('itunes', $itunes);
       
   421         return $this;
       
   422     }
       
   423 }