[pLog-svn] r5950 - plugins/branches/lifetype-1.2/tagcloud

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Mon Sep 24 15:04:37 EDT 2007


Author: jondaley
Date: 2007-09-24 15:04:36 -0400 (Mon, 24 Sep 2007)
New Revision: 5950

Modified:
   plugins/branches/lifetype-1.2/tagcloud/plugintagcloud.class.php
Log:
implemented item #1 on the recently created todo list - made this plugin more efficient by not switching between arrays and strings

Modified: plugins/branches/lifetype-1.2/tagcloud/plugintagcloud.class.php
===================================================================
--- plugins/branches/lifetype-1.2/tagcloud/plugintagcloud.class.php	2007-09-24 18:55:28 UTC (rev 5949)
+++ plugins/branches/lifetype-1.2/tagcloud/plugintagcloud.class.php	2007-09-24 19:04:36 UTC (rev 5950)
@@ -3,6 +3,7 @@
     lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
 
 define('TAGCLOUD_FILTER_REGEXP', '/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|!|=|;|×|\$|\/|:|{|}]\s*/i');
+define('MAX_TAGCLOUD_REPEATS_IN_ONE_POST', 3);
 
     /*
      * This plugin generate TagCloud for a specific Blog
@@ -167,37 +168,38 @@
         $data = array();
 		// get the articles content
 		while ($row = $result->FetchRow()) {
-			$data[] = $row['normalized_topic'] . " ";
+                // Add all words of the topic
+			$words = preg_split(TAGCLOUD_FILTER_REGEXP, strtolower($row['normalized_topic']));
+            foreach($words as $word){
+                if(empty($data[$word]))
+                    $data[$word] = 1;
+                else
+                    $data[$word]++;
+            }
 
                 // Limit the amount of occurrences in one post, to prevent
                 // one post from taking over all of the statistics.
-                // TODO: 1. don't switch back and forth between strings and
-                //          arrays so many times
-                //       2. Make the number of occurrences allowed a configuration
-                //          option
+                // TODO: Make the number of occurrences allowed a configuration
+                //       option
             $text_limited = array();
             $words = preg_split(TAGCLOUD_FILTER_REGEXP, strtolower($row['normalized_text']));
             foreach($words as $word){
                 if(empty($text_limited[$word])){
                     $text_limited[$word] = 1;
+                    if(empty($data[$word]))
+                        $data[$word] = 1;
+                    else
+                        $data[$word]++;
                 }
-                else if($text_limited[$word] == 1){
-                    $text_limited[$word] = 2;
+                else if($text_limited[$word] < MAX_TAGCLOUD_REPEATS_IN_ONE_POST){
+                    $text_limited[$word]++;
+                    $data[$word]++;
                 }
             }
-            foreach($text_limited as $word => $frequency){
-                for($i = 0; $i < $frequency; $i++)
-                    $data[] = $word . " ";
-            }
 		}	
-		$data = implode(' ',$data);
         
-		// Split keywords
-        $words = preg_split(TAGCLOUD_FILTER_REGEXP, strtolower($data));
-		$acv = array_count_values( $words );
-
 		// Remove unwanted keywords
-		foreach($acv as $k=>$v) {
+		foreach($data as $k=>$v) {
             $found = array_search($k,$bannedwords);
 			if(($found === FALSE || $found === NULL) && (strlen($k) >= $minWordLength)) {
 				if (isset($new_acv[$k])) 



More information about the pLog-svn mailing list