Skip to content

Commit

Permalink
Swap to Twemoji
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhgboyle committed Mar 26, 2022
1 parent 483367b commit c545f63
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 51 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"jdorn/sql-formatter": "^1.2",
"smarty/smarty": "^4.0",
"ezyang/htmlpurifier": "^4.13",
"emojione/emojione": "^4.5",
"samayo/bulletproof": "^4.0",
"phpmailer/phpmailer": "^6.5",
"evert/sitemap-php": "^1.2",
Expand All @@ -20,7 +19,8 @@
"xpaw/php-minecraft-query": "^4.0",
"games647/minecraft-banner-generator": "^0.4.1",
"symfony/polyfill-php80": "^v1.24.0",
"ircmaxell/password-compat": "^1.0"
"ircmaxell/password-compat": "^1.0",
"astrotomic/php-twemoji": "^0.2.2"
},
"require-dev": {
"phpstan/phpstan": "^1.4",
Expand Down
73 changes: 51 additions & 22 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/classes/Core/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static function createTinyEditor(Language $language, string $name): strin
spoiler_caption: '{$language->get('general', 'spoiler')}',
default_link_target: '_blank',
skin: '$skin',
emoticons_database: 'emojiimages',
});
";
}
Expand Down
16 changes: 16 additions & 0 deletions core/classes/Core/Util.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Astrotomic\Twemoji\Twemoji;

/**
* Contains misc utility methods.
*
Expand Down Expand Up @@ -557,4 +560,17 @@ public static function isModuleEnabled(string $name): bool {
public static function getCurrentNamelessVersion(): string {
return self::getSetting(DB::getInstance(), 'nameless_version');
}

/**
* Replace native emojis with their Twemoji equivalent.
*
* @param string $text Text to parse
* @return string Text with emojis replaced with URLs to their Twemoji equivalent.
*/
public static function renderEmojis(string $text): string {
return Twemoji::text($text)->toHtml(null, [
'width' => 20,
'height' => 20,
]);
}
}
10 changes: 0 additions & 10 deletions custom/templates/DefaultRevamp/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,6 @@ body.pushable>.pusher {
right: 1rem;
}

#profile-forum .emojione {
height: 24px;
width: auto;
}

/*
* [ FORUM SEARCH ]
*/
Expand Down Expand Up @@ -919,11 +914,6 @@ select {
height: auto;
}

img.emojione {
height: 24px;
width: 24px;
}

.ui.icon.message.announcement i {
padding-right: 20px;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Core/pages/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
$smarty->assign([
'WIDGETS_LEFT' => $widgets->getWidgets('left'),
'WIDGETS_RIGHT' => $widgets->getWidgets('right'),
'CONTENT' => (($custom_page->all_html == 0) ? Output::getPurified(htmlspecialchars_decode($custom_page->content)) : htmlspecialchars_decode($custom_page->content))
'CONTENT' => Util::renderEmojis((($custom_page->all_html == 0) ? Output::getPurified(htmlspecialchars_decode($custom_page->content)) : htmlspecialchars_decode($custom_page->content)))
]);

$page_load = microtime(true) - $start;
Expand Down
12 changes: 11 additions & 1 deletion modules/Core/pages/panel/users_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,17 @@
]);
}

$template->addJSScript(Input::createTinyEditor($this->_language, 'InputSignature'));
$template->addCSSFiles([
(defined('CONFIG_PATH') ? CONFIG_PATH : '') . '/core/assets/plugins/prism/prism.css' => [],
(defined('CONFIG_PATH') ? CONFIG_PATH : '') . '/core/assets/plugins/tinymce/plugins/spoiler/css/spoiler.css' => [],
]);

$template->addJSFiles([
(defined('CONFIG_PATH') ? CONFIG_PATH : '') . '/core/assets/plugins/prism/prism.js' => [],
(defined('CONFIG_PATH') ? CONFIG_PATH : '') . '/core/assets/plugins/tinymce/plugins/spoiler/js/spoiler.js' => [],
(defined('CONFIG_PATH') ? CONFIG_PATH : '') . '/core/assets/plugins/tinymce/tinymce.min.js' => []
]);
$template->addJSScript(Input::createTinyEditor($language, 'InputSignature'));

$page_load = microtime(true) - $start;
define('PAGE_LOAD_TIME', str_replace('{x}', round($page_load, 3), $language->get('general', 'page_loaded_in')));
Expand Down
2 changes: 0 additions & 2 deletions modules/Core/pages/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

$timeago = new TimeAgo(TIMEZONE);

$emojione = new Emojione\Client(new Emojione\Ruleset());

