Skip to content

Commit

Permalink
Added image tag support to Feed::create, fixes #2739
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Jun 26, 2010
1 parent 756012b commit 34f20b1
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions classes/kohana/feed.php
Expand Up @@ -77,19 +77,49 @@ public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-

foreach ($info as $name => $value)
{
if (($name === 'pubDate' OR $name === 'lastBuildDate') AND (is_int($value) OR ctype_digit($value)))
if ($name === 'image')
{
// Convert timestamps to RFC 822 formatted dates
$value = date('r', $value);
// Create an image element
$image = $feed->channel->addChild('image');

if ( ! isset($value['link'], $value['url'], $value['title']))
{
throw new Kohana_Exception('Feed images require a link, url, and title');
}

if (strpos($value['link'], '://') === FALSE)
{
// Convert URIs to URLs
$value['link'] = URL::site($value['link'], 'http');
}

if (strpos($value['url'], '://') === FALSE)
{
// Convert URIs to URLs
$value['url'] = URL::site($value['url'], 'http');
}

// Create the image elements
$image->addChild('link', $value['link']);
$image->addChild('url', $value['url']);
$image->addChild('title', $value['title']);
}
elseif (($name === 'link' OR $name === 'docs') AND strpos($value, '://') === FALSE)
else
{
// Convert URIs to URLs
$value = URL::site($value, 'http');
}
if (($name === 'pubDate' OR $name === 'lastBuildDate') AND (is_int($value) OR ctype_digit($value)))
{
// Convert timestamps to RFC 822 formatted dates
$value = date('r', $value);
}
elseif (($name === 'link' OR $name === 'docs') AND strpos($value, '://') === FALSE)
{
// Convert URIs to URLs
$value = URL::site($value, 'http');
}

// Add the info to the channel
$feed->channel->addChild($name, $value);
// Add the info to the channel
$feed->channel->addChild($name, $value);
}
}

foreach ($items as $item)
Expand Down

0 comments on commit 34f20b1

Please sign in to comment.