Removed remaining occurrences to Feed_, adapted patch_320f

This commit is contained in:
Andrey
2013-06-17 16:52:18 +02:00
parent 6bdfa2da29
commit d8d9ab7607
46 changed files with 116 additions and 5617 deletions

View File

@@ -78,6 +78,7 @@ class Feed implements ControllerProviderInterface
$item->setEntry($entry);
$item->setRecordId($record->get_record_id());
$item->setSbasId($record->get_sbas_id());
$item->setLastInFeedItem();
$entry->addItem($item);
$app['EM']->persist($item);
}
@@ -164,7 +165,7 @@ class Feed implements ControllerProviderInterface
continue;
}
$item = new FeedItem($entry, $item_sort_datas[0]);
$item = new FeedItem();
$item->setEntry($entry);
$entry->addItem($item);
$item->setOrd($item_sort_datas[1]);

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Feed\Formatter;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
use Alchemy\Phrasea\Feed\RSS\FeedRSSImage;
use Symfony\Component\HttpFoundation\Response;
class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterInterface
@@ -95,17 +96,17 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn
$this->addTag($doc, $channel, 'docs', $this->docs);
if (isset($this->ttl))
$this->addTag($doc, $channel, 'ttl', $this->ttl);
if (isset($this->image) && $this->image instanceof Feed_XML_RSS_Image) {
if (isset($this->image) && $this->image instanceof FeedRSSImage) {
$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());
$this->addTag($doc, $image, 'url', $this->image->getUrl());
$this->addTag($doc, $image, 'title', $this->image->getTitle());
$this->addTag($doc, $image, 'link', $this->image->getLink());
if ($this->image->getWidth())
$this->addTag($doc, $image, 'width', $this->image->getWidth());
if ($this->image->getHeight())
$this->addTag($doc, $image, 'height', $this->image->getHeight());
if ($this->image->getDescription())
$this->addTag($doc, $image, 'description', $this->image->getDescription());
}
if (isset($this->skipHours) && count($this->skipHours)) {
$skipHours = $this->addTag($doc, $channel, 'skipHours');

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Feed\Link\FeedLink;
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
use Alchemy\Phrasea\Feed\RSS\FeedRSSImage;
use Symfony\Component\HttpFoundation\Response;
class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterface
@@ -114,17 +115,17 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa
$this->addTag($doc, $channel, 'docs', $this->docs);
if (isset($this->ttl))
$this->addTag($doc, $channel, 'ttl', $this->ttl);
if (isset($this->image) && $this->image instanceof Feed_XML_RSS_Image) {
if (isset($this->image) && $this->image instanceof FeedRSSImage) {
$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());
$this->addTag($doc, $image, 'url', $this->image->getUrl());
$this->addTag($doc, $image, 'title', $this->image->getTitle());
$this->addTag($doc, $image, 'link', $this->image->getLink());
if ($this->image->getWidth())
$this->addTag($doc, $image, 'width', $this->image->getWidth());
if ($this->image->getHeight())
$this->addTag($doc, $image, 'height', $this->image->getHeight());
if ($this->image->getDescription())
$this->addTag($doc, $image, 'description', $this->image->getDescription());
}
if (isset($this->skipHours) && count($this->skipHours)) {
$skipHours = $this->addTag($doc, $channel, 'skipHours');

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Feed\RSS;
/**
*
* @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
class FeedRSSImage implements FeedRSSImageInterface
{
/**
*
@@ -58,7 +60,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
* @param string $url
* @param string $title
* @param string $link
* @return Feed_XML_RSS_Image
* @return FeedRSSImage
*/
public function __construct($url, $title, $link)
{
@@ -72,9 +74,9 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
/**
*
* @param type $description
* @return Feed_XML_RSS_Image
* @return FeedRSSImage
*/
public function set_description($description)
public function setDescription($description)
{
$this->description = $description;
@@ -84,9 +86,9 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
/**
*
* @param int $width
* @return Feed_XML_RSS_Image
* @return FeedRSSImage
*/
public function set_width($width)
public function setWidth($width)
{
$this->width = (int) $width;
@@ -96,9 +98,9 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
/**
*
* @param int $height
* @return Feed_XML_RSS_Image
* @return FeedRSSImage
*/
public function set_height($height)
public function setHeight($height)
{
$this->height = (int) $height;
@@ -109,7 +111,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
*
* @return string
*/
public function get_url()
public function getUrl()
{
return $this->url;
}
@@ -118,7 +120,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
*
* @return string
*/
public function get_title()
public function getTitle()
{
return $this->title;
}
@@ -127,7 +129,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
*
* @return string
*/
public function get_link()
public function getLink()
{
return $this->link;
}
@@ -136,7 +138,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
*
* @return string
*/
public function get_description()
public function getDescription()
{
return $this->description;
}
@@ -145,7 +147,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
*
* @return int
*/
public function get_width()
public function getWidth()
{
return $this->width;
}
@@ -154,7 +156,7 @@ class Feed_XML_RSS_Image implements Feed_XML_RSS_ImageInterface
*
* @return int
*/
public function get_height()
public function getHeight()
{
return $this->height;
}

View File

@@ -9,26 +9,28 @@
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Feed\RSS;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface Feed_XML_RSS_ImageInterface
interface FeedXMLRSSImageInterface
{
public function __construct($url, $title, $link);
public function get_url();
public function getUrl();
public function get_title();
public function getTitle();
public function get_link();
public function getLink();
public function get_description();
public function getDescription();
public function get_height();
public function getHeight();
public function get_width();
public function getWidth();
}

View File

@@ -18,6 +18,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
use Alchemy\Phrasea\Exception\RuntimeException;
use Doctrine\Common\Collections\ArrayCollection;
use Entities\FeedEntry;
class PhraseaEngine implements SearchEngineInterface
{
@@ -303,7 +304,7 @@ class PhraseaEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function addFeedEntry(\Feed_Entry_Adapter $entry)
public function addFeedEntry(FeedEntry $entry)
{
throw new RuntimeException('Feed Entry indexing not supported by Phrasea Engine');
}
@@ -311,7 +312,7 @@ class PhraseaEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function removeFeedEntry(\Feed_Entry_Adapter $entry)
public function removeFeedEntry(FeedEntry $entry)
{
throw new RuntimeException('Feed Entry indexing not supported by Phrasea Engine');
}
@@ -319,7 +320,7 @@ class PhraseaEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function updateFeedEntry(\Feed_Entry_Adapter $entry)
public function updateFeedEntry(FeedEntry $entry)
{
throw new RuntimeException('Feed Entry indexing not supported by Phrasea Engine');
}

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
use Alchemy\Phrasea\Exception\RuntimeException;
use Doctrine\Common\Collections\ArrayCollection;
use Entities\FeedEntry;
interface SearchEngineInterface
{
@@ -131,29 +132,29 @@ interface SearchEngineInterface
/**
* Add an entry to index
*
* @param \Feed_Entry_Adapter $entry
* @param FeedEntry $entry
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function addFeedEntry(\Feed_Entry_Adapter $entry);
public function addFeedEntry(FeedEntry $entry);
/**
* Remove an entry to index
*
* @param \Feed_Entry_Adapter $entry
* @param FeedEntry $entry
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function removeFeedEntry(\Feed_Entry_Adapter $entry);
public function removeFeedEntry(FeedEntry $entry);
/**
* Update an entry in the index
*
* @param \Feed_Entry_Adapter $entry
* @param FeedEntry $entry
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function updateFeedEntry(\Feed_Entry_Adapter $entry);
public function updateFeedEntry(FeedEntry $entry);
/**
* Set options to search-engine

View File

@@ -18,6 +18,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
use Alchemy\Phrasea\Exception\RuntimeException;
use Doctrine\Common\Collections\ArrayCollection;
use Entities\FeedEntry;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
@@ -387,7 +388,7 @@ class SphinxSearchEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function addFeedEntry(\Feed_Entry_Adapter $entry)
public function addFeedEntry(FeedEntry $entry)
{
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
}
@@ -395,7 +396,7 @@ class SphinxSearchEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function removeFeedEntry(\Feed_Entry_Adapter $entry)
public function removeFeedEntry(FeedEntry $entry)
{
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
}
@@ -403,7 +404,7 @@ class SphinxSearchEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function updateFeedEntry(\Feed_Entry_Adapter $entry)
public function updateFeedEntry(FeedEntry $entry)
{
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
}

View File

@@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Feed_EntryNotFound extends NotFoundHttpException
class Exception_FeedEntryNotFound extends NotFoundHttpException
{
}

View File

@@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Feed_ItemNotFound extends NotFoundHttpException
class Exception_FeedItemNotFound extends NotFoundHttpException
{
}

View File

@@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Feed_PublisherNotFound extends NotFoundHttpException
class Exception_FeedPublisherNotFound extends NotFoundHttpException
{
}

View File

@@ -1,98 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Abstract
{
/**
*
*/
const FORMAT_RSS = 'rss';
/**
*
*/
const FORMAT_ATOM = 'atom';
/**
*
*/
const FORMAT_COOLIRIS = 'cooliris';
/**
*
* @var appbox
*/
protected $appbox;
/**
*
* @var string
*/
protected $title;
/**
*
* @var string
*/
protected $subtitle;
/**
*
* @var DateTime
*/
protected $created_on;
/**
*
* @var DateTime
*/
protected $updated_on;
/**
*
* @return string
*/
public function get_title()
{
return $this->title;
}
/**
*
* @return string
*/
public function get_subtitle()
{
return $this->subtitle;
}
/**
*
* @return DateTime
*/
public function get_created_on()
{
return $this->created_on;
}
/**
*
* @return DateTime
*/
public function get_updated_on()
{
return $this->updated_on;
}
}

View File

@@ -1,722 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cacheableInterface
{
/**
*
* @var int
*/
protected $id;
/**
*
* @var collection
*/
protected $collection;
/**
*
* @var array
*/
protected $publishers;
/**
*
* @var boolean
*/
protected $public;
/**
*
* @var Feed_Publisher_Adapter
*/
protected $owner;
/**
*
* @var string
*/
protected $icon_url;
const CACHE_ENTRY_NUMBER = 'entrynumber';
const CACHE_USER_TOKEN = 'usr_token';
const MAX_ENTRIES = 20;
public function __construct(Application $app, $id)
{
$this->app = $app;
$this->id = (int) $id;
$this->load();
return $this;
}
protected function load()
{
try {
$datas = $this->get_data_from_cache();
$this->title = $datas['title'];
$this->subtitle = $datas['subtitle'];
$this->collection = $datas['base_id'] ? collection::get_from_base_id($this->app, $datas['base_id']) : null;
$this->created_on = $datas['created_on'];
$this->updated_on = $datas['updated_on'];
$this->public = $datas['public'];
return $this;
} catch (Exception $e) {
}
$sql = 'SELECT id, title, subtitle, created_on, updated_on, base_id, public
FROM feeds WHERE id = :feed_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_id' => $this->id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row)
throw new NotFoundHttpException('Feed not found');
$this->title = $row['title'];
$this->subtitle = $row['subtitle'];
if (!is_null($row['base_id']))
$this->collection = collection::get_from_base_id($this->app, $row['base_id']);
$this->created_on = new DateTime($row['created_on']);
$this->updated_on = new DateTime($row['updated_on']);
$this->public = !!$row['public'];
$base_id = $this->collection instanceof collection ? $this->collection->get_base_id() : null;
$datas = array(
'title' => $this->title
, 'subtitle' => $this->subtitle
, 'base_id' => $base_id
, 'created_on' => $this->created_on
, 'updated_on' => $this->updated_on
, 'public' => $this->public
);
$this->set_data_to_cache($datas);
return $this;
}
/**
*
* @return string
*/
public function get_icon_url()
{
if ($this->icon_url) {
return $this->icon_url;
}
$url = '/skins/icons/rss32.gif';
$file = $this->app['root.path']
. '/www/custom/feed_' . $this->get_id() . '.jpg';
if (file_exists($file)) {
$url = '/custom/feed_' . $this->get_id() . '.jpg';
}
$this->icon_url = $url;
return $this->icon_url;
}
/**
*
* @param string $file The path to the file
* @return Feed_Adapter
*/
public function set_icon($file)
{
if (!file_exists($file)) {
throw new \Alchemy\Phrasea\Exception\InvalidArgumentException('File does not exists');
}
$config_file = $this->app['root.path'] . '/config/feed_' . $this->get_id() . '.jpg';
$www_file = $this->app['root.path'] . '/www/custom/feed_' . $this->get_id() . '.jpg';
copy($file, $config_file);
copy($file, $www_file);
$this->icon_url = null;
return $this;
}
public function set_created_on(DateTime $created_on)
{
$sql = 'UPDATE feeds SET created_on = :created_on
WHERE id = :feed_id';
$params = array(
':created_on' => $created_on->format(DATE_ISO8601)
, ':feed_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->created_on = $created_on;
$this->delete_data_from_cache();
return $this;
}
public function reset_icon()
{
$config_file = $this->app['root.path']
. '/config/feed_' . $this->get_id() . '.jpg';
$www_file = $this->app['root.path']
. '/www/custom/feed_' . $this->get_id() . '.jpg';
if (is_file($config_file))
unlink($config_file);
if (is_file($www_file))
unlink($www_file);
$this->icon_url = null;
return $this;
}
/**
*
* @return boolean
*/
public function is_aggregated()
{
return false;
}
/**
*
* @param User_Adapter $user
* @return boolean
*/
public function is_owner(User_Adapter $user)
{
$this->load_publishers();
if (!$this->owner) {
return false;
}
return $this->owner->get_user()->get_id() === $user->get_id();
}
/**
*
* @param User_Adapter $user
* @return boolean
*/
public function is_publisher(User_Adapter $user)
{
return in_array($user->get_id(), array_keys($this->get_publishers()));
}
/**
* Tells if a user has access to the feed
*
* @param User_Adapter $user
* @return type
*/
public function has_access(User_Adapter $user)
{
if ($this->get_collection() instanceof collection) {
return $user->ACL()->has_access_to_base($this->collection->get_base_id());
}
return true;
}
/**
*
* @return boolean
*/
public function is_public()
{
if ($this->get_collection() instanceof collection) {
return false;
}
return $this->public;
}
/**
*
* @return array
*/
public function get_publishers()
{
return $this->load_publishers();
}
/**
*
* @return collection
*/
public function get_collection()
{
return $this->collection;
}
/**
*
* @param User_Adapter $user
* @return Feed_Adapter
*/
public function add_publisher(User_Adapter $user)
{
if (in_array($user->get_id(), array_keys($this->get_publishers()))) {
return $this;
}
Feed_Publisher_Adapter::create($this->app, $user, $this, false);
$this->publishers = null;
return $this;
}
/**
*
* @return array
*/
protected function load_publishers()
{
if (is_array($this->publishers)) {
return $this->publishers;
}
$sql = 'SELECT id, usr_id, owner FROM feed_publishers
WHERE feed_id = :feed_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_id' => $this->id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
try {
$publisher = new Feed_Publisher_Adapter($this->app, $row['id']);
} catch (\Exception_Feed_PublisherNotFound $e) {
continue;
}
$this->publishers[$row['usr_id']] = $publisher;
if ($publisher->is_owner()) {
$this->owner = $publisher;
}
}
return $this->publishers;
}
/**
*
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
*
* @param collection $collection
* @return Feed_Adapter
*/
public function set_collection(collection $collection = null)
{
$base_id = null;
if ($collection instanceof collection) {
$base_id = $collection->get_base_id();
}
$sql = 'UPDATE feeds SET base_id = :base_id, updated_on = NOW()
WHERE id = :feed_id';
$params = array(':base_id' => $base_id, ':feed_id' => $this->get_id());
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->collection = $collection;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param boolean $boolean
* @return Feed_Adapter
*/
public function set_public($boolean)
{
$boolean = !!$boolean;
$sql = 'UPDATE feeds SET public = :public, updated_on = NOW()
WHERE id = :feed_id';
$params = array(
':public' => $boolean ? '1' : '0',
':feed_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->public = $boolean;
$this->delete_data_from_cache();
$feed_collection = new Feed_Collection($this->app, array());
$feed_collection->delete_data_from_cache(Feed_Collection::CACHE_PUBLIC);
return $this;
}
/**
*
* @param string $title
* @return Feed_Adapter
*/
public function set_title($title)
{
$title = trim(strip_tags($title));
if ($title === '')
throw new Exception_InvalidArgument();
$sql = 'UPDATE feeds SET title = :title, updated_on = NOW()
WHERE id = :feed_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':title' => $title, ':feed_id' => $this->get_id()));
$stmt->closeCursor();
$this->title = $title;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param string $subtitle
* @return Feed_Adapter
*/
public function set_subtitle($subtitle)
{
$subtitle = strip_tags($subtitle);
$sql = 'UPDATE feeds SET subtitle = :subtitle, updated_on = NOW()
WHERE id = :feed_id';
$params = array(':subtitle' => $subtitle, ':feed_id' => $this->get_id());
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->subtitle = $subtitle;
$this->delete_data_from_cache();
return $this;
}
public static function create(Application $app, User_Adapter $user, $title, $subtitle)
{
$sql = 'INSERT INTO feeds (id, title, subtitle, created_on, updated_on)
VALUES (null, :title, :subtitle, NOW(), NOW())';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':title' => $title, ':subtitle' => $subtitle));
$stmt->closeCursor();
$feed_id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
$feed = new self($app, $feed_id);
Feed_Publisher_Adapter::create($app, $user, $feed, true);
return $feed;
}
public static function load_with_user(Application $app, User_Adapter $user, $id)
{
$feed = new self($app, $id);
$coll = $feed->get_collection();
if (
$feed->is_public()
|| $coll === null
|| in_array($coll->get_base_id(), array_keys($user->ACL()->get_granted_base()))
) {
return $feed;
}
throw new NotFoundHttpException('Feed not found');
}
/**
*
* @return int
*/
public function get_count_total_entries()
{
try {
return $this->get_data_from_cache(self::CACHE_ENTRY_NUMBER);
} catch (Exception $e) {
}
$sql = 'SELECT count(id) as number
FROM feed_entries WHERE feed_id = :feed_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_id' => $this->get_id()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$number = $row ? (int) $row['number'] : 0;
$stmt->closeCursor();
$this->set_data_to_cache($number, self::CACHE_ENTRY_NUMBER);
return $number;
}
/**
*
* @return void
*/
public function delete()
{
$this->reset_icon();
while ($this->get_count_total_entries() > 0) {
$entries_coll = $this->get_entries(0, 10);
foreach ($entries_coll->get_entries() as $entry) {
$entry->delete();
}
unset($entries_coll);
$this->delete_data_from_cache(self::CACHE_ENTRY_NUMBER);
}
foreach ($this->get_publishers() as $publishers)
$publishers->delete();
$sql = 'DELETE FROM feed_tokens WHERE feed_id = :feed_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_id' => $this->get_id()));
$stmt->closeCursor();
$sql = 'DELETE FROM feeds WHERE id = :feed_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_id' => $this->get_id()));
$stmt->closeCursor();
$this->delete_data_from_cache();
$feed_coll = new Feed_Collection($this->app, array());
$feed_coll->delete_data_from_cache(Feed_Collection::CACHE_PUBLIC);
return;
}
/**
*
* @param int $offset_start
* @param int $how_many
* @return Feed_Entry_Collection
*/
public function get_entries($offset_start, $how_many)
{
$offset_start = (int) $offset_start;
$how_many = $how_many > self::MAX_ENTRIES ? self::MAX_ENTRIES : (int) $how_many;
$sql = 'SELECT id
FROM feed_entries
WHERE feed_id = :feed_id
ORDER BY id DESC
LIMIT ' . $offset_start . ', ' . $how_many;
$params = array(
':feed_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$result = new Feed_Entry_Collection();
foreach ($rs as $row) {
$entry = new Feed_Entry_Adapter($this->app, $this, $row['id']);
$result->add_entry($entry);
}
return $result;
}
/**
*
* @param registryInterface $registry
* @param string $format
* @param int $page
* @return Feed_Link
*/
public function get_homepage_link(registryInterface $registry, $format, $page = null)
{
if (!$this->is_public()) {
return null;
}
switch ($format) {
case self::FORMAT_ATOM:
return new Feed_Link(
sprintf('%sfeeds/feed/%s/atom/%s'
, $registry->get('GV_ServerName')
, $this->get_id()
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'Atom')
, 'application/atom+xml'
);
break;
case self::FORMAT_RSS:
default:
return new Feed_Link(
sprintf('%sfeeds/feed/%s/rss/%s'
, $registry->get('GV_ServerName')
, $this->get_id()
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'RSS')
, 'application/rss+xml'
);
break;
}
}
/**
*
* @param User_Adapter $user
* @param boolean $renew
* @return string
*/
protected function get_token(User_Adapter $user, $renew = false)
{
$cache_key = self::CACHE_USER_TOKEN . '_' . $user->get_id();
try {
if (!$renew) {
return $this->get_data_from_cache($cache_key);
}
} catch (Exception $e) {
}
$sql = 'SELECT token FROM feed_tokens
WHERE usr_id = :usr_id AND feed_id = :feed_id
AND aggregated IS NULL';
$params = array(
':usr_id' => $user->get_id(),
':feed_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row || $renew === true) {
$token = random::generatePassword(12, random::LETTERS_AND_NUMBERS);
$sql = 'REPLACE INTO feed_tokens (id, token, feed_id, usr_id, aggregated)
VALUES (null, :token, :feed_id, :usr_id, :aggregated)';
$params = array(
':token' => $token
, ':feed_id' => $this->get_id()
, ':usr_id' => $user->get_id()
, ':aggregated' => null
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$this->delete_data_from_cache($cache_key);
} else {
$token = $row['token'];
}
$this->set_data_to_cache($token, $cache_key);
return $token;
}
/**
*
* @param registryInterface $registry
* @param User_Adapter $user
* @param string $format
* @param int $page
* @param boolean $renew_token
* @return Feed_Link
*/
public function get_user_link(registryInterface $registry, User_Adapter $user, $format, $page = null, $renew_token = false)
{
switch ($format) {
case self::FORMAT_ATOM:
return new Feed_Link(
sprintf('%sfeeds/userfeed/%s/%s/atom/'
, $registry->get('GV_ServerName')
, $this->get_token($user, $renew_token)
, $this->get_id()
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'Atom')
, 'application/atom+xml'
);
break;
case self::FORMAT_RSS:
return new Feed_Link(
sprintf('%sfeeds/userfeed/%s/%s/rss/%s'
, $registry->get('GV_ServerName')
, $this->get_token($user, $renew_token)
, $this->get_id()
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'RSS')
, 'application/rss+xml'
);
break;
}
}
public function get_cache_key($option = null)
{
return 'feed_adapter_' . $this->get_id() . '_' . ($option ? '_' . $option : '');
}
public function get_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option));
}
public function set_data_to_cache($value, $option = null, $duration = 0)
{
return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration);
}
public function delete_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option));
}
}

