*/
public static function toPlaintext($text, $keep_urls = true)
{
- $naked_text = HTML::toPlaintext(BBCode::convert($text, false, 0, true), 0, !$keep_urls);
+ $naked_text = HTML::toPlaintext(self::convert($text, false, 0, true), 0, !$keep_urls);
return $naked_text;
}
- private static function proxyUrl($image, $simplehtml = BBCode::INTERNAL)
+ private static function proxyUrl($image, $simplehtml = self::INTERNAL)
{
// Only send proxied pictures to API and for internal display
- if (in_array($simplehtml, [BBCode::INTERNAL, BBCode::API])) {
+ if (in_array($simplehtml, [self::INTERNAL, self::API])) {
return ProxyUtils::proxifyUrl($image);
} else {
return $image;
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function convertAttachment($text, $simplehtml = BBCode::INTERNAL, $tryoembed = true)
+ private static function convertAttachment($text, $simplehtml = self::INTERNAL, $tryoembed = true)
{
$data = self::getAttachmentData($text);
if (empty($data) || empty($data['url'])) {
} catch (Exception $e) {
$data['title'] = ($data['title'] ?? '') ?: $data['url'];
- if ($simplehtml != BBCode::CONNECTORS) {
+ if ($simplehtml != self::CONNECTORS) {
$return = sprintf('<div class="type-%s">', $data['type']);
}
$return .= sprintf('<sup><a href="%s">%s</a></sup>', $data['url'], parse_url($data['url'], PHP_URL_HOST));
}
- if ($simplehtml != BBCode::CONNECTORS) {
+ if ($simplehtml != self::CONNECTORS) {
$return .= '</div>';
}
}
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function convert($text, $try_oembed = true, $simple_html = BBCode::INTERNAL, $for_plaintext = false)
+ public static function convert($text, $try_oembed = true, $simple_html = self::INTERNAL, $for_plaintext = false)
{
$a = DI::app();
/// @todo Have a closer look at the different html modes
// Handle attached links or videos
- if ($simple_html == BBCode::ACTIVITYPUB) {
+ if ($simple_html == self::ACTIVITYPUB) {
$text = self::removeAttachment($text);
- } elseif (!in_array($simple_html, [BBCode::INTERNAL, BBCode::CONNECTORS])) {
+ } elseif (!in_array($simple_html, [self::INTERNAL, self::CONNECTORS])) {
$text = self::removeAttachment($text, true);
} else {
$text = self::convertAttachment($text, $simple_html, $try_oembed);
// Check for sized text
// [size=50] --> font-size: 50px (with the unit).
- if ($simple_html != BBCode::DIASPORA) {
+ if ($simple_html != self::DIASPORA) {
$text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism", "<span style=\"font-size: $1px; line-height: initial;\">$2</span>", $text);
$text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism", "<span style=\"font-size: $1; line-height: initial;\">$2</span>", $text);
} else {
// Replace non graphical smilies for external posts
if (!$nosmile && !$for_plaintext) {
- $text = Smilies::replace($text);
+ $text = Smilies::replace($text);
+ }
+
+ if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA)) {
+ $conv = html_entity_decode(str_replace([' ', "\n", "\r"], '', $text));
+ // Emojis are always 4 byte Unicode characters
+ if (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4)) {
+ $text = '<span style="font-size: xx-large; line-height: initial;">' . $text . '</span>';
+ }
}
if (!$for_plaintext) {
- if (in_array($simple_html, [BBCode::OSTATUS, BBCode::ACTIVITYPUB])) {
+ if (in_array($simple_html, [self::OSTATUS, self::ACTIVITYPUB])) {
$text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
$text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
}
$text = str_replace(["\r","\n"], ['<br />', '<br />'], $text);
// Remove all hashtag addresses
- if ($simple_html && !in_array($simple_html, [BBCode::DIASPORA, BBCode::OSTATUS, BBCode::ACTIVITYPUB])) {
+ if ($simple_html && !in_array($simple_html, [self::DIASPORA, self::OSTATUS, self::ACTIVITYPUB])) {
$text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
- } elseif ($simple_html == BBCode::DIASPORA) {
+ } elseif ($simple_html == self::DIASPORA) {
// The ! is converted to @ since Diaspora only understands the @
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
'@<a href="$2">$3</a>',
$text);
- } elseif (in_array($simple_html, [BBCode::OSTATUS, BBCode::ACTIVITYPUB])) {
+ } elseif (in_array($simple_html, [self::OSTATUS, self::ACTIVITYPUB])) {
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
'$1<span class="vcard"><a href="$2" class="url u-url mention" title="$3"><span class="fn nickname mention">$3</span></a></span>',
$text);
$text = preg_replace("/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i",
"[bookmark=$1]$2[/bookmark]", $text);
- if (in_array($simple_html, [BBCode::API, BBCode::OSTATUS, BBCode::TWITTER])) {
+ if (in_array($simple_html, [self::API, self::OSTATUS, self::TWITTER])) {
$text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
//$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text);
$text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]',$text);
* - #[url=<anything>]<term>[/url]
* - [url=<anything>]#<term>[/url]
*/
- $text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function($matches) {
- return '#<a href="'
- . DI::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
- . '" class="tag" rel="tag" title="' . XML::escape($matches[1]) . '">'
- . XML::escape($matches[1])
- . '</a>';
+ $text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function($matches) use ($simple_html) {
+ if ($simple_html == BBCode::ACTIVITYPUB) {
+ return '<a href="' . DI::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
+ . '" data-tag="' . XML::escape($matches[1]) . '" rel="tag ugc">#'
+ . XML::escape($matches[1]) . '</a>';
+ } else {
+ return '#<a href="' . DI::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
+ . '" class="tag" rel="tag" title="' . XML::escape($matches[1]) . '">'
+ . XML::escape($matches[1]) . '</a>';
+ }
}, $text);
// We need no target="_blank" rel="noopener noreferrer" for local links
// Convert it to HTML - don't try oembed
if ($for_diaspora) {
- $text = self::convert($text, false, 3);
+ $text = self::convert($text, false, self::DIASPORA);
// Add all tags that maybe were removed
if (preg_match_all("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/ism", $original_text, $tags)) {
$text = $text . " " . $tagline;
}
} else {
- $text = self::convert($text, false, 4);
+ $text = self::convert($text, false, self::CONNECTORS);
}
// If a link is followed by a quote then there should be a newline before it