[pLog-svn] r5191 - in plugins/branches/lifetype-1.2: . technoratitagcloud technoratitagcloud/class technoratitagcloud/class/action technoratitagcloud/class/ducksoup technoratitagcloud/class/view technoratitagcloud/locale technoratitagcloud/templates

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Mar 25 16:08:15 EDT 2007


Author: oscar
Date: 2007-03-25 16:08:15 -0400 (Sun, 25 Mar 2007)
New Revision: 5191

Added:
   plugins/branches/lifetype-1.2/technoratitagcloud/
   plugins/branches/lifetype-1.2/technoratitagcloud/Readme.txt
   plugins/branches/lifetype-1.2/technoratitagcloud/class/
   plugins/branches/lifetype-1.2/technoratitagcloud/class/action/
   plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudconfigaction.class.php
   plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudupdateconfigaction.class.php
   plugins/branches/lifetype-1.2/technoratitagcloud/class/ducksoup/
   plugins/branches/lifetype-1.2/technoratitagcloud/class/ducksoup/ducksoup.class.php
   plugins/branches/lifetype-1.2/technoratitagcloud/class/view/
   plugins/branches/lifetype-1.2/technoratitagcloud/class/view/plugintechnoratitagcloudconfigview.class.php
   plugins/branches/lifetype-1.2/technoratitagcloud/locale/
   plugins/branches/lifetype-1.2/technoratitagcloud/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/technoratitagcloud/plugintechnoratitagcloud.class.php
   plugins/branches/lifetype-1.2/technoratitagcloud/templates/
   plugins/branches/lifetype-1.2/technoratitagcloud/templates/technoratitagcloud.template
Log:
Added a plugin to display your technorati tag cloud, as provided in http://bugs.lifetype.net/view.php?id=1232 (thanks to user 'spollo')


