CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,405 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 20507 2010-01-21 22:21:07Z padraic $
*/
/**
* @see Zend_Feed_Writer_Renderer_RendererAbstract
*/
require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/Source.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Entry_Atom
extends Zend_Feed_Writer_Renderer_RendererAbstract
implements Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Entry $container
* @return void
*/
public function __construct (Zend_Feed_Writer_Entry $container)
{
parent::__construct($container);
}
/**
* Render atom entry
*
* @return Zend_Feed_Writer_Renderer_Entry_Atom
*/
public function render()
{
$this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
$this->_dom->formatOutput = true;
$entry = $this->_dom->createElementNS(Zend_Feed_Writer::NAMESPACE_ATOM_10, 'entry');
$this->_dom->appendChild($entry);
$this->_setSource($this->_dom, $entry);
$this->_setTitle($this->_dom, $entry);
$this->_setDescription($this->_dom, $entry);
$this->_setDateCreated($this->_dom, $entry);
$this->_setDateModified($this->_dom, $entry);
$this->_setLink($this->_dom, $entry);
$this->_setId($this->_dom, $entry);
$this->_setAuthors($this->_dom, $entry);
$this->_setEnclosure($this->_dom, $entry);
$this->_setContent($this->_dom, $entry);
$this->_setCategories($this->_dom, $entry);
foreach ($this->_extensions as $ext) {
$ext->setType($this->getType());
$ext->setRootElement($this->getRootElement());
$ext->setDomDocument($this->getDomDocument(), $entry);
$ext->render();
}
return $this;
}
/**
* Set entry title
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setTitle(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getTitle()) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 entry elements MUST contain exactly one'
. ' atom:title element but a title has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$title = $dom->createElement('title');
$root->appendChild($title);
$title->setAttribute('type', 'html');
$cdata = $dom->createCDATASection($this->getDataContainer()->getTitle());
$title->appendChild($cdata);
}
/**
* Set entry description
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDescription(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDescription()) {
return; // unless src content or base64
}
$subtitle = $dom->createElement('summary');
$root->appendChild($subtitle);
$subtitle->setAttribute('type', 'html');
$cdata = $dom->createCDATASection(
$this->getDataContainer()->getDescription()
);
$subtitle->appendChild($cdata);
}
/**
* Set date entry was modified
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateModified(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDateModified()) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 entry elements MUST contain exactly one'
. ' atom:updated element but a modification date has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$updated = $dom->createElement('updated');
$root->appendChild($updated);
$text = $dom->createTextNode(
$this->getDataContainer()->getDateModified()->get(Zend_Date::ISO_8601)
);
$updated->appendChild($text);
}
/**
* Set date entry was created
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateCreated(DOMDocument $dom, DOMElement $root)
{
if (!$this->getDataContainer()->getDateCreated()) {
return;
}
$el = $dom->createElement('published');
$root->appendChild($el);
$text = $dom->createTextNode(
$this->getDataContainer()->getDateCreated()->get(Zend_Date::ISO_8601)
);
$el->appendChild($text);
}
/**
* Set entry authors
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setAuthors(DOMDocument $dom, DOMElement $root)
{
$authors = $this->_container->getAuthors();
if ((!$authors || empty($authors))) {
/**
* This will actually trigger an Exception at the feed level if
* a feed level author is not set.
*/
return;
}
foreach ($authors as $data) {
$author = $this->_dom->createElement('author');
$name = $this->_dom->createElement('name');
$author->appendChild($name);
$root->appendChild($author);
$text = $dom->createTextNode($data['name']);
$name->appendChild($text);
if (array_key_exists('email', $data)) {
$email = $this->_dom->createElement('email');
$author->appendChild($email);
$text = $dom->createTextNode($data['email']);
$email->appendChild($text);
}
if (array_key_exists('uri', $data)) {
$uri = $this->_dom->createElement('uri');
$author->appendChild($uri);
$text = $dom->createTextNode($data['uri']);
$uri->appendChild($text);
}
}
}
/**
* Set entry enclosure
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setEnclosure(DOMDocument $dom, DOMElement $root)
{
$data = $this->_container->getEnclosure();
if ((!$data || empty($data))) {
return;
}
$enclosure = $this->_dom->createElement('link');
$enclosure->setAttribute('rel', 'enclosure');
$enclosure->setAttribute('type', $data['type']);
$enclosure->setAttribute('length', $data['length']);
$enclosure->setAttribute('href', $data['uri']);
$root->appendChild($enclosure);
}
protected function _setLink(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getLink()) {
return;
}
$link = $dom->createElement('link');
$root->appendChild($link);
$link->setAttribute('rel', 'alternate');
$link->setAttribute('type', 'text/html');
$link->setAttribute('href', $this->getDataContainer()->getLink());
}
/**
* Set entry identifier
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setId(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getId()
&& !$this->getDataContainer()->getLink()) {
require_once 'Zend/Feed/Exception.php';
$message = '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';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
if (!$this->getDataContainer()->getId()) {
$this->getDataContainer()->setId(
$this->getDataContainer()->getLink());
}
if (!Zend_Uri::check($this->getDataContainer()->getId()) &&
!preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", $this->getDataContainer()->getId())) {
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Atom 1.0 IDs must be a valid URI/IRI');
}
$id = $dom->createElement('id');
$root->appendChild($id);
$text = $dom->createTextNode($this->getDataContainer()->getId());
$id->appendChild($text);
}
/**
* Set entry content
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setContent(DOMDocument $dom, DOMElement $root)
{
$content = $this->getDataContainer()->getContent();
if (!$content && !$this->getDataContainer()->getLink()) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 entry elements MUST contain exactly one '
. 'atom:content element, or as an alternative, at least one link '
. 'with a rel attribute of "alternate" to indicate an alternate '
. 'method to consume the content.';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
if (!$content) {
return;
}
$element = $dom->createElement('content');
$element->setAttribute('type', 'xhtml');
$xhtmlElement = $this->_loadXhtml($content);
$xhtml = $dom->importNode($xhtmlElement, true);
$element->appendChild($xhtml);
$root->appendChild($element);
}
/**
* Load a HTML string and attempt to normalise to XML
*/
protected function _loadXhtml($content)
{
$xhtml = '';
if (class_exists('tidy', false)) {
$tidy = new tidy;
$config = array(
'output-xhtml' => true,
'show-body-only' => true
);
$encoding = str_replace('-', '', $this->getEncoding());
$tidy->parseString($content, $config, $encoding);
$tidy->cleanRepair();
$xhtml = (string) $tidy;
} else {
$xhtml = $content;
}
$xhtml = preg_replace(array(
"/(<[\/]?)([a-zA-Z]+)/"
), '$1xhtml:$2', $xhtml);
$dom = new DOMDocument('1.0', $this->getEncoding());
$dom->loadXML('<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">'
. $xhtml . '</xhtml:div>');
return $dom->documentElement;
}
/**
* Set entry cateories
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCategories(DOMDocument $dom, DOMElement $root)
{
$categories = $this->getDataContainer()->getCategories();
if (!$categories) {
return;
}
foreach ($categories as $cat) {
$category = $dom->createElement('category');
$category->setAttribute('term', $cat['term']);
if (isset($cat['label'])) {
$category->setAttribute('label', $cat['label']);
} else {
$category->setAttribute('label', $cat['term']);
}
if (isset($cat['scheme'])) {
$category->setAttribute('scheme', $cat['scheme']);
}
$root->appendChild($category);
}
}
/**
* Append Source element (Atom 1.0 Feed Metadata)
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setSource(DOMDocument $dom, DOMElement $root)
{
$source = $this->getDataContainer()->getSource();
if (!$source) {
return;
}
$renderer = new Zend_Feed_Writer_Renderer_Feed_Atom_Source($source);
$renderer->setType($this->getType());
$element = $renderer->render()->getElement();
$imported = $dom->importNode($element, true);
$root->appendChild($imported);
}
}

View file

@ -0,0 +1,121 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 20506 2010-01-21 22:19:05Z padraic $
*/
/**
* @see Zend_Feed_Writer_Renderer_RendererAbstract
*/
require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted
extends Zend_Feed_Writer_Renderer_RendererAbstract
implements Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Deleted $container
* @return void
*/
public function __construct (Zend_Feed_Writer_Deleted $container)
{
parent::__construct($container);
}
/**
* Render atom entry
*
* @return Zend_Feed_Writer_Renderer_Entry_Atom
*/
public function render()
{
$this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
$this->_dom->formatOutput = true;
$entry = $this->_dom->createElement('at:deleted-entry');
$this->_dom->appendChild($entry);
$entry->setAttribute('ref', $this->_container->getReference());
$entry->setAttribute('when', $this->_container->getWhen()->get(Zend_Date::ISO_8601));
$this->_setBy($this->_dom, $entry);
$this->_setComment($this->_dom, $entry);
return $this;
}
/**
* Set tombstone comment
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setComment(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getComment()) {
return;
}
$c = $dom->createElement('at:comment');
$root->appendChild($c);
$c->setAttribute('type', 'html');
$cdata = $dom->createCDATASection($this->getDataContainer()->getComment());
$c->appendChild($cdata);
}
/**
* Set entry authors
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setBy(DOMDocument $dom, DOMElement $root)
{
$data = $this->_container->getBy();
if ((!$data || empty($data))) {
return;
}
$author = $this->_dom->createElement('at:by');
$name = $this->_dom->createElement('name');
$author->appendChild($name);
$root->appendChild($author);
$text = $dom->createTextNode($data['name']);
$name->appendChild($text);
if (array_key_exists('email', $data)) {
$email = $this->_dom->createElement('email');
$author->appendChild($email);
$text = $dom->createTextNode($data['email']);
$email->appendChild($text);
}
if (array_key_exists('uri', $data)) {
$uri = $this->_dom->createElement('uri');
$author->appendChild($uri);
$text = $dom->createTextNode($data['uri']);
$uri->appendChild($text);
}
}
}

View file

@ -0,0 +1,315 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Rss.php 20241 2010-01-12 20:19:46Z padraic $
*/
/**
* @see Zend_Feed_Writer_Renderer_RendererAbstract
*/
require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Entry_Rss
extends Zend_Feed_Writer_Renderer_RendererAbstract
implements Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Entry $container
* @return void
*/
public function __construct (Zend_Feed_Writer_Entry $container)
{
parent::__construct($container);
}
/**
* Render RSS entry
*
* @return Zend_Feed_Writer_Renderer_Entry_Rss
*/
public function render()
{
$this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
$this->_dom->formatOutput = true;
$this->_dom->substituteEntities = false;
$entry = $this->_dom->createElement('item');
$this->_dom->appendChild($entry);
$this->_setTitle($this->_dom, $entry);
$this->_setDescription($this->_dom, $entry);
$this->_setDateCreated($this->_dom, $entry);
$this->_setDateModified($this->_dom, $entry);
$this->_setLink($this->_dom, $entry);
$this->_setId($this->_dom, $entry);
$this->_setAuthors($this->_dom, $entry);
$this->_setEnclosure($this->_dom, $entry);
$this->_setCommentLink($this->_dom, $entry);
$this->_setCategories($this->_dom, $entry);
foreach ($this->_extensions as $ext) {
$ext->setType($this->getType());
$ext->setRootElement($this->getRootElement());
$ext->setDomDocument($this->getDomDocument(), $entry);
$ext->render();
}
return $this;
}
/**
* Set entry title
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setTitle(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDescription()
&& !$this->getDataContainer()->getTitle()) {
require_once 'Zend/Feed/Exception.php';
$message = 'RSS 2.0 entry elements SHOULD contain exactly one'
. ' title element but a title has not been set. In addition, there'
. ' is no description as required in the absence of a title.';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$title = $dom->createElement('title');
$root->appendChild($title);
$text = $dom->createTextNode($this->getDataContainer()->getTitle());
$title->appendChild($text);
}
/**
* Set entry description
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDescription(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDescription()
&& !$this->getDataContainer()->getTitle()) {
require_once 'Zend/Feed/Exception.php';
$message = 'RSS 2.0 entry elements SHOULD contain exactly one'
. ' description element but a description has not been set. In'
. ' addition, there is no title element as required in the absence'
. ' of a description.';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
if (!$this->getDataContainer()->getDescription()) {
return;
}
$subtitle = $dom->createElement('description');
$root->appendChild($subtitle);
$text = $dom->createCDATASection($this->getDataContainer()->getDescription());
$subtitle->appendChild($text);
}
/**
* Set date entry was last modified
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateModified(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDateModified()) {
return;
}
$updated = $dom->createElement('pubDate');
$root->appendChild($updated);
$text = $dom->createTextNode(
$this->getDataContainer()->getDateModified()->get(Zend_Date::RSS)
);
$updated->appendChild($text);
}
/**
* Set date entry was created
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateCreated(DOMDocument $dom, DOMElement $root)
{
if (!$this->getDataContainer()->getDateCreated()) {
return;
}
if (!$this->getDataContainer()->getDateModified()) {
$this->getDataContainer()->setDateModified(
$this->getDataContainer()->getDateCreated()
);
}
}
/**
* Set entry authors
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setAuthors(DOMDocument $dom, DOMElement $root)
{
$authors = $this->_container->getAuthors();
if ((!$authors || empty($authors))) {
return;
}
foreach ($authors as $data) {
$author = $this->_dom->createElement('author');
$name = $data['name'];
if (array_key_exists('email', $data)) {
$name = $data['email'] . ' (' . $data['name'] . ')';
}
$text = $dom->createTextNode($name);
$author->appendChild($text);
$root->appendChild($author);
}
}
/**
* Set entry enclosure
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setEnclosure(DOMDocument $dom, DOMElement $root)
{
$data = $this->_container->getEnclosure();
if ((!$data || empty($data))) {
return;
}
$enclosure = $this->_dom->createElement('enclosure');
$enclosure->setAttribute('type', $data['type']);
$enclosure->setAttribute('length', $data['length']);
$enclosure->setAttribute('url', $data['uri']);
$root->appendChild($enclosure);
}
/**
* Set link to entry
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setLink(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getLink()) {
return;
}
$link = $dom->createElement('link');
$root->appendChild($link);
$text = $dom->createTextNode($this->getDataContainer()->getLink());
$link->appendChild($text);
}
/**
* Set entry identifier
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setId(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getId()
&& !$this->getDataContainer()->getLink()) {
return;
}
$id = $dom->createElement('guid');
$root->appendChild($id);
if (!$this->getDataContainer()->getId()) {
$this->getDataContainer()->setId(
$this->getDataContainer()->getLink());
}
$text = $dom->createTextNode($this->getDataContainer()->getId());
$id->appendChild($text);
if (!Zend_Uri::check($this->getDataContainer()->getId())) {
$id->setAttribute('isPermaLink', 'false');
}
}
/**
* Set link to entry comments
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
{
$link = $this->getDataContainer()->getCommentLink();
if (!$link) {
return;
}
$clink = $this->_dom->createElement('comments');
$text = $dom->createTextNode($link);
$clink->appendChild($text);
$root->appendChild($clink);
}
/**
* Set entry categories
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCategories(DOMDocument $dom, DOMElement $root)
{
$categories = $this->getDataContainer()->getCategories();
if (!$categories) {
return;
}
foreach ($categories as $cat) {
$category = $dom->createElement('category');
if (isset($cat['scheme'])) {
$category->setAttribute('domain', $cat['scheme']);
}
$text = $dom->createCDATASection($cat['term']);
$category->appendChild($text);
$root->appendChild($category);
}
}
}

View file

@ -0,0 +1,129 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 20519 2010-01-22 14:06:24Z padraic $
*/
/** @see Zend_Feed_Writer_Feed */
require_once 'Zend/Feed/Writer/Feed.php';
/** @see Zend_Version */
require_once 'Zend/Version.php';
/** @see Zend_Feed_Writer_Renderer_RendererInterface */
require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php';
/** @see Zend_Feed_Writer_Renderer_Entry_Atom */
require_once 'Zend/Feed/Writer/Renderer/Entry/Atom.php';
/** @see Zend_Feed_Writer_Renderer_Entry_Atom_Deleted */
require_once 'Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php';
/** @see Zend_Feed_Writer_Renderer_RendererAbstract */
require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Feed_Atom
extends Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract
implements Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Feed $container
* @return void
*/
public function __construct (Zend_Feed_Writer_Feed $container)
{
parent::__construct($container);
}
/**
* Render Atom feed
*
* @return Zend_Feed_Writer_Renderer_Feed_Atom
*/
public function render()
{
if (!$this->_container->getEncoding()) {
$this->_container->setEncoding('UTF-8');
}
$this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
$this->_dom->formatOutput = true;
$root = $this->_dom->createElementNS(
Zend_Feed_Writer::NAMESPACE_ATOM_10, 'feed'
);
$this->setRootElement($root);
$this->_dom->appendChild($root);
$this->_setLanguage($this->_dom, $root);
$this->_setBaseUrl($this->_dom, $root);
$this->_setTitle($this->_dom, $root);
$this->_setDescription($this->_dom, $root);
$this->_setDateCreated($this->_dom, $root);
$this->_setDateModified($this->_dom, $root);
$this->_setGenerator($this->_dom, $root);
$this->_setLink($this->_dom, $root);
$this->_setFeedLinks($this->_dom, $root);
$this->_setId($this->_dom, $root);
$this->_setAuthors($this->_dom, $root);
$this->_setCopyright($this->_dom, $root);
$this->_setCategories($this->_dom, $root);
$this->_setHubs($this->_dom, $root);
foreach ($this->_extensions as $ext) {
$ext->setType($this->getType());
$ext->setRootElement($this->getRootElement());
$ext->setDomDocument($this->getDomDocument(), $root);
$ext->render();
}
foreach ($this->_container as $entry) {
if ($this->getDataContainer()->getEncoding()) {
$entry->setEncoding($this->getDataContainer()->getEncoding());
}
if ($entry instanceof Zend_Feed_Writer_Entry) {
$renderer = new Zend_Feed_Writer_Renderer_Entry_Atom($entry);
} else {
if (!$this->_dom->documentElement->hasAttribute('xmlns:at')) {
$this->_dom->documentElement->setAttribute(
'xmlns:at', 'http://purl.org/atompub/tombstones/1.0'
);
}
$renderer = new Zend_Feed_Writer_Renderer_Entry_Atom_Deleted($entry);
}
if ($this->_ignoreExceptions === true) {
$renderer->ignoreExceptions();
}
$renderer->setType($this->getType());
$renderer->setRootElement($this->_dom->documentElement);
$renderer->render();
$element = $renderer->getElement();
$imported = $this->_dom->importNode($element, true);
$root->appendChild($imported);
}
return $this;
}
}

