13 changed files with 2925 additions and 89 deletions
-
2app/Message.php
-
39app/helpers/StringHelper.php
-
2app/widgets/Chat/_chat.tpl
-
2app/widgets/Notifs/Notifs.php
-
2app/widgets/Post/Post.php
-
1composer.json
-
46composer.lock
-
2src/Movim/Daemon/Api.php
-
100src/Movim/Emoji.php
-
2663src/Movim/Emoji/CompiledEmoji.php
-
75src/Movim/Emoji/compile-file-list.sh
-
19src/Movim/Emoji/replace-test.php
-
61src/Movim/Emoji/test-all-images.sh
@ -0,0 +1,100 @@ |
|||
<?php |
|||
/*- |
|||
* Copyright © 2018 |
|||
* mirabilos <thorsten.glaser@teckids.org> |
|||
* |
|||
* Provided that these terms and disclaimer and all copyright notices |
|||
* are retained or reproduced in an accompanying document, permission |
|||
* is granted to deal in this work without restriction, including un‐ |
|||
* limited rights to use, publicly perform, distribute, sell, modify, |
|||
* merge, give away, or sublicence. |
|||
* |
|||
* This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to |
|||
* the utmost extent permitted by applicable law, neither express nor |
|||
* implied; without malicious intent or gross negligence. In no event |
|||
* may a licensor, author or contributor be held liable for indirect, |
|||
* direct, other damage, loss, or other issues arising in any way out |
|||
* of dealing in the work, even if advised of the possibility of such |
|||
* damage or existence of a defect, except proven that it results out |
|||
* of said person’s immediate fault when using the work as intended. |
|||
*/ |
|||
|
|||
namespace Movim; |
|||
|
|||
class Emoji |
|||
{ |
|||
protected static $instance = null; |
|||
private $_emoji; |
|||
private $_regex = [ |
|||
/* some easy cases first */ |
|||
'/[#*0-9]\x{20E3}
|
|||
|\x{1F3F3}(?:\x{FE0F}\x{200D}\x{1F308})? |
|||
|\x{1F3F4}(?:\x{200D}\x{2620}\x{FE0F}|\x{E0067}\x{E0062} |
|||
(?:\x{E0065}\x{E006E}\x{E0067}|\x{E0073}\x{E0063}\x{E0074}|\x{E0077}\x{E006C}\x{E0073})\x{E007F})? |
|||
|\x{1F441}(?:\x{200D}\x{1F5E8})? |
|||
/ux', |
|||
/* everything starting with 1F468 or 1F469 */ |
|||
'/[\x{1F468}\x{1F469}] |
|||
(?:\x{200D}\x{2764}\x{FE0F}\x{200D}(?:\x{1F48B}\x{200D})?[\x{1F468}\x{1F469}] |
|||
|(?:\x{200D}[\x{1F468}\x{1F469}])? |
|||
(?:\x{200D}[\x{1F466}\x{1F467}])? |
|||
\x{200D}[\x{1F466}\x{1F467}] |
|||
|[\x{1F3FB}-\x{1F3FF}]?\x{200D} |
|||
(?:[\x{2695}\x{2696}\x{2708}]\x{FE0F} |
|||
|[\x{1F33E}\x{1F373}\x{1F393}\x{1F3A4}\x{1F3A8}\x{1F3EB}\x{1F3ED}\x{1F4BB}\x{1F4BC}\x{1F527}\x{1F52C}\x{1F680}\x{1F692}] |
|||
) |
|||
)/ux', |
|||
/* some more combinations (order is important!) */ |
|||
'/[\x{26F9}\x{1F3C3}-\x{1F3CC}\x{1F46E}\x{1F46F}\x{1F461}-\x{1F477}\x{1F481}-\x{1F487}\x{1F575}\x{1F645}-\x{1F64E}\x{1F6A3}\x{1F6B4}-\x{1F6B6}\x{1F926}\x{1F937}-\x{1F93E}\x{1F9D6}-\x{1F9DF}] |
|||
[\x{FE0F}\x{1F3FB}-\x{1F3FF}]? |
|||
\x{200D}[\x{2640}\x{2642}]\x{FE0F} |
|||
/ux', |
|||
'/[\x{261D}\x{26F7}-\x{270D}\x{1F1E6}-\x{1F1FF}\x{1F385}\x{1F3C2}-\x{1F3CC}\x{1F442}-\x{1F487}\x{1F4AA}\x{1F574}-\x{1F596}\x{1F645}-\x{1F6CC}\x{1F918}-\x{1F9DD}] |
|||
[\x{1F1E6}-\x{1F1FF}\x{1F3FB}-\x{1F3FF}]/ux', |
|||
/* individual codepoints last */ |
|||
'/[\x{203C}\x{2049}\x{2139}-\x{21AA}\x{231A}-\x{23FA}\x{24C2}\x{25AA}-\x{27BF}\x{2934}-\x{2B55}\x{3030}-\x{3299}\x{1F004}-\x{1F9E6}]/u' |
|||
]; |
|||
|
|||
protected function __construct() |
|||
{ |
|||
$this->_emoji = require('Emoji/CompiledEmoji.php'); |
|||
} |
|||
|
|||
public function replace($string) |
|||
{ |
|||
return preg_replace_callback($this->_regex, function ($matches) { |
|||
$astext = implode('-', |
|||
array_map('dechex', |
|||
unpack('N*', mb_convert_encoding($matches[0], 'UCS-4BE', 'UTF-8')) |
|||
) |
|||
); |
|||
|
|||
/* Do we know this character? */ |
|||
if (!isset($this->_emoji[$astext])) { |
|||
/* No, return match unchanged */ |
|||
return $matches[0]; |
|||
} |
|||
|
|||
/* Yes, replace */ |
|||
return '<img |
|||
alt="' . $this->_emoji[$astext] . '" |
|||
class="emoji" |
|||
src="' .
|
|||
BASE_URI . |
|||
'themes/' . |
|||
\App\Configuration::findOrNew(1)->theme . |
|||
'/img/emojis/svg/' . |
|||
$astext . |
|||
'.svg" />'; |
|||
}, $string); |
|||
} |
|||
|
|||
public static function getInstance() |
|||
{ |
|||
if (!isset(static::$instance)) { |
|||
static::$instance = new Emoji; |
|||
} |
|||
|
|||
return static::$instance; |
|||
} |
|||
} |
|||
2663
src/Movim/Emoji/CompiledEmoji.php
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,75 @@ |
|||
#!/bin/mksh |
|||
#- |
|||
# Copyright © 2018 |
|||
# mirabilos <thorsten.glaser@teckids.org> |
|||
# |
|||
# Provided that these terms and disclaimer and all copyright notices |
|||
# are retained or reproduced in an accompanying document, permission |
|||
# is granted to deal in this work without restriction, including un‐ |
|||
# limited rights to use, publicly perform, distribute, sell, modify, |
|||
# merge, give away, or sublicence. |
|||
# |
|||
# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to |
|||
# the utmost extent permitted by applicable law, neither express nor |
|||
# implied; without malicious intent or gross negligence. In no event |
|||
# may a licensor, author or contributor be held liable for indirect, |
|||
# direct, other damage, loss, or other issues arising in any way out |
|||
# of dealing in the work, even if advised of the possibility of such |
|||
# damage or existence of a defect, except proven that it results out |
|||
# of said person’s immediate fault when using the work as intended. |
|||
#- |
|||
# Needs the Debian packages mksh and unicode-data installed. |
|||
|
|||
cd "$(dirname "$0")" |
|||
srcpath=../../../themes/material/img/emojis/svg |
|||
|
|||
cd "$srcpath" |
|||
set -A files -- *.svg |
|||
cd "$OLDPWD" |
|||
|
|||
cat >CompiledEmoji.php <<\EOF |
|||
<?php |
|||
|
|||
/* GENERATED FILE, DO NOT EDIT! */ |
|||
|
|||
return [ |
|||
EOF |
|||
|
|||
php >>CompiledEmoji.php |& |
|||
print -pr -- '<?php |
|||
$u = array();' |
|||
typeset -l codepoint |
|||
while IFS=';' read codepoint name rest; do |
|||
[[ $name = *\<* ]] && continue |
|||
print -pr -- "\$u['${codepoint##*(0)}'] = '$name';" |
|||
done </usr/share/unicode/UnicodeData.txt |
|||
print -pr -- ' |
|||
function lookup($name) { |
|||
global $u; |
|||
$x = ""; |
|||
$s = ""; |
|||
foreach (explode("-", $name) as $cp) { |
|||
if (isset($u[$cp])) |
|||
$x .= $s . $u[$cp]; |
|||
else |
|||
$x .= $x . sprintf("<U%04X>", hexdec($cp)); |
|||
$s = " + "; |
|||
} |
|||
return $x; |
|||
} |
|||
function handle($name) { |
|||
printf(" \"%s\" => \"%s\",\n", $name, lookup($name)); |
|||
} |
|||
' |
|||
for ff in "${files[@]}"; do |
|||
f=${ff%.svg} |
|||
if [[ $f != +([0-9a-f-]) ]]; then |
|||
print -ru2 -- "W: source file $ff does not match pattern!" |
|||
continue |
|||
fi |
|||
print -pr -- "handle('$f');" |
|||
done |
|||
exec 3>&p |
|||
exec 3>&- |
|||
wait |
|||
echo "];" >>CompiledEmoji.php |
|||
@ -0,0 +1,19 @@ |
|||
<?php |
|||
|
|||
define('BASE_URI', '(base)'); |
|||
mb_internal_encoding("UTF-8"); |
|||
|
|||
class Configuration |
|||
{ |
|||
public $theme = '(theme)'; |
|||
|
|||
public static function findOrNew() |
|||
{ |
|||
return new Configuration; |
|||
} |
|||
} |
|||
|
|||
require_once '../Emoji.php'; |
|||
|
|||
$text = file_get_contents('php://stdin'); |
|||
echo Emoji::getInstance()->replace($text); |
|||
@ -0,0 +1,61 @@ |
|||
#!/bin/mksh |
|||
#- |
|||
# Copyright © 2018 |
|||
# mirabilos <thorsten.glaser@teckids.org> |
|||
# |
|||
# Provided that these terms and disclaimer and all copyright notices |
|||
# are retained or reproduced in an accompanying document, permission |
|||
# is granted to deal in this work without restriction, including un‐ |
|||
# limited rights to use, publicly perform, distribute, sell, modify, |
|||
# merge, give away, or sublicence. |
|||
# |
|||
# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to |
|||
# the utmost extent permitted by applicable law, neither express nor |
|||
# implied; without malicious intent or gross negligence. In no event |
|||
# may a licensor, author or contributor be held liable for indirect, |
|||
# direct, other damage, loss, or other issues arising in any way out |
|||
# of dealing in the work, even if advised of the possibility of such |
|||
# damage or existence of a defect, except proven that it results out |
|||
# of said person’s immediate fault when using the work as intended. |
|||
|
|||
cd "$(dirname "$0")" |
|||
srcpath=../../../themes/material/img/emojis/svg |
|||
saveIFS=$IFS |
|||
|
|||
cd "$srcpath" |
|||
set -A files -- *.svg |
|||
cd "$OLDPWD" |
|||
|
|||
if [[ -n $1 ]]; then |
|||
set -A files -- "$@" |
|||
print -ru2 -- "W: only testing $# files from command line" |
|||
fi |
|||
|
|||
for f in "${files[@]}"; do |
|||
x=${f%.svg} |
|||
IFS=- |
|||
set -A y -- $x |
|||
IFS=$saveIFS |
|||
s='print "' |
|||
for z in "${y[@]}"; do |
|||
s+="\\x{$z}" |
|||
done |
|||
print -r -- "$s\\n\";" |
|||
done | perl -C7 | php replace-test.php |& |
|||
n=-1 |
|||
rv=0 |
|||
match=0 |
|||
mis=0 |
|||
while IFS= read -pr line; do |
|||
if [[ $line = '<img'*"/svg/${files[++n]}\""*\> ]]; then |
|||
let ++match |
|||
continue |
|||
fi |
|||
print -ru2 -- "W: file ${files[n]} not matched" |
|||
[[ -n $1 ]] && print -ru2 -- "N: line: $line" |
|||
rv=1 |
|||
let ++mis |
|||
done |
|||
(( rv )) || print -ru2 -- "I: all files matched" |
|||
print -ru2 -- "I: $match/${#files[*]} matched, $mis mismatched" |
|||
exit $rv |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue