4 * Description: Adds an smileybutton to the Inputbox
6 * Author: Johannes Schwab <johannes_schwab@gmx.de>
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 $active = get_pconfig(local_user(), 'smileybutton', 'enable');
61 * Prepare the Smilie-Arrays
67 * I have copied this from /include/text.php and removed dobles
99 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
100 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
101 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
102 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
103 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
104 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
105 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
106 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
107 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
108 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
109 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
110 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
111 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
112 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
113 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
114 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
115 '<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
116 '<img class="smiley" src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
117 '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
118 '<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
119 '<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
120 '<img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" />',
121 '<img class="smiley" src="' . $a->get_baseurl() . '/images/rhash-16.png" alt="red" />'
126 * Call hooks to get aditional smileies from other addons
130 $params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed
131 call_hooks('smiley', $params);
136 * Generate html for smileylist
141 for($x = 0; $x < count($params['texts']); $x ++) {
142 $icon = $params['icons'][$x];
143 $icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon);
145 if ($x != 0 && $x % 10 == 0) {
152 * Add the button to the Inputbox
156 $b = "<div id=\"profile-smiley-wrapper\" style=\"display: block;\" >\n";
157 $b .= "\t<img src=\"" . $a->get_baseurl() . "/addon/smileybutton/icon.gif\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n";
162 * Write the smileies to an hidden div
166 $b .= "\t<div id=\"smileybutton\" style=\"display:none;\">\n";
172 * Function to show and hide the smiley-list in the hidden div
177 $b .= " smileybutton_show = 0;\n";
178 $b .= " function toggle_smileybutton() {\n";
179 $b .= " if (! smileybutton_show) {\n";
180 $b .= " $(\"#smileybutton\").show();\n";
181 $b .= " smileybutton_show = 1;\n";
183 $b .= " $(\"#smileybutton\").hide();\n";
184 $b .= " smileybutton_show = 0;\n";
189 * Function to add the chosen smiley to the inputbox
193 $b .= " function smileybutton_addsmiley(text) {\n";
194 $b .= " v = $(\"#profile-jot-text\").val()\n";
195 $b .= " v = v + text\n";
196 $b .= " $(\"#profile-jot-text\").val(v)\n";
207 * Set the configuration
211 function smileybutton_settings_post($a,$post) {
214 if($_POST['smileybutton-submit'])
215 set_pconfig(local_user(),'smileybutton','enable',intval($_POST['smileybutton']));
221 * Add configuration-dialog to form
226 function smileybutton_settings(&$a,&$s) {
231 /* Add our stylesheet to the page so we can make our settings look nice */
233 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
235 /* Get the current state of our config variable */
237 $enabled = get_pconfig(local_user(),'smileybutton','enable');
239 $checked = (($enabled) ? ' checked="checked" ' : '');
241 /* Add some HTML to the existing form */
243 $s .= '<div class="settings-block">';
244 $s .= '<h3>Smileybutton settings</h3>';
245 $s .= '<div id="smileybutton-enable-wrapper">';
246 $s .= '<label id="smileybutton-enable-label" for="smileybutton-checkbox">Enable Smileybutton Plugin</label>';
247 $s .= '<input id="smileybutton-checkbox" type="checkbox" name="smileybutton" value="1" ' . $checked . '/>';
248 $s .= '</div><div class="clear"></div>';
250 /* provide a submit button */
252 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="smileybutton-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';