View file

@ -0,0 +1,408 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Feed_Writer_Feed */
require_once 'Zend/Feed/Writer/Feed.php';
/** @see Zend_Version */
require_once 'Zend/Version.php';
/** @see Zend_Feed_Writer_Renderer_RendererInterface */
require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php';
/** @see Zend_Feed_Writer_Renderer_Entry_Atom */
require_once 'Zend/Feed/Writer/Renderer/Entry/Atom.php';
/** @see Zend_Feed_Writer_Renderer_RendererAbstract */
require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract
extends Zend_Feed_Writer_Renderer_RendererAbstract
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Feed $container
* @return void
*/
public function __construct ($container)
{
parent::__construct($container);
}
/**
* Set feed language
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setLanguage(DOMDocument $dom, DOMElement $root)
{
if ($this->getDataContainer()->getLanguage()) {
$root->setAttribute('xml:lang', $this->getDataContainer()
->getLanguage());
}
}
/**
* Set feed title
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setTitle(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getTitle()) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 feed elements MUST contain exactly one'
. ' atom:title element but a title has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$title = $dom->createElement('title');
$root->appendChild($title);
$title->setAttribute('type', 'text');
$text = $dom->createTextNode($this->getDataContainer()->getTitle());
$title->appendChild($text);
}
/**
* Set feed description
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDescription(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDescription()) {
return;
}
$subtitle = $dom->createElement('subtitle');
$root->appendChild($subtitle);
$subtitle->setAttribute('type', 'text');
$text = $dom->createTextNode($this->getDataContainer()->getDescription());
$subtitle->appendChild($text);
}
/**
* Set date feed was last modified
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateModified(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDateModified()) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 feed elements MUST contain exactly one'
. ' atom:updated element but a modification date has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$updated = $dom->createElement('updated');
$root->appendChild($updated);
$text = $dom->createTextNode(
$this->getDataContainer()->getDateModified()->get(Zend_Date::ISO_8601)
);
$updated->appendChild($text);
}
/**
* Set feed generator string
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setGenerator(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getGenerator()) {
$this->getDataContainer()->setGenerator('Zend_Feed_Writer',
Zend_Version::VERSION, 'http://framework.zend.com');
}
$gdata = $this->getDataContainer()->getGenerator();
$generator = $dom->createElement('generator');
$root->appendChild($generator);
$text = $dom->createTextNode($gdata['name']);
$generator->appendChild($text);
if (array_key_exists('uri', $gdata)) {
$generator->setAttribute('uri', $gdata['uri']);
}
if (array_key_exists('version', $gdata)) {
$generator->setAttribute('version', $gdata['version']);
}
}
/**
* Set link to feed
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setLink(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getLink()) {
return;
}
$link = $dom->createElement('link');
$root->appendChild($link);
$link->setAttribute('rel', 'alternate');
$link->setAttribute('type', 'text/html');
$link->setAttribute('href', $this->getDataContainer()->getLink());
}
/**
* Set feed links
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setFeedLinks(DOMDocument $dom, DOMElement $root)
{
$flinks = $this->getDataContainer()->getFeedLinks();
if(!$flinks || !array_key_exists('atom', $flinks)) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 feed elements SHOULD contain one atom:link '
. 'element with a rel attribute value of "self". This is the '
. 'preferred URI for retrieving Atom Feed Documents representing '
. 'this Atom feed but a feed link has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
foreach ($flinks as $type => $href) {
$mime = 'application/' . strtolower($type) . '+xml';
$flink = $dom->createElement('link');
$root->appendChild($flink);
$flink->setAttribute('rel', 'self');
$flink->setAttribute('type', $mime);
$flink->setAttribute('href', $href);
}
}
/**
* Set feed authors
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setAuthors(DOMDocument $dom, DOMElement $root)
{
$authors = $this->_container->getAuthors();
if (!$authors || empty($authors)) {
/**
* Technically we should defer an exception until we can check
* that all entries contain an author. If any entry is missing
* an author, then a missing feed author element is invalid
*/
return;
}
foreach ($authors as $data) {
$author = $this->_dom->createElement('author');
$name = $this->_dom->createElement('name');
$author->appendChild($name);
$root->appendChild($author);
$text = $dom->createTextNode($data['name']);
$name->appendChild($text);
if (array_key_exists('email', $data)) {
$email = $this->_dom->createElement('email');
$author->appendChild($email);
$text = $dom->createTextNode($data['email']);
$email->appendChild($text);
}
if (array_key_exists('uri', $data)) {
$uri = $this->_dom->createElement('uri');
$author->appendChild($uri);
$text = $dom->createTextNode($data['uri']);
$uri->appendChild($text);
}
}
}
/**
* Set feed identifier
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setId(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getId()
&& !$this->getDataContainer()->getLink()) {
require_once 'Zend/Feed/Exception.php';
$message = 'Atom 1.0 feed 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';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
if (!$this->getDataContainer()->getId()) {
$this->getDataContainer()->setId(
$this->getDataContainer()->getLink());
}
$id = $dom->createElement('id');
$root->appendChild($id);
$text = $dom->createTextNode($this->getDataContainer()->getId());
$id->appendChild($text);
}
/**
* Set feed copyright
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCopyright(DOMDocument $dom, DOMElement $root)
{
$copyright = $this->getDataContainer()->getCopyright();
if (!$copyright) {
return;
}
$copy = $dom->createElement('rights');
$root->appendChild($copy);
$text = $dom->createTextNode($copyright);
$copy->appendChild($text);
}
/**
* Set date feed was created
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateCreated(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDateCreated()) {
return;
}
if(!$this->getDataContainer()->getDateModified()) {
$this->getDataContainer()->setDateModified(
$this->getDataContainer()->getDateCreated()
);
}
}
/**
* Set base URL to feed links
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setBaseUrl(DOMDocument $dom, DOMElement $root)
{
$baseUrl = $this->getDataContainer()->getBaseUrl();
if (!$baseUrl) {
return;
}
$root->setAttribute('xml:base', $baseUrl);
}
/**
* Set hubs to which this feed pushes
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setHubs(DOMDocument $dom, DOMElement $root)
{
$hubs = $this->getDataContainer()->getHubs();
if (!$hubs) {
return;
}
foreach ($hubs as $hubUrl) {
$hub = $dom->createElement('link');
$hub->setAttribute('rel', 'hub');
$hub->setAttribute('href', $hubUrl);
$root->appendChild($hub);
}
}
/**
* Set feed cateories
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCategories(DOMDocument $dom, DOMElement $root)
{
$categories = $this->getDataContainer()->getCategories();
if (!$categories) {
return;
}
foreach ($categories as $cat) {
$category = $dom->createElement('category');
$category->setAttribute('term', $cat['term']);
if (isset($cat['label'])) {
$category->setAttribute('label', $cat['label']);
} else {
$category->setAttribute('label', $cat['term']);
}
if (isset($cat['scheme'])) {
$category->setAttribute('scheme', $cat['scheme']);
}
$root->appendChild($category);
}
}
}

View file

@ -0,0 +1,110 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Feed_Atom_Source
extends Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract
implements Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Feed_Source $container
* @return void
*/
public function __construct (Zend_Feed_Writer_Source $container)
{
parent::__construct($container);
}
/**
* Render Atom Feed Metadata (Source element)
*
* @return Zend_Feed_Writer_Renderer_Feed_Atom
*/
public function render()
{
if (!$this->_container->getEncoding()) {
$this->_container->setEncoding('UTF-8');
}
$this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
$this->_dom->formatOutput = true;
$root = $this->_dom->createElement('source');
$this->setRootElement($root);
$this->_dom->appendChild($root);
$this->_setLanguage($this->_dom, $root);
$this->_setBaseUrl($this->_dom, $root);
$this->_setTitle($this->_dom, $root);
$this->_setDescription($this->_dom, $root);
$this->_setDateCreated($this->_dom, $root);
$this->_setDateModified($this->_dom, $root);
$this->_setGenerator($this->_dom, $root);
$this->_setLink($this->_dom, $root);
$this->_setFeedLinks($this->_dom, $root);
$this->_setId($this->_dom, $root);
$this->_setAuthors($this->_dom, $root);
$this->_setCopyright($this->_dom, $root);
$this->_setCategories($this->_dom, $root);
foreach ($this->_extensions as $ext) {
$ext->setType($this->getType());
$ext->setRootElement($this->getRootElement());
$ext->setDomDocument($this->getDomDocument(), $root);
$ext->render();
}
return $this;
}
/**
* Set feed generator string
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setGenerator(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getGenerator()) {
return;
}
$gdata = $this->getDataContainer()->getGenerator();
$generator = $dom->createElement('generator');
$root->appendChild($generator);
$text = $dom->createTextNode($gdata['name']);
$generator->appendChild($text);
if (array_key_exists('uri', $gdata)) {
$generator->setAttribute('uri', $gdata['uri']);
}
if (array_key_exists('version', $gdata)) {
$generator->setAttribute('version', $gdata['version']);
}
}
}

View file

@ -0,0 +1,374 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Rss.php 20519 2010-01-22 14:06:24Z padraic $
*/
/** @see Zend_Feed_Writer_Feed */
require_once 'Zend/Feed/Writer/Feed.php';
/** @see Zend_Version */
require_once 'Zend/Version.php';
/** @see Zend_Feed_Writer_Renderer_RendererInterface */
require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php';
/** @see Zend_Feed_Writer_Renderer_Entry_Rss */
require_once 'Zend/Feed/Writer/Renderer/Entry/Rss.php';
/** @see Zend_Feed_Writer_Renderer_RendererAbstract */
require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_Feed_Rss
extends Zend_Feed_Writer_Renderer_RendererAbstract
implements Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Constructor
*
* @param Zend_Feed_Writer_Feed $container
* @return void
*/
public function __construct (Zend_Feed_Writer_Feed $container)
{
parent::__construct($container);
}
/**
* Render RSS feed
*
* @return Zend_Feed_Writer_Renderer_Feed_Rss
*/
public function render()
{
if (!$this->_container->getEncoding()) {
$this->_container->setEncoding('UTF-8');
}
$this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
$this->_dom->formatOutput = true;
$this->_dom->substituteEntities = false;
$rss = $this->_dom->createElement('rss');
$this->setRootElement($rss);
$rss->setAttribute('version', '2.0');
$channel = $this->_dom->createElement('channel');
$rss->appendChild($channel);
$this->_dom->appendChild($rss);
$this->_setLanguage($this->_dom, $channel);
$this->_setBaseUrl($this->_dom, $channel);
$this->_setTitle($this->_dom, $channel);
$this->_setDescription($this->_dom, $channel);
$this->_setDateCreated($this->_dom, $channel);
$this->_setDateModified($this->_dom, $channel);
$this->_setGenerator($this->_dom, $channel);
$this->_setLink($this->_dom, $channel);
$this->_setAuthors($this->_dom, $channel);
$this->_setCopyright($this->_dom, $channel);
$this->_setCategories($this->_dom, $channel);
foreach ($this->_extensions as $ext) {
$ext->setType($this->getType());
$ext->setRootElement($this->getRootElement());
$ext->setDomDocument($this->getDomDocument(), $channel);
$ext->render();
}
foreach ($this->_container as $entry) {
if ($this->getDataContainer()->getEncoding()) {
$entry->setEncoding($this->getDataContainer()->getEncoding());
}
if ($entry instanceof Zend_Feed_Writer_Entry) {
$renderer = new Zend_Feed_Writer_Renderer_Entry_Rss($entry);
} else {
continue;
}
if ($this->_ignoreExceptions === true) {
$renderer->ignoreExceptions();
}
$renderer->setType($this->getType());
$renderer->setRootElement($this->_dom->documentElement);
$renderer->render();
$element = $renderer->getElement();
$imported = $this->_dom->importNode($element, true);
$channel->appendChild($imported);
}
return $this;
}
/**
* Set feed language
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setLanguage(DOMDocument $dom, DOMElement $root)
{
$lang = $this->getDataContainer()->getLanguage();
if (!$lang) {
return;
}
$language = $dom->createElement('language');
$root->appendChild($language);
$language->nodeValue = $lang;
}
/**
* Set feed title
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setTitle(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getTitle()) {
require_once 'Zend/Feed/Exception.php';
$message = 'RSS 2.0 feed elements MUST contain exactly one'
. ' title element but a title has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$title = $dom->createElement('title');
$root->appendChild($title);
$text = $dom->createTextNode($this->getDataContainer()->getTitle());
$title->appendChild($text);
}
/**
* Set feed description
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDescription(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDescription()) {
require_once 'Zend/Feed/Exception.php';
$message = 'RSS 2.0 feed elements MUST contain exactly one'
. ' description element but one has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$subtitle = $dom->createElement('description');
$root->appendChild($subtitle);
$text = $dom->createTextNode($this->getDataContainer()->getDescription());
$subtitle->appendChild($text);
}
/**
* Set date feed was last modified
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateModified(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDateModified()) {
return;
}
$updated = $dom->createElement('pubDate');
$root->appendChild($updated);
$text = $dom->createTextNode(
$this->getDataContainer()->getDateModified()->get(Zend_Date::RSS)
);
$updated->appendChild($text);
}
/**
* Set feed generator string
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setGenerator(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getGenerator()) {
$this->getDataContainer()->setGenerator('Zend_Feed_Writer',
Zend_Version::VERSION, 'http://framework.zend.com');
}
$gdata = $this->getDataContainer()->getGenerator();
$generator = $dom->createElement('generator');
$root->appendChild($generator);
$name = $gdata['name'];
if (array_key_exists('version', $gdata)) {
$name .= ' ' . $gdata['version'];
}
if (array_key_exists('uri', $gdata)) {
$name .= ' (' . $gdata['uri'] . ')';
}
$text = $dom->createTextNode($name);
$generator->appendChild($text);
}
/**
* Set link to feed
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setLink(DOMDocument $dom, DOMElement $root)
{
$value = $this->getDataContainer()->getLink();
if(!$value) {
require_once 'Zend/Feed/Exception.php';
$message = 'RSS 2.0 feed elements MUST contain exactly one'
. ' link element but one has not been set';
$exception = new Zend_Feed_Exception($message);
if (!$this->_ignoreExceptions) {
throw $exception;
} else {
$this->_exceptions[] = $exception;
return;
}
}
$link = $dom->createElement('link');
$root->appendChild($link);
$text = $dom->createTextNode($value);
$link->appendChild($text);
if (!Zend_Uri::check($value)) {
$link->setAttribute('isPermaLink', 'false');
}
}
/**
* 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('author');
$name = $data['name'];
if (array_key_exists('email', $data)) {
$name = $data['email'] . ' (' . $data['name'] . ')';
}
$text = $dom->createTextNode($name);
$author->appendChild($text);
$root->appendChild($author);
}
}
/**
* Set feed copyright
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCopyright(DOMDocument $dom, DOMElement $root)
{
$copyright = $this->getDataContainer()->getCopyright();
if (!$copyright) {
return;
}
$copy = $dom->createElement('copyright');
$root->appendChild($copy);
$text = $dom->createTextNode($copyright);
$copy->appendChild($text);
}
/**
* Set date feed was created
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setDateCreated(DOMDocument $dom, DOMElement $root)
{
if(!$this->getDataContainer()->getDateCreated()) {
return;
}
if(!$this->getDataContainer()->getDateModified()) {
$this->getDataContainer()->setDateModified(
$this->getDataContainer()->getDateCreated()
);
}
}
/**
* Set base URL to feed links
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setBaseUrl(DOMDocument $dom, DOMElement $root)
{
$baseUrl = $this->getDataContainer()->getBaseUrl();
if (!$baseUrl) {
return;
}
$root->setAttribute('xml:base', $baseUrl);
}
/**
* Set feed categories
*
* @param DOMDocument $dom
* @param DOMElement $root
* @return void
*/
protected function _setCategories(DOMDocument $dom, DOMElement $root)
{
$categories = $this->getDataContainer()->getCategories();
if (!$categories) {
return;
}
foreach ($categories as $cat) {
$category = $dom->createElement('category');
if (isset($cat['scheme'])) {
$category->setAttribute('domain', $cat['scheme']);
}
$text = $dom->createTextNode($cat['term']);
$category->appendChild($text);
$root->appendChild($category);
}
}
}

