The bottom line here is that most people use the Word Censor as a way of modifying or restricting text in posts. It is an unexpected "feature" that it also interferes with URLs. For many, it's an unwanted feature. I have about 100 word censors set up, and most are for readability purposes, for instance capitalizing place names ("berlin" becomes "Berlin"), fixing acronyms ("ocd" becomes "OCD"), fixing spelling ("Ive" becomes "I've", "im" becomes "I'm"), etc. This makes my forum a much more pleasant experience for users to read because they spend less time trying to interpret meaning. But it also breaks hyperlinks and images. I've had this issue arise several times over the years, and surely my experience is not uncommon.
At least can we discuss what code changes would be required to restrict the censor function to text only? Here is the relevant code:
functions.php
Code: Select all
/**
* Generate regexp for naughty words censoring
* Depends on whether installed PHP version supports unicode properties
*
* @param string $word word template to be replaced
*
* @return string $preg_expr regex to use with word censor
*/
function get_censor_preg_expression($word)
{
// Unescape the asterisk to simplify further conversions
$word = str_replace('\*', '*', preg_quote($word, '#'));
// Replace asterisk(s) inside the pattern, at the start and at the end of it with regexes
$word = preg_replace(array('#(?<=[\p{Nd}\p{L}_])\*+(?=[\p{Nd}\p{L}_])#iu', '#^\*+#', '#\*+$#'), array('([\x20]*?|[\p{Nd}\p{L}_-]*?)', '[\p{Nd}\p{L}_-]*?', '[\p{Nd}\p{L}_-]*?'), $word);
// Generate the final substitution
$preg_expr = '#(?<![\p{Nd}\p{L}_-])(' . $word . ')(?![\p{Nd}\p{L}_-])#iu';
return $preg_expr;
}
functions_content.php:
Code: Select all
/**
* Censoring
*/
function censor_text($text)
{
static $censors;
// Nothing to do?
if ($text === '')
{
return '';
}
// We moved the word censor checks in here because we call this function quite often - and then only need to do the check once
if (!isset($censors) || !is_array($censors))
{
global $config, $user, $auth, $cache;
// We check here if the user is having viewing censors disabled (and also allowed to do so).
if (!$user->optionget('viewcensors') && $config['allow_nocensors'] && $auth->acl_get('u_chgcensors'))
{
$censors = array();
}
else
{
$censors = $cache->obtain_word_list();
}
}
if (count($censors))
{
return preg_replace($censors['match'], $censors['replace'], $text);
}
return $text;
}
If the required modifications are too difficult to easily post here, the only choice I and other affected admins have is to disable the word censoring function/delete all word censoring.