mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
V 3.5 RC 1
This commit is contained in:
354
lib/classes/Feed/XML/Abstract.class.php
Normal file
354
lib/classes/Feed/XML/Abstract.class.php
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class Feed_XML_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $updated_on;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subtitle;
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $items = array();
|
||||
/**
|
||||
*
|
||||
* @var Feed_Link
|
||||
*/
|
||||
protected $next_page;
|
||||
/**
|
||||
*
|
||||
* @var Feed_Link
|
||||
*/
|
||||
protected $previous_page;
|
||||
/**
|
||||
*
|
||||
* @var Feed_Link
|
||||
*/
|
||||
protected $link;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $generator;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mimetype;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $title
|
||||
*/
|
||||
public function set_title($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DateTime $datetime
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_updated_on(DateTime $datetime)
|
||||
{
|
||||
$this->updated_on = $datetime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $subtitle
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_subtitle($subtitle)
|
||||
{
|
||||
$this->subtitle = $subtitle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Feed_Link $link
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_link(Feed_Link $link)
|
||||
{
|
||||
$this->link = $link;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Feed_Link $next_page
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_next_page(Feed_Link $next_page)
|
||||
{
|
||||
$this->next_page = $next_page;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Feed_Link $previous_page
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_previous_page(Feed_Link $previous_page)
|
||||
{
|
||||
$this->previous_page = $previous_page;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Feed_Entry_Adapter $entry
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_item(Feed_Entry_Adapter $entry)
|
||||
{
|
||||
$this->items[] = $entry;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $generator
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function set_generator($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DOMDocument $document
|
||||
* @param DOMNode $node
|
||||
* @param boolean $namespaced
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
public function add_navigation(DOMDocument $document, DOMNode $node, $namespaced)
|
||||
{
|
||||
$prefix = $namespaced ? 'atom:' : '';
|
||||
|
||||
if ($this->previous_page instanceof Feed_Link)
|
||||
{
|
||||
$prev_link = $this->addTag($document, $node, $prefix . 'link');
|
||||
$prev_link->setAttribute('rel', 'previous');
|
||||
$prev_link->setAttribute('href', $this->previous_page->get_href());
|
||||
}
|
||||
|
||||
if ($this->next_page instanceof Feed_Link)
|
||||
{
|
||||
$next_link = $this->addTag($document, $node, $prefix . 'link');
|
||||
$next_link->setAttribute('rel', 'next');
|
||||
$next_link->setAttribute('href', $this->next_page->get_href());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DOMDocument $document
|
||||
* @param DOMNode $node
|
||||
* @param string $tagname
|
||||
* @param string $tagcontent
|
||||
* @return DOMElement
|
||||
*/
|
||||
protected function addTag(DOMDocument &$document, DOMNode &$node, $tagname, $tagcontent = null)
|
||||
{
|
||||
$tag = $document->createElement($tagname);
|
||||
|
||||
if (trim($tagcontent) !== '')
|
||||
$tag->appendChild($document->createTextNode($tagcontent));
|
||||
$node->appendChild($tag);
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DOMDocument $document
|
||||
* @param DOMNode $item
|
||||
* @param Feed_Entry_Item $content
|
||||
* @return Feed_XML_Interface
|
||||
*/
|
||||
protected function addContent(DOMDocument $document, DOMNode $item, Feed_Entry_Item $content)
|
||||
{
|
||||
$preview_sd = $content->get_record()->get_subdef('preview');
|
||||
$preview_permalink = $preview_sd->get_permalink();
|
||||
$thumbnail_sd = $content->get_record()->get_thumbnail();
|
||||
$thumbnail_permalink = $thumbnail_sd->get_permalink();
|
||||
|
||||
$medium = strtolower($content->get_record()->get_type());
|
||||
|
||||
if (!in_array($medium, array('image', 'audio', 'video')))
|
||||
|
||||
return $this;
|
||||
|
||||
if (!$preview_permalink || !$thumbnail_permalink)
|
||||
|
||||
return $this;
|
||||
|
||||
$group = $this->addTag($document, $item, 'media:group');
|
||||
|
||||
$title_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
if ($title_field)
|
||||
{
|
||||
$str_title = $title_field->get_value(true, ' ');
|
||||
$title = $this->addTag($document, $group, 'media:title', $str_title);
|
||||
$title->setAttribute('type', 'plain');
|
||||
}
|
||||
|
||||
$desc_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
if ($desc_field)
|
||||
{
|
||||
$str_desc = $desc_field->get_value(true, ' ');
|
||||
$desc = $this->addTag($document, $group, 'media:description', $str_desc);
|
||||
$desc->setAttribute('type', 'plain');
|
||||
}
|
||||
|
||||
$contrib_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Contributor);
|
||||
if ($contrib_field)
|
||||
{
|
||||
$str_contrib = $contrib_field->get_value(true, ' ');
|
||||
$contrib = $this->addTag($document, $group, 'media:credit', $str_contrib);
|
||||
$contrib->setAttribute('role', 'contributor');
|
||||
$contrib->setAttribute('scheme', 'urn:ebu');
|
||||
}
|
||||
|
||||
$director_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Creator);
|
||||
if ($director_field)
|
||||
{
|
||||
$str_director = $director_field->get_value(true, ' ');
|
||||
$director = $this->addTag($document, $group, 'media:credit', $str_director);
|
||||
$director->setAttribute('role', 'director');
|
||||
$director->setAttribute('scheme', 'urn:ebu');
|
||||
}
|
||||
|
||||
$publisher_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Publisher);
|
||||
if ($publisher_field)
|
||||
{
|
||||
$str_publisher = $publisher_field->get_value(true, ' ');
|
||||
$publisher = $this->addTag($document, $group, 'media:credit', $str_publisher);
|
||||
$publisher->setAttribute('role', 'publisher');
|
||||
$publisher->setAttribute('scheme', 'urn:ebu');
|
||||
}
|
||||
|
||||
$rights_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Rights);
|
||||
if ($rights_field)
|
||||
{
|
||||
$str_rights = $rights_field->get_value(true, ' ');
|
||||
$rights = $this->addTag($document, $group, 'media:copyright', $str_rights);
|
||||
}
|
||||
|
||||
$keyword_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Subject);
|
||||
if ($keyword_field)
|
||||
{
|
||||
$str_keywords = $keyword_field->get_value(true, ', ');
|
||||
$keywords = $this->addTag($document, $group, 'media:keywords', $str_keywords);
|
||||
}
|
||||
|
||||
$duration = $content->get_record()->get_duration();
|
||||
|
||||
if ($preview_permalink)
|
||||
{
|
||||
$preview = $this->addTag($document, $group, 'media:content');
|
||||
|
||||
$preview->setAttribute('url', $preview_permalink->get_url());
|
||||
$preview->setAttribute('fileSize', $preview_sd->get_size());
|
||||
$preview->setAttribute('type', $preview_sd->get_mime());
|
||||
$preview->setAttribute('medium', $medium);
|
||||
$preview->setAttribute('expression', 'full');
|
||||
$preview->setAttribute('isDefault', 'true');
|
||||
|
||||
if ($preview_sd->get_width())
|
||||
$preview->setAttribute('width', $preview_sd->get_width());
|
||||
if ($preview_sd->get_height())
|
||||
$preview->setAttribute('height', $preview_sd->get_height());
|
||||
if ($duration)
|
||||
$preview->setAttribute('duration', $duration);
|
||||
}
|
||||
|
||||
if ($thumbnail_permalink)
|
||||
{
|
||||
$thumbnail = $this->addTag($document, $group, 'media:thumbnail');
|
||||
|
||||
$thumbnail->setAttribute('url', $thumbnail_permalink->get_url());
|
||||
|
||||
if ($thumbnail_sd->get_width())
|
||||
$thumbnail->setAttribute('width', $thumbnail_sd->get_width());
|
||||
if ($thumbnail_sd->get_height())
|
||||
$thumbnail->setAttribute('height', $thumbnail_sd->get_height());
|
||||
|
||||
|
||||
$thumbnail = $this->addTag($document, $group, 'media:content');
|
||||
|
||||
$thumbnail->setAttribute('url', $thumbnail_permalink->get_url());
|
||||
$thumbnail->setAttribute('fileSize', $thumbnail_sd->get_size());
|
||||
$thumbnail->setAttribute('type', $thumbnail_sd->get_mime());
|
||||
$thumbnail->setAttribute('medium', $medium);
|
||||
$thumbnail->setAttribute('isDefault', 'false');
|
||||
|
||||
if ($thumbnail_sd->get_width())
|
||||
$thumbnail->setAttribute('width', $thumbnail_sd->get_width());
|
||||
if ($thumbnail_sd->get_height())
|
||||
$thumbnail->setAttribute('height', $thumbnail_sd->get_height());
|
||||
if ($duration)
|
||||
$thumbnail->setAttribute('duration', $duration);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_mimetype()
|
||||
{
|
||||
return $this->mimetype;
|
||||
}
|
||||
|
||||
abstract public function render();
|
||||
}
|
194
lib/classes/Feed/XML/Atom.class.php
Normal file
194
lib/classes/Feed/XML/Atom.class.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class Feed_XML_Atom extends Feed_XML_Abstract implements Feed_XML_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $author_name;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $author_email;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $author_url;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $author = false;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $icon;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mimetype = 'application/atom+xml';
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$document = new DOMDocument('1.0', 'UTF-8');
|
||||
$document->formatOutput = true;
|
||||
$document->standalone = true;
|
||||
|
||||
$root = $this->addTag($document, $document, 'feed');
|
||||
$root->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
|
||||
$root->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/');
|
||||
|
||||
$this->addTag($document, $root, 'title', $this->title);
|
||||
if ($this->updated_on instanceof DateTime)
|
||||
{
|
||||
$updated_on = $this->updated_on->format(DATE_ATOM);
|
||||
$this->addTag($document, $root, 'updated', $updated_on);
|
||||
}
|
||||
|
||||
if ($this->link instanceof Feed_Link)
|
||||
{
|
||||
$link = $this->addTag($document, $root, 'link');
|
||||
$link->setAttribute('rel', 'self');
|
||||
$link->setAttribute('href', $this->link->get_href());
|
||||
$this->addTag($document, $root, 'id', $this->link->get_href());
|
||||
}
|
||||
|
||||
$this->add_navigation($document, $root, false);
|
||||
|
||||
if ($this->generator)
|
||||
$this->addTag($document, $root, 'generator', $this->generator);
|
||||
if ($this->subtitle)
|
||||
$this->addTag($document, $root, 'subtitle', $this->subtitle);
|
||||
if ($this->icon)
|
||||
$this->addTag($document, $root, 'icon', $this->icon);
|
||||
if ($this->author)
|
||||
{
|
||||
$author = $this->addTag($document, $root, 'author');
|
||||
if ($this->author_email)
|
||||
$this->addTag($document, $author, 'email', $this->author_email);
|
||||
if ($this->author_name)
|
||||
$this->addTag($document, $author, 'name', $this->author_name);
|
||||
if ($this->author_url)
|
||||
$this->addTag($document, $author, 'uri', $this->author_url);
|
||||
}
|
||||
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
$this->add_item($document, $root, $item);
|
||||
}
|
||||
|
||||
return $document->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DOMDocument $document
|
||||
* @param DOMElement $feed
|
||||
* @param Feed_Entry_Adapter $entry
|
||||
* @return DOMElement
|
||||
*/
|
||||
protected function add_item(DOMDocument $document, DOMElement $feed, Feed_Entry_Adapter $entry)
|
||||
{
|
||||
$entry_node = $this->addTag($document, $feed, 'entry');
|
||||
|
||||
$link = sprintf('%sentry/%d/', $this->link->get_href(), $entry->get_id());
|
||||
|
||||
$this->addTag($document, $entry_node, 'id', $link);
|
||||
$link_tag = $this->addTag($document, $entry_node, 'link');
|
||||
$link_tag->setAttribute('rel', 'self');
|
||||
$link_tag->setAttribute('href', $link);
|
||||
|
||||
$updated_on = $entry->get_updated_on()->format(DATE_ATOM);
|
||||
$created_on = $entry->get_created_on()->format(DATE_ATOM);
|
||||
|
||||
$this->addTag($document, $entry_node, 'updated', $updated_on);
|
||||
$this->addTag($document, $entry_node, 'published', $created_on);
|
||||
$this->addTag($document, $entry_node, 'title', $entry->get_title());
|
||||
$author = $this->addTag($document, $entry_node, 'author');
|
||||
|
||||
if ($entry->get_author_email())
|
||||
$this->addTag($document, $author, 'email', $entry->get_author_email());
|
||||
if ($entry->get_author_name())
|
||||
$this->addTag($document, $author, 'name', $entry->get_author_name());
|
||||
|
||||
$this->addTag($document, $entry_node, 'content', $entry->get_subtitle());
|
||||
|
||||
|
||||
foreach ($entry->get_content() as $content)
|
||||
{
|
||||
$this->addContent($document, $entry_node, $content);
|
||||
}
|
||||
|
||||
return $entry_node;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $author_name
|
||||
* @return Feed_XML_Atom
|
||||
*/
|
||||
public function set_author_name($author_name)
|
||||
{
|
||||
$this->author = true;
|
||||
$this->author_name = $author_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $author_name
|
||||
* @return Feed_XML_Atom
|
||||
*/
|
||||
public function set_author_email($author_email)
|
||||
{
|
||||
$this->author = true;
|
||||
$this->author_email = $author_email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $author_name
|
||||
* @return Feed_XML_Atom
|
||||
*/
|
||||
public function set_author_url($author_url)
|
||||
{
|
||||
$this->author = true;
|
||||
$this->author_url = $author_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
39
lib/classes/Feed/XML/Interface.class.php
Normal file
39
lib/classes/Feed/XML/Interface.class.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface Feed_XML_Interface
|
||||
{
|
||||
public function set_title($title);
|
||||
|
||||
public function set_updated_on(DateTime $datetime);
|
||||
|
||||
public function set_subtitle($subtitle);
|
||||
|
||||
public function set_link(Feed_Link $link);
|
||||
|
||||
public function set_next_page(Feed_Link $next_page);
|
||||
|
||||
public function set_previous_page(Feed_Link $previous_page);
|
||||
|
||||
public function set_item(Feed_Entry_Adapter $entry);
|
||||
|
||||
public function set_generator($generator);
|
||||
|
||||
public function add_navigation(DOMDocument $document, DOMNode $node, $namespaced);
|
||||
|
||||
public function get_mimetype();
|
||||
}
|
371
lib/classes/Feed/XML/RSS.class.php
Normal file
371
lib/classes/Feed/XML/RSS.class.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class Feed_XML_RSS extends Feed_XML_Abstract implements Feed_XML_Interface
|
||||
{
|
||||
/**
|
||||
* RSS version
|
||||
*/
|
||||
const VERSION = '2.0';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $required_fields = array('title', 'subtitle', 'link');
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $language;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $copyright;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $managingEditor;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $webMaster;
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $lastBuildDate;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $categories;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $docs = 'http://blogs.law.harvard.edu/tech/rss';
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $ttl;
|
||||
/**
|
||||
*
|
||||
* @var Feed_XML_RSS_Image
|
||||
*/
|
||||
protected $image;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $skipHours = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $skipDays = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mimetype = 'application/rss+xml';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $language
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_language($language)
|
||||
{
|
||||
$this->language = $language;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $language
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_copyright($copyright)
|
||||
{
|
||||
$this->copyright = $copyright;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $managingEditor
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_managingEditor($managingEditor)
|
||||
{
|
||||
$this->managingEditor = $managingEditor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $webMaster
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_webMaster($webMaster)
|
||||
{
|
||||
$this->webMaster = $webMaster;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DateTime $lastBuildDate
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_lastBuildDate(DateTime $lastBuildDate)
|
||||
{
|
||||
$this->lastBuildDate = $lastBuildDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $category
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_category($category)
|
||||
{
|
||||
$this->categories[] = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $docs
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_docs($docs)
|
||||
{
|
||||
$this->docs = $docs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $ttl
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_ttl($ttl)
|
||||
{
|
||||
$this->ttl = $ttl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Feed_XML_RSS_Image $image
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_image(Feed_XML_RSS_Image $image)
|
||||
{
|
||||
$this->image = $image;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $skipHours
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_skipHour($hour)
|
||||
{
|
||||
$this->skipHours[] = (int) $hour;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $skipDays
|
||||
* @return Feed_XML_RSS
|
||||
*/
|
||||
public function set_skipDays($day)
|
||||
{
|
||||
$this->skipDays[] = $day;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$doc = new DOMDocument('1.0', 'UTF-8');
|
||||
$doc->formatOutput = true;
|
||||
$doc->standalone = true;
|
||||
|
||||
|
||||
$root = $this->addTag($doc, $doc, 'rss');
|
||||
|
||||
$root->setAttribute('version', self::VERSION);
|
||||
$root->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/');
|
||||
$root->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
|
||||
$root->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
|
||||
|
||||
$channel = $this->addTag($doc, $root, 'channel');
|
||||
|
||||
$this->addTag($doc, $channel, 'title', $this->title);
|
||||
$this->addTag($doc, $channel, 'dc:title', $this->title);
|
||||
$this->addTag($doc, $channel, 'description', $this->subtitle);
|
||||
if ($this->link instanceof Feed_Link)
|
||||
$this->addTag($doc, $channel, 'link', $this->link->get_href());
|
||||
|
||||
if ($this->language)
|
||||
$this->addTag($doc, $channel, 'language', $this->language);
|
||||
if ($this->copyright)
|
||||
$this->addTag($doc, $channel, 'copyright', $this->copyright);
|
||||
if ($this->managingEditor)
|
||||
$this->addTag($doc, $channel, 'managingEditor', $this->managingEditor);
|
||||
if ($this->webMaster)
|
||||
$this->addTag($doc, $channel, 'webMaster', $this->webMaster);
|
||||
if ($this->updated_on instanceof DateTime)
|
||||
{
|
||||
$updated_on = $this->updated_on->format(DATE_RFC2822);
|
||||
$this->addTag($doc, $channel, 'pubDate', $updated_on);
|
||||
}
|
||||
if ($this->lastBuildDate instanceof DateTime)
|
||||
{
|
||||
$last_build = $this->lastBuildDate->format(DATE_RFC2822);
|
||||
$this->addTag($doc, $channel, 'lastBuildDate', $last_build);
|
||||
}
|
||||
if (count($this->categories) > 0)
|
||||
{
|
||||
foreach ($this->categories as $category)
|
||||
{
|
||||
$this->addTag($doc, $channel, 'category', $category);
|
||||
}
|
||||
}
|
||||
if ($this->generator)
|
||||
$this->addTag($doc, $channel, 'generator', $this->generator);
|
||||
if ($this->docs)
|
||||
$this->addTag($doc, $channel, 'docs', $this->docs);
|
||||
if ($this->ttl)
|
||||
$this->addTag($doc, $channel, 'ttl', $this->ttl);
|
||||
if ($this->image instanceof Feed_XML_RSS_Image)
|
||||
{
|
||||
$image = $this->addTag($doc, $channel, 'image');
|
||||
$this->addTag($doc, $image, 'url', $this->image->get_url());
|
||||
$this->addTag($doc, $image, 'title', $this->image->get_title());
|
||||
$this->addTag($doc, $image, 'link', $this->image->get_link());
|
||||
if ($this->image->get_width())
|
||||
$this->addTag($doc, $image, 'width', $this->image->get_width());
|
||||
if ($this->image->get_height())
|
||||
$this->addTag($doc, $image, 'height', $this->image->get_height());
|
||||
if ($this->image->get_description())
|
||||
$this->addTag($doc, $image, 'description', $this->image->get_description());
|
||||
}
|
||||
if (count($this->skipHours))
|
||||
{
|
||||
$skipHours = $this->addTag($doc, $channel, 'skipHours');
|
||||
foreach ($this->skipHours as $hour)
|
||||
{
|
||||
$this->addTag($doc, $skipHours, 'hour', $hour);
|
||||
}
|
||||
}
|
||||
if (count($this->skipDays) > 0)
|
||||
{
|
||||
$skipDays = $this->addTag($doc, $channel, 'skipDays');
|
||||
foreach ($this->skipDays as $day)
|
||||
{
|
||||
$this->addTag($doc, $skipDays, 'day', $day);
|
||||
}
|
||||
}
|
||||
if ($this->link instanceof Feed_Link)
|
||||
{
|
||||
$self_link = $this->addTag($doc, $channel, 'atom:link');
|
||||
$self_link->setAttribute('rel', 'self');
|
||||
$self_link->setAttribute('href', $this->link->get_href());
|
||||
}
|
||||
|
||||
$this->add_navigation($doc, $channel, true);
|
||||
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
$this->add_item($doc, $channel, $item);
|
||||
}
|
||||
|
||||
return $doc->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DOMDocument $document
|
||||
* @param DOMNode $node
|
||||
* @param Feed_Entry_Adapter $entry
|
||||
* @return DOMElement
|
||||
*/
|
||||
protected function add_item(DOMDocument $document, DOMNode $node, Feed_Entry_Adapter $entry)
|
||||
{
|
||||
$item = $this->addTag($document, $node, 'item');
|
||||
|
||||
$link = $entry->get_link();
|
||||
|
||||
$this->addTag($document, $item, 'title', $entry->get_title());
|
||||
$this->addTag($document, $item, 'description', $entry->get_subtitle());
|
||||
|
||||
$author = sprintf(
|
||||
'%s (%s)'
|
||||
, $entry->get_author_email()
|
||||
, $entry->get_author_name()
|
||||
);
|
||||
$created_on = $entry->get_created_on()->format(DATE_RFC2822);
|
||||
|
||||
$this->addTag($document, $item, 'author', $author);
|
||||
$this->addTag($document, $item, 'pubDate', $created_on);
|
||||
$this->addTag($document, $item, 'guid', $link->get_href());
|
||||
$this->addTag($document, $item, 'link', $link->get_href());
|
||||
|
||||
/**
|
||||
* Missing :
|
||||
*
|
||||
* category Includes the item in one or more categories. More.
|
||||
* comments URL of a page for comments relating to the item. More.
|
||||
* enclosure Describes a media object that is attached to the item. More.
|
||||
* source The RSS channel that the item came from. More.
|
||||
*
|
||||
*/
|
||||
foreach ($entry->get_content() as $content)
|
||||
{
|
||||
$this->addContent($document, $item, $content);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
}
|
158
lib/classes/Feed/XML/RSS/Image.class.php
Normal file
158
lib/classes/Feed/XML/RSS/Image.class.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $link;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $width;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $title
|
||||
* @param string $link
|
||||
* @return Feed_XML_RSS_Image
|
||||
*/
|
||||
public function __construct($url, $title, $link)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->title = $title;
|
||||
$this->link = $link;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $description
|
||||
* @return Feed_XML_RSS_Image
|
||||
*/
|
||||
public function set_description($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $width
|
||||
* @return Feed_XML_RSS_Image
|
||||
*/
|
||||
public function set_width($width)
|
||||
{
|
||||
$this->width = (int) $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $height
|
||||
* @return Feed_XML_RSS_Image
|
||||
*/
|
||||
public function set_height($height)
|
||||
{
|
||||
$this->height = (int) $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_link()
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_width()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_height()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
}
|
33
lib/classes/Feed/XML/RSS/ImageInterface.class.php
Normal file
33
lib/classes/Feed/XML/RSS/ImageInterface.class.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface Feed_XML_RSS_ImageInterface
|
||||
{
|
||||
public function __construct($url, $title, $link);
|
||||
|
||||
public function get_url();
|
||||
|
||||
public function get_title();
|
||||
|
||||
public function get_link();
|
||||
|
||||
public function get_description();
|
||||
|
||||
public function get_height();
|
||||
|
||||
public function get_width();
|
||||
}
|
Reference in New Issue
Block a user