first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,262 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Class to encapsulate a feed entry for the Joomla Platform.
*
* @property JFeedPerson $author Person responsible for feed entry content.
* @property array $categories Categories to which the feed entry belongs.
* @property string $content The content of the feed entry.
* @property array $contributors People who contributed to the feed entry content.
* @property string $copyright Information about rights, e.g. copyrights, held in and over the feed entry.
* @property array $links Links associated with the feed entry.
* @property JDate $publishedDate The publication date for the feed entry.
* @property JFeed $source The feed from which the entry is sourced.
* @property string $title A human readable title for the feed entry.
* @property JDate $updatedDate The last time the content of the feed entry changed.
* @property string $uri Universal, permanent identifier for the feed entry.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
class JFeedEntry
{
/**
* @var array The entry properties.
* @since 12.3
*/
protected $properties = array(
'uri' => '',
'title' => '',
'updatedDate' => '',
'content' => '',
'categories' => array(),
'contributors' => array(),
'links' => array()
);
/**
* Magic method to return values for feed entry properties.
*
* @param string $name The name of the property.
*
* @return mixed
*
* @since 12.3
*/
public function __get($name)
{
return (isset($this->properties[$name])) ? $this->properties[$name] : null;
}
/**
* Magic method to set values for feed properties.
*
* @param string $name The name of the property.
* @param mixed $value The value to set for the property.
*
* @return void
*
* @since 12.3
*/
public function __set($name, $value)
{
// Ensure that setting a date always sets a JDate instance.
if ((($name == 'updatedDate') || ($name == 'publishedDate')) && !($value instanceof JDate))
{
$value = new JDate($value);
}
// Validate that any authors that are set are instances of JFeedPerson or null.
if (($name == 'author') && (!($value instanceof JFeedPerson) || ($value === null)))
{
throw new InvalidArgumentException('JFeedEntry "author" must be of type JFeedPerson. ' . gettype($value) . 'given.');
}
// Validate that any sources that are set are instances of JFeed or null.
if (($name == 'source') && (!($value instanceof JFeed) || ($value === null)))
{
throw new InvalidArgumentException('JFeedEntry "source" must be of type JFeed. ' . gettype($value) . 'given.');
}
// Disallow setting categories, contributors, or links directly.
if (($name == 'categories') || ($name == 'contributors') || ($name == 'links'))
{
throw new InvalidArgumentException('Cannot directly set JFeedEntry property "' . $name . '".');
}
$this->properties[$name] = $value;
}
/**
* Method to add a category to the feed entry object.
*
* @param string $name The name of the category to add.
* @param string $uri The optional URI for the category to add.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function addCategory($name, $uri = '')
{
$this->properties['categories'][$name] = $uri;
return $this;
}
/**
* Method to add a contributor to the feed entry object.
*
* @param string $name The full name of the person to add.
* @param string $email The email address of the person to add.
* @param string $uri The optional URI for the person to add.
* @param string $type The optional type of person to add.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function addContributor($name, $email, $uri = null, $type = null)
{
$contributor = new JFeedPerson($name, $email, $uri, $type);
// If the new contributor already exists then there is nothing to do, so just return.
foreach ($this->properties['contributors'] as $c)
{
if ($c == $contributor)
{
return $this;
}
}
// Add the new contributor.
$this->properties['contributors'][] = $contributor;
return $this;
}
/**
* Method to add a link to the feed entry object.
*
* @param JFeedLink $link The link object to add.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function addLink(JFeedLink $link)
{
// If the new link already exists then there is nothing to do, so just return.
foreach ($this->properties['links'] as $l)
{
if ($l == $link)
{
return $this;
}
}
// Add the new link.
$this->properties['links'][] = $link;
return $this;
}
/**
* Method to remove a category from the feed entry object.
*
* @param string $name The name of the category to remove.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function removeCategory($name)
{
unset($this->properties['categories'][$name]);
return $this;
}
/**
* Method to remove a contributor from the feed entry object.
*
* @param JFeedPerson $contributor The person object to remove.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function removeContributor(JFeedPerson $contributor)
{
// If the contributor exists remove it.
foreach ($this->properties['contributors'] as $k => $c)
{
if ($c == $contributor)
{
unset($this->properties['contributors'][$k]);
$this->properties['contributors'] = array_values($this->properties['contributors']);
return $this;
}
}
return $this;
}
/**
* Method to remove a link from the feed entry object.
*
* @param JFeedLink $link The link object to remove.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function removeLink(JFeedLink $link)
{
// If the link exists remove it.
foreach ($this->properties['links'] as $k => $l)
{
if ($l == $link)
{
unset($this->properties['links'][$k]);
$this->properties['links'] = array_values($this->properties['links']);
return $this;
}
}
return $this;
}
/**
* Shortcut method to set the author for the feed entry object.
*
* @param string $name The full name of the person to set.
* @param string $email The email address of the person to set.
* @param string $uri The optional URI for the person to set.
* @param string $type The optional type of person to set.
*
* @return JFeedEntry
*
* @since 12.3
*/
public function setAuthor($name, $email, $uri = null, $type = null)
{
$author = new JFeedPerson($name, $email, $uri, $type);
$this->properties['author'] = $author;
return $this;
}
}

