Podcast feed with CakePHP 1.2
Desarrollo
I figure out how to build a podcast feed on CakePHP 1.2. If you are reading this you should already know how to make a normal RSS feeder with CakePHP.
Made podcast is easy but no documented. So, you have a Podcast model wich keeps podcast information, in podcasts_controller.php I wrote a rss() method:
public function rss($username)
{
$this->pageTitle = $username .' Podcasts'; //bloggerdata
$User = $this->Podcast->User->find(array('username'=>$username), array('id', 'username','name','email', 'name_blog', 'avatar'));
$channelData = array('title' => $username.' Podcasts',
'link' => array('controller' => 'blog', 'action' => $username),
'description' => 'Audio from '. $username .' edublog',
'itunes:summary' => 'Audio from '. $username .' edublog',
'language' => 'en-us',
'copyright' => 'Chipotle Software, 2008',
'generator' => 'Karamelo Platform',
'managingEditor' => 'podcasts@chipotle-software.com',
'itunes:owner' => $username,
'itunes:image' => '/images/avatars/'.$User['User']['avatar'],
'itunes:author' => $User['User']['name']
);
$this->Podcast->User->unbindAll();
$conditions = array('status'=>1, 'user_id'=>$User['User']['id']);
$fields = array('Podcast.id', 'Podcast.title', 'Podcast.filename', 'Podcast.description', 'Podcast.keywords', 'Podcast.created', 'Podcast.duration', 'Podcast.title', 'Podcast.length', 'Podcast.subject_id', 'Subject.title');
$order = 'Podcast.created DESC';
$limit = 12;
$podcasts = $this->Podcast->findAll($conditions, $fields, $order, $limit);
$this->set(compact('channelData', 'podcasts'));
}
As you can see I am using $username argument to get user data. You already have a RSS template in APP/views/layouts/rss/default.ctp wich looks like:
echo $rss->header();
$channel = $rss->channel(array(), $channelData, $items);
echo $rss->document(array(), $channel);
this file is the same to RSS 2.0 feeder, you don't need create another layout file. Now the view file to rss action wich is in APP/views/podcasts/rss/rss.ctp
function rss_transform($item)
{
return array(
'title' => $item['Podcast']['title'],
'guid' => '/files/podcasts/'. $item['Podcast']['filename'],
'enclosure' => array('url'=>'/files/podcasts/'. $item['Podcast']['filename'], 'length'=> $item['Podcast']['length']),
'description' => strip_tags($item['Podcast']['description']),
'pubDate' => $item['Podcast']['created'],
'itunes:author' => 'Karamelo',
'itunes:summary' => strip_tags($item['Podcast']['description'])
);
}
$rss->addNs('itunes');
$this->set('items', $rss->items($podcasts, 'rss_transform'));
The magic is done by addNs (add name space) method wich insert itunes tags... Voila!
You can see results here.
Permalink: http://www.mononeurona.org/users/entry/aarkerio/1592
Comentblogs:










