Drupal: Remove censored tags using Wordfilter and Tagadelic

One of my first Drupal 'hooks', a long time ago.


function dbo_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
	if ($node && ($op == 'submit' || $op == 'update')) {

		if (module_exists('wordfilter')){
			if (module_exists('tagadelic')){
				$tags = array(); $thetags = array();
				if (count($node->taxonomy['tags'][2]) > 0){
					$tags = preg_split('/\,(\s)*/i',$node->taxonomy['tags'][2]);
					$ztaglist = _wordfilter_list();
					foreach ($tags as $tag){
						$badtag = false;
						if (preg_match('/\s+/',$tag)){
							$tag = str_replace('"','',$tag);
						}
						foreach($ztaglist as $key => $val){
							if ($tag == $val->words && $val->standalone || stristr($tag, $val->words) && !$val->standalone){
								$badtag = true;
							}
						}
						if (!$badtag){
							$thetags[] = (preg_match('/\s+/',$tag))?'"'.$tag.'"':$tag;
						}
					}
					$node->taxonomy['tags'][2] = implode(",", $thetags);
				}
			}
		}
	}
}


click here to add a comment