[pLog-svn] r802 - in plugins/trunk/gravatar: . avatars class class/action class/avatars locale templates

mark at devel.plogworld.net mark at devel.plogworld.net
Sun Jan 23 16:45:45 GMT 2005


Author: mark
Date: 2005-01-23 16:45:44 +0000 (Sun, 23 Jan 2005)
New Revision: 802

Added:
   plugins/trunk/gravatar/avatars/
   plugins/trunk/gravatar/avatars/baby.jpg
   plugins/trunk/gravatar/avatars/bigson.jpg
   plugins/trunk/gravatar/avatars/daugther.jpg
   plugins/trunk/gravatar/avatars/default.jpg
   plugins/trunk/gravatar/avatars/father.jpg
   plugins/trunk/gravatar/avatars/mother.jpg
   plugins/trunk/gravatar/class/
   plugins/trunk/gravatar/class/action/
   plugins/trunk/gravatar/class/action/plugingravatarconfigaction.class.php
   plugins/trunk/gravatar/class/action/plugingravatarupdateconfigaction.class.php
   plugins/trunk/gravatar/class/avatars/
   plugins/trunk/gravatar/class/avatars/avatars.class.php
   plugins/trunk/gravatar/locale/
   plugins/trunk/gravatar/locale/locale_en_UK.php
   plugins/trunk/gravatar/locale/locale_zh_TW.php
   plugins/trunk/gravatar/readme.txt
   plugins/trunk/gravatar/templates/
   plugins/trunk/gravatar/templates/gravatar.template
Modified:
   plugins/trunk/gravatar/plugingravatar.class.php
Log:
1. Move the description to readme.txt to reduce the pluign loading time.

2. Add UI implementatoin.

Added: plugins/trunk/gravatar/avatars/baby.jpg
===================================================================
(Binary files differ)


Property changes on: plugins/trunk/gravatar/avatars/baby.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plugins/trunk/gravatar/avatars/bigson.jpg
===================================================================
(Binary files differ)


Property changes on: plugins/trunk/gravatar/avatars/bigson.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plugins/trunk/gravatar/avatars/daugther.jpg
===================================================================
(Binary files differ)


Property changes on: plugins/trunk/gravatar/avatars/daugther.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plugins/trunk/gravatar/avatars/default.jpg
===================================================================
(Binary files differ)


Property changes on: plugins/trunk/gravatar/avatars/default.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plugins/trunk/gravatar/avatars/father.jpg
===================================================================
(Binary files differ)


Property changes on: plugins/trunk/gravatar/avatars/father.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plugins/trunk/gravatar/avatars/mother.jpg
===================================================================
(Binary files differ)