Added: plugins/branches/lifetype-1.2/technoratitagcloud/Readme.txt
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/Readme.txt	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/Readme.txt	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,19 @@
+This is a plugin that I wrote using Duck Soup(http://kailashnadh.name/ducksoup/), the great API library developed by Kailash Nadh.
+
+In order for it to work you will need to get a Developer Key from Technorati(http://www.technorati.com/developers/apikey.html).
+
+This plugin will download your technorati tags (using your developer key) and display them in a tag cloud, assigning the font-size and font-weight properties depending on the occurrences of those tags in you technorati account. The units for font-size are in .em and the valid values for font-weight is any number between 100 and 900.
+
+The setup is pretty straight-forward, just enter your API key, how many tags you want to be downloaded from technorati and the font-size and font-weight properties.  The plugin creates a file on lifetype's temp folder and  stores/read the cloud from there. The tag cloud is regenerated everytime there is a post-add, post-edit and post-delete event, as well as everytime there are changes to the plugin settings.
+
+You will need to edit your template and add the following code where you want your cloud to appear:
+
+{if $technoratitagcloud->isEnabled()}
+<div id="technoraticloud">
+{$technoratitagcloud->gettechnoratiTagCloud()}
+</div>
+{/if}
+
+This plugin has been tested to work with the latest development version of LT 1.2.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Added: plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudconfigaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudconfigaction.class.php	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,27 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/technoratitagcloud/class/view/plugintechnoratitagcloudconfigview.class.php" );	
+
+	/**
+	 * shows a form with the current configuration
+	 */
+	class PluginTechnoratiTagCloudConfigAction extends AdminAction
+	{
+		
+		function PluginTechnoratiTagCloudConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+            $this->_view = new PluginTechnoratiTagCloudConfigView( $this->_blogInfo );
+			
+			$this->setCommonData();
+			
+			return true;
+		}
+	}
+?>

Added: plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudupdateconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudupdateconfigaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/class/action/plugintechnoratitagcloudupdateconfigaction.class.php	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,119 @@
+<?php
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/technoratitagcloud/class/view/plugintechnoratitagcloudconfigview.class.php" );	
+		
+	/**
+	 * updates the plugin configuration
+	 */
+	class PluginTechnoratiTagCloudUpdateConfigAction extends AdminAction
+	{
+		var $_pluginEnabled;
+		var $_apikey;
+		var $_showtags;
+		var $_maxsize;
+		var $_minsize;
+		var $_maxweight;
+		var $_minweight;
+		
+		
+		function PluginTechnoratiTagCloudUpdateConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function validate()
+		{
+            $errorMessages = array();
+			$this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ 	                $this->_pluginEnabled = ($this->_pluginEnabled != "" );			
+            
+			$this->_apikey = $this->_request->getValue( "apikey" );
+			if( $this->_pluginEnabled && empty($this->_apikey) ) {
+                $errorMessages[] = "technoratitagcloud_error_apikey";
+				$isError = true;
+			}
+			
+			$this->_showtags = $this->_request->getValue( "showtags" );
+			if( $this->_pluginEnabled && empty($this->_showtags) ) {
+				$this->_showtags = "20";
+			}
+
+			$this->_maxsize = $this->_request->getValue( "maxsize" );
+			if( $this->_pluginEnabled && empty($this->_maxsize) ) {
+				$this->_maxsize = "1.5";
+			}
+			
+			$this->_minsize = $this->_request->getValue( "minsize" );
+			if( $this->_pluginEnabled && empty($this->_minsize) ) {
+				$this->_minsize = "0.65";
+			}
+			
+			$this->_maxweight = $this->_request->getValue( "maxweight" );
+			if( $this->_pluginEnabled && empty($this->_maxweight) ) {
+				$this->_maxweight = "200";
+			}
+			
+			$this->_minweight = $this->_request->getValue( "minweight" );
+			if( $this->_pluginEnabled && empty($this->_minweight) ) {
+				$this->_minweight = "100";
+			}
+			
+			if( count($errorMessages) > 0 ) {
+                $this->_view = new PluginTechnoratiTagCloudConfigView( $this->_blogInfo );
+				$allerror='';
+				foreach( $errorMessages as $error ){
+					$allerror .= $this->_locale->tr($error).'<br />';
+				}
+		$this->_view->setErrorMessage( $this->_locale->tr($allerror));
+                $this->setCommonData();
+                return false;
+            }        	                
+			
+			return true;
+		}
+		        
+		function perform()
+		{
+            // // update the plugin configurations to blog setting
+			$blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue( "plugin_technoratitagcloud_enabled", $this->_pluginEnabled );
+            $blogSettings->setValue( "plugin_technoratitagcloud_apikey", $this->_apikey );
+            $blogSettings->setValue( "plugin_technoratitagcloud_showtags", $this->_showtags );
+			$blogSettings->setValue( "plugin_technoratitagcloud_maxsize", $this->_maxsize );
+			$blogSettings->setValue( "plugin_technoratitagcloud_minsize", $this->_minsize );
+			$blogSettings->setValue( "plugin_technoratitagcloud_maxweight", $this->_maxweight );
+			$blogSettings->setValue( "plugin_technoratitagcloud_minweight", $this->_minweight );
+            $this->_blogInfo->setSettings( $blogSettings ); 
+		
+			// save the blogs settings
+			$blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo )) {
+                $this->_view = new PluginTechnoratiTagCloudConfigView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $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 PluginTechnoratiTagCloudConfigView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("technoratitagcloud_settings_saved_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());				
+			
+			//regenerate the cloud
+			$plugins = $this->_pm->getPlugins();
+			$plugin = $plugins["technoratitagcloud"];
+            $plugin->createTechnoratiTagCloud();
+            
+            return true;		
+		}
+	}
+?>

Added: plugins/branches/lifetype-1.2/technoratitagcloud/class/ducksoup/ducksoup.class.php
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/class/ducksoup/ducksoup.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/class/ducksoup/ducksoup.class.php	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,445 @@
+<?php
+
+//	error_reporting(error_reporting() & ~E_STRICT);
+	// helps run on php5. e_strict doesnt do any good anyway ;)
+
+/* =========================================
+
+	DuckSoup v1.2 (Technorati API library)
+	October 08 2006
+	
+	Developed by
+		Kailash Nadh
+		mail at kailashnadh.name , http://kailashnadh.name
+	
+	Changes by
+		Yassen Damyanov
+		yassen_tis at yahoo.com
+
+	DuckSoup website
+		http://kaialshnadh.name/ducksoup
+
+	Documentation
+		http://kailashnadh.name/ducksoup/docs
+
+
+	Permission is hereby granted, free of charge, to any person
+	obtaining a copy of this software and associated documentation files
+	("DuckSoup"), to deal in the DuckSoup without restriction,
+	including without limitation the rights to use, copy, modify, merge,
+	publish, distribute, sublicense, and/or sell copies of the DuckSoup,
+	and to permit persons to whom the Software is furnished to do so,
+	subject to the following conditions:
+
+	DuckSoup (c) 2005-2006, Kailash Nadh (http://kailashnadh.name)
+
+	The above copyright notice and this permission notice shall be
+	included in all copies or substantial portions of the DuckSoup.
+
+	// --- Please see disclaimer.txt for the disclaimer
+
+	// --- v1.1a changes
+	   - added support for 'authority' parameter of 'search' API
+
+	// --- v1.1 changes
+	   - fixed the compatibility problem with PHP4 and PHP5
+	   - Added Technorati's new BlogPostTags api
+
+
+  ========================================= */
+
+
+
+class duckSoup {
+
+	var $api_fqdn="api.technorati.com";	// Technorati API server (no http:// and no trailing slash)
+
+	var $api_key;
+	var $type;
+	var $params;
+
+	var $query = "";
+
+
+	// ============= creates a tree (array) from the given xml data (only for internal use)
+	function xml2array($text) {
+	   $reg_exp = '/<(\w+)[^>]*>(.*?)<\/\\1>/s';
+	   preg_match_all($reg_exp, $text, $match);
+		   foreach ($match[1] as $key=>$val) {
+	       if ( preg_match($reg_exp, $match[2][$key]) ) {
+    	       $array[$val][] = $this->xml2array($match[2][$key]);
+	       } else {
+    	       $array[$val] = $match[2][$key];
+	       }
+	   }
+	   return $array;
+	}
+
+
+	// ============= Prepares the query based on the given api/parameters
+	function prepare_query() {
+
+		// == No API type has been specified
+		if(!$this->type) {
+			return false;
+		}
+
+		// urlencode the parameters
+		if(isset($this->params) && is_array($this->params)) {
+			while(list($key, $value) = each($this->params)) {
+				$this->params[$key]=urlencode($value);
+			}
+		}
+
+			// These routine prepares the query for each API type
+			switch($this->type) {
+
+				// ============== Cosmos api
+				case 'cosmos':
+
+						// == Prepare the parameters for the cosmos api
+						$cosmos['url']=(!isset($this->params['url'])) ? '' : "&url=".$this->params['url'];
+						$cosmos['type']=(!isset($this->params['type'])) ? '' :"&type=".$this->params['type'];
+						$cosmos['limit']=(!isset($this->params['limit'])) ? '' : "&limit=".$this->params['limit'];
+						$cosmos['start']=(!isset($this->params['start'])) ? '' : "&start=".$this->params['start'];
+						$cosmos['current']=(!isset($this->params['current'])) ? '' : "&current=".$this->params['current'];
+						//$cosmos['format']=(!isset($this->params['format'])) ? '' : "&format=".$this->params['format'];
+						$cosmos['claim']=(!isset($this->params['claim'])) ? '' : "&claim=".$this->params['claim'];
+						$cosmos['highlight']=(!isset($this->params['highlight'])) ? '' : "&highlight=".$this->params['highlight'];
+
+						// == Prepare the url for cosmos api query
+						$query="/cosmos?key={$this->api_key}{$cosmos['url']}";
+						$url.="{$cosmos['type']}{$cosmos['limit']}{$cosmos['start']}";
+						$url.="{$cosmos['current']}{$cosmos['claim']}{$cosmos['highlight']}";
+				break;
+
+
+				// ============== Search api
+				case 'search':
+
+						// == Prepare the parameters for the search api
+						$search['query']=(!isset($this->params['query'])) ? '' : "&query=".$this->params['query'];
+						$search['start']=(!isset($this->params['start'])) ? '' : "&start=".$this->params['start'];
+						$search['limit']=(!isset($this->params['limit'])) ? '' : "&limit=".$this->params['limit'];
+						//$search['format']=(!isset($this->params['format'])) ? '' : "&format=".$this->params['format'];
+						$search['claim']=(!isset($this->params['claim'])) ? '' : "&claim=".$this->params['claim'];
+						$search['language']=(!isset($this->params['language'])) ? '' : "&claim=".$this->params['language'];
+						$search['authority']=(!isset($this->params['authority'])) ? '' : "&authority=".$this->params['authority'];
+
+						// == Prepare the url for search api query
+						$query="/search?key={$this->api_key}{$search['query']}";
+						$query.="{$search['limit']}{$search['start']}{$search['claim']}{$search['language']}{$search['authority']}";
+				break;
+
+
+				// ============== getinfo api
+				case 'getinfo':
+
+						// == Prepare the parameters for the getinfo api
+						$getinfo['username']=(!isset($this->params['username'])) ? '' : "&username=".$this->params['username'];
+						//$getinfo['format']=(!isset($this->params['format'])) ? '' : "&format=".$this->params['format'];
+
+						// == Prepare the url for getinfo api query
+						$query="/getinfo?key={$this->api_key}{$getinfo['username']}";
+				break;
+
+
+				// ============== outbound api
+				case 'outbound':
+
+						// == Prepare the parameters for the getinfo api
+						$outbound['url']=(!isset($this->params['url'])) ? '' : "&url=".$this->params['url'];
+						//$outbound['format']=(!isset($this->params['format'])) ? '' : "&format=".$this->params['format'];
+						$outbound['start']=(!isset($this->params['start'])) ? '' : "&start=".$this->params['start'];
+
+						// == Prepare the url for getinfo api query
+						$query="/outbound?key={$this->api_key}{$outbound['url']}{$outbound['start']}";
+				break;
+
+
+				// ============== bloginfo api
+				case 'bloginfo':
+
+						// == Prepare the parameters for the getinfo api
+						$bloginfo['url']=(!isset($this->params['url'])) ? '' : "&url=".$this->params['url'];
+						//$bloginfo['format']=(!isset($this->params['format'])) ? '' : "&format=".$this->params['format'];
+
+						// == Prepare the url for getinfo api query
+						$query="/bloginfo?key={$this->api_key}{$bloginfo['url']}";
+				break;
+
+
+				// ============== taginfo api
+				case 'taginfo':
+
+						// == Prepare the parameters for the getinfo api
+						$taginfo['tag']=(!isset($this->params['tag'])) ? '' : "&tag=".$this->params['tag'];
+						$taginfo['limit']=(!isset($this->params['limit'])) ? '' : "&limit=".$this->params['limit'];
+						$taginfo['start']=(!isset($this->params['start'])) ? '' : "&start=".$this->params['start'];
+						//$taginfo['format']=(!isset($this->params['format'])) ? '' : "&format=".$this->params['format'];
+						$taginfo['excerptsize']=(!isset($this->params['excerptsize'])) ? '' : "&excerptsize=".$this->params['excerptsize'];
+						$taginfo['topexcerptsize']=(!isset($this->params['topexcerptsize'])) ? '' : "&topexcerptsize=".$this->params['topexcerptsize'];
+
+						// == Prepare the url for getinfo api query
+						$query="/tag?key={$this->api_key}{$taginfo['tag']}{$taginfo['limit']}";
+						$query.="{$taginfo['start']}{$taginfo['excerptsize']}{$taginfo['topexcerptsize']}";
+				break;
+
+
+				// ============== toptags api
+				case 'toptags':
+						// == Prepare the url for getinfo api query
+						$toptags['limit']=(!isset($this->params['limit'])) ? '' : "&limit=".$this->params['limit'];
+						$query="/toptags?key={$this->api_key}{$toptags['limit']}";
+				break;
+
+
+				// ============== keyinfo api
+				case 'keyinfo':
+						// == Prepare the url for getinfo api query
+						$query="/keyinfo?key={$this->api_key}";
+				break;
+
+				// ============== blogPostTags api
+				case 'blogposttags':
+						$blogposttags['url']=(!isset($this->params['url'])) ? '' : "&url=".$this->params['url'];
+						$blogposttags['limit']=(!isset($this->params['limit'])) ? '' : "&limit=".$this->params['limit'];
+
+						// == Prepare the url for blogPostTags api query
+						$query="/blogposttags?key={$this->api_key}{$blogposttags['url']}{$blogposttags['limit']}";
+				break;
+
+
+				// ============== No proper type ?
+				default:
+					return false;
+				break;
+
+			}
+
+		$this->query=$query;
+//		print "\nQuery: [$query]\n\n";
+
+	}
+
+
+	// ============= Fetches the data over http from Technorati
+	function fetch_content() {
+
+			// =========== Fetch the data
+			$data="";
+
+
+			// Get data by opening a socket connection. If this doesnt work, uncomment and use the routine below
+			$fp = @fsockopen($this->api_fqdn, 80, $errnum, $errstr, 15); // Open a socket connection
+				if($fp) { 
+					$fp_data="GET {$this->query} HTTP/1.0\r\n";
+					$fp_data.="Host: {$this->api_fqdn}\r\n"; 
+					$fp_data.="User-Agent: DuckSoup client\r\n";
+					$fp_data.="Connection: Close\r\n\r\n";
+					fputs($fp, $fp_data);
+						while(!feof($fp)) {
+							$data.=fgets($fp, 512);
+						}
+
+					fclose($fp);
+				} else {
+					return false;
+				}
+
+			// Clean up the data by removing the http headers
+			$data=substr($data, strpos($data, "\r\n\r\n"), strlen($data));
+
+			/* =============================
+			$url="http://".$this->api_fqdn.$this->query;
+			$fp=@fopen($url, "r");
+			if($fp) {
+				while(!feof($fp)) {
+					$data.=fgets($fp, 512);
+				}
+				fclose($fp);
+			} else {
+				return false;	// connection failed
+			}
+			================================ */
+
+		return $data;
+	}
+
+
+
+	// ============= The core function that processes technorati data
+	function get_content() {
+
+		// == No API type has been specified
+		if(!$this->type) {
+			return false;
+		}
+
+		$this->prepare_query();	// Prepare the query with all necessary variables
+		$data=$this->fetch_content();	// get data from Technorati
+		if(!$data) return false;
+
+		$xml_array=$this->xml2array($data);
+		if(!$xml_array) return false;
+
+		$parent=$xml_array['tapi'][0]['document']['0'];
+
+
+
+			// parses and formats data for each API
+			switch($this->type) {
+
+				// ============= format the cosmos data
+				case 'cosmos':
+					$cosmos_result=$parent['result'][0];
+
+					if(!isset($cosmos_result['error'])) {
+						// === the base weblog
+						$cosmos_result['weblog']=$cosmos_result['weblog'][0];
+
+						// ==== Author data if present (when claim=1)
+						if(isset($cosmos_result['weblog']['author']) && is_array($cosmos_result['weblog']['author'])) {
+							$cosmos_result['weblog']['author']=$cosmos_result['weblog']['author'][0];
+						}
+
+						$result['result']=$cosmos_result;
+
+						// === linked weblogs
+						if(isset($parent['item']) && is_array($parent['item'])) {
+							$n=0;
+							foreach($parent['item'] as $item) {
+								$item['weblog']=$item['weblog'][0];
+								$result['item'][$n]['weblog']=$item['weblog'][0];
+
+								// ==== Author data if present (when claim=1)		
+								if(isset($item['weblog']['author']) && is_array($item['weblog']['author'])) {
+									$item['weblog']['author']=$item['weblog']['author'][0];
+								}
+
+								$result['item'][$n]=$item;
+								$n++;
+							}
+						}
+					}
+				break;
+
+				// ============= format search data
+				case 'search':
+					$result['result']=$parent['result'][0];
+
+					if(!isset($result['error'])  && isset($parent['item']) && is_array($parent['item'])) {
+						$n=0;
+						foreach($parent['item'] as $item) {
+							$item['weblog']=$item['weblog'][0];
+							$result['item'][$n]['weblog']=$item['weblog']; //$result['item'][$n]['weblog']=$item['weblog'][0];
+
+							// === Author data if present (when claim=1)
+							if(isset($item['weblog']['author']) && is_array($item['weblog']['author'])) {
+								$item['weblog']['author']=$item['weblog']['author'][0];
+							}
+
+							$result['item'][$n]=$item;
+
+							$n++;
+						}
+					}
+				break;
+
+				// ============= format getinfo data
+				case 'getinfo':
+					$result['result']=$parent['result'][0];
+
+					if(!isset($result['error']) && isset($result['item']) && is_array($result['item'])) {
+						$n=0;
+						foreach($parent['item'] as $item) {
+							$item['weblog']=$item['weblog'][0];
+							$result['item'][$n]['weblog']=$item['weblog'][0];
+							$result['item'][$n]=$item;
+							$n++;
+						}
+					}
+				break;
+
+				// ============= format outbound data
+				case 'outbound':
+					$outbound_result=$parent['result'][0];
+
+					if(!isset($result['error'])) {
+						$outbound_result['weblog']=$outbound_result['weblog'][0];
+						$result['result']=$outbound_result;
+
+						if(isset($parent['item']) && is_array($parent['item'])) {
+							$n=0;
+							foreach($parent['item'] as $item) {
+								$item['weblog']=$item['weblog'][0];
+								$result['item'][$n]['weblog']=$item['weblog'][0];
+								$result['item'][$n]=$item;
+								$n++;
+							}
+						}
+					}
+				break;
+
+				// ============= format bloginfo data
+				case 'bloginfo':
+					$result['result']=$parent['result'][0];
+
+					if(!isset($result['error'])) {
+						$result['result']['weblog']=$result['result']['weblog'][0];
+					}
+				break;
+
+				// ============= format taginfo data
+				case 'taginfo':
+					$result['result']=$parent['result'][0];
+
+					if(!isset($result['error']) && isset($parent['item']) && is_array($parent['item'])) {
+						$n=0;
+						foreach($parent['item'] as $item) {
+							$item['weblog']=$item['weblog'][0];
+							$result['item'][$n]['weblog']=$item['weblog'][0];
+							$result['item'][$n]=$item;
+							$n++;
+						}
+					}
+				break;
+
+				// ============= format toptags data
+				case 'toptags':
+					$result['result']=$parent['result'][0];
+
+					if(!isset($result['error']) && isset($parent['item']) && is_array($parent['item'])) {
+						$n=0;
+						foreach($parent['item'] as $item) {
+							$result['item'][$n]=$item;
+							$n++;
+						}
+					}
+				break;
+
+				// ============= the keyinfo data
+				case 'keyinfo':
+					$result['result']=$parent['result'][0];
+				break;
+
+				// ============= the blogposttags data
+				case 'blogposttags':
+				$result['result']=$parent['result'][0];
+					if(!isset($result['error']) && isset($parent['item']) && is_array($parent['item'])) {
+						$n=0;
+						foreach($parent['item'] as $item) {
+							$result['item'][$n]=$item;
+							$n++;
+						}
+					}
+				break;
+
+			}
+
+		return $result;
+	}
+
+}
+
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/technoratitagcloud/class/view/plugintechnoratitagcloudconfigview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/class/view/plugintechnoratitagcloudconfigview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/class/view/plugintechnoratitagcloudconfigview.class.php	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,40 @@
+<?php
+	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+	/**
+	 * implements the main view of the technorati tag cloud plugin
+	 */
+	class PluginTechnoratiTagCloudConfigView extends AdminPluginTemplatedView
+	{
+
+		function PluginTechnoratiTagCloudConfigView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "technoratitagcloud", "technoratitagcloud" );
+		}
+		
+		function render()
+		{
+			// load some configuration settings
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue( "plugin_technoratitagcloud_enabled" );
+			$apikey = $blogSettings->getValue( "plugin_technoratitagcloud_apikey");
+			$showtags = $blogSettings->getValue( "plugin_technoratitagcloud_showtags");
+			$maxsize = $blogSettings->getValue( "plugin_technoratitagcloud_maxsize" );
+			$minsize = $blogSettings->getValue( "plugin_technoratitagcloud_minsize" );
+			$maxweight = $blogSettings->getValue( "plugin_technoratitagcloud_maxweight" );
+			$minweight = $blogSettings->getValue( "plugin_technoratitagcloud_minweight" );
+			
+			// create a view and export the settings to the template
+			$this->setValue( "pluginEnabled", $pluginEnabled );
+			$this->setValue( "apikey", $apikey );
+			$this->setValue( "showtags", $showtags );
+			$this->setValue( "maxsize", $maxsize );
+			$this->setValue( "minsize", $minsize );
+			$this->setValue( "maxweight", $maxweight );
+			$this->setValue( "minweight", $minweight );
+			
+			parent::render();
+		}
+	}
+?>

