diff options
Diffstat (limited to '3rdparty/ZendFeed/Writer/Extension')
13 files changed, 1954 insertions, 0 deletions
diff --git a/3rdparty/ZendFeed/Writer/Extension/AbstractRenderer.php b/3rdparty/ZendFeed/Writer/Extension/AbstractRenderer.php new file mode 100644 index 000000000..5e4eb8c82 --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/AbstractRenderer.php @@ -0,0 +1,164 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension; + +use DOMDocument; +use DOMElement; + +/** +*/ +abstract class AbstractRenderer implements RendererInterface +{ + /** + * @var DOMDocument + */ + protected $dom = null; + + /** + * @var mixed + */ + protected $entry = null; + + /** + * @var DOMElement + */ + protected $base = null; + + /** + * @var mixed + */ + protected $container = null; + + /** + * @var string + */ + protected $type = null; + + /** + * @var DOMElement + */ + protected $rootElement = null; + + /** + * Encoding of all text values + * + * @var string + */ + protected $encoding = 'UTF-8'; + + /** + * Set the data container + * + * @param mixed $container + * @return AbstractRenderer + */ + public function setDataContainer($container) + { + $this->container = $container; + return $this; + } + + /** + * Set feed encoding + * + * @param string $enc + * @return AbstractRenderer + */ + public function setEncoding($enc) + { + $this->encoding = $enc; + return $this; + } + + /** + * Get feed encoding + * + * @return string + */ + public function getEncoding() + { + return $this->encoding; + } + + /** + * Set DOMDocument and DOMElement on which to operate + * + * @param DOMDocument $dom + * @param DOMElement $base + * @return AbstractRenderer + */ + public function setDomDocument(DOMDocument $dom, DOMElement $base) + { + $this->dom = $dom; + $this->base = $base; + return $this; + } + + /** + * Get data container being rendered + * + * @return mixed + */ + public function getDataContainer() + { + return $this->container; + } + + /** + * Set feed type + * + * @param string $type + * @return AbstractRenderer + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Get feedtype + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set root element of document + * + * @param DOMElement $root + * @return AbstractRenderer + */ + public function setRootElement(DOMElement $root) + { + $this->rootElement = $root; + return $this; + } + + /** + * Get root element + * + * @return DOMElement + */ + public function getRootElement() + { + return $this->rootElement; + } + + /** + * Append namespaces to feed + * + * @return void + */ + abstract protected function _appendNamespaces(); +} diff --git a/3rdparty/ZendFeed/Writer/Extension/Atom/Renderer/Feed.php b/3rdparty/ZendFeed/Writer/Extension/Atom/Renderer/Feed.php new file mode 100644 index 000000000..f79025958 --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/Atom/Renderer/Feed.php @@ -0,0 +1,109 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension\Atom\Renderer; + +use DOMDocument; +use DOMElement; +use Zend\Feed\Writer\Extension; + +/** +*/ +class Feed extends Extension\AbstractRenderer +{ + + /** + * Set to TRUE if a rendering method actually renders something. This + * is used to prevent premature appending of a XML namespace declaration + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $called = false; + + /** + * Render feed + * + * @return void + */ + public function render() + { + /** + * RSS 2.0 only. Used mainly to include Atom links and + * Pubsubhubbub Hub endpoint URIs under the Atom namespace + */ + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setFeedLinks($this->dom, $this->base); + $this->_setHubs($this->dom, $this->base); + if ($this->called) { + $this->_appendNamespaces(); + } + } + + /** + * Append namespaces to root element of feed + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:atom', + 'http://www.w3.org/2005/Atom'); + } + + /** + * Set feed link elements + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setFeedLinks(DOMDocument $dom, DOMElement $root) + { + $flinks = $this->getDataContainer()->getFeedLinks(); + if (!$flinks || empty($flinks)) { + return; + } + foreach ($flinks as $type => $href) { + if (strtolower($type) == $this->getType()) { // issue 2605 + $mime = 'application/' . strtolower($type) . '+xml'; + $flink = $dom->createElement('atom:link'); + $root->appendChild($flink); + $flink->setAttribute('rel', 'self'); + $flink->setAttribute('type', $mime); + $flink->setAttribute('href', $href); + } + } + $this->called = true; + } + + /** + * Set PuSH hubs + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setHubs(DOMDocument $dom, DOMElement $root) + { + $hubs = $this->getDataContainer()->getHubs(); + if (!$hubs || empty($hubs)) { + return; + } + foreach ($hubs as $hubUrl) { + $hub = $dom->createElement('atom:link'); + $hub->setAttribute('rel', 'hub'); + $hub->setAttribute('href', $hubUrl); + $root->appendChild($hub); + } + $this->called = true; + } +} diff --git a/3rdparty/ZendFeed/Writer/Extension/Content/Renderer/Entry.php b/3rdparty/ZendFeed/Writer/Extension/Content/Renderer/Entry.php new file mode 100644 index 000000000..6d64bc2fc --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/Content/Renderer/Entry.php @@ -0,0 +1,76 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension\Content\Renderer; + +use DOMDocument; +use DOMElement; +use Zend\Feed\Writer\Extension; + +/** +*/ +class Entry extends Extension\AbstractRenderer +{ + + /** + * Set to TRUE if a rendering method actually renders something. This + * is used to prevent premature appending of a XML namespace declaration + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setContent($this->dom, $this->base); + if ($this->called) { + $this->_appendNamespaces(); + } + } + + /** + * Append namespaces to root element + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:content', + 'http://purl.org/rss/1.0/modules/content/'); + } + + /** + * Set entry content + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setContent(DOMDocument $dom, DOMElement $root) + { + $content = $this->getDataContainer()->getContent(); + if (!$content) { + return; + } + $element = $dom->createElement('content:encoded'); + $root->appendChild($element); + $cdata = $dom->createCDATASection($content); + $element->appendChild($cdata); + $this->called = true; + } +} diff --git a/3rdparty/ZendFeed/Writer/Extension/DublinCore/Renderer/Entry.php b/3rdparty/ZendFeed/Writer/Extension/DublinCore/Renderer/Entry.php new file mode 100644 index 000000000..d7ca4fda7 --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/DublinCore/Renderer/Entry.php @@ -0,0 +1,80 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension\DublinCore\Renderer; + +use DOMDocument; +use DOMElement; +use Zend\Feed\Writer\Extension; + +/** +*/ +class Entry extends Extension\AbstractRenderer +{ + + /** + * Set to TRUE if a rendering method actually renders something. This + * is used to prevent premature appending of a XML namespace declaration + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setAuthors($this->dom, $this->base); + if ($this->called) { + $this->_appendNamespaces(); + } + } + + /** + * Append namespaces to entry + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:dc', + 'http://purl.org/dc/elements/1.1/'); + } + + /** + * Set entry author elements + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $data) { + $author = $this->dom->createElement('dc:creator'); + if (array_key_exists('name', $data)) { + $text = $dom->createTextNode($data['name']); + $author->appendChild($text); + $root->appendChild($author); + } + } + $this->called = true; + } +} diff --git a/3rdparty/ZendFeed/Writer/Extension/DublinCore/Renderer/Feed.php b/3rdparty/ZendFeed/Writer/Extension/DublinCore/Renderer/Feed.php new file mode 100644 index 000000000..e888fbd07 --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/DublinCore/Renderer/Feed.php @@ -0,0 +1,80 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension\DublinCore\Renderer; + +use DOMDocument; +use DOMElement; +use Zend\Feed\Writer\Extension; + +/** +*/ +class Feed extends Extension\AbstractRenderer +{ + + /** + * Set to TRUE if a rendering method actually renders something. This + * is used to prevent premature appending of a XML namespace declaration + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $called = false; + + /** + * Render feed + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setAuthors($this->dom, $this->base); + if ($this->called) { + $this->_appendNamespaces(); + } + } + + /** + * Append namespaces to feed element + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:dc', + 'http://purl.org/dc/elements/1.1/'); + } + + /** + * Set feed authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $data) { + $author = $this->dom->createElement('dc:creator'); + if (array_key_exists('name', $data)) { + $text = $dom->createTextNode($data['name']); + $author->appendChild($text); + $root->appendChild($author); + } + } + $this->called = true; + } +} diff --git a/3rdparty/ZendFeed/Writer/Extension/ITunes/Entry.php b/3rdparty/ZendFeed/Writer/Extension/ITunes/Entry.php new file mode 100644 index 000000000..1b7b64aa5 --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/ITunes/Entry.php @@ -0,0 +1,246 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension\ITunes; + +use Zend\Feed\Writer; +use Zend\Feed\Writer\Extension; +use Zend\Stdlib\StringUtils; +use Zend\Stdlib\StringWrapper\StringWrapperInterface; + +/** +*/ +class Entry +{ + /** + * Array of Feed data for rendering by Extension's renderers + * + * @var array + */ + protected $data = array(); + + /** + * Encoding of all text values + * + * @var string + */ + protected $encoding = 'UTF-8'; + + /** + * The used string wrapper supporting encoding + * + * @var StringWrapperInterface + */ + protected $stringWrapper; + + public function __construct() + { + $this->stringWrapper = StringUtils::getWrapper($this->encoding); + } + + /** + * Set feed encoding + * + * @param string $enc + * @return Entry + */ + public function setEncoding($enc) + { + $this->stringWrapper = StringUtils::getWrapper($enc); + $this->encoding = $enc; + return $this; + } + + /** + * Get feed encoding + * + * @return string + */ + public function getEncoding() + { + return $this->encoding; + } + + /** + * Set a block value of "yes" or "no". You may also set an empty string. + * + * @param string + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesBlock($value) + { + if (!ctype_alpha($value) && strlen($value) > 0) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' + . ' contain alphabetic characters'); + } + + if ($this->stringWrapper->strlen($value) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' + . ' contain a maximum of 255 characters'); + } + $this->data['block'] = $value; + } + + /** + * Add authors to itunes entry + * + * @param array $values + * @return Entry + */ + public function addItunesAuthors(array $values) + { + foreach ($values as $value) { + $this->addItunesAuthor($value); + } + return $this; + } + + /** + * Add author to itunes entry + * + * @param string $value + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function addItunesAuthor($value) + { + if ($this->stringWrapper->strlen($value) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' + . ' contain a maximum of 255 characters each'); + } + if (!isset($this->data['authors'])) { + $this->data['authors'] = array(); + } + $this->data['authors'][] = $value; + return $this; + } + + /** + * Set duration + * + * @param int $value + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesDuration($value) + { + $value = (string) $value; + if (!ctype_digit($value) + && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) + && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) + ) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only' + . ' be of a specified [[HH:]MM:]SS format'); + } + $this->data['duration'] = $value; + return $this; + } + + /** + * Set "explicit" flag + * + * @param bool $value + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesExplicit($value) + { + if (!in_array($value, array('yes', 'no', 'clean'))) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only' + . ' be one of "yes", "no" or "clean"'); + } + $this->data['explicit'] = $value; + return $this; + } + + /** + * Set keywords + * + * @param array $value + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesKeywords(array $value) + { + if (count($value) > 12) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' + . ' contain a maximum of 12 terms'); + } + + $concat = implode(',', $value); + if ($this->stringWrapper->strlen($concat) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' + . ' have a concatenated length of 255 chars where terms are delimited' + . ' by a comma'); + } + $this->data['keywords'] = $value; + return $this; + } + + /** + * Set subtitle + * + * @param string $value + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesSubtitle($value) + { + if ($this->stringWrapper->strlen($value) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only' + . ' contain a maximum of 255 characters'); + } + $this->data['subtitle'] = $value; + return $this; + } + + /** + * Set summary + * + * @param string $value + * @return Entry + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesSummary($value) + { + if ($this->stringWrapper->strlen($value) > 4000) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' + . ' contain a maximum of 4000 characters'); + } + $this->data['summary'] = $value; + return $this; + } + + /** + * Overloading to itunes specific setters + * + * @param string $method + * @param array $params + * @throws Writer\Exception\BadMethodCallException + * @return mixed + */ + public function __call($method, array $params) + { + $point = lcfirst(substr($method, 9)); + if (!method_exists($this, 'setItunes' . ucfirst($point)) + && !method_exists($this, 'addItunes' . ucfirst($point)) + ) { + throw new Writer\Exception\BadMethodCallException( + 'invalid method: ' . $method + ); + } + if (!array_key_exists($point, $this->data) + || empty($this->data[$point]) + ) { + return null; + } + return $this->data[$point]; + } +} diff --git a/3rdparty/ZendFeed/Writer/Extension/ITunes/Feed.php b/3rdparty/ZendFeed/Writer/Extension/ITunes/Feed.php new file mode 100644 index 000000000..22c54db6e --- /dev/null +++ b/3rdparty/ZendFeed/Writer/Extension/ITunes/Feed.php @@ -0,0 +1,362 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Feed\Writer\Extension\ITunes; + +use Zend\Feed\Uri; +use Zend\Feed\Writer; +use Zend\Stdlib\StringUtils; +use Zend\Stdlib\StringWrapper\StringWrapperInterface; + +/** +*/ +class Feed +{ + /** + * Array of Feed data for rendering by Extension's renderers + * + * @var array + */ + protected $data = array(); + + /** + * Encoding of all text values + * + * @var string + */ + protected $encoding = 'UTF-8'; + + /** + * The used string wrapper supporting encoding + * + * @var StringWrapperInterface + */ + protected $stringWrapper; + + /** + * Constructor + */ + public function __construct() + { + $this->stringWrapper = StringUtils::getWrapper($this->encoding); + } + + /** + * Set feed encoding + * + * @param string $enc + * @return Feed + */ + public function setEncoding($enc) + { + $this->stringWrapper = StringUtils::getWrapper($enc); + $this->encoding = $enc; + return $this; + } + + /** + * Get feed encoding + * + * @return string + */ + public function getEncoding() + { + return $this->encoding; + } + + /** + * Set a block value of "yes" or "no". You may also set an empty string. + * + * @param string + * @return Feed + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesBlock($value) + { + if (!ctype_alpha($value) && strlen($value) > 0) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' + . ' contain alphabetic characters'); + } + if ($this->stringWrapper->strlen($value) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' + . ' contain a maximum of 255 characters'); + } + $this->data['block'] = $value; + return $this; + } + + /** + * Add feed authors + * + * @param array $values + * @return Feed + */ + public function addItunesAuthors(array $values) + { + foreach ($values as $value) { + $this->addItunesAuthor($value); + } + return $this; + } + + /** + * Add feed author + * + * @param string $value + * @return Feed + * @throws Writer\Exception\InvalidArgumentException + */ + public function addItunesAuthor($value) + { + if ($this->stringWrapper->strlen($value) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' + . ' contain a maximum of 255 characters each'); + } + if (!isset($this->data['authors'])) { + $this->data['authors'] = array(); + } + $this->data['authors'][] = $value; + return $this; + } + + /** + * Set feed categories + * + * @param array $values + * @return Feed + * @throws Writer\Exception\InvalidArgumentException + */ + public function setItunesCategories(array $values) + { + if (!isset($this->data['categories'])) { + $this->data['categories'] = array(); + } + foreach ($values as $key => $value) { + if (!is_array($value)) { + if ($this->stringWrapper->strlen($value) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' + . ' contain a maximum of 255 characters each'); + } + $this->data['categories'][] = $value; + } else { + if ($this->stringWrapper->strlen($key) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' + . ' contain a maximum of 255 characters each'); + } + $this->data['categories'][$key] = array(); + foreach ($value as $val) { + if ($this->stringWrapper->strlen($val) > 255) { + throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' + . ' contain a maximum of 255 characters each'); + } + $this->data['categories'][$key][] = $val; + } + } + } + return $this; + } + + /** + * Set feed image (icon)< |