|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
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. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Feed_Writer |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @category Zend |
|
24 * @package Zend_Feed_Writer |
|
25 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
26 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
27 */ |
|
28 class Zend_Feed_Writer_Extension_ITunes_Entry |
|
29 { |
|
30 /** |
|
31 * Array of Feed data for rendering by Extension's renderers |
|
32 * |
|
33 * @var array |
|
34 */ |
|
35 protected $_data = array(); |
|
36 |
|
37 /** |
|
38 * Encoding of all text values |
|
39 * |
|
40 * @var string |
|
41 */ |
|
42 protected $_encoding = 'UTF-8'; |
|
43 |
|
44 /** |
|
45 * Set feed encoding |
|
46 * |
|
47 * @param string $enc |
|
48 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
49 */ |
|
50 public function setEncoding($enc) |
|
51 { |
|
52 $this->_encoding = $enc; |
|
53 return $this; |
|
54 } |
|
55 |
|
56 /** |
|
57 * Get feed encoding |
|
58 * |
|
59 * @return string |
|
60 */ |
|
61 public function getEncoding() |
|
62 { |
|
63 return $this->_encoding; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Set a block value of "yes" or "no". You may also set an empty string. |
|
68 * |
|
69 * @param string |
|
70 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
71 */ |
|
72 public function setItunesBlock($value) |
|
73 { |
|
74 if (!ctype_alpha($value) && strlen($value) > 0) { |
|
75 require_once 'Zend/Feed/Exception.php'; |
|
76 throw new Zend_Feed_Exception('invalid parameter: "block" may only' |
|
77 . ' contain alphabetic characters'); |
|
78 } |
|
79 if (iconv_strlen($value, $this->getEncoding()) > 255) { |
|
80 require_once 'Zend/Feed/Exception.php'; |
|
81 throw new Zend_Feed_Exception('invalid parameter: "block" may only' |
|
82 . ' contain a maximum of 255 characters'); |
|
83 } |
|
84 $this->_data['block'] = $value; |
|
85 } |
|
86 |
|
87 /** |
|
88 * Add authors to itunes entry |
|
89 * |
|
90 * @param array $values |
|
91 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
92 */ |
|
93 public function addItunesAuthors(array $values) |
|
94 { |
|
95 foreach ($values as $value) { |
|
96 $this->addItunesAuthor($value); |
|
97 } |
|
98 return $this; |
|
99 } |
|
100 |
|
101 /** |
|
102 * Add author to itunes entry |
|
103 * |
|
104 * @param string $value |
|
105 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
106 */ |
|
107 public function addItunesAuthor($value) |
|
108 { |
|
109 if (iconv_strlen($value, $this->getEncoding()) > 255) { |
|
110 require_once 'Zend/Feed/Exception.php'; |
|
111 throw new Zend_Feed_Exception('invalid parameter: any "author" may only' |
|
112 . ' contain a maximum of 255 characters each'); |
|
113 } |
|
114 if (!isset($this->_data['authors'])) { |
|
115 $this->_data['authors'] = array(); |
|
116 } |
|
117 $this->_data['authors'][] = $value; |
|
118 return $this; |
|
119 } |
|
120 |
|
121 /** |
|
122 * Set duration |
|
123 * |
|
124 * @param int $value |
|
125 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
126 */ |
|
127 public function setItunesDuration($value) |
|
128 { |
|
129 $value = (string) $value; |
|
130 if (!ctype_digit($value) |
|
131 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) |
|
132 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) |
|
133 ) { |
|
134 require_once 'Zend/Feed/Exception.php'; |
|
135 throw new Zend_Feed_Exception('invalid parameter: "duration" may only' |
|
136 . ' be of a specified [[HH:]MM:]SS format'); |
|
137 } |
|
138 $this->_data['duration'] = $value; |
|
139 return $this; |
|
140 } |
|
141 |
|
142 /** |
|
143 * Set "explicit" flag |
|
144 * |
|
145 * @param bool $value |
|
146 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
147 */ |
|
148 public function setItunesExplicit($value) |
|
149 { |
|
150 if (!in_array($value, array('yes','no','clean'))) { |
|
151 require_once 'Zend/Feed/Exception.php'; |
|
152 throw new Zend_Feed_Exception('invalid parameter: "explicit" may only' |
|
153 . ' be one of "yes", "no" or "clean"'); |
|
154 } |
|
155 $this->_data['explicit'] = $value; |
|
156 return $this; |
|
157 } |
|
158 |
|
159 /** |
|
160 * Set keywords |
|
161 * |
|
162 * @param array $value |
|
163 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
164 */ |
|
165 public function setItunesKeywords(array $value) |
|
166 { |
|
167 if (count($value) > 12) { |
|
168 require_once 'Zend/Feed/Exception.php'; |
|
169 throw new Zend_Feed_Exception('invalid parameter: "keywords" may only' |
|
170 . ' contain a maximum of 12 terms'); |
|
171 } |
|
172 $concat = implode(',', $value); |
|
173 if (iconv_strlen($concat, $this->getEncoding()) > 255) { |
|
174 require_once 'Zend/Feed/Exception.php'; |
|
175 throw new Zend_Feed_Exception('invalid parameter: "keywords" may only' |
|
176 . ' have a concatenated length of 255 chars where terms are delimited' |
|
177 . ' by a comma'); |
|
178 } |
|
179 $this->_data['keywords'] = $value; |
|
180 return $this; |
|
181 } |
|
182 |
|
183 /** |
|
184 * Set subtitle |
|
185 * |
|
186 * @param string $value |
|
187 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
188 */ |
|
189 public function setItunesSubtitle($value) |
|
190 { |
|
191 if (iconv_strlen($value, $this->getEncoding()) > 255) { |
|
192 require_once 'Zend/Feed/Exception.php'; |
|
193 throw new Zend_Feed_Exception('invalid parameter: "subtitle" may only' |
|
194 . ' contain a maximum of 255 characters'); |
|
195 } |
|
196 $this->_data['subtitle'] = $value; |
|
197 return $this; |
|
198 } |
|
199 |
|
200 /** |
|
201 * Set summary |
|
202 * |
|
203 * @param string $value |
|
204 * @return Zend_Feed_Writer_Extension_ITunes_Entry |
|
205 */ |
|
206 public function setItunesSummary($value) |
|
207 { |
|
208 if (iconv_strlen($value, $this->getEncoding()) > 4000) { |
|
209 require_once 'Zend/Feed/Exception.php'; |
|
210 throw new Zend_Feed_Exception('invalid parameter: "summary" may only' |
|
211 . ' contain a maximum of 4000 characters'); |
|
212 } |
|
213 $this->_data['summary'] = $value; |
|
214 return $this; |
|
215 } |
|
216 |
|
217 /** |
|
218 * Overloading to itunes specific setters |
|
219 * |
|
220 * @param string $method |
|
221 * @param array $params |
|
222 * @return mixed |
|
223 */ |
|
224 public function __call($method, array $params) |
|
225 { |
|
226 $point = Zend_Feed_Writer::lcfirst(substr($method, 9)); |
|
227 if (!method_exists($this, 'setItunes' . ucfirst($point)) |
|
228 && !method_exists($this, 'addItunes' . ucfirst($point)) |
|
229 ) { |
|
230 require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php'; |
|
231 throw new Zend_Feed_Writer_Exception_InvalidMethodException( |
|
232 'invalid method: ' . $method |
|
233 ); |
|
234 } |
|
235 if (!array_key_exists($point, $this->_data) |
|
236 || empty($this->_data[$point]) |
|
237 ) { |
|
238 return null; |
|
239 } |
|
240 return $this->_data[$point]; |
|
241 } |
|
242 } |