Censor improvements/ Bad_* improvements
Posted by ChrisW
Censor improvements/ Bad_* improvements October 21, 2003 05:52PM |
This change will go through the censor much, much, much faster since it's just four calls to preg_replace, rather than four calls times the number of word. Also, it will move the censor from a file on the server to the database and include update functionality in the admin
1) Add a table in your database called bad (here is the mysql command):
CREATE TABLE `bad` (
`Value` varchar(255) NOT NULL default '',
`Type` char(1) NOT NULL default ''
) ;
2 ) Put the file ./admin/pages/censor.php from censor.tar.gz into ./admin/pages/
3) Add a line to your ./admin/pages/main.php so you have link to the censor admin:
<a href="<?php echo $myname; ?>?page=censor">Censor</a><br />
4) Change ./include/censor.php to the following:
<?php
global $DB, $q;
$stmt="select Value from bad where Type='p'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$profan[]="/(".quotemeta($rec[Value]).")/ie";
}
?>
5) In include/post_functions.inc with the change to the censor function as follows:
function censor($author, $subject, $email, $body)
{
global $include_path, $ForumConfigSuffix;
if(file_exists("$include_path/censor_$ForumConfigSuffix.php")){
include "$include_path/censor_$ForumConfigSuffix.php";
} else {
include "$include_path/censor.php";
}
if (is_array($profan)) {
$author=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $author);
$email=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $email);
$subject=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $subject);
$body=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $body);
}
return(array($author, $subject, $email, $body));
}
Everything past this is optional, but if you also want to drive your bad_email, bad_name and bad_host out of the database with an admin, then make the following changes as well:
1) Replace includes/bad_emails.php with:
<?php
global $DB, $q;
$stmt="select Value from bad where type='e'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$emails[]=$rec[Value];
}
?>
2) Replace includes/bad_hosts.php with:
<?php
global $DB, $q;
$stmt="select Value from bad where type='h'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$hosts[]=$rec[Value];
}
?>
3) Replace includes/bad_names.php with:
<?php
global $DB, $q;
$stmt="select Value from bad where type='n'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$names[]=$rec[Value];
}
?>
4) Include the bad_* file from bad.tar.gz in your admin/pages directory
4) Add the following lines to admin/pages/main.php
<a href="<?php echo $myname; ?>?page=bad_emails">Bad Emails</a><br />
<a href="<?php echo $myname; ?>?page=bad_hosts">Bad Hosts</a><br />
<a href="<?php echo $myname; ?>?page=bad_names">Bad Names</a><br />
1) Add a table in your database called bad (here is the mysql command):
CREATE TABLE `bad` (
`Value` varchar(255) NOT NULL default '',
`Type` char(1) NOT NULL default ''
) ;
2 ) Put the file ./admin/pages/censor.php from censor.tar.gz into ./admin/pages/
3) Add a line to your ./admin/pages/main.php so you have link to the censor admin:
<a href="<?php echo $myname; ?>?page=censor">Censor</a><br />
4) Change ./include/censor.php to the following:
<?php
global $DB, $q;
$stmt="select Value from bad where Type='p'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$profan[]="/(".quotemeta($rec[Value]).")/ie";
}
?>
5) In include/post_functions.inc with the change to the censor function as follows:
function censor($author, $subject, $email, $body)
{
global $include_path, $ForumConfigSuffix;
if(file_exists("$include_path/censor_$ForumConfigSuffix.php")){
include "$include_path/censor_$ForumConfigSuffix.php";
} else {
include "$include_path/censor.php";
}
if (is_array($profan)) {
$author=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $author);
$email=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $email);
$subject=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $subject);
$body=preg_replace($profan,"str_pad('', strlen('\\1'), '*')", $body);
}
return(array($author, $subject, $email, $body));
}
Everything past this is optional, but if you also want to drive your bad_email, bad_name and bad_host out of the database with an admin, then make the following changes as well:
1) Replace includes/bad_emails.php with:
<?php
global $DB, $q;
$stmt="select Value from bad where type='e'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$emails[]=$rec[Value];
}
?>
2) Replace includes/bad_hosts.php with:
<?php
global $DB, $q;
$stmt="select Value from bad where type='h'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$hosts[]=$rec[Value];
}
?>
3) Replace includes/bad_names.php with:
<?php
global $DB, $q;
$stmt="select Value from bad where type='n'";
$q->query($DB, $stmt);
while($rec=$q->getrow()) {
$names[]=$rec[Value];
}
?>
4) Include the bad_* file from bad.tar.gz in your admin/pages directory
4) Add the following lines to admin/pages/main.php
<a href="<?php echo $myname; ?>?page=bad_emails">Bad Emails</a><br />
<a href="<?php echo $myname; ?>?page=bad_hosts">Bad Hosts</a><br />
<a href="<?php echo $myname; ?>?page=bad_names">Bad Names</a><br />
Sorry, you do not have permission to post/reply in this forum.