View File

@@ -1,260 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_Aggregate extends Feed_Abstract implements Feed_Interface
{
/**
*
* @var array
*/
protected $feeds;
public function __construct(Application $app, Array $feeds)
{
$this->title = 'AGGREGGATE';
$this->subtitle = 'AGREGGATE SUBTITLE';
$this->created_on = new DateTime();
$this->updated_on = new DateTime();
$this->app = $app;
$tmp_feeds = array();
foreach ($feeds as $feed) {
$tmp_feeds[$feed->get_id()] = $feed;
}
$this->feeds = $tmp_feeds;
return $this;
}
public function get_id()
{
throw new LogicException('Aggregate feed does not have an id');
}
/**
*
* @return string
*/
public function get_icon_url()
{
$url = '/skins/icons/rss32.gif';
return $url;
}
/**
*
* @return boolean
*/
public function is_aggregated()
{
return true;
}
/**
*
* @param int $offset_start
* @param int $how_many
* @return Feed_Entry_Collection
*/
public function get_entries($offset_start, $how_many)
{
$result = new Feed_Entry_Collection();
if (count($this->feeds) === 0) {
return $result;
}
$offset_start = (int) $offset_start;
$how_many = $how_many > 20 ? 20 : (int) $how_many;
$sql = 'SELECT id, feed_id
FROM feed_entries
WHERE feed_id IN (' . implode(', ', array_keys($this->feeds)) . ')
ORDER BY id DESC
LIMIT ' . $offset_start . ', ' . $how_many;
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
$entry = new Feed_Entry_Adapter($this->app, $this->feeds[$row['feed_id']], $row['id']);
$result->add_entry($entry);
}
return $result;
}
/**
*
* @return int
*/
public function get_count_total_entries()
{
if (count($this->feeds) === 0) {
return 0;
}
$sql = 'SELECT count(id) as number
FROM feed_entries
WHERE feed_id
IN (' . implode(', ', array_keys($this->feeds)) . ') ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$number = $row ? (int) $row['number'] : 0;
$stmt->closeCursor();
return $number;
}
/**
*
* @param registryInterface $registry
* @param string $format
* @param int $page
* @return Feed_Link
*/
public function get_homepage_link(registryInterface $registry, $format, $page = null)
{
switch ($format) {
case self::FORMAT_ATOM:
return new Feed_Link(
sprintf('%sfeeds/aggregated/atom/%s'
, $registry->get('GV_ServerName')
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'Atom')
, 'application/atom+xml'
);
break;
case self::FORMAT_COOLIRIS:
return new Feed_Link(
sprintf('%sfeeds/cooliris/%s'
, $registry->get('GV_ServerName')
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'RSS')
, 'application/rss+xml'
);
break;
default:
case self::FORMAT_RSS:
return new Feed_Link(
sprintf('%sfeeds/aggregated/rss/%s'
, $registry->get('GV_ServerName')
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'RSS')
, 'application/rss+xml'
);
break;
}
}
/**
*
* @param User_Adapter $user
* @param boolean $renew
* @return string
*/
protected function get_token(User_Adapter $user, $renew = false)
{
$sql = 'SELECT token FROM feed_tokens
WHERE usr_id = :usr_id AND aggregated = "1"';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $user->get_id()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row || $renew === true) {
$token = random::generatePassword(12, random::LETTERS_AND_NUMBERS);
$sql = 'REPLACE INTO feed_tokens (id, token, feed_id, usr_id, aggregated)
VALUES (null, :token, :feed_id, :usr_id, :aggregated)';
$params = array(
':token' => $token
, ':feed_id' => null
, ':usr_id' => $user->get_id()
, ':aggregated' => '1'
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
} else {
$token = $row['token'];
}
return $token;
}
/**
*
* @param Application $app
* @param User_Adapter $user
* @return Feed_Aggregate
*/
public static function load_with_user(Application $app, User_Adapter $user)
{
$feeds = Feed_Collection::load_all($app, $user);
return new self($app, $feeds->get_feeds());
}
/**
*
* @param registryInterface $registry
* @param User_Adapter $user
* @param string $format
* @param int $page
* @param boolean $renew_token
* @return Feed_Link
*/
public function get_user_link(registryInterface $registry, User_Adapter $user, $format, $page = null, $renew_token = false)
{
switch ($format) {
case self::FORMAT_ATOM:
return new Feed_Link(
sprintf('%sfeeds/userfeed/aggregated/%s/atom/%s'
, $registry->get('GV_ServerName')
, $this->get_token($user, $renew_token)
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'Atom')
, 'application/atom+xml'
);
break;
case self::FORMAT_RSS:
return new Feed_Link(
sprintf('%sfeeds/userfeed/aggregated/%s/rss/%s'
, $registry->get('GV_ServerName')
, $this->get_token($user, $renew_token)
, ($page ? '?page=' . $page : '')
)
, sprintf('%s - %s', $this->get_title(), 'RSS')
, 'application/rss+xml'
);
break;
}
}
}

