I've looked hard and the doesn't seem to be one (which surprises me) so I'm going to be working on one as I need one for my site to keep it suitable for all ages. I'm happy using PHP and I'm getting there with Drupal. This will be my first module so and feedback would be greatly appreciated.

Here's my current thinking (it may not be the right option):

1. Administrator enables filter module
2. Administrator adds words to the filter which are removed any time they are met when a person adds a comment or a node to the site.

Only problem with this approach is that if your filter doesn't have a word in it, you'll have to manually delete the word from any comments made with it before this point in time.

The other option is that the words are removed when displaying the nodes and comments. This might cause the site to slow down.

Any thoughts most welcome.

Comments

micha_1977’s picture

you could use the cron hook for overlooking existing nodes

-micha
work in progress with Drupal 4.6: langmi.de

Bèr Kessels’s picture

Just use the filter system. This is exactly what it is there for. (And Drual users are just polite people no need to censor them :) )
---
Next time, please consider filing a support request.

[Bèr Kessels | Drupal services www.webschuur.com]

Bèr Kessels’s picture

The filters have all sorts of cching, taht will help you, do not fear performance loss.

---
Next time, please consider filing a support request.

[Bèr Kessels | Drupal services www.webschuur.com]

cre8d’s picture

and reassurance.

Now, here's my first module (I hope no-one is offended by my example):


function swearingfilter_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Filter out swearing.');
  }
}

function swearingfilter_filter_tips($delta, $format, $long = false) {
  if ($long) {
    return t('This filter will completely remove all swearing from comments, so it is better not to use them in the first place.');
  }
  else {
    return t('Swear words will be deleted.');
  }
}

function swearingfilter_censored($text) {
    $text = ' ' . $text . ' ';
    $swearing = 'bitch|shit';
    $swearing = explode('|',$swearing); 
    foreach ($swearing as $swearword) 
        $text = preg_replace('/([^A-Za-z])'.$swearword.'([^A-Za-z])/si','\\1' . '****' . '\\2',$text);    
    $text = substr($text,1);
    $text = substr($text, 0, -1);
    return $text;
}

function swearingfilter_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(0 => t('Swearing filter'));
    case 'description':
      return swearingfilter_help('admin/modules#description');
    case 'process':
      $text = swearingfilter_censored($text);
      return $text;
    default:
      return $text;
  }
}

Issues I can think of: how to add/delete/edit terms without changing the module file - should I use MySQL table?

Bèr Kessels’s picture

* Your regular expressuins are not utf8 safe. People will be able to avoid filtring by adding utf 8 equivalants of their words.
* Your regular expressions do not catch html.
<strong>cur</strong><strong>se</strong> for example will just show curse
* It would be easiest to add a single textarea with comma-separated swear words. Save that with variable_get/-set and explode on , (comma), Simple yet effective.

---
Next time, please consider filing a support request.

[Bèr Kessels | Drupal services www.webschuur.com]

cre8d’s picture

I will try and work on those issues too :)

kmillecam’s picture

The glossary module compares words in posts/comments/stories and hyperlinks words that match those in the glossary taxonomy.

Seems like this could be a foundation for a swearing module.

You would use a taxonomy to define the bad words and then display them as *** instead of hyperlinks.

Just a thought.

Kevin

https://bkjdigital.com
We make magic.