From 9545ff614b28d9d8fc22b0647b3870fca7b34b77 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Jun 2019 15:00:33 -0400 Subject: [PATCH 1/4] Limit smilies replacement to BBCode::convert --- include/text.php | 10 +++------- mod/message.php | 2 +- src/Content/Text/BBCode.php | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/text.php b/include/text.php index e4227cd7d..052bdc4c3 100644 --- a/include/text.php +++ b/include/text.php @@ -143,13 +143,9 @@ function redir_private_images($a, &$item) * @return string Formattet HTML. * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ -function prepare_text($text) { - if (stristr($text, '[nosmile]')) { - $s = BBCode::convert($text); - } else { - $s = Smilies::replace(BBCode::convert($text)); - } - +function prepare_text($text) +{ + $s = BBCode::convert($text); return trim($s); } diff --git a/mod/message.php b/mod/message.php index 3ff84a1e6..fe4429e00 100644 --- a/mod/message.php +++ b/mod/message.php @@ -384,7 +384,7 @@ function message_content(App $a) $from_name_e = $message['from-name']; $subject_e = $message['title']; - $body_e = Smilies::replace(BBCode::convert($message['body'])); + $body_e = BBCode::convert($message['body']); $to_name_e = $message['name']; $contact = Contact::getDetailsByURL($message['from-url']); diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index e08d60579..da09e13dd 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1395,6 +1395,7 @@ class BBCode extends BaseObject // This is actually executed in Item::prepareBody() + $nosmile = strpos($text, '[nosmile]') !== false; $text = str_replace('[nosmile]', '', $text); // Check for font change text @@ -1572,7 +1573,7 @@ class BBCode extends BaseObject } // Replace non graphical smilies for external posts - if ($simple_html) { + if (!$nosmile && !$for_plaintext) { $text = Smilies::replace($text); } From 19b7398c6a877f328f6f05e3b895336e20948ab9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Jun 2019 16:14:05 -0400 Subject: [PATCH 2/4] Update BBCode::convert test mock-ups --- tests/src/Content/Text/BBCodeTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 3efb40893..6ae28e8c2 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -40,6 +40,9 @@ class BBCodeTest extends MockedTest $this->configMock->shouldReceive('get') ->with('system', 'url') ->andReturn('friendica.local'); + $this->configMock->shouldReceive('get') + ->with('system', 'no_smilies') + ->andReturn(false); $this->mockL10nT(); } From b51fb8c9941006d3c5b54a9e7f9504b22e692364 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Jun 2019 19:31:47 -0400 Subject: [PATCH 3/4] Fix typo in docblock in include/text --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index 052bdc4c3..7bed8b499 100644 --- a/include/text.php +++ b/include/text.php @@ -140,7 +140,7 @@ function redir_private_images($a, &$item) * @brief Given a text string, convert from bbcode to html and add smilie icons. * * @param string $text String with bbcode. - * @return string Formattet HTML. + * @return string Formatted HTML * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ function prepare_text($text) From 2fb70bd5f2884b95398620d046174b24ce1c5316 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Jun 2019 20:25:14 -0400 Subject: [PATCH 4/4] Use Unicode to convert multiple hearts in Content\Smilies --- src/Content/Smilies.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 57d14633a..2bf232d09 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -267,17 +267,18 @@ class Smilies * @return string HTML Output * * @throws \Friendica\Network\HTTPException\InternalServerErrorException - * @todo : Rework because it doesn't work correctly */ private static function pregHeart($x) { if (strlen($x[1]) == 1) { return $x[0]; } + $t = ''; for ($cnt = 0; $cnt < strlen($x[1]); $cnt ++) { - $t .= '<3'; + $t .= '❤'; } + $r = str_replace($x[0], $t, $x[0]); return $r; }