[CLEANUP] move plugin urilfy to composer setup

This commit is contained in:
Kanti 2016-07-31 11:52:28 +02:00
commit 5955ec2007
52 changed files with 780 additions and 6560 deletions

View file

@ -1,189 +0,0 @@
<?php
namespace Suin\RSSWriter;
use \Suin\RSSWriter\SimpleXMLElement;
class Channel implements \Suin\RSSWriter\ChannelInterface
{
/** @var string */
protected $title;
/** @var string */
protected $url;
/** @var string */
protected $description;
/** @var string */
protected $language;
/** @var string */
protected $copyright;
/** @var int */
protected $pubDate;
/** @var int */
protected $lastBuildDate;
/** @var int */
protected $ttl;
/** @var \Suin\RSSWriter\ItemInterface[] */
protected $items = array();
/**
* Set channel title
* @param string $title
* @return $this
*/
public function title($title)
{
$this->title = $title;
return $this;
}
/**
* Set channel URL
* @param string $url
* @return $this
*/
public function url($url)
{
$this->url = $url;
return $this;
}
/**
* Set channel description
* @param string $description
* @return $this
*/
public function description($description)
{
$this->description = $description;
return $this;
}
/**
* Set ISO639 language code
*
* The language the channel is written in. This allows aggregators to group all
* Italian language sites, for example, on a single page. A list of allowable
* values for this element, as provided by Netscape, is here. You may also use
* values defined by the W3C.
*
* @param string $language
* @return $this
*/
public function language($language)
{
$this->language = $language;
return $this;
}
/**
* Set channel copyright
* @param string $copyright
* @return $this
*/
public function copyright($copyright)
{
$this->copyright = $copyright;
return $this;
}
/**
* Set channel published date
* @param int $pubDate Unix timestamp
* @return $this
*/
public function pubDate($pubDate)
{
$this->pubDate = $pubDate;
return $this;
}
/**
* Set channel last build date
* @param int $lastBuildDate Unix timestamp
* @return $this
*/
public function lastBuildDate($lastBuildDate)
{
$this->lastBuildDate = $lastBuildDate;
return $this;
}
/**
* Set channel ttl (minutes)
* @param int $ttl
* @return $this
*/
public function ttl($ttl)
{
$this->ttl = $ttl;
return $this;
}
/**
* Add item object
* @param \Suin\RSSWriter\ItemInterface $item
* @return $this
*/
public function addItem(ItemInterface $item)
{
$this->items[] = $item;
return $this;
}
/**
* Append to feed
* @param \Suin\RSSWriter\FeedInterface $feed
* @return $this
*/
public function appendTo(FeedInterface $feed)
{
$feed->addChannel($this);
return $this;
}
/**
* Return XML object
* @return \Suin\RSSWriter\SimpleXMLElement
*/
public function asXML()
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel></channel>', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL);
$xml->addChild('title', $this->title);
$xml->addChild('link', $this->url);
$xml->addChild('description', $this->description);
if ( $this->language !== null )
{
$xml->addChild('language', $this->language);
}
if ( $this->copyright !== null )
{
$xml->addChild('copyright', $this->copyright);
}
if ( $this->pubDate !== null )
{
$xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
}
if ( $this->lastBuildDate !== null )
{
$xml->addChild('lastBuildDate', date(DATE_RSS, $this->lastBuildDate));
}
if ( $this->ttl !== null )
{
$xml->addChild('ttl', $this->ttl);
}
foreach ( $this->items as $item )
{
$toDom = dom_import_simplexml($xml);
$fromDom = dom_import_simplexml($item->asXML());
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
}
return $xml;
}
}

View file

@ -1,91 +0,0 @@
<?php
namespace Suin\RSSWriter;
use \Suin\RSSWriter\FeedInterface;
use \Suin\RSSWriter\ItemInterface;
interface ChannelInterface
{
/**
* Set channel title
* @param string $title
* @return $this
*/
public function title($title);
/**
* Set channel URL
* @param string $url
* @return $this
*/
public function url($url);
/**
* Set channel description
* @param string $description
* @return $this
*/
public function description($description);
/**
* Set ISO639 language code
*
* The language the channel is written in. This allows aggregators to group all
* Italian language sites, for example, on a single page. A list of allowable
* values for this element, as provided by Netscape, is here. You may also use
* values defined by the W3C.
*
* @param string $language
* @return $this
*/
public function language($language);
/**
* Set channel copyright
* @param string $copyright
* @return $this
*/
public function copyright($copyright);
/**
* Set channel published date
* @param int $pubDate Unix timestamp
* @return $this
*/
public function pubDate($pubDate);
/**
* Set channel last build date
* @param int $lastBuildDate Unix timestamp
* @return $this
*/
public function lastBuildDate($lastBuildDate);
/**
* Set channel ttl (minutes)
* @param int $ttl
* @return $this
*/
public function ttl($ttl);
/**
* Add item object
* @param \Suin\RSSWriter\ItemInterface $item
* @return $this
*/
public function addItem(ItemInterface $item);
/**
* Append to feed
* @param \Suin\RSSWriter\FeedInterface $feed
* @return $this
*/
public function appendTo(FeedInterface $feed);
/**
* Return XML object
* @return \Suin\RSSWriter\SimpleXMLElement
*/
public function asXML();
}

