4 * Description: Adds a smileybutton to the Inputbox
6 * Author: Johannes Schwab <http://friendica.jschwab.mooo.com/profile/ddorian>
10 function smileybutton_install() {
14 * Register hooks for jot_tool and plugin_settings
18 register_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button');
19 register_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings');
20 register_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post');
22 logger("installed smileybutton");
26 function smileybutton_uninstall() {
30 * Delet registered hooks
34 unregister_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button');
35 unregister_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings');
36 unregister_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post');
38 logger("removed smileybutton");
43 function show_button($a, &$b) {
47 * Check if it is a local user and he has enabled smileybutton
54 $nobutton = get_pconfig(local_user(), 'smileybutton', 'nobutton');
59 * Prepare the Smilie-Arrays
65 * I have copied this from /include/text.php, removed dobles
98 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
99 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
100 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
101 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
102 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
103 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
104 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
105 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
106 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
107 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
108 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
109 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
110 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
111 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
112 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
113 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
114 '<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
115 '<img class="smiley" src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
116 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
117 '<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
118 '<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
119 '<img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" />',
120 '<img class="smiley" src="' . $a->get_baseurl() . '/images/rhash-16.png" alt="red" />'
125 * Call hooks to get aditional smileies from other addons
129 $params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed
130 call_hooks('smilie', $params);
134 * Generate html for smileylist
138 $s = "\t<table class=\"smiley-preview\"><tr>\n";
139 for($x = 0; $x < count($params['texts']); $x ++) {
140 $icon = $params['icons'][$x];
141 $icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon);
142 $icon = str_replace('class="smiley"', 'class="smiley_preview"', $icon);
143 $s .= "<td>" . $icon . "</td>";
144 if (($x+1) % (sqrt(count($params['texts']))+1) == 0) {
145 $s .= "</tr>\n\t<tr>";
148 $s .= "\t</tr></table>\n";
156 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
160 * Add the button to the Inputbox
164 $b = "<div id=\"profile-smiley-wrapper\" style=\"display: block;\" >\n";
165 $b .= "\t<img src=\"" . $a->get_baseurl() . "/addon/smileybutton/icon.gif\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n";
172 * Write the smileies to an (hidden) div
177 $b .= "\t<div id=\"smileybutton\">\n";
179 $b .= "\t<div id=\"smileybutton\" style=\"display:none;\">\n";
186 * Function to show and hide the smiley-list in the hidden div
193 $b .= " smileybutton_show = 0;\n";
194 $b .= " function toggle_smileybutton() {\n";
195 $b .= " if (! smileybutton_show) {\n";
196 $b .= " $(\"#smileybutton\").show();\n";
197 $b .= " smileybutton_show = 1;\n";
199 $b .= " $(\"#smileybutton\").hide();\n";
200 $b .= " smileybutton_show = 0;\n";
206 * Function to add the chosen smiley to the inputbox
210 $b .= " function smileybutton_addsmiley(text) {\n";
211 $b .= " if(plaintext == 'none') {\n";
212 $b .= " var v = $(\"#profile-jot-text\").val();\n";
213 $b .= " v = v + text;\n";
214 $b .= " $(\"#profile-jot-text\").val(v);\n";
215 $b .= " $(\"#profile-jot-text\").focus();\n";
217 $b .= " var v = tinymce.activeEditor.getContent();\n";
218 $b .= " v = v + text;\n";
219 $b .= " tinymce.activeEditor.setContent(v);\n";
220 $b .= " tinymce.activeEditor.focus();\n";
232 * Set the configuration
236 function smileybutton_settings_post($a,$post) {
239 if($_POST['smileybutton-submit'])
240 set_pconfig(local_user(),'smileybutton','nobutton',intval($_POST['smileybutton']));
247 * Add configuration-dialog to form
252 function smileybutton_settings(&$a,&$s) {
257 /* Add our stylesheet to the page so we can make our settings look nice */
259 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
261 /* Get the current state of our config variable */
263 $nobutton = get_pconfig(local_user(),'smileybutton','nobutton');
264 $checked = (($nobutton) ? ' checked="checked" ' : '');
266 /* Add some HTML to the existing form */
268 $s .= '<div class="settings-block">';
269 $s .= '<h3>Smileybutton settings</h3>';
270 $s .= '<div id="smileybutton-enable-wrapper">';
272 $s .= 'You can hide the button and show the smilies directly.<br /><br />';
274 $s .= '<label id="smileybutton-enable-label" for="smileybutton-nobutton-checkbox">Hide the button</label>';
275 $s .= '<input id="smileybutton-nobutton-checkbox" type="checkbox" name="smileybutton" value="1" ' . $checked . '/>';
277 $s .= '</div><div class="clear"></div>';
279 /* provide a submit button */
281 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="smileybutton-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';