Added: plugins/branches/lifetype-1.2/technoratitagcloud/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/locale/locale_en_UK.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/locale/locale_en_UK.php	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,22 @@
+<?php
+$messages["technoratitagcloud"] = "Technorati Tag Cloud";
+$messages["TechnoratiTagCloud"] = "Technorati Tag Cloud";
+$messages["technoratitagcloud_plugin"] = "Technorati Tag Cloud Configuration";
+$messages["technoratitagcloud_plugin_enabled"] = "Enable Technorati Tag Cloud Plugin.";
+$messages["label_apikey"] = "Api Key";
+$messages["technoratitagcloud_apikey"] = "Please fill in your Api Key. You can find this code in Technorati Developer Center.";
+$messages["technoratitagcloud_error_apikey"] = "You must fill in the Api Key.";
+$messages["label_showtags"] = "Show Tags";
+$messages["label_maxsize"] = "Maximum Size";
+$messages["label_minsize"] = "Minimum Size";
+$messages["label_maxweight"] = "Maximum Weight";
+$messages["label_minweight"] = "Minimum Weight";
+$messages["technoratitagcloud_showtags"] = "How many tags you want to show (Default=20).";
+$messages["technoratitagcloud_minsize"] = "Minimum font size for the cloud. (Default=0.65).";
+$messages["technoratitagcloud_maxsize"] = "Maximum font size for the cloud. (Default=1.5).";
+$messages["technoratitagcloud_maxweight"] = "Maximum font size for the cloud. (valid values: 100, 200, ..., 900. Default=200).";
+$messages["technoratitagcloud_minweight"] = "Minimum font size for the cloud. (valid values: 100, 200, ..., 900. Default=100).";
+$messages["technoratitagcloud_error_showtags"] = "You must fill in how many tags.";
+$messages["technoratitagcloud_settings_saved_ok"] = "Technorati Tag Cloud configuration update successed !";
+
+?>

