Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Feed / Writer / Extension / ITunes / Feed.php
blob7e6c5ac55e461928b3c45fd8f5246f1342ac3a6a
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Feed\Writer\Extension\ITunes;
12 use Zend\Feed\Uri;
13 use Zend\Feed\Writer;
14 use Zend\Stdlib\StringUtils;
15 use Zend\Stdlib\StringWrapper\StringWrapperInterface;
17 /**
19 class Feed
21 /**
22 * Array of Feed data for rendering by Extension's renderers
24 * @var array
26 protected $data = array();
28 /**
29 * Encoding of all text values
31 * @var string
33 protected $encoding = 'UTF-8';
35 /**
36 * The used string wrapper supporting encoding
38 * @var StringWrapperInterface
40 protected $stringWrapper;
42 /**
43 * Constructor
45 public function __construct()
47 $this->stringWrapper = StringUtils::getWrapper($this->encoding);
50 /**
51 * Set feed encoding
53 * @param string $enc
54 * @return Feed
56 public function setEncoding($enc)
58 $this->stringWrapper = StringUtils::getWrapper($enc);
59 $this->encoding = $enc;
60 return $this;
63 /**
64 * Get feed encoding
66 * @return string
68 public function getEncoding()
70 return $this->encoding;
73 /**
74 * Set a block value of "yes" or "no". You may also set an empty string.
76 * @param string
77 * @return Feed
78 * @throws Writer\Exception\InvalidArgumentException
80 public function setItunesBlock($value)
82 if (!ctype_alpha($value) && strlen($value) > 0) {
83 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only'
84 . ' contain alphabetic characters');
86 if ($this->stringWrapper->strlen($value) > 255) {
87 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only'
88 . ' contain a maximum of 255 characters');
90 $this->data['block'] = $value;
91 return $this;
94 /**
95 * Add feed authors
97 * @param array $values
98 * @return Feed
100 public function addItunesAuthors(array $values)
102 foreach ($values as $value) {
103 $this->addItunesAuthor($value);
105 return $this;
109 * Add feed author
111 * @param string $value
112 * @return Feed
113 * @throws Writer\Exception\InvalidArgumentException
115 public function addItunesAuthor($value)
117 if ($this->stringWrapper->strlen($value) > 255) {
118 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only'
119 . ' contain a maximum of 255 characters each');
121 if (!isset($this->data['authors'])) {
122 $this->data['authors'] = array();
124 $this->data['authors'][] = $value;
125 return $this;
129 * Set feed categories
131 * @param array $values
132 * @return Feed
133 * @throws Writer\Exception\InvalidArgumentException
135 public function setItunesCategories(array $values)
137 if (!isset($this->data['categories'])) {
138 $this->data['categories'] = array();
140 foreach ($values as $key => $value) {
141 if (!is_array($value)) {
142 if ($this->stringWrapper->strlen($value) > 255) {
143 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only'
144 . ' contain a maximum of 255 characters each');
146 $this->data['categories'][] = $value;
147 } else {
148 if ($this->stringWrapper->strlen($key) > 255) {
149 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only'
150 . ' contain a maximum of 255 characters each');
152 $this->data['categories'][$key] = array();
153 foreach ($value as $val) {
154 if ($this->stringWrapper->strlen($val) > 255) {
155 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only'
156 . ' contain a maximum of 255 characters each');
158 $this->data['categories'][$key][] = $val;
162 return $this;
166 * Set feed image (icon)
168 * @param string $value
169 * @return Feed
170 * @throws Writer\Exception\InvalidArgumentException
172 public function setItunesImage($value)
174 if (!Uri::factory($value)->isValid()) {
175 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only'
176 . ' be a valid URI/IRI');
178 if (!in_array(substr($value, -3), array('jpg', 'png'))) {
179 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only'
180 . ' use file extension "jpg" or "png" which must be the last three'
181 . ' characters of the URI (i.e. no query string or fragment)');
183 $this->data['image'] = $value;
184 return $this;
188 * Set feed cumulative duration
190 * @param string $value
191 * @return Feed
192 * @throws Writer\Exception\InvalidArgumentException
194 public function setItunesDuration($value)
196 $value = (string) $value;
197 if (!ctype_digit($value)
198 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value)
199 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value)
201 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only'
202 . ' be of a specified [[HH:]MM:]SS format');
204 $this->data['duration'] = $value;
205 return $this;
209 * Set "explicit" flag
211 * @param bool $value
212 * @return Feed
213 * @throws Writer\Exception\InvalidArgumentException
215 public function setItunesExplicit($value)
217 if (!in_array($value, array('yes', 'no', 'clean'))) {
218 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only'
219 . ' be one of "yes", "no" or "clean"');
221 $this->data['explicit'] = $value;
222 return $this;
226 * Set feed keywords
228 * @param array $value
229 * @return Feed
230 * @throws Writer\Exception\InvalidArgumentException
232 public function setItunesKeywords(array $value)
234 if (count($value) > 12) {
235 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only'
236 . ' contain a maximum of 12 terms');
238 $concat = implode(',', $value);
239 if ($this->stringWrapper->strlen($concat) > 255) {
240 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only'
241 . ' have a concatenated length of 255 chars where terms are delimited'
242 . ' by a comma');
244 $this->data['keywords'] = $value;
245 return $this;
249 * Set new feed URL
251 * @param string $value
252 * @return Feed
253 * @throws Writer\Exception\InvalidArgumentException
255 public function setItunesNewFeedUrl($value)
257 if (!Uri::factory($value)->isValid()) {
258 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "newFeedUrl" may only'
259 . ' be a valid URI/IRI');
261 $this->data['newFeedUrl'] = $value;
262 return $this;
266 * Add feed owners
268 * @param array $values
269 * @return Feed
271 public function addItunesOwners(array $values)
273 foreach ($values as $value) {
274 $this->addItunesOwner($value);
276 return $this;
280 * Add feed owner
282 * @param array $value
283 * @return Feed
284 * @throws Writer\Exception\InvalidArgumentException
286 public function addItunesOwner(array $value)
288 if (!isset($value['name']) || !isset($value['email'])) {
289 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" must'
290 . ' be an array containing keys "name" and "email"');
292 if ($this->stringWrapper->strlen($value['name']) > 255
293 || $this->stringWrapper->strlen($value['email']) > 255
295 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" may only'
296 . ' contain a maximum of 255 characters each for "name" and "email"');
298 if (!isset($this->data['owners'])) {
299 $this->data['owners'] = array();
301 $this->data['owners'][] = $value;
302 return $this;
306 * Set feed subtitle
308 * @param string $value
309 * @return Feed
310 * @throws Writer\Exception\InvalidArgumentException
312 public function setItunesSubtitle($value)
314 if ($this->stringWrapper->strlen($value) > 255) {
315 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only'
316 . ' contain a maximum of 255 characters');
318 $this->data['subtitle'] = $value;
319 return $this;
323 * Set feed summary
325 * @param string $value
326 * @return Feed
327 * @throws Writer\Exception\InvalidArgumentException
329 public function setItunesSummary($value)
331 if ($this->stringWrapper->strlen($value) > 4000) {
332 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only'
333 . ' contain a maximum of 4000 characters');
335 $this->data['summary'] = $value;
336 return $this;
340 * Overloading: proxy to internal setters
342 * @param string $method
343 * @param array $params
344 * @return mixed
345 * @throws Writer\Exception\BadMethodCallException
347 public function __call($method, array $params)
349 $point = lcfirst(substr($method, 9));
350 if (!method_exists($this, 'setItunes' . ucfirst($point))
351 && !method_exists($this, 'addItunes' . ucfirst($point))
353 throw new Writer\Exception\BadMethodCallException(
354 'invalid method: ' . $method
357 if (!array_key_exists($point, $this->data) || empty($this->data[$point])) {
358 return null;
360 return $this->data[$point];