[pLog-svn] r2369 - in plugins/trunk: . tagcloud

oscar at devel.plogworld.net oscar at devel.plogworld.net
Wed Jul 27 19:38:38 GMT 2005


Author: oscar
Date: 2005-07-27 19:38:37 +0000 (Wed, 27 Jul 2005)
New Revision: 2369

Added:
   plugins/trunk/tagcloud/
   plugins/trunk/tagcloud/Readme.txt
   plugins/trunk/tagcloud/plugintagcloud.class.php
Log:
plugin submitted by user 'hatem' from the forums (http://forums.plogworld.net/viewtopic.php?t=2989)


Added: plugins/trunk/tagcloud/Readme.txt
===================================================================
--- plugins/trunk/tagcloud/Readme.txt	2005-07-27 19:03:28 UTC (rev 2368)
+++ plugins/trunk/tagcloud/Readme.txt	2005-07-27 19:38:37 UTC (rev 2369)
@@ -0,0 +1,28 @@
+Plugin: TagCloud
+Author: Hatem Ben Yacoub
+Release Date: 2005/07/25
+Version: a1.0.0
+
+This is an alpha plugin that generate tag cloud of latest articles.
+
+Usage:
+
+
+<!--TagCloud-->
+<h2> {$locale->tr("Tag cloud")} </h2>
+<ul>
+<li><div style="text-align:center">
+
+{assign var="BlogID" value=$blog->getId()}
+{ $tagcloud->getTagCloud($BlogID,20,30)}
+
+</div></li>
+</ul>
+
+
+TODO :
+
+Add admin interface
+Add css design
+Make it support all encoding (actually limited to [a-zA-Z])
+Generate tags by Categories
\ No newline at end of file


Property changes on: plugins/trunk/tagcloud/Readme.txt
___________________________________________________________________
Name: svn:executable
   + *

Added: plugins/trunk/tagcloud/plugintagcloud.class.php
===================================================================
--- plugins/trunk/tagcloud/plugintagcloud.class.php	2005-07-27 19:03:28 UTC (rev 2368)
+++ plugins/trunk/tagcloud/plugintagcloud.class.php	2005-07-27 19:38:37 UTC (rev 2369)
@@ -0,0 +1,102 @@
+<?php
+
+include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+
+    
+    /*
+     * This plugin generate TagCloud for a specific Blog
+     */
+     class PluginTagCloud extends PluginBase
+     {
+	
+	/*
+	* Constructor
+	*/
+	function PluginTagCloud(){
+	
+		$this->author = "Ben Yacoub Hatem";
+		$this->desc = "This plugin generate TagCloud for a specific Blog, usage
+			    :<br/>
+			    <b>{ \$tagcloud->getTagCloud(blogId,MaxArticles,MaxKeywords)}</b><br/><br/>
+			   <em> blogId</em> is the id of the Current Blog<br/>
+			   <em> MaxArticles</em> Latest articles to parse and generate the Tag Clouds<br/> 
+			   <em> MaxKeywords</em> maximum number of keywords to display<br/> <br/>
+			   getTagCloud return html of the Tag Cloud ready to use.<br/>
+			   See Readme for example usage.";
+		    
+		$this->PluginBase();
+		$this->db =& Db::getDb();
+		$this->id = "TagCloud";
+	}
+
+	/*
+	* Return cloud of the latest articles
+	*/
+	function getTagCloud($MaxArticles = 20, $MaxKeywords = 50){
+
+		$this->_prefix = Db::getPrefix();
+		$blogId = $this->blogInfo->getId();
+		
+	
+		$MaxArticles = mysql_escape_string($MaxArticles);
+	
+		$query = "SELECT t.normalized_text,t.normalized_topic FROM " . $this->_prefix . 
+		    "articles a, " . $this->_prefix."articles_text t" .
+		    " WHERE a.id=t.article_id " .
+		    " AND a.status=1 AND a.blog_id = " . $blogId . 
+		    " ORDER BY a.date DESC LIMIT 0,$MaxArticles;";
+	
+	
+		$result = $this->db->Execute($query);
+		    if(!$result || ($result->RecordCount() == 0))
+		    return false;
+	
+		// get the articles content
+		while ($row = $result->FetchRow()) {
+			$data[] = $row['normalized_topic'].' '.$row['normalized_text'];
+		}	
+		$data = implode(' ',$data);
+		
+		// Split keywords
+		$words = preg_split('/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|!|=|;|&#0215;|\$|\/|:|{|}]\s*/i', $data);
+		$acv = array_count_values( $words );
+		
+		// Remove unwanted keywords
+		$bannedwords = array( '', 'a', 'an', 'the', 'and', 'of', 'i', 'its' , 'to', 'is', 'in', 'with', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'after', 'all', 'almost', 'along', 'also', 'amp', 'another', 'any', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'being', 'best', 'better', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'dan', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'doesn', 'don', 'down', 'drive', 'e', 'each', 'easily', 'easy', 'edition', 'end', 'enough', 'even', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'gt', 'had', 'hard', 'has', 'have', 'he', 'her', 'here', 'how', 'if', 'into', 'isn', 'just', 'know', 'last', 'left', 'li', 'like', 'little', 'll', 'long', 'look', 'lot', 'lt', 'm', 'made', 'make', 'many', 'mb', 'me', 'menu', 'might', 'mm', 'more', 'most', 'much', 'name', 'nbsp', 'need', 'new', 'no', 'not', 'now', 'number', 'off', 'old', 'one', 'only', 'or', 'original', 'other', 'out', 'over', 'part', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'see', 'set', 'several', 'she', 'sherree', 'should', 'since', 'size', 'small', 'so', 'some', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'white', 'who', 'will', 'would', 'your');
+		$i = 0;
+		foreach($acv as $k=>$v) {
+			if (!array_search(strtolower($k),$bannedwords) and eregi("[a-zA-Z]",$k) and $i<=$MaxKeywords and strlen($k)>2) {
+				if (isset($new_acv[strtolower($k)] )) 
+					$new_acv[strtolower($k)] += $v;
+				else 
+					$new_acv[strtolower($k)] = $v;
+				$i++;
+			}
+		}
+		
+		// Sort the keys alphabetically.
+		ksort( $new_acv );
+		
+		// Create the Cloud
+		$Cloud = '';
+		foreach( $new_acv as $k=>$v) {
+			$size = $v*0.4;
+			$weight = $v*4;
+			
+			if ($size > 4) $size = 4;
+			if ($weight > 50) $weight = 50;
+
+            $rg = $this->blogInfo->getBlogRequestGenerator();
+            $baseUrl = $rg->getBaseUrl();		
+			$Cloud .= "<a href=\"{$baseUrl}?searchTerms=$k&op=Search&blogId={$blogId}\" style=\"font-size: {$size}em; font-weight: {$weight}\" title=\"$k\">$k</a> \n";
+		}
+	
+		return $Cloud;
+		
+    }
+	
+}
+        
+        
+?>
\ No newline at end of file


Property changes on: plugins/trunk/tagcloud/plugintagcloud.class.php
___________________________________________________________________
Name: svn:executable
   + *




More information about the pLog-svn mailing list