[pLog-svn] r2030 - in plog/branches/plog-1.0.1: class/dao templates/rss

Oscar Renalias phunkphorce at gmail.com
Fri May 20 10:16:23 GMT 2005


been meaning to do this for a while but it never seemed to be the
right time... But it's finally here for those into podcastig or
vlogging :-)

I've modified the resource chooser (the pop-up window one gets when
clicking the "add resource" link in the new post and edit post pages)
so that it adds an extra "id" attribute to each one of the links that
point to resources which contains the internal resource identifier of
the file. Otherwise I didn't see an easy way to keep track of the
links to files that had been added from the resource centre... and
nobody *usually* uses the "id" attribute of links nayway.

The new method Article::getArticleResources() basically extracts all
those id attributes via a regexp and then tries to load the
GalleryResource object with the given identifier. If it can be found,
it adds it to an array and if not it ignores it.

The result is an array of GalleryResource objects that can be handled
like any other object. We can query the description, size, link, etc.

The only downside is that this does not affect old posts, or links
which are manually added unless the "id" attribute is added
afterwards. As I said, I couldn't find an easy way to identify which
links point to local resources and which ones don't, so this seemed
the best alternative. Let me know if you can think of something better
:)

Oscar

On 5/20/05, oscar at devel.plogworld.net <oscar at devel.plogworld.net> wrote:
> Author: oscar
> Date: 2005-05-20 09:55:20 +0000 (Fri, 20 May 2005)
> New Revision: 2030
> 
> Modified:
>    plog/branches/plog-1.0.1/class/dao/article.class.php
>    plog/branches/plog-1.0.1/templates/rss/rss20.template
> Log:
> yay! native support for rss 2.0 enclosures :)
> 
> 
> Modified: plog/branches/plog-1.0.1/class/dao/article.class.php
> ===================================================================
> --- plog/branches/plog-1.0.1/class/dao/article.class.php        2005-05-20 08:04:30 UTC (rev 2029)
> +++ plog/branches/plog-1.0.1/class/dao/article.class.php        2005-05-20 09:55:20 UTC (rev 2030)
> @@ -828,6 +828,44 @@
>                         }
> 
>                         return( $this->_nextArticle );
> -               }
> +               }
> +
> +               /**
> +                * returns all the resources which are linked in this post. It basically looks
> +                * at the "id" attribute of all links. When the resource has been added via the
> +                * "add resource" pop-up window from the "new post" and "edit post" pages
> +                * from the admin interface contains something like "res_XX" where "XX" is the
> +                * internal id of the resource.
> +                *
> +                * If this id attribute is not found this method will not work. We could not find
> +                * a better way to identify these resources...
> +                *
> +                * @return An array of GalleryResource objects containing all the resources
> +                */
> +               function getArticleResources()
> +               {
> +                       include_once( PLOG_CLASS_PATH."class/data/stringutils.class.php" );
> +                       include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
> +
> +                       // extract all the "res_XX" values
> +            $regexp ="/<a.*id=\"res_([0-9]+)\".*>.*<\/a>/im";
> +                       $resources = Array();
> +                       $galleryResources = new GalleryResources();
> +               if( preg_match_all( $regexp, $this->getText(), $out, PREG_SET_ORDER )) {
> +                               // process the results
> +                               foreach( $out as $match ) {
> +                                       $resourceId = $match[1];
> +                                       // try to load the resource
> +                                       $resource = $galleryResources->getResource( $resourceId, $this->getBlog());
> +                                       if( $resource ) {
> +                                               // add it to the array
> +                                               $resources[] = $resource;
> +                                               // and continue...
> +                                       }
> +                               }
> +                       }
> +
> +                       return( $resources );
> +               }
>         }
>  ?>
> 
> Modified: plog/branches/plog-1.0.1/templates/rss/rss20.template
> ===================================================================
> --- plog/branches/plog-1.0.1/templates/rss/rss20.template       2005-05-20 08:04:30 UTC (rev 2029)
> +++ plog/branches/plog-1.0.1/templates/rss/rss20.template       2005-05-20 09:55:20 UTC (rev 2030)
> @@ -3,7 +3,7 @@
>  <rss version="2.0"
>         xmlns:content="http://purl.org/rss/1.0/modules/content/"
>         xmlns:dc="http://purl.org/dc/elements/1.1/"
> ->
> +>
>  {$locale->setLocale("en_UK")}
>   <channel>
>    <title>{$blog->getBlog()|escape}</title>
> @@ -27,7 +27,15 @@
>     {/foreach}
>     {assign var="postDate" value=$post->getDateObject()}
>     <pubDate>{$locale->formatDate($postDate, "%a, %d %b %Y %H:%M:%S")}</pubDate>
> -   <source url="{$url->rssLink("rss20")}">{$blog->getBlog()|escape}</source>
> +   <source url="{$url->rssLink("rss20")}">{$blog->getBlog()|escape}</source>
> +   {foreach from=$post->getArticleResources() item=resource}
> +    {** please uncomment the line below if you'd like to server everything but images, instead of
> +        only audio and video **}
> +    {** if !$resource->isImage() **}
> +    {if $resource->isSound() || $resource->isVideo()}
> +     <enclosure type="{$resource->getMimeType()}" length="{$resource->getFileSize()}" url="{$url->resourceDownloadLink($resource)}" />
> +    {/if}
> +   {/foreach}
>    </item>
>    {/foreach}
>   </channel>
> 
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>



More information about the pLog-svn mailing list