Chris@0: stringWrapper = StringUtils::getWrapper($this->encoding); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed encoding Chris@0: * Chris@0: * @param string $enc Chris@0: * @return Feed Chris@0: */ Chris@0: public function setEncoding($enc) Chris@0: { Chris@0: $this->stringWrapper = StringUtils::getWrapper($enc); Chris@0: $this->encoding = $enc; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get feed encoding Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getEncoding() Chris@0: { Chris@0: return $this->encoding; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set a block value of "yes" or "no". You may also set an empty string. Chris@0: * Chris@0: * @param string Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesBlock($value) Chris@0: { Chris@12: if (! ctype_alpha($value) && strlen($value) > 0) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' Chris@0: . ' contain alphabetic characters'); Chris@0: } Chris@0: if ($this->stringWrapper->strlen($value) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' Chris@0: . ' contain a maximum of 255 characters'); Chris@0: } Chris@0: $this->data['block'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Add feed authors Chris@0: * Chris@0: * @param array $values Chris@0: * @return Feed Chris@0: */ Chris@0: public function addItunesAuthors(array $values) Chris@0: { Chris@0: foreach ($values as $value) { Chris@0: $this->addItunesAuthor($value); Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Add feed author Chris@0: * Chris@0: * @param string $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function addItunesAuthor($value) Chris@0: { Chris@0: if ($this->stringWrapper->strlen($value) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' Chris@0: . ' contain a maximum of 255 characters each'); Chris@0: } Chris@12: if (! isset($this->data['authors'])) { Chris@0: $this->data['authors'] = []; Chris@0: } Chris@0: $this->data['authors'][] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed categories Chris@0: * Chris@0: * @param array $values Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesCategories(array $values) Chris@0: { Chris@12: if (! isset($this->data['categories'])) { Chris@0: $this->data['categories'] = []; Chris@0: } Chris@0: foreach ($values as $key => $value) { Chris@12: if (! is_array($value)) { Chris@0: if ($this->stringWrapper->strlen($value) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' Chris@0: . ' contain a maximum of 255 characters each'); Chris@0: } Chris@0: $this->data['categories'][] = $value; Chris@0: } else { Chris@0: if ($this->stringWrapper->strlen($key) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' Chris@0: . ' contain a maximum of 255 characters each'); Chris@0: } Chris@0: $this->data['categories'][$key] = []; Chris@0: foreach ($value as $val) { Chris@0: if ($this->stringWrapper->strlen($val) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' Chris@0: . ' contain a maximum of 255 characters each'); Chris@0: } Chris@0: $this->data['categories'][$key][] = $val; Chris@0: } Chris@0: } Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed image (icon) Chris@0: * Chris@0: * @param string $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesImage($value) Chris@0: { Chris@16: if (! is_string($value) || ! Uri::factory($value)->isValid()) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only' Chris@0: . ' be a valid URI/IRI'); Chris@0: } Chris@12: if (! in_array(substr($value, -3), ['jpg', 'png'])) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only' Chris@0: . ' use file extension "jpg" or "png" which must be the last three' Chris@0: . ' characters of the URI (i.e. no query string or fragment)'); Chris@0: } Chris@0: $this->data['image'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed cumulative duration Chris@0: * Chris@0: * @param string $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesDuration($value) Chris@0: { Chris@0: $value = (string) $value; Chris@12: if (! ctype_digit($value) Chris@12: && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) Chris@12: && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) Chris@0: ) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only' Chris@0: . ' be of a specified [[HH:]MM:]SS format'); Chris@0: } Chris@0: $this->data['duration'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set "explicit" flag Chris@0: * Chris@0: * @param bool $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesExplicit($value) Chris@0: { Chris@12: if (! in_array($value, ['yes', 'no', 'clean'])) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only' Chris@0: . ' be one of "yes", "no" or "clean"'); Chris@0: } Chris@0: $this->data['explicit'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed keywords Chris@0: * Chris@16: * @deprecated since 2.10.0; itunes:keywords is no longer part of the Chris@16: * iTunes podcast RSS specification. Chris@0: * @param array $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesKeywords(array $value) Chris@0: { Chris@16: trigger_error( Chris@16: 'itunes:keywords has been deprecated in the iTunes podcast RSS specification,' Chris@16: . ' and should not be relied on.', Chris@16: \E_USER_DEPRECATED Chris@16: ); Chris@16: Chris@0: if (count($value) > 12) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' Chris@0: . ' contain a maximum of 12 terms'); Chris@0: } Chris@0: $concat = implode(',', $value); Chris@0: if ($this->stringWrapper->strlen($concat) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' Chris@0: . ' have a concatenated length of 255 chars where terms are delimited' Chris@0: . ' by a comma'); Chris@0: } Chris@0: $this->data['keywords'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set new feed URL Chris@0: * Chris@0: * @param string $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesNewFeedUrl($value) Chris@0: { Chris@12: if (! Uri::factory($value)->isValid()) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "newFeedUrl" may only' Chris@0: . ' be a valid URI/IRI'); Chris@0: } Chris@0: $this->data['newFeedUrl'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Add feed owners Chris@0: * Chris@0: * @param array $values Chris@0: * @return Feed Chris@0: */ Chris@0: public function addItunesOwners(array $values) Chris@0: { Chris@0: foreach ($values as $value) { Chris@0: $this->addItunesOwner($value); Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Add feed owner Chris@0: * Chris@0: * @param array $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function addItunesOwner(array $value) Chris@0: { Chris@12: if (! isset($value['name']) || ! isset($value['email'])) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" must' Chris@0: . ' be an array containing keys "name" and "email"'); Chris@0: } Chris@0: if ($this->stringWrapper->strlen($value['name']) > 255 Chris@0: || $this->stringWrapper->strlen($value['email']) > 255 Chris@0: ) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" may only' Chris@0: . ' contain a maximum of 255 characters each for "name" and "email"'); Chris@0: } Chris@12: if (! isset($this->data['owners'])) { Chris@0: $this->data['owners'] = []; Chris@0: } Chris@0: $this->data['owners'][] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed subtitle Chris@0: * Chris@0: * @param string $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesSubtitle($value) Chris@0: { Chris@0: if ($this->stringWrapper->strlen($value) > 255) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only' Chris@0: . ' contain a maximum of 255 characters'); Chris@0: } Chris@0: $this->data['subtitle'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set feed summary Chris@0: * Chris@0: * @param string $value Chris@0: * @return Feed Chris@0: * @throws Writer\Exception\InvalidArgumentException Chris@0: */ Chris@0: public function setItunesSummary($value) Chris@0: { Chris@0: if ($this->stringWrapper->strlen($value) > 4000) { Chris@0: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' Chris@0: . ' contain a maximum of 4000 characters'); Chris@0: } Chris@0: $this->data['summary'] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@16: * Set podcast type Chris@16: * Chris@16: * @param string $type Chris@16: * @return Feed Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesType($type) Chris@16: { Chris@16: $validTypes = ['episodic', 'serial']; Chris@16: if (! in_array($type, $validTypes, true)) { Chris@16: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@16: 'invalid parameter: "type" MUST be one of [%s]; received %s', Chris@16: implode(', ', $validTypes), Chris@16: is_object($type) ? get_class($type) : var_export($type, true) Chris@16: )); Chris@16: } Chris@16: $this->data['type'] = $type; Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@16: * Set "completion" status (whether more episodes will be released) Chris@16: * Chris@16: * @param bool $status Chris@16: * @return Feed Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesComplete($status) Chris@16: { Chris@16: if (! is_bool($status)) { Chris@16: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@16: 'invalid parameter: "complete" MUST be boolean; received %s', Chris@16: is_object($status) ? get_class($status) : var_export($status, true) Chris@16: )); Chris@16: } Chris@16: Chris@16: if (! $status) { Chris@16: return $this; Chris@16: } Chris@16: Chris@16: $this->data['complete'] = 'Yes'; Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@0: * Overloading: proxy to internal setters Chris@0: * Chris@0: * @param string $method Chris@0: * @param array $params Chris@0: * @return mixed Chris@0: * @throws Writer\Exception\BadMethodCallException Chris@0: */ Chris@0: public function __call($method, array $params) Chris@0: { Chris@0: $point = lcfirst(substr($method, 9)); Chris@12: if (! method_exists($this, 'setItunes' . ucfirst($point)) Chris@12: && ! method_exists($this, 'addItunes' . ucfirst($point)) Chris@0: ) { Chris@0: throw new Writer\Exception\BadMethodCallException( Chris@0: 'invalid method: ' . $method Chris@0: ); Chris@0: } Chris@16: Chris@12: if (! array_key_exists($point, $this->data) || empty($this->data[$point])) { Chris@0: return; Chris@0: } Chris@0: return $this->data[$point]; Chris@0: } Chris@0: }