Added: plugins/branches/lifetype-1.2/technoratitagcloud/plugintechnoratitagcloud.class.php
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/plugintechnoratitagcloud.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/plugintechnoratitagcloud.class.php	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,170 @@
+<?php
+
+lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+lt_include( PLOG_CLASS_PATH."plugins/technoratitagcloud/class/ducksoup/ducksoup.class.php" );	
+    
+/**
+* offers features to insert Technorati Tags and display them in a Cloud.
+*/
+
+class PluginTechnoratiTagCloud extends PluginBase {
+	var $pluginEnabled;
+	var $apikey;
+	var $showtags;
+
+	function PluginTechnoratiTagCloud($source = ""){
+	$this->PluginBase($source);
+
+	$this->id = "technoratitagcloud";
+	$this->author = "Omar Romero";
+	$this->desc = "This plugin will download your technorati tags and display them as a tag cloud.";
+	$this->version = "20070315";
+
+	$this->locales = Array( "en_UK" );
+
+	if( $source == "admin" )
+		$this->initAdmin();
+	else
+		$this->init();
+	}
+
+	function init(){
+		// register the events we want
+		$this->registerNotification( EVENT_POST_POST_ADD );
+		$this->registerNotification( EVENT_POST_POST_UPDATE );
+		$this->registerNotification( EVENT_POST_POST_DELETE );    
+	}
+
+	function initAdmin(){
+		$this->init();
+		$this->registerAdminAction( "technoratitagcloud", "PluginTechnoratiTagCloudConfigAction" );
+		$this->registerAdminAction( "updatetechnoratitagcloud", "PluginTechnoratiTagCloudUpdateConfigAction" );
+		$menu =& Menu::getMenu();
+		$this->addMenuEntry( "/menu/controlCenter/manageSettings", "TechnoratiTagCloud", "?op=technoratitagcloud");
+	}	
+
+	function register(){
+		$blogSettings = $this->blogInfo->getSettings();
+		$this->pluginEnabled = $blogSettings->getValue( "plugin_technoratitagcloud_enabled" );
+		$this->apikey = $blogSettings->getValue( "plugin_technoratitagcloud_apikey" );
+		$this->showtags = $blogSettings->getValue( "plugin_technoratitagcloud_showtags" );
+		
+		$this->maxsize = $blogSettings->getValue( "plugin_technoratitagcloud_maxsize" );
+		$this->minsize = $blogSettings->getValue( "plugin_technoratitagcloud_minsize" );
+		$this->maxweight = $blogSettings->getValue( "plugin_technoratitagcloud_maxweight" );
+		$this->minweight = $blogSettings->getValue( "plugin_technoratitagcloud_minweight" );
+
+		//TODO: add values for the max and min weight and size
+
+		$config =& Config::getConfig();
+		$this->cacheFolder = $config->getValue('temp_folder');
+		$this->cacheFolder = $this->cacheFolder.'/technoratitagcloud/'.$this->blogInfo->getId();
+		if( !File::exists( $this->cacheFolder ))
+			File::createDir( $this->cacheFolder, 0755 );
+	}
+
+	function isEnabled(){
+		return $this->pluginEnabled;
+	}
+
+	function process( $eventType, $params ){
+		// make sure we're processing the right event!
+		if( $eventType != EVENT_POST_POST_ADD &&
+		    $eventType != EVENT_POST_POST_UPDATE &&
+		    $eventType != EVENT_POST_POST_DELETE ){
+			return true;
+		}
+		
+		// Load all of the settings for this blog
+		$this->register();
+		
+		// make sure that the plugin is enabled
+		if(!$this->isEnabled())
+			return true;
+
+		// Update the Technorati Tag Cloud
+		$this->createTechnoratiTagCloud();
+
+		return true;
+	}
+
+	function createTechnoratiTagCloud(){
+		$maxSize = $this->maxsize;
+		$maxWeight = $this->maxweight;
+		$minSize = $this->minsize;
+		$minWeight = $this->minweight;
+
+		$rg = $this->blogInfo->getBlogRequestGenerator();
+		$url = $rg->getBaseUrl();
+
+		$api = new duckSoup;
+		$api->api_key= $this->apikey;
+		$api->type = 'blogposttags';
+		$api->params = array('url' => $url, 'limit' => $this->showtags);
+		$items = $api->get_content();
+
+		if(!isset($items[item]))
+			return true;
+
+		foreach ($items[item] as $item)
+			$tagData[$item['tag']] = $item['posts'] ;
+		
+		arsort($tagData);
+		reset($tagData);
+		$max = current($tagData);
+		$min = end($tagData);
+
+		// Normalize the maximum values
+		$max = $max - $min;
+
+		// avoid a divide by zero if all of the words in our group
+		// occur exactly the same number of times.
+		if($max == 0)
+			$max = 1;
+
+
+		if (sizeof($tagData)) {
+			ksort($tagData);
+			$tags_string = "";	
+
+			// Create the Cloud
+			foreach( $tagData as $k=>$v) {
+				$link = urlencode($k);
+				$link = str_replace("%2F", "/", $link);
+				$disp = htmlspecialchars($k);			
+
+				$value = $v - $min;
+
+				$size = (($value *$maxSize)/$max) + $minSize;
+				$weight = (($value *$maxWeight)/$max) + $minWeight;
+
+				if ($size > $maxSize) $size = $maxSize;
+				if ($weight > $maxWeight) $weight = $maxWeight;
+				$weight = floor($weight / 100) * 100;
+
+				$tags_string .= "<a rel=\"nofollow\" href=\"http://technorati.com/tag/".$link."?from=".$url."\" style=\"font-size: ".$size."em; font-weight: ".$weight."; line-height: 90%\">".$disp."</a>...\n";
+			}
+		}
+
+		$saveFile = $this->cacheFolder."/tagcloud";  
+		$fh = fopen( $saveFile, "w");
+		if ($fh){
+			fwrite($fh, $tags_string);
+			File::chMod($saveFile, 0644);
+		}
+	}
+
+	function gettechnoratiTagCloud(){
+		$saveFile = $this->cacheFolder."/tagcloud";  
+		$Cloud = '';
+		if(File::isReadable($saveFile)){
+			$fh = fopen( $saveFile, "r");
+			if ($fh){
+				$Cloud = fread($fh, filesize($saveFile));
+				fclose($fh);
+			}
+		}
+		return $Cloud;
+	}
+}
+?>

