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	16 Mar 2009 03:17:59 -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() {
Index: wordfilter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wordfilter/wordfilter.module,v
retrieving revision 1.7.2.9.2.11
diff -b -u -p -r1.7.2.9.2.11 wordfilter.module
--- wordfilter.module	10 Dec 2008 16:29:39 -0000	1.7.2.9.2.11
+++ wordfilter.module	16 Mar 2009 03:18:06 -0000
@@ -147,6 +147,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);
 }
 
@@ -194,13 +202,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':
@@ -211,10 +215,10 @@ function wordfilter_nodeapi(&$node, $op,
        * and body are not able to be filtered prior to inserting
        * into the search index for the node. So instead we
        * have to filter the node body on 'search result' operation
-       * of hook_nodeapi. 
+       * 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;
   }
@@ -235,13 +239,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;
   }
@@ -309,7 +314,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 or phrases 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':
@@ -319,9 +324,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.
@@ -345,15 +350,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) {
-    $result = db_query('SELECT * FROM {wordfilter} ORDER BY words DESC');
+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, language ASC');
+
     $list = array();
-    while ($a = db_fetch_object($result)) {
-      $list[] = $a;
+    while ($row = db_fetch_object($result)) {
+      $list[] = $row;
     }
   }
+
   return $list;
 }
 
@@ -381,16 +411,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);
@@ -430,6 +470,15 @@ function wordfilter_admin_edit_form($for
     '#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'),
@@ -450,8 +499,8 @@ function wordfilter_admin_edit_form($for
 }
 
 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', t('Updated filter for: %word', array('%word' => $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', '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';
 }
@@ -464,14 +513,20 @@ function wordfilter_admin_add_form() {
 
   $form['help'] = array(
     '#type' => 'markup',
-    '#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.</p>"),
+    '#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 if any."),
-    '#required' => true
+    '#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(
     '#type' => 'textfield',
@@ -481,6 +536,15 @@ function wordfilter_admin_add_form() {
     '#maxlength' => 255,
     '#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'),
@@ -504,13 +568,16 @@ 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"]);
+    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', 'Added filter for: %word', array('%word' => $word));
-    drupal_set_message(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';
 }
@@ -558,3 +625,15 @@ function _wordfilter_test_filter($word) 
     return t("Your test word '<em>@word</em>' was filtered to '<em>@filtered_word</em>'", array('@word' => $word, '@filtered_word' => $filtered_word));
   }
 }
+
+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;
+}
