The most effective way to restrict democracy is to transfer decision making from the public arena to unaccountable institutions. Chomsky.

Podcast feed with CakePHP 1.2

2008-10-13 13:48:09-05

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


Comments Comentblogs:

New Comentblog

Captcha



Login



Remember me:
aarkerio
Manuel Montoya estudió neuropsicología en la facultad y en el Instituto de Biomédicas de la UNAM. Trabajó en Compaq de México como diseñador de software, tiene diez años de experiencia en Java, Python, PHP y SQL. Le interesan muchas cosas y neciamente le da por escribir sobre todas ellas.

Actualmente trabaja en Chipotle Software, desarrollando Karamelo, una herramienta de e-Learning. Emacs y WindowMaker son su editor y escritorio favoritos.
GNU W3C anarquismo cakephp centauro ciencia cine cooperación cooperativa hacking historia humor internet karamelo linux literatura méxico música netbsd política programación psicología recetas sociedad software libre arte
Powered by:
Despabilando la MonoNeurona.org
Livechat

<-Nombre
aarkerio wrote:
Fixed!
on 23/10/08

marcos_d wrote:
Los temas en el rss de la Mononeurona no se actualizan
on 14/8/08

diablomx wrote:
aarkerio me URGE URGE hablar contigo...hablame a mi cel.
on 13/6/08

mayralorena wrote:
que gane Meeexico!!!!
on 8/6/08

s1m0 wrote:
Thot dice que se apunta para los de melon(Aunque yo te dije piñon :)' ) solo hay que ponernos de acuerdo....
on 14/5/08

aarkerio wrote:
En Tehuacán nos vemos, en el tapanco
on 10/5/08

s1m0 wrote:
Ps tu dices cuando, brindamos con la bebida de los dioses!!!
on 30/4/08

Karla wrote:
saludos guapo!
on 7/3/08

aarkerio wrote:
No, sólo que hagas cut&paste
on 28/2/08

dmesg wrote:
aarkerio, crees que puede haber la posibilidad de en mi blog de mononeurona se puedan ver los post que he puesto en mononeurona?
on 21/2/08

¿Qué estuve haciendo?
Portando Karamelo a Windows, guacala!
3 days, 1 hour ago
Chido! thx asarch
3 days, 18 hours ago
Cómo se crea una imagen linux.img para Qemu?
3 days, 20 hours ago
Aprendiendo Mercurial
1 week, 3 days ago
Me voy a hacer in licuado de plátano
1 week, 4 days ago
Mejor un caballito d' limón y dos de tequila, el Aderogyl mexicano!
1 week, 6 days ago
toy enfermo, inche gripe
2 weeks ago
Basic? wacala! enseñales Python
2 weeks, 3 days ago
I an in IRC channel
2 weeks, 3 days ago
inche red inalámbrica de de la unam, está del nabo
2 weeks, 4 days ago
Galerias
aarkerio's Forums
FirefoxjEdit.orgGimpOpenOffice.orgHacker
Top
Colectivo MonoNeurona.org © 2002-2008.