[pLog-svn] r4192 - in plugins/branches/lifetype-1.1/tagcloud: . class/action class/view locale templates

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri Oct 27 02:30:23 GMT 2006


Author: jondaley
Date: 2006-10-27 02:28:14 +0000 (Fri, 27 Oct 2006)
New Revision: 4192

Modified:
   plugins/branches/lifetype-1.1/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php
   plugins/branches/lifetype-1.1/tagcloud/class/view/plugintagcloudconfigview.class.php
   plugins/branches/lifetype-1.1/tagcloud/locale/locale_en_UK.php
   plugins/branches/lifetype-1.1/tagcloud/plugintagcloud.class.php
   plugins/branches/lifetype-1.1/tagcloud/templates/tagcloud.template
Log:
add minimum word length to config options, since I don't like the default.  fixed divide by zero issue http://bugs.lifetype.net/view.php?id=1096.  Simplified some code.

Modified: plugins/branches/lifetype-1.1/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php	2006-10-26 22:19:46 UTC (rev 4191)
+++ plugins/branches/lifetype-1.1/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php	2006-10-27 02:28:14 UTC (rev 4192)
@@ -16,6 +16,7 @@
         var $_minWeight;
         var $_maxWeight;
         var $_bannedKeywords;
+        var $_minWordLength;
 		
 		function PluginTagCloudUpdateConfigAction( $actionInfo, $request )
 		{
@@ -40,6 +41,7 @@
             $this->_maxWeight = $this->_request->getValue( "maxWeight" );
 
             $this->_bannedKeywords = $this->_request->getValue( "bannedKeywords" );
+            $this->_minWordLength = $this->_request->getValue( "minWordLength" );
             
             return true;
 		}
@@ -56,6 +58,7 @@
             $blogSettings->setValue( "plugin_tagcloud_min_weight", $this->_minWeight );
             $blogSettings->setValue( "plugin_tagcloud_max_weight", $this->_maxWeight );
             $blogSettings->setValue( "plugin_tagcloud_banned_keywords", $this->_bannedKeywords );
+            $blogSettings->setValue( "plugin_tagcloud_min_word_length", $this->_minWordLength );
             $this->_blogInfo->setSettings( $blogSettings ); 
 		
 			// save the blogs settings

