UBB.Dev
Posted By: ghubbell Bad Subjects - 11/12/2003 6:52 PM
K I would like if one of the PHP Gurus could have a look-see at this please:

Similar to badword or badnames, I wish to run 'bad subjects'. On www.UtterAccess.com as with most any forum especially now that we've all found ways to get the pages read by the engines, a decent subject line is very helpful both to the forum users, and to improve the words which the engines pick up (the subject does become the page title).

Taken almost verbatim from some lines in addpost.php, and after creating a file in filters similar to badnames, I've come up with this:

//Subject
$badsubject = @file("{$config['path']}/filters/badsubject");
if (!is_array($badsubject)) {$badsubject = @file("{$config['phpurl']}/filters/badsubject");}
while (list($linenum,$line) = each($badsubject)) {
if (preg_match("/^#/",$line)) {continue;}
chop ($line);
if (strstr(strtolower($Subject),strtolower($line))) {$html -> not_right($ubbt_lang['BAD_SUBJECT'],$Cat);}
}
//Subject end

The code runs in addpost.php just after:

$Subject = rtrim($Subject);
if ( (preg_match("/^\s*$/",$Subject)) || ($Body == "") || ($Body == " ") || ($Body == " ") || ($postername == "") ) {
$html -> not_right($ubbt_lang['ALL_FIELDS'],$Cat);
}


The touch-ups to the admin panel to access this badsubject file are a piece of cake (add a line to the admin/menu.php) like:

<a href="{$config['phpurl']}/admin/editfilters.php?Cat=$Cat&filter=badsubject" target="mainFrame">Edit bad Subjects</a><br />

(spiffy that up with a language entry if you don't want the hard-coded "Edit bad Subjects"...if you so choose...)


in admin/editfilters.php, add:

elseif ($filter == "badsubject") {
echo "Edit bad Subjects. ";
}

just after:

elseif ($filter == "badwords") {
echo "{$ubbt_lang['BADWORDS']}";
}

The language/addpost.php gets an entry like:

$ubbt_lang['BAD_SUBJECT'] = "Please correct your subject line. Include words which pertain to your question or response. Do not include phrases such as "Please Help", which will not assist anyone in finding or understanding your post. Thank you.";


I have entries in badsubject (line by line) like: Please Help, Need Help, Help Me ... and so on.

The code works and will return the listed "bad subject response", but only on the last 'bad subject'.

What am I missing to get out of the 'While' once the first instance is found? As this is virtually a mirror of BadNames, (which is not used at UA as it's a registration only forum), is BadNames ok - for those who do run with anonymous users?

Thanks,

Gord
Posted By: ghubbell Re: Bad Subjects - 11/13/2003 8:54 PM
anyone?
Posted By: ghubbell Re: Bad Subjects - 11/14/2003 6:13 AM
The solution can be found right here.

Josh, Allen, perhaps you'd like to wrap this up as a nice hack to compliment the search engine work?

Enjoy,

Gord Hubbell
Webmaster, www.UtterAccess.com
Posted By: Twisty Re: Bad Subjects - 11/20/2003 8:13 PM
I added a tweak to this which allows spaces to be completely ignored when comparing a badsubject string with the actual subject string.

It's pretty useful for preventing swearing in the subject line when a poster tries to add his own random spaces in order to fool the system

ORIGINAL:

//Subject
$badsubject = @file("{$config['path']}/filters/badsubject");
if (!is_array($badsubject)) {$badsubject = @file("{$config['phpurl']}/filters/badsubject");}
while (list($linenum,$line) = each($badsubject)) {
if (preg_match("/^#/",$line)) {continue;}
chop ($line);
if (strstr(strtolower($Subject),strtolower($line))) {$html -> not_right($ubbt_lang['BAD_SUBJECT'],$Cat);}
}
//Subject end

TWEAK:

//Subject
$badsubject = @file("{$config['path']}/filters/badsubject");
if (!is_array($badsubject)) {$badsubject = @file("{$config['phpurl']}/filters/badsubject");}
while (list($linenum,$line) = each($badsubject)) {
if (preg_match("/^#/",$line)) {continue;}
$line = chop ($line);
if (strstr(strtolower(trim(eregi_replace(' ', '', $Subject))),strtolower($line))) {$html -> not_right($ubbt_lang['BAD_SUBJECT'],$Cat);}
}
//Subject end
Posted By: ghubbell Re: Bad Subjects - 11/20/2003 8:47 PM
Awesome! Even better as it's now able to do 'double duty' []http://www.utteraccess.com/forums/images/graemlins/cheers.gif[/]

Thanks very much,

Gord []http://www.utteraccess.com/forums/images/graemlins/thumbup.gif[/]
Webmaster, www.UtterAccess.com
Posted By: Twisty Re: Bad Subjects - 11/20/2003 9:20 PM
Well thanks for the mod, I installed it on my board earlier on today. The regs are freaking out over how strict it is lol
Posted By: Twisty Re: Bad Subjects - 11/20/2003 9:42 PM
Btw Gord, I forget to mention...the exact same changes made to addpost.php & language/addpost.php also need to be included in modifypost.php and language/modifypost.php.

Or else a person could do a clean subject, then go back and edit in a badsubject
Posted By: ghubbell Re: Bad Subjects - 11/20/2003 10:05 PM
Great - thanks again. I'll see those get wrapped up too. Keeps everything all tidy like!

Cheers!

Gord
© UBB.Developers