X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FPageInfo.php;h=fa6a93994de978d55dd4e195271edba3610fb1f2;hb=1f889b6086c5fe81a4ab694a55efa1134f8326b3;hp=806a92a03c5cac6c4f191920b373f6700ff09d10;hpb=70bf75c3424215c4bcec10b208f74253fccfb3b7;p=friendica.git diff --git a/src/Content/PageInfo.php b/src/Content/PageInfo.php index 806a92a03c..fa6a93994d 100644 --- a/src/Content/PageInfo.php +++ b/src/Content/PageInfo.php @@ -1,6 +1,6 @@ $body]); + Logger::debug('add_page_info_to_body: fetch page info for body', ['body' => $body]); $url = self::getRelevantUrlFromBody($body, $searchNakedUrls); if (!$url) { @@ -64,7 +64,7 @@ class PageInfo * @return string * @throws HTTPException\InternalServerErrorException */ - public static function appendDataToBody(string $body, array $data, bool $no_photos = false) + public static function appendDataToBody(string $body, array $data, bool $no_photos = false): string { // Only one [attachment] tag per body is allowed $existingAttachmentPos = strpos($body, '[attachment'); @@ -73,7 +73,7 @@ class PageInfo // Additional link attachments are prepended before the existing [attachment] tag $body = substr_replace($body, "\n[bookmark=" . $data['url'] . ']' . $linkTitle . "[/bookmark]\n", $existingAttachmentPos, 0); } else { - $footer = PageInfo::getFooterFromData($data, $no_photos); + $footer = self::getFooterFromData($data, $no_photos); $body = self::stripTrailingUrlFromBody($body, $data['url']); $body .= "\n" . $footer; } @@ -90,7 +90,7 @@ class PageInfo * @return string * @throws HTTPException\InternalServerErrorException */ - public static function getFooterFromUrl(string $url, bool $no_photos = false, string $photo = '', bool $keywords = false, string $keyword_denylist = '') + public static function getFooterFromUrl(string $url, bool $no_photos = false, string $photo = '', bool $keywords = false, string $keyword_denylist = ''): string { $data = self::queryUrl($url, $photo, $keywords, $keyword_denylist); @@ -103,7 +103,7 @@ class PageInfo * @return string * @throws HTTPException\InternalServerErrorException */ - public static function getFooterFromData(array $data, bool $no_photos = false) + public static function getFooterFromData(array $data, bool $no_photos = false): string { Hook::callAll('page_info_data', $data); @@ -131,7 +131,7 @@ class PageInfo // Escape some bad characters $text = "[attachment"; - foreach (['type', 'url', 'title', 'alternative_title', 'publisher', 'publisher_url', 'publisher_image', 'author', 'author_url', 'author_image'] as $field) { + foreach (['type', 'url', 'title', 'alternative_title', 'publisher_name', 'publisher_url', 'publisher_img', 'author_name', 'author_url', 'author_img'] as $field) { if (!empty($data[$field])) { $text .= " " . $field . "='" . str_replace(['[', ']'], ['[', ']'], htmlentities($data[$field], ENT_QUOTES, 'UTF-8', false)) . "'"; } @@ -155,7 +155,7 @@ class PageInfo if (empty($data['text'])) { $data['text'] = $data['title']; } - + if (empty($data['text'])) { $data['text'] = $data['url']; } @@ -187,7 +187,7 @@ class PageInfo */ public static function queryUrl(string $url, string $photo = '', bool $keywords = false, string $keyword_denylist = '') { - $data = ParseUrl::getSiteinfoCached($url, true); + $data = ParseUrl::getSiteinfoCached($url); if ($photo != '') { $data['images'][0]['src'] = $photo; @@ -208,7 +208,7 @@ class PageInfo } } - Logger::info('fetch page info for URL', ['url' => $url, 'data' => $data]); + Logger::debug('fetch page info for URL', ['url' => $url, 'data' => $data]); return $data; } @@ -220,7 +220,7 @@ class PageInfo * @return array * @throws HTTPException\InternalServerErrorException */ - public static function getTagsFromUrl(string $url, string $photo = '', string $keyword_denylist = '') + public static function getTagsFromUrl(string $url, string $photo = '', string $keyword_denylist = ''): array { $data = self::queryUrl($url, $photo, true, $keyword_denylist); @@ -246,17 +246,22 @@ class PageInfo * @param bool $searchNakedUrls Whether we should pick a naked URL (outside of BBCode tags) as a last resort * @return string|null */ - protected static function getRelevantUrlFromBody(string $body, bool $searchNakedUrls = false) + public static function getRelevantUrlFromBody(string $body, bool $searchNakedUrls = false) { $URLSearchString = 'https?://[^\[\]]*'; // Fix for Mastodon where the mentions are in a different format $body = preg_replace("~\[url=($URLSearchString)]([#!@])(.*?)\[/url]~is", '$2[url=$1]$3[/url]', $body); - preg_match("~(?