Property changes on: plugins/trunk/gravatar/avatars/mother.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plugins/trunk/gravatar/class/action/plugingravatarconfigaction.class.php
===================================================================
--- plugins/trunk/gravatar/class/action/plugingravatarconfigaction.class.php	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/class/action/plugingravatarconfigaction.class.php	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,44 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );	
+
+	/**
+	 * shows a form with the current configuration
+	 */
+	class PluginGravatarConfigAction extends AdminAction
+	{
+		
+		function PluginGravatarConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+			// load some configuration settings
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue( "plugin_gravatar_enabled" );
+			$rating = $blogSettings->getValue( "plugin_gravatar_rating" );
+			if ($rating == "") $rating = "G";
+			$default = $blogSettings->getValue( "plugin_gravatar_default" );
+			if ($default == "") $default = "default.jpg";
+			$size = $blogSettings->getValue( "plugin_gravatar_size" );
+			if ($size == "") $size = 40;	
+			
+			$avatars = Avatars::scanAvatarImages();	
+			
+			// create a view and export the settings to the template
+			$this->_view = new AdminPluginTemplatedView( $this->_blogInfo, "gravatar", "gravatar", true );
+			$this->_view->setValue( "pluginEnabled", $pluginEnabled );
+			$this->_view->setValue( "rating", $rating );
+			$this->_view->setValue( "default", $default );
+			$this->_view->setValue( "avatars", $avatars );
+			$this->_view->setValue( "size", $size );
+			
+			$this->setCommonData();
+			
+			return true;
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/gravatar/class/action/plugingravatarupdateconfigaction.class.php
===================================================================
--- plugins/trunk/gravatar/class/action/plugingravatarupdateconfigaction.class.php	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/class/action/plugingravatarupdateconfigaction.class.php	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,65 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+		
+	/**
+	 * updates the plugin configuration
+	 */
+	class PluginGravatarUpdateConfigAction extends AdminAction
+	{
+		var $_pluginEnabled;
+		var $_rating;
+		var $_default;
+		var $_size;
+		
+		function PluginGravatarUpdateConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function validate()
+		{
+            $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+            $this->_pluginEnabled = ($this->_pluginEnabled != "" );
+            $this->_rating = $this->_request->getValue( "rating" );
+            $this->_default = $this->_request->getValue( "default" );
+            $this->_size = $this->_request->getValue( "size" );
+
+			return true;
+		}
+		        
+		function perform()
+		{
+            // // update the plugin configurations to blog setting
+			$blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue( "plugin_gravatar_enabled", $this->_pluginEnabled );
+            $blogSettings->setValue( "plugin_gravatar_rating", $this->_rating );
+            $blogSettings->setValue( "plugin_gravatar_default", $this->_default );
+            $blogSettings->setValue( "plugin_gravatar_size", $this->_size );            
+            $this->_blogInfo->setSettings( $blogSettings ); 
+		
+			// save the blogs settings
+			$blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+                $this->_view = new AdminErrorView( $this->_blogInfo );
+                $this->_view->setValue( "message", $this->_locale->tr("error_updating_settings"));
+                $this->setCommonData();
+
+                return false;
+            }
+			
+			// if everything went ok...
+            $this->_blogInfo->setSettings( $blogSettings );
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+			
+			$this->_view = new AdminMessageView( $this->_blogInfo );
+			$this->_view->setMessage( $this->_locale->tr("gravatar_settings_saved_ok"));
+			$this->setCommonData();
+            
+            return true;		
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/gravatar/class/avatars/avatars.class.php
===================================================================
--- plugins/trunk/gravatar/class/avatars/avatars.class.php	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/class/avatars/avatars.class.php	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,42 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+    include_once( PLOG_CLASS_PATH."class/misc/glob.class.php" );
+    include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );    
+	
+	/**
+	 * deals with smileys in disk and so on...
+	 */
+	class Avatars extends Object
+	{
+        /**
+         * tries to detect and load all the different avatas that can be found in the
+         * avatars folder, so that the user can chose the nicest one :)
+		 *
+		 * @static
+         */
+        function scanAvatarImages()
+        {
+            $gifImages = Glob::glob( AVATAR_FILE_PATH , '*.gif');
+            $jpgImages = Glob::glob( AVATAR_FILE_PATH , '*.jpg');
+            
+            $avatarImages = Array();
+            
+            if ( !empty($gifImages) ) {
+                foreach($gifImages as $image) {
+                    $imageName =  basename($image);
+                    array_push( $avatarImages, $imageName);
+                }
+            }
+
+            if ( !empty($jpgImages) ) {
+                foreach($jpgImages as $image) {
+                    $imageName =  basename($image);
+                    array_push( $avatarImages, $imageName);
+                }
+            }                       
+            
+            return $avatarImages;
+        }		
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/gravatar/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/gravatar/locale/locale_en_UK.php	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/locale/locale_en_UK.php	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,10 @@
+<?php
+$messages["gravatar_rating"] = "Allowed Avatar Rating";
+$messages["gravatar_default"] = "Choose Default Avatar (This Avatar will showed if the commenter does not have Gravatar Account)";
+$messages["gravatar_avatars"] = "Available Avatars";
+$messages["gravatar_size"] = "Avatar Size";
+$messages["gravatar_plugin_configuration"] = "Configuration this plugin";
+$messages["gravatar_plugin_enabled"] = "Enable this plugin";
+$messages["gravatar_plugin"] = "Gravatar Plugin";
+$messages["gravatar_settings_saved_ok"] = "Gravatar settings saved successfully!";
+?>
\ No newline at end of file

Added: plugins/trunk/gravatar/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/gravatar/locale/locale_zh_TW.php	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/locale/locale_zh_TW.php	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,10 @@
+<?php
+$messages["gravatar_rating"] = "允許肖像分級";
+$messages["gravatar_default"] = "選擇預設肖像(當迴響訪客沒有全球肖像認證帳號時所顯示的肖像)";
+$messages["gravatar_avatars"] = "現有肖像";
+$messages["gravatar_size"] = "肖像顯示大小";
+$messages["gravatar_plugin_configuration"] = "外掛程式設定";
+$messages["gravatar_plugin_enabled"] = "啟動外掛程式";
+$messages["gravatar_plugin"] = "全球認證肖像外掛程式";
+$messages["gravatar_settings_saved_ok"] = "全球認證肖像設定儲存成功。";
+?>
\ No newline at end of file

Modified: plugins/trunk/gravatar/plugingravatar.class.php
===================================================================
--- plugins/trunk/gravatar/plugingravatar.class.php	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/plugingravatar.class.php	2005-01-23 16:45:44 UTC (rev 802)
@@ -2,46 +2,101 @@
 
     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/dao/blogs.class.php" );
+    include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );	
+    include_once( PLOG_CLASS_PATH."plugins/gravatar/class/avatars/avatars.class.php" );
+    
     /**
      * Mostra un avatar a cada comentari descarregant-lo de Gravatar.com. Versió 0.2
      */
 
+    define( "AVATAR_FILE_PATH", PLOG_CLASS_PATH."/plugins/gravatar/avatars/" );
 
-    class PluginGravatar extends PluginBase {
+    class PluginGravatar extends PluginBase
+    {
+        var $prefix;
+        var $pluginEnabled;
+        var $rating;
+        var $default;
+        var $size;
 
         function PluginGravatar()
         {
             $this->PluginBase();
-            $this->desc = "<p>Returns the URL of an (gr)avatar for every comment. The image is loaded from Gravatar.com</p>
-                           <p>In order to use, simply include the following:<br/><br/>
-                           <strongs>{\$gravatar->gravatar(\$comment,\$rating,\$default,\$size)}</strong><br/>
-                           <p>Where \$default is the URL of the default image that will be shown in case there is no gravatar available
-                           or if the user did not give an email address. \$size is the desired size in pixels of the gravatar.</p>
-                           <p>Example:</p>
-                           &lt;img class=\"gravatar\" <br/>
-                           src=\"{\$gravatar->gravatar(\$comment,\"R\",\"http://lalah.com/default.png\",40)}\" <br/>
-                           alt=\"{\$comment->getUsername()}\" <br/>
-                           title=\"{\$comment->getUsername()}\" <br/>
-                           width=\"40\" height=\"40\" /&gt;";
-            $this->author = "Dani Armengol";
-            $this->id = "gravatar";
-            $this->locales = Array();
+
+            $this->id = "gravatar";            
+            $this->author = "Original by Dani Armengol, Modified by Mark Wu";
+            $this->desc = "Returns the URL of an (gr)avatar for every comment. The image is loaded from Gravatar.com";
+
+            $this->locales = Array( "en_UK" , "zh_TW" );
+
+            $this->init();            
         }
+        
+		function init()
+		{
+            $this->registerAdminAction( "gravatar", "PluginGravatarConfigAction" );
+			$this->registerAdminAction( "updateGravatarConfig", "PluginGravatarUpdateConfigAction" );
+			
+			$menu =& Menu::getMenu();
+			if( !$menu->entryExists( "/menu/controlCenter/manageAppearancePlugins" ))						
+				$this->addMenuEntry( "/menu/controlCenter", "manageAppearancePlugins", "", "", true, false );			
+            $this->addMenuEntry( "/menu/controlCenter/manageAppearancePlugins", "Gravatar", "?op=gravatar", "" );
+		}
 
-        function gravatar($comment,$rating,$default,$size)
+		function register()
+		{
+		    $blogSettings = $this->blogInfo->getSettings();
+		    $this->pluginEnabled = $blogSettings->getValue( "plugin_gravatar_enabled" );
+		    $this->rating = $blogSettings->getValue( "plugin_gravatar_rating" );
+	        $this->default = $blogSettings->getValue( "plugin_gravatar_default" );
+	        $this->size = $blogSettings->getValue( "plugin_gravatar_size" );	
+	    }
+	    
+	    function isEnabled()
+	    {
+	        return $this->pluginEnabled;
+	    }
+
+	    function getSize()
+	    {
+	        return $this->size;
+	    } 	       
+
+        /**
+         * Returns the gravatar object from www.gravatar.com
+         */
+         
+        function gravatar($comment, $rating="", $default = "", $size="" )
         {
-            if($rating != "G" && $rating != "PG" && $rating != "R" && $rating != "X")
-                $rating = "R";
+			if ( $rating == "") {
+			    $rating = $this->rating;
+			} else {
+			    if ( $rating != "G" && $rating != "PG" && $rating != "R" && $rating != "X" )
+			        $rating = "G";
+			}
+
+			if ( $default == "" ) {
+			    $rg =& RequestGenerator::getRequestGenerator( $this->blogInfo );
+				$default = $rg->getUrl( "/plugins/gravatar/avatars/".$this->default);
+            }
+			
+			if ( $size == "") {
+			    $size = $this->size;
+			} else {
+			    if ( $size < 30 || $size > 80)
+			        $size = 40;
+			
+			}          
                 
             if($comment->getUserEmail() != "")
             {
-	            $grav_url = "http://www.gravatar.com/avatar.php?rating=".$rating."&amp;gravatar_id=".md5($comment->getUserEmail())."&amp;default=".urlencode($default)."&amp;size=".$size;
+	            $gravatar_url = "http://www.gravatar.com/avatar.php?rating=".$rating."&gravatar_id=".md5($comment->getUserEmail())."&default=".urlencode($default)."&size=".$size;
             } else {
-	            $grav_url = $default;
+	            $gravatar_url = $default;
             }
 
-            return $grav_url;
+            return $gravatar_url;
         }
     }
 ?>

Added: plugins/trunk/gravatar/readme.txt
===================================================================
--- plugins/trunk/gravatar/readme.txt	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/readme.txt	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,21 @@
+Plugin: Gravatar
+Author: Original by Dani Armengol, Modified by Mark Wu
+Release Date: 2005/01/23
+Version: 1.0
+
+Returns the URL of an (gr)avatar for every comment. The image is loaded from Gravatar.com
+
+In order to use, simply include the following:
+1. $gravatar->isEnabled() to check the plugin is enabled or not. 
+2. $gravatar->gravatar($comment,$rating,$default,$size) to get to Avatar from Gravatar.com
+
+Where:
+1. $rating is the allowed rating of avatar. Default is "G"
+2. $default is the URL of the default image that will be shown in case there is no gravatar available or if the user did not give an email address. You also can choose your default avatar from configuration panel. Default is "default.jpg"
+3. $size is the desired size in pixels of the gravatar. Default is 40.
+
+Example:
+Add the following code to postandcomments.template:
+{if $gravatar->isEnabled()}
+<img src="{$gravatar->gravatar($comment)}" width="{$gravatar->getSize()}" height="{$gravatar->getSize()}" align="left" />
+{/if}
\ No newline at end of file

Added: plugins/trunk/gravatar/templates/gravatar.template
===================================================================
--- plugins/trunk/gravatar/templates/gravatar.template	2005-01-23 16:44:26 UTC (rev 801)
+++ plugins/trunk/gravatar/templates/gravatar.template	2005-01-23 16:45:44 UTC (rev 802)
@@ -0,0 +1,47 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=Gravatar title=$locale->tr("gravatar_plugin")}
+<form name="gravatarPluginConfig" method="post">
+ {$locale->tr("gravatar_plugin_enabled")}
+ <input type="checkbox" name="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" /><br/>
+ <fieldset>
+ <legend>{$locale->tr("gravatar_plugin_configuration")}</legend> 
+ {$locale->tr("gravatar_rating")}
+ <select name="rating">
+  <option value="G" {if $rating=="G"}selected="selected"{/if}>G</option>
+  <option value="PG" {if $rating=="PG"}selected="selected"{/if}>PG</option>
+  <option value="R" {if $rating=="R"}selected="selected"{/if}>R</option>
+  <option value="X" {if $rating=="X"}selected="selected"{/if}>X</option>
+ </select><br/>
+ {$locale->tr("gravatar_size")}
+ <select name="size">
+  <option value="30" {if $size==30}selected="selected"{/if}>30x30</option>
+  <option value="40" {if $size==40}selected="selected"{/if}>40x40</option>
+  <option value="50" {if $size==50}selected="selected"{/if}>50x50</option>
+  <option value="60" {if $size==60}selected="selected"{/if}>60x60</option>
+  <option value="70" {if $size==70}selected="selected"{/if}>70x70</option>
+  <option value="80" {if $size==80}selected="selected"{/if}>80x80</option>
+ </select><br/>  
+ {$locale->tr("gravatar_default")}
+ <fieldset>
+ <legend>{$locale->tr("gravatar_avatars")}</legend> 
+ <table>
+ {foreach from=$avatars item=avatar}
+  <tr>
+   <td>
+    <input type="radio" name="default" value="{$avatar}" {if $default==$avatar} checked="checked" {/if} /> {$avatar}
+   </td>
+   <td>
+    <img src="{$url->getUrl("/plugins/gravatar/avatars/$avatar")}" alt="{$avatar}" />
+   </td> 
+  </tr> 
+ {/foreach}
+ </table>
+ </fieldset>
+ <br/>
+ </fieldset>
+ <br/>
+ <input type="hidden" name="op" value="updateGravatarConfig" />
+ <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file




More information about the pLog-svn mailing list