Added: plugins/branches/lifetype-1.2/technoratitagcloud/templates/technoratitagcloud.template
===================================================================
--- plugins/branches/lifetype-1.2/technoratitagcloud/templates/technoratitagcloud.template	                        (rev 0)
+++ plugins/branches/lifetype-1.2/technoratitagcloud/templates/technoratitagcloud.template	2007-03-25 20:08:15 UTC (rev 5191)
@@ -0,0 +1,64 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=TechnoratiTagCloud title=$locale->tr("technoratitagcloud_plugin")}
+<form name="technoratitagcloudPluginConfig" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("label_configuration")}</legend>
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}  
+  
+  <div class="field">
+   <label for="pluginEnabled">{$locale->tr("label_enable")}</label>
+   <span class="required"></span>
+   <div class="formHelp">
+    <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" />{$locale->tr("technoratitagcloud_plugin_enabled")}
+   </div>
+  </div>
+  
+  <div class="field">
+   <label for="apikey">{$locale->tr("label_apikey")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("technoratitagcloud_apikey")}</div>
+   <input class="text" type="text" name="apikey" id="apikey" value="{$apikey}" width="20" />
+  </div>
+  
+  <div class="field">
+   <label for="showtags">{$locale->tr("label_showtags")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("technoratitagcloud_showtags")}</div>
+   <input class="text" type="text" name="showtags" id="showtags" value="{$showtags}" width="20" />
+  </div>
+
+  <div class="field">
+   <label for="maxsize">{$locale->tr("label_maxsize")}</label>
+   <div class="formHelp">{$locale->tr("technoratitagcloud_maxsize")}</div>
+   <input class="text" type="text" name="maxsize" id="maxsize" value="{$maxsize}" width="20" />
+  </div>
+
+  <div class="field">
+   <label for="showtags">{$locale->tr("label_minsize")}</label>
+   <div class="formHelp">{$locale->tr("technoratitagcloud_minsize")}</div>
+   <input class="text" type="text" name="minsize" id="minsize" value="{$minsize}" width="20" />
+  </div>
+
+  <div class="field">
+   <label for="showtags">{$locale->tr("label_maxweight")}</label>
+   <div class="formHelp">{$locale->tr("technoratitagcloud_maxweight")}</div>
+   <input class="text" type="text" name="maxweight" id="maxweight" value="{$maxweight}" width="20" />
+  </div>
+
+  <div class="field">
+   <label for="showtags">{$locale->tr("label_minweight")}</label>
+   <div class="formHelp">{$locale->tr("technoratitagcloud_minweight")}</div>
+   <input class="text" type="text" name="minweight" id="minweight" value="{$minweight}" width="20" />
+  </div>
+
+ </div>
+ 
+ <div class="buttons">
+  <input type="hidden" name="op" value="updatetechnoratitagcloud" />
+  <input type="reset" name="{$locale->tr("reset")}" />
+  <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}


More information about the pLog-svn mailing list