diff options
author | Mario <mario@mariovavti.com> | 2024-03-09 20:53:18 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-03-09 20:53:18 +0000 |
commit | 46fa26502b285213f3438abb1e3bd1482eb55bf5 (patch) | |
tree | c40ee65fc9da26319e26758c80339124f5247bea /include | |
parent | ba1e705c6154d347000ab6c92ef59f7f6f60e886 (diff) | |
download | volse-hubzilla-46fa26502b285213f3438abb1e3bd1482eb55bf5.tar.gz volse-hubzilla-46fa26502b285213f3438abb1e3bd1482eb55bf5.tar.bz2 volse-hubzilla-46fa26502b285213f3438abb1e3bd1482eb55bf5.zip |
more work on emojis
Diffstat (limited to 'include')
-rw-r--r-- | include/items.php | 7 | ||||
-rw-r--r-- | include/network.php | 8 | ||||
-rw-r--r-- | include/text.php | 55 |
3 files changed, 62 insertions, 8 deletions
diff --git a/include/items.php b/include/items.php index e26366af5..a5a23650e 100644 --- a/include/items.php +++ b/include/items.php @@ -1999,14 +1999,15 @@ function item_store($arr, $allow_exec = false, $deliver = true) { if(($terms) && (is_array($terms))) { foreach($terms as $t) { - q("insert into term (uid,oid,otype,ttype,term,url) - values(%d,%d,%d,%d,'%s','%s') ", + q("insert into term (uid,oid,otype,ttype,term,url,imgurl) + values(%d,%d,%d,%d,'%s','%s','%s') ", intval($arr['uid']), intval($current_post), intval(TERM_OBJ_POST), intval($t['ttype']), dbesc($t['term']), - dbesc($t['url']) + dbesc($t['url']), + dbesc($t['imgurl'] ?? ''), ); } diff --git a/include/network.php b/include/network.php index d41ba198d..a5c14f9d1 100644 --- a/include/network.php +++ b/include/network.php @@ -423,7 +423,7 @@ function json_return_and_die($x, $content_type = 'application/json') { killme(); } -function as_return_and_die($obj, $channel) { +function as_return_and_die($obj, $channel = []) { $ret = Activity::build_packet($obj, $channel); logger('data: ' . jindent($ret), LOGGER_DATA); @@ -433,8 +433,10 @@ function as_return_and_die($obj, $channel) { $headers['Digest'] = HTTPSig::generate_digest_header($ret); $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; - $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel)); - HTTPSig::set_headers($h); + if ($channel) { + $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel)); + HTTPSig::set_headers($h); + } echo $ret; killme(); diff --git a/include/text.php b/include/text.php index 26bf94828..baf1f770b 100644 --- a/include/text.php +++ b/include/text.php @@ -1270,6 +1270,33 @@ function sslify($s) { return $s; } +function get_emojis() { + $emojis = [ + // Reactions (emojitwo emojis) + 'astonished_face' => ['shortname' => ':astonished_face:', 'filepath' => 'images/emoji/astonished_face.png'], + 'bottle_with_popping_cork' => ['shortname' => ':bottle_with_popping_cork:', 'filepath' => 'images/emoji/bottle_with_popping_cork.png'], + 'clapping_hands' => ['shortname' => ':clapping_hands:', 'filepath' => 'images/emoji/clapping_hands.png'], + 'disappointed_face' => ['shortname' => ':disappointed_face:', 'filepath' => 'images/emoji/disappointed_face.png'], + 'grinning_face' => ['shortname' => ':grinning_face:', 'filepath' => 'images/emoji/grinning_face.png'], + 'kiss_mark' => ['shortname' => ':kiss_mark:', 'filepath' => 'images/emoji/kiss_mark.png'], + 'red_heart' => ['shortname' => ':red_heart:', 'filepath' => 'images/emoji/red_heart.png'], + 'sleeping_face' => ['shortname' => ':sleeping_face:', 'filepath' => 'images/emoji/sleeping_face.png'], + 'slightly_smiling_face' => ['shortname' => ':slightly_smiling_face:', 'filepath' => 'images/emoji/slightly_smiling_face.png'], + 'smiling_face_with_halo' => ['shortname' => ':smiling_face_with_halo:', 'filepath' => 'images/emoji/smiling_face_with_halo.png'], + 'smiling_face_with_horns' => ['shortname' => ':smiling_face_with_horns:', 'filepath' => 'images/emoji/smiling_face_with_horns.png'], + 'winking_face_with_tongue' => ['shortname' => ':winking_face_with_tongue:', 'filepath' => 'images/emoji/winking_face_with_tongue.png'], + + 'facepalm' => ['shortname' => ':facepalm:', 'filepath' => 'images/emoticons/smiley-facepalm.gif'] + ]; + + call_hooks('get_emojis', $emojis); + + return $emojis; +} + +function is_solo_string(string $emoji, string $body) : bool { + return empty(trim(str_replace($emoji, '', $body, $count))) && $count === 1; +} /** * @brief Function to list all smilies, both internal and from addons. @@ -1386,10 +1413,34 @@ function smilies($s, $sample = false) { || (local_channel() && intval(get_pconfig(local_channel(), 'system', 'no_smilies')))) return $s; + $s = preg_replace_callback('{<(pre|code)>.*?</\1>}ism', 'smile_shield', $s); $s = preg_replace_callback('/<[a-z]+ .*?>/ism', 'smile_shield', $s); + if (preg_match_all('/(\:(\w|\+|\-)+\:)(?=|[\!\.\?]|$)/', $s, $match)) { + // emoji shortcodes + $emojis = get_emojis(); + foreach ($match[0] as $mtch) { + $name = trim($mtch, ':'); + + if (!isset($emojis[$name])) { + continue; + } + + $emoji = $emojis[$name]; + + $class = 'emoji'; + if (is_solo_string($mtch, $s)) { + $class .= ' single-emoji'; + } + + $img = '<img class="' . $class . '" src="' . $emoji['filepath'] . '" alt="' . $emoji['shortname'] . '" title="' . $emoji['shortname'] . '" />'; + + string_replace($emoji['shortname'], $img, $s); + } + } +/* $params = list_smilies(); $params['string'] = $s; @@ -1400,9 +1451,9 @@ function smilies($s, $sample = false) { } } else { $params['string'] = preg_replace_callback('/<(3+)/','preg_heart',$params['string']); - $s = str_replace($params['texts'],$params['icons'],$params['string']); + $s = str_replace($params['texts'], $params['icons'], $params['string']); } - +*/ $s = preg_replace_callback('/<!--base64:(.*?)-->/ism', 'smile_unshield', $s); |