X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FParseUrl.php;h=79f427a654df4b5f672bc52f3470ebe01deb2b5b;hb=e1863951986ba5be173758324a00652bc5af870c;hp=f21528353d3fee175d1259b0c3b86ca501777031;hpb=6aa1dcfad371f34fea1f8e39b73de2cc3dd05784;p=friendica.git diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index f21528353d..79f427a654 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -24,6 +24,8 @@ namespace Friendica\Util; use DOMDocument; use DOMXPath; use Friendica\Content\OEmbed; +use Friendica\Content\Text\HTML; +use Friendica\Protocol\HTTP\MediaType; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Database\Database; @@ -68,7 +70,12 @@ class ParseUrl $options = []; } - $curlResult = DI::httpClient()->head($url, array_merge([HttpClientOptions::ACCEPT_CONTENT => $accept], $options)); + try { + $curlResult = DI::httpClient()->head($url, array_merge([HttpClientOptions::ACCEPT_CONTENT => $accept], $options)); + } catch (\Exception $e) { + DI::logger()->debug('Got exception', ['url' => $url, 'message' => $e->getMessage()]); + return []; + } // Workaround for systems that can't handle a HEAD request. Don't retry on timeouts. if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() >= 400) && !in_array($curlResult->getReturnCode(), [408, 504])) { @@ -89,7 +96,7 @@ class ParseUrl } /** - * Search for chached embeddable data of an url otherwise fetch it + * Search for cached embeddable data of an url otherwise fetch it * * @param string $url The url of the page which should be scraped * @param bool $do_oembed The false option is used by the function fetch_oembed() @@ -283,25 +290,13 @@ class ParseUrl } $charset = ''; - // Look for a charset, first in headers - // Expected form: Content-Type: text/html; charset=ISO-8859-4 - if (preg_match('/charset=([a-z0-9-_.\/]+)/i', $curlResult->getContentType(), $matches)) { - $charset = trim(trim(trim(array_pop($matches)), ';,')); - } else { - // Then in body that gets precedence - // Expected forms: - // - - // - - // - - // - - // We escape