View File

@@ -1,165 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterface
{
/**
*
* @var Array
*/
protected $feeds;
/**
*
* @var Application
*/
protected $app;
const CACHE_PUBLIC = 'public';
/**
*
* @param Application $app
* @param array $feeds
* @return Feed_Collection
*/
public function __construct(Application $app, Array $feeds)
{
$this->feeds = $feeds;
$this->app = $app;
return $this;
}
/**
*
* @param Application $app
* @param User_Adapter $user
* @return Feed_Collection
*/
public static function load_all(Application $app, User_Adapter $user)
{
$base_ids = array_keys($user->ACL()->get_granted_base());
$sql = 'SELECT id FROM feeds
WHERE base_id IS NULL ';
if (count($base_ids) > 0) {
$sql .= ' OR base_id
IN (' . implode(', ', $base_ids) . ') ';
}
$sql .= ' OR public = "1"
ORDER BY created_on DESC';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$feeds = array();
foreach ($rs as $row) {
$feeds[] = new Feed_Adapter($app, $row['id']);
}
return new self($app, $feeds);
}
/**
*
* @return Array
*/
public function get_feeds()
{
return $this->feeds;
}
/**
*
* @return Feed_Aggregate
*/
public function get_aggregate()
{
return new Feed_Aggregate($this->app, $this->feeds);
}
/**
*
* @param Application $app
* @return Feed_Collection
*/
public static function load_public_feeds(Application $app)
{
$rs = self::retrieve_public_feed_ids($app['phraseanet.appbox']);
$feeds = array();
foreach ($rs as $feed_id) {
$feeds[] = new Feed_Adapter($app, $feed_id);
}
return new self($app, $feeds);
}
protected static function retrieve_public_feed_ids(appbox $appbox)
{
$key = 'feedcollection_' . self::CACHE_PUBLIC;
try {
return $appbox->get_data_from_cache($key);
} catch (Exception $e) {
}
$sql = 'SELECT id FROM feeds WHERE public = "1" AND base_id IS null ORDER BY created_on DESC';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$feeds = array();
foreach ($rs as $row) {
$feeds[] = $row['id'];
}
$appbox->set_data_to_cache($feeds, $key);
return $feeds;
}
public function get_cache_key($option = null)
{
return 'feedcollection_' . ($option ? '_' . $option : '');
}
public function get_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option));
}
public function set_data_to_cache($value, $option = null, $duration = 0)
{
return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration);
}
public function delete_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option));
}
}

View File

@@ -1,24 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_CollectionInterface
{
public function get_feeds();
public function get_aggregate();
}

View File

