From bad919b1cd722651e364f0b423091cec22bf6d78 Mon Sep 17 00:00:00 2001 From: Fraenkiman Date: Sat, 2 Mar 2024 01:56:59 +0100 Subject: [PATCH] Emoticons toolbar - allows the integration of emoticons as UTFT-8 HTML entity via a toolbar - the toolbar is available when creating/editing entries, static pages and in the comment function --- admin/panels/entry/admin.entry.write.tpl | 1 + admin/panels/static/admin.static.write.tpl | 1 + fp-interface/sharedtpls/comment-form.tpl | 28 ++++---- fp-plugins/emoticons/plugin.emoticons.php | 84 ++++++++++++++++++++++ fp-plugins/emoticons/res/emoticons.css | 13 ++++ fp-plugins/emoticons/res/emoticons.js | 21 ++++++ 6 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 fp-plugins/emoticons/plugin.emoticons.php create mode 100644 fp-plugins/emoticons/res/emoticons.css create mode 100644 fp-plugins/emoticons/res/emoticons.js diff --git a/admin/panels/entry/admin.entry.write.tpl b/admin/panels/entry/admin.entry.write.tpl index 5b50e8f..aaeba27 100755 --- a/admin/panels/entry/admin.entry.write.tpl +++ b/admin/panels/entry/admin.entry.write.tpl @@ -37,6 +37,7 @@ {if function_exists('plugin_bbcode_init')} {include file="plugin:bbcode/toolbar"} {/if} + {action hook=simple_toolbar_form}

{if isset($error) && isset($error.content) && !empty($error.content)} {assign var=class value="field-error"} diff --git a/admin/panels/static/admin.static.write.tpl b/admin/panels/static/admin.static.write.tpl index a4dd3ca..3ac0e26 100755 --- a/admin/panels/static/admin.static.write.tpl +++ b/admin/panels/static/admin.static.write.tpl @@ -35,6 +35,7 @@ {if function_exists('plugin_bbcode_init')} {include file="plugin:bbcode/toolbar"} {/if} + {action hook=simple_toolbar_form}

{if isset($error) && isset($error.content) && !empty($error.content)} {assign var=class value="field-error"} diff --git a/fp-interface/sharedtpls/comment-form.tpl b/fp-interface/sharedtpls/comment-form.tpl index 9f22f4f..e2e7312 100644 --- a/fp-interface/sharedtpls/comment-form.tpl +++ b/fp-interface/sharedtpls/comment-form.tpl @@ -1,21 +1,21 @@ {if !$entry_commslock}

{$lang.comments.head}

{$lang.comments.descr}

- +
- + {include file='shared:errorlist.tpl'} - - + + {if not $flatpress.loggedin} - + {*
*}
- +

{if isset($error) && isset($error.name) && !empty($error.name)} {assign var=class value="field-error"} @@ -30,7 +30,7 @@

- +

{if isset($error) && isset($error.email) && !empty($error.email)} {assign var=class value="field-error"} @@ -45,7 +45,7 @@

- +

{if isset($error) && isset($error.url) && !empty($error.url)} {assign var=class value="field-error"} @@ -60,15 +60,15 @@

- + {* do action *} {comment_form} - +
- + {/if} - - + + {action hook=simple_toolbar_form}
{if isset($error) && isset($error.content) && !empty($error.content)} {assign var=class value="field-error"} @@ -84,7 +84,7 @@ id="content" rows="10" cols="74">{$contentvalue|wp_specialchars:1}

{*here will go a plugin hook*}
- +
diff --git a/fp-plugins/emoticons/plugin.emoticons.php b/fp-plugins/emoticons/plugin.emoticons.php new file mode 100644 index 0000000..95ee2ef --- /dev/null +++ b/fp-plugins/emoticons/plugin.emoticons.php @@ -0,0 +1,84 @@ + '😄', + ':smiley:' => '😃', + ':wink:' => '😉', + ':blush:' => '😊', + ':grin:' => '😁', + ':smirk:' => '😏', + ':heart_eyes:' => '😍', + ':sunglasses:' => '😎', + ':laughing:' => '😆', + ':neutral_face:' => '😐', + ':flushed:' => '😳', + ':dizzy_face:' => '😵', + ':cry:' => '😢', + ':persevere:' => '😣', + ':worried:' => '😟', + ':hushed:' => '😮', + ':mag:' => '🔍', + ':hot_beverage:' => '☕', + ':exclamation:' => '❗', + ':question:' => '❓' +); + +// outputs the editor toolbar +function plugin_emoticons() { + global $plugin_emoticons; + if (!count($plugin_emoticons)) + return true; + echo ''; + echo '
'; + foreach ($plugin_emoticons as $text => $emoticon) { + echo ''; + echo $emoticon; + echo ' '; + } + echo '
'; + return true; +} + +// replaces the text with an utf-8 emoticon +function plugin_emoticons_filter ($emostring) { + global $plugin_emoticons; + + foreach ($plugin_emoticons as $text => $emoticon) { + $emostring = str_replace( + ["$text"], + "{$emoticon}", + $emostring + ); + } + return $emostring; +} + +// css file +function plugin_emoticons_css() { + $pdir = plugin_geturl('emoticons'); + echo ' + + + '; +} + +// register css file +add_action('wp_head', 'plugin_emoticons_css', 0); +// register editor toolbar +add_filter('simple_toolbar_form', 'plugin_emoticons',); +// register to the hook +add_filter('the_content','plugin_emoticons_filter'); +// register for emoticon in comment +add_filter('comment_text','plugin_emoticons_filter'); +// register for the excerpt of a post +add_filter('the_excerpt', 'plugin_emoticons_filter'); +?> diff --git a/fp-plugins/emoticons/res/emoticons.css b/fp-plugins/emoticons/res/emoticons.css new file mode 100644 index 0000000..b014cbf --- /dev/null +++ b/fp-plugins/emoticons/res/emoticons.css @@ -0,0 +1,13 @@ +/* + * Name: Emoticons CSS + * Author: Fraenkiman + * Version: 1.0.0 + * Module: emoticons.css + * Description: This file defines the style of the emoticons + */ + +.emoticons a, .emoticons a:hover { + text-decoration: none !IMPORTANT; + text-shadow: none !IMPORTANT; + font-weight: normal !IMPORTANT +} diff --git a/fp-plugins/emoticons/res/emoticons.js b/fp-plugins/emoticons/res/emoticons.js new file mode 100644 index 0000000..8586aaf --- /dev/null +++ b/fp-plugins/emoticons/res/emoticons.js @@ -0,0 +1,21 @@ +/* + * Emoticons Plugin + */ +function insertAtCursor(myField, myValue) { + if(document.selection) { + myField.focus(); + sel = document.selection.createRange(); + sel.text = myValue; + } + else if (myField.selectionStart || myField.selectionStart == '0') { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); + } else { + myField.value += myValue; + } +} + +function emoticons(value) { + return insertAtCursor(document.getElementById('content'), value); +}