NewsFeaturesDownloadsDevelopmentSupportAbout Us

Plugin galleryfeeds

From LifeType Wiki


Name: galleryfeeds

Download link: http://sourceforge.net/projects/lifetype/files/

License: GPL

Author: The LifeType Project

Description

This plugin allows to generate custom feeds based on the contents of our files in the "Resource Centre". The idea behind this plugin is that we can easily generate, for example, an RSS 2.0 feed with enclosures including all the audio files from a certain album if we're into podcasting (or video files if we're into videoblogging)

The plugin includes the following feeds:

- Full RSS 2.0, including all kinds of files - RSS 2.0 feed of only audio files - RSS 2.0 feed of only video files - M3U playlist of only audio files

The plugin can also accept custom feeds or playlists formats, see the Notes section below.

Configuration

URLs generated by this plugin look like http://yourserver.com/plog/index.php?op=generateGalleryFeed&blogId=1&albumId=4&feedType=rss20. We can choose to hardcode them in our templates but we can also use the feed() function that will take care of generating the correct URLs for us.

In order to use this plugin, edit your album.template file and add the following bit of Smarty code wherever you would like to get the link to your resource feed:

<a href="{$galleryfeeds->feed($album)}">RSS Feed for this album</a>

By default, the link points to the full RSS 2.0 feed but in case we would like to use a custom one, the feed() method supports a secon parameter indicating the type of feed we'd like to get:

<a href="{$galleryfeeds->feed($album,"rss20audio")}">RSS Feed for this album</a>

In this case, we would get a link to the RSS 2.0 feed that only includes audio files.

It is also possible to get more than one link to different resource feeds in the same page.

Feeds generated by this plugin are also cached in disk, as long as template caching is enabled site-wide.

Notes

It is possible to easily add custom resource feeds to our plugin. Feeds are generated from normal Smarty template files which have a fixed set of data available, so they work in the same way as any other template file in pLog.

In order to add a new feed, two things need to be done:

  1. Create our own .template file and drop it into the plugins/galleryfeeds/templates folder
  2. Add the right MIME type needed by the template file to the file plugins/galleryfeeds/mimetypes.properties.php.

As an example, we are going to add a SMIL playlist file that will play all our resources in a givem album. SMIL is an XML-based recommendation of the W3C to create multimedia presentations from web resources and includes features such as backgroun playing of audio while images are displayed, etc. Our template will not cover those areas and will be very simple. It will only list the files in our album using the right SMIL tags, but it can be used and expanded upon to create more complex playlists.

First of all, we will create a file called smil.template in the plugins/galleryfeeds/templates. The contents of this file will be:

<smil>
 <body>
  <seq>
   {foreach from=$resources item=resource}
    {if $resource->isVideo()}
     <video src="{$url->resourceDownloadLink($resource)}" />
    {elseif $resource->isSound()}
     <audio src="{$url->resourceDownloadLink($resource)}" />    
    {elseif $resource->isImage()}
     <img src="{$url->resourceDownloadLink($resource)}" />    
    {else}
     <ref src="{$url->resourceDownloadLink($resource)}" />    
    {/if}
   {/foreach}
  </seq>
 </body>
</smil>

The $resources variable is an array of GalleryResource objects, which are all the resources available in this album. In order to display all of them we have to loop in the array. The $url object will be used to generate URIs to our resources (more information available in the pLog object model documentation. The $album variable of type GalleryAlbum is also available and it represents the album we're currently browsing.

Once our file is ready, we have to add a new MIME type for it. This step is not strictly necessary if our file is an XML-based formate because the default type is text/xml which ought to be enough, but it will help us to describe this step better.

MIME types are defined in the file plugins/galleryfeeds/mimetypes.properties.php. The contents of the file is a simple PHP Array where the key is the name of the template file (without the .template extension) and the value is the MIME type that should be used for that template file. In our case, we should add an extra line and the final contents of the file should look like:

$config = Array( 

  "rss20" => "text/xml",
  "rss20audio" => "text/xml",
  "rss20video" => "text/xml",
  "m3u" => "audio/x-mpegurl",
  "smil" => "text/xml"
);

Finally, all we need to do is modify the file album.template in our favourite template set to generate the correct URL to our feed:

<a href="{$galleryfeeds->feed($album,"smil")}">SMIL playlist of this album</a>

The second parameter of the feed() method is the name of the template file, again without the .template extension. It should also match the value that we added to the mimetypes.properties.php file.