From 28ea8829a07db685d4d016e1bdd3f320b73e9add Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 10 Jul 2021 17:35:01 +0200 Subject: unshorturl: A possibly better way to replace the links. --- unshorturl/unshorturl.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'unshorturl') diff --git a/unshorturl/unshorturl.php b/unshorturl/unshorturl.php index bf79fe3..70d7cf6 100644 --- a/unshorturl/unshorturl.php +++ b/unshorturl/unshorturl.php @@ -27,5 +27,14 @@ function unshorturl_prepare_body(&$body) { return; } - preg_replace('/https?:\/\/bit.ly\/[^\s]+/', '[hidden bitly link]', $body['html']); + $matches = []; + $num_matches = preg_match_all('/https?:\/\/bit\.ly\/\w+/', $body['html'], $links); + if ($num_matches > 0) { + foreach ($matches as $links) { + error_log('unshorturl: Links found: ' . implode(', ', $links)); + foreach($links as $l) { + str_replace($l, '[filtered bit.ly url]', $body['html']); + } + } + } } -- cgit v1.2.3