View file

@ -1,54 +0,0 @@
<?php
namespace Suin\RSSWriter;
use \DOMDocument;
use \Suin\RSSWriter\ChannelInterface;
use \Suin\RSSWriter\SimpleXMLElement;
class Feed implements \Suin\RSSWriter\FeedInterface
{
/** @var \Suin\RSSWriter\ChannelInterface[] */
protected $channels = array();
/**
* Add channel
* @param \Suin\RSSWriter\ChannelInterface $channel
* @return $this
*/
public function addChannel(ChannelInterface $channel)
{
$this->channels[] = $channel;
return $this;
}
/**
* Render XML
* @return string
*/
public function render()
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" />', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL);
foreach ( $this->channels as $channel )
{
$toDom = dom_import_simplexml($xml);
$fromDom = dom_import_simplexml($channel->asXML());
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
}
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->appendChild($dom->importNode(dom_import_simplexml($xml), true));
$dom->formatOutput = true;
return $dom->saveXML();
}
/**
* Render XML
* @return string
*/
public function __toString()
{
return $this->render();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace Suin\RSSWriter;
use \Suin\RSSWriter\ChannelInterface;
interface FeedInterface
{
/**
* Add channel
* @param \Suin\RSSWriter\ChannelInterface $channel
* @return $thisJ
*/
public function addChannel(ChannelInterface $channel);
/**
* Render XML
* @return string
*/
public function render();
/**
* Render XML
* @return string
*/
public function __toString();
}

View file

@ -1,169 +0,0 @@
<?php
namespace Suin\RSSWriter;
use \Suin\RSSWriter\SimpleXMLElement;
class Item implements \Suin\RSSWriter\ItemInterface
{
/** @var string */
protected $title;
/** @var string */
protected $url;
/** @var string */
protected $description;
/** @var array */
protected $categories = array();
/** @var string */
protected $guid;
/** @var bool */
protected $isPermalink;
/** @var int */
protected $pubDate;
/** @var array */
protected $enclosure;
/**
* Set item title
* @param string $title
* @return $this
*/
public function title($title)
{
$this->title = $title;
return $this;
}
/**
* Set item URL
* @param string $url
* @return $this
*/
public function url($url)
{
$this->url = $url;
return $this;
}
/**
* Set item description
* @param string $description
* @return $this
*/
public function description($description)
{
$this->description = $description;
return $this;
}
/**
* Set item category
* @param string $name Category name
* @param string $domain Category URL
* @return $this
*/
public function category($name, $domain = null)
{
$this->categories[] = array($name, $domain);
return $this;
}
/**
* Set GUID
* @param string $guid
* @param bool $isPermalink
* @return $this
*/
public function guid($guid, $isPermalink = false)
{
$this->guid = $guid;
$this->isPermalink = $isPermalink;
return $this;
}
/**
* Set published date
* @param int $pubDate Unix timestamp
* @return $this
*/
public function pubDate($pubDate)
{
$this->pubDate = $pubDate;
return $this;
}
/**
* Set enclosure
* @param var $url Url to media file
* @param int $length Length in bytes of the media file
* @param var $type Media type, default is audio/mpeg
* @return $this
*/
public function enclosure($url, $length = 0, $type = 'audio/mpeg')
{
$this->enclosure = array('url' => $url, 'length' => $length, 'type' => $type);
return $this;
}
/**
* Append item to the channel
* @param \Suin\RSSWriter\ChannelInterface $channel
* @return $this
*/
public function appendTo(ChannelInterface $channel)
{
$channel->addItem($this);
return $this;
}
/**
* Return XML object
* @return \Suin\RSSWriter\SimpleXMLElement
*/
public function asXML()
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL);
$xml->addChild('title', $this->title);
$xml->addChild('link', $this->url);
$xml->addChild('description', $this->description);
foreach ( $this->categories as $category )
{
$element = $xml->addChild('category', $category[0]);
if ( isset($category[1]) )
{
$element->addAttribute('domain', $category[1]);
}
}
if ( $this->guid )
{
$guid = $xml->addChild('guid', $this->guid);
if ( $this->isPermalink )
{
$guid->addAttribute('isPermaLink', 'true');
}
}
if ( $this->pubDate !== null )
{
$xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
}
if (is_array($this->enclosure) && (count($this->enclosure) == 3))
{
$element = $xml->addChild('enclosure');
$element->addAttribute('url', $this->enclosure['url']);
$element->addAttribute('type', $this->enclosure['type']);
if ($this->enclosure['length'])
{
$element->addAttribute('length', $this->enclosure['length']);
}
}
return $xml;
}
}

View file

