Add support for ignoring URLs when using word filters

This commit is contained in:
Benjamin Southall 2016-12-14 05:47:08 +09:00
parent d01bcf48d7
commit c9edbdc1c8

View File

@ -1782,6 +1782,37 @@ function wordfilters(&$body) {
global $config; global $config;
foreach ($config['wordfilters'] as $filter) { foreach ($config['wordfilters'] as $filter) {
if (isset($filter[3]) && $filter[3]) {
$refilter = $filter[0];
if (strncmp($filter[0], "/", 1) !== 0)
{
$refilter = "/.*" . $filter[0] . "/";
}
$body = preg_replace_callback($refilter,
function($matches) use ($filter , $body) {
foreach ($matches as $match) {
if (preg_match("/(http|https|ftp):\/\//i", $match)) {
return $match;
} else {
if (isset($filter[2]) && $filter[2]) {
$refilter = $filter[0];
if (strncmp($filter[0], "/", 1) !== 0)
{
$refilter = "/.*" . $filter[0] . "/";
}
if (is_callable($filter[1]))
return preg_replace_callback($refilter, $filter[1], $match);
else
return preg_replace($refilter, $filter[1], $match);
} else {
return str_ireplace($filter[0], $filter[1], $match);
}
}
}
}
, $body);
} else {
if (isset($filter[2]) && $filter[2]) { if (isset($filter[2]) && $filter[2]) {
if (is_callable($filter[1])) if (is_callable($filter[1]))
$body = preg_replace_callback($filter[0], $filter[1], $body); $body = preg_replace_callback($filter[0], $filter[1], $body);
@ -1791,8 +1822,11 @@ function wordfilters(&$body) {
$body = str_ireplace($filter[0], $filter[1], $body); $body = str_ireplace($filter[0], $filter[1], $body);
} }
} }
}
} }
function quote($body, $quote=true) { function quote($body, $quote=true) {
global $config; global $config;