View File

@ -0,0 +1,125 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Feed factory class.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
class JFeedFactory
{
/**
* @var array The list of registered parser classes for feeds.
* @since 12.3
*/
protected $parsers = array('rss' => 'JFeedParserRss', 'feed' => 'JFeedParserAtom');
/**
* Method to load a URI into the feed reader for parsing.
*
* @param string $uri The URI of the feed to load. Idn uris must be passed already converted to punycode.
*
* @return JFeedReader
*
* @since 12.3
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function getFeed($uri)
{
// Create the XMLReader object.
$reader = new XMLReader;
// Open the URI within the stream reader.
if (!$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING))
{
throw new RuntimeException('Unable to open the feed.');
}
try
{
// Skip ahead to the root node.
do
{
$reader->read();
}
while ($reader->nodeType !== XMLReader::ELEMENT);
}
catch (Exception $e)
{
throw new RuntimeException('Error reading feed.');
}
// Setup the appopriate feed parser for the feed.
$parser = $this->_fetchFeedParser($reader->name, $reader);
return $parser->parse();
}
/**
* Method to register a JFeedParser class for a given root tag name.
*
* @param string $tagName The root tag name for which to register the parser class.
* @param string $className The JFeedParser class name to register for a root tag name.
* @param boolean $overwrite True to overwrite the parser class if one is already registered.
*
* @return JFeedFactory
*
* @since 12.3
* @throws InvalidArgumentException
*/
public function registerParser($tagName, $className, $overwrite = false)
{
// Verify that the class exists.
if (!class_exists($className))
{
throw new InvalidArgumentException('The feed parser class ' . $className . ' does not exist.');
}
// Validate that the tag name is valid.
if (!preg_match('/\A(?!XML)[a-z][\w0-9-]*/i', $tagName))
{
throw new InvalidArgumentException('The tag name ' . $tagName . ' is not valid.');
}
// Register the given parser class for the tag name if nothing registered or the overwrite flag set.
if (empty($this->parsers[$tagName]) || (bool) $overwrite)
{
$this->parsers[(string) $tagName] = (string) $className;
}
return $this;
}
/**
* Method to return a new JFeedParser object based on the registered parsers and a given type.
*
* @param string $type The name of parser to return.
* @param XMLReader $reader The XMLReader instance for the feed.
*
* @return JFeedParser
*
* @since 12.3
* @throws LogicException
*/
private function _fetchFeedParser($type, XMLReader $reader)
{
// Look for a registered parser for the feed type.
if (empty($this->parsers[$type]))
{
throw new LogicException('No registered feed parser for type ' . $type . '.');
}
return new $this->parsers[$type]($reader);
}
}

View File

