Index: wordfilter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wordfilter/wordfilter.module,v
retrieving revision 1.7.2.9.2.9
diff -b -u -p -r1.7.2.9.2.9 wordfilter.module
--- wordfilter.module	6 Oct 2008 16:16:38 -0000	1.7.2.9.2.9
+++ wordfilter.module	9 Dec 2008 18:19:38 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: wordfilter.module,v 1.7.2.9.2.9 2008/10/06 16:16:38 jaydub Exp $
+// $Id: wordfilter.module,v 1.7.2.9.2.7 2008/08/29 11:04:23 jaydub Exp $
 
 /**
  * @file
@@ -20,9 +20,10 @@ function wordfilter_help($page = 'admin/
     case 'admin/modules#description':
       return t('Replaces words inside posts with filtered versions.');
     case 'admin/help#wordfilter':
-      return t('<p>The wordfilter module allows you to filter words or phrases in site content and replace the filtered words with specified replacement words. The text body of node and comments are filtered and optionally the title of nodes and subject of comments are filtered. The filters are applied on content viewing so the original text of your content is not altered.</p>');
+      return t('<p>The wordfilter module allows you to filter words or phrases in site content and replace the filtered words or phrases with specified replacement words or phrases. The text body of node and comments are filtered and optionally the title of nodes and subject of comments are filtered. The filters are applied on content viewing so the original text of your content is not altered.</p>');
     case 'admin/settings/wordfilter':
       return t('In order for filtering to work on the body text of a node or comment, you must activate the wordfilter filter for the input formats you wish to enable filtering for. Check your filter settings at <a href="@filter">Input Formats</a>.', array('@filter' => url('admin/settings/filters')));
+
   }
 }
 
@@ -50,7 +51,7 @@ function wordfilter_menu() {
 
   $items['admin/settings/wordfilter'] = array(
     'title' => 'Word filter',
-    'description' => 'Replaces words inside posts with filtered versions.',
+    'description' => 'Replaces words or phrases inside posts with filtered versions.',
     'page callback' => 'wordfilter_admin_list',
     'access callback' => 'user_access',
     'access arguments' => array('administer words filtered'),
@@ -138,6 +139,14 @@ function wordfilter_settings_form() {
     '#required' => TRUE,
   );
 
+  $form['general_options']['wordfilter_default_language'] = array(
+    '#type' => 'select',
+    '#title' => t('Default wordfilter language'),
+    '#description' => t('Select the default language you would like to use when adding new word filters. Select "All" to use word filters for all languages by default .'),
+    '#options' => _wordfilter_get_language_list(),
+    '#default_value' => variable_get('wordfilter_default_language', ''),
+  );
+
   return system_settings_form($form);
 }
 
@@ -151,7 +160,7 @@ function wordfilter_admin_form_delete_co
     '#type' => 'value',
     '#value' => $word_id,
   );
-  return confirm_form($form, t('Are you sure you want to delete this word from the word filtering list?'), 'admin/settings/wordfilter');
+  return confirm_form($form, t('Are you sure you want to delete this word or phrase from the word filtering list?'), 'admin/settings/wordfilter');
 }
 
 /**
@@ -185,13 +194,9 @@ function wordfilter_nodeapi(&$node, $op,
   switch ($op) {
     case 'insert':
     case 'update':
-      if (variable_get('wordfilter_node_title', TRUE)) {
-        $node->title = wordfilter_filter_process($node->title);
-      }
-      break;
     case 'load':
       if (variable_get('wordfilter_node_title', TRUE)) {
-        $node->title = wordfilter_filter_process($node->title);
+        $node->title = wordfilter_filter_process($node->title, $node);
       }
       break;
     case 'search result':
@@ -205,7 +210,7 @@ function wordfilter_nodeapi(&$node, $op,
        * of hook_nodeapi. 
        */ 
       if (variable_get('wordfilter_comment_title', TRUE)) {
-        $node->body = wordfilter_filter_process($node->body);
+        $node->body = wordfilter_filter_process($node->body, $node); 
       }
       break;
   }
@@ -226,13 +231,14 @@ function wordfilter_comment(&$comment, $
     case 'update':
     case 'publish':
       if (variable_get('wordfilter_comment_title', TRUE)) {
-        $comment = (array)$comment;
-        $comment['subject'] = wordfilter_filter_process($comment['subject']);
+        $node = node_load($comment['nid']);
+        $comment['subject'] = wordfilter_filter_process($comment['subject'], $node);
       }
       break;
     case 'view':
       if (variable_get('wordfilter_comment_title', TRUE)) {
-        $comment->subject = wordfilter_filter_process($comment->subject);
+        $node = node_load($comment->nid);
+        $comment->subject = wordfilter_filter_process($comment->subject, $node);
       }
       break;
   }
