A while back Topher created a program to filter words in 6.1.4. Well, haven't seen Topher around in quite awhile, his site appears to be gone from the net, but I did manage to come across a copy of his mod. Yes, the good old Word Filtering program that enables us to get around certain words/phrases being placed on the sites.
So, doing what any good person would do, I gave it a run to see if it worked on 6.1.6. Kinda... It has a surprising result that really surprised me. It filters the words perfectly, only one catch:
It duplicates ALL blog posts, comments and e-mails that members make on the site. Nice huh.
So, I managed to figure out where I believe the issue is, inside the inc/utils.inc.php file. Though, can't seem to quite isolate the exact spot causing it, though I do have a suspicion. Figure someone else might be able to spot it. Also, this was a Freebie created by Topher and I do have the source files on it. If someone would like them to help us get this thing working in 6.1.6 I'm happy to send them over.
Remember guys, this is the mod that when they typed a censored word would make the site tell them they sucked on volvos.
Here's the section that applies to the inc/utils.inc.php
Open '/inc/utils.inc.php':
Add this function (right before the ?> at the bottom of the file).
// Convictions Community BAD word filter -- start -----------
function censor_words($text, $matchit = false)
{
static $search_for, $replace_with, $enable_filter;
if (!isset($enable_filter)){$enable_filter = (getParam( 'enable_censor' ) == 'on');}
if (!$enable_filter){if ($matchit){return false;}else{return $text;}}
if (!isset($search_for))
{
$result = db_res("SELECT `search_for`, `replace_with` FROM `censoring`");
$num_words = mysql_num_rows($result);
$search_for = array();
for ($i = 0; $i < $num_words; ++$i)
{
list($search_for[$i], $replace_with[$i]) = mysql_fetch_row($result);
$search_for[$i] = '/\b('.str_replace('\*', '\w*?', preg_quote($search_for[$i], '/')).')\b/i';
}
}
if ($matchit){
$foundit=false;
if (!empty($search_for)){
foreach ($search_for as &$value) {if (preg_match($value, $text)){$foundit=true; break;}}
unset($value);}
return $foundit;}
if (!empty($search_for))
$text = substr(preg_replace($search_for, $replace_with, ' '.$text.' '), 1, -1);
return $text;
}
// --- end -- CC Bad Word Filter ----------------------
Find this function:
function clear_xss($val)
{
global $dir;
require_once( "{$dir['plugins']}safehtml/safehtml.php" );
$safehtml =& new safehtml();
$res = $safehtml->parse($val);
return $res;
}
Replace with:
function clear_xss($val)
{
global $dir;
require_once( "{$dir['plugins']}safehtml/safehtml.php" );
$safehtml =& new safehtml();
$res = censor_words($safehtml->parse($val));
return $res;
}
Find this function:
function process_db_input( $text, $strip_tags = 0, $force_addslashes = 0 )
{
if ( $strip_tags )
$text = strip_tags($text);
if ( !get_magic_quotes_gpc() || $force_addslashes )
return addslashes($text);
else
return $text;
}
Replace with:
function process_db_input( $text, $strip_tags = 0, $force_addslashes = 0 )
{
$text = censor_words($text);if ( $strip_tags ){$text = strip_tags($text);}
if ( !get_magic_quotes_gpc() || $force_addslashes ){return addslashes($text);}
else {return $text;}
}
Close and save '/inc/utils.inc.php'.
Note: The red italicized section is where I believe the issue is, as that section of the file actually reads:
function clear_xss($val)
{
require_once( BX_DIRECTORY_PATH_PLUGINS . 'safehtml/safehtml.php' );
$safehtml =& new safehtml();
$res = $safehtml->parse($val);
return $res;
}
And I edited it as follows to hold structure:
function clear_xss($val)
{
require_once( BX_DIRECTORY_PATH_PLUGINS . 'safehtml/safehtml.php' );
$safehtml =& new safehtml();
$res = $safehtml->parse($val);
$res = censor_words($safehtml->parse($val));
return $res;
}