@@ -1,593 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterface
{
/**
*
* @var appbox
*/
protected $app;
/**
*
* @var int
*/
protected $id;
/**
*
* @var string
*/
protected $title;
/**
*
* @var string
*/
protected $subtitle;
/**
*
* @var DateTime
*/
protected $created_on;
/**
*
* @var DateTime
*/
protected $updated_on;
/**
*
* @var Feed_Publisher_Adapter
*/
protected $publisher;
/**
*
* @var int
*/
protected $publisher_id;
/**
*
* @var String
*/
protected $author_name;
/**
*
* @var String
*/
protected $author_email;
/**
*
* @var Feed_Adapter
*/
protected $feed;
/**
*
* @var array
*/
protected $items;
const CACHE_ELEMENTS = 'elements';
/**
*
* @param Application $app
* @param Feed_Adapter $feed
* @param int $id
* @return Feed_Entry_Adapter
*/
public function __construct(Application $app, Feed_Adapter $feed, $id)
{
$this->app = $app;
$this->feed = $feed;
$this->id = (int) $id;
$this->load();
return $this;
}
/**
*
* @return Feed_Entry_Adapter
*/
protected function load()
{
try {
$datas = $this->get_data_from_cache();
$this->title = $datas['title'];
$this->subtitle = $datas['subtitle'];
$this->author_name = $datas['author_name'];
$this->author_email = $datas['author_email'];
$this->publisher_id = $datas['publisher_id'];
$this->updated_on = $datas['updated_on'];
$this->created_on = $datas['created_on'];
return $this;
} catch (Exception $e) {
}
$sql = 'SELECT publisher, title, description, created_on, updated_on
, author_name, author_email
FROM feed_entries
WHERE id = :id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $this->id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new Exception_Feed_EntryNotFound();
$this->title = $row['title'];
$this->subtitle = $row['description'];
$this->author_name = $row['author_name'];
$this->author_email = $row['author_email'];
$this->publisher_id = $row['publisher'];
$this->updated_on = new DateTime($row['updated_on']);
$this->created_on = new DateTime($row['created_on']);
$datas = array(
'title' => $this->title
, 'subtitle' => $this->subtitle
, 'author_name' => $this->author_name
, 'author_email' => $this->author_email
, 'publisher_id' => $this->publisher_id
, 'updated_on' => $this->updated_on
, 'created_on' => $this->created_on
);
$this->set_data_to_cache($datas);
return $this;
}
public function get_link()
{
$href = sprintf(
'%slightbox/feeds/entry/%d/'
, $this->app['phraseanet.registry']->get('GV_ServerName')
, $this->get_id()
);
return new Feed_Link($href, $this->get_title(), 'text/html');
}
/**
*
* @return Feed_Adapter
*/
public function get_feed()
{
return $this->feed;
}
/**
*
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
*
* @return string
*/
public function get_title()
{
return $this->title;
}
/**
*
* @return string
*/
public function get_subtitle()
{
return $this->subtitle;
}
/**
* Change the parent feed of the entry
*
* @param Feed_Adapter $feed
* @return \Feed_Entry_Adapter
*/
public function set_feed(Feed_Adapter $feed)
{
$sql = 'UPDATE feed_entries
SET feed_id = :feed_id, updated_on = NOW() WHERE id = :entry_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(
':feed_id' => $feed->get_id(),
':entry_id' => $this->get_id(),
));
$stmt->closeCursor();
$this->feed->delete_data_from_cache();
$this->feed = $feed;
$feed->delete_data_from_cache();
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param string $title
* @return Feed_Entry_Adapter
*/
public function set_title($title)
{
$title = trim(strip_tags($title));
if ($title === '')
throw new Exception_InvalidArgument();
$sql = 'UPDATE feed_entries
SET title = :title, updated_on = NOW() WHERE id = :entry_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':title' => $title, ':entry_id' => $this->get_id()));
$stmt->closeCursor();
$this->title = $title;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param string $subtitle
* @return Feed_Entry_Adapter
*/
public function set_subtitle($subtitle)
{
$subtitle = strip_tags($subtitle);
$sql = 'UPDATE feed_entries
SET description = :subtitle, updated_on = NOW()
WHERE id = :entry_id';
$params = array(':subtitle' => $subtitle, ':entry_id' => $this->get_id());
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->subtitle = $subtitle;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param string $author_name
* @return Feed_Entry_Adapter
*/
public function set_author_name($author_name)
{
$sql = 'UPDATE feed_entries
SET author_name = :author_name, updated_on = NOW()
WHERE id = :entry_id';
$params = array(
':author_name' => $author_name,
':entry_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->author_name = $author_name;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param string $author_email
* @return Feed_Entry_Adapter
*/
public function set_author_email($author_email)
{
$sql = 'UPDATE feed_entries
SET author_email = :author_email, updated_on = NOW()
WHERE id = :entry_id';
$params = array(
':author_email' => $author_email,
':entry_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->author_email = $author_email;
$this->delete_data_from_cache();
return $this;
}
public function set_created_on(DateTime $datetime)
{
$sql = 'UPDATE feed_entries
SET created_on = :created_on
WHERE id = :entry_id';
$params = array(
':created_on' => $datetime->format(DATE_ISO8601),
':entry_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->created_on = $datetime;
$this->delete_data_from_cache();
return $this;
}
public function set_updated_on(DateTime $datetime)
{
$sql = 'UPDATE feed_entries
SET updated_on = :updated_on
WHERE id = :entry_id';
$params = array(
':updated_on' => $datetime->format(DATE_ISO8601),
':entry_id' => $this->get_id()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->updated_on = $datetime;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @return Feed_Publisher_Adapter
*/
public function get_publisher()
{
if (! $this->publisher instanceof Feed_Publisher_Adapter) {
try {
$this->publisher = new Feed_Publisher_Adapter($this->app, $this->publisher_id);
} catch (\Exception_Feed_PublisherNotFound $e) {
}
}
return $this->publisher;
}
/**
*
* @param User_adapter $user
* @return boolean
*/
public function is_publisher(User_adapter $user)
{
$publisher = $this->get_publisher();
if ($publisher instanceof Feed_Publisher_Interface) {
return $user->get_id() === $publisher->get_user()->get_id();
}
return false;
}
/**
*
* @return DateTime
*/
public function get_created_on()
{
return $this->created_on;
}
/**
*
* @return DateTime
*/
public function get_updated_on()
{
return $this->updated_on;
}
/**
*
* @return string
*/
public function get_author_name()
{
return $this->author_name;
}
/**
*
* @return string
*/
public function get_author_email()
{
return $this->author_email;
}
/**
*
* @return array
*/
public function get_content()
{
if ($this->items) {
return $this->items;
}
$rs = $this->retrieve_elements();
$items = array();
foreach ($rs as $item_id) {
try {
$items[] = new Feed_Entry_Item($this->app['phraseanet.appbox'], $this, $item_id);
} catch (NotFoundHttpException $e) {
}
}
$this->items = $items;
return $this->items;
}
protected function retrieve_elements()
{
try {
return $this->get_data_from_cache(self::CACHE_ELEMENTS);
} catch (Exception $e) {
}
$sql = 'SELECT id FROM feed_entry_elements
WHERE entry_id = :entry_id ORDER BY ord ASC';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':entry_id' => $this->get_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$items = array();
foreach ($rs as $row) {
$items[] = (int) $row['id'];
}
$this->set_data_to_cache($items, self::CACHE_ELEMENTS);
return $items;
}
/**
*
* @return void
*/
public function delete()
{
foreach ($this->get_content() as $content) {
$content->delete();
}
$sql = 'DELETE FROM feed_entries WHERE id = :entry_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':entry_id' => $this->get_id()));
$stmt->closeCursor();
return;
}
public static function create(Application $app, Feed_Adapter $feed
, Feed_Publisher_Adapter $publisher, $title, $subtitle, $author_name, $author_mail)
{
if ( ! $feed->is_publisher($publisher->get_user())) {
throw new Exception_Feed_PublisherNotFound("Publisher not found");
}
if ( ! $feed->is_public() && $feed->get_collection() instanceof Collection) {
if ( ! $publisher->get_user()->ACL()->has_access_to_base($feed->get_collection()->get_base_id())) {
throw new AccessDeniedHttpException("User has no rights to publish in current feed");
}
}
$sql = 'INSERT INTO feed_entries (id, feed_id, publisher, title
, description, created_on, updated_on, author_name, author_email)
VALUES (null, :feed_id, :publisher_id, :title
, :description, NOW(), NOW(), :author_name, :author_email)';
$params = array(
':feed_id' => $feed->get_id(),
':publisher_id' => $publisher->get_id(),
':title' => trim($title),
':description' => trim($subtitle),
':author_name' => trim($author_name),
':author_email' => trim($author_mail),
);
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$entry_id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
$feed->delete_data_from_cache();
$entry = new self($app, $feed, $entry_id);
$app['events-manager']->trigger('__FEED_ENTRY_CREATE__', array('entry_id' => $entry_id), $entry);
return $entry;
}
/**
*
* @param Application $app
* @param type $id
* @return Feed_Entry_Adapter
*/
public static function load_from_id(Application $app, $id)
{
$sql = 'SELECT feed_id FROM feed_entries WHERE id = :entry_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':entry_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new Exception_Feed_EntryNotFound();
$feed = new Feed_Adapter($app, $row['feed_id']);
return new self($app, $feed, $id);
}
public function get_cache_key($option = null)
{
return 'feedentry_' . $this->get_id() . '_' . ($option ? '_' . $option : '');
}
public function get_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option));
}
public function set_data_to_cache($value, $option = null, $duration = 0)
{
return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration);
}
public function delete_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option));
}
}

View File

@@ -1,73 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Entry_Collection implements Feed_Entry_CollectionInterface
{
/**
*
* @var array
*/
protected $entries = array();
/**
*
* @var DateTime
*/
protected $updated_on;
/**
*
* @var string
*/
protected $title;
/**
*
* @var string
*/
protected $subtitle;
/**
*
* @return Feed_Entry_Collection
*/
public function __construct()
{
return $this;
}
/**
*
* @param Feed_Entry_Adapter $entry
* @return Feed_Entry_Collection
*/
public function add_entry(Feed_Entry_Adapter $entry)
{
$this->entries[] = $entry;
return $this;
}
/**
*
* @return Array
*/
public function get_entries()
{
return $this->entries;
}
}

View File

@@ -1,26 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Entry_CollectionInterface
{
public function __construct();
public function add_entry(Feed_Entry_Adapter $entry);
public function get_entries();
}

View File

@@ -1,59 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface Feed_Entry_Interface
{
public function __construct(Application $app, Feed_Adapter $feed, $id);
public function get_feed();
public function get_id();
public function get_title();
public function get_subtitle();
public function set_title($title);
public function set_subtitle($subtitle);
public function set_author_name($author_name);
public function set_author_email($author_email);
public function get_publisher();
public function get_created_on();
public function get_updated_on();
public function get_author_name();
public function get_author_email();
public function get_content();
public function delete();
public static function create(Application $app, Feed_Adapter $feed
, Feed_Publisher_Adapter $publisher, $title, $subtitle, $author_name, $author_mail);
public static function load_from_id(Application $app, $id);
}

View File

@@ -1,229 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Entry_Item implements Feed_Entry_ItemInterface, cache_cacheableInterface
{
/**
*
* @var appbox
*/
protected $appbox;
/**
*
* @var int
*/
protected $id;
/**
*
* @var record_adapter
*/
protected $record;
/**
*
* @var Feed_Entry_Adapter
*/
protected $entry;
/**
*
* @var int
*/
protected $ord;
/**
*
* @param appbox $appbox
* @param Feed_Entry_Adapter $entry
* @param int $id
* @return Feed_Entry_Item
*/
public function __construct(appbox $appbox, Feed_Entry_Adapter $entry, $id)
{
$this->appbox = $appbox;
$this->id = (int) $id;
$this->entry = $entry;
$this->load();
return $this;
}
public function get_entry()
{
return $this->entry;
}
/**
*
* @return Feed_Entry_Item
*/
protected function load()
{
try {
$datas = $this->get_data_from_cache();
$this->record = $this->appbox->get_databox($datas['sbas_id'])
->get_record($datas['record_id'], $datas['ord']);
$this->ord = $datas['ord'];
return $this;
} catch (Exception $e) {
}
$sql = 'SELECT id, sbas_id, record_id, ord
FROM feed_entry_elements WHERE id = :id';
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $this->id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new Exception_Feed_ItemNotFound();
$this->record = $this->appbox->get_databox($row['sbas_id'])
->get_record($row['record_id']);
$this->ord = (int) $row['ord'];
$datas = array(
'record_id' => $this->record->get_record_id()
, 'sbas_id' => $this->record->get_sbas_id()
, 'ord' => $this->ord
);
$this->set_data_to_cache($datas);
return $this;
}
/**
*
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
*
* @return record_adapter
*/
public function get_record()
{
return $this->record;
}
/**
*
* @return int
*/
public function get_ord()
{
return $this->ord;
}
public function set_ord($order)
{
$order = (int) $order;
$sql = 'UPDATE feed_entry_elements SET ord = :ord WHERE id = :item_id';
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':ord' => $order, ':item_id' => $this->get_id()));
$stmt->closeCursor();
$this->ord = $order;
return $this;
}
/**
*
* @return void
*/
public function delete()
{
$sql = 'DELETE FROM feed_entry_elements WHERE id = :id';
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $this->get_id()));
$stmt->closeCursor();
return;
}
/**
*
* @param appbox $appbox
* @param Feed_Entry_Adapter $entry
* @param record_adapter $record
* @return Feed_Entry_Item
*/
public static function create(appbox $appbox, Feed_Entry_Adapter $entry, record_adapter $record)
{
$sql = 'SELECT (MAX(ord)+1) as sorter FROM feed_entry_elements
WHERE entry_id = :entry_id';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute(array(':entry_id' => $entry->get_id()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$sorter = ($row && $row['sorter'] > 0) ? (int) $row['sorter'] : 1;
$sql = 'INSERT INTO feed_entry_elements
(id, entry_id, sbas_id, record_id, ord)
VALUES (null, :entry_id, :sbas_id, :record_id, :ord)';
$params = array(
':entry_id' => $entry->get_id()
, ':sbas_id' => $record->get_sbas_id()
, ':record_id' => $record->get_record_id()
, ':ord' => $sorter
);
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$item_id = $appbox->get_connection()->lastInsertId();
$entry->delete_data_from_cache(Feed_Entry_Adapter::CACHE_ELEMENTS);
return new self($appbox, $entry, $item_id);
}
public function get_cache_key($option = null)
{
return 'feedentryitem_' . $this->get_id() . '_' . ($option ? '_' . $option : '');
}
public function get_data_from_cache($option = null)
{
return $this->appbox->get_data_from_cache($this->get_cache_key($option));
}
public function set_data_to_cache($value, $option = null, $duration = 0)
{
return $this->appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
}
public function delete_data_from_cache($option = null)
{
return $this->appbox->delete_data_from_cache($this->get_cache_key($option));
}
}

