]> git.mxchange.org Git - friendica-addons.git/blob - smileybutton/smileybutton.php
wording submit -> save settings
[friendica-addons.git] / smileybutton / smileybutton.php
1 <?php
2 /**
3  * Name: Smileybutton
4  * Description: Adds a smileybutton to the Inputbox
5  * Version: 0.1
6  * Author: Johannes Schwab <http://friendica.jschwab.mooo.com/profile/ddorian>
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                 $nobutton = false;
53         } else {
54                 $nobutton = get_pconfig(local_user(), 'smileybutton', 'nobutton');
55         }
56
57         /**
58          *
59          * Prepare the Smilie-Arrays
60          *
61          */
62
63         /**
64          *
65          * I have copied this from /include/text.php, removed dobles
66          * and some escapes.
67          *
68          */
69
70         $texts =  array( 
71                 '&lt;3', 
72                 '&lt;/3', 
73                 ':-)', 
74                 ';-)', 
75                 ':-(', 
76                 ':-P', 
77                 ':-X', 
78                 ':-D', 
79                 ':-O', 
80                 '\\\\o/', 
81                 'O_o', 
82                 ":\'(", 
83                 ":-!", 
84                 ":-/", 
85                 ":-[", 
86                 "8-)",
87                 ':beer', 
88                 ':coffee', 
89                 ':facepalm',
90                 ':like',
91                 ':dislike',
92                 '~friendica',
93                 'red#'
94
95         );
96
97         $icons = array(
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" />'
121         );
122         
123         /**
124          * 
125          * Call hooks to get aditional smileies from other addons
126          *
127          */
128
129         $params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed
130         call_hooks('smilie', $params);
131
132         /**
133          *
134          * Generate html for smileylist
135          *
136          */
137
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>";
146                 }
147         }
148         $s .= "\t</tr></table>\n";
149
150         /**
151          *
152          * Add css to page
153          *
154          */     
155
156         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
157
158         /**
159          *
160          * Add the button to the Inputbox
161          *
162          */     
163         if (! $nobutton) {
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";
166                 $b .= "\t</div>\n";
167         }
168
169  
170         /**
171          *
172          * Write the smileies to an (hidden) div
173          *
174          */
175
176         if ($nobutton) {
177                 $b .= "\t<div id=\"smileybutton\">\n";
178         } else {
179                 $b .= "\t<div id=\"smileybutton\" style=\"display:none;\">\n";
180         }
181         $b .= $s . "\n"; 
182         $b .= "</div>\n";
183
184         /**
185          *
186          * Function to show and hide the smiley-list in the hidden div
187          *
188          */
189
190         $b .= "<script>\n"; 
191
192         if (! $nobutton) {
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";
198                 $b .= " } else {\n";
199                 $b .= "         $(\"#smileybutton\").hide();\n";
200                 $b .= "         smileybutton_show = 0;\n";
201                 $b .= " }}\n";
202         } 
203
204         /**
205          *
206          * Function to add the chosen smiley to the inputbox
207          *
208          */
209
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";
216         $b .= "         } else {\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";
221         $b .= "         }\n";
222         $b .= " }\n";
223         $b .= "</script>\n";
224 }
225
226
227
228
229
230 /**
231  *
232  * Set the configuration
233  *
234  */
235
236 function smileybutton_settings_post($a,$post) {
237         if(! local_user())
238                 return;
239         if($_POST['smileybutton-submit'])
240                 set_pconfig(local_user(),'smileybutton','nobutton',intval($_POST['smileybutton']));
241
242 }
243
244
245 /**
246  *
247  * Add configuration-dialog to form
248  *
249  */
250
251
252 function smileybutton_settings(&$a,&$s) {
253
254         if(! local_user())
255                 return;
256
257         /* Add our stylesheet to the page so we can make our settings look nice */
258
259         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
260
261         /* Get the current state of our config variable */
262
263         $nobutton = get_pconfig(local_user(),'smileybutton','nobutton');
264         $checked = (($nobutton) ? ' checked="checked" ' : '');
265
266         /* Add some HTML to the existing form */
267
268         $s .= '<div class="settings-block">';
269         $s .= '<h3>Smileybutton settings</h3>';
270         $s .= '<div id="smileybutton-enable-wrapper">';
271
272         $s .= 'You can hide the button and show the smilies directly.<br /><br />';
273
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 . '/>';
276
277         $s .= '</div><div class="clear"></div>';
278
279         /* provide a submit button */
280
281         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="smileybutton-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
282
283 }