From 0ed6c5339731936d5150a9f6174ae49d641333ad Mon Sep 17 00:00:00 2001 From: Johannes Schwab Date: Fri, 30 Aug 2013 03:00:56 +0200 Subject: [PATCH 1/4] Add Smileybutton Plugin --- smileybutton/icon.gif | Bin 0 -> 306 bytes smileybutton/smileybutton.css | 14 ++ smileybutton/smileybutton.php | 254 ++++++++++++++++++++++++++++++++++ 3 files changed, 268 insertions(+) create mode 100644 smileybutton/icon.gif create mode 100755 smileybutton/smileybutton.css create mode 100755 smileybutton/smileybutton.php diff --git a/smileybutton/icon.gif b/smileybutton/icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..e3fe6a55c6c226dedffb4cde18e703529411f8bd GIT binary patch literal 306 zcmZ?wbhEHb6k-r!Xpv&z=jXSxvkMLmj*pM8sHkXfZ=W({%8VH^=FFM1WXY0c%a*NJ zv104it=qP3+r4}Do;`bxA3uKbW$ z@h1x-7lS;54g(N?>||hF|3JMjCA05zpvdu}zMhXEkzuxM#Y$eSks@8J!GQ{1-EPM| zRj|yS=5yH8NJq2D!9e?rM1bI#r$QV(r;~kJs#ZiCV`hx0+Ze*9^!kU>Odk~i0ikAz zc=@W@=C0-@v9??h0oLwjRsmtL3VCip5g`_4-ez8A79o*rB|a{RI%b9q49s;BTq>Sx tg}GQ*xV8kVa`KAS)QO0T@^Y$ka|t@z3vz|%b8~WWabD5CqoT-Q4FI4}eft0a literal 0 HcmV?d00001 diff --git a/smileybutton/smileybutton.css b/smileybutton/smileybutton.css new file mode 100755 index 000000000..bb84030f8 --- /dev/null +++ b/smileybutton/smileybutton.css @@ -0,0 +1,14 @@ + + + +#smileybutton-enable-label { + float: left; + width: 200px; + margin-bottom: 25px; +} + +#smileybutton-checkbox { + float: left; +} + + diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php new file mode 100755 index 000000000..d6520a75b --- /dev/null +++ b/smileybutton/smileybutton.php @@ -0,0 +1,254 @@ + + */ + + +function smileybutton_install() { + + /** + * + * Register hooks for jot_tool and plugin_settings + * + */ + + register_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); + register_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings'); + register_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post'); + + logger("installed smileybutton"); +} + + +function smileybutton_uninstall() { + + /** + * + * Delet registered hooks + * + */ + + unregister_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); + unregister_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings'); + unregister_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post'); + + logger("removed smileybutton"); +} + + + +function show_button($a, &$b) { + + /** + * + * Check if it is a local user and he has enabled smileybutton + * + */ + + if(! local_user()) + return; + + $active = get_pconfig(local_user(), 'smileybutton', 'enable'); + + if(! $active) + return; + + /** + * + * Prepare the Smilie-Arrays + * + */ + + /** + * + * I have copied this from /include/text.php and removed dobles + * + */ + + $texts = array( + '<3', + '</3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-X', + ':-D', + ':-O', + '\\\\o/', + 'O_o', + ":\'(", + ":-!", + ":-/", + ":-[", + "8-)", + ':beer', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica', + 'red#' + + ); + + $icons = array( + '<3', + '</3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-X', + ':-D', + ':-O', + '\\o/', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica', + 'red' + ); + + /** + * + * Call hooks to get aditional smileies from other addons + * + */ + + $params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed + call_hooks('smiley', $params); + + + /** + * + * Generate html for smileylist + * + */ + + $s = "\t"; + for($x = 0; $x < count($params['texts']); $x ++) { + $icon = $params['icons'][$x]; + $icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon); + $s .= $icon . ' '; + if ($x != 0 && $x % 10 == 0) { + $s .= "
\n\t"; + } + } + + /** + * + * Add the button to the Inputbox + * + */ + + $b = "
\n"; + $b .= "\tget_baseurl() . "/addon/smileybutton/icon.gif\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n"; + $b .= "\t
\n"; + + /** + * + * Write the smileies to an hidden div + * + */ + + $b .= "\t
\n"; + $b .= $s . "\n"; + $b .= "
\n"; + + /** + * + * Function to show and hide the smiley-list in the hidden div + * + */ + + $b .= "\n"; +} + + + + + +/** + * + * Set the configuration + * + */ + +function smileybutton_settings_post($a,$post) { + if(! local_user()) + return; + if($_POST['smileybutton-submit']) + set_pconfig(local_user(),'smileybutton','enable',intval($_POST['smileybutton'])); +} + + +/** + * + * Add configuration-dialog to form + * + */ + + +function smileybutton_settings(&$a,&$s) { + + if(! local_user()) + return; + + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= '' . "\r\n"; + + /* Get the current state of our config variable */ + + $enabled = get_pconfig(local_user(),'smileybutton','enable'); + + $checked = (($enabled) ? ' checked="checked" ' : ''); + + /* Add some HTML to the existing form */ + + $s .= '
'; + $s .= '