View File

@@ -1,32 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Entry_ItemInterface
{
public function __construct(appbox $appbox, Feed_Entry_Adapter $entry, $id);
public function get_id();
public function get_record();
public function get_ord();
public function delete();
public static function create(appbox $appbox, Feed_Entry_Adapter $entry, record_adapter $record);
}

View File

@@ -1,40 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Interface
{
public function get_title();
public function get_subtitle();
public function get_created_on();
public function get_updated_on();
public function get_entries($offset_start, $how_many);
public function get_count_total_entries();
public function get_homepage_link(registryInterface $registry, $format, $page = null);
public function get_user_link(registryInterface $registry, User_Adapter $user, $format, $page = null, $renew_token = false);
public function get_icon_url();
public function is_aggregated();
}

View File

@@ -1,80 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Link implements Feed_LinkInterface
{
/**
*
* @var string
*/
protected $mimetype;
/**
*
* @var string
*/
protected $title;
/**
*
* @var string
*/
protected $href;
/**
*
* @param string $href
* @param string $title
* @param string $mimetype
* @return Feed_Link
*/
public function __construct($href, $title, $mimetype)
{
$this->mimetype = $mimetype;
$this->href = $href;
$this->title = $title;
return $this;
}
/**
*
* @return string
*/
public function get_mimetype()
{
return $this->mimetype;
}
/**
*
* @return string
*/
public function get_title()
{
return $this->title;
}
/**
*
* @return string
*/
public function get_href()
{
return $this->href;
}
}

View File

@@ -1,26 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_LinkInterface
{
public function get_mimetype();
public function get_title();
public function get_href();
}

View File

@@ -1,240 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheableInterface
{
/**
*
* @var Application
*/
protected $app;
/**
*
* @var int
*/
protected $id;
/**
*
* @var User_Adapter
*/
protected $user;
/**
*
* @var boolean
*/
protected $owner;
/**
*
* @var DateTime
*/
protected $created_on;
/**
*
* @var User_Adapter
*/
protected $added_by;
/**
*
* @param Application $app
* @param int $id
* @return Feed_Publisher_Adapter
*/
public function __construct(Application $app, $id)
{
$this->app = $app;
$this->id = (int) $id;
$this->load();
return $this;
}
/**
*
* @return Feed_Publisher_Adapter
*/
protected function load()
{
try {
$datas = $this->get_data_from_cache();
$this->user = User_Adapter::getInstance($datas['usr_id'], $this->app);
$this->added_by = User_Adapter::getInstance($datas['added_by_usr_id'], $this->app);
$this->created_on = $datas['created_on'];
$this->owner = $datas['owner'];
return $this;
} catch (Exception $e) {
}
$sql = 'SELECT id, usr_id, owner, created_on, added_by
FROM feed_publishers WHERE id = :feed_publisher_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_publisher_id' => $this->id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new Exception_Feed_PublisherNotFound('Publisher is not Found');
$this->user = User_Adapter::getInstance($row['usr_id'], $this->app);
$this->owner = ! ! $row['owner'];
$this->created_on = new DateTime($row['created_on']);
$this->added_by = User_Adapter::getInstance($row['added_by'], $this->app);
$datas = array(
'usr_id' => $this->user->get_id()
, 'owner' => $this->owner
, 'created_on' => $this->created_on
, 'added_by_usr_id' => $this->added_by->get_id()
);
$this->set_data_to_cache($datas);
return $this;
}
/**
*
* @return User_Adapter
*/
public function get_user()
{
return $this->user;
}
/**
*
* @return boolean
*/
public function is_owner()
{
return $this->owner;
}
/**
*
* @return DateTime
*/
public function get_created_on()
{
return $this->created_on;
}
/**
*
* @return User_Adapter
*/
public function get_added_by()
{
return $this->added_by;
}
/**
*
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
*
* @return void
*/
public function delete()
{
$sql = 'DELETE FROM feed_publishers WHERE id = :feed_publisher_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':feed_publisher_id' => $this->get_id()));
$stmt->closeCursor();
return;
}
/**
*
* @param Application $app
* @param User_Adapter $user
* @param Feed_Adapter $feed
* @param boolean $owner
* @return Feed_Publisher_Adapter
*/
public static function create(Application $app, User_Adapter $user, Feed_Adapter $feed, $owner)
{
$sql = 'INSERT INTO feed_publishers (id, usr_id, feed_id, owner, created_on, added_by)
VALUES (null, :usr_id, :feed_id, :owner, NOW(), :added_by)';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$params = array(
':usr_id' => $user->get_id()
, ':feed_id' => $feed->get_id()
, ':owner' => $owner ? '1' : null
, ':added_by' => $owner ? $user->get_id() : $app['authentication']->getUser()->get_id()
);
$stmt->execute($params);
$id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
$stmt->closeCursor();
return new self($app, $id);
}
/**
*
* @param appbox $appbox
* @param Feed_Adapter $feed
* @param User_Adapter $user
* @return Feed_Publisher_Adapter
*/
public static function getPublisher(appbox $appbox, Feed_Adapter $feed, User_Adapter $user)
{
foreach ($feed->get_publishers() as $publisher) {
if ($publisher->get_user()->get_id() === $user->get_id()) {
return $publisher;
}
}
throw new Exception_Feed_PublisherNotFound('Publisher not found');
}
public function get_cache_key($option = null)
{
return 'feedpublisher_' . $this->get_id() . '_' . ($option ? '_' . $option : '');
}
public function get_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option));
}
public function set_data_to_cache($value, $option = null, $duration = 0)
{
return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration);
}
public function delete_data_from_cache($option = null)
{
return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option));
}
}

View File

@@ -1,40 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface Feed_Publisher_Interface
{
public function __construct(Application $app, $id);
public function get_user();
public function is_owner();
public function get_created_on();
public function get_added_by();
public function get_id();
public function delete();
public static function create(Application $app, User_Adapter $user, Feed_Adapter $feed, $owner);
public static function getPublisher(appbox $appbox, Feed_Adapter $feed, User_Adapter $user);
}

View File

@@ -1,110 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_Token
{
/**
*
* @var int
*/
protected $usr_id;
/**
*
* @var int
*/
protected $feed_id;
/**
*
* @var User_Adapter
*/
protected $user;
/**
*
* @var Feed_Adapter
*/
protected $feed;
/**
*
* @var appbox
*/
protected $app;
/**
*
* @param Application $app
* @param string $token
* @param int $feed_id
*
* @return Feed_Token
*/
public function __construct(Application $app, $token, $feed_id)
{
$sql = 'SELECT feed_id, usr_id FROM feed_tokens
WHERE feed_id = :feed_id
AND aggregated IS NULL AND token = :token';
$params = array(
':feed_id' => $feed_id
, ':token' => $token
);
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new NotFoundHttpException('Feed not found.');
$this->feed_id = (int) $row['feed_id'];
$this->usr_id = (int) $row['usr_id'];
$this->app = $app;
return $this;
}
/**
*
* @return User_Adapter
*/
public function get_user()
{
if ( ! $this->user)
$this->user = User_Adapter::getInstance($this->usr_id, $this->app);
return $this->user;
}
/**
*
* @return Feed_Adapter
*/
public function get_feed()
{
if ( ! $this->feed)
$this->feed = Feed_Adapter::load_with_user($this->app, $this->get_user(), $this->feed_id);
return $this->feed;
}
}

View File

@@ -1,66 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
*
* @package Feeds
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Feed_TokenAggregate extends Feed_Token
{
/**
*
* @param Application $app
* @param string $token
* @return Feed_TokenAggregate
*/
public function __construct(Application $app, $token)
{
$sql = 'SELECT usr_id FROM feed_tokens
WHERE aggregated = "1" AND token = :token';
$params = array(
':token' => $token
);
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new NotFoundHttpException('Feed not found.');
$this->usr_id = $row['usr_id'];
$this->app = $app;
return $this;
}
/**
*
* @return Feed_Aggregate
*/
public function get_feed()
{
if (! $this->feed) {
$this->feed = Feed_Aggregate::load_with_user($this->app, $this->get_user());
}
return $this->feed;
}
}

View File

@@ -1,351 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Adapter $entry, 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');
$caption = $content->get_record()->get_caption();
$title_field = $caption->get_dc_field(databox_Field_DCESAbstract::Title);
if ($title_field) {
$str_title = $title_field->get_serialized_values(' ');
$title = $this->addTag($document, $group, 'media:title', $str_title);
$title->setAttribute('type', 'plain');
}
$desc_field = $caption->get_dc_field(databox_Field_DCESAbstract::Description);
if ($desc_field) {
$str_desc = $desc_field->get_serialized_values(' ');
$desc = $this->addTag($document, $group, 'media:description', $str_desc);
$desc->setAttribute('type', 'plain');
}
$contrib_field = $caption->get_dc_field(databox_Field_DCESAbstract::Contributor);
if ($contrib_field) {
$str_contrib = $contrib_field->get_serialized_values(' ');
$contrib = $this->addTag($document, $group, 'media:credit', $str_contrib);
$contrib->setAttribute('role', 'contributor');
$contrib->setAttribute('scheme', 'urn:ebu');
}
$director_field = $caption->get_dc_field(databox_Field_DCESAbstract::Creator);
if ($director_field) {
$str_director = $director_field->get_serialized_values(' ');
$director = $this->addTag($document, $group, 'media:credit', $str_director);
$director->setAttribute('role', 'director');
$director->setAttribute('scheme', 'urn:ebu');
}
$publisher_field = $caption->get_dc_field(databox_Field_DCESAbstract::Publisher);
if ($publisher_field) {
$str_publisher = $publisher_field->get_serialized_values(' ');
$publisher = $this->addTag($document, $group, 'media:credit', $str_publisher);
$publisher->setAttribute('role', 'publisher');
$publisher->setAttribute('scheme', 'urn:ebu');
}
$rights_field = $caption->get_dc_field(databox_Field_DCESAbstract::Rights);
if ($rights_field) {
$str_rights = $rights_field->get_serialized_values(' ');
$rights = $this->addTag($document, $group, 'media:copyright', $str_rights);
}
$keyword_field = $caption->get_dc_field(databox_Field_DCESAbstract::Subject);
if ($keyword_field) {
$str_keywords = $keyword_field->get_serialized_values(', ');
$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();
}

View File

@@ -1,192 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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, $entry, $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_email
* @return Feed_XML_Atom
*/
public function set_author_email($author_email)
{
$this->author = true;
$this->author_email = $author_email;
return $this;
}
/**
*
* @param string $author_url
* @return Feed_XML_Atom
*/
public function set_author_url($author_url)
{
$this->author = true;
$this->author_url = $author_url;
return $this;
}
}

View File

