Refactor bbcode() into BBCode::convert()

This commit is contained in:
Hypolite Petovan 2018-02-14 21:33:55 -05:00
parent 29f5270313
commit 0c52866693
21 changed files with 89 additions and 73 deletions

View file

@ -174,7 +174,7 @@ class BBCode
}
if ($title != "") {
$title = bbcode(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, false, true);
$title = BBCode::convert(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, true);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$title = str_replace(["[", "]"], ["[", "]"], $title);
$data["title"] = $title;
@ -409,7 +409,7 @@ class BBCode
}
}
$html = bbcode($post["text"].$post["after"], false, false, $htmlmode);
$html = BBCode::convert($post["text"].$post["after"], false, $htmlmode);
$msg = html2plain($html, 0, true);
$msg = trim(html_entity_decode($msg, ENT_QUOTES, 'UTF-8'));
@ -706,7 +706,7 @@ class BBCode
}
if ($data["description"] != "" && $data["description"] != $data["title"]) {
$return .= sprintf('<blockquote>%s</blockquote>', trim(bbcode($data["description"])));
$return .= sprintf('<blockquote>%s</blockquote>', trim(BBCode::convert($data["description"])));
}
if ($data["type"] == "link") {

View file

@ -7,6 +7,7 @@
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Content\Text\BBCode;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
@ -46,7 +47,7 @@ class NotificationsManager extends BaseObject
$local_time = DateTimeFormat::local($n['date']);
$n['timestamp'] = strtotime($local_time);
$n['date_rel'] = Temporal::getRelativeDate($n['date']);
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
$n['msg_html'] = BBCode::convert($n['msg'], false);
$n['msg_plain'] = explode("\n", trim(html2plain($n['msg_html'], 0)))[0];
$rets[] = $n;
@ -243,7 +244,7 @@ class NotificationsManager extends BaseObject
$default_item_link = System::baseUrl(true) . '/notify/view/' . $it['id'];
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
$default_item_url = $it['url'];
$default_item_text = strip_tags(bbcode($it['msg']));
$default_item_text = strip_tags(BBCode::convert($it['msg']));
$default_item_when = DateTimeFormat::local($it['date'], 'r');
$default_item_ago = Temporal::getRelativeDate($it['date']);
break;
@ -843,8 +844,8 @@ class NotificationsManager extends BaseObject
'contact_id' => $it['contact-id'],
'photo' => ((x($it, 'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
'name' => $it['name'],
'location' => bbcode($it['glocation'], false, false),
'about' => bbcode($it['gabout'], false, false),
'location' => BBCode::convert($it['glocation'], false),
'about' => BBCode::convert($it['gabout'], false),
'keywords' => $it['gkeywords'],
'gender' => $it['ggender'],
'hidden' => $it['hidden'] == 1,

View file

@ -7,6 +7,7 @@ namespace Friendica\Model;
use Friendica\App;
use Friendica\Content\Feature;
use Friendica\Content\ForumManager;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Addon;
use Friendica\Core\Cache;
use Friendica\Core\Config;
@ -487,13 +488,13 @@ class Profile
}
if (isset($p['about'])) {
$p['about'] = bbcode($p['about']);
$p['about'] = BBCode::convert($p['about']);
}
if (isset($p['address'])) {
$p['address'] = bbcode($p['address']);
$p['address'] = BBCode::convert($p['address']);
} else {
$p['address'] = bbcode($p['location']);
$p['address'] = BBCode::convert($p['location']);
}
if (isset($p['photo'])) {
@ -667,13 +668,13 @@ class Profile
$istoday = true;
}
$title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
$title = strip_tags(html_entity_decode(BBCode::convert($rr['summary']), ENT_QUOTES, 'UTF-8'));
if (strlen($title) > 35) {
$title = substr($title, 0, 32) . '... ';
}
$description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
$description = substr(strip_tags(BBCode::convert($rr['desc'])), 0, 32) . '... ';
if (!$description) {
$description = L10n::t('[No description]');
}

View file

@ -832,7 +832,7 @@ class DFRN
}
}
if ($r->content) {
XML::addElement($doc, $entry, "content", bbcode($r->content), ["type" => "html"]);
XML::addElement($doc, $entry, "content", BBCode::convert($r->content), ["type" => "html"]);
}
return $entry;
@ -938,7 +938,7 @@ class DFRN
$htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
}
$htmlbody = bbcode($htmlbody, false, false, 7);
$htmlbody = BBCode::convert($htmlbody, false, 7);
}
$author = self::addEntryAuthor($doc, "author", $item["author-link"], $item);

View file

@ -9,6 +9,7 @@
*/
namespace Friendica\Protocol;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\L10n;
@ -4197,7 +4198,7 @@ class Diaspora
}
$about = $profile['about'];
$about = strip_tags(bbcode($about));
$about = strip_tags(BBCode::convert($about));
$location = Profile::formatLocation($profile);
$tags = '';

View file

@ -1373,7 +1373,7 @@ class OStatus
XML::addElement($doc, $author, "uri", $owner["url"]);
XML::addElement($doc, $author, "name", $owner["nick"]);
XML::addElement($doc, $author, "email", $owner["addr"]);
XML::addElement($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
XML::addElement($doc, $author, "summary", BBCode::convert($owner["about"], false, 7));
$attributes = ["rel" => "alternate", "type" => "text/html", "href" => $owner["url"]];
XML::addElement($doc, $author, "link", "", $attributes);
@ -1398,7 +1398,7 @@ class OStatus
XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
XML::addElement($doc, $author, "poco:note", bbcode($owner["about"], false, false, 7));
XML::addElement($doc, $author, "poco:note", BBCode::convert($owner["about"], false, 7));
if (trim($owner["location"]) != "") {
$element = $doc->createElement("poco:address");
@ -1879,7 +1879,7 @@ class OStatus
$body = "[b]".$item['title']."[/b]\n\n".$body;
}
$body = bbcode($body, false, false, 7);
$body = BBCode::convert($body, false, 7);
XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);