]> git.mxchange.org Git - friendica-addons.git/blob - smileybutton/smileybutton.php
Add Smileybutton Plugin
[friendica-addons.git] / smileybutton / smileybutton.php
1 <?php
2 /**
3  * Name: Smileybutton
4  * Description: Adds an smileybutton to the Inputbox
5  * Version: 0.1
6  * Author: Johannes Schwab <johannes_schwab@gmx.de>
7  */
8
9
10 function smileybutton_install() {
11
12         /**
13          * 
14          * Register hooks for jot_tool and plugin_settings
15          *
16          */
17
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');
21  
22         logger("installed smileybutton");
23 }
24
25
26 function smileybutton_uninstall() {
27
28         /**
29          *
30          * Delet registered hooks
31          *
32          */
33
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');
37          
38         logger("removed smileybutton");
39 }
40
41
42
43 function show_button($a, &$b) {
44
45         /**
46          *
47          * Check if it is a local user and he has enabled smileybutton
48          *
49          */
50
51         if(! local_user())
52                 return;
53
54         $active = get_pconfig(local_user(), 'smileybutton', 'enable');
55
56         if(! $active)
57                 return;
58
59         /**
60          *
61          * Prepare the Smilie-Arrays
62          *
63          */
64
65         /**
66          *
67          * I have copied this from /include/text.php and removed dobles
68          *
69          */
70
71         $texts =  array( 
72                 '&lt;3', 
73                 '&lt;/3', 
74                 ':-)', 
75                 ';-)', 
76                 ':-(', 
77                 ':-P', 
78                 ':-X', 
79                 ':-D', 
80                 ':-O', 
81                 '\\\\o/', 
82                 'O_o', 
83                 ":\'(", 
84                 ":-!", 
85                 ":-/", 
86                 ":-[", 
87                 "8-)",
88                 ':beer', 
89                 ':coffee', 
90                 ':facepalm',
91                 ':like',
92                 ':dislike',
93                 '~friendica',
94                 'red#'
95
96         );
97
98         $icons = array(
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" />'
122         );
123         
124         /**
125          * 
126          * Call hooks to get aditional smileies from other addons
127          *
128          */
129
130         $params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed
131         call_hooks('smiley', $params);
132
133
134         /**
135          *
136          * Generate html for smileylist
137          *
138          */
139
140         $s = "\t";
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);
144                 $s .= $icon . ' ';
145                 if ($x != 0 && $x % 10 == 0) {
146                         $s .= "<br />\n\t";
147                 }
148         }
149
150         /**
151          *
152          * Add the button to the Inputbox
153          *
154          */     
155
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";
158         $b .= "\t</div>\n";
159  
160         /**
161          *
162          * Write the smileies to an hidden div
163          *
164          */
165
166         $b .= "\t<div id=\"smileybutton\" style=\"display:none;\">\n";
167         $b .= $s . "\n"; 
168         $b .= "</div>\n";
169
170         /**
171          *
172          * Function to show and hide the smiley-list in the hidden div
173          *
174          */
175
176         $b .= "<script>\n"; 
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";
182         $b .= " } else {\n";
183         $b .= "         $(\"#smileybutton\").hide();\n";
184         $b .= "         smileybutton_show = 0;\n";
185         $b .= " }}\n";
186
187         /**
188          *
189          * Function to add the chosen smiley to the inputbox
190          *
191          */
192
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";
197         $b .= " }\n";
198         $b .= "</script>\n";
199 }
200
201
202
203
204
205 /**
206  *
207  * Set the configuration
208  *
209  */
210
211 function smileybutton_settings_post($a,$post) {
212         if(! local_user())
213                 return;
214         if($_POST['smileybutton-submit'])
215                 set_pconfig(local_user(),'smileybutton','enable',intval($_POST['smileybutton']));
216 }
217
218
219 /**
220  *
221  * Add configuration-dialog to form
222  *
223  */
224
225
226 function smileybutton_settings(&$a,&$s) {
227
228         if(! local_user())
229                 return;
230
231         /* Add our stylesheet to the page so we can make our settings look nice */
232
233         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
234
235         /* Get the current state of our config variable */
236
237         $enabled = get_pconfig(local_user(),'smileybutton','enable');
238
239         $checked = (($enabled) ? ' checked="checked" ' : '');
240
241         /* Add some HTML to the existing form */
242
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>';
249
250         /* provide a submit button */
251
252         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="smileybutton-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
253
254 }