File indexing completed on 2024-12-29 05:27:36

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Feed
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 
0024 /**
0025  * ITunes rss extension
0026  *
0027  * Classes used to describe the itunes channel extension
0028  *
0029  * @category   Zend
0030  * @package    Zend_Feed
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Feed_Builder_Header_Itunes extends ArrayObject
0035 {
0036     /**
0037      * Constructor
0038      *
0039      * @param  array $categories Categories columns and in iTunes Music Store Browse
0040      * @return void
0041      */
0042     public function __construct(array $categories)
0043     {
0044         $this->setCategories($categories);
0045     }
0046 
0047     /**
0048      * Sets the categories column and in iTunes Music Store Browse
0049      * $categories must conform to the following format:
0050      * <code>
0051      * array(array('main' => 'main category',
0052      *             'sub' => 'sub category' // optionnal
0053      *            ),
0054      *       // up to 3 rows
0055      *      )
0056      * </code>
0057      *
0058      * @param  array $categories
0059      * @return Zend_Feed_Builder_Header_Itunes
0060      * @throws Zend_Feed_Builder_Exception
0061      */
0062     public function setCategories(array $categories)
0063     {
0064         $nb = count($categories);
0065         if (0 === $nb) {
0066             /**
0067              * @see Zend_Feed_Builder_Exception
0068              */
0069             // require_once 'Zend/Feed/Builder/Exception.php';
0070             throw new Zend_Feed_Builder_Exception("you have to set at least one itunes category");
0071         }
0072         if ($nb > 3) {
0073             /**
0074              * @see Zend_Feed_Builder_Exception
0075              */
0076             // require_once 'Zend/Feed/Builder/Exception.php';
0077             throw new Zend_Feed_Builder_Exception("you have to set at most three itunes categories");
0078         }
0079         foreach ($categories as $i => $category) {
0080             if (empty($category['main'])) {
0081                 /**
0082                  * @see Zend_Feed_Builder_Exception
0083                  */
0084                 // require_once 'Zend/Feed/Builder/Exception.php';
0085                 throw new Zend_Feed_Builder_Exception("you have to set the main category (category #$i)");
0086             }
0087         }
0088         $this->offsetSet('category', $categories);
0089         return $this;
0090     }
0091 
0092     /**
0093      * Sets the artist value, default to the feed's author value
0094      *
0095      * @param  string $author
0096      * @return Zend_Feed_Builder_Header_Itunes
0097      */
0098     public function setAuthor($author)
0099     {
0100         $this->offsetSet('author', $author);
0101         return $this;
0102     }
0103 
0104     /**
0105      * Sets the owner of the postcast
0106      *
0107      * @param  string $name  default to the feed's author value
0108      * @param  string $email default to the feed's email value
0109      * @return Zend_Feed_Builder_Header_Itunes
0110      * @throws Zend_Feed_Builder_Exception
0111      */
0112     public function setOwner($name = '', $email = '')
0113     {
0114         if (!empty($email)) {
0115             /**
0116              * @see Zend_Validate_EmailAddress
0117              */
0118             // require_once 'Zend/Validate/EmailAddress.php';
0119             $validate = new Zend_Validate_EmailAddress();
0120             if (!$validate->isValid($email)) {
0121                 /**
0122                  * @see Zend_Feed_Builder_Exception
0123                  */
0124                 // require_once 'Zend/Feed/Builder/Exception.php';
0125                 throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the itunes owner's email property");
0126             }
0127         }
0128         $this->offsetSet('owner', array('name' => $name, 'email' => $email));
0129         return $this;
0130     }
0131 
0132     /**
0133      * Sets the album/podcast art picture
0134      * Default to the feed's image value
0135      *
0136      * @param  string $image
0137      * @return Zend_Feed_Builder_Header_Itunes
0138      */
0139     public function setImage($image)
0140     {
0141         $this->offsetSet('image', $image);
0142         return $this;
0143     }
0144 
0145     /**
0146      * Sets the short description of the podcast
0147      * Default to the feed's description
0148      *
0149      * @param  string $subtitle
0150      * @return Zend_Feed_Builder_Header_Itunes
0151      */
0152     public function setSubtitle($subtitle)
0153     {
0154         $this->offsetSet('subtitle', $subtitle);
0155         return $this;
0156     }
0157 
0158     /**
0159      * Sets the longer description of the podcast
0160      * Default to the feed's description
0161      *
0162      * @param  string $summary
0163      * @return Zend_Feed_Builder_Header_Itunes
0164      */
0165     public function setSummary($summary)
0166     {
0167         $this->offsetSet('summary', $summary);
0168         return $this;
0169     }
0170 
0171     /**
0172      * Prevent a feed from appearing
0173      *
0174      * @param  string $block can be 'yes' or 'no'
0175      * @return Zend_Feed_Builder_Header_Itunes
0176      * @throws Zend_Feed_Builder_Exception
0177      */
0178     public function setBlock($block)
0179     {
0180         $block = strtolower($block);
0181         if (!in_array($block, array('yes', 'no'))) {
0182             /**
0183              * @see Zend_Feed_Builder_Exception
0184              */
0185             // require_once 'Zend/Feed/Builder/Exception.php';
0186             throw new Zend_Feed_Builder_Exception("you have to set yes or no to the itunes block property");
0187         }
0188         $this->offsetSet('block', $block);
0189         return $this;
0190     }
0191 
0192     /**
0193      * Configuration of the parental advisory graphic
0194      *
0195      * @param  string $explicit can be 'yes', 'no' or 'clean'
0196      * @return Zend_Feed_Builder_Header_Itunes
0197      * @throws Zend_Feed_Builder_Exception
0198      */
0199     public function setExplicit($explicit)
0200     {
0201         $explicit = strtolower($explicit);
0202         if (!in_array($explicit, array('yes', 'no', 'clean'))) {
0203             /**
0204              * @see Zend_Feed_Builder_Exception
0205              */
0206             // require_once 'Zend/Feed/Builder/Exception.php';
0207             throw new Zend_Feed_Builder_Exception("you have to set yes, no or clean to the itunes explicit property");
0208         }
0209         $this->offsetSet('explicit', $explicit);
0210         return $this;
0211     }
0212 
0213     /**
0214      * Sets a comma separated list of 12 keywords maximum
0215      *
0216      * @param  string $keywords
0217      * @return Zend_Feed_Builder_Header_Itunes
0218      */
0219     public function setKeywords($keywords)
0220     {
0221         $this->offsetSet('keywords', $keywords);
0222         return $this;
0223     }
0224 
0225     /**
0226      * Sets the new feed URL location
0227      *
0228      * @param  string $url
0229      * @return Zend_Feed_Builder_Header_Itunes
0230      */
0231     public function setNewFeedUrl($url)
0232     {
0233         $this->offsetSet('new_feed_url', $url);
0234         return $this;
0235     }
0236 
0237     /**
0238      * Read only properties accessor
0239      *
0240      * @param  string $name property to read
0241      * @return mixed
0242      */
0243     public function __get($name)
0244     {
0245         if (!$this->offsetExists($name)) {
0246             return NULL;
0247         }
0248 
0249         return $this->offsetGet($name);
0250     }
0251 
0252     /**
0253      * Write properties accessor
0254      *
0255      * @param  string $name  name of the property to set
0256      * @param  mixed  $value value to set
0257      * @return void
0258      */
0259     public function __set($name, $value)
0260     {
0261         $this->offsetSet($name, $value);
0262     }
0263 
0264     /**
0265      * Isset accessor
0266      *
0267      * @param  string $key
0268      * @return boolean
0269      */
0270     public function __isset($key)
0271     {
0272         return $this->offsetExists($key);
0273     }
0274 
0275     /**
0276      * Unset accessor
0277      *
0278      * @param  string $key
0279      * @return void
0280      */
0281     public function __unset($key)
0282     {
0283         if ($this->offsetExists($key)) {
0284             $this->offsetUnset($key);
0285         }
0286     }
0287 
0288 }