From 881cb456e2712e04d0a510619e06fa371567feaf Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 19 Jan 2023 08:44:06 -0500 Subject: [PATCH 1/4] Throw an exception when parse_url fails in HttpClient->request - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1383147421 --- src/Network/HTTPClient/Client/HttpClient.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Network/HTTPClient/Client/HttpClient.php b/src/Network/HTTPClient/Client/HttpClient.php index 2ef704df1..4ee084215 100644 --- a/src/Network/HTTPClient/Client/HttpClient.php +++ b/src/Network/HTTPClient/Client/HttpClient.php @@ -69,6 +69,10 @@ class HttpClient implements ICanSendHttpRequests $this->logger->debug('Request start.', ['url' => $url, 'method' => $method]); $host = parse_url($url, PHP_URL_HOST); + if (empty($host)) { + throw new \InvalidArgumentException('Unable to retrieve the host in URL: ' . $url); + } + if(!filter_var($host, FILTER_VALIDATE_IP) && !@dns_get_record($host . '.', DNS_A + DNS_AAAA) && !gethostbyname($host)) { $this->logger->debug('URL cannot be resolved.', ['url' => $url, 'callstack' => System::callstack(20)]); $this->profiler->stopRecording(); From 7e618856ab09ac74a3760e238c73ecb9515f6701 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 19 Jan 2023 09:02:05 -0500 Subject: [PATCH 2/4] Replace deprecated use of "self" in callables - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1383147421 --- src/Content/OEmbed.php | 2 +- src/Content/Smilies.php | 10 +++++----- src/Content/Text/BBCode.php | 16 ++++++++-------- src/Content/Text/HTML.php | 2 +- src/Content/Widget/TagCloud.php | 2 +- src/Database/DBA.php | 4 ++-- src/Model/Event.php | 2 +- src/Protocol/ActivityPub/Transmitter.php | 2 +- src/Util/ParseUrl.php | 2 +- src/Util/Proxy.php | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 7553cd9f8..562febdaf 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -316,7 +316,7 @@ class OEmbed if ($stopoembed == true) { return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "" . DI::l10n()->t('Embedding disabled') . " : $1", $text); } - return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", ['self', 'replaceCallback'], $text); + return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", [self::class, 'replaceCallback'], $text); } /** diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 5ebb5b64e..c51d9b330 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -218,8 +218,8 @@ class Smilies return $text; } - $text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', 'self::encode', $text); - $text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', 'self::encode', $text); + $text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', [self::class, 'encode'], $text); + $text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', [self::class, 'encode'], $text); if ($no_images) { $cleaned = ['texts' => [], 'icons' => []]; @@ -233,11 +233,11 @@ class Smilies $smilies = $cleaned; } - $text = preg_replace_callback('/<(3+)/', 'self::heartReplaceCallback', $text); + $text = preg_replace_callback('/<(3+)/', [self::class, 'heartReplaceCallback'], $text); $text = self::strOrigReplace($smilies['texts'], $smilies['icons'], $text); - $text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', 'self::decode', $text); - $text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', 'self::decode', $text); + $text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', [self::class, 'decode'], $text); + $text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', [self::class, 'decode'], $text); return $text; } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index f65eeeee2..e95ed0675 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1415,8 +1415,8 @@ class BBCode public static function cleanPictureLinks(string $text): string { DI::profiler()->startRecording('rendering'); - $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text); - $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $return); + $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $text); + $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $return); DI::profiler()->stopRecording(); return $return; } @@ -1450,7 +1450,7 @@ class BBCode { DI::profiler()->startRecording('rendering'); $regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; - $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body); + $body = preg_replace_callback($regexp, [self::class, 'mentionCallback'], $body); DI::profiler()->stopRecording(); return $body; } @@ -2002,12 +2002,12 @@ class BBCode if (!$for_plaintext) { if (in_array($simple_html, [self::OSTATUS, self::MASTODON_API, self::TWITTER_API, self::ACTIVITYPUB])) { - $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); - $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); + $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text); + $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text); } } else { $text = preg_replace("(\[url\](.*?)\[\/url\])ism", " $1 ", $text); - $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text); + $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'removePictureLinksCallback'], $text); } // Bookmarks in red - will be converted to bookmarks in friendica @@ -2017,7 +2017,7 @@ class BBCode "[bookmark=$1]$2[/bookmark]", $text); if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) { - $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text); + $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", [self::class, 'expandLinksCallback'], $text); //$text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $text); $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]', $text); } @@ -2327,7 +2327,7 @@ class BBCode $url_search_string = "^\[\]"; $text = preg_replace_callback( "/([@!])\[(.*?)\]\(([$url_search_string]*?)\)/ism", - ['self', 'bbCodeMention2DiasporaCallback'], + [self::class, 'bbCodeMention2DiasporaCallback'], $text ); } diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index c65e1d982..f9f340135 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -1032,7 +1032,7 @@ class HTML // the quotes, e.g.: // // concat("'foo'", '"', "bar") - return 'concat(' . implode(', \'"\', ', array_map(['self', 'xpathQuote'], explode('"', $value))) . ')'; + return 'concat(' . implode(', \'"\', ', array_map([self::class, 'xpathQuote'], explode('"', $value))) . ')'; } /** diff --git a/src/Content/Widget/TagCloud.php b/src/Content/Widget/TagCloud.php index 6f146f4ac..53d332f0a 100644 --- a/src/Content/Widget/TagCloud.php +++ b/src/Content/Widget/TagCloud.php @@ -144,7 +144,7 @@ class TagCloud $x ++; } - usort($tags, 'self::tagsSort'); + usort($tags, [self::class, 'tagsSort']); $range = max(0.01, $max - $min) * 1.0001; for ($x = 0; $x < count($tags); $x ++) { diff --git a/src/Database/DBA.php b/src/Database/DBA.php index ffeecfaa7..e29cd3038 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -527,7 +527,7 @@ class DBA public static function buildTableString(array $tables): string { // Quote each entry - return implode(',', array_map(['self', 'quoteIdentifier'], $tables)); + return implode(',', array_map([self::class, 'quoteIdentifier'], $tables)); } /** @@ -717,7 +717,7 @@ class DBA { $groupby_string = ''; if (!empty($params['group_by'])) { - $groupby_string = " GROUP BY " . implode(', ', array_map(['self', 'quoteIdentifier'], $params['group_by'])); + $groupby_string = " GROUP BY " . implode(', ', array_map([self::class, 'quoteIdentifier'], $params['group_by'])); } $order_string = ''; diff --git a/src/Model/Event.php b/src/Model/Event.php index ca22c32ac..e39ee5fd5 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -198,7 +198,7 @@ class Event public static function sortByDate(array $event_list): array { - usort($event_list, ['self', 'compareDatesCallback']); + usort($event_list, [self::class, 'compareDatesCallback']); return $event_list; } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 6e1180bca..bcff0b53b 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1661,7 +1661,7 @@ class Transmitter * * } elseif (($type == 'Article') && empty($data['summary'])) { * $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; - * $summary = preg_replace_callback($regexp, ['self', 'mentionAddrCallback'], $body); + * $summary = preg_replace_callback($regexp, [self::class, 'mentionAddrCallback'], $body); * $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($summary), 1000)); * } */ diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 9d19a4eba..f1e96dedc 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -646,7 +646,7 @@ class ParseUrl $arr_tags = str_getcsv($string); if (count($arr_tags)) { // add the # sign to every tag - array_walk($arr_tags, ['self', 'arrAddHashes']); + array_walk($arr_tags, [self::class, 'arrAddHashes']); return $arr_tags; } diff --git a/src/Util/Proxy.php b/src/Util/Proxy.php index 67a0becb0..7f3c94672 100644 --- a/src/Util/Proxy.php +++ b/src/Util/Proxy.php @@ -141,7 +141,7 @@ class Proxy { $html = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/', DI::baseUrl() . '/', $html); - return preg_replace_callback('/(]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'self::replaceUrl', $html); + return preg_replace_callback('/(]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', [self::class, 'replaceUrl'], $html); } /** From c79cec265274d458d27e16d039078738f639b48e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 19 Jan 2023 09:03:45 -0500 Subject: [PATCH 3/4] Replace deprecated uses of ${var} in strings - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1383147421 --- src/Navigation/Notifications/Repository/Notify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Navigation/Notifications/Repository/Notify.php b/src/Navigation/Notifications/Repository/Notify.php index 87671f7e6..2d15dd85c 100644 --- a/src/Navigation/Notifications/Repository/Notify.php +++ b/src/Navigation/Notifications/Repository/Notify.php @@ -614,7 +614,7 @@ class Notify extends BaseRepository $emailBuilder->setHeader('Message-ID', $message_id); $log_msg = "No previous notification found for this parent:\n" . - " parent: ${params['parent']}\n" . " uid : ${params['uid']}\n"; + " parent: {$params['parent']}\n" . " uid : {$params['uid']}\n"; $this->logger->info($log_msg); } else { // If not, just "follow" the thread. From 73c8720d4171c8de1f8a1f9d4acd7fdad148b2db Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 19 Jan 2023 09:32:46 -0500 Subject: [PATCH 4/4] Declare history property in Mastodon\Card - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1383173055 --- src/Object/Api/Mastodon/Card.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Object/Api/Mastodon/Card.php b/src/Object/Api/Mastodon/Card.php index d9b734456..c4d21f66a 100644 --- a/src/Object/Api/Mastodon/Card.php +++ b/src/Object/Api/Mastodon/Card.php @@ -54,6 +54,8 @@ class Card extends BaseDataTransferObject protected $image; /** @var string */ protected $blurhash; + /** @var array */ + protected $history; /** * Creates a card record from an attachment array.