Refactor bbcode() into BBCode::convert()
This commit is contained in:
parent
29f5270313
commit
0c52866693
21 changed files with 89 additions and 73 deletions
|
@ -2604,13 +2604,12 @@ function api_format_messages($item, $recipient, $sender)
|
|||
if (x($_GET, 'getText')) {
|
||||
$ret['title'] = $item['title'];
|
||||
if ($_GET['getText'] == 'html') {
|
||||
$ret['text'] = bbcode($item['body'], false, false);
|
||||
$ret['text'] = BBCode::convert($item['body'], false);
|
||||
} elseif ($_GET['getText'] == 'plain') {
|
||||
//$ret['text'] = html2plain(bbcode($item['body'], false, false, true), 0);
|
||||
$ret['text'] = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0));
|
||||
$ret['text'] = trim(html2plain(BBCode::convert(api_clean_plain_items($item['body']), false, 2, true), 0));
|
||||
}
|
||||
} else {
|
||||
$ret['text'] = $item['title'] . "\n" . html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0);
|
||||
$ret['text'] = $item['title'] . "\n" . html2plain(BBCode::convert(api_clean_plain_items($item['body']), false, 2, true), 0);
|
||||
}
|
||||
if (x($_GET, 'getUserObjects') && $_GET['getUserObjects'] == 'false') {
|
||||
unset($ret['sender']);
|
||||
|
@ -2632,7 +2631,7 @@ function api_convert_item($item)
|
|||
$attachments = api_get_attachments($body);
|
||||
|
||||
// Workaround for ostatus messages where the title is identically to the body
|
||||
$html = bbcode(api_clean_plain_items($body), false, false, 2, true);
|
||||
$html = BBCode::convert(api_clean_plain_items($body), false, 2, true);
|
||||
$statusbody = trim(html2plain($html, 0));
|
||||
|
||||
// handle data: images
|
||||
|
@ -2650,7 +2649,7 @@ function api_convert_item($item)
|
|||
$statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
|
||||
}
|
||||
|
||||
$statushtml = bbcode(api_clean_attachments($body), false, false);
|
||||
$statushtml = BBCode::convert(api_clean_attachments($body), false);
|
||||
|
||||
// Workaround for clients with limited HTML parser functionality
|
||||
$search = ["<br>", "<blockquote>", "</blockquote>",
|
||||
|
@ -2664,7 +2663,7 @@ function api_convert_item($item)
|
|||
$statushtml = str_replace($search, $replace, $statushtml);
|
||||
|
||||
if ($item['title'] != "") {
|
||||
$statushtml = "<br><h4>" . bbcode($item['title']) . "</h4><br>" . $statushtml;
|
||||
$statushtml = "<br><h4>" . BBCode::convert($item['title']) . "</h4><br>" . $statushtml;
|
||||
}
|
||||
|
||||
do {
|
||||
|
@ -2682,7 +2681,7 @@ function api_convert_item($item)
|
|||
|
||||
// feeds without body should contain the link
|
||||
if (($item['network'] == NETWORK_FEED) && (strlen($item['body']) == 0)) {
|
||||
$statushtml .= bbcode($item['plink']);
|
||||
$statushtml .= BBCode::convert($item['plink']);
|
||||
}
|
||||
|
||||
$entities = api_get_entitities($statustext, $body);
|
||||
|
@ -3053,18 +3052,18 @@ function api_format_items_profiles($profile_row)
|
|||
'religion' => $profile_row['religion'],
|
||||
'public_keywords' => $profile_row['pub_keywords'],
|
||||
'private_keywords' => $profile_row['prv_keywords'],
|
||||
'likes' => bbcode(api_clean_plain_items($profile_row['likes']) , false, false, 2, false),
|
||||
'dislikes' => bbcode(api_clean_plain_items($profile_row['dislikes']) , false, false, 2, false),
|
||||
'about' => bbcode(api_clean_plain_items($profile_row['about']) , false, false, 2, false),
|
||||
'music' => bbcode(api_clean_plain_items($profile_row['music']) , false, false, 2, false),
|
||||
'book' => bbcode(api_clean_plain_items($profile_row['book']) , false, false, 2, false),
|
||||
'tv' => bbcode(api_clean_plain_items($profile_row['tv']) , false, false, 2, false),
|
||||
'film' => bbcode(api_clean_plain_items($profile_row['film']) , false, false, 2, false),
|
||||
'interest' => bbcode(api_clean_plain_items($profile_row['interest']) , false, false, 2, false),
|
||||
'romance' => bbcode(api_clean_plain_items($profile_row['romance']) , false, false, 2, false),
|
||||
'work' => bbcode(api_clean_plain_items($profile_row['work']) , false, false, 2, false),
|
||||
'education' => bbcode(api_clean_plain_items($profile_row['education']), false, false, 2, false),
|
||||
'social_networks' => bbcode(api_clean_plain_items($profile_row['contact']) , false, false, 2, false),
|
||||
'likes' => BBCode::convert(api_clean_plain_items($profile_row['likes']) , false, 2),
|
||||
'dislikes' => BBCode::convert(api_clean_plain_items($profile_row['dislikes']) , false, 2),
|
||||
'about' => BBCode::convert(api_clean_plain_items($profile_row['about']) , false, 2),
|
||||
'music' => BBCode::convert(api_clean_plain_items($profile_row['music']) , false, 2),
|
||||
'book' => BBCode::convert(api_clean_plain_items($profile_row['book']) , false, 2),
|
||||
'tv' => BBCode::convert(api_clean_plain_items($profile_row['tv']) , false, 2),
|
||||
'film' => BBCode::convert(api_clean_plain_items($profile_row['film']) , false, 2),
|
||||
'interest' => BBCode::convert(api_clean_plain_items($profile_row['interest']) , false, 2),
|
||||
'romance' => BBCode::convert(api_clean_plain_items($profile_row['romance']) , false, 2),
|
||||
'work' => BBCode::convert(api_clean_plain_items($profile_row['work']) , false, 2),
|
||||
'education' => BBCode::convert(api_clean_plain_items($profile_row['education']), false, 2),
|
||||
'social_networks' => BBCode::convert(api_clean_plain_items($profile_row['contact']) , false, 2),
|
||||
'homepage' => $profile_row['homepage'],
|
||||
'users' => null
|
||||
];
|
||||
|
|
|
@ -164,7 +164,7 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) {
|
|||
|
||||
// Convert it to HTML - don't try oembed
|
||||
if ($fordiaspora) {
|
||||
$Text = bbcode($Text, $preserve_nl, false, 3);
|
||||
$Text = BBCode::convert($Text, false, 3);
|
||||
|
||||
// Add all tags that maybe were removed
|
||||
if (preg_match_all("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $OriginalText, $tags)) {
|
||||
|
@ -178,7 +178,7 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) {
|
|||
$Text = $Text." ".$tagline;
|
||||
}
|
||||
} else {
|
||||
$Text = bbcode($Text, $preserve_nl, false, 4);
|
||||
$Text = BBCode::convert($Text, false, 4);
|
||||
}
|
||||
|
||||
// mask some special HTML chars from conversation to markdown
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* @file include/enotify.php
|
||||
*/
|
||||
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
|
@ -448,7 +449,7 @@ function notification($params)
|
|||
$datarray = [];
|
||||
$datarray['hash'] = $hash;
|
||||
$datarray['name'] = $params['source_name'];
|
||||
$datarray['name_cache'] = strip_tags(bbcode($params['source_name']));
|
||||
$datarray['name_cache'] = strip_tags(BBCode::convert($params['source_name']));
|
||||
$datarray['url'] = $params['source_link'];
|
||||
$datarray['photo'] = $params['source_photo'];
|
||||
$datarray['date'] = DateTimeFormat::utcNow();
|
||||
|
@ -519,7 +520,7 @@ function notification($params)
|
|||
|
||||
$itemlink = System::baseUrl().'/notify/view/'.$notify_id;
|
||||
$msg = replace_macros($epreamble, ['$itemlink' => $itemlink]);
|
||||
$msg_cache = format_notification_message($datarray['name_cache'], strip_tags(bbcode($msg)));
|
||||
$msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg)));
|
||||
q("UPDATE `notify` SET `msg` = '%s', `msg_cache` = '%s' WHERE `id` = %d AND `uid` = %d",
|
||||
dbesc($msg),
|
||||
dbesc($msg_cache),
|
||||
|
@ -567,9 +568,9 @@ function notification($params)
|
|||
}
|
||||
|
||||
// textversion keeps linebreaks
|
||||
$textversion = strip_tags(str_replace("<br>", "\n", html_entity_decode(bbcode(stripslashes(str_replace(["\\r\\n", "\\r", "\\n"], "\n",
|
||||
$textversion = strip_tags(str_replace("<br>", "\n", html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r\\n", "\\r", "\\n"], "\n",
|
||||
$body))),ENT_QUOTES, 'UTF-8')));
|
||||
$htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(["\\r\\n", "\\r", "\\n\\n", "\\n"],
|
||||
$htmlversion = html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r\\n", "\\r", "\\n\\n", "\\n"],
|
||||
"<br />\n", $body))), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$datarray = [];
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
use Friendica\Content\Feature;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig;
|
||||
|
@ -38,9 +39,9 @@ function format_event_html($ev, $simple = false) {
|
|||
);
|
||||
|
||||
if ($simple) {
|
||||
$o = "<h3>" . bbcode($ev['summary']) . "</h3>";
|
||||
$o = "<h3>" . BBCode::convert($ev['summary']) . "</h3>";
|
||||
|
||||
$o .= "<div>" . bbcode($ev['desc']) . "</div>";
|
||||
$o .= "<div>" . BBCode::convert($ev['desc']) . "</div>";
|
||||
|
||||
$o .= "<h4>" . L10n::t('Starts:') . "</h4><p>" . $event_start . "</p>";
|
||||
|
||||
|
@ -57,7 +58,7 @@ function format_event_html($ev, $simple = false) {
|
|||
|
||||
$o = '<div class="vevent">' . "\r\n";
|
||||
|
||||
$o .= '<div class="summary event-summary">' . bbcode($ev['summary']) . '</div>' . "\r\n";
|
||||
$o .= '<div class="summary event-summary">' . BBCode::convert($ev['summary']) . '</div>' . "\r\n";
|
||||
|
||||
$o .= '<div class="event-start"><span class="event-label">' . L10n::t('Starts:') . '</span> <span class="dtstart" title="'
|
||||
. DateTimeFormat::utc($ev['start'], (($ev['adjust']) ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s' ))
|
||||
|
@ -71,11 +72,11 @@ function format_event_html($ev, $simple = false) {
|
|||
. '</span></div>' . "\r\n";
|
||||
}
|
||||
|
||||
$o .= '<div class="description event-description">' . bbcode($ev['desc']) . '</div>' . "\r\n";
|
||||
$o .= '<div class="description event-description">' . BBCode::convert($ev['desc']) . '</div>' . "\r\n";
|
||||
|
||||
if (strlen($ev['location'])) {
|
||||
$o .= '<div class="event-location"><span class="event-label">' . L10n::t('Location:') . '</span> <span class="location">'
|
||||
. bbcode($ev['location'])
|
||||
. BBCode::convert($ev['location'])
|
||||
. '</span></div>' . "\r\n";
|
||||
|
||||
// Include a map of the location if the [map] BBCode is used.
|
||||
|
@ -610,15 +611,15 @@ function process_events($arr) {
|
|||
$drop = [System::baseUrl() . '/events/drop/' . $rr['id'], L10n::t('Delete event'), '', ''];
|
||||
}
|
||||
|
||||
$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 (! $title) {
|
||||
list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
|
||||
list($title, $_trash) = explode("<br", BBCode::convert($rr['desc']), 2);
|
||||
$title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
$html = format_event_html($rr);
|
||||
$rr['desc'] = bbcode($rr['desc']);
|
||||
$rr['location'] = bbcode($rr['location']);
|
||||
$rr['desc'] = BBCode::convert($rr['desc']);
|
||||
$rr['location'] = BBCode::convert($rr['location']);
|
||||
$events[] = [
|
||||
'id' => $rr['id'],
|
||||
'start' => $start,
|
||||
|
|
|
@ -7,6 +7,7 @@ use Friendica\App;
|
|||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Feature;
|
||||
use Friendica\Content\Smilies;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
|
@ -15,7 +16,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Render\FriendicaSmarty;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Map;
|
||||
|
||||
|
@ -1427,9 +1428,9 @@ function prepare_text($text) {
|
|||
require_once 'include/bbcode.php';
|
||||
|
||||
if (stristr($text, '[nosmile]')) {
|
||||
$s = bbcode($text);
|
||||
$s = BBCode::convert($text);
|
||||
} else {
|
||||
$s = Smilies::replace(bbcode($text));
|
||||
$s = Smilies::replace(BBCode::convert($text));
|
||||
}
|
||||
|
||||
return trim($s);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue