From 45b1be8962903868c5d3a5e98ff09bd74bbecc85 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 8 Mar 2024 08:42:50 +0000 Subject: inbound support for custom emojis --- Zotlabs/Lib/Activity.php | 21 +++++++--------- include/bbcode.php | 57 ++++++++++++++++++++++++++++++++---------- include/text.php | 63 +++++++++++++++++++++++------------------------ view/css/conversation.css | 8 +++++- 4 files changed, 91 insertions(+), 58 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 45cb1d803..29b99fab5 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2183,18 +2183,6 @@ class Activity { if (grapheme_strlen($t) === 1) { $content['content'] = $t; } - - // Custom emojis - $e = self::decode_taxonomy($act->data); - - if ($e) { - $s['term'] = $e; - foreach ($e as $ee) { - if ($ee['ttype'] === TERM_EMOJI) { - $content['content'] = '[img=32x32]' . $ee['url'] . '[/img]'; - } - } - } } } @@ -2894,8 +2882,17 @@ class Activity { } } + if (!PConfig::Get($channel['channel_id'], 'system', 'no_smilies')) { + foreach ($item['term'] as $t) { + if ($t['ttype'] === TERM_EMOJI) { + $item['body'] = str_replace($t['term'], '[img class="smiley emoji custom-emoji" alt="' . $t['term'] . '" title="' . $t['term'] . '"]' . $t['url'] . '[/img]', $item['body']); + } + } + } + // TODO: not implemented // self::rewrite_mentions($item); + $r = q("select id, created, edited from item where mid = '%s' and uid = %d limit 1", dbesc($item['mid']), intval($item['uid']) diff --git a/include/bbcode.php b/include/bbcode.php index 6bb63bbaf..848d117fb 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -869,11 +869,13 @@ function bb_imgoptions($match) { // [img|zmg=wwwxhhh float=left|right alt=alt text]url[/img|zmg] $local_match = null; - $width = 0; - $float = false; - $alt = false; - - $style = EMPTY_STR; + $width = EMPTY_STR; + $height = EMPTY_STR; + $float = EMPTY_STR; + $alt = EMPTY_STR; + $title = EMPTY_STR; + $style = EMPTY_STR; + $class = EMPTY_STR; $attributes = $match[3]; @@ -882,6 +884,16 @@ function bb_imgoptions($match) { $alt = $matches[1]; } + $x = preg_match("/title=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($x) { + $title = $matches[1]; + } + + $x = preg_match("/title='(.*?)'/ism", $attributes, $matches); + if ($x) { + $title = $matches[1]; + } + $x = preg_match("/alt=\"\;(.*?)\"\;/ism", $attributes, $matches); if ($x) { $alt = $matches[1]; @@ -907,16 +919,27 @@ function bb_imgoptions($match) { $height = $matches[1]; } + $x = preg_match("/class='(.*?)'/ism", $attributes, $matches); + if ($x) { + $class = $matches[1]; + } + + $x = preg_match("/class=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($x) { + $class = $matches[1]; + } + +/* should probably sanitize css somehow $x = preg_match("/style='(.*?)'/ism", $attributes, $matches); if ($x) { - $style = $matches[1]; + $style = $matches[1] . ' '; } $x = preg_match("/style=\"\;(.*?)\"\;/ism", $attributes, $matches); if ($x) { - $style = $matches[1]; + $style = $matches[1] . ' '; } - +*/ // legacy img options if ($match[2] === '=') { @@ -932,6 +955,7 @@ function bb_imgoptions($match) { $float = 'left'; $match[3] = substr($match[3],$n + 10); } + if ($n = strpos($match[3],'float=right') !== false) { $float = 'right'; $match[3] = substr($match[3],$n + 11); @@ -947,18 +971,25 @@ function bb_imgoptions($match) { $output = ''; + $output .= 'src="' . $match[4] . '" />'; return $output; diff --git a/include/text.php b/include/text.php index 3582b430c..26bf94828 100644 --- a/include/text.php +++ b/include/text.php @@ -1317,38 +1317,37 @@ function list_smilies($default_only = false) { ); $icons = array( - '<3', - '</3', - ':-)', - ';-)', - ':-(', - ':-P', - ':-p', - ':-\', - ':-\', - ':-x', - ':-X', - ':-D', - '8-|', - '8-O', - ':-O', - '\\o/', - 'o.O', - 'O.o', - 'o_O', - 'O_o', - ':\'(', - ':-!', - ':-/', - ':-[', - '8-)', - ':beer', - ':homebrew', - ':coffee', - ':facepalm', - ':like', - ':dislike' - + '<3', + '</3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-p', + ':-\', + ':-\', + ':-x', + ':-X', + ':-D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + 'o_O', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':like', + ':dislike' ); $params = array('texts' => $texts, 'icons' => $icons); diff --git a/view/css/conversation.css b/view/css/conversation.css index dcd38839a..3af51d102 100644 --- a/view/css/conversation.css +++ b/view/css/conversation.css @@ -299,10 +299,16 @@ code.inline-code { text-decoration: overline; } +img.smiley.emoji { + height: .9em; + vertical-align: baseline; + margin-bottom: -.1em; +} + img.smiley.emoji:hover { transform: scale(2); transition: transform .1s ease-out; - filter: drop-shadow(0px 0px 1px rgba(0,0,0,.5)); + filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, .5)); } .checklist input { -- cgit v1.2.3