[pLog-svn] r1955 - in plugins/trunk: . galleryfeeds galleryfeeds/class galleryfeeds/class/action galleryfeeds/locale galleryfeeds/templates

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri May 6 16:23:09 GMT 2005


Author: oscar
Date: 2005-05-06 16:23:09 +0000 (Fri, 06 May 2005)
New Revision: 1955

Added:
   plugins/trunk/galleryfeeds/
   plugins/trunk/galleryfeeds/class/
   plugins/trunk/galleryfeeds/class/action/
   plugins/trunk/galleryfeeds/class/action/generatefeedaction.class.php
   plugins/trunk/galleryfeeds/locale/
   plugins/trunk/galleryfeeds/locale/locale_en_UK.php
   plugins/trunk/galleryfeeds/mimetypes.properties.php
   plugins/trunk/galleryfeeds/plugingalleryfeeds.class.php
   plugins/trunk/galleryfeeds/templates/
   plugins/trunk/galleryfeeds/templates/m3u.template
   plugins/trunk/galleryfeeds/templates/rss20.template
   plugins/trunk/galleryfeeds/templates/rss20audio.template
   plugins/trunk/galleryfeeds/templates/rss20video.template
Log:
added a plugin that is capable of generating feeds or playlists from galleries. This allows to create for example cool RSS 2.0 feeds of our podcasts. The type and amount of feeds is totally customizable, and new feeds can be added anytime if needed. Just drop the .template file in the templates/ folfer and add the mime type required by the template to the mimetypes.properties.php file.

In order to generate the right URL to the feed, use {$galleryfeeds->feed($album)} in your album.template file. It is possible to include a second parameter to specify the type of feed:

{$galleryfeeds->feed($album,"rss20audio")}

The feed type must match the name of a .template file in the templates/ folder.

Caching is enabled for these feeds as long as it is enabled by the site administrator.


