From 60bec48f61ffbfd52258cc85bb0fca7d1eaa79f8 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 4 May 2021 11:35:23 +0000 Subject: [PATCH] Replace "curl" calls with centralized "head" function --- src/Content/Text/BBCode.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b03100fc9..c639923e3 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1104,20 +1104,14 @@ class BBCode $text = DI::cache()->get($cache_key); if (is_null($text)) { - $a = DI::app(); + $curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]); + if ($curlResult->isSuccess()) { + $mimetype = $curlResult->getHeader('Content-Type'); + } else { + $mimetype = ''; + } - $stamp1 = microtime(true); - - $ch = @curl_init($match[1]); - @curl_setopt($ch, CURLOPT_NOBODY, true); - @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - @curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent()); - @curl_exec($ch); - $curl_info = @curl_getinfo($ch); - - DI::profiler()->saveTimestamp($stamp1, "network"); - - if (substr($curl_info['content_type'], 0, 6) == 'image/') { + if (substr($mimetype, 0, 6) == 'image/') { $text = "[url=" . $match[1] . ']' . $match[1] . "[/url]"; } else { $text = "[url=" . $match[2] . ']' . $match[2] . "[/url]";