From 48182a95fbcfdbabf0a6ac2b7238446e05076268 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Oct 2022 21:50:20 +0000 Subject: [PATCH 01/11] Improve quote share ("message_id" added) --- mod/item.php | 2 ++ mod/share.php | 13 ++----------- src/App/Router.php | 2 +- src/Content/Text/BBCode.php | 9 +++++++-- src/Model/Item.php | 12 ++++++------ src/Protocol/ActivityPub/Processor.php | 5 +++-- src/Protocol/Diaspora.php | 7 ++++--- src/Protocol/Email.php | 4 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/mod/item.php b/mod/item.php index 6793d44342..4dc1d77ce3 100644 --- a/mod/item.php +++ b/mod/item.php @@ -621,6 +621,7 @@ function item_post(App $a) { $datarray["author-uri-id"] = ItemURI::getIdByURI($datarray["author-link"]); $datarray["owner-updated"] = ''; $datarray["has-media"] = false; + $datarray['body'] = Item::improveSharedDataInBody($datarray); $o = DI::conversation()->create([array_merge($contact_record, $datarray)], 'search', false, true); @@ -661,6 +662,7 @@ function item_post(App $a) { } $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']); + $datarray['body'] = Item::improveSharedDataInBody($datarray); if ($orig_post) { $fields = [ diff --git a/mod/share.php b/mod/share.php index 2f836c5aa0..09097f070f 100644 --- a/mod/share.php +++ b/mod/share.php @@ -20,7 +20,6 @@ */ use Friendica\App; -use Friendica\Content\Text\BBCode; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -34,8 +33,7 @@ function share_init(App $a) { System::exit(); } - $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar', - 'guid', 'created', 'plink', 'title']; + $fields = ['private', 'body', 'uri']; $item = Post::selectFirst($fields, ['id' => $post_id]); if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { @@ -46,14 +44,7 @@ function share_init(App $a) { $pos = strpos($item['body'], "[share"); $o = substr($item['body'], $pos); } else { - $o = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']); - - if ($item['title']) { - $o .= '[h3]'.$item['title'].'[/h3]'."\n"; - } - - $o .= $item['body']; - $o .= "[/share]"; + $o = "[share message_id='" . $item['uri'] . "'][/share]"; } echo $o; diff --git a/src/App/Router.php b/src/App/Router.php index 9906568925..a4fe4f9411 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -339,7 +339,7 @@ class Router if ($this->dice_profiler_threshold > 0) { $dur = floatval(microtime(true) - $stamp); if ($dur >= $this->dice_profiler_threshold) { - $this->logger->warning('Dice module creation lasts too long.', ['duration' => round($dur, 3), 'module' => $module_class, 'parameters' => $module_parameters]); + $this->logger->notice('Dice module creation lasts too long.', ['duration' => round($dur, 3), 'module' => $module_class, 'parameters' => $module_parameters]); } } } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 0a07e18f40..f735833036 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1047,7 +1047,7 @@ class BBCode private static function extractShareAttributes(string $shareString): array { $attributes = []; - foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid'] as $field) { + foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid', 'message_id'] as $field) { preg_match("/$field=(['\"])(.+?)\\1/ism", $shareString, $matches); $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'); } @@ -2458,10 +2458,11 @@ class BBCode * @param string $link Post source URL * @param string $posted Post created date * @param string|null $guid Post guid (if any) + * @param string|null $uri Post uri (if any) * @return string * @TODO Rewrite to handle over whole record array */ - public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null): string + public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null, string $uri = null): string { DI::profiler()->startRecording('rendering'); $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author) . @@ -2474,6 +2475,10 @@ class BBCode $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); } + if ($uri) { + $header .= "' message_id='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $uri); + } + $header .= "']"; DI::profiler()->stopRecording(); diff --git a/src/Model/Item.php b/src/Model/Item.php index acd2360ef8..6cce806bed 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3667,22 +3667,22 @@ class Item public static function improveSharedDataInBody(array $item): string { $shared = BBCode::fetchShareAttributes($item['body']); - if (empty($shared['link'])) { + if (empty($shared['link']) && empty($shared['message_id'])) { return $item['body']; } - $id = self::fetchByLink($shared['link']); - Logger::info('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'callstack' => System::callstack()]); + $id = self::fetchByLink($shared['link'] ?: $shared['message_id']); + Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]); if (!$id) { return $item['body']; } - $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]); + $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'uri', 'title', 'body'], ['id' => $id]); if (!DBA::isResult($shared_item)) { return $item['body']; } - $shared_content = BBCode::getShareOpeningTag($shared_item['author-name'], $shared_item['author-link'], $shared_item['author-avatar'], $shared_item['plink'], $shared_item['created'], $shared_item['guid']); + $shared_content = BBCode::getShareOpeningTag($shared_item['author-name'], $shared_item['author-link'], $shared_item['author-avatar'], $shared_item['plink'], $shared_item['created'], $shared_item['guid'], $shared_item['uri']); if (!empty($shared_item['title'])) { $shared_content .= '[h3]'.$shared_item['title'].'[/h3]'."\n"; @@ -3691,7 +3691,7 @@ class Item $shared_content .= $shared_item['body']; $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $shared_content . '[/share]', $item['body']); - Logger::info('New shared data', ['uri-id' => $item['uri-id'], 'id' => $id, 'shared_item' => $shared_item]); + Logger::debug('New shared data', ['uri-id' => $item['uri-id'], 'id' => $id, 'shared_item' => $shared_item]); return $item['body']; } } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index f75e6189b8..bfd70f2bab 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -883,7 +883,7 @@ class Processor return ''; } - $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]); + $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'uri', 'title', 'body'], ['id' => $id]); if (!DBA::isResult($shared_item)) { return ''; } @@ -894,7 +894,8 @@ class Processor $shared_item['author-avatar'], $shared_item['plink'], $shared_item['created'], - $shared_item['guid'] + $shared_item['guid'], + $shared_item['uri'], ); if (!empty($shared_item['title'])) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 781ae57a36..bcf049945f 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2483,7 +2483,8 @@ class Diaspora $original_item['author-avatar'], $original_item['plink'], $original_item['created'], - $original_item['guid'] + $original_item['guid'], + $original_item['uri'], ); if (!empty($original_item['title'])) { @@ -4181,7 +4182,7 @@ class Diaspora public static function performReshare(int $UriId, int $uid): int { - $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; + $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'uri']; $item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]); if (!DBA::isResult($item)) { return 0; @@ -4191,7 +4192,7 @@ class Diaspora $pos = strpos($item['body'], '[share'); $post = substr($item['body'], $pos); } else { - $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']); + $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid'], $item['uri']); if (!empty($item['title'])) { $post .= '[h3]' . $item['title'] . "[/h3]\n"; diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index bcde2b4e29..be10ca0815 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -51,12 +51,12 @@ class Email $errors = imap_errors(); if (!empty($errors)) { - Logger::warning('IMAP Errors occured', ['errors' => $errors]); + Logger::notice('IMAP Errors occured', ['errors' => $errors]); } $alerts = imap_alerts(); if (!empty($alerts)) { - Logger::warning('IMAP Alerts occured: ', ['alerts' => $alerts]); + Logger::notice('IMAP Alerts occured: ', ['alerts' => $alerts]); } return $mbox; From 8e9acfe210b2d5377159f3abbcef4c2e40332c36 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 05:22:10 +0000 Subject: [PATCH 02/11] Fix tests? --- tests/src/Content/Text/BBCodeTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 9f293b706c..8b678042e3 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -487,6 +487,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'link' => '', 'posted' => '', 'guid' => '', + 'message_id' => '', 'comment' => '', 'shared' => '', ], @@ -500,6 +501,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'link' => '', 'posted' => '', 'guid' => '', + 'message_id' => '', 'comment' => 'comment', 'shared' => 'shared', ], @@ -516,6 +518,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'posted' => '2022-06-16 12:34:10', 'guid' => '735a2029-1062-ab23-42e4-f9c631220243', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => '', 'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? @@ -528,6 +531,7 @@ Lucas: For the right price, yes.', link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' posted='2022-06-16 12:34:10' guid='735a2029-1062-ab23-42e4-f9c631220243' + message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.[/share]", @@ -540,6 +544,7 @@ Lucas: For the right price, yes.[/share]", 'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'posted' => '2022-06-16 12:34:10', 'guid' => '', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => '', 'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? @@ -551,6 +556,7 @@ Lucas: For the right price, yes.', avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png' link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' posted='2022-06-16 12:34:10' + message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.[/share]", @@ -563,6 +569,7 @@ Lucas: For the right price, yes.[/share]", 'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'posted' => '2022-06-16 12:34:10', 'guid' => '', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => '', 'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? @@ -573,6 +580,7 @@ Lucas: For the right price, yes.', profile="https://friendica.mrpetovan.com/profile/hypolite" avatar="https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png" link="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243" + message_id="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243" posted="2022-06-16 12:34:10" ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? From d7a9745ffd2d20581a04bd70fcf1459a36c96377 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 05:51:36 +0000 Subject: [PATCH 03/11] Simplified share element --- mod/share.php | 2 +- src/Model/Item.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mod/share.php b/mod/share.php index 09097f070f..792ee40082 100644 --- a/mod/share.php +++ b/mod/share.php @@ -44,7 +44,7 @@ function share_init(App $a) { $pos = strpos($item['body'], "[share"); $o = substr($item['body'], $pos); } else { - $o = "[share message_id='" . $item['uri'] . "'][/share]"; + $o = "[share]" . $item['uri'] . "[/share]"; } echo $o; diff --git a/src/Model/Item.php b/src/Model/Item.php index 6cce806bed..a88e61124a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3666,9 +3666,18 @@ class Item */ public static function improveSharedDataInBody(array $item): string { - $shared = BBCode::fetchShareAttributes($item['body']); - if (empty($shared['link']) && empty($shared['message_id'])) { - return $item['body']; + if (preg_match('#\[share](.*)\[/share]#', $item['body'], $matches)) { + $shared = [ + 'message_id' => $matches[1], + 'link' => '', + 'guid' => '', + 'profile' => '', + ]; + } else { + $shared = BBCode::fetchShareAttributes($item['body']); + if (empty($shared['link']) && empty($shared['message_id'])) { + return $item['body']; + } } $id = self::fetchByLink($shared['link'] ?: $shared['message_id']); From 1ef5730d3dbfe2fa6012082251dd7c03c61f7ccd Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 05:54:17 +0000 Subject: [PATCH 04/11] "share" added to autocomplete --- view/js/autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index d9fcddd7b8..91dd0053f1 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -366,7 +366,7 @@ function string2bb(element) { $.fn.bbco_autocomplete = function(type) { if (type === 'bbcode') { - var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'quote', 'code', 'spoiler', 'map', 'img', 'url', 'audio', 'video', 'embed', 'youtube', 'vimeo', 'list', 'ul', 'ol', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'nobb', 'noparse', 'pre', 'abstract']; + var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'quote', 'code', 'spoiler', 'map', 'img', 'url', 'audio', 'video', 'embed', 'youtube', 'vimeo', 'list', 'ul', 'ol', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'nobb', 'noparse', 'pre', 'abstract', 'share']; var open_elements = ['*', 'hr']; var elements = open_close_elements.concat(open_elements); From ef934db61462f5882cf180307c9acbe11d0145d4 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 07:41:03 +0000 Subject: [PATCH 05/11] Moved the share interpretation --- src/Content/Text/BBCode.php | 13 +++++++++++++ src/Model/Item.php | 17 ++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index f735833036..fe2e94c684 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1021,6 +1021,19 @@ class BBCode public static function fetchShareAttributes(string $text): array { DI::profiler()->startRecording('rendering'); + if (preg_match('#(.*?)\[share](.*)\[/share]#', $text, $matches)) { + return [ + 'author' => '', + 'profile' => '', + 'avatar' => '', + 'link' => '', + 'posted' => '', + 'guid' => '', + 'message_id' => $matches[2], + 'comment' => trim($matches[1]), + 'shared' => '', + ]; + } // See Issue https://github.com/friendica/friendica/issues/10454 // Hashtags in usernames are expanded to links. This here is a quick fix. $text = preg_replace('~([@!#])\[url=.*?](.*?)\[/url]~ism', '$1$2', $text); diff --git a/src/Model/Item.php b/src/Model/Item.php index a88e61124a..9253a282e3 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3666,19 +3666,10 @@ class Item */ public static function improveSharedDataInBody(array $item): string { - if (preg_match('#\[share](.*)\[/share]#', $item['body'], $matches)) { - $shared = [ - 'message_id' => $matches[1], - 'link' => '', - 'guid' => '', - 'profile' => '', - ]; - } else { - $shared = BBCode::fetchShareAttributes($item['body']); - if (empty($shared['link']) && empty($shared['message_id'])) { - return $item['body']; - } - } + $shared = BBCode::fetchShareAttributes($item['body']); + if (empty($shared['link']) && empty($shared['message_id'])) { + return $item['body']; + } $id = self::fetchByLink($shared['link'] ?: $shared['message_id']); Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]); From f8d4ab1830e286f5d8005c79dd6269f21739f3c9 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 07:55:44 +0000 Subject: [PATCH 06/11] Whitespace removed --- mod/item.php | 2 +- src/Content/Text/BBCode.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/item.php b/mod/item.php index 4dc1d77ce3..6c01cdbc18 100644 --- a/mod/item.php +++ b/mod/item.php @@ -401,7 +401,7 @@ function item_post(App $a) { $body = $item['body']; $inform = $item['inform']; $postopts = $item['postopts']; - $private = $item['private']; + $private = $item['private']; $str_contact_allow = $item['allow_cid']; $str_group_allow = $item['allow_gid']; $str_contact_deny = $item['deny_cid']; diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index fe2e94c684..bef48dcac8 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -294,7 +294,7 @@ class BBCode // Simplify image codes $post['text'] = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $post['text']); $post['text'] = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $post['text']); - + // if nothing is found, it maybe having an image. if (!isset($post['type'])) { if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $post['text'], $pictures, PREG_SET_ORDER)) { From 21bd2a839676ecb3254de3bdd2019718b0e1d2d0 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 07:57:20 +0000 Subject: [PATCH 07/11] More whitespace --- src/Model/Item.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 9253a282e3..f6c990bb44 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1930,7 +1930,7 @@ class Item { $latin = ''; $non_latin = ''; - for ($i = 0; $i < mb_strlen($body); $i++) { + for ($i = 0; $i < mb_strlen($body); $i++) { $character = mb_substr($body, $i, 1); $ord = mb_ord($character); @@ -3669,7 +3669,7 @@ class Item $shared = BBCode::fetchShareAttributes($item['body']); if (empty($shared['link']) && empty($shared['message_id'])) { return $item['body']; - } + } $id = self::fetchByLink($shared['link'] ?: $shared['message_id']); Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]); From f340fc6efaa17c447f2784e5219c99b270c6b8fd Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 08:00:09 +0000 Subject: [PATCH 08/11] Harmonized regular expression --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index bef48dcac8..93d1be2c44 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1021,7 +1021,7 @@ class BBCode public static function fetchShareAttributes(string $text): array { DI::profiler()->startRecording('rendering'); - if (preg_match('#(.*?)\[share](.*)\[/share]#', $text, $matches)) { + if (preg_match('~(.*?)\[share](.*)\[/share]~ism', $text, $matches)) { return [ 'author' => '', 'profile' => '', From a07fd7d7c26d98349958b535b0e2fc89373cd70a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 08:07:12 +0000 Subject: [PATCH 09/11] Spaces to tabs --- tests/src/Content/Text/BBCodeTest.php | 68 +++++++++++++-------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 8b678042e3..0d9be478b9 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -482,14 +482,14 @@ Karl Marx - Die ursprüngliche Akkumulation 'empty-tag' => [ 'expected' => [ 'author' => '', - 'profile' => '', - 'avatar' => '', - 'link' => '', - 'posted' => '', - 'guid' => '', - 'message_id' => '', - 'comment' => '', - 'shared' => '', + 'profile' => '', + 'avatar' => '', + 'link' => '', + 'posted' => '', + 'guid' => '', + 'message_id' => '', + 'comment' => '', + 'shared' => '', ], 'text' => '[share][/share]', ], @@ -501,7 +501,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'link' => '', 'posted' => '', 'guid' => '', - 'message_id' => '', + 'message_id' => '', 'comment' => 'comment', 'shared' => 'shared', ], @@ -518,21 +518,21 @@ Karl Marx - Die ursprüngliche Akkumulation 'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'posted' => '2022-06-16 12:34:10', 'guid' => '735a2029-1062-ab23-42e4-f9c631220243', - 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => '', 'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.', ], 'text' => "[share - author='Hypolite Petovan' - profile='https://friendica.mrpetovan.com/profile/hypolite' - avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png' - link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' - posted='2022-06-16 12:34:10' - guid='735a2029-1062-ab23-42e4-f9c631220243' - message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' - ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. + author='Hypolite Petovan' + profile='https://friendica.mrpetovan.com/profile/hypolite' + avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png' + link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' + posted='2022-06-16 12:34:10' + guid='735a2029-1062-ab23-42e4-f9c631220243' + message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' + ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.[/share]", ], @@ -544,20 +544,20 @@ Lucas: For the right price, yes.[/share]", 'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'posted' => '2022-06-16 12:34:10', 'guid' => '', - 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => '', 'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.', ], 'text' => "[share - author='Hypolite Petovan' - profile='https://friendica.mrpetovan.com/profile/hypolite' - avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png' - link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' - posted='2022-06-16 12:34:10' - message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' - ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. + author='Hypolite Petovan' + profile='https://friendica.mrpetovan.com/profile/hypolite' + avatar='https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png' + link='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' + posted='2022-06-16 12:34:10' + message_id='https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243' + ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.[/share]", ], @@ -569,20 +569,20 @@ Lucas: For the right price, yes.[/share]", 'link' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'posted' => '2022-06-16 12:34:10', 'guid' => '', - 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => '', 'shared' => 'George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.', ], 'text' => '[share - author="Hypolite Petovan" - profile="https://friendica.mrpetovan.com/profile/hypolite" - avatar="https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png" - link="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243" - message_id="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243" - posted="2022-06-16 12:34:10" - ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. + author="Hypolite Petovan" + profile="https://friendica.mrpetovan.com/profile/hypolite" + avatar="https://friendica.mrpetovan.com/photo/20682437145daa4e85f019a278584494-5.png" + link="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243" + message_id="https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243" + posted="2022-06-16 12:34:10" + ]George Lucas: I made a science-fiction universe with a straightforward anti-authoritarianism plot where even the libertarian joins the rebellion. Disney: So a morally grey “choose your side” story, right? Lucas: For the right price, yes.[/share]', ], From ee03e4de08c25258590aa55f1deba705788cbab3 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 08:13:26 +0000 Subject: [PATCH 10/11] Fix test --- tests/src/Content/Text/BBCodeTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 0d9be478b9..ee3d96b1f1 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -501,14 +501,12 @@ Karl Marx - Die ursprüngliche Akkumulation 'link' => '', 'posted' => '', 'guid' => '', - 'message_id' => '', + 'message_id' => 'https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243', 'comment' => 'comment', - 'shared' => 'shared', + 'shared' => '', ], 'text' => ' comment - [share] - shared - [/share]', + [share]https://friendica.mrpetovan.com/display/735a2029-1062-ab23-42e4-f9c631220243[/share]', ], 'all-attributes' => [ 'expected' => [ From 33d48f7d553088c338599cef15ac9006e234bbcc Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Oct 2022 08:14:04 +0000 Subject: [PATCH 11/11] Use trim --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 93d1be2c44..2a3bced6af 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1029,7 +1029,7 @@ class BBCode 'link' => '', 'posted' => '', 'guid' => '', - 'message_id' => $matches[2], + 'message_id' => trim($matches[2]), 'comment' => trim($matches[1]), 'shared' => '', ];