[pLog-svn] r3648 - in plugins/branches/lifetype-1.0: . randomimage

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Jun 24 18:46:28 GMT 2006


Author: jondaley
Date: 2006-06-24 18:46:27 +0000 (Sat, 24 Jun 2006)
New Revision: 3648

Added:
   plugins/branches/lifetype-1.0/randomimage/
   plugins/branches/lifetype-1.0/randomimage/pluginrandomimage.class.php
   plugins/branches/lifetype-1.0/randomimage/readme.txt
Log:
plugin for grabbing a random picture for a given album

Added: plugins/branches/lifetype-1.0/randomimage/pluginrandomimage.class.php
===================================================================
--- plugins/branches/lifetype-1.0/randomimage/pluginrandomimage.class.php	2006-06-23 22:46:04 UTC (rev 3647)
+++ plugins/branches/lifetype-1.0/randomimage/pluginrandomimage.class.php	2006-06-24 18:46:27 UTC (rev 3648)
@@ -0,0 +1,94 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+    include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+
+define("RANDOMIMAGE_DEBUG", 1);
+
+    /**
+     * Plugin returns a randomly selected image from a given album
+     */
+    class PluginRandomImage extends PluginBase
+    {
+        function PluginRandomImage(){
+            $this->PluginBase();
+  
+            $this->id = "randomimage";
+            $this->author = "Jon Daley";
+            $this->desc = "This plugin offers a random image from a specific album.";
+  
+            $this->locales = Array( "en_UK" );
+        }
+
+        /**
+         * Returns the URL to a random image in $albumName
+         * previewType can be "PREVIEW", "MEDIUM" or "FULL"
+         */
+        function getImage($albumName, $previewType){
+            $albums = new GalleryAlbums();
+            $album = $albums->getAlbumByName($albumName);
+            if(!$album){
+                if(RANDOMIMAGE_DEBUG)
+                    return "no album '$albumName'";
+                else
+                    return "";
+            }
+
+            $resources = new GalleryResources();
+
+
+            $numResources = $resources->getNumUserResources(
+                $this->blogInfo->getOwner(), $album->getId(), GALLERY_RESOURCE_IMAGE);
+                
+            if($numResources <= 0){
+                if(RANDOMIMAGE_DEBUG)
+                    return "no resources in album: ".
+                        $this->blogInfo->getOwner()." ". $album->getId()." ".GALLERY_RESOURCE_IMAGE;
+                else
+                    return "";
+            }
+            
+            $whichResource = rand(0, $numResources-1);
+            
+            $query = "SELECT id FROM ".Db::getPrefix()."gallery_resources ".
+                "WHERE album_id = '".$album->getId()."' ".
+                "AND resource_type='".GALLERY_RESOURCE_IMAGE."' ".
+                "LIMIT $whichResource, 1";
+
+            $result = $albums->_db->Execute($query);
+            
+            if(!$result){
+                if(RANDOMIMAGE_DEBUG)
+                    return "bad query '".$query."'";
+                else
+                    return "";
+            }
+
+            if(!($row = $result->FetchRow())){
+                if(RANDOMIMAGE_DEBUG)
+                    return "no results";
+                else
+                    return "";
+            }
+
+            $resource = $resources->getResource($row["id"]);
+            if(!$resource){
+                if(RANDOMIMAGE_DEBUG)
+                    return "bad resource: '".$row["id"]."'";
+                else
+                    return "";
+            }
+
+            $rg = $this->blogInfo->getBlogRequestGenerator();
+            if($previewType == "FULL")
+                return $rg->resourceDownloadLink($resource);
+            else if($previewType == "MEDIUM")
+                return $rg->resourceMediumSizePreviewLink($resource);
+            else
+                return $rg->resourcePreviewLink($resource);
+
+        }
+        
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.0/randomimage/readme.txt
===================================================================
--- plugins/branches/lifetype-1.0/randomimage/readme.txt	2006-06-23 22:46:04 UTC (rev 3647)
+++ plugins/branches/lifetype-1.0/randomimage/readme.txt	2006-06-24 18:46:27 UTC (rev 3648)
@@ -0,0 +1,37 @@
+Random Image plugin for LifeType
+Author: Jon Daley
+Contact URL: http://limedaley.com/
+
+Example URL using this plugin: http://groshlink.net/ 
+  (click into any of the categories to see the images on the right)
+
+
+Example template code:
+
+{if $randomimage}
+  <li>
+    <a title="Eden (2006)" href="http://groshlink.net/album/eden_06">
+      <img src="{$randomimage->getImage("eden_06", "PREVIEW")}" border="0" />
+    </a>
+  </li>
+  <li>
+    <a title="Graduate & Faculty Ministry" href="http://groshlink.net/album/graduate__faculty_ministry">
+      <img src="{$randomimage->getImage("graduate__faculty_ministry", "PREVIEW")}" border="0" />
+    </a>
+  </li>
+  <li>
+    <a title="Pittsburgh" href="http://groshlink.net/album/pittsburgh">
+      <img src="{$randomimage->getImage("pittsburgh", "PREVIEW")}" border="0" />
+    </a>
+  </li>
+{/if}
+
+
+
+TODO:
+  Have the album links, and <a title> strings generated automatically
+   probably with a parameter or configuration options so it works for
+   everyone
+
+  Probably can get rid of the SQL query in the plugin and use class
+   methods for better compatibility



More information about the pLog-svn mailing list