From b5666bd27ffcc9b270ea7f1fffe1001a96d8d72b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 7 Mar 2018 16:24:13 -0500 Subject: [PATCH] Replace html2bbcode calls by HTML::toBBCode --- include/api.php | 5 +++-- mod/babel.php | 29 +++++++++++++---------------- mod/oexchange.php | 2 +- src/Content/Text/Markdown.php | 2 +- src/Protocol/DFRN.php | 2 +- src/Protocol/Email.php | 6 ++++-- src/Protocol/Feed.php | 2 +- src/Protocol/OStatus.php | 9 +++++---- src/Protocol/PortableContact.php | 5 +++-- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/api.php b/include/api.php index 60a9acce0d..2f0566b6e0 100644 --- a/include/api.php +++ b/include/api.php @@ -10,6 +10,7 @@ use Friendica\App; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; +use Friendica\Content\Text\HTML; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -1096,7 +1097,7 @@ function api_statuses_mediap($type) $purifier = new HTMLPurifier($config); $txt = $purifier->purify($txt); } - $txt = html2bbcode($txt); + $txt = HTML::toBBCode($txt); $a->argv[1]=$user_info['screen_name']; //should be set to username? @@ -1147,7 +1148,7 @@ function api_statuses_update($type) $purifier = new HTMLPurifier($config); $txt = $purifier->purify($txt); - $_REQUEST['body'] = html2bbcode($txt); + $_REQUEST['body'] = HTML::toBBCode($txt); } } else { $_REQUEST['body'] = requestdata('status'); diff --git a/mod/babel.php b/mod/babel.php index 99e6f4078d..a2d197599c 100644 --- a/mod/babel.php +++ b/mod/babel.php @@ -3,12 +3,9 @@ * @file mod/babel.php */ -use Friendica\Content\Text\BBCode; -use Friendica\Content\Text\Markdown; +use Friendica\Content\Text; use Friendica\Core\L10n; -require_once 'include/html2bbcode.php'; - function visible_lf($s) { return str_replace("\n", '
', $s); @@ -37,31 +34,31 @@ function babel_content() $o .= '

' . L10n::t('Source input: ') . '

' . EOL . EOL; $o .= visible_lf($text) . EOL . EOL; - $html = BBCode::convert($text); - $o .= '

' . L10n::t("bbcode \x28raw HTML\x28: ") . '

' . EOL . EOL; + $html = Text\BBCode::convert($text); + $o .= '

' . L10n::t("BBCode::convert \x28raw HTML\x28: ") . '

' . EOL . EOL; $o .= htmlspecialchars($html) . EOL . EOL; - $o .= '

' . L10n::t('bbcode: ') . '

' . EOL . EOL; + $o .= '

' . L10n::t('BBCode::convert: ') . '

' . EOL . EOL; $o .= $html . EOL . EOL; - $bbcode = html2bbcode($html); - $o .= '

' . L10n::t('bbcode => html2bbcode: ') . '

' . EOL . EOL; + $bbcode = Text\HTML::toBBCode($html); + $o .= '

' . L10n::t('BBCode::convert => HTML::toBBCode: ') . '

' . EOL . EOL; $o .= visible_lf($bbcode) . EOL . EOL; - $diaspora = BBCode::toMarkdown($text); + $diaspora = Text\BBCode::toMarkdown($text); $o .= '

' . L10n::t('BBCode::toMarkdown: ') . '

' . EOL . EOL; $o .= visible_lf($diaspora) . EOL . EOL; - $html = Markdown::convert($diaspora); + $html = Text\Markdown::convert($diaspora); $o .= '

' . L10n::t('BBCode::toMarkdown => Markdown::convert: ') . '

' . EOL . EOL; $o .= $html . EOL . EOL; - $bbcode = Markdown::toBBCode($diaspora); + $bbcode = Text\Markdown::toBBCode($diaspora); $o .= '

' . L10n::t('BBCode::toMarkdown => Markdown::toBBCode: ') . '

' . EOL . EOL; $o .= visible_lf($bbcode) . EOL . EOL; - $bbcode = html2bbcode($html); - $o .= '

' . L10n::t('bbcode => html2bbcode: ') . '

' . EOL . EOL; + $bbcode = Text\HTML::toBBCode($html); + $o .= '

' . L10n::t('BBCode::toMarkdown => Markdown::convert => HTML::toBBCode: ') . '

' . EOL . EOL; $o .= visible_lf($bbcode) . EOL . EOL; } @@ -70,8 +67,8 @@ function babel_content() $o .= '

' . L10n::t("Source input \x28Diaspora format\x29: ") . '

