Skip to content

Commit

Permalink
Merge pull request #3 from kdambekalns/cleanup
Browse files Browse the repository at this point in the history
TASK: Style cleanup, add LICENSE
  • Loading branch information
robertlemke committed Mar 7, 2016
2 parents 15b53e0 + b0c9016 commit 451ce15
Show file tree
Hide file tree
Showing 7 changed files with 546 additions and 446 deletions.
255 changes: 136 additions & 119 deletions Classes/RobertLemke/Rss/Channel.php
Original file line number Diff line number Diff line change
@@ -1,134 +1,151 @@
<?php
namespace RobertLemke\Rss;

/* *
* This script belongs to the Flow package "RobertLemke.Rss". *
* */
/*
* This file is part of the RobertLemke.Rss package.
*
* (c) Robert Lemke
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

/**
* An RSS Channel
*/
class Channel {

/**
* @var string
*/
protected $title;

/**
* @var string
*/
protected $description;

/**
* @var string
*/
protected $feedUri;

/**
* @var string
*/
protected $websiteUri;

/**
* @var string
*/
protected $imageUri;

/**
* @var string
*/
protected $language;

/**
* @var array
*/
protected $items = array();

/**
* @param string $description
* @return void
*/
public function setDescription($description) {
$this->description = $description;
}

/**
* @param string $title
* @return void
*/
public function setTitle($title) {
$this->title = $title;
}

/**
* @param string $feedUri
* @return void
*/
public function setFeedUri($feedUri) {
$this->feedUri = $feedUri;
}

/**
* @param string $websiteUri
* @return void
*/
public function setWebsiteUri($websiteUri) {
$this->websiteUri = $websiteUri;
}

/**
* @param string $language
* @return void
*/
public function setLanguage($language) {
$this->language = $language;
}

/**
* Adds a new item to this channel
*
* @param Item $item An item
* @return void
*/
public function addItem(Item $item) {
$this->items[] = $item;
}

/**
* @return \SimpleXMLElement
*/
public function asXML() {
$date = new \DateTime('now', new \DateTimeZone('GMT'));
$nowFormatted = $date->format('D, d M Y H:i:s') . ' GMT';

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?>
class Channel
{

/**
* @var string
*/
protected $title;

/**
* @var string
*/
protected $description;

/**
* @var string
*/
protected $feedUri;

/**
* @var string
*/
protected $websiteUri;

/**
* @var string
*/
protected $imageUri;

/**
* @var string
*/
protected $language;

/**
* @var array
*/
protected $items = array();

/**
* @param string $description
* @return void
*/
public function setDescription($description)
{
$this->description = $description;
}

/**
* @param string $title
* @return void
*/
public function setTitle($title)
{
$this->title = $title;
}

/**
* @param string $feedUri
* @return void
*/
public function setFeedUri($feedUri)
{
$this->feedUri = $feedUri;
}

/**
* @param string $websiteUri
* @return void
*/
public function setWebsiteUri($websiteUri)
{
$this->websiteUri = $websiteUri;
}

/**
* @param string $language
* @return void
*/
public function setLanguage($language)
{
$this->language = $language;
}

/**
* Adds a new item to this channel
*
* @param Item $item An item
* @return void
*/
public function addItem(Item $item)
{
$this->items[] = $item;
}

/**
* @return \SimpleXMLElement
*/
public function asXML()
{
$date = new \DateTime('now', new \DateTimeZone('GMT'));
$nowFormatted = $date->format('D, d M Y H:i:s') . ' GMT';

$xml = new SimpleXMLElement(
'<?xml version="1.0" encoding="UTF-8" ?>
<channel
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
/>', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL);
$xml->addChild('title', $this->title);

$linkNode = $xml->addChild('link', NULL, 'http://www.w3.org/2005/Atom');
$linkNode->addAttribute('href', $this->feedUri);
$linkNode->addAttribute('rel', 'self');
$linkNode->addAttribute('type', 'application/rss+xml');

$xml->addChild('link', $this->websiteUri);
$xml->addChild('description', $this->description);
$xml->addChild('lastBuildDate', $nowFormatted);
$xml->addChild('language', $this->language);

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;
}
/>',
LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL
);
$xml->addChild('title', $this->title);

$linkNode = $xml->addChild('link', null, 'http://www.w3.org/2005/Atom');
$linkNode->addAttribute('href', $this->feedUri);
$linkNode->addAttribute('rel', 'self');
$linkNode->addAttribute('type', 'application/rss+xml');

$xml->addChild('link', $this->websiteUri);
$xml->addChild('description', $this->description);
$xml->addChild('lastBuildDate', $nowFormatted);
$xml->addChild('language', $this->language);

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;
}
}
113 changes: 62 additions & 51 deletions Classes/RobertLemke/Rss/Feed.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,70 @@
<?php
namespace RobertLemke\Rss;

/* *
* This script belongs to the Flow package "RobertLemke.Rss". *
* */
/*
* This file is part of the RobertLemke.Rss package.
*
* (c) Robert Lemke
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

/**
* An RSS Feed
*/
class Feed {

/**
* @var array<Channel>
*/
protected $channels = array();

/**
* Adds a new channel to this feed
*
* @param Channel $channel
* @return Feed
*/
public function addChannel(Channel $channel) {
$this->channels[] = $channel;
return $this;
}

/**
* Renders the full XML output for this RSS feed
*
* @return string
*/
public function render() {
$xml = new SimpleXMLElement('
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
/>
', 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();
}
class Feed
{

/**
* @var array<Channel>
*/
protected $channels = array();

/**
* Adds a new channel to this feed
*
* @param Channel $channel
* @return Feed
*/
public function addChannel(Channel $channel)
{
$this->channels[] = $channel;

return $this;
}

/**
* Renders the full XML output for this RSS feed
*
* @return string
*/
public function render()
{
$xml = new SimpleXMLElement(
'<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
/>',
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();
}
}
Loading

0 comments on commit 451ce15

Please sign in to comment.