@@ -300,7 +306,7 @@ function wordfilter_filter($op, $delta =
       $form['word_filter'] = array(
         '#type' => 'fieldset',
         '#title' => t('Word filter'),
-        '#description' => t('You can define a global list of words to be filtered on the <a href="!url">wordfilter settings page</a>.', array('!url' => url('admin/settings/wordfilter'))),
+        '#description' => t('You can define a global list of words or phrases to be filtered on the <a href="!url">wordfilter settings page</a>.', array('!url' => url('admin/settings/wordfilter'))),
       );
       return $form;
     case 'process':
@@ -310,9 +316,9 @@ function wordfilter_filter($op, $delta =
   }
 }
 
-function wordfilter_filter_process($text) {
+function wordfilter_filter_process($text, $object = NULL) {
   $text = ' '. $text .' ';
-  $list = _wordfilter_list();
+  $list = _wordfilter_list($object);
   $utf8 = variable_get('wordfilter_use_utf8_flag', FALSE);
   foreach ($list as $word) {
     // Prevent mysterious empty value from blowing away the node title.
@@ -336,15 +342,40 @@ function wordfilter_filter_process($text
  * Query to get the list of words to filter in the
  * filter processing stage. Does not use a pager.
  */
-function _wordfilter_list($refresh = 0) {
-  static $list = NULL;
-  if (is_null($list) || $refresh) {
+function _wordfilter_list($object = NULL, $refresh = FALSE) {
+  static $list, $language_list;
+
+  if (module_exists('locale')) {
+    if (!isset($language_list) || $refresh) {
+      $language_list = array();
+    }
+
+    $node = isset($object) ? $object : menu_get_object();
+    // We're viewing a node. If it has a language, apply its language's filter
+    // plus the global one.
+    if ($node && !empty($node->language)) {
+      if (!isset($language_list[$node->language])) {
+        $language_list[$node->language] = array(); 
+        $result = db_query("SELECT * FROM {wordfilter} WHERE language = '' OR language = '%s' ORDER BY language DESC, words DESC", $node->language);
+        while ($row = db_fetch_object($result)) {
+          $language_list[$node->language][] = $row;
+        }
+      }
+      return $language_list[$node->language];
+    }
+  }
+
+  if (!isset($list) || $refresh) {
+    // The locale module is not enabled, or we don't know the context, so
+    // apply all word filters.
     $result = db_query('SELECT * FROM {wordfilter} ORDER BY words DESC');
+    
     $list = array();
-    while ($a = db_fetch_object($result)) {
-      $list[] = $a;
+    while ($row = db_fetch_object($result)) {
+      $list[] = $row;
     }
   }
+
   return $list;
 }
 
@@ -372,16 +403,26 @@ function wordfilter_admin_list() {
     array('data' => t('Standalone'), 'field' => 'standalone'),
     array('data' => t('Operations'), 'colspan' => 2)
   );
+
+  if (module_exists('locale')) {
+    array_unshift($header, array('data' => t('Language'), 'field' => 'language', 'sort' => 'asc'));
+  }
+
   $rows = array();
   $list = _wordfilter_admin_list($header);
   foreach ($list as $word) {
-    $rows[] = array(
+    $row = array(
       check_plain($word->words),
       ($word->replacement) ? $word->replacement : variable_get('wordfilter_default_replacement', '[filtered word]'),
       ($word->standalone) ? t('Yes') : t('No'),
       l(t('Edit word'), 'admin/settings/wordfilter/edit/'. $word->id),
       l(t('Delete word'), 'admin/settings/wordfilter/delete/'. $word->id),
     );
+    if (module_exists('locale')) {
+      array_unshift($row, locale_language_name($word->language));
+    }
+
+    $rows[] = $row;
   }
   $output .= drupal_get_form('wordfilter_settings_form');
   $output .= theme('table', $header, $rows);
@@ -392,7 +433,7 @@ function wordfilter_admin_list() {
 
 function wordfilter_admin_edit_form($form, $word_id = NULL) {
   if (!isset($word_id) || !is_numeric($word_id)) {
-    drupal_set_message(t('The word ID of the word you are trying to edit is missing or is not a number.'), 'error');
+    drupal_set_message(t('The wordfilter ID of the word or phrase you are trying to edit is missing or is not a number.'), 'error');
     drupal_goto('admin/settings/wordfilter');
   }
   $result = db_query('SELECT * FROM {wordfilter} WHERE id = %d', $word_id);
@@ -406,9 +447,9 @@ function wordfilter_admin_edit_form($for
 
   $form['words'] = array(
     '#type' => 'textfield',
-    '#title' => t('Word to filter'),
+    '#title' => t('Word or phrase to filter'),
     '#default_value' => $word->words,
-    '#description' => t('Enter the word you want to filter.'),
+    '#description' => t('Enter the word or phrase you want to filter.'),
     '#size' => 50,
     '#maxlength' => 255,
     '#required' => TRUE,
@@ -416,16 +457,25 @@ function wordfilter_admin_edit_form($for
   $form['replacement'] = array(
     '#type' => 'textfield',
     '#title' => t('Replacement text'),
-    '#description' => t('Enter the filtered version of the word to replace the original word.'),
+    '#description' => t('Enter the filtered version of the word or phrase to replace the original word or phrase.'),
     '#default_value' => ($word->replacement) ? $word->replacement : variable_get('wordfilter_default_replacement', '[filtered word]'),
     '#size' => 50,
     '#maxlength' => 255,
   );
+
+  $form['language'] = array(
+    '#type' => 'select',
+    '#title' => t('Language'),
+    '#description' => t('Enter the language of the word or phrase you wish to replace. Select "All" to use this filter for all languages.'),
+    '#options' => _wordfilter_get_language_list(),
+    '#default_value' => $word->language,
+  );
+
   $form['standalone'] = array(
     '#type' => 'checkbox',
     '#title' => t('Stand-alone'),
     '#default_value' => $word->standalone,
-    '#description' => t('When checked, the word will only be filtered when found as a separate word (i.e. prefixed and suffixed by spaces or "whitespace"). A period one character after a word will exclude the words from replacement in stand-alone mode. This is useful for preventing accidental word filtering with short or common words.'),
+    '#description' => t('When checked, the word or phrase will only be filtered when found as a separate word or phrase (i.e. prefixed and suffixed by spaces or "whitespace"). A period one character after a word or phrase will exclude the words or phrases from replacement in stand-alone mode. This is useful for preventing accidental word or phrase filtering with short or common words or phrases.'),
   );
 
   $form['Save word filter'] = array(
@@ -440,16 +490,10 @@ function wordfilter_admin_edit_form($for
   return $form;
 }
 
-function wordfilter_admin_edit_form_validate($form, &$form_state) {
-  if (trim($form_state['values']['words']) == '') {
-    form_set_error('words', t('Please enter a word to filter.'));
-  }
-}
-
 function wordfilter_admin_edit_form_submit($form, &$form_state) {
-  db_query("UPDATE {wordfilter} SET words = '%s', replacement = '%s', standalone = %d WHERE id = %d", $form_state['values']['words'], $form_state['values']['replacement'], $form_state['values']['standalone'], $form_state['values']['id']);
-  watchdog('wordfilter', 'Updated filter for: %form_state', array('%form_state' => $form_state['values']['words']));
-  drupal_set_message(t('Updated filter for:') . $form_state['values']['words']);
+  db_query("UPDATE {wordfilter} SET words = '%s', replacement = '%s', language = '%s', standalone = %d WHERE id = %d", $form_state['values']['words'], $form_state['values']['replacement'], $form_state['values']['language'], $form_state['values']['standalone'], $form_state['values']['id']);
+  watchdog('wordfilter', t('Updated filter for: %word', array('%word' => $form_state['values']['words'])));
+  drupal_set_message(t('Updated filter for: %word', array('%word' => $form_state['values']['words'])));
   $form_state['redirect'] = 'admin/settings/wordfilter';
 }
 
@@ -461,13 +505,19 @@ function wordfilter_admin_add_form() {
 
   $form['help'] = array(
     '#type' => 'markup',
-    '#value' => t("Enter a word or phrase you want to filter followed by '|' and the replacement word or phrase. You can enter multiple word and replacement word pairs by hitting return and adding more word pairs. Any word or phrases that do not have a replacement word or phrase will use the default replacement word below."),
+    '#value' => t("<p>Enter a word or phrase you want to filter followed by '|' and the replacement word or phrase. You can enter multiple word and replacement word pairs by hitting return and adding more word pairs. Any word or phrases that do not have a replacement word or phrase will use the default replacement word below. Any word or phrases that do not have a language set will be filtered for all languages.</p>
+<p><strong>Examples:</strong><br />
+foo|bar|de - Replace 'foo' with 'bar' when content language is German<br />
+bar|baz - Replace 'foo' with 'baz' using the language setting option below<br />
+baz - Replace 'baz' with the default replacement  using the language setting option below<br />
+foo||hu - Replace 'foo' with the default replacement when content language is Hungarian<br/>
+</p>"),
   );
 
   $form['words'] = array(
     '#type' => 'textarea',
     '#title' => t('Words'),
-    '#description' => t("Enter a word or phrase you want to filter followed by '|' and the replacement word or phrase."),
+    '#description' => t("Enter a word or phrase you want to filter followed by '|' and the replacement word or phrase if any followed by '|' and the language if any the word filter pair is to be used for."),
     '#required' => true
   );
   $form['replacement'] = array(
@@ -476,12 +526,21 @@ function wordfilter_admin_add_form() {
     '#default_value' => variable_get('wordfilter_default_replacement', '[filtered word]'),
     '#size' => 50,
     '#maxlength' => 255,
-    '#description' => t('Enter the filtered version of the word to replace the original words with.')
+    '#description' => t('Enter the filtered version of the word to replace the original words with. If no replacement word or phrase is specified for a word or phrase in the list above, the word or phrase entered here will be used as the replacement for that word or phrase.')
   );
+
+  $form['language'] = array(
+    '#type' => 'select',
+    '#title' => t('Language'),
+    '#description' => t('Enter the language of the word or phrase you wish to replace. Select "All" to use this filter for all languages.'),
+    '#options' => _wordfilter_get_language_list(),
+    '#default_value' => variable_get('wordfilter_default_language', ''),
+  );
+
   $form['standalone'] = array(
     '#type' => 'checkbox',
     '#title' => t('Stand-alone'),
-    '#description' => t('When checked, the word will only be filtered when found as a separate word (i.e. prefixed and suffixed by spaces or "whitespace"). A period one character after a word will exclude the words from replacement in stand-alone mode. This is useful for preventing accidental word filtering with short or common words.')
+    '#description' => t('When checked, the word or phrase will only be filtered when found as a separate word or phrase (i.e. prefixed and suffixed by spaces or "whitespace"). A period one character after a word or phrase will exclude the words from replacement in stand-alone mode. This is useful for preventing accidental word or phrase filtering with short or common words and phrases.')
   );
 
   $form['Save word filter'] = array(
@@ -507,13 +566,28 @@ function wordfilter_admin_add_form_submi
   $pairs = array_map('trim', $pairs);
   $pairs = array_filter($pairs, 'strlen');
   foreach ($pairs as $pair) {
-    list($word, $replacement) = explode('|', $pair);
+    list($word, $replacement, $language) = explode('|', $pair);
     if (!$replacement) {
       $replacement = $form_state['values']['replacement'];
     }
-    db_query("INSERT INTO {wordfilter} (words, replacement, standalone) VALUES ('%s', '%s', %d)", $word, $replacement, $form_state['values']["standalone"]);
-    watchdog('wordfilter', 'Added filter for: %word', array('%word' => $word));
-    drupal_set_message(t('Added filter for: @word', array('@word' => $word)));
+    if (!$language) {
+      $language = $form_state['values']['language'];
+    }
+    db_query("INSERT INTO {wordfilter} (words, replacement, language, standalone) VALUES ('%s', '%s', '%s', %d)", $word, $replacement, $language, $form_state['values']["standalone"]);
+    watchdog('wordfilter', t('Added filter for: %word', array('%word' => $word)));
+    drupal_set_message(t('Added filter for: %word', array('%word' => $word)));
   }
   $form_state['redirect'] = 'admin/settings/wordfilter';
 }
+
+function _wordfilter_get_language_list() {
+  $options = array('' => t('All'));
+  if (module_exists('locale')) {
+    $languages = language_list('enabled');
+    $languages = $languages[1];
+    foreach ($languages as $language) {
+      $options[$language->language] = $language->native .' ('. t($language->name) .' - '. $language->language .')';
+    }
+  }
+  return $options;
+}
Index: wordfilter.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wordfilter/wordfilter.install,v
retrieving revision 1.4.2.1.2.2
diff -b -u -p -r1.4.2.1.2.2 wordfilter.install
--- wordfilter.install	21 May 2008 05:41:02 -0000	1.4.2.1.2.2
+++ wordfilter.install	9 Dec 2008 18:19:44 -0000
@@ -25,6 +25,13 @@ function wordfilter_schema() {
         'not null' => TRUE,
         'default' => '',
       ),
+      'language' => array(
+        'description' => t('The {languages}.language of this word to filter.'),
+        'type' => 'varchar',
+        'length' => 12,
+        'not null' => TRUE,
+        'default' => '',
+      ),
       'standalone' => array(
         'description' => t('A boolean to indicate if the word filtering should only be done if the word is not part of another word.'),
         'type' => 'int',
@@ -70,6 +77,17 @@ function wordfilter_update_3() {
 }
 
 /**
+ * Update function to add a language column to the wordfilter
+ * table so that words and replacement words can be set on 
+ * a per language basis
+ */
+function wordfilter_update_6100() {
+  $ret = array();
+  db_add_field($ret, 'wordfilter', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
+  return $ret;
+}
+
+/**
  * Implementation of hook_uninstall().
  */
 function wordfilter_uninstall() {
