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@2: 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@2: 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@2: if (! ctype_digit($value) Chris@2: && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) Chris@2: && ! 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@2: 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@2: * @deprecated since 2.10.0; itunes:keywords is no longer part of the Chris@2: * 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@2: trigger_error( Chris@2: 'itunes:keywords has been deprecated in the iTunes podcast RSS specification,' Chris@2: . ' and should not be relied on.', Chris@2: \E_USER_DEPRECATED Chris@2: ); Chris@2: 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@5: * Set title Chris@5: * Chris@5: * @param string $value Chris@5: * @return Entry Chris@5: * @throws Writer\Exception\InvalidArgumentException Chris@5: */ Chris@5: public function setItunesTitle($value) Chris@5: { Chris@5: if ($this->stringWrapper->strlen($value) > 255) { Chris@5: throw new Writer\Exception\InvalidArgumentException('invalid parameter: "title" may only' Chris@5: . ' contain a maximum of 255 characters'); Chris@5: } Chris@5: $this->data['title'] = $value; Chris@5: return $this; Chris@5: } Chris@5: Chris@5: /** 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@2: * Set entry image (icon) Chris@2: * Chris@2: * @param string $value Chris@4: * @return Entry Chris@2: * @throws Writer\Exception\InvalidArgumentException Chris@2: */ Chris@2: public function setItunesImage($value) Chris@2: { Chris@2: if (! is_string($value) || ! Uri::factory($value)->isValid()) { Chris@2: throw new Writer\Exception\InvalidArgumentException( Chris@2: 'invalid parameter: "image" may only be a valid URI/IRI' Chris@2: ); Chris@2: } Chris@2: Chris@2: if (! in_array(substr($value, -3), ['jpg', 'png'])) { Chris@2: throw new Writer\Exception\InvalidArgumentException( Chris@2: 'invalid parameter: "image" may only use file extension "jpg"' Chris@2: . ' or "png" which must be the last three characters of the URI' Chris@2: . ' (i.e. no query string or fragment)' Chris@2: ); Chris@2: } Chris@2: Chris@2: $this->data['image'] = $value; Chris@2: return $this; Chris@2: } Chris@2: Chris@2: /** Chris@2: * Set the episode number Chris@2: * Chris@2: * @param int $number Chris@2: * @return self Chris@2: * @throws Writer\Exception\InvalidArgumentException Chris@2: */ Chris@2: public function setItunesEpisode($number) Chris@2: { Chris@2: if (! is_numeric($number) || is_float($number)) { Chris@2: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@2: 'invalid parameter: "number" may only be an integer; received %s', Chris@2: is_object($number) ? get_class($number) : gettype($number) Chris@2: )); Chris@2: } Chris@2: Chris@2: $this->data['episode'] = (int) $number; Chris@2: Chris@2: return $this; Chris@2: } Chris@2: Chris@2: /** Chris@2: * Set the episode type Chris@2: * Chris@2: * @param string $type One of "full", "trailer", or "bonus". Chris@2: * @return self Chris@2: * @throws Writer\Exception\InvalidArgumentException Chris@2: */ Chris@2: public function setItunesEpisodeType($type) Chris@2: { Chris@2: $validTypes = ['full', 'trailer', 'bonus']; Chris@2: if (! in_array($type, $validTypes, true)) { Chris@2: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@2: 'invalid parameter: "episodeType" MUST be one of the strings [%s]; received %s', Chris@2: implode(', ', $validTypes), Chris@2: is_object($type) ? get_class($type) : var_export($type, true) Chris@2: )); Chris@2: } Chris@2: Chris@2: $this->data['episodeType'] = $type; Chris@2: Chris@2: return $this; Chris@2: } Chris@2: Chris@2: /** Chris@2: * Set the status of closed captioning Chris@2: * Chris@2: * @param bool $status Chris@2: * @return self Chris@2: * @throws Writer\Exception\InvalidArgumentException Chris@2: */ Chris@2: public function setItunesIsClosedCaptioned($status) Chris@2: { Chris@2: if (! is_bool($status)) { Chris@2: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@2: 'invalid parameter: "isClosedCaptioned" MUST be a boolean; received %s', Chris@2: is_object($status) ? get_class($status) : var_export($status, true) Chris@2: )); Chris@2: } Chris@2: Chris@2: if (! $status) { Chris@2: return $this; Chris@2: } Chris@2: Chris@2: $this->data['isClosedCaptioned'] = true; Chris@2: Chris@2: return $this; Chris@2: } Chris@2: Chris@2: /** Chris@2: * Set the season number to which the episode belongs Chris@2: * Chris@2: * @param int $number Chris@2: * @return self Chris@2: * @throws Writer\Exception\InvalidArgumentException Chris@2: */ Chris@2: public function setItunesSeason($number) Chris@2: { Chris@2: if (! is_numeric($number) || is_float($number)) { Chris@2: throw new Writer\Exception\InvalidArgumentException(sprintf( Chris@2: 'invalid parameter: "season" may only be an integer; received %s', Chris@2: is_object($number) ? get_class($number) : gettype($number) Chris@2: )); Chris@2: } Chris@2: Chris@2: $this->data['season'] = (int) $number; Chris@2: Chris@2: return $this; Chris@2: } Chris@2: Chris@2: /** 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@2: if (! method_exists($this, 'setItunes' . ucfirst($point)) Chris@2: && ! 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@2: 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: }