From c9edbdc1c86127b31b8f59c19c1904e41bcb3842 Mon Sep 17 00:00:00 2001 From: Benjamin Southall Date: Wed, 14 Dec 2016 05:47:08 +0900 Subject: [PATCH] Add support for ignoring URLs when using word filters --- inc/functions.php | 56 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 86efe789..ff7c129a 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1779,20 +1779,54 @@ function ReverseIPOctets($ip) { } function wordfilters(&$body) { - global $config; + global $config; + + 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 (is_callable($filter[1])) + $body = preg_replace_callback($filter[0], $filter[1], $body); + else + $body = preg_replace($filter[0], $filter[1], $body); + } else { + $body = str_ireplace($filter[0], $filter[1], $body); + } + } + } - foreach ($config['wordfilters'] as $filter) { - if (isset($filter[2]) && $filter[2]) { - if (is_callable($filter[1])) - $body = preg_replace_callback($filter[0], $filter[1], $body); - else - $body = preg_replace($filter[0], $filter[1], $body); - } else { - $body = str_ireplace($filter[0], $filter[1], $body); - } - } } + function quote($body, $quote=true) { global $config;