@@ -1,440 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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_Cooliris 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 $copyright
* @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 $hour
* @return Feed_XML_RSS
*/
public function set_skipHour($hour)
{
$this->skipHours[] = (int) $hour;
return $this;
}
/**
*
* @param string $day
* @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)
{
foreach ($entry->get_content() as $content) {
$this->addContent($document, $node, $entry, $content);
}
return;
}
/**
*
* @param DOMDocument $document
* @param DOMNode $item
* @param Feed_Entry_Item $content
* @return Feed_XML_Interface
*/
protected function addContent(DOMDocument $document, DOMNode $node, Feed_Entry_Adapter $entry, 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;
}
//add item node to channel node
$item = $this->addTag($document, $node, 'item');
$caption = $content->get_record()->get_caption();
$title_field = $caption->get_dc_field(databox_Field_DCESAbstract::Title);
if ($title_field) {
$str_title = $title_field->get_serialized_values(' ');
} else {
$str_title = $content->get_record()->get_title();
}
//attach tile node to item node
$title = $this->addTag($document, $item, 'title', $str_title);
$desc_field = $caption->get_dc_field(databox_Field_DCESAbstract::Description);
if ($desc_field) {
$str_desc = $desc_field->get_serialized_values(' ');
} else {
$str_desc = '';
}
//attach desc node to item node
$desc = $this->addTag($document, $item, 'description', $str_desc);
$duration = $content->get_record()->get_duration();
if ($preview_permalink) {
$preview = $this->addTag($document, $item, '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, $item, '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, $item, '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;
}
}

View File

@@ -1,40 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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();
}

View File

@@ -1,369 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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 $copyright
* @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 $hour
* @return Feed_XML_RSS
*/
public function set_skipHour($hour)
{
$this->skipHours[] = (int) $hour;
return $this;
}
/**
*
* @param string $day
* @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, $entry, $content);
}
return $item;
}
}

View File

@@ -10,6 +10,10 @@
*/
use Alchemy\Phrasea\Application;
use Entities\Feed;
use Entities\FeedEntry;
use Entities\FeedItem;
use Entities\FeedPublisher;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@@ -81,22 +85,31 @@ class patch_320f implements patchInterface
foreach ($rs as $row) {
$user = User_Adapter::getInstance($row['usr_id'], $app);
$feed = $this->get_feed($appbox, $user, $row['pub_restrict'], $row['homelink']);
$feed = $this->getFeed($appbox, $user, $row['pub_restrict'], $row['homelink'], $app);
if (! $feed instanceof Feed_Adapter) {
if (! $feed instanceof Feed) {
continue;
}
$publishers = $feed->get_publishers();
$entry = Feed_Entry_Adapter::create($app, $feed, array_shift($publishers), $row['name'], $row['descript'], $user->get_display_name(), $user->get_email());
$publishers = $feed->getPublishers();
$entry = new FeedEntry();
$entry->setAuthorEmail($user->get_email());
$entry->setAuthorName($user->get_display_name());
$entry->setFeed($feed);
$entry->setPublisher($publishers->first());
$entry->setTitle($row['name']);
$entry->setSubtitle($row['descript']);
$feed->addEntry($entry);
$date_create = new DateTime($row['pub_date']);
if ($date_create < $date_ref) {
$date_ref = $date_create;
}
$entry->set_created_on($date_create);
$entry->setCreatedOn($date_create);
if ($row['updater'] != '0000-00-00 00:00:00') {
$date_update = new DateTime($row['updater']);
$entry->set_updated_on($date_update);
$entry->setUpdatedOn($date_update);
}
$sql = 'SELECT sselcont_id, ssel_id, base_id, record_id
@@ -109,12 +122,20 @@ class patch_320f implements patchInterface
foreach ($rs as $row) {
try {
$record = new record_adapter($app, phrasea::sbasFromBas($app, $row['base_id']), $row['record_id']);
$item = Feed_Entry_Item::create($appbox, $entry, $record);
$item = new FeedItem();
$item->setEntry($entry);
$entry->addItem($item);
$item->setRecordId($record->get_record_id());
$item->setSbasId($record->get_sbas_id());
$item->setLastInFeedItem();
$app['EM']->persist($item);
} catch (NotFoundHttpException $e) {
}
}
$app['EM']->persist($entry);
$sql = 'UPDATE ssel SET deleted = "1", migrated="1"
WHERE ssel_id = :ssel_id';
$stmt = $appbox->get_connection()->prepare($sql);
@@ -122,15 +143,17 @@ class patch_320f implements patchInterface
$stmt->closeCursor();
}
$this->set_feed_dates($date_ref);
$app['EM']->persist($feed);
$app['EM']->flush();
return true;
}
protected function set_feed_dates(DateTime $date_ref)
protected function setFeedDates(DateTime $date_ref)
{
foreach (self::$feeds as $array_feeds) {
foreach ($array_feeds as $feed) {
$feed->set_created_on($date_ref);
$feed->setCreatedOn($date_ref);
}
}
@@ -138,7 +161,7 @@ class patch_320f implements patchInterface
}
protected static $feeds = array();
protected function get_feed(appbox $appbox, User_Adapter $user, $pub_restrict, $homelink)
protected function getFeed(appbox $appbox, User_Adapter $user, $pub_restrict, $homelink, Application $app)
{
$user_key = 'user_' . $user->get_id();
if ($homelink == '1')
@@ -156,10 +179,23 @@ class patch_320f implements patchInterface
else
$title = $user->get_display_name() . ' - ' . 'public Feed';
$feed = Feed_Adapter::create($app, $user, $title, '');
$feed = new Feed();
$publisher = new FeedPublisher();
$feed->setTitle('title');
$feed->setSubtitle('');
$feed->setIconUrl(false);
$feed->addPublisher($publisher);
$publisher->setFeed($feed);
$publisher->setOwner(true);
$publisher->setUsrId($user->get_id());
if ($homelink) {
$feed->set_public(true);
$feed->setPublic(true);
$app['EM']->persist($feed);
$app['EM']->persist($user);
$app['EM']->flush();
} elseif ($pub_restrict == 1) {
$collections = $user->ACL()->get_granted_base();
$collection = array_shift($collections);
@@ -177,7 +213,7 @@ class patch_320f implements patchInterface
if ( ! ($collection instanceof collection)) {
return false;
}
$feed->set_collection($collection);
$feed->setCollection($collection);
}
self::$feeds[$user_key][$feed_key] = $feed;
} else {

View File

@@ -1,166 +0,0 @@
<?php
class Feed_Entry_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
*
* @var Feed_Entry_Adapter
*/
protected static $object;
/**
*
* @var Feed_Adapter
*/
protected static $feed;
protected static $feed_title = 'Feed test';
protected static $feed_subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
protected static $title = 'entry title';
protected static $subtitle = 'subtitle lalalala';
protected static $author_name = 'Jean Bonno';
protected static $author_email = 'Jean@bonno.fr';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle);
$publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']);
self::$object = Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email);
}
public static function tearDownAfterClass()
{
self::$feed->delete();
parent::tearDownAfterClass();
}
public function testGet_feed()
{
$this->assertInstanceOf('Feed_Adapter', self::$object->get_feed());
$this->assertEquals(self::$feed->get_id(), self::$object->get_feed()->get_id());
}
public function testGet_id()
{
$this->assertTrue(is_int(self::$object->get_id()));
}
public function testGet_title()
{
$this->assertEquals(self::$title, self::$object->get_title());
}
public function testGet_subtitle()
{
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
}
public function testSet_title()
{
$new_titre = 'UNnouveau titre';
self::$object->set_title($new_titre);
$this->assertEquals($new_titre, self::$object->get_title());
$new_titre = '<i>UNnouveau titre encore</i>';
self::$object->set_title($new_titre);
$this->assertNotEquals($new_titre, self::$object->get_title());
$this->assertEquals(strip_tags($new_titre), self::$object->get_title());
try {
self::$object->set_title('');
$this->fail();
} catch (Exception_InvalidArgument $e) {
}
}
public function testSet_subtitle()
{
$new_subtitle = 'PROUT
ET PROUT';
self::$object->set_subtitle($new_subtitle);
$this->assertEquals($new_subtitle, self::$object->get_subtitle());
$new_subtitle = '';
self::$object->set_subtitle($new_subtitle);
$this->assertEquals($new_subtitle, self::$object->get_subtitle());
}
public function testSet_author_name()
{
$new_author = 'Tintin et Milou';
self::$object->set_author_name($new_author);
$this->assertEquals($new_author, self::$object->get_author_name());
self::$object->set_author_name(self::$author_name);
$this->assertEquals(self::$author_name, self::$object->get_author_name());
}
public function testSetFeed()
{
self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
->disableOriginalConstructor()
->getMock();
self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce())
->method('deliver')
->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null));
$new_feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle);
$publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], $new_feed, self::$DI['user']);
$entry = Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email);
$this->assertEquals(self::$feed, $entry->get_feed());
$entry->set_feed($new_feed);
$this->assertEquals($new_feed, $entry->get_feed());
$new_feed->delete();
}
public function testSet_author_email()
{
$new_email = 'Tintin@herge.be';
self::$object->set_author_email($new_email);
$this->assertEquals($new_email, self::$object->get_author_email());
self::$object->set_author_email(self::$author_email);
$this->assertEquals(self::$author_email, self::$object->get_author_email());
}
public function testGet_publisher()
{
$this->assertInstanceOf('Feed_Publisher_Adapter', self::$object->get_publisher());
$this->assertEquals(self::$object->get_publisher()->get_user()->get_id(), self::$DI['user']->get_id());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_created_on());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_updated_on());
}
public function testGet_author_name()
{
$this->assertEquals(self::$author_name, self::$object->get_author_name());
}
public function testGet_author_email()
{
$this->assertEquals(self::$author_email, self::$object->get_author_email());
}
public function testGet_content()
{
$this->assertTrue(is_array(self::$object->get_content()));
$this->assertEquals(0, count(self::$object->get_content()));
}
public function testLoad_from_id()
{
$test_entry = Feed_Entry_Adapter::load_from_id(self::$DI['app'], self::$object->get_id());
$this->assertInstanceOf('Feed_Entry_Adapter', $test_entry);
$this->assertEquals(self::$object->get_id(), $test_entry->get_id());
}
}

View File

@@ -1,63 +0,0 @@
<?php
class Feed_Entry_CollectionTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Feed_Entry_Collection
*/
protected static $object;
/**
*
* @var Feed_Entry_Item
*/
protected static $item;
/**
*
* @var Feed_Entry_Adapter
*/
protected static $entry;
/**
*
* @var Feed_Adapter
*/
protected static $feed;
protected static $feed_title = 'Feed test';
protected static $feed_subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
protected static $title = 'entry title';
protected static $subtitle = 'subtitle lalalala';
protected static $author_name = 'Jean Bonno';
protected static $author_email = 'Jean@bonno.fr';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle);
$publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']);
self::$entry = Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email);
self::$item = Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], self::$entry, self::$DI['record_1']);
self::$object = new Feed_Entry_Collection();
}
public static function tearDownAfterClass()
{
self::$feed->delete();
parent::tearDownAfterClass();
}
public function testAdd_entry()
{
self::$object->add_entry(self::$entry);
}
public function testGet_entries()
{
$this->assertTrue(is_array(self::$object->get_entries()));
$this->assertTrue(count(self::$object->get_entries()) == 1);
}
}

View File