View file

@ -0,0 +1,250 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: RendererAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Feed_Writer */
require_once 'Zend/Feed/Writer.php';
/** @see Zend_Version */
require_once 'Zend/Version.php';
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer_Renderer_RendererAbstract
{
/**
* Extensions
* @var array
*/
protected $_extensions = array();
/**
* @var mixed
*/
protected $_container = null;
/**
* @var DOMDocument
*/
protected $_dom = null;
/**
* @var bool
*/
protected $_ignoreExceptions = false;
/**
* @var array
*/
protected $_exceptions = array();
/**
* Encoding of all text values
*
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Holds the value "atom" or "rss" depending on the feed type set when
* when last exported.
*
* @var string
*/
protected $_type = null;
/**
* @var DOMElement
*/
protected $_rootElement = null;
/**
* Constructor
*
* @param mixed $container
* @return void
*/
public function __construct($container)
{
$this->_container = $container;
$this->setType($container->getType());
$this->_loadExtensions();
}
/**
* Save XML to string
*
* @return string
*/
public function saveXml()
{
return $this->getDomDocument()->saveXml();
}
/**
* Get DOM document
*
* @return DOMDocument
*/
public function getDomDocument()
{
return $this->_dom;
}
/**
* Get document element from DOM
*
* @return DOMElement
*/
public function getElement()
{
return $this->getDomDocument()->documentElement;
}
/**
* Get data container of items being rendered
*
* @return mixed
*/
public function getDataContainer()
{
return $this->_container;
}
/**
* Set feed encoding
*
* @param string $enc
* @return Zend_Feed_Writer_Renderer_RendererAbstract
*/
public function setEncoding($enc)
{
$this->_encoding = $enc;
return $this;
}
/**
* Get feed encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Indicate whether or not to ignore exceptions
*
* @param bool $bool
* @return Zend_Feed_Writer_Renderer_RendererAbstract
*/
public function ignoreExceptions($bool = true)
{
if (!is_bool($bool)) {
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)');
}
$this->_ignoreExceptions = $bool;
return $this;
}
/**
* Get exception list
*
* @return array
*/
public function getExceptions()
{
return $this->_exceptions;
}
/**
* Set the current feed type being exported to "rss" or "atom". This allows
* other objects to gracefully choose whether to execute or not, depending
* on their appropriateness for the current type, e.g. renderers.
*
* @param string $type
*/
public function setType($type)
{
$this->_type = $type;
}
/**
* Retrieve the current or last feed type exported.
*
* @return string Value will be "rss" or "atom"
*/
public function getType()
{
return $this->_type;
}
/**
* Sets the absolute root element for the XML feed being generated. This
* helps simplify the appending of namespace declarations, but also ensures
* namespaces are added to the root element - not scattered across the entire
* XML file - may assist namespace unsafe parsers and looks pretty ;).
*
* @param DOMElement $root
*/
public function setRootElement(DOMElement $root)
{
$this->_rootElement = $root;
}
/**
* Retrieve the absolute root element for the XML feed being generated.
*
* @return DOMElement
*/
public function getRootElement()
{
return $this->_rootElement;
}
/**
* Load extensions from Zend_Feed_Writer
*
* @return void
*/
protected function _loadExtensions()
{
Zend_Feed_Writer::registerCoreExtensions();
$all = Zend_Feed_Writer::getExtensions();
if (stripos(get_class($this), 'entry')) {
$exts = $all['entryRenderer'];
} else {
$exts = $all['feedRenderer'];
}
foreach ($exts as $extension) {
$className = Zend_Feed_Writer::getPluginLoader()->getClassName($extension);
$this->_extensions[$extension] = new $className(
$this->getDataContainer()
);
$this->_extensions[$extension]->setEncoding($this->getEncoding());
}
}
}