Modified: plugins/branches/lifetype-1.1/tagcloud/class/view/plugintagcloudconfigview.class.php
===================================================================
--- plugins/branches/lifetype-1.1/tagcloud/class/view/plugintagcloudconfigview.class.php	2006-10-26 22:19:46 UTC (rev 4191)
+++ plugins/branches/lifetype-1.1/tagcloud/class/view/plugintagcloudconfigview.class.php	2006-10-27 02:28:14 UTC (rev 4192)
@@ -3,7 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
 
 	/**
-	 * implements the main view of the feed reader plugin
+	 * implements the main view of the tag cloud plugin
 	 */
 	class PluginTagCloudConfigView extends AdminPluginTemplatedView
 	{
@@ -26,9 +26,11 @@
 			$maxSize = $blogSettings->getValue( "plugin_tagcloud_max_size" );
 			if ($maxSize == "") $maxSize = 3;
 			$minWeight = $blogSettings->getValue( "plugin_tagcloud_min_weight" );
-			if ($minWeight == "") $minWeight = 3;
+			if ($minWeight == "") $minWeight = 100;
 			$maxWeight = $blogSettings->getValue( "plugin_tagcloud_max_weight" );
-			if ($maxWeight == "") $maxWeight = 10;
+			if ($maxWeight == "") $maxWeight = 900;
+			$minWordLength = $blogSettings->getValue( "plugin_tagcloud_min_word_length" );
+			if ($minWordLength == "") $minWordLength = 3;
 			$bannedKeywords = $blogSettings->getValue( "plugin_tagcloud_banned_keywords" );
 			if ($bannedKeywords == "") $bannedKeywords =  implode( ",", 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'));
 ;
@@ -42,6 +44,7 @@
 			$this->setValue( "minWeight", $minWeight );
 			$this->setValue( "maxWeight", $maxWeight );
 			$this->setValue( "bannedKeywords", $bannedKeywords );
+			$this->setValue( "minWordLength", $minWordLength );
 
 			parent::render();
 		}

Modified: plugins/branches/lifetype-1.1/tagcloud/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.1/tagcloud/locale/locale_en_UK.php	2006-10-26 22:19:46 UTC (rev 4191)
+++ plugins/branches/lifetype-1.1/tagcloud/locale/locale_en_UK.php	2006-10-27 02:28:14 UTC (rev 4192)
@@ -9,19 +9,21 @@
 $messages["tagcloud_keywords"] = "Number of tags in the tag cloud.";
 $messages["tagcloud_min_font"] = "Minimum font size for the cloud.";
 $messages["tagcloud_max_font"] = "Maximum font size for the cloud.";
-$messages["tagcloud_min_weight"] = "Minimum font size for the cloud.";
-$messages["tagcloud_max_weight"] = "Maximum font size for the cloud.";
+$messages["tagcloud_min_weight"] = "Minimum font size for the cloud. (valid values: 100, 200, ..., 900)";
+$messages["tagcloud_max_weight"] = "Maximum font size for the cloud. (valid values: 100, 200, ..., 900)";
 $messages["tagcloud_banned_keywords"] = "Keywords that should not appear in the tag cloud (comma separated).";
+$messages["tagcloud_min_word_length"] = "When searching for keywords, only use words this length or greater";
 
 $messages["tagcloud_settings_saved_ok"] = "Tag Cloud settings saved successfully!";
 
 $messages["label_configuration"] = "Configuration";
 $messages["label_enable"] = "Enable";
-$messages["max_articles"] = "Max Articles";
-$messages["max_keywords"] = "Max Keywords";
-$messages["min_font_size"] = "Min Font Size";
-$messages["max_font_size"] = "Max Font Size";
-$messages["min_font_weight"] = "Min Font Weight";
-$messages["max_font_weight"] = "Max Font Weight";
+$messages["max_articles"] = "Maximum Articles";
+$messages["max_keywords"] = "Maximum Keywords";
+$messages["min_font_size"] = "Minimum Font Size";
+$messages["max_font_size"] = "Maximum Font Size";
+$messages["min_font_weight"] = "Minimum Font Weight";
+$messages["max_font_weight"] = "Maximum Font Weight";
 $messages["banned_keywords"] = "Banned Keywords";
+$messages["min_word_length"] = "Minimum Keyword Length";
 ?>
\ No newline at end of file

Modified: plugins/branches/lifetype-1.1/tagcloud/plugintagcloud.class.php
===================================================================
--- plugins/branches/lifetype-1.1/tagcloud/plugintagcloud.class.php	2006-10-26 22:19:46 UTC (rev 4191)
+++ plugins/branches/lifetype-1.1/tagcloud/plugintagcloud.class.php	2006-10-27 02:28:14 UTC (rev 4192)
@@ -131,6 +131,7 @@
 
 		$minSize = $blogSettings->getValue( "plugin_tagcloud_min_size" );
 		$minWeight = $blogSettings->getValue( "plugin_tagcloud_min_weight" );	
+		$minWordLength = $blogSettings->getValue( "plugin_tagcloud_min_word_length" );	
 		
 		$bannedwords = $blogSettings->getValue( "plugin_tagcloud_banned_keywords" );
 		$bannedwords = explode(",", strtolower($bannedwords));
@@ -145,7 +146,7 @@
 	
 	
 		$result = $this->db->Execute($query);
-		    if(!$result || ($result->RecordCount() == 0))
+        if(!$result || ($result->RecordCount() == 0))
 		    return false;
 	
 		// get the articles content
@@ -161,7 +162,7 @@
 		// Remove unwanted keywords
 		foreach($acv as $k=>$v) {
             $found = array_search($k,$bannedwords);
-			if(($found === FALSE || $found === NULL) && strlen($k)>2) {
+			if(($found === FALSE || $found === NULL) && (strlen($k) >= $minWordLength)) {
 				if (isset($new_acv[$k])) 
 					$new_acv[$k] += $v;
 				else 
@@ -173,22 +174,21 @@
 		arsort($new_acv);
 		
 		// Now limit the array to $MaxKeywords
-		$chunkedArray = array_chunk( $new_acv, $MaxKeywords, true);
-		
-		// Get the first array chunk
-		$new_acv = $chunkedArray[0];
+        $new_acv = array_slice($new_acv, 0, $MaxKeywords);
 
-		$valueArray = array_values($new_acv);
-		$maxValue = current($valueArray);
-		
-		$minValue = end($valueArray);
-		
+            // get the highest and lowest occurrences
+        $maxValue = current($new_acv);
+        $minValue = end($new_acv);
+
 		// Sort the keys alphabetically.
 		ksort( $new_acv );
 		
 		// Normalize the max value
 		$maxValue = $maxValue - $minValue;
-
+            // avoid a divide by zero if all of the words in our group
+            // occur exactly the same number of times.
+        if($maxValue == 0)
+            $maxValue = 1;
 		
 		// Create the Cloud
 		$Cloud = '';

Modified: plugins/branches/lifetype-1.1/tagcloud/templates/tagcloud.template
===================================================================
--- plugins/branches/lifetype-1.1/tagcloud/templates/tagcloud.template	2006-10-26 22:19:46 UTC (rev 4191)
+++ plugins/branches/lifetype-1.1/tagcloud/templates/tagcloud.template	2006-10-27 02:28:14 UTC (rev 4192)
@@ -55,6 +55,13 @@
    <input class="text" type="text" name="maxWeight" id="maxWeight" value="{$maxWeight}" width="10" />
   </div>
 
+ <div class="field">
+   <label for="width">{$locale->tr("min_word_length")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("tagcloud_min_word_length")}</div>
+   <input class="text" type="text" name="minWordLength" id="minWordLength" value="{$minWordLength}" width="3" />
+  </div>
+
  
  <div class="field">
    <label for="width">{$locale->tr("banned_keywords")}</label>
@@ -73,4 +80,4 @@
  </div>
 </form>
 {include file="$admintemplatepath/footernavigation.template"}
-{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
+{include file="$admintemplatepath/footer.template"}



More information about the pLog-svn mailing list