Smileybutton settings

'; + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + /* provide a submit button */ + + $s .= '
'; + +} From f2a019504c1624507447a35edd08931b909773bc Mon Sep 17 00:00:00 2001 From: Johannes Schwab Date: Sat, 31 Aug 2013 13:50:02 +0200 Subject: [PATCH 2/4] Fixed for tinymce and improved appearance --- smileybutton/icon.gif | Bin 306 -> 293 bytes smileybutton/smileybutton.css | 7 +++++++ smileybutton/smileybutton.php | 35 +++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/smileybutton/icon.gif b/smileybutton/icon.gif index e3fe6a55c6c226dedffb4cde18e703529411f8bd..6ce0947194f28f0bd04357af315f529d8262525e 100644 GIT binary patch literal 293 zcmZ?wbhEHb6k-r!Xkh>WV`F0iYHTw{G2f^5n^f40ti+WYDAMiQsG%z*e)=(E443q}iHe?r zEDhHl9Bt^jqSxr4`={51U-V(B!itUA(@r^>{0&l@ynf#AmG{3kL@Q;82(VTO39$-z z7Rz%BiU_eVdkFC|vxtkNDe-ZMS1>ayVPLKh=TdQBD9pve!nGnmm6O+`Tv)`6ms6da YOE61JkSkE1o0E%+^SJ(b6-5SX00NL_j{pDw literal 306 zcmZ?wbhEHb6k-r!Xpv&z=jXSxvkMLmj*pM8sHkXfZ=W({%8VH^=FFM1WXY0c%a*NJ zv104it=qP3+r4}Do;`bxA3uKbW$ z@h1x-7lS;54g(N?>||hF|3JMjCA05zpvdu}zMhXEkzuxM#Y$eSks@8J!GQ{1-EPM| zRj|yS=5yH8NJq2D!9e?rM1bI#r$QV(r;~kJs#ZiCV`hx0+Ze*9^!kU>Odk~i0ikAz zc=@W@=C0-@v9??h0oLwjRsmtL3VCip5g`_4-ez8A79o*rB|a{RI%b9q49s;BTq>Sx tg}GQ*xV8kVa`KAS)QO0T@^Y$ka|t@z3vz|%b8~WWabD5CqoT-Q4FI4}eft0a diff --git a/smileybutton/smileybutton.css b/smileybutton/smileybutton.css index bb84030f8..916e04165 100755 --- a/smileybutton/smileybutton.css +++ b/smileybutton/smileybutton.css @@ -1,5 +1,12 @@ +img.smiley_preview { + max-height: 25px; + max-width: 25px; +} +table.smiley-preview { + border: 1px solid #AAAAAA; +} #smileybutton-enable-label { float: left; diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php index d6520a75b..afd3e214c 100755 --- a/smileybutton/smileybutton.php +++ b/smileybutton/smileybutton.php @@ -128,8 +128,7 @@ function show_button($a, &$b) { */ $params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed - call_hooks('smiley', $params); - + call_hooks('smilie', $params); /** * @@ -137,15 +136,25 @@ function show_button($a, &$b) { * */ - $s = "\t"; + $s = "\t\n"; for($x = 0; $x < count($params['texts']); $x ++) { $icon = $params['icons'][$x]; $icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon); - $s .= $icon . ' '; - if ($x != 0 && $x % 10 == 0) { - $s .= "
\n\t"; + $icon = str_replace('class="smiley"', 'class="smiley_preview"', $icon); + $s .= ""; + if (($x+1) % (sqrt(count($params['texts']))+1) == 0) { + $s .= "\n\t"; } } + $s .= "\t
" . $icon . "
\n"; + + /** + * + * Add css to page + * + */ + + $a->page['htmlhead'] .= '' . "\r\n"; /** * @@ -191,9 +200,17 @@ function show_button($a, &$b) { */ $b .= " function smileybutton_addsmiley(text) {\n"; - $b .= " v = $(\"#profile-jot-text\").val()\n"; - $b .= " v = v + text\n"; - $b .= " $(\"#profile-jot-text\").val(v)\n"; + $b .= " if(plaintext == 'none') {\n"; + $b .= " var v = $(\"#profile-jot-text\").val();\n"; + $b .= " v = v + text;\n"; + $b .= " $(\"#profile-jot-text\").val(v);\n"; + $b .= " $(\"#profile-jot-text\").focus();\n"; + $b .= " } else {\n"; + $b .= " var v = tinymce.activeEditor.getContent();\n"; + $b .= " v = v + text;\n"; + $b .= " tinymce.activeEditor.setContent(v);\n"; + $b .= " tinymce.activeEditor.focus();\n"; + $b .= " }\n"; $b .= " }\n"; $b .= "\n"; } From ad6e4c2ba058163a73e6d3dbb91ff38dbbcc4697 Mon Sep 17 00:00:00 2001 From: Johannes Schwab Date: Sat, 7 Sep 2013 18:35:00 +0200 Subject: [PATCH 3/4] Add an option to hide the button --- smileybutton/smileybutton.php | 72 ++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php index afd3e214c..abedf27ea 100755 --- a/smileybutton/smileybutton.php +++ b/smileybutton/smileybutton.php @@ -1,9 +1,9 @@ + * Author: Johannes Schwab */ @@ -48,13 +48,11 @@ function show_button($a, &$b) { * */ - if(! local_user()) - return; - - $active = get_pconfig(local_user(), 'smileybutton', 'enable'); - - if(! $active) - return; + if(! local_user()) { + $nobutton = false; + } else { + $nobutton = get_pconfig(local_user(), 'smileybutton', 'nobutton'); + } /** * @@ -64,7 +62,8 @@ function show_button($a, &$b) { /** * - * I have copied this from /include/text.php and removed dobles + * I have copied this from /include/text.php, removed dobles + * and some escapes. * */ @@ -161,18 +160,24 @@ function show_button($a, &$b) { * Add the button to the Inputbox * */ + if (! $nobutton) { + $b = "
\n"; + $b .= "\tget_baseurl() . "/addon/smileybutton/icon.gif\" id=\"smileybutton\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n"; + $b .= "\t
\n"; + } - $b = "
\n"; - $b .= "\tget_baseurl() . "/addon/smileybutton/icon.gif\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n"; - $b .= "\t
\n"; /** * - * Write the smileies to an hidden div + * Write the smileies to an (hidden) div * */ - $b .= "\t
\n"; + if ($nobutton) { + $b .= "\t
\n"; + } else { + $b .= "\t
\n"; + } $b .= $s . "\n"; $b .= "
\n"; @@ -183,15 +188,18 @@ function show_button($a, &$b) { */ $b .= "