PDA

View Full Version : End-User Options - User Optional Word Censorship


MrEyes
04-17-2008, 10:00 PM
User Optional Word Censorship

What this hack does

The default censorship options in VB are all or nothing, in other words it is either enabled or disabled for all users regardless of their personal preference. Without any additional SQL calls and an extremely low runtime impact (on top of the resource usage required when using the censor in the first place), this hack gives the user the option to view your forum with the AdminCP configured censor switched on if you have it enabled.

How to install

In summary the install requires:


Around 2 minutes.
1 file change.
The addition of a custom user profile field.
A basic understanding of PHP.


So this is what you need to do:

First create a custom user profile field:


Log in to your AdminCP.
Goto "User Profile Fields -> Add New User Profile Field"
In "Profile Field Type" select "Multiple-Selection Checkbox" and then click "Continue"
In "Title" enter "Enable word censor" *
In "Description" enter "If you choose to enabled this option all words on the current censor list will be replaced with * characters" *
In "Options" enter "Enable censor" *
Set "Private Field" to "Yes"
Set "Field Searchable on Members List" to "No"
Set "Show on Members List" to "No"
Set "Display Page -> Which page displays this option?" to "Options: Other"
Click "Save", this will then take you to a page that summarises all current profile fields.
On this profile fields list find the one you just added and take note of the "Name" value. Typically this will be somthing like "Field5".


* These options set the text that is displayed to the user, feel free to customise/change these to whatever you want.

All the AdminCP work is done now, so if you want logout. The next step is to make a small file edit, to check this field value when VB calls the censor code.


Take a backup of "includes\functions.php" just incase something goes horribly wrong.
Open the "includes\functions.php" file in your favourite text editor.
Find the following lines (typically these are around line 545):