@@ -1,69 +0,0 @@
<?php
class Feed_Entry_ItemTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
*
* @var Feed_Entry_Item
*/
protected static $object;
/**
*
* @var Feed_Entry_Adapter
*/
protected static $entry;
/**
*
* @var Feed_Adapter
*/
protected static $feed;
protected static $feed_title = 'Feed test';
protected static $feed_subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
protected static $title = 'entry title';
protected static $subtitle = 'subtitle lalalala';
protected static $author_name = 'Jean Bonno';
protected static $author_email = 'Jean@bonno.fr';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle);
$publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']);
self::$entry = Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email);
self::$object = Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], self::$entry, self::$DI['record_1']);
}
public static function tearDownAfterClass()
{
self::$feed->delete();
parent::tearDownAfterClass();
}
public function testGet_id()
{
$this->assertTrue(is_int(self::$object->get_id()));
}
public function testGet_record()
{
$this->assertInstanceOf('record_adapter', self::$object->get_record());
$this->assertEquals(self::$DI['record_1']->get_record_id(), self::$object->get_record()->get_record_id());
$this->assertEquals(self::$DI['record_1']->get_sbas_id(), self::$object->get_record()->get_sbas_id());
$this->assertEquals(self::$DI['record_1']->get_base_id(), self::$object->get_record()->get_base_id());
}
public function testGet_ord()
{
$this->assertTrue(is_int(self::$object->get_ord()));
}
public function testGet_entry()
{
$this->assertInstanceOf('Feed_Entry_Adapter', self::$object->get_entry());
$this->assertEquals(self::$entry->get_id(), self::$object->get_entry()->get_id());
}
}

View File

@@ -1,259 +0,0 @@
<?php
class Feed_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
*
* @var Feed_Adapter
*/
protected static $object;
protected static $title = 'Feed test';
protected static $subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$object = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$title, self::$subtitle);
}
public static function tearDownAfterClass()
{
self::$object->delete();
parent::tearDownAfterClass();
}
public function testGet_icon_url()
{
$this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
}
public function testSet_icon()
{
$this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
$file = __DIR__ . '/../../files/p4logo.jpg';
self::$object->set_icon($file);
$this->assertEquals('/custom/feed_' . self::$object->get_id() . '.jpg', self::$object->get_icon_url());
}
/**
* @expectedException \Alchemy\Phrasea\Exception\InvalidArgumentException
*/
public function testSet_iconFail()
{
$file = __DIR__ . '/../../files/unknown.jpg';
self::$object->set_icon($file);
}
public function testIs_aggregated()
{
$this->assertFalse(self::$object->is_aggregated());
}
public function testIs_owner()
{
$this->assertTrue(self::$object->is_owner(self::$DI['user']));
}
public function testIs_publisher()
{
$this->assertTrue(self::$object->is_publisher(self::$DI['user']));
}
public function testIs_public()
{
$this->assertFalse(self::$object->is_public());
self::$object->set_public(true);
$this->assertTrue(self::$object->is_public());
$coll = null;
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
$coll = $collection;
break;
}
if ($coll instanceof collection)
break;
}
self::$object->set_collection($coll);
$this->assertFalse(self::$object->is_public());
self::$object->set_collection(null);
$this->assertTrue(self::$object->is_public());
self::$object->set_public(false);
$this->assertFalse(self::$object->is_public());
}
public function testGet_publishers()
{
$publishers = self::$object->get_publishers();
$this->assertEquals(1, count($publishers));
}
public function testGet_collection()
{
$this->assertNull(self::$object->get_collection());
}
public function testAdd_publisher()
{
self::$object->add_publisher(self::$DI['user']);
$publishers = self::$object->get_publishers();
$this->assertEquals(1, count($publishers));
}
public function testGet_id()
{
$this->assertTrue(is_int(self::$object->get_id()));
$this->assertTrue(self::$object->get_id() > 0);
}
public function testSet_collection()
{
$coll = null;
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
$coll = $collection;
break;
}
if ($coll instanceof collection)
break;
}
self::$object->set_collection($coll);
$this->assertInstanceOf('collection', self::$object->get_collection());
self::$object->set_collection(null);
$this->assertNull(self::$object->get_collection());
}
public function testSet_public()
{
self::$object->set_collection(null);
self::$object->set_public(true);
$this->assertTrue(self::$object->is_public());
self::$object->set_public(false);
$this->assertFalse(self::$object->is_public());
}
public function testSet_title()
{
$this->assertEquals(self::$title, self::$object->get_title());
$title = 'GROS NIchONS';
self::$object->set_title($title);
$this->assertEquals($title, self::$object->get_title());
$title = '<i>GROS NIchONS</i>';
self::$object->set_title($title);
$this->assertNotEquals($title, self::$object->get_title());
$this->assertEquals(strip_tags($title), self::$object->get_title());
try {
self::$object->set_title('<a></a> ');
$this->fail();
} catch (Exception $e) {
}
try {
self::$object->set_title(' ');
$this->fail();
} catch (Exception $e) {
}
try {
self::$object->set_title('');
$this->fail();
} catch (Exception $e) {
}
self::$object->set_title(self::$title);
}
public function testSet_subtitle()
{
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
self::$object->set_subtitle('');
$this->assertEquals('', self::$object->get_subtitle());
self::$object->set_subtitle(' un sous titre ');
$this->assertEquals(' un sous titre ', self::$object->get_subtitle());
self::$object->set_subtitle(self::$subtitle);
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
}
public function testLoad_with_user()
{
$this->assertEquals(Feed_Adapter::load_with_user(self::$DI['app'], self::$DI['user'], self::$object->get_id())->get_id(), self::$object->get_id());
}
public function testGet_count_total_entries()
{
$n = self::$object->get_count_total_entries();
$this->assertTrue($n === 0);
}
public function testGet_entries()
{
$entries_coll = self::$object->get_entries(0, 5);
$this->assertInstanceOf('Feed_Entry_Collection', $entries_coll);
$this->assertEquals(0, count($entries_coll->get_entries()));
}
public function testGet_homepage_link()
{
self::$object->set_public(false);
$link = self::$object->get_homepage_link(self::$DI['app']['phraseanet.registry'], Feed_Adapter::FORMAT_ATOM);
$this->assertNull($link);
self::$object->set_public(true);
$link = self::$object->get_homepage_link(self::$DI['app']['phraseanet.registry'], Feed_Adapter::FORMAT_ATOM);
$this->assertInstanceOf('Feed_Link', $link);
}
public function testGet_user_link()
{
$link = self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM);
$supposed = '/feeds\/userfeed\/([a-zA-Z0-9]{12})\/' . self::$object->get_id() . '\/atom\//';
$atom = $link->get_href();
$this->assertRegExp($supposed, str_replace(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '', $atom));
$this->assertEquals($atom, self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertEquals($atom, self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertNotEquals($atom, self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM, null, true)->get_href());
$link = self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_RSS);
$supposed = '/feeds\/userfeed\/([a-zA-Z0-9]{12})\/' . self::$object->get_id() . '\/rss\//';
$this->assertRegExp($supposed, str_replace(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '', $link->get_href()));
}
public function testGet_title()
{
$this->assertEquals(self::$object->get_title(), self::$title);
try {
self::$object->set_title('');
$this->fail();
} catch (Exception $e) {
}
}
public function testGet_subtitle()
{
$this->assertEquals(self::$object->get_subtitle(), self::$subtitle);
self::$object->set_subtitle('');
$this->assertEquals(self::$object->get_subtitle(), '');
self::$object->set_subtitle(self::$subtitle);
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_created_on());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_updated_on());
}
}

View File

@@ -1,87 +0,0 @@
<?php
class Feed_AggregateTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Feed_Aggregate
*/
protected static $object;
protected static $feeds;
protected static $title = 'Feed test';
protected static $subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$objects[] = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$title, self::$subtitle);
$objects[] = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$title, self::$subtitle);
self::$feeds = $objects;
self::$object = new Feed_Aggregate(self::$DI['app'], self::$feeds);
}
public static function tearDownAfterClass()
{
foreach (self::$feeds as $feed) {
$feed->delete();
}
parent::tearDownAfterClass();
}
public function testGet_icon_url()
{
$this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
}
public function testIs_aggregated()
{
$this->assertTrue(self::$object->is_aggregated());
}
public function testGet_entries()
{
$entries_coll = self::$object->get_entries(0, 5);
$this->assertInstanceOf('Feed_Entry_Collection', $entries_coll);
$this->assertEquals(0, count($entries_coll->get_entries()));
}
public function testGet_count_total_entries()
{
$this->assertEquals(0, self::$object->get_count_total_entries());
}
public function testGet_homepage_link()
{
$link = self::$object->get_homepage_link(self::$DI['app']['phraseanet.registry'], Feed_Adapter::FORMAT_ATOM);
$this->assertInstanceOf('Feed_Link', $link);
$this->assertEquals(self::$DI['app']['phraseanet.registry']->get('GV_ServerName') . 'feeds/aggregated/atom/', $link->get_href());
}
public function testGet_user_link()
{
$link = self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM);
$supposed = '/feeds\/userfeed\/aggregated\/([a-zA-Z0-9]{12})\/atom\//';
$atom = $link->get_href();
$this->assertRegExp($supposed, str_replace(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '', $atom));
$this->assertEquals($atom, self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertEquals($atom, self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertNotEquals($atom, self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_ATOM, null, true)->get_href());
$link = self::$object->get_user_link(self::$DI['app']['phraseanet.registry'], self::$DI['user'], Feed_Adapter::FORMAT_RSS);
$supposed = '/feeds\/userfeed\/aggregated\/([a-zA-Z0-9]{12})\/rss\//';
$this->assertRegExp($supposed, str_replace(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '', $link->get_href()));
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_created_on());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_updated_on());
}
}

View File

@@ -1,59 +0,0 @@
<?php
class Feed_CollectionTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
*
* @var Feed_Adapter
*/
protected static $object;
protected static $title = 'Feed test';
protected static $subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$object = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$title, self::$subtitle);
self::$object->set_public(true);
}
public static function tearDownAfterClass()
{
self::$object->delete();
parent::tearDownAfterClass();
}
public function testLoad_all()
{
$coll = Feed_Collection::load_all(self::$DI['app'], self::$DI['user']);
foreach ($coll->get_feeds() as $feed) {
$this->assertInstanceOf('Feed_Adapter', $feed);
}
}
public function testGet_feeds()
{
$coll = Feed_Collection::load_public_feeds(self::$DI['app']);
foreach ($coll->get_feeds() as $feed) {
$this->assertInstanceOf('Feed_Adapter', $feed);
}
}
public function testGet_aggregate()
{
$coll = Feed_Collection::load_public_feeds(self::$DI['app']);
$this->assertInstanceOf('Feed_Aggregate', $coll->get_aggregate());
}
public function testLoad_public_feeds()
{
$coll = Feed_Collection::load_public_feeds(self::$DI['app']);
foreach ($coll->get_feeds() as $feed) {
$this->assertTrue($feed->is_public());
}
}
}

View File

@@ -1,33 +0,0 @@
<?php
class Feed_LinkTest extends PhraseanetPHPUnitAbstract
{
/**
* @var Feed_Link
*/
protected $object;
protected $href = "http://www.google.fr/";
protected $title = "google";
protected $mime = "html/text";
public function setUp()
{
parent::setUp();
$this->object = new Feed_Link($this->href, $this->title, $this->mime);
}
public function testGet_mimetype()
{
$this->assertEquals($this->mime, $this->object->get_mimetype());
}
public function testGet_title()
{
$this->assertEquals($this->title, $this->object->get_title());
}
public function testGet_href()
{
$this->assertEquals($this->href, $this->object->get_href());
}
}

View File