@ -1,75 +0,0 @@
<?php
namespace Suin\RSSWriter;
use \Suin\RSSWriter\ChannelInterface;
use \Suin\RSSWriter\SimpleXMLElement;
interface ItemInterface
{
/**
* Set item title
* @param string $title
* @return $this
*/
public function title($title);
/**
* Set item URL
* @param string $url
* @return $this
*/
public function url($url);
/**
* Set item description
* @param string $description
* @return $this
*/
public function description($description);
/**
* Set item category
* @param string $name Category name
* @param string $domain Category URL
* @return $this
*/
public function category($name, $domain = null);
/**
* Set GUID
* @param string $guid
* @param bool $isPermalink
* @return $this
*/
public function guid($guid, $isPermalink = false);
/**
* Set published date
* @param int $pubDate Unix timestamp
* @return $this
*/
public function pubDate($pubDate);
/**
* Set enclosure
* @param var $url Url to media file
* @param int $length Length in bytes of the media file
* @param var $type Media type, default is audio/mpeg
* @return $this
*/
public function enclosure($url, $length = 0, $type = 'audio/mpeg');
/**
* Append item to the channel
* @param \Suin\RSSWriter\ChannelInterface $channel
* @return $this
*/
public function appendTo(ChannelInterface $channel);
/**
* Return XML object
* @return \Suin\RSSWriter\SimpleXMLElement
*/
public function asXML();
}

View file

@ -1,16 +0,0 @@
<?php
namespace Suin\RSSWriter;
class SimpleXMLElement extends \SimpleXMLElement
{
public function addChild($name, $value = null, $namespace = null)
{
if ( $value !== null and is_string($value) === true )
{
$value = str_replace('&', '&amp;', $value);
}
return parent::addChild($name, $value, $namespace);
}
}

View file

@ -143,7 +143,52 @@ class ItemTest extends TestCase
<description>{$data['description']}</description>
<category>{$data['categories'][0][0]}</category>
<category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category>
<guid isPermaLink=\"true\">{$data['guid']}</guid>
<guid>{$data['guid']}</guid>
<pubDate>{$nowString}</pubDate>
<enclosure url=\"{$data['enclosure']['url']}\" type=\"{$data['enclosure']['type']}\" length=\"{$data['enclosure']['length']}\"/>
<author>{$data['author']}</author>
</item>
";
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML());
}
public function testAsXML_false_permalink()
{
$now = time();
$nowString = date(DATE_RSS, $now);
$data = array(
'title' => "Venice Film Festival Tries to Quit Sinking",
'url' => 'http://nytimes.com/2004/12/07FEST.html',
'description' => "Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.",
'categories' => array(
array("Grateful Dead", null),
array("MSFT", 'http://www.fool.com/cusips'),
),
'guid' => "http://inessential.com/2002/09/01.php#a2",
'isPermalink' => false,
'pubDate' => $now,
'enclosure' => array(
'url' => 'http://link-to-audio-file.com/test.mp3',
'length' => 4992,
'type' => 'audio/mpeg'),
'author' => 'Hidehito Nozawa aka Suin'
);
$item = new Item();
foreach ($data as $key => $value) {
$this->reveal($item)->attr($key, $value);
}
$expect = "
<item>
<title>{$data['title']}</title>
<link>{$data['url']}</link>
<description>{$data['description']}</description>
<category>{$data['categories'][0][0]}</category>
<category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category>
<guid isPermaLink=\"false\">{$data['guid']}</guid>
<pubDate>{$nowString}</pubDate>
<enclosure url=\"{$data['enclosure']['url']}\" type=\"{$data['enclosure']['type']}\" length=\"{$data['enclosure']['length']}\"/>
<author>{$data['author']}</author>

View file

@ -1,35 +0,0 @@
<?php
// Load test target classes
spl_autoload_register(function($c) { @include_once strtr($c, '\\_', '//').'.php'; });
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/Source');
use \Suin\RSSWriter\Feed;
use \Suin\RSSWriter\Channel;
use \Suin\RSSWriter\Item;
$feed = new Feed();
$channel = new Channel();
$channel
->title("Channel Title")
->description("Channel Description")
->url('http://blog.example.com')
->language('en-US')
->copyright('Copyright 2012, Foo Bar')
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
->ttl(60)
->appendTo($feed);
$item = new Item();
$item
->title("Blog Entry Title")
->description("<div>Blog body</div>")
->url('http://blog.example.com/2012/08/21/blog-entry/')
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
->guid('http://blog.example.com/2012/08/21/blog-entry/', true)
->appendTo($channel);
echo $feed; // or echo $feed->render();

View file

@ -108,8 +108,8 @@ class Item implements ItemInterface
if ($this->guid) {
$guid = $xml->addChild('guid', $this->guid);
if ($this->isPermalink) {
$guid->addAttribute('isPermaLink', 'true');
if ($this->isPermalink === false) {
$guid->addAttribute('isPermaLink', 'false');
}
}