An alternative behaviour would be to validate the form submission and prevent completion if filtered words are encountered. This will give people a chance to fix their text. Not sure if this is possible with hook_filter.

With this behaviour the module is not acting as a filter anymore, but the end result is pretty close IMO.

Comments

jaydub’s picture

Status: Active » Closed (works as designed)

You can implement this yourself by writing a custom form validation handler and running wordfilter_filter_process() directly against a form value. If the returned text is not equal to the original text you could act on this and fail validation for the form field perhaps.

jgoodwill01’s picture

Any suggestions on what this might look like. I've been trying to figure out how to validate using Wordfilter.

rickvug’s picture

I needed this so I created a very small module called wordfiler_plus. Here's the code. Add an info file and rename the module/functions as needed. Work is still needed to integrate with CCK and provide a more helpful error message. I hope this helps someone in the mean time.

/**
 * Implementation of hook_perm().
 */
function wordfilter_plus_perm() {
  return array('skip banned word check');
}

/**
 * Implementation of hook_nodeapi().
 */
function wordfilter_plus_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'validate':
      if(!user_access('skip banned word check')) {
	    // Run node body through word filter. Any words matching the word filter
	    // list will be modified.
	    $filtered_body = wordfilter_filter_process($node->body);
        
	    // Compare filtered $node->body to not filter $node->body.
	    // If there are different we know that a banned word is present.
	    if ($node->body != $filtered_body) {
	      form_set_error('body', t('This text contains a banned word.'));
	    }
	  }
	break;
  }
}
rickvug’s picture

I also chucked this code up on GitHub is anyone is interested. See http://github.com/rickvug/wordfilter_plus. If this gets into a workable state maybe I'll make a patch to wordfilter for better integration or throw the code up on d.o. Anyone is welcome to fork and improve.

websites-development.com’s picture

rickvug’s picture

Also see this sandbox: http://drupal.org/sandbox/rickvug/1072642. If anyone is interested please contact me about becoming a co-maintainer. Should this become useful we can transition the sandbox to be a full project with releases.