@@ -1,57 +0,0 @@
<?php
class Feed_Publisher_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Feed_Publisher_Adapter
*/
protected static $object;
protected static $title = 'Feed test';
protected static $subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
/**
* @var Feed_Adapter
*/
protected static $feed;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$title, self::$subtitle);
$publishers = self::$feed->get_publishers();
self::$object = array_pop($publishers);
}
public static function tearDownAfterClass()
{
self::$feed->delete();
parent::tearDownAfterClass();
}
public function testGet_user()
{
$this->assertInstanceOf('user_Adapter', self::$object->get_user());
$this->assertEquals(self::$DI['user']->get_id(), self::$object->get_user()->get_id());
}
public function testIs_owner()
{
$this->assertTrue(self::$object->is_owner());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_created_on());
}
public function testGet_added_by()
{
$this->assertInstanceOf('User_Adapter', self::$object->get_added_by());
}
public function testGet_id()
{
$this->assertTrue(is_int(self::$object->get_id()));
}
}

View File

@@ -1,209 +0,0 @@
<?php
class Feed_XML_AtomTest extends PhraseanetPHPUnitAbstract
{
/**
*
* @var Feed_XML_Atom
*/
protected static $atom;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$atom = new Feed_XML_Atom();
}
public function testRender()
{
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
}
public function testSet_author_name()
{
self::$atom->set_author_name('boulbil');
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('boulbil', (string) $sxe->author->name);
self::$atom->set_author_name('boubi bouba');
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('boubi bouba', (string) $sxe->author->name);
}
public function testSet_author_email()
{
self::$atom->set_author_email('bouba@example.net');
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('bouba@example.net', (string) $sxe->author->email);
self::$atom->set_author_email('email+test@example.org');
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('email+test@example.org', (string) $sxe->author->email);
}
public function testSet_author_url()
{
self::$atom->set_author_url('http://example.net/');
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('http://example.net/', (string) $sxe->author->uri);
}
public function testSet_title()
{
$title = 'Un joli titre';
self::$atom->set_title($title);
self::$atom->set_title($title);
$xml = self::$atom->render();
$sxe = simplexml_load_string($xml);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('__empty_ns', $namespaces['']);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$obj = $sxe->xpath('/__empty_ns:feed/__empty_ns:title');
$this->assertEquals(1, count($obj));
$this->assertEquals($title, (string) $obj[0]);
}
public function testSet_updated_on()
{
$date_obj = new DateTime();
self::$atom->set_updated_on($date_obj);
$sxe = simplexml_load_string(self::$atom->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($date_obj->format(DATE_ATOM), (string) $sxe->updated);
}
public function testSet_subtitle()
{
$subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
self::$atom->set_subtitle($subtitle);
self::$atom->set_subtitle($subtitle);
$xml = self::$atom->render();
$sxe = simplexml_load_string($xml);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('__empty_ns', $namespaces['']);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$obj = $sxe->xpath('/__empty_ns:feed/__empty_ns:subtitle');
$this->assertEquals(1, count($obj));
$this->assertEquals($subtitle, (string) $obj[0]);
}
public function testSet_link()
{
$href = 'http://www.example.org/?page=24';
$current_page = new Feed_Link($href, 'example next page', 'application/atom+xml');
self::$atom->set_link($current_page);
self::$atom->set_link($current_page);
$xml = self::$atom->render();
$sxe = simplexml_load_string($xml);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('__empty_ns', $namespaces['']);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$obj = $sxe->xpath('/__empty_ns:feed/__empty_ns:link[@rel="self"]');
$this->assertEquals(1, count($obj));
$found = false;
foreach ($obj[0]->attributes() as $attr => $attr_value) {
if ($attr != 'href')
continue;
$found = true;
$this->assertEquals($href, (string) $attr_value);
}
if ( ! $found)
$this->fail();
}
public function testSet_next_page()
{
$href = 'http://www.example.org/?page=23';
$next_page = new Feed_Link($href, 'example next page', 'application/atom+xml');
self::$atom->set_next_page($next_page);
self::$atom->set_next_page($next_page);
$xml = self::$atom->render();
$sxe = simplexml_load_string($xml);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('__empty_ns', $namespaces['']);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$obj = $sxe->xpath('/__empty_ns:feed/__empty_ns:link[@rel="next"]');
$this->assertEquals(1, count($obj));
$found = false;
foreach ($obj[0]->attributes() as $attr => $attr_value) {
if ($attr != 'href')
continue;
$found = true;
$this->assertEquals($href, (string) $attr_value);
}
if ( ! $found)
$this->fail();
}
public function testSet_previous_page()
{
$href = 'http://www.example.org/?page=25';
$prev_page = new Feed_Link($href, 'example next page', 'application/atom+xml');
self::$atom->set_previous_page($prev_page);
self::$atom->set_previous_page($prev_page);
$xml = self::$atom->render();
$sxe = simplexml_load_string($xml);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('__empty_ns', $namespaces['']);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$obj = $sxe->xpath('/__empty_ns:feed/__empty_ns:link[@rel="previous"]');
$this->assertEquals(1, count($obj));
$found = false;
foreach ($obj[0]->attributes() as $attr => $attr_value) {
if ($attr != 'href')
continue;
$found = true;
$this->assertEquals($href, (string) $attr_value);
}
if ( ! $found)
$this->fail();
}
public function testSet_generator()
{
$generator = 'Arnold Schwarzenegger';
self::$atom->set_generator($generator);
self::$atom->set_generator($generator);
$xml = self::$atom->render();
$sxe = simplexml_load_string($xml);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('__empty_ns', $namespaces['']);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$obj = $sxe->xpath('/__empty_ns:feed/__empty_ns:generator');
$this->assertEquals(1, count($obj));
$this->assertEquals($generator, (string) $obj[0]);
}
public function testGet_mimetype()
{
$this->assertEquals('application/atom+xml', self::$atom->get_mimetype());
}
}

View File

@@ -1,189 +0,0 @@
<?php
class Feed_XML_RSSTest extends PhraseanetPHPUnitAbstract
{
/**
* @var Feed_XML_RSS
*/
protected static $rss;
public function setUp()
{
parent::setUp();
self::$rss = new Feed_XML_RSS();
}
public function testSet_language()
{
$language = 'fr-fr';
self::$rss->set_language($language);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($language, (string) $sxe->channel->language);
}
public function testSet_copyright()
{
$copyright = '2006-2014 No copyright';
self::$rss->set_copyright($copyright);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($copyright, (string) $sxe->channel->copyright);
}
public function testSet_managingEditor()
{
$email = 'manager@example.org';
self::$rss->set_managingEditor($email);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($email, (string) $sxe->channel->managingEditor);
}
public function testSet_webMaster()
{
$email = 'webmaster@example.org';
self::$rss->set_webMaster($email);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($email, (string) $sxe->channel->webMaster);
}
public function testSet_lastBuildDate()
{
$last_build = new DateTime('-2 hours');
self::$rss->set_lastBuildDate($last_build);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($last_build->format(DATE_RFC2822), (string) $sxe->channel->lastBuildDate);
}
public function testSet_category()
{
$categories = array('banana' => 'banana', 'prout' => 'prout');
foreach ($categories as $category) {
self::$rss->set_category($category);
}
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$cat_objs = $sxe->xpath('//channel/category');
$this->assertEquals(count($cat_objs), count($categories));
foreach ($cat_objs as $cat_obj) {
$str_cat = (string) $cat_obj;
$this->assertArrayHasKey($str_cat, $categories);
unset($categories[$str_cat]);
}
$this->assertTrue((count($categories) === 0));
}
public function testSet_docs()
{
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('http://blogs.law.harvard.edu/tech/rss', (string) $sxe->channel->docs);
self::$rss->set_docs('http://www.example.org');
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals('http://www.example.org', (string) $sxe->channel->docs);
}
public function testSet_ttl()
{
self::$rss->set_ttl(240);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals(240, (string) $sxe->channel->ttl);
}
public function testSet_image()
{
$link = 'http://www.example.org';
$title = 'Un beau titre';
$url = 'http://www.example.org/image.jpg';
$image = new Feed_XML_RSS_Image($url, $title, $link);
$width = 42;
$height = 30;
$description = 'KIKOO';
$image->set_width($width);
$image->set_height($height);
$image->set_description($description);
self::$rss->set_image($image);
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
$this->assertEquals($title, (string) $sxe->channel->image->title);
$this->assertEquals($link, (string) $sxe->channel->image->link);
$this->assertEquals($url, (string) $sxe->channel->image->url);
$this->assertEquals($height, (string) $sxe->channel->image->height);
$this->assertEquals($width, (string) $sxe->channel->image->width);
$this->assertEquals($description, (string) $sxe->channel->image->description);
}
public function testSet_skipHours()
{
$hours = array('4' => '4', '8' => '8', '12' => '12');
foreach ($hours as $hour) {
self::$rss->set_skipHour($hour);
}
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
foreach ($sxe->channel->skipHours->hour as $sx_hour) {
$sx_hour = (string) $sx_hour;
$this->assertArrayHasKey($sx_hour, $hours);
unset($hours[$sx_hour]);
}
$this->assertTrue(empty($hours));
}
public function testSet_skipDays()
{
$days = array('sunday' => 'sunday', 'saturday' => 'saturday', 'monday' => 'monday');
foreach ($days as $day) {
self::$rss->set_skipDays($day);
}
$xml = self::$rss->render();
$sxe = simplexml_load_string($xml);
$this->assertInstanceOf('SimpleXMLElement', $sxe);
foreach ($sxe->channel->skipDays->day as $sx_day) {
$sx_day = (string) $sx_day;
$this->assertArrayHasKey($sx_day, $days);
unset($days[$sx_day]);
}
$this->assertTrue(empty($days));
}
public function testRender()
{
$sxe = simplexml_load_string(self::$rss->render());
$this->assertInstanceOf('SimpleXMLElement', $sxe);
}
}

View File

@@ -1,81 +0,0 @@
<?php
class Feed_XML_RSS_ImageTest extends PhraseanetPHPUnitAbstract
{
/**
* @var Feed_XML_RSS_Image
*/
protected $object;
protected $url;
protected $title;
protected $link;
protected $description;
protected $width;
protected $height;
public function setUp()
{
parent::setUp();
$this->link = 'http://www.example.org';
$this->title = 'Un beau titre';
$this->url = 'http://www.example.org/image.jpg';
$this->width = 42;
$this->height = 30;
$this->description = 'KIKOO';
$this->object = new Feed_XML_RSS_Image($this->url, $this->title, $this->link);
$this->object->set_width($this->width);
$this->object->set_height($this->height);
$this->object->set_description($this->description);
}
public function testGet_url()
{
$this->assertEquals($this->url, $this->object->get_url());
}
public function testGet_title()
{
$this->assertEquals($this->title, $this->object->get_title());
}
public function testGet_link()
{
$this->assertEquals($this->link, $this->object->get_link());
}
public function testGet_description()
{
$this->assertEquals($this->description, $this->object->get_description());
}
public function testGet_height()
{
$this->assertEquals($this->height, $this->object->get_height());
}
public function testGet_width()
{
$this->assertEquals($this->width, $this->object->get_width());
}
public function testSet_description()
{
$new_desc = 'une nouvelle';
$this->object->set_description($new_desc);
$this->assertEquals($new_desc, $this->object->get_description());
}
public function testSet_height()
{
$new_height = 27;
$this->object->set_height($new_height);
$this->assertEquals($new_height, $this->object->get_height());
}
public function testSet_width()
{
$new_width = 14;
$this->object->set_width($new_width);
$this->assertEquals($new_width, $this->object->get_width());
}
}