forked from wallabag/wallabag
update to 3.2 version of full-text-rss, issue #694
This commit is contained in:
100
inc/3rdparty/libraries/feedwriter/FeedItem.php
vendored
Normal file → Executable file
100
inc/3rdparty/libraries/feedwriter/FeedItem.php
vendored
Normal file → Executable file
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Univarsel Feed Writer
|
||||
*
|
||||
*
|
||||
* FeedItem class - Used as feed element in FeedWriter class
|
||||
*
|
||||
* @package UnivarselFeedWriter
|
||||
@ -12,20 +12,20 @@
|
||||
{
|
||||
private $elements = array(); //Collection of feed elements
|
||||
private $version;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param contant (RSS1/RSS2/ATOM) RSS2 is default.
|
||||
*/
|
||||
* Constructor
|
||||
*
|
||||
* @param contant (RSS1/RSS2/ATOM) RSS2 is default.
|
||||
*/
|
||||
function __construct($version = RSS2)
|
||||
{
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element (overwrites existing elements with $elementName)
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param srting The tag name of an element
|
||||
* @param srting The content of tag
|
||||
@ -38,11 +38,11 @@
|
||||
unset($this->elements[$elementName]);
|
||||
}
|
||||
$this->addElement($elementName, $content, $attributes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element to elements array
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param srting The tag name of an element
|
||||
* @param srting The content of tag
|
||||
@ -61,11 +61,11 @@
|
||||
$this->elements[$elementName][$i]['content'] = $content;
|
||||
$this->elements[$elementName][$i]['attributes'] = $attributes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set multiple feed elements from an array.
|
||||
* Set multiple feed elements from an array.
|
||||
* Elements which have attributes cannot be added by this method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param array array of elements in 'tagName' => 'tagContent' format.
|
||||
* @return void
|
||||
@ -73,15 +73,15 @@
|
||||
public function addElementArray($elementArray)
|
||||
{
|
||||
if(! is_array($elementArray)) return;
|
||||
foreach ($elementArray as $elementName => $content)
|
||||
foreach ($elementArray as $elementName => $content)
|
||||
{
|
||||
$this->addElement($elementName, $content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the collection of elements in this feed item
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
@ -89,68 +89,74 @@
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
|
||||
// Wrapper functions ------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Set the 'dscription' element of feed item
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string The content of 'description' element
|
||||
* @return void
|
||||
*/
|
||||
public function setDescription($description)
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->setElement('description', $description);
|
||||
$tag = ($this->version == ATOM)? 'summary' : 'description';
|
||||
$this->setElement($tag, $description);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc Set the 'title' element of feed item
|
||||
* @access public
|
||||
* @param string The content of 'title' element
|
||||
* @return void
|
||||
*/
|
||||
public function setTitle($title)
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->setElement('title', $title);
|
||||
$this->setElement('title', $title);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the 'date' element of feed item
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string The content of 'date' element
|
||||
* @return void
|
||||
*/
|
||||
public function setDate($date)
|
||||
public function setDate($date)
|
||||
{
|
||||
if(! is_numeric($date))
|
||||
{
|
||||
$date = strtotime($date);
|
||||
}
|
||||
|
||||
if($this->version == RSS2)
|
||||
|
||||
if($this->version == ATOM)
|
||||
{
|
||||
$tag = 'pubDate';
|
||||
$value = date(DATE_RSS, $date);
|
||||
$tag = 'updated';
|
||||
$value = date(DATE_ATOM, $date);
|
||||
}
|
||||
else
|
||||
elseif($this->version == RSS2)
|
||||
{
|
||||
$tag = 'dc:date';
|
||||
$value = date("Y-m-d", $date);
|
||||
$tag = 'pubDate';
|
||||
$value = date(DATE_RSS, $date);
|
||||
}
|
||||
|
||||
$this->setElement($tag, $value);
|
||||
else
|
||||
{
|
||||
$tag = 'dc:date';
|
||||
$value = date("Y-m-d", $date);
|
||||
}
|
||||
|
||||
$this->setElement($tag, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the 'link' element of feed item
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string The content of 'link' element
|
||||
* @return void
|
||||
*/
|
||||
public function setLink($link)
|
||||
public function setLink($link)
|
||||
{
|
||||
if($this->version == RSS2 || $this->version == RSS1)
|
||||
{
|
||||
@ -161,27 +167,27 @@
|
||||
{
|
||||
$this->setElement('link','',array('href'=>$link));
|
||||
$this->setElement('id', FeedWriter::uuid($link,'urn:uuid:'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 'source' element of feed item
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string The content of 'source' element
|
||||
* @return void
|
||||
*/
|
||||
public function setSource($link)
|
||||
public function setSource($link)
|
||||
{
|
||||
$attributes = array('url'=>$link);
|
||||
$this->setElement('source', "wallabag",$attributes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the 'encloser' element of feed item
|
||||
* For RSS 2.0 only
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string The url attribute of encloser tag
|
||||
* @param string The length attribute of encloser tag
|
||||
@ -193,6 +199,6 @@
|
||||
$attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
|
||||
$this->setElement('enclosure','',$attributes);
|
||||
}
|
||||
|
||||
|
||||
} // end of class FeedItem
|
||||
?>
|
||||
17
inc/3rdparty/libraries/feedwriter/FeedWriter.php
vendored
17
inc/3rdparty/libraries/feedwriter/FeedWriter.php
vendored
@ -97,15 +97,12 @@ define('JSONP', 3, true);
|
||||
header('X-content-type-options: nosniff');
|
||||
} elseif ($this->version == JSON) {
|
||||
header('Content-type: application/json; charset=UTF-8');
|
||||
$this->json = new stdClass();
|
||||
} elseif ($this->version == JSONP) {
|
||||
header('Content-type: application/javascript; charset=UTF-8');
|
||||
$this->json = new stdClass();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->version == JSON || $this->version == JSONP) {
|
||||
$this->json = new stdClass();
|
||||
}
|
||||
|
||||
|
||||
$this->printHead();
|
||||
$this->printChannels();
|
||||
@ -116,6 +113,11 @@ define('JSONP', 3, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function &getItems()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new FeedItem.
|
||||
*
|
||||
@ -199,7 +201,8 @@ define('JSONP', 3, true);
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->setChannelElement('description', $description);
|
||||
$tag = ($this->version == ATOM)? 'subtitle' : 'description';
|
||||
$this->setChannelElement($tag, $desciption);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +247,7 @@ define('JSONP', 3, true);
|
||||
{
|
||||
$out = '<?xml version="1.0" encoding="utf-8"?>'."\n";
|
||||
if ($this->xsl) $out .= '<?xml-stylesheet type="text/xsl" href="'.htmlspecialchars($this->xsl).'"?>' . PHP_EOL;
|
||||
$out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">' . PHP_EOL;
|
||||
$out .= '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">' . PHP_EOL;
|
||||
echo $out;
|
||||
}
|
||||
elseif ($this->version == JSON || $this->version == JSONP)
|
||||
|
||||
Reference in New Issue
Block a user