From 13ed5851567140a4a9b0f74998a1cf13d6827ccb Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 21 Mar 2021 23:32:49 +0000 Subject: [PATCH] Display rhe provider and author of a shared post --- src/Content/Text/BBCode.php | 68 +++++++++++++++++++++++++++++++++---- src/Util/ParseUrl.php | 15 -------- 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index eaa5e1640..12d9cfd7d 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -50,7 +50,7 @@ use Friendica\Util\XML; class BBCode { // Update this value to the current date whenever changes are made to BBCode::convert - const VERSION = '2020-12-18-video-embeds'; + const VERSION = '2021-03-21'; const INTERNAL = 0; const API = 2; @@ -154,6 +154,7 @@ class BBCode 'after' => '', 'image' => null, 'url' => '', + 'author_name' => '', 'provider_name' => '', 'provider_url' => '', 'title' => '', @@ -254,17 +255,66 @@ class BBCode $data['preview'] = html_entity_decode($preview, ENT_QUOTES, 'UTF-8'); } + $provider_name = ''; + preg_match("/publisher_name='(.*?)'/ism", $attributes, $matches); + if (!empty($matches[1])) { + $provider_name = $matches[1]; + } + + preg_match('/publisher_name="(.*?)"/ism', $attributes, $matches); + if (!empty($matches[1])) { + $provider_name = $matches[1]; + } + + if ($provider_name != '') { + $data['provider_name'] = html_entity_decode($provider_name, ENT_QUOTES, 'UTF-8'); + } + + $provider_url = ''; + preg_match("/publisher_url='(.*?)'/ism", $attributes, $matches); + if (!empty($matches[1])) { + $provider_url = $matches[1]; + } + + preg_match('/publisher_url="(.*?)"/ism', $attributes, $matches); + if (!empty($matches[1])) { + $provider_url = $matches[1]; + } + + if ($provider_url != '') { + $data['provider_url'] = html_entity_decode($provider_url, ENT_QUOTES, 'UTF-8'); + } + + $author_name = ''; + preg_match("/author_name='(.*?)'/ism", $attributes, $matches); + if (!empty($matches[1])) { + $author_name = $matches[1]; + } + + preg_match('/author_name="(.*?)"/ism', $attributes, $matches); + if (!empty($matches[1])) { + $author_name = $matches[1]; + } + + if (($author_name != '') && ($author_name != $provider_name)) { + $data['author_name'] = html_entity_decode($author_name, ENT_QUOTES, 'UTF-8'); + } + $data['description'] = trim($match[3]); $data['after'] = trim($match[4]); $parts = parse_url($data['url']); if (!empty($parts['scheme']) && !empty($parts['host'])) { - $data['provider_name'] = $parts['host']; - $data['provider_url'] = $parts['scheme'] . '://' . $parts['host']; + if (empty($data['provider_name'])) { + $data['provider_name'] = $parts['host']; + } + if (empty($data['provider_url'])) { + $data['provider_url'] = $parts['scheme'] . '://' . $parts['host']; - if (!empty($parts['port'])) { - $data['provider_url'] .= ':' . $parts['port']; + if (!empty($parts['port'])) { + $data['provider_url'] .= ':' . $parts['port']; + } } } @@ -688,8 +738,12 @@ class BBCode $return .= sprintf('
%s
', trim(self::convert($bbcode))); } - if (!empty($data['url'])) { - $return .= sprintf('%s', $data['url'], parse_url($data['url'], PHP_URL_HOST)); + if (!empty($data['provider_url']) && !empty($data['provider_name'])) { + if (!empty($data['author_name'])) { + $return .= sprintf('%s (%s)', $data['provider_url'], $data['author_name'], $data['provider_name']); + } else { + $return .= sprintf('%s', $data['provider_url'], $data['provider_name']); + } } if ($simplehtml != self::CONNECTORS) { diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 13cb55b73..af34a0cb6 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -820,11 +820,6 @@ class ParseUrl $jsonldinfo['publisher_name'] = trim($content); } - $content = JsonLD::fetchElement($jsonld, 'publisher', 'sameAs'); - if (!empty($content) && is_string($content)) { - $jsonldinfo['publisher_url'] = trim($content); - } - $content = JsonLD::fetchElement($jsonld, 'publisher', 'url'); if (!empty($content) && is_string($content)) { $jsonldinfo['publisher_url'] = trim($content); @@ -837,11 +832,6 @@ class ParseUrl $jsonldinfo['publisher_name'] = trim($content); } - $content = JsonLD::fetchElement($brand, 'sameAs'); - if (!empty($content) && is_string($content)) { - $jsonldinfo['publisher_url'] = trim($content); - } - $content = JsonLD::fetchElement($brand, 'url'); if (!empty($content) && is_string($content)) { $jsonldinfo['publisher_url'] = trim($content); @@ -1055,11 +1045,6 @@ class ParseUrl $jsonldinfo['publisher_description'] = trim($content); } - $content = JsonLD::fetchElement($jsonld, 'sameAs'); - if (!empty($content) && is_string($content)) { - $jsonldinfo['publisher_url'] = trim($content); - } - $content = JsonLD::fetchElement($jsonld, 'url'); if (!empty($content)) { $jsonldinfo['publisher_url'] = trim($content);