@ -0,0 +1,330 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die();
/**
* Class to encapsulate a feed for the Joomla Platform.
*
* @property JFeedPerson $author Person responsible for feed content.
* @property array $categories Categories to which the feed belongs.
* @property array $contributors People who contributed to the feed content.
* @property string $copyright Information about rights, e.g. copyrights, held in and over the feed.
* @property string $description A phrase or sentence describing the feed.
* @property string $generator A string indicating the program used to generate the feed.
* @property string $image Specifies a GIF, JPEG or PNG image that should be displayed with the feed.
* @property JDate $publishedDate The publication date for the feed content.
* @property string $title A human readable title for the feed.
* @property JDate $updatedDate The last time the content of the feed changed.
* @property string $uri Universal, permanent identifier for the feed.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
class JFeed implements ArrayAccess
{
/**
* @var array The entry properties.
* @since 12.3
*/
protected $properties = array(
'uri' => '',
'title' => '',
'updatedDate' => '',
'description' => '',
'categories' => array(),
'contributors' => array()
);
/**
* @var array The list of feed entry objects.
* @since 12.3
*/
protected $entries = array();
/**
* Magic method to return values for feed properties.
*
* @param string $name The name of the property.
*
* @return mixed
*
* @since 12.3
*/
public function __get($name)
{
return isset($this->properties[$name]) ? $this->properties[$name] : null;
}
/**
* Magic method to set values for feed properties.
*
* @param string $name The name of the property.
* @param mixed $value The value to set for the property.
*
* @return void
*
* @since 12.3
*/
public function __set($name, $value)
{
// Ensure that setting a date always sets a JDate instance.
if ((($name == 'updatedDate') || ($name == 'publishedDate')) && !($value instanceof JDate))
{
$value = new JDate($value);
}
// Validate that any authors that are set are instances of JFeedPerson or null.
if (($name == 'author') && (!($value instanceof JFeedPerson) || ($value === null)))
{
throw new InvalidArgumentException('JFeed "author" must be of type JFeedPerson. ' . gettype($value) . 'given.');
}
// Disallow setting categories or contributors directly.
if (($name == 'categories') || ($name == 'contributors'))
{
throw new InvalidArgumentException('Cannot directly set JFeed property "' . $name . '".');
}
$this->properties[$name] = $value;
}
/**
* Method to add a category to the feed object.
*
* @param string $name The name of the category to add.
* @param string $uri The optional URI for the category to add.
*
* @return JFeed
*
* @since 12.3
*/
public function addCategory($name, $uri = '')
{
$this->properties['categories'][$name] = $uri;
return $this;
}
/**
* Method to add a contributor to the feed object.
*
* @param string $name The full name of the person to add.
* @param string $email The email address of the person to add.
* @param string $uri The optional URI for the person to add.
* @param string $type The optional type of person to add.
*
* @return JFeed
*
* @since 12.3
*/
public function addContributor($name, $email, $uri = null, $type = null)
{
$contributor = new JFeedPerson($name, $email, $uri, $type);
// If the new contributor already exists then there is nothing to do, so just return.
foreach ($this->properties['contributors'] as $c)
{
if ($c == $contributor)
{
return $this;
}
}
// Add the new contributor.
$this->properties['contributors'][] = $contributor;
return $this;
}
/**
* Method to add an entry to the feed object.
*
* @param JFeedEntry $entry The entry object to add.
*
* @return JFeed
*
* @since 12.3
*/
public function addEntry(JFeedEntry $entry)
{
// If the new entry already exists then there is nothing to do, so just return.
foreach ($this->entries as $e)
{
if ($e == $entry)
{
return $this;
}
}
// Add the new entry.
$this->entries[] = $entry;
return $this;
}
/**
* Whether or not an offset exists. This method is executed when using isset() or empty() on
* objects implementing ArrayAccess.
*
* @param mixed $offset An offset to check for.
*
* @return boolean
*
* @see ArrayAccess::offsetExists()
* @since 12.3
*/
public function offsetExists($offset)
{
return isset($this->entries[$offset]);
}
/**
* Returns the value at specified offset.
*
* @param mixed $offset The offset to retrieve.
*
* @return mixed The value at the offset.
*
* @see ArrayAccess::offsetGet()
* @since 12.3
*/
public function offsetGet($offset)
{
return $this->entries[$offset];
}
/**
* Assigns a value to the specified offset.
*
* @param mixed $offset The offset to assign the value to.
* @param JFeedEntry $value The JFeedEntry to set.
*
* @return boolean
*
* @see ArrayAccess::offsetSet()
* @since 12.3
*/
public function offsetSet($offset, $value)
{
if (!($value instanceof JFeedEntry))
{
throw new InvalidArgumentException('Cannot set value of type "' . gettype($value) . '".');
}
$this->entries[$offset] = $value;
return true;
}
/**
* Unsets an offset.
*
* @param mixed $offset The offset to unset.
*
* @return void
*
* @see ArrayAccess::offsetUnset()
* @since 12.3
*/
public function offsetUnset($offset)
{
unset($this->entries[$offset]);
}
/**
* Method to remove a category from the feed object.
*
* @param string $name The name of the category to remove.
*
* @return JFeed
*
* @since 12.3
*/
public function removeCategory($name)
{
unset($this->properties['categories'][$name]);
return $this;
}
/**
* Method to remove a contributor from the feed object.
*
* @param JFeedPerson $contributor The person object to remove.
*
* @return JFeed
*
* @since 12.3
*/
public function removeContributor(JFeedPerson $contributor)
{
// If the contributor exists remove it.
foreach ($this->properties['contributors'] as $k => $c)
{
if ($c == $contributor)
{
unset($this->properties['contributors'][$k]);
$this->properties['contributors'] = array_values($this->properties['contributors']);
return $this;
}
}
return $this;
}
/**
* Method to remove an entry from the feed object.
*
* @param JFeedEntry $entry The entry object to remove.
*
* @return JFeed
*
* @since 12.3
*/
public function removeEntry(JFeedEntry $entry)
{
// If the entry exists remove it.
foreach ($this->entries as $k => $e)
{
if ($e == $entry)
{
unset($this->entries[$k]);
$this->entries = array_values($this->entries);
return $this;
}
}
return $this;
}
/**
* Shortcut method to set the author for the feed object.
*
* @param string $name The full name of the person to set.
* @param string $email The email address of the person to set.
* @param string $uri The optional URI for the person to set.
* @param string $type The optional type of person to set.
*
* @return JFeed
*
* @since 12.3
*/
public function setAuthor($name, $email, $uri = null, $type = null)
{
$author = new JFeedPerson($name, $email, $uri, $type);
$this->properties['author'] = $author;
return $this;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,84 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Feed Link class.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
class JFeedLink
{
/**
* @var string
* @since 12.3
*/
public $uri;
/**
* @var string
* @since 12.3
*/
public $relation;
/**
* @var string
* @since 12.3
*/
public $type;
/**
* @var string
* @since 12.3
*/
public $language;
/**
* @var string
* @since 12.3
*/
public $title;
/**
* @var integer
* @since 12.3
*/
public $length;
/**
* Constructor.
*
* @param string $uri The URI to the linked resource.
* @param string $relation The relationship between the feed and the linked resource.
* @param string $type The resource type.
* @param string $language The language of the resource found at the given URI.
* @param string $title The title of the resource.
* @param integer $length The length of the resource in bytes.
*
* @since 12.3
*/
public function __construct($uri = null, $relation = null, $type = null, $language = null, $title = null, $length = null)
{
$this->uri = $uri;
$this->relation = $relation;
$this->type = $type;
$this->language = $language;
$this->title = $title;
// Validate the length input.
if (isset($length) && !is_numeric($length))
{
throw new InvalidArgumentException('Length must be numeric.');
}
$this->length = (int) $length;
}
}

View File

@ -0,0 +1,277 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Feed Parser class.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
abstract class JFeedParser
{
/**
* @var string The feed element name for the entry elements.
* @since 12.3
*/
protected $entryElementName = 'entry';
/**
* @var array
* @since 12.3
*/
protected $namespaces = array();
/**
* @var XMLReader
* @since 12.3
*/
protected $stream;
/**
* Constructor.
*
* @param XMLReader $stream The XMLReader stream object for the feed.
*
* @since 12.3
*/
public function __construct(XMLReader $stream)
{
$this->stream = $stream;
}
/**
* Method to parse the feed into a JFeed object.
*
* @return JFeed
*
* @since 12.3
*/
public function parse()
{
$feed = new JFeed;
// Detect the feed version.
$this->initialise();
// Let's get this party started...
do
{
// Expand the element for processing.
$el = new SimpleXMLElement($this->stream->readOuterXml());
// Get the list of namespaces used within this element.
$ns = $el->getNamespaces(true);
// Get an array of available namespace objects for the element.
$namespaces = array();
foreach ($ns as $prefix => $uri)
{
// Ignore the empty namespace prefix.
if (empty($prefix))
{
continue;
}
// Get the necessary namespace objects for the element.
$namespace = $this->fetchNamespace($prefix);
if ($namespace)
{
$namespaces[] = $namespace;
}
}
// Process the element.
$this->processElement($feed, $el, $namespaces);
// Skip over this element's children since it has been processed.
$this->moveToClosingElement();
}
while ($this->moveToNextElement());
return $feed;
}
/**
* Method to register a namespace handler object.
*
* @param string $prefix The XML namespace prefix for which to register the namespace object.
* @param JFeedParserNamespace $namespace The namespace object to register.
*
* @return JFeed
*
* @since 12.3
*/
public function registerNamespace($prefix, JFeedParserNamespace $namespace)
{
$this->namespaces[$prefix] = $namespace;
return $this;
}
/**
* Method to initialise the feed for parsing. If child parsers need to detect versions or other
* such things this is where you'll want to implement that logic.
*
* @return void
*
* @since 12.3
*/
abstract protected function initialise();
/**
* Method to parse a specific feed element.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
* @param array $namespaces The array of relevant namespace objects to process for the element.
*
* @return void
*
* @since 12.3
*/
protected function processElement(JFeed $feed, SimpleXMLElement $el, array $namespaces)
{
// Build the internal method name.
$method = 'handle' . ucfirst($el->getName());
// If we are dealing with an item then it is feed entry time.
if ($el->getName() == $this->entryElementName)
{
// Create a new feed entry for the item.
$entry = new JFeedEntry;
// First call the internal method.
$this->processFeedEntry($entry, $el);
foreach ($namespaces as $namespace)
{
if ($namespace instanceof JFeedParserNamespace)
{
$namespace->processElementForFeedEntry($entry, $el);
}
}
// Add the new entry to the feed.
$feed->addEntry($entry);
}
// Otherwise we treat it like any other element.
else
{
// First call the internal method.
if (is_callable(array($this, $method)))
{
$this->$method($feed, $el);
}
foreach ($namespaces as $namespace)
{
if ($namespace instanceof JFeedParserNamespace)
{
$namespace->processElementForFeed($feed, $el);
}
}
}
}
/**
* Method to get a namespace object for a given namespace prefix.
*
* @param string $prefix The XML prefix for which to fetch the namespace object.
*
* @return mixed JFeedParserNamespace or false if none exists.
*
* @since 12.3
*/
protected function fetchNamespace($prefix)
{
if (isset($this->namespaces[$prefix]))
{
return $this->namespaces[$prefix];
}
$className = get_class($this) . ucfirst($prefix);
if (class_exists($className))
{
$this->namespaces[$prefix] = new $className;
return $this->namespaces[$prefix];
}
return false;
}
/**
* Method to move the stream parser to the next XML element node.
*
* @param string $name The name of the element for which to move the stream forward until is found.
*
* @return boolean True if the stream parser is on an XML element node.
*
* @since 12.3
*/
protected function moveToNextElement($name = null)
{
// Only keep looking until the end of the stream.
while ($this->stream->read())
{
// As soon as we get to the next ELEMENT node we are done.
if ($this->stream->nodeType == XMLReader::ELEMENT)
{
// If we are looking for a specific name make sure we have it.
if (isset($name) && ($this->stream->name != $name))
{
continue;
}
return true;
}
}
return false;
}
/**
* Method to move the stream parser to the closing XML node of the current element.
*
* @return void
*
* @since 12.3
* @throws RuntimeException If the closing tag cannot be found.
*/
protected function moveToClosingElement()
{
// If we are on a self-closing tag then there is nothing to do.
if ($this->stream->isEmptyElement)
{
return;
}
// Get the name and depth for the current node so that we can match the closing node.
$name = $this->stream->name;
$depth = $this->stream->depth;
// Only keep looking until the end of the stream.
while ($this->stream->read())
{
// If we have an END_ELEMENT node with the same name and depth as the node we started with we have a bingo. :-)
if (($this->stream->name == $name) && ($this->stream->depth == $depth) && ($this->stream->nodeType == XMLReader::END_ELEMENT))
{
return;
}
}
throw new RuntimeException('Unable to find the closing XML node.');
}
}

View File

@ -0,0 +1,206 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* ATOM Feed Parser class.
*
* @package Joomla.Platform
* @subpackage Feed
* @link http://www.atomenabled.org/developers/syndication/
* @since 12.3
*/
class JFeedParserAtom extends JFeedParser
{
/**
* @var string The feed format version.
* @since 12.3
*/
protected $version;
/**
* Method to handle the <author> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleAuthor(JFeed $feed, SimpleXMLElement $el)
{
// Set the author information from the XML element.
$feed->setAuthor((string) $el->name, (string) $el->email, (string) $el->uri);
}
/**
* Method to handle the <contributor> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleContributor(JFeed $feed, SimpleXMLElement $el)
{
$feed->addContributor((string) $el->name, (string) $el->email, (string) $el->uri);
}
/**
* Method to handle the <generator> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleGenerator(JFeed $feed, SimpleXMLElement $el)
{
$feed->generator = (string) $el;
}
/**
* Method to handle the <id> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleId(JFeed $feed, SimpleXMLElement $el)
{
$feed->uri = (string) $el;
}
/**
* Method to handle the <link> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleLink(JFeed $feed, SimpleXMLElement $el)
{
$link = new JFeedLink;
$link->uri = (string) $el['href'];
$link->language = (string) $el['hreflang'];
$link->length = (int) $el['length'];
$link->relation = (string) $el['rel'];
$link->title = (string) $el['title'];
$link->type = (string) $el['type'];
$feed->link = $link;
}
/**
* Method to handle the <rights> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleRights(JFeed $feed, SimpleXMLElement $el)
{
$feed->copyright = (string) $el;
}
/**
* Method to handle the <subtitle> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleSubtitle(JFeed $feed, SimpleXMLElement $el)
{
$feed->description = (string) $el;
}
/**
* Method to handle the <title> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleTitle(JFeed $feed, SimpleXMLElement $el)
{
$feed->title = (string) $el;
}
/**
* Method to handle the <updated> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleUpdated(JFeed $feed, SimpleXMLElement $el)
{
$feed->updatedDate = (string) $el;
}
/**
* Method to initialise the feed for parsing. Here we detect the version and advance the stream
* reader so that it is ready to parse feed elements.
*
* @return void
*
* @since 12.3
*/
protected function initialise()
{
// Read the version attribute.
$this->version = ($this->stream->getAttribute('version') == '0.3') ? '0.3' : '1.0';
// We want to move forward to the first element after the root element.
$this->moveToNextElement();
}
/**
* Method to handle the feed entry element for the feed: <entry>.
*
* @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function processFeedEntry(JFeedEntry $entry, SimpleXMLElement $el)
{
$entry->uri = (string) $el->id;
$entry->title = (string) $el->title;
$entry->updatedDate = (string) $el->updated;
$entry->content = (string) $el->summary;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,44 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Feed Namespace interface.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
interface JFeedParserNamespace
{
/**
* Method to handle an element for the feed given that a certain namespace is present.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
public function processElementForFeed(JFeed $feed, SimpleXMLElement $el);
/**
* Method to handle the feed entry element for the feed given that a certain namespace is present.
*
* @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
public function processElementForFeedEntry(JFeedEntry $entry, SimpleXMLElement $el);
}

View File

@ -0,0 +1,426 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* RSS Feed Parser class.
*
* @package Joomla.Platform
* @subpackage Feed
* @link http://cyber.law.harvard.edu/rss/rss.html
* @since 12.3
*/
class JFeedParserRss extends JFeedParser
{
/**
* @var string The feed element name for the entry elements.
* @since 12.3
*/
protected $entryElementName = 'item';
/**
* @var string The feed format version.
* @since 12.3
*/
protected $version;
/**
* Method to handle the <category> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleCategory(JFeed $feed, SimpleXMLElement $el)
{
// Get the data from the element.
$domain = (string) $el['domain'];
$category = (string) $el;
$feed->addCategory($category, $domain);
}
/**
* Method to handle the <cloud> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleCloud(JFeed $feed, SimpleXMLElement $el)
{
$cloud = new stdClass;
$cloud->domain = (string) $el['domain'];
$cloud->port = (string) $el['port'];
$cloud->path = (string) $el['path'];
$cloud->protocol = (string) $el['protocol'];
$cloud->registerProcedure = (string) $el['registerProcedure'];
$feed->cloud = $cloud;
}
/**
* Method to handle the <copyright> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleCopyright(JFeed $feed, SimpleXMLElement $el)
{
$feed->copyright = (string) $el;
}
/**
* Method to handle the <description> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleDescription(JFeed $feed, SimpleXMLElement $el)
{
$feed->description = (string) $el;
}
/**
* Method to handle the <generator> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleGenerator(JFeed $feed, SimpleXMLElement $el)
{
$feed->generator = (string) $el;
}
/**
* Method to handle the <image> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleImage(JFeed $feed, SimpleXMLElement $el)
{
// Create a feed link object for the image.
$image = new JFeedLink(
(string) $el->url,
null,
'logo',
null,
(string) $el->title
);
// Populate extra fields if they exist.
$image->link = (string) $el->link;
$image->description = (string) $el->description;
$image->height = (string) $el->height;
$image->width = (string) $el->width;
$feed->image = $image;
}
/**
* Method to handle the <language> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleLanguage(JFeed $feed, SimpleXMLElement $el)
{
$feed->language = (string) $el;
}
/**
* Method to handle the <lastBuildDate> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleLastBuildDate(JFeed $feed, SimpleXMLElement $el)
{
$feed->updatedDate = (string) $el;
}
/**
* Method to handle the <link> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleLink(JFeed $feed, SimpleXMLElement $el)
{
$feed->uri = (string) $el;
}
/**
* Method to handle the <managingEditor> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleManagingEditor(JFeed $feed, SimpleXMLElement $el)
{
$feed->author = $this->processPerson((string) $el);
}
/**
* Method to handle the <skipDays> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleSkipDays(JFeed $feed, SimpleXMLElement $el)
{
// Initialise the array.
$days = array();
// Add all of the day values from the feed to the array.
foreach ($el->day as $day)
{
$days[] = (string) $day;
}
$feed->skipDays = $days;
}
/**
* Method to handle the <skipHours> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleSkipHours(JFeed $feed, SimpleXMLElement $el)
{
// Initialise the array.
$hours = array();
// Add all of the day values from the feed to the array.
foreach ($el->hour as $hour)
{
$hours[] = (int) $hour;
}
$feed->skipHours = $hours;
}
/**
* Method to handle the <pubDate> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handlePubDate(JFeed $feed, SimpleXMLElement $el)
{
$feed->publishedDate = (string) $el;
}
/**
* Method to handle the <title> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleTitle(JFeed $feed, SimpleXMLElement $el)
{
$feed->title = (string) $el;
}
/**
* Method to handle the <ttl> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleTtl(JFeed $feed, SimpleXMLElement $el)
{
$feed->ttl = (integer) $el;
}
/**
* Method to handle the <webmaster> element for the feed.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function handleWebmaster(JFeed $feed, SimpleXMLElement $el)
{
// Get the tag contents and split it over the first space.
$tmp = (string) $el;
$tmp = explode(' ', $tmp, 2);
// This is really cheap parsing. Probably need to create a method to do this more robustly.
$name = null;
if (isset($tmp[1]))
{
$name = trim($tmp[1], ' ()');
}
$email = trim($tmp[0]);
$feed->addContributor($name, $email, null, 'webmaster');
}
/**
* Method to initialise the feed for parsing. Here we detect the version and advance the stream
* reader so that it is ready to parse feed elements.
*
* @return void
*
* @since 12.3
*/
protected function initialise()
{
// Read the version attribute.
$this->version = $this->stream->getAttribute('version');
// We want to move forward to the first element after the <channel> element.
$this->moveToNextElement('channel');
$this->moveToNextElement();
}
/**
* Method to handle the feed entry element for the feed: <item>.
*
* @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
protected function processFeedEntry(JFeedEntry $entry, SimpleXMLElement $el)
{
$entry->uri = (string) $el->link;
$entry->title = (string) $el->title;
$entry->publishedDate = (string) $el->pubDate;
$entry->updatedDate = (string) $el->pubDate;
$entry->content = (string) $el->description;
$entry->guid = (string) $el->guid;
$entry->comments = (string) $el->comments;
// Add the feed entry author if available.
$author = (string) $el->author;
if (!empty($author))
{
$entry->author = $this->processPerson($author);
}
// Add any categories to the entry.
foreach ($el->category as $category)
{
$entry->addCategory((string) $category, (string) $category['domain']);
}
// Add any enclosures to the entry.
foreach ($el->enclosure as $enclosure)
{
$link = new JFeedLink(
(string) $enclosure['url'],
null,
(string) $enclosure['type'],
null,
null,
(int) $enclosure['length']
);
$entry->addLink($link);
}
}
/**
* Method to parse a string with person data and return a JFeedPerson object.
*
* @param string $data The string to parse for a person.
*
* @return JFeedPerson
*
* @since 12.3
*/
protected function processPerson($data)
{
// Create a new person object.
$person = new JFeedPerson;
// This is really cheap parsing, but so far good enough. :)
$data = explode(' ', $data, 2);
if (isset($data[1]))
{
$person->name = trim($data[1], ' ()');
}
// Set the email for the person.
$person->email = trim($data[0]);
return $person;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,51 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* RSS Feed Parser Namespace handler for iTunes.
*
* @package Joomla.Platform
* @subpackage Feed
* @see http://www.apple.com/itunes/podcasts/specs.html
* @since 12.3
*/
class JFeedParserRssItunes implements JFeedParserNamespace
{
/**
* Method to handle an element for the feed given that the itunes namespace is present.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
public function processElementForFeed(JFeed $feed, SimpleXMLElement $el)
{
}
/**
* Method to handle the feed entry element for the feed given that the itunes namespace is present.
*
* @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
public function processElementForFeedEntry(JFeedEntry $entry, SimpleXMLElement $el)
{
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* RSS Feed Parser Namespace handler for MediaRSS.
*
* @package Joomla.Platform
* @subpackage Feed
* @see http://video.search.yahoo.com/mrss
* @since 12.3
*/
class JFeedParserRssMedia implements JFeedParserNamespace
{
/**
* Method to handle an element for the feed given that the media namespace is present.
*
* @param JFeed $feed The JFeed object being built from the parsed feed.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
public function processElementForFeed(JFeed $feed, SimpleXMLElement $el)
{
}
/**
* Method to handle the feed entry element for the feed given that the media namespace is present.
*
* @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
* @param SimpleXMLElement $el The current XML element object to handle.
*
* @return void
*
* @since 12.3
*/
public function processElementForFeedEntry(JFeedEntry $entry, SimpleXMLElement $el)
{
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Feed
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Feed Person class.
*
* @package Joomla.Platform
* @subpackage Feed
* @since 12.3
*/
class JFeedPerson
{
/**
* @var string
* @since 12.3
*/
public $email;
/**
* @var string
* @since 12.3
*/
public $name;
/**
* @var string
* @since 12.3
*/
public $type;
/**
* @var string
* @since 12.3
*/
public $uri;
/**
* Constructor.
*
* @param string $name The full name of the person.
* @param string $email The email address of the person.
* @param string $uri The URI for the person.
* @param string $type The type of person.
*
* @since 12.3
*/
public function __construct($name = null, $email = null, $uri = null, $type = null)
{
$this->name = $name;
$this->email = $email;
$this->uri = $uri;
$this->type = $type;
}
}