From 0ce0aa4d2c38ebfa94c9c2a4e009ef78030e7eee Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 13 Jan 2025 12:53:09 +0000 Subject: [PATCH] Replace Logger with DI::logger() in Util classes --- src/Util/Crypto.php | 15 ++++----- src/Util/DateTimeFormat.php | 4 +-- src/Util/HTTPSignature.php | 65 ++++++++++++++++++------------------- src/Util/Images.php | 11 +++---- src/Util/JsonLD.php | 27 ++++++++------- src/Util/LDSignature.php | 4 +-- src/Util/Network.php | 23 +++++++------ src/Util/ParseUrl.php | 39 +++++++++++----------- src/Util/Strings.php | 4 +-- src/Util/XML.php | 16 ++++----- 10 files changed, 101 insertions(+), 107 deletions(-) diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php index 8113697639..da4645ea0e 100644 --- a/src/Util/Crypto.php +++ b/src/Util/Crypto.php @@ -8,7 +8,6 @@ namespace Friendica\Util; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\DI; use phpseclib3\Crypt\PublicKeyLoader; @@ -27,7 +26,7 @@ class Crypto public static function rsaSign($data, $key, $alg = 'sha256') { if (empty($key)) { - Logger::warning('Empty key parameter'); + DI::logger()->warning('Empty key parameter'); } openssl_sign($data, $sig, $key, (($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg)); return $sig; @@ -43,7 +42,7 @@ class Crypto public static function rsaVerify($data, $sig, $key, $alg = 'sha256') { if (empty($key)) { - Logger::warning('Empty key parameter'); + DI::logger()->warning('Empty key parameter'); } return openssl_verify($data, $sig, $key, (($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg)); } @@ -80,7 +79,7 @@ class Crypto $result = openssl_pkey_new($openssl_options); if (empty($result)) { - Logger::notice('new_keypair: failed'); + DI::logger()->notice('new_keypair: failed'); return false; } @@ -161,7 +160,7 @@ class Crypto private static function encapsulateOther($data, $pubkey, $alg) { if (!$pubkey) { - Logger::notice('no key. data: '.$data); + DI::logger()->notice('no key. data: '.$data); } $fn = 'encrypt' . strtoupper($alg); if (method_exists(__CLASS__, $fn)) { @@ -173,7 +172,7 @@ class Crypto // log the offending call so we can track it down if (!openssl_public_encrypt($key, $k, $pubkey)) { $x = debug_backtrace(); - Logger::notice('RSA failed', ['trace' => $x[0]]); + DI::logger()->notice('RSA failed', ['trace' => $x[0]]); } $result['alg'] = $alg; @@ -203,7 +202,7 @@ class Crypto private static function encapsulateAes($data, $pubkey) { if (!$pubkey) { - Logger::notice('aes_encapsulate: no key. data: ' . $data); + DI::logger()->notice('aes_encapsulate: no key. data: ' . $data); } $key = random_bytes(32); @@ -214,7 +213,7 @@ class Crypto // log the offending call so we can track it down if (!openssl_public_encrypt($key, $k, $pubkey)) { $x = debug_backtrace(); - Logger::notice('aes_encapsulate: RSA failed.', ['data' => $x[0]]); + DI::logger()->notice('aes_encapsulate: RSA failed.', ['data' => $x[0]]); } $result['alg'] = 'aes256cbc'; diff --git a/src/Util/DateTimeFormat.php b/src/Util/DateTimeFormat.php index a8a900fd36..3e10eb1b53 100644 --- a/src/Util/DateTimeFormat.php +++ b/src/Util/DateTimeFormat.php @@ -7,10 +7,10 @@ namespace Friendica\Util; -use Friendica\Core\Logger; use DateTime; use DateTimeZone; use Exception; +use Friendica\DI; /** * Temporal class @@ -140,7 +140,7 @@ class DateTimeFormat try { $d = new DateTime(self::fix($s), $from_obj); } catch (\Throwable $e) { - Logger::warning('DateTimeFormat::convert: exception: ' . $e->getMessage()); + DI::logger()->warning('DateTimeFormat::convert: exception: ' . $e->getMessage()); $d = new DateTime('now', $from_obj); } } diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 5f668255ca..a544119616 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -7,7 +7,6 @@ namespace Friendica\Util; -use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Database\Database; use Friendica\Database\DBA; @@ -72,7 +71,7 @@ class HTTPSignature $sig_block = self::parseSigheader($headers['authorization']); if (!$sig_block) { - Logger::notice('no signature provided.'); + DI::logger()->notice('no signature provided.'); return $result; } @@ -102,7 +101,7 @@ class HTTPSignature $key = $key($sig_block['keyId']); } - Logger::info('Got keyID ' . $sig_block['keyId']); + DI::logger()->info('Got keyID ' . $sig_block['keyId']); if (!$key) { return $result; @@ -110,7 +109,7 @@ class HTTPSignature $x = Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm); - Logger::info('verified: ' . $x); + DI::logger()->info('verified: ' . $x); if (!$x) { return $result; @@ -293,7 +292,7 @@ class HTTPSignature $postResult = DI::httpClient()->post($target, $content, $headers, DI::config()->get('system', 'curl_timeout'), HttpClientRequest::ACTIVITYPUB); $return_code = $postResult->getReturnCode(); - Logger::info('Transmit to ' . $target . ' returned ' . $return_code); + DI::logger()->info('Transmit to ' . $target . ' returned ' . $return_code); self::setInboxStatus($target, ($return_code >= 200) && ($return_code <= 299)); @@ -327,7 +326,7 @@ class HTTPSignature return false; } - Logger::debug('Process directly', ['uid' => $uid, 'target' => $target, 'type' => $type]); + DI::logger()->debug('Process directly', ['uid' => $uid, 'target' => $target, 'type' => $type]); return Receiver::routeActivities($object_data, $type, true, true, $uid); } @@ -371,7 +370,7 @@ class HTTPSignature try { $postResult = self::post($data, $target, $owner); } catch (\Throwable $th) { - Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); + DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); return false; } $return_code = $postResult->getReturnCode(); @@ -402,7 +401,7 @@ class HTTPSignature $status = DBA::selectFirst('inbox-status', [], ['url' => $url]); if (empty($status)) { - Logger::warning('Unable to insert inbox-status row', $insertFields); + DI::logger()->warning('Unable to insert inbox-status row', $insertFields); return; } } @@ -476,12 +475,12 @@ class HTTPSignature try { $curlResult = self::fetchRaw($request, $uid); } catch (\Exception $exception) { - Logger::notice('Error fetching url', ['url' => $request, 'exception' => $exception]); + DI::logger()->notice('Error fetching url', ['url' => $request, 'exception' => $exception]); return []; } if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) { - Logger::debug('Fetching was unsuccessful', ['url' => $request, 'return-code' => $curlResult->getReturnCode(), 'error-number' => $curlResult->getErrorNumber(), 'error' => $curlResult->getError()]); + DI::logger()->debug('Fetching was unsuccessful', ['url' => $request, 'return-code' => $curlResult->getReturnCode(), 'error-number' => $curlResult->getErrorNumber(), 'error' => $curlResult->getError()]); return []; } @@ -510,7 +509,7 @@ class HTTPSignature } if (current(explode(';', $contentType)) == 'application/json') { - Logger::notice('Unexpected content type, possibly from a remote system that is not standard compliant.', ['content-type' => $contentType, 'url' => $url]); + DI::logger()->notice('Unexpected content type, possibly from a remote system that is not standard compliant.', ['content-type' => $contentType, 'url' => $url]); } return false; } @@ -572,7 +571,7 @@ class HTTPSignature } $return_code = $curlResult->getReturnCode(); - Logger::info('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code); + DI::logger()->info('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code); return $curlResult; } @@ -587,14 +586,14 @@ class HTTPSignature public static function getKeyIdContact(array $http_headers): array { if (empty($http_headers['HTTP_SIGNATURE'])) { - Logger::debug('No HTTP_SIGNATURE header', ['header' => $http_headers]); + DI::logger()->debug('No HTTP_SIGNATURE header', ['header' => $http_headers]); return []; } $sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']); if (empty($sig_block['keyId'])) { - Logger::debug('No keyId', ['sig_block' => $sig_block]); + DI::logger()->debug('No keyId', ['sig_block' => $sig_block]); return []; } @@ -614,14 +613,14 @@ class HTTPSignature public static function getSigner(string $content, array $http_headers) { if (empty($http_headers['HTTP_SIGNATURE'])) { - Logger::debug('No HTTP_SIGNATURE header'); + DI::logger()->debug('No HTTP_SIGNATURE header'); return false; } if (!empty($content)) { $object = json_decode($content, true); if (empty($object)) { - Logger::info('No object'); + DI::logger()->info('No object'); return false; } @@ -659,7 +658,7 @@ class HTTPSignature } if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) { - Logger::info('No headers or keyId'); + DI::logger()->info('No headers or keyId'); return false; } @@ -668,13 +667,13 @@ class HTTPSignature if (array_key_exists($h, $headers)) { $signed_data .= $h . ': ' . $headers[$h] . "\n"; } else { - Logger::info('Requested header field not found', ['field' => $h, 'header' => $headers]); + DI::logger()->info('Requested header field not found', ['field' => $h, 'header' => $headers]); } } $signed_data = rtrim($signed_data, "\n"); if (empty($signed_data)) { - Logger::info('Signed data is empty'); + DI::logger()->info('Signed data is empty'); return false; } @@ -697,18 +696,18 @@ class HTTPSignature } if (empty($algorithm)) { - Logger::info('No algorithm'); + DI::logger()->info('No algorithm'); return false; } $key = self::fetchKey($sig_block['keyId'], $actor); if (empty($key)) { - Logger::info('Empty key'); + DI::logger()->info('Empty key'); return false; } if (!empty($key['url']) && !empty($key['type']) && ($key['type'] == 'Tombstone')) { - Logger::info('Actor is a tombstone', ['key' => $key]); + DI::logger()->info('Actor is a tombstone', ['key' => $key]); if (!Contact::isLocal($key['url'])) { // We now delete everything that we possibly knew from this actor @@ -718,12 +717,12 @@ class HTTPSignature } if (empty($key['pubkey'])) { - Logger::info('Empty pubkey'); + DI::logger()->info('Empty pubkey'); return false; } if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key['pubkey'], $algorithm)) { - Logger::info('Verification failed', ['signed_data' => $signed_data, 'algorithm' => $algorithm, 'header' => $sig_block['headers'], 'http_headers' => $http_headers]); + DI::logger()->info('Verification failed', ['signed_data' => $signed_data, 'algorithm' => $algorithm, 'header' => $sig_block['headers'], 'http_headers' => $http_headers]); return false; } @@ -742,7 +741,7 @@ class HTTPSignature /// @todo add all hashes from the rfc if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) { - Logger::info('Digest does not match'); + DI::logger()->info('Digest does not match'); return false; } @@ -769,23 +768,23 @@ class HTTPSignature // Calculate with a grace period of 60 seconds to avoid slight time differences between the servers if (($created - 60) > $current) { - Logger::notice('Signature created in the future', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]); + DI::logger()->notice('Signature created in the future', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]); return false; } if ($current > $expired) { - Logger::notice('Signature expired', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]); + DI::logger()->notice('Signature expired', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]); return false; } - Logger::debug('Valid creation date', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]); + DI::logger()->debug('Valid creation date', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]); $hasGoodSignedContent = true; } // Check the content-length when it is part of the signed data if (in_array('content-length', $sig_block['headers'])) { if (strlen($content) != $headers['content-length']) { - Logger::info('Content length does not match'); + DI::logger()->info('Content length does not match'); return false; } } @@ -793,7 +792,7 @@ class HTTPSignature // Ensure that the authentication had been done with some content // Without this check someone could authenticate with fakeable data if (!$hasGoodSignedContent) { - Logger::info('No good signed content'); + DI::logger()->info('No good signed content'); return false; } @@ -815,17 +814,17 @@ class HTTPSignature $profile = APContact::getByURL($url); if (!empty($profile)) { - Logger::info('Taking key from id', ['id' => $id]); + DI::logger()->info('Taking key from id', ['id' => $id]); return ['url' => $url, 'pubkey' => $profile['pubkey'], 'type' => $profile['type']]; } elseif ($url != $actor) { $profile = APContact::getByURL($actor); if (!empty($profile)) { - Logger::info('Taking key from actor', ['actor' => $actor]); + DI::logger()->info('Taking key from actor', ['actor' => $actor]); return ['url' => $actor, 'pubkey' => $profile['pubkey'], 'type' => $profile['type']]; } } - Logger::notice('Key could not be fetched', ['url' => $url, 'actor' => $actor]); + DI::logger()->notice('Key could not be fetched', ['url' => $url, 'actor' => $actor]); return []; } } diff --git a/src/Util/Images.php b/src/Util/Images.php index f478a0b8b2..804ba73877 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -8,7 +8,6 @@ namespace Friendica\Util; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\DI; use Friendica\Model\Photo; use Friendica\Network\HTTPClient\Client\HttpClientAccept; @@ -103,7 +102,7 @@ class Images } } - Logger::debug('Undetected mimetype', ['mimetype' => $mimetype]); + DI::logger()->debug('Undetected mimetype', ['mimetype' => $mimetype]); return 0; } @@ -116,7 +115,7 @@ class Images public static function getExtensionByImageType(int $type): string { if (empty($type)) { - Logger::debug('Invalid image type', ['type' => $type]); + DI::logger()->debug('Invalid image type', ['type' => $type]); return ''; } @@ -201,7 +200,7 @@ class Images return $image['mime']; } - Logger::debug('Undetected mime type', ['image' => $image, 'size' => strlen($image_data)]); + DI::logger()->debug('Undetected mime type', ['image' => $image, 'size' => strlen($image_data)]); return ''; } @@ -284,7 +283,7 @@ class Images } } - Logger::debug('Unhandled extension', ['filename' => $filename, 'extension' => $ext]); + DI::logger()->debug('Unhandled extension', ['filename' => $filename, 'extension' => $ext]); return ''; } @@ -345,7 +344,7 @@ class Images try { $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4, '', HttpClientRequest::MEDIAVERIFIER); } catch (\Exception $exception) { - Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]); + DI::logger()->notice('Image is invalid', ['url' => $url, 'exception' => $exception]); return []; } } diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index fc91bcd0b6..833de559d7 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -8,7 +8,6 @@ namespace Friendica\Util; use Friendica\Core\Cache\Enum\Duration; -use Friendica\Core\Logger; use Exception; use Friendica\Core\System; use Friendica\DI; @@ -72,7 +71,7 @@ class JsonLD $url = DI::basePath() . '/static/apschema.jsonld'; break; default: - Logger::info('Got url', ['url' => $url]); + DI::logger()->info('Got url', ['url' => $url]); break; } } @@ -89,7 +88,7 @@ class JsonLD } if ($recursion > 5) { - Logger::error('jsonld bomb detected at: ' . $url); + DI::logger()->error('jsonld bomb detected at: ' . $url); System::exit(); } @@ -127,9 +126,9 @@ class JsonLD $messages[] = $currentException->getMessage(); } while ($currentException = $currentException->getPrevious()); - Logger::notice('JsonLD normalize error', ['messages' => $messages]); - Logger::info('JsonLD normalize error', ['trace' => $e->getTraceAsString()]); - Logger::debug('JsonLD normalize error', ['jsonobj' => $jsonobj]); + DI::logger()->notice('JsonLD normalize error', ['messages' => $messages]); + DI::logger()->info('JsonLD normalize error', ['trace' => $e->getTraceAsString()]); + DI::logger()->debug('JsonLD normalize error', ['jsonobj' => $jsonobj]); } return $normalized; @@ -176,18 +175,18 @@ class JsonLD $compacted = jsonld_compact($jsonobj, $context); } catch (Exception $e) { $compacted = false; - Logger::notice('compacting error', ['msg' => $e->getMessage(), 'previous' => $e->getPrevious(), 'line' => $e->getLine()]); + DI::logger()->notice('compacting error', ['msg' => $e->getMessage(), 'previous' => $e->getPrevious(), 'line' => $e->getLine()]); if ($logfailed && DI::config()->get('debug', 'ap_log_failure')) { $tempfile = tempnam(System::getTempPath(), 'failed-jsonld'); file_put_contents($tempfile, json_encode(['json' => $orig_json, 'msg' => $e->getMessage(), 'previous' => $e->getPrevious()], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); - Logger::notice('Failed message stored', ['file' => $tempfile]); + DI::logger()->notice('Failed message stored', ['file' => $tempfile]); } } $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); if ($json === false) { - Logger::notice('JSON encode->decode failed', ['orig_json' => $orig_json, 'compacted' => $compacted]); + DI::logger()->notice('JSON encode->decode failed', ['orig_json' => $orig_json, 'compacted' => $compacted]); $json = []; } @@ -212,7 +211,7 @@ class JsonLD // Workaround for servers with missing context // See issue https://github.com/nextcloud/social/issues/330 if (!in_array('https://w3id.org/security/v1', $json['@context'])) { - Logger::debug('Missing security context'); + DI::logger()->debug('Missing security context'); $json['@context'][] = 'https://w3id.org/security/v1'; } } @@ -220,16 +219,16 @@ class JsonLD // Issue 14448: Peertube transmits an unexpected type and schema URL. array_walk_recursive($json['@context'], function (&$value, $key) { if ($key == '@type' && $value == '@json') { - Logger::debug('"@json" converted to "@id"'); + DI::logger()->debug('"@json" converted to "@id"'); $value = '@id'; } if ($key == 'sc' && $value == 'http://schema.org/') { - Logger::debug('schema.org path fixed'); + DI::logger()->debug('schema.org path fixed'); $value = 'http://schema.org#'; } // Issue 14630: Wordpress Event Bridge uses a URL that cannot be retrieved if (is_int($key) && $value == 'https://schema.org/') { - Logger::debug('https schema.org path fixed'); + DI::logger()->debug('https schema.org path fixed'); $value = 'https://schema.org/docs/jsonldcontext.json#'; } }); @@ -237,7 +236,7 @@ class JsonLD // Bookwyrm transmits "id" fields with "null", which isn't allowed. array_walk_recursive($json, function (&$value, $key) { if ($key == 'id' && is_null($value)) { - Logger::debug('Fixed null id'); + DI::logger()->debug('Fixed null id'); $value = ''; } }); diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index 9d0c08d33b..8728915dd0 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -7,7 +7,7 @@ namespace Friendica\Util; -use Friendica\Core\Logger; +use Friendica\DI; use Friendica\Model\APContact; /** @@ -55,7 +55,7 @@ class LDSignature $dhash = self::hash(self::signableData($data)); $x = Crypto::rsaVerify($ohash . $dhash, base64_decode($data['signature']['signatureValue']), $pubkey); - Logger::info('LD-verify', ['verified' => (int)$x, 'actor' => $profile['url']]); + DI::logger()->info('LD-verify', ['verified' => (int)$x, 'actor' => $profile['url']]); if (empty($x)) { return false; diff --git a/src/Util/Network.php b/src/Util/Network.php index 60f4bbab23..a9c14779c7 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -8,7 +8,6 @@ namespace Friendica\Util; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPClient\Client\HttpClientAccept; @@ -79,13 +78,13 @@ class Network try { $curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options); } catch (\Exception $e) { - Logger::notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]); + DI::logger()->notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]); return false; } } if (!$curlResult->isSuccess()) { - Logger::notice('Url not reachable', ['host' => $host, 'url' => $url]); + DI::logger()->notice('Url not reachable', ['host' => $host, 'url' => $url]); return false; } elseif ($curlResult->isRedirectUrl()) { $url = $curlResult->getRedirectUrl(); @@ -184,7 +183,7 @@ class Network try { return self::isUriBlocked(new Uri($url)); } catch (\Throwable $e) { - Logger::warning('Invalid URL', ['url' => $url]); + DI::logger()->warning('Invalid URL', ['url' => $url]); return false; } } @@ -310,7 +309,7 @@ class Network $avatar['url'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO; } - Logger::info('Avatar: ' . $avatar['email'] . ' ' . $avatar['url']); + DI::logger()->info('Avatar: ' . $avatar['email'] . ' ' . $avatar['url']); return $avatar['url']; } @@ -508,7 +507,7 @@ class Network private static function idnToAscii(string $uri): string { if (!function_exists('idn_to_ascii')) { - Logger::error('IDN functions are missing.'); + DI::logger()->error('IDN functions are missing.'); return $uri; } return idn_to_ascii($uri); @@ -634,7 +633,7 @@ class Network } if ($sanitized != $url) { - Logger::debug('Link got sanitized', ['url' => $url, 'sanitzed' => $sanitized]); + DI::logger()->debug('Link got sanitized', ['url' => $url, 'sanitzed' => $sanitized]); } return $sanitized; } @@ -654,7 +653,7 @@ class Network try { return new Uri($uri); } catch (\Exception $e) { - Logger::debug('Invalid URI', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'uri' => $uri]); + DI::logger()->debug('Invalid URI', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'uri' => $uri]); return null; } } @@ -662,10 +661,10 @@ class Network /** * Remove an Url parameter * - * @param string $url - * @param string $parameter - * @return string - * @throws MalformedUriException + * @param string $url + * @param string $parameter + * @return string + * @throws MalformedUriException */ public static function removeUrlParameter(string $url, string $parameter): string { diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 97ecdb977b..8e86007695 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -12,7 +12,6 @@ use DOMXPath; use Friendica\Content\Text\HTML; use Friendica\Protocol\HTTP\MediaType; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; @@ -68,13 +67,13 @@ class ParseUrl try { $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options)); } catch (\Throwable $th) { - Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); + DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); return []; } } if (!$curlResult->isSuccess()) { - Logger::debug('Got HTTP Error', ['http error' => $curlResult->getReturnCode(), 'url' => $url]); + DI::logger()->debug('Got HTTP Error', ['http error' => $curlResult->getReturnCode(), 'url' => $url]); return []; } @@ -210,7 +209,7 @@ class ParseUrl ]; if ($count > 10) { - Logger::warning('Endless loop detected', ['url' => $url]); + DI::logger()->warning('Endless loop detected', ['url' => $url]); return $siteinfo; } @@ -219,25 +218,25 @@ class ParseUrl } else { $type = self::getContentType($url); } - Logger::info('Got content-type', ['content-type' => $type, 'url' => $url]); + DI::logger()->info('Got content-type', ['content-type' => $type, 'url' => $url]); if (!empty($type) && in_array($type[0], ['image', 'video', 'audio'])) { $siteinfo['type'] = $type[0]; return $siteinfo; } if ((count($type) >= 2) && (($type[0] != 'text') || ($type[1] != 'html'))) { - Logger::info('Unparseable content-type, quitting here, ', ['content-type' => $type, 'url' => $url]); + DI::logger()->info('Unparseable content-type, quitting here, ', ['content-type' => $type, 'url' => $url]); return $siteinfo; } try { $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]); } catch (\Throwable $th) { - Logger::info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]); + DI::logger()->info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]); return $siteinfo; } if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) { - Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]); + DI::logger()->info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]); return $siteinfo; } @@ -268,7 +267,7 @@ class ParseUrl // See https://github.com/friendica/friendica/issues/5470#issuecomment-418351211 $charset = str_ireplace('latin-1', 'latin1', $charset); - Logger::info('detected charset', ['charset' => $charset]); + DI::logger()->info('detected charset', ['charset' => $charset]); $body = iconv($charset, 'UTF-8//TRANSLIT', $body); } @@ -494,7 +493,7 @@ class ParseUrl } } - Logger::info('Siteinfo fetched', ['url' => $url, 'siteinfo' => $siteinfo]); + DI::logger()->info('Siteinfo fetched', ['url' => $url, 'siteinfo' => $siteinfo]); Hook::callAll('getsiteinfo', $siteinfo); @@ -746,7 +745,7 @@ class ParseUrl { $type = JsonLD::fetchElement($jsonld, '@type'); if (empty($type)) { - Logger::info('Empty type', ['url' => $siteinfo['url']]); + DI::logger()->info('Empty type', ['url' => $siteinfo['url']]); return $siteinfo; } @@ -823,7 +822,7 @@ class ParseUrl case 'ImageObject': return self::parseJsonLdMediaObject($siteinfo, $jsonld, 'images'); default: - Logger::info('Unknown type', ['type' => $type, 'url' => $siteinfo['url']]); + DI::logger()->info('Unknown type', ['type' => $type, 'url' => $siteinfo['url']]); return $siteinfo; } } @@ -907,7 +906,7 @@ class ParseUrl $jsonldinfo['author_name'] = trim($jsonld['author']); } - Logger::info('Fetched Author information', ['fetched' => $jsonldinfo]); + DI::logger()->info('Fetched Author information', ['fetched' => $jsonldinfo]); return array_merge($siteinfo, $jsonldinfo); } @@ -978,7 +977,7 @@ class ParseUrl $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld); - Logger::info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); + DI::logger()->info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); return array_merge($siteinfo, $jsonldinfo); } @@ -1018,7 +1017,7 @@ class ParseUrl $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld); - Logger::info('Fetched WebPage information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); + DI::logger()->info('Fetched WebPage information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); return array_merge($siteinfo, $jsonldinfo); } @@ -1058,7 +1057,7 @@ class ParseUrl $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld); - Logger::info('Fetched WebSite information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); + DI::logger()->info('Fetched WebSite information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); return array_merge($siteinfo, $jsonldinfo); } @@ -1107,7 +1106,7 @@ class ParseUrl $jsonldinfo['publisher_url'] = Network::sanitizeUrl($content); } - Logger::info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); + DI::logger()->info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); return array_merge($siteinfo, $jsonldinfo); } @@ -1146,14 +1145,14 @@ class ParseUrl $content = JsonLD::fetchElement($jsonld, 'image', 'url', '@type', 'ImageObject'); if (!empty($content) && !is_string($content)) { - Logger::notice('Unexpected return value for the author image', ['content' => $content]); + DI::logger()->notice('Unexpected return value for the author image', ['content' => $content]); } if (!empty($content) && is_string($content)) { $jsonldinfo['author_img'] = trim($content); } - Logger::info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); + DI::logger()->info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); return array_merge($siteinfo, $jsonldinfo); } @@ -1229,7 +1228,7 @@ class ParseUrl } } - Logger::info('Fetched Media information', ['url' => $siteinfo['url'], 'fetched' => $media]); + DI::logger()->info('Fetched Media information', ['url' => $siteinfo['url'], 'fetched' => $media]); $siteinfo[$name][] = $media; return $siteinfo; } diff --git a/src/Util/Strings.php b/src/Util/Strings.php index fbf691879e..60bb83e0d5 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -8,7 +8,7 @@ namespace Friendica\Util; use Friendica\Content\ContactSelector; -use Friendica\Core\Logger; +use Friendica\DI; use ParagonIE\ConstantTime\Base64; /** @@ -498,7 +498,7 @@ class Strings ); if (is_null($return)) { - Logger::notice('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId]); + DI::logger()->notice('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId]); } $text = $callback($return ?? $text) ?? ''; diff --git a/src/Util/XML.php b/src/Util/XML.php index 52a1d9f3bf..8cf0e86b82 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -11,7 +11,7 @@ use DOMDocument; use DOMElement; use DOMNode; use DOMXPath; -use Friendica\Core\Logger; +use Friendica\DI; use SimpleXMLElement; /** @@ -256,7 +256,7 @@ class XML } if (!function_exists('xml_parser_create')) { - Logger::error('Xml::toArray: parser function missing'); + DI::logger()->error('Xml::toArray: parser function missing'); return []; } @@ -272,7 +272,7 @@ class XML } if (!$parser) { - Logger::warning('Xml::toArray: xml_parser_create: no resource'); + DI::logger()->warning('Xml::toArray: xml_parser_create: no resource'); return []; } @@ -284,9 +284,9 @@ class XML @xml_parser_free($parser); if (! $xml_values) { - Logger::debug('Xml::toArray: libxml: parse error: ' . $contents); + DI::logger()->debug('Xml::toArray: libxml: parse error: ' . $contents); foreach (libxml_get_errors() as $err) { - Logger::debug('libxml: parse: ' . $err->code . ' at ' . $err->line . ':' . $err->column . ' : ' . $err->message); + DI::logger()->debug('libxml: parse: ' . $err->code . ' at ' . $err->line . ':' . $err->column . ' : ' . $err->message); } libxml_clear_errors(); return []; @@ -436,11 +436,11 @@ class XML $x = @simplexml_load_string($s); if (!$x) { if (!$suppress_log) { - Logger::error('Error(s) while parsing XML string.'); + DI::logger()->error('Error(s) while parsing XML string.'); foreach (libxml_get_errors() as $err) { - Logger::info('libxml error', ['code' => $err->code, 'position' => $err->line . ':' . $err->column, 'message' => $err->message]); + DI::logger()->info('libxml error', ['code' => $err->code, 'position' => $err->line . ':' . $err->column, 'message' => $err->message]); } - Logger::debug('Erroring XML string', ['xml' => $s]); + DI::logger()->debug('Erroring XML string', ['xml' => $s]); } libxml_clear_errors(); }