/** * Set entry identifier * * @param XMLWriter $xml * @return void */ protected function _setId(XMLWriter $xml) { if (!$this->entry->getId() && !$this->entry->getLink()) { return; } if (!$this->entry->getId()) { $this->entry->setId($this->entry->getLink()); } $xml->startElement('guid'); if (!Uri::factory($this->entry->getId())->isValid()) { $xml->writeAttribute('isPermaLink', 'false'); } $xml->text($this->entry->getId()); $xml->endElement(); // guid }
/** * Adds an enclosure to the entry. The array parameter may contain the * keys 'uri', 'type' and 'length'. Only 'uri' is required for Atom, though the * others must also be provided or RSS rendering (where they are required) * will throw an Exception. * * @param array $enclosure * @throws InvalidArgumentException * @return Entry */ public function setEnclosure(array $enclosure) { if (!isset($enclosure['uri'])) { throw new InvalidArgumentException('Enclosure "uri" is not set'); } if (!Uri::factory($enclosure['uri'])->isValid()) { throw new InvalidArgumentException('Enclosure "uri" is not a valid URI/IRI'); } $this->data['enclosure'] = $enclosure; return $this; }
/** * Set feed channel image * * @param XMLWriter $xml * @return void * @throws InvalidArgumentException */ protected function _setImage(XMLWriter $xml) { $image = $this->feed->getImage(); if (!$image) { return; } if (!isset($image['title']) || empty($image['title']) || !is_string($image['title'])) { throw new InvalidArgumentException('RSS 2.0 feed images must include a title'); } if (empty($image['link']) || !is_string($image['link']) || !Uri::factory($image['link'])->isValid()) { throw new InvalidArgumentException('Invalid parameter: parameter \'link\' must be a non-empty string and valid URI/IRI'); } $xml->startElement('image'); $xml->writeElement('url', $image['uri']); $xml->writeElement('title', $image['title']); $xml->writeElement('link', $image['link']); if (isset($image['height'])) { if (!ctype_digit((string) $image['height']) || $image['height'] > 400) { throw new InvalidArgumentException('Invalid parameter: parameter \'height\' must be an integer not exceeding 400'); } $xml->writeElement('height', $image['height']); } if (isset($image['width'])) { if (!ctype_digit((string) $image['width']) || $image['width'] > 144) { throw new InvalidArgumentException('Invalid parameter: parameter \'width\' must be an integer not exceeding 144'); } $xml->writeElement('width', $image['width']); } if (isset($image['description'])) { if (empty($image['description']) || !is_string($image['description'])) { throw new InvalidArgumentException('Invalid parameter: parameter \'description\' must be a non-empty string'); } $xml->writeElement('description', $image['description']); } $xml->endElement(); // image }
/** * Set entry identifier * * @param XMLWriter $xml * @return void * @throws InvalidArgumentException */ protected function _setId(XMLWriter $xml) { if (!$this->entry->getId() && !$this->entry->getLink()) { throw new InvalidArgumentException('Atom 1.0 entry elements MUST contain exactly one ' . 'atom:id element, or as an alternative, we can use the same ' . 'value as atom:link however neither a suitable link nor an ' . 'id have been set'); } if (!$this->entry->getId()) { $this->entry->setId($this->entry->getLink()); } if (!Uri::factory($this->entry->getId())->isValid() && !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\\-]{1,31}:([a-zA-Z0-9\\(\\)\\+\\,\\.\\:\\=\\@\\;\$\\_\\!\\*\\-]|%[0-9a-fA-F]{2})*#", $this->entry->getId()) && !$this->_validateTagUri($this->entry->getId())) { throw new InvalidArgumentException('Atom 1.0 IDs must be a valid URI/IRI'); } $xml->writeElement('id', $this->entry->getId()); }
/** * Add a feed category * * @param array $category * @throws InvalidArgumentException * @return Syndication\Feed */ public function addCategory(array $category) { if (!isset($category['term'])) { throw new InvalidArgumentException('Each category must be an array and ' . 'contain at least a "term" element containing the machine ' . ' readable category name'); } if (isset($category['scheme'])) { if (empty($category['scheme']) || !is_string($category['scheme']) || !Uri::factory($category['scheme'])->isValid()) { throw new InvalidArgumentException('The Atom scheme or RSS domain of a category must be a valid URI'); } } if (!isset($this->data['categories'])) { $this->data['categories'] = array(); } $this->data['categories'][] = $category; return $this; }