/[drupal]/contributions/modules/wordfilter/wordfilter.module
ViewVC logotype

Diff of /contributions/modules/wordfilter/wordfilter.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.7.2.18, Wed Dec 10 16:00:05 2008 UTC revision 1.7.2.19, Tue Apr 14 09:35:18 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: wordfilter.module,v 1.7.2.13 2008/06/23 16:06:09 jaydub Exp $  // $Id: wordfilter.module,v 1.7.2.18 2008/12/10 16:00:05 jaydub Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 271  function wordfilter_block($op = 'list', Line 271  function wordfilter_block($op = 'list',
271      switch ($delta) {      switch ($delta) {
272        case 0:        case 0:
273          $block['subject'] = t('Filtered words');          $block['subject'] = t('Filtered words');
274          $block['content'] = $GLOBALS['display_wordfilter_block'] ? wordfilter_table() : '';          $block['content'] = $GLOBALS['display_wordfilter_block'] ? _wordfilter_table() : '';
275          return $block;          return $block;
276      }      }
277    }    }
278  }  }
279    
280  /**  /**
281   * @return string   * Displays a list of words that will be filtered as an HTML table.
282   */   */
283  function wordfilter_filter_tips($delta, $format, $long = FALSE) {  function _wordfilter_table() {
   if ($long) {  
     return t('If you include a word in your post that\'s filtered (usually foul language), it will be replaced by the filtered version of the word.') .'<br />';  
   }  
   else {  
     $GLOBALS['display_wordfilter_block'] = TRUE;  
     return t('Filtered words will be replaced with the filtered version of the word.');  
   }  
 }  
   
 function wordfilter_table() {  
284    $content .= '<div align="center">';    $content .= '<div align="center">';
285    $content .= '<table border="0" cellspacing="1" cellpadding="0">';    $content .= '<table border="0" cellspacing="1" cellpadding="0">';
286    $list = _wordfilter_list();    $list = _wordfilter_list();
# Line 302  function wordfilter_table() { Line 292  function wordfilter_table() {
292    return $content;    return $content;
293  }  }
294    
295    /**
296     * Implementation of hook_filter_tips().
297     */
298    function wordfilter_filter_tips($delta, $format, $long = FALSE) {
299      if ($long) {
300        return t("If you include a word in your post that's filtered (usually foul language), it will be replaced by the filtered version of the word.") .'<br />';
301      }
302      else {
303        $GLOBALS['display_wordfilter_block'] = TRUE;
304        return t('Filtered words will be replaced with the filtered version of the word.');
305      }
306    }
307    
308    /**
309     * Implementation of hook_filter().
310     */
311  function wordfilter_filter($op, $delta = 0, $format = -1, $text = '') {  function wordfilter_filter($op, $delta = 0, $format = -1, $text = '') {
312    switch ($op) {    switch ($op) {
313      case 'list':      case 'list':
# Line 312  function wordfilter_filter($op, $delta = Line 318  function wordfilter_filter($op, $delta =
318        $form['word_filter'] = array(        $form['word_filter'] = array(
319          '#type' => 'fieldset',          '#type' => 'fieldset',
320          '#title' => t('Word filter'),          '#title' => t('Word filter'),
321          '#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'))),
322        );        );
323        return $form;        return $form;
324      case 'process':      case 'process':
# Line 322  function wordfilter_filter($op, $delta = Line 328  function wordfilter_filter($op, $delta =
328    }    }
329  }  }
330    
331    /**
332     * hook_filter process operation callback.
333     */
334  function wordfilter_filter_process($text) {  function wordfilter_filter_process($text) {
335    $text = ' '. $text .' ';    $text = ' '. $text .' ';
336    $list = _wordfilter_list();    $list = _wordfilter_list();
# Line 375  function _wordfilter_admin_list($header) Line 384  function _wordfilter_admin_list($header)
384  }  }
385    
386  /**  /**
387   * wordfilter admin settings page   * Wordfilter admin settings page callback.
388   */   */
389  function wordfilter_admin_list() {  function wordfilter_admin_list() {
390    $header = array(    $header = array(
# Line 402  function wordfilter_admin_list() { Line 411  function wordfilter_admin_list() {
411    return $output;    return $output;
412  }  }
413    
414    /**
415     * Edit word filter form.
416     */
417  function wordfilter_admin_edit_form($word_id = NULL) {  function wordfilter_admin_edit_form($word_id = NULL) {
418    if (!isset($word_id) || !is_numeric($word_id)) {    if (!isset($word_id) || !is_numeric($word_id)) {
419      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_set_message(t('The wordfilter ID of the word or phrase you are trying to edit is missing or is not a number.'), 'error');
# Line 437  function wordfilter_admin_edit_form($wor Line 449  function wordfilter_admin_edit_form($wor
449      '#type' => 'checkbox',      '#type' => 'checkbox',
450      '#title' => t('Stand-alone'),      '#title' => t('Stand-alone'),
451      '#default_value' => $word->standalone,      '#default_value' => $word->standalone,
452      '#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 filtering with short or common words or phrases.'),      '#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.'),
453    );    );
454    
455    $form['Save word filter'] = array(    $form['Save word filter'] = array(
# Line 452  function wordfilter_admin_edit_form($wor Line 464  function wordfilter_admin_edit_form($wor
464    return $form;    return $form;
465  }  }
466    
467    /**
468     * Edit word filter form submit handler.
469     */
470  function wordfilter_admin_edit_form_submit($form_id, $form_values) {  function wordfilter_admin_edit_form_submit($form_id, $form_values) {
471    db_query("UPDATE {wordfilter} SET words = '%s', replacement = '%s', standalone = %d WHERE id = %d", $form_values['words'], $form_values['replacement'], $form_values['standalone'], $form_values['id']);    db_query("UPDATE {wordfilter} SET words = '%s', replacement = '%s', standalone = %d WHERE id = %d", $form_values['words'], $form_values['replacement'], $form_values['standalone'], $form_values['id']);
472    $message = t('Updated filter for: %words', array('%words' => $form_values['words']));    $message = t('Updated filter for: %words', array('%words' => $form_values['words']));
# Line 460  function wordfilter_admin_edit_form_subm Line 475  function wordfilter_admin_edit_form_subm
475    return 'admin/settings/wordfilter';    return 'admin/settings/wordfilter';
476  }  }
477    
478    /**
479     * Add word filter form.
480     */
481  function wordfilter_admin_add_form() {  function wordfilter_admin_add_form() {
482    $form = array();    $form = array();
483    
484    $form['help'] = array(    $form['help'] = array(
485      '#type' => 'markup',      '#type' => 'markup',
486      '#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.</p>
487    <p><strong>Examples:</strong><br />
488    bar|baz - Replace 'bar' with 'baz'<br />
489    baz - Replace 'baz' with the default replacement below<br />
490    </p>"),
491    );    );
492    
493    $form['words'] = array(    $form['words'] = array(
494      '#type' => 'textarea',      '#type' => 'textarea',
495      '#title' => t('Words'),      '#title' => t('Words'),
496      '#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."),
497      '#required' => TRUE,      '#required' => TRUE,
498    );    );
499    $form['replacement'] = array(    $form['replacement'] = array(
# Line 500  function wordfilter_admin_add_form() { Line 522  function wordfilter_admin_add_form() {
522    return $form;    return $form;
523  }  }
524    
525    /**
526     * Add word filter form submit handler.
527     */
528  function wordfilter_admin_add_form_submit($form_id, $form_values) {  function wordfilter_admin_add_form_submit($form_id, $form_values) {
529    $pairs = explode("\n", $form_values['words']);    $pairs = explode("\n", $form_values['words']);
530    $pairs = array_map('trim', $pairs);    $pairs = array_map('trim', $pairs);
# Line 517  function wordfilter_admin_add_form_submi Line 542  function wordfilter_admin_add_form_submi
542    return 'admin/settings/wordfilter';    return 'admin/settings/wordfilter';
543  }  }
544    
545    /**
546     * Test word filter form.
547     */
548  function wordfilter_admin_test_filter_form($form_values = NULL) {  function wordfilter_admin_test_filter_form($form_values = NULL) {
549    $form = array();    $form = array();
550    $form['#multistep'] = TRUE;    $form['#multistep'] = TRUE;
# Line 548  function wordfilter_admin_test_filter_fo Line 576  function wordfilter_admin_test_filter_fo
576    return $form;    return $form;
577  }  }
578    
579    /**
580     * Test word filter page callback.
581     */
582  function _wordfilter_test_filter($word) {  function _wordfilter_test_filter($word) {
583    $filtered_word = wordfilter_filter_process($word);    $filtered_word = wordfilter_filter_process($word);
584    if ($word == $filtered_word) {    if ($word == $filtered_word) {

Legend:
Removed from v.1.7.2.18  
changed lines
  Added in v.1.7.2.19

  ViewVC Help
Powered by ViewVC 1.1.2