View file

@ -0,0 +1,111 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: RendererInterface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Feed_Writer_Renderer_RendererInterface
{
/**
* Render feed/entry
*
* @return void
*/
public function render();
/**
* Save feed and/or entry to XML and return string
*
* @return string
*/
public function saveXml();
/**
* Get DOM document
*
* @return DOMDocument
*/
public function getDomDocument();
/**
* Get document element from DOM
*
* @return DOMElement
*/
public function getElement();
/**
* Get data container containing feed items
*
* @return mixed
*/
public function getDataContainer();
/**
* Should exceptions be ignored?
*
* @return mixed
*/
public function ignoreExceptions();
/**
* Get list of thrown exceptions
*
* @return array
*/
public function getExceptions();
/**
* Set the current feed type being exported to "rss" or "atom". This allows
* other objects to gracefully choose whether to execute or not, depending
* on their appropriateness for the current type, e.g. renderers.
*
* @param string $type
*/
public function setType($type);
/**
* Retrieve the current or last feed type exported.
*
* @return string Value will be "rss" or "atom"
*/
public function getType();
/**
* Sets the absolute root element for the XML feed being generated. This
* helps simplify the appending of namespace declarations, but also ensures
* namespaces are added to the root element - not scattered across the entire
* XML file - may assist namespace unsafe parsers and looks pretty ;).
*
* @param DOMElement $root
*/
public function setRootElement(DOMElement $root);
/**
* Retrieve the absolute root element for the XML feed being generated.
*
* @return DOMElement
*/
public function getRootElement();
}