$profile = explode('/', rtrim($_GET['route'], '/'));
if (count($profile) >= 3 && ($profile[count($profile) - 1] != 'profile' || $profile[count($profile) - 2] == 'profile') && !isset($_GET['error'])) {
// User specified
Expand Down
6 changes: 2 additions & 4 deletions modules/Core/pages/user/messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

$timeago = new TimeAgo(TIMEZONE);

$emojione = new Emojione\Client(new Emojione\Ruleset());

$smarty->assign(
[
'ERROR_TITLE' => $language->get('general', 'error')
Expand Down Expand Up @@ -470,7 +468,7 @@
'author_groups' => $target_user->getAllGroupHtml(),
'message_date' => $timeago->inWords(date('d M Y, H:i', $nValue->created), $language->getTimeLanguage()),
'message_date_full' => date('d M Y, H:i', $nValue->created),
'content' => Output::getPurified($emojione->unicodeToImage(Output::getDecoded($nValue->content)))
'content' => Output::getPurified(Util::renderEmojis(Output::getDecoded($nValue->content))),
];
}

Expand Down Expand Up @@ -505,7 +503,7 @@
'author_groups' => $target_user->getAllGroupHtml(),
'message_date' => $timeago->inWords(date('d M Y, H:i', $nValue->created), $language->getTimeLanguage()),
'message_date_full' => date('d M Y, H:i', $nValue->created),
'content' => Output::getPurified($emojione->toImage(Output::getDecoded($nValue->content)))
'content' => Output::getPurified(Util::renderEmojis(Output::getDecoded($nValue->content))),
];
}

Expand Down
2 changes: 0 additions & 2 deletions modules/Core/pages/user/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
$page_title = $language->get('user', 'user_cp');
require_once(ROOT_PATH . '/core/templates/frontend_init.php');

$emojione = new Emojione\Client(new Emojione\Ruleset());

// Forum enabled?
$forum_enabled = Util::isModuleEnabled('Forum');

Expand Down
3 changes: 1 addition & 2 deletions modules/Forum/pages/forum/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

// Initialise
$timeago = new TimeAgo(TIMEZONE);
$emojione = new Emojione\Client(new Emojione\Ruleset());

// Get user group ID
$user_groups = $user->getAllGroupIds();
Expand Down Expand Up @@ -173,7 +172,7 @@
$n = 0;
while (($n < count($results->data)) && isset($results->data[$n])) {
$content = htmlspecialchars_decode($results->data[$n]['post_content']);
$content = $emojione->toImage($content);
$content = Util::renderEmojis($content);
$content = Output::getPurified($content);

$post_user = new User($results->data[$n]['post_author']);
Expand Down
6 changes: 2 additions & 4 deletions modules/Forum/pages/forum/view_topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
$timeago = new TimeAgo(TIMEZONE);
$mentionsParser = new MentionsParser();

$emojione = new Emojione\Client(new Emojione\Ruleset());

// Get topic ID
$tid = explode('/', $route);
$tid = $tid[count($tid) - 1];
Expand Down Expand Up @@ -671,7 +669,7 @@

// Purify post content
$content = Util::replaceAnchorsWithText(Output::getDecoded($nValue->post_content));
$content = $emojione->toImage($content);
$content = Util::renderEmojis($content);
$content = Output::getPurified($content, true);

// Get post date
Expand Down Expand Up @@ -708,7 +706,7 @@
'post_date' => $post_date,
'buttons' => $buttons,
'content' => $content,
'signature' => Output::getPurified(htmlspecialchars_decode($signature)),
'signature' => Output::getPurified(Util::renderEmojis(htmlspecialchars_decode($signature))),
'fields' => (empty($fields) ? [] : $fields),
'edited' => (is_null($nValue->last_edited) ? null : str_replace('{x}', $timeago->inWords(date('Y-m-d H:i:s', $nValue->last_edited), $language->getTimeLanguage()), $forum_language->get('forum', 'last_edited'))),
'edited_full' => (is_null($nValue->last_edited) ? null : date('d M Y, H:i', $nValue->last_edited)),
Expand Down
2 changes: 1 addition & 1 deletion modules/Forum/profile_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
$posts[] = [
'link' => URL::build('/forum/topic/' . $latest_post->topic_id . '-' . $forum->titleToURL($topic_title), 'pid=' . $latest_post->id),
'title' => $topic_title,
'content' => Output::getPurified($emojione->toImage(htmlspecialchars_decode($latest_post->post_content))),
'content' => Output::getPurified(Util::renderEmojis(htmlspecialchars_decode($latest_post->post_content))),
'date_friendly' => $date_friendly,
'date_full' => $date_full
];
Expand Down

0 comments on commit c545f63

Please sign in to comment.