XF 1.2 Transferring 300 censored words from vB to Xenforo. Is there a quick way?

Stuart Wright

Well-known member
Most are domains which we banned to stop spammers.
It would take ages to add all 300.
Can I just write an SQL query to do it?
Thanks
 
Can't be done with queries because the information is serialized. However, I did a small script for you.

Save this as "updateCensor.php" on your XenForo installation, then open http://yoursite.com/updateCensor.php

Also, change the word list (from Ugly to Fantastic in the example) to the list that you want to use

Code:
<?php

$censor = <<<HERE

Ugly
Terrible
Words
Nasty
Fantasstic

HERE;


####################################################################################################
# Do not change anything below this
####################################################################################################

$words = trim($censor);
$words = preg_split("#[\r\n]+#", $words);
sort($words);
$data = array();
foreach ($words as $w)
{
    $data['exact'][$w] = strlen($w);
}


$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$db = XenForo_Application::getDb();
$db->query("UPDATE xf_option SET option_value = ? WHERE option_id='censorWords'", serialize($data));
print "Done";
 
Last edited:
Thanks so much!
The vast majority of our censor words are parts of domains (recently relating to kitchens) so I would rather have the exact tickbox unticked for all the censored words and then go through and tick it for the few where I want an exact match. I assume that $data['exact'] sets the exact option. Can I change this to something else to achieve what I want?
 
You may be better off using the "spam phrases" option for them, and you can force the posts into moderation or just reject them.
 
Can't be done with queries because the information is serialized. However, I did a small script for you.

Save this as "updateCensor.php" on your XenForo installation, then open http://yoursite.com/updateCensor.php

Also, change the word list (from Ugly to Fantastic in the example) to the list that you want to use

Code:
<?php

$censor = <<<HERE

Ugly
Terrible
Words
Nasty
Fantasstic

HERE;


####################################################################################################
# Do not change anything below this
####################################################################################################

$words = trim($censor);
$words = preg_split("#[\r\n]+#", $words);
sort($words);
$data = array();
foreach ($words as $w)
{
    $data['exact'][$w] = strlen($w);
}


$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$db = XenForo_Application::getDb();
$db->query("UPDATE xf_option SET option_value = ? WHERE option_id='censorWords'", serialize($data));
print "Done";
Could you please change the script to cater spam phrases ?
Thanks !
 
Top Bottom