From 234bdff7ab23e6d8f38e3a1668746cd880856ad9 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Jul 2021 15:06:15 +0000 Subject: [PATCH] Improved link check --- src/Model/Post/Link.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Model/Post/Link.php b/src/Model/Post/Link.php index 0a593ddee..3bd92bfe3 100644 --- a/src/Model/Post/Link.php +++ b/src/Model/Post/Link.php @@ -39,16 +39,21 @@ class Link return $url; } + if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https'])) { + Logger::info('Bad URL, quitting', ['uri-id' => $uri_id, 'url' => $url]); + return $url; + } + $link = DBA::selectFirst('post-link', ['id'], ['uri-id' => $uri_id, 'url' => $url]); if (!empty($link['id'])) { $id = $link['id']; - Logger::info('Found', ['id' => $id, 'url' => $url]); + Logger::info('Found', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]); } else { $mime = self::fetchMimeType($url); DBA::insert('post-link', ['uri-id' => $uri_id, 'url' => $url, 'mimetype' => $mime]); $id = DBA::lastInsertId(); - Logger::info('Inserted', ['id' => $id, 'url' => $url]); + Logger::info('Inserted', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]); } if (empty($id)) { @@ -106,9 +111,7 @@ class Link if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) { foreach ($pictures as $picture) { - if (parse_url($picture[1], PHP_URL_SCHEME)) { - $body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body); - } + $body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body); } }