From 46aa7cee819b1ba2d6d055386642b53b0f9b92f5 Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 4 Jul 2019 19:27:21 +0200 Subject: [PATCH] Initial emoticon management stuff. --- assets/less/emoticon.less | 4 ++ assets/less/main.less | 1 + assets/less/manage/emotes.less | 46 +++++++++++++ assets/less/manage/manage.less | 1 + misuzu.php | 1 + public/manage/general/emoticons.php | 4 +- src/emotes.php | 91 +++++++++++++++++++++++++ src/url.php | 1 + templates/manage/general/emoticons.twig | 62 +++++++++++++++++ 9 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 assets/less/emoticon.less create mode 100644 assets/less/manage/emotes.less create mode 100644 src/emotes.php diff --git a/assets/less/emoticon.less b/assets/less/emoticon.less new file mode 100644 index 00000000..dd0f8610 --- /dev/null +++ b/assets/less/emoticon.less @@ -0,0 +1,4 @@ +.emoticon { + vertical-align: middle; + display: inline-block; +} diff --git a/assets/less/main.less b/assets/less/main.less index abfa6924..4b200705 100644 --- a/assets/less/main.less +++ b/assets/less/main.less @@ -137,6 +137,7 @@ html { // Base styles @import "avatar"; @import "container"; +@import "emoticon"; @import "flag"; @import "navigation"; @import "pagination"; diff --git a/assets/less/manage/emotes.less b/assets/less/manage/emotes.less new file mode 100644 index 00000000..5b355b2e --- /dev/null +++ b/assets/less/manage/emotes.less @@ -0,0 +1,46 @@ +.manage__emotes { + + &__actions { + margin: 2px; + } + + &__emoticon { + max-width: 100px; + max-height: 100px; + } + + &__list { + width: 100%; + } + + &__entry { + display: flex; + justify-content: center; + align-items: center; + margin: 2px; + text-align: center; + + &--header { + border-bottom: 1px solid var(--accent-colour); + padding-bottom: 2px; + } + + &__id, + &__order, + &__hierarchy { + min-width: 40px; + } + + &__string { + min-width: 150px; + } + + &__image { + flex: 1 1 auto; + } + + &__actions { + min-width: 164px; + } + } +} diff --git a/assets/less/manage/manage.less b/assets/less/manage/manage.less index 76e9da07..d27c7907 100644 --- a/assets/less/manage/manage.less +++ b/assets/less/manage/manage.less @@ -27,6 +27,7 @@ } @import "blacklist"; +@import "emotes"; @import "navigation"; @import "role-item"; @import "roles"; diff --git a/misuzu.php b/misuzu.php index cc9fff55..94af2f09 100644 --- a/misuzu.php +++ b/misuzu.php @@ -40,6 +40,7 @@ require_once 'src/comments.php'; require_once 'src/config.php'; require_once 'src/csrf.php'; require_once 'src/db.php'; +require_once 'src/emotes.php'; require_once 'src/general.php'; require_once 'src/git.php'; require_once 'src/integer.php'; diff --git a/public/manage/general/emoticons.php b/public/manage/general/emoticons.php index 32bae19b..cfc24b41 100644 --- a/public/manage/general/emoticons.php +++ b/public/manage/general/emoticons.php @@ -6,4 +6,6 @@ if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), MSZ_PER return; } -echo tpl_render('manage.general.emoticons'); +echo tpl_render('manage.general.emoticons', [ + 'emotes' => emotes_list(PHP_INT_MAX), +]); diff --git a/src/emotes.php b/src/emotes.php new file mode 100644 index 00000000..99d3973a --- /dev/null +++ b/src/emotes.php @@ -0,0 +1,91 @@ +bindValue('hierarchy', $hierarchy); + $getEmotes->bindValue('order', $order); + $emotes = db_fetch_all($getEmotes); + } + + return $emotes ?? []; +} + +function emotes_add(string $string, string $url, int $hierarchy = 0, int $order = 0): int { + if(empty($string) || empty($url)) { + return -1; + } + + $insertEmote = db_prepare(' + INSERT INTO `msz_emoticons` ( + `emote_order`, `emote_hierarchy`, `emote_string`, `emote_url` + ) + VALUES ( + :order, :hierarchy, :string, :url + ) + '); + $insertEmote->bindValue('order', $order); + $insertEmote->bindValue('hierarchy', $hierarchy); + $insertEmote->bindValue('string', $string); + $insertEmote->bindValue('url', $url); + + if(!$insertEmote->execute()) { + return -2; + } + + return db_last_insert_id(); +} + +function emotes_add_alias(string $string, string $alias): int { + if(empty($string) || empty($alias)) { + return -1; + } + + $createAlias = db_prepare(' + INSERT INTO `msz_emoticons` ( + `emote_order`, `emote_hierarchy`, `emote_string`, `emote_url` + ) + SELECT `emote_order`, `emote_hierarchy`, :alias, `emote_url` + FROM `msz_emoticons` + WHERE `emote_string` = :string + '); + $createAlias->bindValue('string', $string); + $createAlias->bindValue('alias', $alias); + + if(!$insertEmote->execute()) { + return -2; + } + + return db_last_insert_id(); +} + +// use this for actually removing emoticons +function emotes_remove_url(string $url): void { + $removeByUrl = db_prepare(' + DELETE FROM `msz_emoticons` + WHERE `emote_url` = :url + '); + $removeByUrl->bindValue('url', $url); + $removeByUrl->execute(); +} + +// use this for removing single aliases +function emotes_remove_string(string $string): void { + $removeByString = db_prepare(' + DELETE FROM `msz_emoticons` + WHERE `emote_string` = :string + '); + $removeByString->bindValue('string', $string); + $removeByString->execute(); +} diff --git a/src/url.php b/src/url.php index 8b4e1a5c..384de21a 100644 --- a/src/url.php +++ b/src/url.php @@ -97,6 +97,7 @@ define('MSZ_URLS', [ 'manage-general-overview' => ['/manage/general'], 'manage-general-logs' => ['/manage/general/logs.php'], 'manage-general-emoticons' => ['/manage/general/emoticons.php'], + 'manage-general-emoticon' => ['/manage/general/emoticon.php', ['e' => '']], 'manage-general-settings' => ['/manage/general/settings.php'], 'manage-general-blacklist' => ['/manage/general/blacklist.php'], diff --git a/templates/manage/general/emoticons.twig b/templates/manage/general/emoticons.twig index cc9bba57..6509a214 100644 --- a/templates/manage/general/emoticons.twig +++ b/templates/manage/general/emoticons.twig @@ -1 +1,63 @@ {% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% block manage_content %} +
+ {{ container_title(' Emoticons') }} + +
+ Here you can manage emoticons and their aliases and other properties. +
+ +
+ Add New +
+ +
+
+
+ ID +
+
+ Order +
+
+ Hier. +
+
+ String +
+
+ Image +
+
+ Actions +
+
+ + {% for emote in emotes %} +
+
+ #{{ emote.emote_id }} +
+
+ {{ emote.emote_order }} +
+
+ {{ emote.emote_hierarchy }} +
+
+ {{ emote.emote_string }} +
+
+ {{ emote.emote_string }} +
+
+ + Edit +
+
+ {% endfor %} +
+
+{% endblock %}