if ($vbulletin->options['enablecensor'] AND !empty($vbulletin->options['censorwords']))
{


Immediately after the lines above (i.e. after the {) add the following code:


if ((isset($vbulletin->userinfo['field5'])) && ($vbulletin->userinfo['field5'] != 1))
{
return $text;
}


You should end up with something that looks like this:


if ($vbulletin->options['enablecensor'] AND !empty($vbulletin->options['censorwords']))
{
if ((isset($vbulletin->userinfo['field5'])) && ($vbulletin->userinfo['field5'] != 1))
{
return $text;
}

if (empty($censorwords))


Now this is probably the most complicated part of this simple install. Remember when you setup the profile field and you took a note of the "Name" value? Well in the text you just pasted into the function.php file you need to change this:


if ((isset($vbulletin->userinfo['field5'])) && ($vbulletin->userinfo['field5'] != 1))


To match the name of the field, so for example if your field name is "Field12", it would look like this:


if ((isset($vbulletin->userinfo['field12'])) && ($vbulletin->userinfo['field12'] != 1))


Save the file, and upload to your server.


The last, and most critically important step is:


Click Install ;)

All done, sit back and relax

Footnotes

By default the censor will be off for all users, so they will have to change their profile in order to enabled this. I could not find a way to create a profile checkbox field that is checked by default, and describing how to run SQL scripts to set the field value is more complicated than I wanted to go with this simple hack. So if anybody knows how to do this post the details and I will update the article. In the meantime a simpler option (rather than playing with the DB) is to use "Yes" / "No" radio buttons and set the default value to Yes (or no if you prefer). If you do this you will also have to subtly change the code above from:


if ((isset($vbulletin->userinfo['field5'])) && ($vbulletin->userinfo['field5'] != "Yes"))


to:


if ((isset($vbulletin->userinfo['field5'])) && ($vbulletin->userinfo['field5'] != "Yes"))

MrEyes
04-18-2008, 04:27 PM
Because you just never know ;)

youradhere4222
04-18-2008, 06:41 PM
I've been wanting this! Thanks!

iogames
04-18-2008, 09:30 PM
Nominated!
although I'm in favor of free speech :p

Wayne Luke
04-18-2008, 10:27 PM
Even without queries, parsing the post every display can really rack up resource usage. Formatting and displaying the post is more intensive than pulling it from the database. How do you work around this?

MrEyes
04-18-2008, 11:12 PM
Even without queries, parsing the post every display can really rack up resource usage. Formatting and displaying the post is more intensive than pulling it from the database. How do you work around this?

Yes, running with the vBulletin word censor enabled will of course increase usage. However this isn't an issue for me as this modification doesn't alter the default vBulletin parsing system.

Wayne Luke
04-19-2008, 12:55 PM
Yeah, but it prevents you from using the postcache which is created on edit of the post and stores the post in its parsed state to be shown on the screen without running BBCode and censor parsing at runtime.

MrEyes
04-19-2008, 04:53 PM
In which case take the issue up your VB development team as the issue you have is with default VB code/architecture and is most certainly beyond the scope of this 2 minute hack.

ZombieAndy
06-02-2008, 11:57 PM
Dosn't work, just makes the screen go white and nothing else.

This is my code, i might of missed something obvious..

if ($vbulletin->options['enablecensor'] AND !empty($vbulletin->options['censorwords']))
{
if ((isset($vbulletin->userinfo['field13'])) && ($vbulletin->userinfo['field13'] != "Yes"))
{
return $text;
}

if (empty($censorwords))
{
return $text;
}

ZombieAndy
06-05-2008, 08:18 PM
Anyone?

TheFallenAngel
06-06-2008, 02:32 AM
Dosn't work, just makes the screen go white and nothing else.

This is my code, i might of missed something obvious..

if ($vbulletin->options['enablecensor'] AND !empty($vbulletin->options['censorwords']))
{
if ((isset($vbulletin->userinfo['field13'])) && ($vbulletin->userinfo['field13'] != "Yes"))
{
return $text;
}

if (empty($censorwords))
{
return $text;
}
Remove the second

{
return $text;
}

ZombieAndy
06-06-2008, 02:20 PM
D'uh! I knew it would be something simple!

Thanks man!

VikesRule
09-10-2008, 07:10 PM
Does this code mess up with editing posts and whatnot and does it take a while to load?

JackThomson120
11-18-2008, 07:05 PM
Theres one problem, when the post is submitted, it censors the words and puts them in the database censored. So if this is turned off, they will display uncensored for all users.

Brittany
12-02-2008, 11:04 PM
OK I installed this exactly how you said and when I go to disable the censor
it says

"A required field called Enable word censor is missing or has an invalid value."

What am I doing wrong?


eta:
My code

if ($vbulletin->options['enablecensor'] AND !empty($vbulletin->options['censorwords']))
{
if ((isset($vbulletin->userinfo['field10'])) && ($vbulletin->userinfo['field10'] != 1))
{
return $text;
}

Brittany
12-04-2008, 11:59 AM
anyone?

Brittany
12-31-2008, 12:09 PM
nobody can help me?

Phaedrus
01-02-2009, 04:57 AM
You need to go to your options, create a list of censor words and then turn it on. The user then can decide to use the censoring or not by adding or removing the checkmark.

Have you created a censor list in your options in the admin control panel?

Phaedrus
01-02-2009, 05:47 AM
OK I installed this exactly how you said and when I go to disable the censor
it says

"A required field called Enable word censor is missing or has an invalid value."

What am I doing wrong?


eta:
My code

if ($vbulletin->options['enablecensor'] AND !empty($vbulletin->options['censorwords']))
{
if ((isset($vbulletin->userinfo['field10'])) && ($vbulletin->userinfo['field10'] != 1))
{
return $text;
}


Go to "User Profile Field Manager" in AdminCP.

Click "Edit" next to the option you created.

Choose "no" for required field.

Brittany
01-02-2009, 06:07 AM
ok did all that and Im not getting an error message anymore but it isnt working.
I added test to the list of curse words, turned it on, and it isnt working still

Brittany
01-02-2009, 06:10 AM
nvm i got it working that you sooooo much.

Brittany
01-02-2009, 06:42 AM
ok now when I go to enable it, it works fine, when I go to disable it all the words remain with stars

Brittany
01-02-2009, 11:43 AM
It works just fine now.

Phaedrus
01-02-2009, 03:13 PM
Any user who has the option selected will have their words turned into asterisk if they use one of the words they chose to have edited, that will go into the database exactly that way and all users will see it that way.

However those who do not have it on, their words will remain and everybody will see them except those tender souls with the option turned on.

beansbaxter
01-04-2009, 08:36 PM
For a super large big forum with a ton of traffic, how much server load will this add?

Phaedrus
01-07-2009, 12:12 AM
For a super large big forum with a ton of traffic, how much server load will this add?
It would add one query per page.

asailorsanchor
01-10-2009, 02:19 AM
When I unclick enable it still censors my words.. anyone know how i can fix this?

asailorsanchor
01-12-2009, 04:04 AM
anyone?

asailorsanchor
01-15-2009, 02:38 AM
one more try, anyone know how to make this work?

asailorsanchor
01-18-2009, 04:15 AM
anyone know how I click install?

Brittany
03-09-2009, 11:39 AM
works in 3.8 just fine!

Feign
04-07-2009, 06:05 PM
I like this mod. Very simple and easy to control.

The only thing I don't like is the case sensitivity of the censored words, but I guess that's an issue with the stock vBulletin censor?

steeler7
02-18-2010, 01:29 PM
Anyone ever try or get this to work with 3.8? I just tried to install.. no error messages or anything but nothing works unless I have the VB censor list on which seems to be backwards from what this mod said

Carly
02-20-2010, 03:08 AM
This didn't work for me in 3.8.2 -- it wasn't retroactive and it appears that it worked backwards. It seems that if Member A had the censor on and Member B did not, if Member A posted a censored word, it appeared censored to Member B (even though Member B didn't want the censor). If Member B posted a censored word, Member A would view it in its full glory (even though Member A *wanted* the censor). Totally backwards.

crs6785
02-21-2010, 11:56 PM
This didn't work for me in 3.8.2 -- it wasn't retroactive and it appears that it worked backwards. It seems that if Member A had the censor on and Member B did not, if Member A posted a censored word, it appeared censored to Member B (even though Member B didn't want the censor). If Member B posted a censored word, Member A would view it in its full glory (even though Member A *wanted* the censor). Totally backwards.

The reason that happens is because of how caching works and the way censored posts are added to the DB. If Member A has the censor turned on and creates a post, then the post is actually censored before it is written to the DB. Same for the cached part of the post that goes into the postparsed table in the DB. So in the same respect, if Member B has the censor disabled and creates a thread, then the uncensored thread will go into the cache as well, which I don't believe is censored again when it is retrieved (defeats the purpose of the cache, eh?), which means that Member A will not get the text censored if it is retrieved from cache.

The only way I've found to get around such behavior and make a user based censorship mod work is to globally disable the censor so all text is written to the DB uncensored and then selectively enable the censor (via hooks) when they view certain pages. This requires a lot of plugins in various spots to catch things that should be censored.

A real solution for user based censorship is going to need a rethinking of the way censorship is done in general and how it works with caching.

sully02
01-31-2011, 04:20 PM
Any chance this can be updated for 4.x?

I'm sure there are some folks who could use this aside from me.