From 492b9dde9bfdf8a8577c132289251dcd3dcf95aa Mon Sep 17 00:00:00 2001
From: unknown <Administrator@.(none)>
Date: Fri, 28 May 2010 00:51:34 +0800
Subject: [PATCH] maxwords minwords

---
 delete_orphaned_terms.module |   62 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/delete_orphaned_terms.module b/delete_orphaned_terms.module
index 1ac5d21..6455535 100644
--- a/delete_orphaned_terms.module
+++ b/delete_orphaned_terms.module
@@ -42,6 +42,12 @@ function __delete_orphaned_terms_defaults($var) {
   case 'delete_orphaned_terms_enablecron':
     return FALSE;
     break;
+  case 'delete_orphaned_terms_maxwords':
+    return 0;
+    break;
+  case 'delete_orphaned_terms_minwords':
+    return 0;
+    break;
   default:
     DIE('Don\'t know this option');
   }
@@ -170,6 +176,8 @@ function _delete_orphaned_terms($form, $form_state) {
     variable_set('delete_orphaned_terms_vocabs', $form_state['values']['delete_orphaned_terms_vocabs']);
   }
   $thres = _dot_get('delete_orphaned_terms_threshold');
+  $maxwords = _dot_get('delete_orphaned_terms_maxwords');
+  $minwords = _dot_get('delete_orphaned_terms_minwords');
 
   // assemble the terms to process and generate output
   $prune = array();
@@ -198,6 +206,38 @@ function _delete_orphaned_terms($form, $form_state) {
           }
         }
       }
+      if (($maxwords >0) && (str_word_count($term->name) > $maxwords)){
+        $prune_local[] = $term->tid;
+        $del_term++;
+        if ($sim) {
+          drupal_set_message(t('Would delete term #!tid: !name (!vname)', array('!tid' => $term->tid,
+                                                                                '!name' => $term->name,
+                                                                                '!vname' => $vocab->name)));
+        }
+        else {
+          if (!$cron) {
+            drupal_set_message(t('Deleting term #!tid: !name (!vname)', array('!tid' => $term->tid,
+                                                                              '!name' => $term->name,
+                                                                              '!vname' => $vocab->name)));
+          }
+        }
+      }
+      if (($minwords >0 ) && (str_word_count($term->name) < $minwords)){
+        $prune_local[] = $term->tid;
+        $del_term++;
+        if ($sim) {
+          drupal_set_message(t('Would delete term #!tid: !name (!vname)', array('!tid' => $term->tid,
+                                                                                '!name' => $term->name,
+                                                                                '!vname' => $vocab->name)));
+        }
+        else {
+          if (!$cron) {
+            drupal_set_message(t('Deleting term #!tid: !name (!vname)', array('!tid' => $term->tid,
+                                                                              '!name' => $term->name,
+                                                                              '!vname' => $vocab->name)));
+          }
+        }
+      }
     }
     // issue an error to the log if the configured failsafe (any) is out of bounds
     if (count($terms) > 0 && count($prune)/count($terms)*100 > _dot_get('delete_orphaned_terms_failsafe')) {
@@ -454,6 +494,26 @@ function delete_orphaned_terms_admin_parameters() {
     '#type' => 'textfield',
   );
 
+  $form['dot_param']['delete_orphaned_terms_maxwords'] = array(
+    '#description' => t('Number of words in a term <em>over</em> to which it is considered as Too-Long-Tail-Term (Should be deleted). Leave 0 this setting will be ignored.'),
+    '#default_value' => _dot_get('delete_orphaned_terms_maxwords'),
+    '#element_validate' => array('_delete_orphaned_terms_element_validate_threshold'),
+    '#maxlength' => 2,
+    '#size' => 2,
+    '#title' => t('Max words of a Long-Tail-Term'),
+    '#type' => 'textfield',
+  );
+
+  $form['dot_param']['delete_orphaned_terms_minwords'] = array(
+    '#description' => t('Number of words in a term <em>less</em> to which it is considered as Too-Short-Term (Should be deleted). Leave 0 this setting will be ignored.'),
+    '#default_value' => _dot_get('delete_orphaned_terms_minwords'),
+    '#element_validate' => array('_delete_orphaned_terms_element_validate_threshold'),
+    '#maxlength' => 1,
+    '#size' => 1,
+    '#title' => t('Min words a term should inculde'),
+    '#type' => 'textfield',
+  );
+
   return system_settings_form($form);
 }
 
@@ -519,4 +579,4 @@ function delete_orphaned_terms_menu() {
   );
 
   return $items;
-}
+}
\ No newline at end of file
-- 
1.7.0.2.msysgit.0

