web/Zend/Feed/Builder/Header/Itunes.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     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: Itunes.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /**
       
    25  * ITunes rss extension
       
    26  *
       
    27  * Classes used to describe the itunes channel extension
       
    28  *
       
    29  * @category   Zend
       
    30  * @package    Zend_Feed
       
    31  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  */
       
    34 class Zend_Feed_Builder_Header_Itunes extends ArrayObject
       
    35 {
       
    36     /**
       
    37      * Constructor
       
    38      *
       
    39      * @param  array $categories Categories columns and in iTunes Music Store Browse
       
    40      * @return void
       
    41      */
       
    42     public function __construct(array $categories)
       
    43     {
       
    44         $this->setCategories($categories);
       
    45     }
       
    46 
       
    47     /**
       
    48      * Sets the categories column and in iTunes Music Store Browse
       
    49      * $categories must conform to the following format:
       
    50      * <code>
       
    51      * array(array('main' => 'main category',
       
    52      *             'sub' => 'sub category' // optionnal
       
    53      *            ),
       
    54      *       // up to 3 rows
       
    55      *      )
       
    56      * </code>
       
    57      *
       
    58      * @param  array $categories
       
    59      * @return Zend_Feed_Builder_Header_Itunes
       
    60      * @throws Zend_Feed_Builder_Exception
       
    61      */
       
    62     public function setCategories(array $categories)
       
    63     {
       
    64         $nb = count($categories);
       
    65         if (0 === $nb) {
       
    66             /**
       
    67              * @see Zend_Feed_Builder_Exception
       
    68              */
       
    69             require_once 'Zend/Feed/Builder/Exception.php';
       
    70             throw new Zend_Feed_Builder_Exception("you have to set at least one itunes category");
       
    71         }
       
    72         if ($nb > 3) {
       
    73             /**
       
    74              * @see Zend_Feed_Builder_Exception
       
    75              */
       
    76             require_once 'Zend/Feed/Builder/Exception.php';
       
    77             throw new Zend_Feed_Builder_Exception("you have to set at most three itunes categories");
       
    78         }
       
    79         foreach ($categories as $i => $category) {
       
    80             if (empty($category['main'])) {
       
    81                 /**
       
    82                  * @see Zend_Feed_Builder_Exception
       
    83                  */
       
    84                 require_once 'Zend/Feed/Builder/Exception.php';
       
    85                 throw new Zend_Feed_Builder_Exception("you have to set the main category (category #$i)");
       
    86             }
       
    87         }
       
    88         $this->offsetSet('category', $categories);
       
    89         return $this;
       
    90     }
       
    91 
       
    92     /**
       
    93      * Sets the artist value, default to the feed's author value
       
    94      *
       
    95      * @param  string $author
       
    96      * @return Zend_Feed_Builder_Header_Itunes
       
    97      */
       
    98     public function setAuthor($author)
       
    99     {
       
   100         $this->offsetSet('author', $author);
       
   101         return $this;
       
   102     }
       
   103 
       
   104     /**
       
   105      * Sets the owner of the postcast
       
   106      *
       
   107      * @param  string $name  default to the feed's author value
       
   108      * @param  string $email default to the feed's email value
       
   109      * @return Zend_Feed_Builder_Header_Itunes
       
   110      * @throws Zend_Feed_Builder_Exception
       
   111      */
       
   112     public function setOwner($name = '', $email = '')
       
   113     {
       
   114         if (!empty($email)) {
       
   115             /**
       
   116              * @see Zend_Validate_EmailAddress
       
   117              */
       
   118             require_once 'Zend/Validate/EmailAddress.php';
       
   119             $validate = new Zend_Validate_EmailAddress();
       
   120             if (!$validate->isValid($email)) {
       
   121                 /**
       
   122                  * @see Zend_Feed_Builder_Exception
       
   123                  */
       
   124                 require_once 'Zend/Feed/Builder/Exception.php';
       
   125                 throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the itunes owner's email property");
       
   126             }
       
   127         }
       
   128         $this->offsetSet('owner', array('name' => $name, 'email' => $email));
       
   129         return $this;
       
   130     }
       
   131 
       
   132     /**
       
   133      * Sets the album/podcast art picture
       
   134      * Default to the feed's image value
       
   135      *
       
   136      * @param  string $image
       
   137      * @return Zend_Feed_Builder_Header_Itunes
       
   138      */
       
   139     public function setImage($image)
       
   140     {
       
   141         $this->offsetSet('image', $image);
       
   142         return $this;
       
   143     }
       
   144 
       
   145     /**
       
   146      * Sets the short description of the podcast
       
   147      * Default to the feed's description
       
   148      *
       
   149      * @param  string $subtitle
       
   150      * @return Zend_Feed_Builder_Header_Itunes
       
   151      */
       
   152     public function setSubtitle($subtitle)
       
   153     {
       
   154         $this->offsetSet('subtitle', $subtitle);
       
   155         return $this;
       
   156     }
       
   157 
       
   158     /**
       
   159      * Sets the longer description of the podcast
       
   160      * Default to the feed's description
       
   161      *
       
   162      * @param  string $summary
       
   163      * @return Zend_Feed_Builder_Header_Itunes
       
   164      */
       
   165     public function setSummary($summary)
       
   166     {
       
   167         $this->offsetSet('summary', $summary);
       
   168         return $this;
       
   169     }
       
   170 
       
   171     /**
       
   172      * Prevent a feed from appearing
       
   173      *
       
   174      * @param  string $block can be 'yes' or 'no'
       
   175      * @return Zend_Feed_Builder_Header_Itunes
       
   176      * @throws Zend_Feed_Builder_Exception
       
   177      */
       
   178     public function setBlock($block)
       
   179     {
       
   180         $block = strtolower($block);
       
   181         if (!in_array($block, array('yes', 'no'))) {
       
   182             /**
       
   183              * @see Zend_Feed_Builder_Exception
       
   184              */
       
   185             require_once 'Zend/Feed/Builder/Exception.php';
       
   186             throw new Zend_Feed_Builder_Exception("you have to set yes or no to the itunes block property");
       
   187         }
       
   188         $this->offsetSet('block', $block);
       
   189         return $this;
       
   190     }
       
   191 
       
   192     /**
       
   193      * Configuration of the parental advisory graphic
       
   194      *
       
   195      * @param  string $explicit can be 'yes', 'no' or 'clean'
       
   196      * @return Zend_Feed_Builder_Header_Itunes
       
   197      * @throws Zend_Feed_Builder_Exception
       
   198      */
       
   199     public function setExplicit($explicit)
       
   200     {
       
   201         $explicit = strtolower($explicit);
       
   202         if (!in_array($explicit, array('yes', 'no', 'clean'))) {
       
   203             /**
       
   204              * @see Zend_Feed_Builder_Exception
       
   205              */
       
   206             require_once 'Zend/Feed/Builder/Exception.php';
       
   207             throw new Zend_Feed_Builder_Exception("you have to set yes, no or clean to the itunes explicit property");
       
   208         }
       
   209         $this->offsetSet('explicit', $explicit);
       
   210         return $this;
       
   211     }
       
   212 
       
   213     /**
       
   214      * Sets a comma separated list of 12 keywords maximum
       
   215      *
       
   216      * @param  string $keywords
       
   217      * @return Zend_Feed_Builder_Header_Itunes
       
   218      */
       
   219     public function setKeywords($keywords)
       
   220     {
       
   221         $this->offsetSet('keywords', $keywords);
       
   222         return $this;
       
   223     }
       
   224 
       
   225     /**
       
   226      * Sets the new feed URL location
       
   227      *
       
   228      * @param  string $url
       
   229      * @return Zend_Feed_Builder_Header_Itunes
       
   230      */
       
   231     public function setNewFeedUrl($url)
       
   232     {
       
   233         $this->offsetSet('new_feed_url', $url);
       
   234         return $this;
       
   235     }
       
   236 
       
   237     /**
       
   238      * Read only properties accessor
       
   239      *
       
   240      * @param  string $name property to read
       
   241      * @return mixed
       
   242      */
       
   243     public function __get($name)
       
   244     {
       
   245         if (!$this->offsetExists($name)) {
       
   246             return NULL;
       
   247         }
       
   248 
       
   249         return $this->offsetGet($name);
       
   250     }
       
   251 
       
   252     /**
       
   253      * Write properties accessor
       
   254      *
       
   255      * @param  string $name  name of the property to set
       
   256      * @param  mixed  $value value to set
       
   257      * @return void
       
   258      */
       
   259     public function __set($name, $value)
       
   260     {
       
   261         $this->offsetSet($name, $value);
       
   262     }
       
   263 
       
   264     /**
       
   265      * Isset accessor
       
   266      *
       
   267      * @param  string $key
       
   268      * @return boolean
       
   269      */
       
   270     public function __isset($key)
       
   271     {
       
   272         return $this->offsetExists($key);
       
   273     }
       
   274 
       
   275     /**
       
   276      * Unset accessor
       
   277      *
       
   278      * @param  string $key
       
   279      * @return void
       
   280      */
       
   281     public function __unset($key)
       
   282     {
       
   283         if ($this->offsetExists($key)) {
       
   284             $this->offsetUnset($key);
       
   285         }
       
   286     }
       
   287 
       
   288 }