File indexing completed on 2024-06-23 05:55:15

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Feed_Writer
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @category   Zend
0024  * @package    Zend_Feed_Writer
0025  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0026  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0027  */
0028 class Zend_Feed_Writer_Extension_ITunes_Entry
0029 {
0030     /**
0031      * Array of Feed data for rendering by Extension's renderers
0032      *
0033      * @var array
0034      */
0035     protected $_data = array();
0036 
0037     /**
0038      * Encoding of all text values
0039      *
0040      * @var string
0041      */
0042     protected $_encoding = 'UTF-8';
0043 
0044     /**
0045      * Set feed encoding
0046      *
0047      * @param  string $enc
0048      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0049      */
0050     public function setEncoding($enc)
0051     {
0052         $this->_encoding = $enc;
0053         return $this;
0054     }
0055 
0056     /**
0057      * Get feed encoding
0058      *
0059      * @return string
0060      */
0061     public function getEncoding()
0062     {
0063         return $this->_encoding;
0064     }
0065 
0066     /**
0067      * Set a block value of "yes" or "no". You may also set an empty string.
0068      *
0069      * @param  string
0070      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0071      */
0072     public function setItunesBlock($value)
0073     {
0074         if (!ctype_alpha($value) && strlen($value) > 0) {
0075             // require_once 'Zend/Feed/Exception.php';
0076             throw new Zend_Feed_Exception('invalid parameter: "block" may only'
0077             . ' contain alphabetic characters');
0078         }
0079         if (iconv_strlen($value, $this->getEncoding()) > 255) {
0080             // require_once 'Zend/Feed/Exception.php';
0081             throw new Zend_Feed_Exception('invalid parameter: "block" may only'
0082             . ' contain a maximum of 255 characters');
0083         }
0084         $this->_data['block'] = $value;
0085     }
0086 
0087     /**
0088      * Add authors to itunes entry
0089      *
0090      * @param  array $values
0091      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0092      */
0093     public function addItunesAuthors(array $values)
0094     {
0095         foreach ($values as $value) {
0096             $this->addItunesAuthor($value);
0097         }
0098         return $this;
0099     }
0100 
0101     /**
0102      * Add author to itunes entry
0103      *
0104      * @param  string $value
0105      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0106      */
0107     public function addItunesAuthor($value)
0108     {
0109         if (iconv_strlen($value, $this->getEncoding()) > 255) {
0110             // require_once 'Zend/Feed/Exception.php';
0111             throw new Zend_Feed_Exception('invalid parameter: any "author" may only'
0112             . ' contain a maximum of 255 characters each');
0113         }
0114         if (!isset($this->_data['authors'])) {
0115             $this->_data['authors'] = array();
0116         }
0117         $this->_data['authors'][] = $value;
0118         return $this;
0119     }
0120 
0121     /**
0122      * Set duration
0123      *
0124      * @param  int $value
0125      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0126      */
0127     public function setItunesDuration($value)
0128     {
0129         $value = (string) $value;
0130         if (!ctype_digit($value)
0131             && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value)
0132             && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value)
0133         ) {
0134             // require_once 'Zend/Feed/Exception.php';
0135             throw new Zend_Feed_Exception('invalid parameter: "duration" may only'
0136             . ' be of a specified [[HH:]MM:]SS format');
0137         }
0138         $this->_data['duration'] = $value;
0139         return $this;
0140     }
0141 
0142     /**
0143      * Set "explicit" flag
0144      *
0145      * @param  bool $value
0146      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0147      */
0148     public function setItunesExplicit($value)
0149     {
0150         if (!in_array($value, array('yes','no','clean'))) {
0151             // require_once 'Zend/Feed/Exception.php';
0152             throw new Zend_Feed_Exception('invalid parameter: "explicit" may only'
0153             . ' be one of "yes", "no" or "clean"');
0154         }
0155         $this->_data['explicit'] = $value;
0156         return $this;
0157     }
0158 
0159     /**
0160      * Set keywords
0161      *
0162      * @param  array $value
0163      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0164      */
0165     public function setItunesKeywords(array $value)
0166     {
0167         if (count($value) > 12) {
0168             // require_once 'Zend/Feed/Exception.php';
0169             throw new Zend_Feed_Exception('invalid parameter: "keywords" may only'
0170             . ' contain a maximum of 12 terms');
0171         }
0172         $concat = implode(',', $value);
0173         if (iconv_strlen($concat, $this->getEncoding()) > 255) {
0174             // require_once 'Zend/Feed/Exception.php';
0175             throw new Zend_Feed_Exception('invalid parameter: "keywords" may only'
0176             . ' have a concatenated length of 255 chars where terms are delimited'
0177             . ' by a comma');
0178         }
0179         $this->_data['keywords'] = $value;
0180         return $this;
0181     }
0182 
0183     /**
0184      * Set subtitle
0185      *
0186      * @param  string $value
0187      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0188      */
0189     public function setItunesSubtitle($value)
0190     {
0191         if (iconv_strlen($value, $this->getEncoding()) > 255) {
0192             // require_once 'Zend/Feed/Exception.php';
0193             throw new Zend_Feed_Exception('invalid parameter: "subtitle" may only'
0194             . ' contain a maximum of 255 characters');
0195         }
0196         $this->_data['subtitle'] = $value;
0197         return $this;
0198     }
0199 
0200     /**
0201      * Set summary
0202      *
0203      * @param  string $value
0204      * @return Zend_Feed_Writer_Extension_ITunes_Entry
0205      */
0206     public function setItunesSummary($value)
0207     {
0208         if (iconv_strlen($value, $this->getEncoding()) > 4000) {
0209             // require_once 'Zend/Feed/Exception.php';
0210             throw new Zend_Feed_Exception('invalid parameter: "summary" may only'
0211             . ' contain a maximum of 4000 characters');
0212         }
0213         $this->_data['summary'] = $value;
0214         return $this;
0215     }
0216 
0217     /**
0218      * Overloading to itunes specific setters
0219      *
0220      * @param  string $method
0221      * @param  array $params
0222      * @return mixed
0223      */
0224     public function __call($method, array $params)
0225     {
0226         $point = Zend_Feed_Writer::lcfirst(substr($method, 9));
0227         if (!method_exists($this, 'setItunes' . ucfirst($point))
0228             && !method_exists($this, 'addItunes' . ucfirst($point))
0229         ) {
0230             // require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php';
0231             throw new Zend_Feed_Writer_Exception_InvalidMethodException(
0232                 'invalid method: ' . $method
0233             );
0234         }
0235         if (!array_key_exists($point, $this->_data)
0236             || empty($this->_data[$point])
0237         ) {
0238             return null;
0239         }
0240         return $this->_data[$point];
0241     }
0242 }