first commit
This commit is contained in:
7
plugins/stRSSPlugin/lib/LICENSE
Normal file
7
plugins/stRSSPlugin/lib/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2004-2006 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
19
plugins/stRSSPlugin/lib/README
Normal file
19
plugins/stRSSPlugin/lib/README
Normal file
@@ -0,0 +1,19 @@
|
||||
= sfFeedPlugin plugin =
|
||||
|
||||
The `sfFeedPlugin` simplifies the creation of syndication feeds.
|
||||
|
||||
== Installation ==
|
||||
|
||||
* Install the plugin
|
||||
|
||||
{{{
|
||||
symfony plugin-install http://plugins.symfony-project.com/sfFeedPlugin
|
||||
}}}
|
||||
|
||||
* Clear you cache
|
||||
|
||||
{{{
|
||||
symfony cc
|
||||
}}}
|
||||
|
||||
* You're done.
|
||||
168
plugins/stRSSPlugin/lib/sfAtom1Feed.class.php
Normal file
168
plugins/stRSSPlugin/lib/sfAtom1Feed.class.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfAtom1Feed.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
class sfAtom1Feed extends sfFeed
|
||||
{
|
||||
public function getFeed()
|
||||
{
|
||||
header('Content-Type: application/atom+xml');
|
||||
|
||||
$xml = array();
|
||||
$xml[] = '<?xml version="1.0" encoding="'.$this->getEncoding().'" ?>';
|
||||
|
||||
if ($this->getLanguage())
|
||||
{
|
||||
$xml[] = sprintf('<feed xmlns="%s" xml:lang="%s">', 'http://www.w3.org/2005/Atom', $this->getLanguage());
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml[] = sprintf('<feed xmlns="%s">', 'http://www.w3.org/2005/Atom');
|
||||
}
|
||||
|
||||
$xml[] = ' <title>'.$this->getTitle().'</title>';
|
||||
$xml[] = ' <link rel="alternate" href="'.sfContext::getInstance()->getController()->genUrl($this->getLink(), true).'"></link>';
|
||||
if ($this->getFeedUrl())
|
||||
{
|
||||
$xml[] = ' <link rel="self" href="'.sfContext::getInstance()->getController()->genUrl($this->getFeedUrl(), true).'"></link>';
|
||||
}
|
||||
$xml[] = ' <id>'.sfContext::getInstance()->getController()->genUrl($this->getLink(), true).'</id>';
|
||||
$xml[] = ' <updated>'.strftime('%Y-%m-%dT%H:%M:%SZ', $this->getLatestPostDate()).'</updated>';
|
||||
|
||||
if ($this->getAuthorName())
|
||||
{
|
||||
$xml[] = ' <author>';
|
||||
$xml[] = ' <name>'.$this->getAuthorName().'</name>';
|
||||
if ($this->getAuthorEmail())
|
||||
{
|
||||
$xml[] = ' <author_email>'.$this->getAuthorEmail().'</author_email>';
|
||||
}
|
||||
if ($this->getAuthorLink())
|
||||
{
|
||||
$xml[] = ' <author_link>'.$this->getAuthorLink().'</author_link>';
|
||||
}
|
||||
$xml[] = ' </author>';
|
||||
}
|
||||
|
||||
if ($this->getSubtitle())
|
||||
{
|
||||
$xml[] = ' <subtitle>'.$this->getSubtitle().'</subtitle>';
|
||||
}
|
||||
|
||||
foreach ($this->getCategories() as $category)
|
||||
{
|
||||
$xml[] = ' <category term="'.$category.'"></category>';
|
||||
}
|
||||
|
||||
$xml[] = $this->getFeedElements();
|
||||
|
||||
$xml[] = '</feed>';
|
||||
|
||||
return implode("\n", $xml);
|
||||
}
|
||||
|
||||
private function getFeedElements()
|
||||
{
|
||||
$xml = array();
|
||||
|
||||
foreach ($this->getItems() as $item)
|
||||
{
|
||||
$xml[] = '<entry>';
|
||||
$xml[] = ' <title>'.htmlspecialchars($this->getItemFeedTitle($item)).'</title>';
|
||||
$xml[] = ' <link rel="alternate" href="'.sfContext::getInstance()->getController()->genUrl($this->getItemFeedLink($item), true).'"></link>';
|
||||
if ($this->getItemFeedPubdate($item))
|
||||
{
|
||||
$xml[] = ' <updated>'.strftime('%Y-%m-%dT%H:%M:%SZ', $this->getItemFeedPubdate($item)).'</updated>';
|
||||
}
|
||||
|
||||
// author information
|
||||
if ($this->getItemFeedAuthorName($item))
|
||||
{
|
||||
$xml[] = ' <author>';
|
||||
$xml[] = ' <name>'.$this->getItemFeedAuthorName($item).'</name>';
|
||||
if ($this->getItemFeedAuthorEmail($item))
|
||||
{
|
||||
$xml[] = ' <author_email>'.$this->getItemFeedAuthorEmail($item).'</author_email>';
|
||||
}
|
||||
if ($this->getItemFeedAuthorLink($item))
|
||||
{
|
||||
$xml[] = ' <author_link>'.sfContext::getInstance()->getController()->genUrl($this->getItemFeedAuthorLink($item), true).'</author_link>';
|
||||
}
|
||||
$xml[] = ' </author>';
|
||||
}
|
||||
|
||||
// unique id
|
||||
if ($this->getItemFeedUniqueId($item))
|
||||
{
|
||||
$uniqueId = $this->getItemFeedUniqueId($item);
|
||||
}
|
||||
else
|
||||
{
|
||||
$uniqueId = $this->getTagUri($this->getItemFeedLink($item), $this->getItemFeedPubdate($item));
|
||||
}
|
||||
$xml[] = ' <id>'.$uniqueId.'</id>';
|
||||
|
||||
// summary
|
||||
if ($this->getItemFeedDescription($item))
|
||||
{
|
||||
$xml[] = sprintf(' <summary type="html">%s</summary>', htmlspecialchars($this->getItemFeedDescription($item)));
|
||||
}
|
||||
|
||||
// enclosure
|
||||
if ((method_exists($item, 'getFeedEnclosure')) && ($enclosure = $item->getFeedEnclosure()))
|
||||
{
|
||||
$xml[] = sprintf(' <link rel="enclosure" href="%s" length="%s" type="%s"></link>', $enclosure->getUrl(), $enclosure->getLength(), $enclosure->getMimeType());
|
||||
}
|
||||
|
||||
// categories
|
||||
foreach ($this->getItemFeedCategories($item) as $category)
|
||||
{
|
||||
$xml[] = ' <category term="'.$category.'"></category>';
|
||||
}
|
||||
|
||||
$xml[] = '</entry>';
|
||||
}
|
||||
|
||||
return implode("\n", $xml);
|
||||
}
|
||||
|
||||
// Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id
|
||||
private function getTagUri($url, $date)
|
||||
{
|
||||
$tag = preg_replace('#^http\://#', '', $url);
|
||||
if ($date)
|
||||
{
|
||||
$tag = preg_replace('#/#', ','.strftime('%Y-%m-%d', $date).':/', $tag, 1);
|
||||
}
|
||||
$tag = preg_replace('/#/', '/', $tag);
|
||||
|
||||
return 'tag:'.$tag;
|
||||
}
|
||||
|
||||
private function getLatestPostDate()
|
||||
{
|
||||
$updates = array();
|
||||
foreach ($this->getItems() as $item)
|
||||
{
|
||||
if ($this->getItemFeedPubdate($item))
|
||||
{
|
||||
$updates[] = $this->getItemFeedPubdate($item);
|
||||
}
|
||||
}
|
||||
|
||||
if ($updates)
|
||||
{
|
||||
sort($updates);
|
||||
return $updates[count($updates) - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return time();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
480
plugins/stRSSPlugin/lib/sfFeed.class.php
Normal file
480
plugins/stRSSPlugin/lib/sfFeed.class.php
Normal file
@@ -0,0 +1,480 @@
|
||||
<?php
|
||||
/**
|
||||
* sfFeed.
|
||||
*
|
||||
* based on feedgenerator.py from django project
|
||||
*
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfFeed.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
class sfFeed
|
||||
{
|
||||
protected
|
||||
$items = array(),
|
||||
$title,
|
||||
$link,
|
||||
$description,
|
||||
$language = 'en',
|
||||
$authorEmail,
|
||||
$authorName,
|
||||
$authorLink,
|
||||
$subtitle,
|
||||
$categories = array(),
|
||||
$feedItemsRouteName = '',
|
||||
$feedUrl,
|
||||
$encoding = 'UTF-8';
|
||||
|
||||
private
|
||||
$context = null;
|
||||
|
||||
/**
|
||||
* Retrieve a new sfFeed implementation instance.
|
||||
*
|
||||
* @param string A sfFeed implementation name.
|
||||
*
|
||||
* @return sfFeed A sfFeed implementation instance.
|
||||
*
|
||||
* @throws sfFactoryException If a new syndication feed implementation instance cannot be created.
|
||||
*/
|
||||
public static function newInstance ($class)
|
||||
{
|
||||
try
|
||||
{
|
||||
$class = 'sf'.ucfirst($class).'Feed';
|
||||
|
||||
// the class exists
|
||||
$object = new $class();
|
||||
|
||||
if (!($object instanceof sfFeed))
|
||||
{
|
||||
// the class name is of the wrong type
|
||||
$error = 'Class "%s" is not of the type sfFeed';
|
||||
$error = sprintf($error, $class);
|
||||
|
||||
throw new sfFactoryException($error);
|
||||
}
|
||||
|
||||
$object->context = sfContext::getInstance();
|
||||
|
||||
return $object;
|
||||
}
|
||||
catch (sfException $e)
|
||||
{
|
||||
$e->printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public function addItem($item)
|
||||
{
|
||||
$this->items[] = $item;
|
||||
}
|
||||
|
||||
public function setItems($items)
|
||||
{
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
public function getItems()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
public function addItemFromArray($item_array)
|
||||
{
|
||||
$item = new sfFeedItem();
|
||||
|
||||
$item->setTitle(isset($item_array['title']) ? $item_array['title'] : '');
|
||||
$item->setLink(isset($item_array['link']) ? $item_array['link'] : '');
|
||||
$item->setDescription(isset($item_array['description']) ? $item_array['description'] : '');
|
||||
$item->setAuthorEmail(isset($item_array['authorEmail']) ? $item_array['authorEmail'] : '');
|
||||
$item->setAuthorName(isset($item_array['authorName']) ? $item_array['authorName'] : '');
|
||||
$item->setAuthorLink(isset($item_array['authorLink']) ? $item_array['authorLink'] : '');
|
||||
$item->setPubdate(isset($item_array['pubdate']) ? $item_array['pubdate'] : '');
|
||||
$item->setComments(isset($item_array['comments']) ? $item_array['comments'] : '');
|
||||
$item->setUniqueId(isset($item_array['uniqueId']) ? $item_array['uniqueId'] : '');
|
||||
$item->setEnclosure(isset($item_array['enclosure']) ? $item_array['enclosure'] : '');
|
||||
$item->setCategories(isset($item_array['categories']) ? $item_array['categories'] : '');
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
|
||||
public function getFeed()
|
||||
{
|
||||
throw new sfException('You must use newInstance to get a real feed.');
|
||||
}
|
||||
|
||||
public function setFeedItemsRouteName($routeName)
|
||||
{
|
||||
$this->feedItemsRouteName = $routeName;
|
||||
}
|
||||
|
||||
public function getFeedItemsRouteName()
|
||||
{
|
||||
return $this->feedItemsRouteName;
|
||||
}
|
||||
|
||||
public function setTitle ($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getTitle ()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setLink ($link)
|
||||
{
|
||||
$this->link = $link;
|
||||
}
|
||||
|
||||
public function getLink ()
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
public function setDescription ($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getDescription ()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setLanguage ($language)
|
||||
{
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
public function getLanguage ()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function setAuthorEmail ($authorEmail)
|
||||
{
|
||||
$this->authorEmail = $authorEmail;
|
||||
}
|
||||
|
||||
public function getAuthorEmail ()
|
||||
{
|
||||
return $this->authorEmail;
|
||||
}
|
||||
|
||||
public function setAuthorName ($authorName)
|
||||
{
|
||||
$this->authorName = $authorName;
|
||||
}
|
||||
|
||||
public function getAuthorName ()
|
||||
{
|
||||
return $this->authorName;
|
||||
}
|
||||
|
||||
public function setAuthorLink ($authorLink)
|
||||
{
|
||||
$this->authorLink = $authorLink;
|
||||
}
|
||||
|
||||
public function getAuthorLink ()
|
||||
{
|
||||
return $this->authorLink;
|
||||
}
|
||||
|
||||
public function setSubtitle ($subtitle)
|
||||
{
|
||||
$this->subtitle = $subtitle;
|
||||
}
|
||||
|
||||
public function getSubtitle ()
|
||||
{
|
||||
return $this->subtitle;
|
||||
}
|
||||
|
||||
public function setFeedUrl ($feedUrl)
|
||||
{
|
||||
$this->feedUrl = $feedUrl;
|
||||
}
|
||||
|
||||
public function getFeedUrl ()
|
||||
{
|
||||
return $this->feedUrl;
|
||||
}
|
||||
|
||||
public function setCategories ($categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
public function getCategories ()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
// item feed methods
|
||||
public function getItemFeedTitle ($item)
|
||||
{
|
||||
foreach (array('getFeedTitle', 'getTitle', 'getName', '__toString') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedDescription ($item)
|
||||
{
|
||||
foreach (array('getFeedDescription', 'getDescription', 'getBody') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedLink ($item)
|
||||
{
|
||||
if ($routeName = $this->getFeedItemsRouteName())
|
||||
{
|
||||
$routing = sfRouting::getInstance();
|
||||
$route = $routing->getRouteByName($routeName);
|
||||
|
||||
$url = $route[0];
|
||||
$defaults = $route[4];
|
||||
|
||||
// we get all parameters
|
||||
$params = array();
|
||||
if (preg_match_all('/\:([^\/]+)/', $url, $matches))
|
||||
{
|
||||
foreach ($matches[1] as $paramName)
|
||||
{
|
||||
$value = null;
|
||||
$name = ucfirst(sfInflector::camelize($paramName));
|
||||
|
||||
$found = false;
|
||||
foreach (array('getFeed'.$name, 'get'.$name) as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
$value = $item->$methodName();
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found)
|
||||
{
|
||||
if (array_key_exists($paramName, $defaults))
|
||||
{
|
||||
$value = $defaults[$paramName];
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = 'Cannot find a "getFeed%s()" or "get%s()" method for object "%s" to generate URL with the "%s" route';
|
||||
$error = sprintf($error, $name, $name, get_class($item), $routeName);
|
||||
throw new sfException($error);
|
||||
}
|
||||
}
|
||||
|
||||
$params[] = $paramName.'='.$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->context->getController()->genUrl($routeName.($params ? '?'.implode('&', $params) : ''), true);
|
||||
}
|
||||
|
||||
foreach (array('getFeedLink', 'getLink', 'getUrl') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $this->context->getController()->genUrl($item->$methodName(), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getLink())
|
||||
{
|
||||
return sfContext::getInstance()->getController()->genUrl($this->getLink(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->context->getController()->genUrl('/', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function getItemFeedUniqueId ($item)
|
||||
{
|
||||
foreach (array('getFeedUniqueId', 'getUniqueId', 'getId') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedAuthorEmail ($item)
|
||||
{
|
||||
foreach (array('getFeedAuthorEmail', 'getAuthorEmail') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
// author as an object link
|
||||
if ($author = $this->getItemFeedAuthor($item))
|
||||
{
|
||||
foreach (array('getEmail', 'getMail') as $methodName)
|
||||
{
|
||||
if (method_exists($author, $methodName))
|
||||
{
|
||||
return $author->$methodName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedAuthorName ($item)
|
||||
{
|
||||
foreach (array('getFeedAuthorName', 'getAuthorName') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
// author as an object link
|
||||
if ($author = $this->getItemFeedAuthor($item))
|
||||
{
|
||||
foreach (array('getName', '__toString') as $methodName)
|
||||
{
|
||||
if (method_exists($author, $methodName))
|
||||
{
|
||||
return $author->$methodName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedAuthorLink ($item)
|
||||
{
|
||||
foreach (array('getFeedAuthorLink', 'getAuthorLink') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
// author as an object link
|
||||
if ($author = $this->getItemFeedAuthor($item))
|
||||
{
|
||||
foreach (array('getLink') as $methodName)
|
||||
{
|
||||
if (method_exists($author, $methodName))
|
||||
{
|
||||
return $author->$methodName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedPubdate ($item)
|
||||
{
|
||||
foreach (array('getFeedPubdate', 'getPubdate', 'getCreatedAt', 'getDate') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName('U');
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedComments ($item)
|
||||
{
|
||||
foreach (array('getFeedComments', 'getComments') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getItemFeedCategories ($item)
|
||||
{
|
||||
foreach (array('getFeedCategories', 'getCategories') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName) && is_object($item->$methodName()))
|
||||
{
|
||||
// categories as an object
|
||||
$categories = $item->$methodName();
|
||||
if (is_array($categories))
|
||||
{
|
||||
$cats = array();
|
||||
foreach ($categories as $category)
|
||||
{
|
||||
$cats[] = (string) $category;
|
||||
}
|
||||
|
||||
return $cats;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
private function getItemFeedAuthor ($item)
|
||||
{
|
||||
foreach (array('getAuthor', 'getUser', 'getPerson') as $methodName)
|
||||
{
|
||||
if (method_exists($item, $methodName) && is_object($item->$methodName()))
|
||||
{
|
||||
return $item->$methodName();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
45
plugins/stRSSPlugin/lib/sfFeedEnclosure.class.php
Normal file
45
plugins/stRSSPlugin/lib/sfFeedEnclosure.class.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfFeedEnclosure.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
class sfFeedEnclosure
|
||||
{
|
||||
private
|
||||
$url,
|
||||
$length,
|
||||
$mimeType;
|
||||
|
||||
public function setUrl ($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function getUrl ()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setLength ($length)
|
||||
{
|
||||
$this->length = $length;
|
||||
}
|
||||
|
||||
public function getLength ()
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
|
||||
public function setMimeType ($mimeType)
|
||||
{
|
||||
$this->mimeType = $mimeType;
|
||||
}
|
||||
|
||||
public function getMimeType ()
|
||||
{
|
||||
return $this->mimeType;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
133
plugins/stRSSPlugin/lib/sfFeedItem.class.php
Normal file
133
plugins/stRSSPlugin/lib/sfFeedItem.class.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfFeedItem.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
class sfFeedItem
|
||||
{
|
||||
private
|
||||
$title,
|
||||
$link,
|
||||
$description,
|
||||
$authorEmail,
|
||||
$authorName,
|
||||
$authorLink,
|
||||
$pubdate,
|
||||
$comments,
|
||||
$uniqueId,
|
||||
$enclosure,
|
||||
$categories = array();
|
||||
|
||||
public function setTitle ($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getTitle ()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setLink ($link)
|
||||
{
|
||||
$this->link = $link;
|
||||
}
|
||||
|
||||
public function getLink ()
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
public function setDescription ($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getDescription ()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setAuthorEmail ($authorEmail)
|
||||
{
|
||||
$this->authorEmail = $authorEmail;
|
||||
}
|
||||
|
||||
public function getAuthorEmail ()
|
||||
{
|
||||
return $this->authorEmail;
|
||||
}
|
||||
|
||||
public function setAuthorName ($authorName)
|
||||
{
|
||||
$this->authorName = $authorName;
|
||||
}
|
||||
|
||||
public function getAuthorName ()
|
||||
{
|
||||
return $this->authorName;
|
||||
}
|
||||
|
||||
public function setAuthorLink ($authorLink)
|
||||
{
|
||||
$this->authorLink = $authorLink;
|
||||
}
|
||||
|
||||
public function getAuthorLink ()
|
||||
{
|
||||
return $this->authorLink;
|
||||
}
|
||||
|
||||
public function setPubdate ($pubdate)
|
||||
{
|
||||
$this->pubdate = $pubdate;
|
||||
}
|
||||
|
||||
public function getPubdate ()
|
||||
{
|
||||
return $this->pubdate;
|
||||
}
|
||||
|
||||
public function setComments ($comments)
|
||||
{
|
||||
$this->comments = $comments;
|
||||
}
|
||||
|
||||
public function getComments ()
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function setUniqueId ($uniqueId)
|
||||
{
|
||||
$this->uniqueId = $uniqueId;
|
||||
}
|
||||
|
||||
public function getUniqueId ()
|
||||
{
|
||||
return $this->uniqueId;
|
||||
}
|
||||
|
||||
public function setEnclosure ($enclosure)
|
||||
{
|
||||
$this->enclosure = $enclosure;
|
||||
}
|
||||
|
||||
public function getEnclosure ()
|
||||
{
|
||||
return $this->enclosure;
|
||||
}
|
||||
|
||||
public function setCategories ($categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
public function getCategories ()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
65
plugins/stRSSPlugin/lib/sfRss201rev2Feed.class.php
Normal file
65
plugins/stRSSPlugin/lib/sfRss201rev2Feed.class.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfRss201rev2Feed.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
class sfRss201rev2Feed extends sfRssFeed
|
||||
{
|
||||
protected function getFeedElements()
|
||||
{
|
||||
$xml = array();
|
||||
foreach ($this->getItems() as $item)
|
||||
{
|
||||
$xml[] = '<item>';
|
||||
$xml[] = ' <title>'.htmlspecialchars($this->getItemFeedTitle($item)).'</title>';
|
||||
if ($this->getItemFeedDescription($item))
|
||||
{
|
||||
$xml[] = ' <description>'.htmlspecialchars($this->getItemFeedDescription($item)).'</description>';
|
||||
}
|
||||
$xml[] = ' <link>'.$this->getItemFeedLink($item).'</link>';
|
||||
if ($this->getItemFeedUniqueId($item))
|
||||
{
|
||||
$xml[] = ' <guid isPermalink="false">'.$this->getItemFeedUniqueId($item).'</guid>';
|
||||
}
|
||||
|
||||
// author information
|
||||
if ($this->getItemFeedAuthorEmail($item) && $this->getItemFeedAuthorName($item))
|
||||
{
|
||||
$xml[] = sprintf(' <author>%s (%s)</author>', $this->getItemFeedAuthorEmail($item), $this->getItemFeedAuthorName($item));
|
||||
}
|
||||
if ($this->getItemFeedPubdate($item))
|
||||
{
|
||||
$xml[] = ' <pubDate>'.date('r', $this->getItemFeedPubdate($item)).'</pubDate>';
|
||||
}
|
||||
if ($this->getItemFeedComments($item))
|
||||
{
|
||||
$xml[] = ' <comments>'.htmlspecialchars($this->getItemFeedComments($item)).'</comments>';
|
||||
}
|
||||
|
||||
// enclosure
|
||||
if ((method_exists($item, 'getFeedEnclosure')) && ($enclosure = $item->getFeedEnclosure()))
|
||||
{
|
||||
$enclosure_attributes = sprintf('url="%s" length="%s" type="%s"', $enclosure->getUrl(), $enclosure->getLength(), $enclosure->getMimeType());
|
||||
$xml[] = ' <enclosure '.$enclosure_attributes.'></enclosure>';
|
||||
}
|
||||
|
||||
// categories
|
||||
foreach ($this->getItemFeedCategories($item) as $category)
|
||||
{
|
||||
$xml[] = ' <category>'.$category.'</category>';
|
||||
}
|
||||
|
||||
$xml[] = '</item>';
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
protected function getVersion()
|
||||
{
|
||||
return '2.0';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
36
plugins/stRSSPlugin/lib/sfRssFeed.class.php
Normal file
36
plugins/stRSSPlugin/lib/sfRssFeed.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfRssFeed.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
abstract class sfRssFeed extends sfFeed
|
||||
{
|
||||
public function getFeed()
|
||||
{
|
||||
$this->getContext()->getResponse()->setContentType('application/rss+xml');
|
||||
|
||||
$xml = array();
|
||||
$xml[] = '<?xml version="1.0" encoding="'.$this->getEncoding().'" ?>';
|
||||
$xml[] = '<rss version="'.$this->getVersion().'">';
|
||||
$xml[] = ' <channel>';
|
||||
$xml[] = ' <title>'.$this->getTitle().'</title>';
|
||||
$xml[] = ' <link>'.sfContext::getInstance()->getController()->genUrl($this->getLink(), true).'</link>';
|
||||
$xml[] = ' <description>'.$this->getDescription().'</description>';
|
||||
if ($this->getLanguage())
|
||||
{
|
||||
$xml[] = ' <language>'.$this->getLanguage().'</language>';
|
||||
}
|
||||
$xml[] = implode("\n", $this->getFeedElements());
|
||||
$xml[] = ' </channel>';
|
||||
$xml[] = '</rss>';
|
||||
|
||||
return implode("\n", $xml);
|
||||
}
|
||||
|
||||
abstract protected function getFeedElements();
|
||||
|
||||
abstract protected function getVersion();
|
||||
}
|
||||
|
||||
?>
|
||||
33
plugins/stRSSPlugin/lib/sfRssUserland091Feed.class.php
Normal file
33
plugins/stRSSPlugin/lib/sfRssUserland091Feed.class.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @package stRSSPlugin
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfRssUserland091Feed.class.php 2092 2008-11-18 19:28:41Z michal $
|
||||
*/
|
||||
class sfRssUserland091Feed extends sfRssFeed
|
||||
{
|
||||
protected function getFeedElements()
|
||||
{
|
||||
$xml = array();
|
||||
foreach ($this->getItems() as $item)
|
||||
{
|
||||
$xml[] = '<item>';
|
||||
$xml[] = ' <title>'.htmlspecialchars($this->getItemFeedTitle($item)).'</title>';
|
||||
if ($this->getItemFeedDescription($item))
|
||||
{
|
||||
$xml[] = ' <description>'.htmlspecialchars($this->getItemFeedDescription($item)).'</description>';
|
||||
}
|
||||
$xml[] = ' <link>'.$this->getItemFeedLink($item).'</link>';
|
||||
$xml[] = '</item>';
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
protected function getVersion()
|
||||
{
|
||||
return '0.91';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user