Added: plugins/trunk/galleryfeeds/class/action/generatefeedaction.class.php
===================================================================
--- plugins/trunk/galleryfeeds/class/action/generatefeedaction.class.php	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/class/action/generatefeedaction.class.php	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,94 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/view/plugintemplatedview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
+    
+    /**
+     * This is the class that is executed when index.php receives an "op"
+     * parameter called "GenerateSmilAction". Plugins can register as many
+     * actions as they wish, as long as they use $this->registerBlogAction()
+     */
+    class GenerateFeedAction extends BlogAction
+    {
+    
+        var $_albumId;
+    
+        /**
+         * this makes sure that our parameters are correct and sets the album id 
+         * to '1' in case the parameter is not correct. This method would need some additional work,
+         * should this plugin ever be released :)
+         */
+        function validate()
+        {
+            // make sure that the album id is correct and if not, set it to
+            // a harmless value such as '1' (though this probably would need to be changed!)
+            $this->_albumId = $this->_request->getValue( "albumId" );
+            $val = new IntegerValidator();
+            if( !$val->validate( $this->_albumId ))
+                $this->_albumId = 1;
+                
+            $this->_feedType = $this->_request->getValue( "feed" );
+            // check if the feed type is correct and if not use the default "rss20" one
+            if( !File::isReadable( PLOG_CLASS_PATH."plugins/galleryfeeds/templates/".$this->_feedType.".template" ))
+                $this->_feedType = "rss20";
+                
+            return( true );
+        }
+        
+        /**
+         * returns the right MIME type which depends on the kind of feed that we're trying to generate, since
+         * probably not all kinds of feeds need text/xml. The MIME type for each template is loaded from the file
+         * plugins/galleryfeeds/mimetypes.properties.php. If no matching mime type is found, 
+         * text/xml will be used by default.
+         *
+         * @private
+         */
+        function _getMimeType( $feedType )
+        {
+            $types = new ConfigFileStorage( Array( "file" => PLOG_CLASS_PATH."plugins/galleryfeeds/mimetypes.properties.php" ));
+            $mimeType = $types->getValue( $feedType );
+            if( !$mimeType ) $mimeType = "text/xml";
+            
+            return( $mimeType );
+        }
+    
+        /** 
+         * This is the main method of an Action class and the one providing the 
+         * business logic
+         */
+        function perform()
+        {
+            // load our view (a Smarty template)
+            $this->_view = new PluginTemplatedView( $this->_blogInfo, 
+                                                    "galleryfeeds",
+                                                    $this->_feedType,
+                                                    SMARTY_VIEW_CACHE_CHECK,
+                                                    Array( "blogId" => $this->_blogInfo->getId(),
+                                                           "albumId" => $this->_albumId,
+                                                           "feedType" => $this->_feedType ));                                                                                                                                 
+                                                           
+            // tell the browser about the right content type            
+            $this->_view->setContentType( $this->_getMimeType( $this->_feedType ));                                                                
+            
+            // nothing to do if the view is cached
+            if( $this->_view->isCached())
+                return true;        
+        
+            // load the albums by using the correct API method :)
+            $galleryResources = new GalleryResources();
+            $resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),
+                                                              $this->_albumId );
+            // load the album too
+            $galleryAlbums = new GalleryAlbums();
+            $album = $galleryAlbums->getAlbum( $this->_albumId );
+
+            // pass the resources to the template so that they can be rendered
+            $this->_view->setValue( "resources", $resources );
+            $this->_view->setValue( "album", $album );
+            $this->setCommonData();
+            
+            return( true );
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/galleryfeeds/locale/locale_en_UK.php	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/locale/locale_en_UK.php	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,3 @@
+<?php
+
+?>
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/mimetypes.properties.php
===================================================================
--- plugins/trunk/galleryfeeds/mimetypes.properties.php	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/mimetypes.properties.php	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,18 @@
+<?php
+
+#
+# please define here the custom MIME types that are needed by your playlists. The
+# definion of the array is very simple. As the key, we have the name of the templat
+# file without the .template (the same value as the "feed" parameter from URLs)
+#
+
+$config = Array( 
+
+  "rss20" => "text/xml",
+  "rss20audio" => "text/xml",
+  "rss20video" => "text/xml",
+  "m3u" => "audio/x-mpegurl"
+
+);
+
+?>
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/plugingalleryfeeds.class.php
===================================================================
--- plugins/trunk/galleryfeeds/plugingalleryfeeds.class.php	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/plugingalleryfeeds.class.php	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,45 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+    
+    /**
+     * Generates all sorts of feeds from our resources. This plugin is perfect for generating
+     * RSS 2.0 feeds with enclosures, for example
+     */
+    class PluginGalleryFeeds extends PluginBase
+    {
+    
+        function PluginGalleryFeeds()
+        {
+            $this->PluginBase();
+            
+            $this->id = "galleryfeeds";
+            $this->description = "Generates feeds/playlists based on the contents of albums";
+            $this->author = "The pLog Team";
+            // no need to fill this array after 1.0.1
+            $this->locales = Array();
+            
+            // register a new action for us
+            $this->registerBlogAction( "generateGalleryFeed", "GenerateFeedAction" );
+        }
+        
+        /**
+         * Given a GalleryAlbum object, this will automatically genereate the right link to the
+         * SMIL playlist, so that we don't have to manually type the same URL every time with
+         * only one different parameter
+         *
+         *Ê@param album A GalleryAlbum obejct
+         * @param feedType The type of feed that we're trying to generate. Defaults to "rss20".
+         * @return a string
+         */
+        function feed( $album, $feedType = "rss20" )
+        {
+            $rg =& $this->blogInfo->getBlogRequestGenerator();
+            $blogId = $this->blogInfo->getId();
+            $albumId = $album->getId();
+            $smilPage = $rg->getIndexUrl()."?op=generateGalleryFeed&amp;blogId={$blogId}&amp;albumId={$albumId}&amp;feed={$feedType}";
+            
+            return( $smilPage );
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/templates/m3u.template
===================================================================
--- plugins/trunk/galleryfeeds/templates/m3u.template	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/templates/m3u.template	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,8 @@
+{**
+  Generates M3U playlists from the audio files in our resources
+**}
+{foreach from=$resources item=resource}
+{if $resource->isSound()}
+{$url->resourceDownloadLink($resource)}
+{/if}
+{/foreach}
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/templates/rss20.template
===================================================================
--- plugins/trunk/galleryfeeds/templates/rss20.template	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/templates/rss20.template	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="{$locale->getCharset()}"?>
+<rss version="2.0" 
+	xmlns:content="http://purl.org/rss/1.0/modules/content/"
+	xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <channel>
+  <title>{$blog->getBlog()|escape} - {$album->getName()|escape}</title>
+  <link>{$url->blogLink()}</link>
+  <description>{$album->getDescription()|escape}</description>
+  <pubDate>{$locale->formatDate($now, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+  <generator>http://www.plogworld.net</generator>
+  {foreach from=$resources item=resource}
+  <item>
+   <title>{$resource->getFileName()|escape}</title>
+   <description>
+    {$resource->getDescription()|escape}
+   </description>
+   <link>{$url->resourceLink($resource)}</link>
+   <guid>{$url->resourceLink($resource)}</guid>
+   {assign var="resourceOwner" value=$blog->getOwnerInfo()}
+   <dc:creator>{$resourceOwner->getUsername()|escape}</dc:creator>
+   <category>{$album->getName()|escape}</category>
+   {assign var="resourceDate" value=$resource->getTimestamp()}
+   <pubDate>{$locale->formatDate($resourceDate, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+   <enclosure url="{$url->resourceDownloadLink($resource)}" type="{$resource->getMimeType()}" length="{$resource->getFileSize()}" />
+  </item>
+  {/foreach}
+ </channel>
+</rss>
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/templates/rss20audio.template
===================================================================
--- plugins/trunk/galleryfeeds/templates/rss20audio.template	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/templates/rss20audio.template	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="{$locale->getCharset()}"?>
+<rss version="2.0" 
+	xmlns:content="http://purl.org/rss/1.0/modules/content/"
+	xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <channel>
+  <title>{$blog->getBlog()|escape} - {$album->getName()|escape}</title>
+  <link>{$url->blogLink()}</link>
+  <description>{$album->getDescription()|escape}</description>
+  <pubDate>{$locale->formatDate($now, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+  <generator>http://www.plogworld.net</generator>
+  {foreach from=$resources item=resource}
+   {if $resource->isSound()}
+   <item>
+    <title>{$resource->getFileName()|escape}</title>
+    <description>
+     {$resource->getDescription()|escape}
+    </description>
+    <link>{$url->resourceLink($resource)}</link>
+    <guid>{$url->resourceLink($resource)}</guid>
+    {assign var="resourceOwner" value=$blog->getOwnerInfo()}
+    <dc:creator>{$resourceOwner->getUsername()|escape}</dc:creator>
+    <category>{$album->getName()|escape}</category>
+    {assign var="resourceDate" value=$resource->getTimestamp()}
+    <pubDate>{$locale->formatDate($resourceDate, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+    <enclosure url="{$url->resourceDownloadLink($resource)}" type="{$resource->getMimeType()}" length="{$resource->getFileSize()}" />
+   </item>
+   {/if}
+  {/foreach}
+ </channel>
+</rss>
\ No newline at end of file

Added: plugins/trunk/galleryfeeds/templates/rss20video.template
===================================================================
--- plugins/trunk/galleryfeeds/templates/rss20video.template	2005-05-06 15:49:05 UTC (rev 1954)
+++ plugins/trunk/galleryfeeds/templates/rss20video.template	2005-05-06 16:23:09 UTC (rev 1955)
@@ -0,0 +1,34 @@
+{**
+  This version of the rss20.template file only includes files which are video
+  in the feed. This one would be ideal for vloggers
+**}
+<?xml version="1.0" encoding="{$locale->getCharset()}"?>
+<rss version="2.0" 
+	xmlns:content="http://purl.org/rss/1.0/modules/content/"
+	xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <channel>
+  <title>{$blog->getBlog()|escape} - {$album->getName()|escape}</title>
+  <link>{$url->blogLink()}</link>
+  <description>{$album->getDescription()|escape}</description>
+  <pubDate>{$locale->formatDate($now, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+  <generator>http://www.plogworld.net</generator>
+  {foreach from=$resources item=resource}
+   {if $resource->isVideo()}
+    <item>
+    <title>{$resource->getFileName()|escape}</title>
+    <description>
+     {$resource->getDescription()|escape}
+    </description>
+    <link>{$url->resourceLink($resource)}</link>
+    <guid>{$url->resourceLink($resource)}</guid>
+    {assign var="resourceOwner" value=$blog->getOwnerInfo()}
+    <dc:creator>{$resourceOwner->getUsername()|escape}</dc:creator>
+    <category>{$album->getName()|escape}</category>
+    {assign var="resourceDate" value=$resource->getTimestamp()}
+    <pubDate>{$locale->formatDate($resourceDate, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+    <enclosure url="{$url->resourceDownloadLink($resource)}" type="{$resource->getMimeType()}" length="{$resource->getFileSize()}" />
+   </item>
+   {/if} 
+  {/foreach}
+ </channel>
+</rss>
\ No newline at end of file




More information about the pLog-svn mailing list