' . EOL . EOL; $o .= '
' . $d2bbtext . '
' . EOL . EOL; - $bb = Markdown::toBBCode($d2bbtext); - $o .= '

' . L10n::t('diaspora2bb: ') . '

' . EOL . EOL; + $bb = Text\Markdown::toBBCode($d2bbtext); + $o .= '

' . L10n::t('Markdown::toBBCode: ') . '

' . EOL . EOL; $o .= '
' . $bb . '
' . EOL . EOL; } diff --git a/mod/oexchange.php b/mod/oexchange.php index feca39d353..2e1d7a2dbc 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -52,7 +52,7 @@ function oexchange_content(App $a) { $post['profile_uid'] = local_user(); $post['return'] = '/oexchange/done' ; - $post['body'] = html2bbcode($s); + $post['body'] = Friendica\Content\Text\HTML::toBBCode($s); $post['type'] = 'wall'; $_REQUEST = $post; diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php index e7383a3fd7..6e982c7f04 100644 --- a/src/Content/Text/Markdown.php +++ b/src/Content/Text/Markdown.php @@ -94,7 +94,7 @@ class Markdown extends BaseObject $s = str_replace('#', '#', $s); - $s = html2bbcode($s); + $s = Friendica\Content\Text\HTML::toBBCode($s); // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands $s = str_replace('♲', html_entity_decode('♲', ENT_QUOTES, 'UTF-8'), $s); diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 5e7cc02a36..a82ae3d255 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2454,7 +2454,7 @@ class DFRN $purifier = new HTMLPurifier($config); $item['body'] = $purifier->purify($item['body']); - $item['body'] = @html2bbcode($item['body']); + $item['body'] = @Friendica\Content\Text\HTML::toBBCode($item['body']); } /// @todo We should check for a repeated post and if we know the repeated author. diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index b1eeb94d62..fadd124c96 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -4,6 +4,8 @@ */ namespace Friendica\Protocol; +use Friendica\Content\Text\HTML; + require_once 'include/html2plain.php'; /** @@ -111,7 +113,7 @@ class Email if (trim($ret['body']) == '') { $ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'plain'); } else { - $ret['body'] = html2bbcode($ret['body']); + $ret['body'] = HTML::toBBCode($ret['body']); } } else { $text = ''; @@ -128,7 +130,7 @@ class Email } } if (trim($html) != '') { - $ret['body'] = html2bbcode($html); + $ret['body'] = HTML::toBBCode($html); } else { $ret['body'] = $text; } diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 17234ce45a..d54846fc34 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -363,7 +363,7 @@ class Feed { if (self::titleIsBody($item["title"], $body)) { $item["title"] = ""; } - $item["body"] = html2bbcode($body, $basepath); + $item["body"] = Friendica\Content\Text\HTML::toBBCode($body, $basepath); if (($item["body"] == '') && ($item["title"] != '')) { $item["body"] = $item["title"]; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index c6f840a66e..9eebc7f2e4 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -5,6 +5,7 @@ namespace Friendica\Protocol; use Friendica\Content\Text\BBCode; +use Friendica\Content\Text\HTML; use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -168,7 +169,7 @@ class OStatus $value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue; if ($value != "") { - $contact["about"] = html2bbcode($value); + $contact["about"] = HTML::toBBCode($value); } $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; @@ -557,7 +558,7 @@ class OStatus */ private static function processPost($xpath, $entry, &$item, $importer) { - $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); + $item["body"] = HTML::toBBCode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; @@ -659,7 +660,7 @@ class OStatus if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) { $clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue; - $item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]'; + $item["body"] = HTML::toBBCode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]'; } if (($self != '') && empty($item['protocol'])) { @@ -1014,7 +1015,7 @@ class OStatus $item["author-link"] = $orig_author["author-link"]; $item["author-avatar"] = $orig_author["author-avatar"]; - $item["body"] = html2bbcode($orig_body); + $item["body"] = HTML::toBBCode($orig_body); $item["created"] = $orig_created; $item["edited"] = $orig_edited; diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 5b419e42ef..f5513bddd6 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -9,6 +9,7 @@ namespace Friendica\Protocol; +use Friendica\Content\Text\HTML; use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; @@ -155,7 +156,7 @@ class PortableContact } if (isset($entry->aboutMe)) { - $about = html2bbcode($entry->aboutMe); + $about = HTML::toBBCode($entry->aboutMe); } if (isset($entry->gender)) { @@ -1669,7 +1670,7 @@ class PortableContact } if (isset($entry->aboutMe)) { - $about = html2bbcode($entry->aboutMe); + $about = HTML::toBBCode($entry->aboutMe); } if (isset($entry->gender)) { -- 2.39.5