Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
fixed date format (issue #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roumen Damianoff committed Dec 11, 2015
1 parent f2087a5 commit 953e9df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
38 changes: 14 additions & 24 deletions src/Roumen/Feed/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Feed generator class for laravel-feed package.
*
* @author Roumen Damianoff <[email protected]>
* @version 2.9.7
* @version 2.9.8
* @link https://roumen.it/projects/laravel-feed
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
Expand All @@ -16,7 +16,7 @@
class Feed
{

public $items = array();
public $items = [];
public $title = 'My feed title';
public $description = 'My feed description';
public $link;
Expand All @@ -31,7 +31,7 @@ class Feed
protected $shortening = false;
protected $shorteningLimit = 150;
protected $dateFormat = 'datetime';
protected $namespaces = array();
protected $namespaces = [];
protected $customView = null;


Expand Down Expand Up @@ -67,8 +67,6 @@ public function add($title, $author, $link, $pubdate, $description, $content='',
$description = mb_substr($description, 0, $this->shorteningLimit, 'UTF-8');
}

$pubdate = $this->formatDate($pubdate);

$this->items[] = array(
'title' => $title,
'author' => $author,
Expand Down Expand Up @@ -96,8 +94,6 @@ public function addArray(array $a)
$a['description'] = mb_substr($a['description'], 0, $this->shorteningLimit, 'UTF-8');
}

$a['pubdate'] = $this->formatDate($a['pubdate']);

$this->items[] = $a;
}

Expand All @@ -121,18 +117,7 @@ public function render($format = null, $cache = null, $key = null)

if ($this->ctype == null)
{
switch ($format)
{
case "rss":
$this->ctype = 'application/rss+xml';
break;
case "atom":
$this->ctype = 'application/atom+xml';
break;
default:
$this->ctype = 'application/atom+xml';
break;
}
($format == 'rss') ? $this->ctype = 'application/rss+xml' : $this->ctype = 'application/atom+xml';
}

// if cache is on and there is cached feed => return it
Expand All @@ -147,15 +132,20 @@ public function render($format = null, $cache = null, $key = null)

$this->pubdate = $this->formatDate($this->pubdate, $format);

$channel = array(
foreach($this->items as $k => $v)
{
$this->items[$k]['pubdate'] = $this->formatDate($this->items[$k]['pubdate'], $format);
}

$channel = [
'title'=>$this->title,
'description'=>$this->description,
'logo' => $this->logo,
'icon' => $this->icon,
'link'=>$this->link,
'pubdate'=>$this->pubdate,
'lang'=>$this->lang
);
];

if ($format == 'rss')
{
Expand All @@ -170,11 +160,11 @@ public function render($format = null, $cache = null, $key = null)
}
}

$viewData = array(
$viewData = [
'items' => $this->items,
'channel' => $channel,
'namespaces' => $this->getNamespaces()
);
];

// if cache is on put this feed in cache and return it
if ($this->caching > 0)
Expand Down Expand Up @@ -345,7 +335,7 @@ public function setShortening($b=false)
*
* @return string
*/
protected function formatDate($date, $format="atom")
protected function formatDate($date, $format='atom')
{
if ($format == "atom")
{
Expand Down
2 changes: 1 addition & 1 deletion tests/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testFeedAdd()
$this->assertEquals('TestTitle', $this->feed->items[0]['title']);
$this->assertEquals('TestAuthor', $this->feed->items[0]['author']);
$this->assertEquals('TestUrl', $this->feed->items[0]['link']);
$this->assertEquals(date('c',strtotime("2014-02-29 00:00:00")), $this->feed->items[0]['pubdate']);
$this->assertEquals('2014-02-29 00:00:00', $this->feed->items[0]['pubdate']);
$this->assertEquals('<p>TestResume</p>', $this->feed->items[0]['description']);
$this->assertEquals('<p>TestContent</p>', $this->feed->items[0]['content']);
}
Expand Down

0 comments on commit 953e9df

Please sign in to comment.