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 Entry 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: * @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: 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: } Chris@0: Chris@0: /** Chris@0: * Add authors to itunes entry Chris@0: * Chris@0: * @param array $values Chris@0: * @return Entry 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 author to itunes entry Chris@0: * Chris@0: * @param string $value Chris@0: * @return Entry 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 duration Chris@0: * Chris@0: * @param int $value Chris@0: * @return Entry 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 Entry 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 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 Entry 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: 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@18: * Set title Chris@18: * Chris@18: * @param string $value Chris@18: * @return Entry Chris@18: * @throws Writer\Exception\InvalidArgumentException Chris@18: */ Chris@18: public function setItunesTitle($value) Chris@18: { Chris@18: if ($this->stringWrapper->strlen($value) > 255) { Chris@18: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "title" may only' Chris@18: . ' contain a maximum of 255 characters'); Chris@18: } Chris@18: $this->data['title'] = $value; Chris@18: return $this; Chris@18: } Chris@18: Chris@18: /** Chris@0: * Set subtitle Chris@0: * Chris@0: * @param string $value Chris@0: * @return Entry 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 summary Chris@0: * Chris@0: * @param string $value Chris@0: * @return Entry 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 entry image (icon) Chris@16: * Chris@16: * @param string $value Chris@17: * @return Entry Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesImage($value) Chris@16: { Chris@16: if (! is_string($value) || ! Uri::factory($value)->isValid()) { Chris@16: throw new Writer\Exception\InvalidArgumentException( Chris@16: 'invalid parameter: "image" may only be a valid URI/IRI' Chris@16: ); Chris@16: } Chris@16: Chris@16: if (! in_array(substr($value, -3), ['jpg', 'png'])) { Chris@16: throw new Writer\Exception\InvalidArgumentException( Chris@16: 'invalid parameter: "image" may only use file extension "jpg"' Chris@16: . ' or "png" which must be the last three characters of the URI' Chris@16: . ' (i.e. no query string or fragment)' Chris@16: ); Chris@16: } Chris@16: Chris@16: $this->data['image'] = $value; Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@16: * Set the episode number Chris@16: * Chris@16: * @param int $number Chris@16: * @return self Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesEpisode($number) Chris@16: { Chris@16: if (! is_numeric($number) || is_float($number)) { Chris@16: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@16: 'invalid parameter: "number" may only be an integer; received %s', Chris@16: is_object($number) ? get_class($number) : gettype($number) Chris@16: )); Chris@16: } Chris@16: Chris@16: $this->data['episode'] = (int) $number; Chris@16: Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@16: * Set the episode type Chris@16: * Chris@16: * @param string $type One of "full", "trailer", or "bonus". Chris@16: * @return self Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesEpisodeType($type) Chris@16: { Chris@16: $validTypes = ['full', 'trailer', 'bonus']; Chris@16: if (! in_array($type, $validTypes, true)) { Chris@16: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@16: 'invalid parameter: "episodeType" MUST be one of the strings [%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: Chris@16: $this->data['episodeType'] = $type; Chris@16: Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@16: * Set the status of closed captioning Chris@16: * Chris@16: * @param bool $status Chris@16: * @return self Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesIsClosedCaptioned($status) Chris@16: { Chris@16: if (! is_bool($status)) { Chris@16: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@16: 'invalid parameter: "isClosedCaptioned" MUST be a 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['isClosedCaptioned'] = true; Chris@16: Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@16: * Set the season number to which the episode belongs Chris@16: * Chris@16: * @param int $number Chris@16: * @return self Chris@16: * @throws Writer\Exception\InvalidArgumentException Chris@16: */ Chris@16: public function setItunesSeason($number) Chris@16: { Chris@16: if (! is_numeric($number) || is_float($number)) { Chris@16: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@16: 'invalid parameter: "season" may only be an integer; received %s', Chris@16: is_object($number) ? get_class($number) : gettype($number) Chris@16: )); Chris@16: } Chris@16: Chris@16: $this->data['season'] = (int) $number; Chris@16: Chris@16: return $this; Chris@16: } Chris@16: Chris@16: /** Chris@0: * Overloading to itunes specific setters Chris@0: * Chris@0: * @param string $method Chris@0: * @param array $params Chris@0: * @throws Writer\Exception\BadMethodCallException Chris@0: * @return mixed 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@12: if (! array_key_exists($point, $this->data) Chris@0: || empty($this->data[$point]) Chris@0: ) { Chris@0: return; Chris@0: } Chris@0: return $this->data[$point]; Chris@0: } Chris@0: }