1 | <?php |
---|
2 | /*********************************************************************** |
---|
3 | |
---|
4 | Copyright (C) 2005 Vincent Garnier (vin100@forx.fr) |
---|
5 | |
---|
6 | This software is free software; you can redistribute it and/or modify it |
---|
7 | under the terms of the GNU General Public License as published |
---|
8 | by the Free Software Foundation; either version 2 of the License, |
---|
9 | or (at your option) any later version. |
---|
10 | |
---|
11 | This software is distributed in the hope that it will be useful, but |
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software |
---|
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
19 | MA 02111-1307 USA |
---|
20 | |
---|
21 | ************************************************************************/ |
---|
22 | |
---|
23 | |
---|
24 | /************************************************************************\ |
---|
25 | Configuration des limites / Limits configuration |
---|
26 | \************************************************************************/ |
---|
27 | |
---|
28 | $smilies_config_image_size = 10240; // max upload image size in bytes |
---|
29 | $smilies_config_image_width = 20; // max upload image width in pixels |
---|
30 | $smilies_config_image_height = 20; // max upload image height in pixels |
---|
31 | |
---|
32 | |
---|
33 | /************************************************************************\ |
---|
34 | Ne pas modifier ci-dessous / Do not edit bellow |
---|
35 | \************************************************************************/ |
---|
36 | |
---|
37 | // Make sure no one attempts to run this script "directly" |
---|
38 | if (!defined('PUN')) |
---|
39 | exit; |
---|
40 | |
---|
41 | // Tell admin_loader.php that this is indeed a plugin and that it is loaded |
---|
42 | define('PUN_PLUGIN_LOADED', 1); |
---|
43 | define('PLUGIN_VERSION', '1.0'); |
---|
44 | define('PLUGIN_URL', 'admin_loader.php?plugin=AP_Smilies.php'); |
---|
45 | |
---|
46 | // Load the smilies language files |
---|
47 | require PUN_ROOT.'lang/'.$pun_user['language'].'/smilies.php'; |
---|
48 | |
---|
49 | // Display the smiley set |
---|
50 | @include_once PUN_ROOT.'cache/cache_smilies.php'; |
---|
51 | if (!defined('PUN_CACHE_SMILEY')) |
---|
52 | { |
---|
53 | require_once PUN_ROOT.'include/cache_smilies.php'; |
---|
54 | generate_smiley_cache(); |
---|
55 | require PUN_ROOT.'cache/cache_smilies.php'; |
---|
56 | } |
---|
57 | |
---|
58 | // Changer les positions |
---|
59 | if (isset($_POST['reord'])) |
---|
60 | { |
---|
61 | $smilies_order = $_POST['smilies_order']; |
---|
62 | |
---|
63 | $result = $db->query('SELECT id FROM '.$db->prefix.'smilies ORDER BY disp_position') or error('Unable to retrieve smilies', __FILE__, __LINE__, $db->error()); |
---|
64 | |
---|
65 | while ($db_smilies = $db->fetch_assoc($result)) |
---|
66 | { |
---|
67 | if (!preg_match('#^\d+$#', $smilies_order[$db_smilies['id']])) |
---|
68 | message($lang_smiley['Must int']); |
---|
69 | |
---|
70 | $db->query('UPDATE '.$db->prefix.'smilies SET disp_position='.$smilies_order[$db_smilies['id']].' WHERE id='.$db_smilies['id']) or error('Unable to change smilies positions', __FILE__, __LINE__, $db->error()); |
---|
71 | } |
---|
72 | |
---|
73 | require_once PUN_ROOT.'include/cache_smilies.php'; |
---|
74 | generate_smiley_cache(); |
---|
75 | |
---|
76 | redirect(PLUGIN_URL, $lang_smiley['Positions changed']); |
---|
77 | } |
---|
78 | |
---|
79 | // Retirer des smileys |
---|
80 | elseif (isset($_POST['remove'])) |
---|
81 | { |
---|
82 | $rem_smilies = array_map('trim', $_POST['rem_smilies']); |
---|
83 | |
---|
84 | foreach (array_keys($rem_smilies) as $id) |
---|
85 | $db->query('DELETE FROM '.$db->prefix."smilies WHERE id = '".$id."'") or error('Unable to delete smiley', __FILE__, __LINE__, $db->error()); |
---|
86 | |
---|
87 | require_once PUN_ROOT.'include/cache_smilies.php'; |
---|
88 | generate_smiley_cache(); |
---|
89 | |
---|
90 | redirect(PLUGIN_URL, $lang_smiley['Delete Smiley Redirect']); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | // Supprimer des images |
---|
95 | elseif (isset($_POST['delete'])) |
---|
96 | { |
---|
97 | $del_smilies = array_map('trim', $_POST['del_smilies']); |
---|
98 | |
---|
99 | $to_delete = array(); |
---|
100 | $images_affected = array(); |
---|
101 | $not_deleted = array(); |
---|
102 | |
---|
103 | foreach (array_keys($del_smilies) as $img) |
---|
104 | { |
---|
105 | if (!in_array($img, $smiley_img)) |
---|
106 | $to_delete[] = $img; |
---|
107 | else |
---|
108 | $images_affected[] = $img; |
---|
109 | } |
---|
110 | |
---|
111 | if (!empty($images_affected)) |
---|
112 | message(sprintf($lang_smiley['Images affected'], implode(', ', $images_affected))); |
---|
113 | |
---|
114 | else { |
---|
115 | foreach ($to_delete as $img) |
---|
116 | { |
---|
117 | if (!@unlink(PUN_ROOT.'img/smilies/'.$img)) |
---|
118 | $not_deleted[] = $img; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | if (!empty($not_deleted)) |
---|
123 | $message = sprintf($lang_smiley['Images not deleted'], implode(', ', $not_deleted)); |
---|
124 | else |
---|
125 | $message = $lang_smiley['Images deleted']; |
---|
126 | |
---|
127 | redirect(PLUGIN_URL, $message); |
---|
128 | } |
---|
129 | |
---|
130 | // Ajouter une image |
---|
131 | elseif (isset($_POST['add_image'])) |
---|
132 | { |
---|
133 | if (!isset($_FILES['req_file'])) |
---|
134 | message($lang_smiley['No file']); |
---|
135 | |
---|
136 | $uploaded_file = $_FILES['req_file']; |
---|
137 | |
---|
138 | // Make sure the upload went smooth |
---|
139 | if (isset($uploaded_file['error'])) |
---|
140 | { |
---|
141 | switch ($uploaded_file['error']) |
---|
142 | { |
---|
143 | case 1: // UPLOAD_ERR_INI_SIZE |
---|
144 | case 2: // UPLOAD_ERR_FORM_SIZE |
---|
145 | message($lang_smiley['Too large ini']); |
---|
146 | break; |
---|
147 | |
---|
148 | case 3: // UPLOAD_ERR_PARTIAL |
---|
149 | message($lang_smiley['Partial upload']); |
---|
150 | break; |
---|
151 | |
---|
152 | case 4: // UPLOAD_ERR_NO_FILE |
---|
153 | message($lang_smiley['No file']); |
---|
154 | break; |
---|
155 | |
---|
156 | case 6: // UPLOAD_ERR_NO_TMP_DIR |
---|
157 | message($lang_smiley['No tmp directory']); |
---|
158 | break; |
---|
159 | |
---|
160 | default: |
---|
161 | // No error occured, but was something actually uploaded? |
---|
162 | if ($uploaded_file['size'] == 0) |
---|
163 | message($lang_smiley['No file']); |
---|
164 | break; |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | if (is_uploaded_file($uploaded_file['tmp_name'])) |
---|
169 | { |
---|
170 | $filename = substr($uploaded_file['name'], 0, strpos($uploaded_file['name'], '.')); |
---|
171 | |
---|
172 | $allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'); |
---|
173 | if (!in_array($uploaded_file['type'], $allowed_types)) |
---|
174 | message($lang_smiley['Bad type']); |
---|
175 | |
---|
176 | // Make sure the file isn't too big |
---|
177 | if ($uploaded_file['size'] > $smilies_config_image_size) |
---|
178 | message($lang_smiley['Too large'].' '.$smilies_config_image_size.' '.$lang_smiley['bytes'].'.'); |
---|
179 | |
---|
180 | // Determine type |
---|
181 | $extensions = null; |
---|
182 | if ($uploaded_file['type'] == 'image/gif') |
---|
183 | $extensions = array('.gif', '.jpg', '.png'); |
---|
184 | else if ($uploaded_file['type'] == 'image/jpeg' || $uploaded_file['type'] == 'image/pjpeg') |
---|
185 | $extensions = array('.jpg', '.gif', '.png'); |
---|
186 | else |
---|
187 | $extensions = array('.png', '.gif', '.jpg'); |
---|
188 | |
---|
189 | // Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions. |
---|
190 | if (!@move_uploaded_file($uploaded_file['tmp_name'], PUN_ROOT.'img/smilies/'.$filename.'.tmp')) |
---|
191 | message($lang_smiley['Move failed']); |
---|
192 | |
---|
193 | // Now check the width/height |
---|
194 | list($width, $height, $type,) = getimagesize(PUN_ROOT.'img/smilies/'.$filename.'.tmp'); |
---|
195 | if (empty($width) || empty($height) || $width > $smilies_config_image_width || $height > $smilies_config_image_height) |
---|
196 | { |
---|
197 | @unlink(PUN_ROOT.'img/smilies/'.$filename.'.tmp'); |
---|
198 | message($lang_smiley['Too wide or high'].' '.$smilies_config_image_width.'x'.$smilies_config_image_height.' '.$lang_profile['pixels'].'.'); |
---|
199 | } |
---|
200 | else if ($type == 1 && $uploaded_file['type'] != 'image/gif') // Prevent dodgy uploads |
---|
201 | { |
---|
202 | @unlink(PUN_ROOT.'img/smilies/'.$filename.'.tmp'); |
---|
203 | message($lang_smiley['Bad type']); |
---|
204 | } |
---|
205 | |
---|
206 | // Delete any old avatars and put the new one in place |
---|
207 | @unlink(PUN_ROOT.'img/smilies/'.$filename.$extensions[0]); |
---|
208 | @unlink(PUN_ROOT.'img/smilies/'.$filename.$extensions[1]); |
---|
209 | @unlink(PUN_ROOT.'img/smilies/'.$filename.$extensions[2]); |
---|
210 | @rename(PUN_ROOT.'img/smilies/'.$filename.'.tmp', PUN_ROOT.'img/smilies/'.$filename.$extensions[0]); |
---|
211 | @chmod(PUN_ROOT.'img/smilies/'.$filename.$extensions[0], 0644); |
---|
212 | } |
---|
213 | else |
---|
214 | message($lang_smiley['Unknown failure']); |
---|
215 | |
---|
216 | redirect(PLUGIN_URL, $lang_smiley['Successful Upload']); |
---|
217 | } |
---|
218 | |
---|
219 | // Ajouter un smiley à la liste |
---|
220 | elseif (isset($_POST['add_smiley'])) |
---|
221 | { |
---|
222 | $smiley_code = trim($_POST['smiley_code']); |
---|
223 | $smiley_image = trim($_POST['smiley_image']); |
---|
224 | |
---|
225 | if ($smiley_code == '') |
---|
226 | message($lang_smiley['Create Smiley Code None']); |
---|
227 | |
---|
228 | if ($smiley_image == '') |
---|
229 | message($lang_smiley['Create Smiley Image None']); |
---|
230 | |
---|
231 | if (in_array($smiley_code, $smiley_text)) |
---|
232 | message($lang_smiley['Code already exists']); |
---|
233 | |
---|
234 | $db->query('INSERT INTO '.$db->prefix."smilies (image, text) VALUES ('".$smiley_image."', '".$db->escape($smiley_code)."')") or error('Unable to add smiley', __FILE__, __LINE__, $db->error()); |
---|
235 | |
---|
236 | require_once PUN_ROOT.'include/cache_smilies.php'; |
---|
237 | generate_smiley_cache(); |
---|
238 | |
---|
239 | redirect(PLUGIN_URL, $lang_smiley['Successful Creation']); |
---|
240 | } |
---|
241 | |
---|
242 | // Affichage |
---|
243 | else { |
---|
244 | |
---|
245 | // Display the admin navigation menu |
---|
246 | generate_admin_menu($plugin); |
---|
247 | |
---|
248 | ?> |
---|
249 | <div class="block"> |
---|
250 | <h2><span>Plugin Smilies v.<?php echo PLUGIN_VERSION; ?></span></h2> |
---|
251 | <div class="box"> |
---|
252 | <div class="inbox"> |
---|
253 | <p><?php echo $lang_smiley['Description'] ?></p> |
---|
254 | </div> |
---|
255 | </div> |
---|
256 | </div> |
---|
257 | |
---|
258 | <div class="blockform"> |
---|
259 | |
---|
260 | <h2 class="block2"><span><?php echo $lang_smiley['Current Smilies'] ?></span></h2> |
---|
261 | <div class="box"> |
---|
262 | <?php |
---|
263 | $result = $db->query('SELECT * FROM '.$db->prefix.'smilies ORDER BY disp_position') or error('Unable to retrieve smilies', __FILE__, __LINE__, $db->error()); |
---|
264 | |
---|
265 | $num_db_smilies = $db->num_rows($result); |
---|
266 | |
---|
267 | if ($num_db_smilies > 0) : ?> |
---|
268 | <form method="post" action="<?php echo PLUGIN_URL; ?>"> |
---|
269 | <div class="inform"> |
---|
270 | <fieldset> |
---|
271 | <legend><?php echo $lang_smiley['List Current Smilies'] ?></legend> |
---|
272 | <div class="infldset"> |
---|
273 | <table> |
---|
274 | <thead> |
---|
275 | <tr> |
---|
276 | <th scope="row"><?php echo $lang_smiley['Position']; ?></th> |
---|
277 | <th scope="row"><?php echo $lang_smiley['Image Filename']; ?></th> |
---|
278 | <th scope="row"><?php echo $lang_smiley['Code']; ?></th> |
---|
279 | <th scope="row"><?php echo $lang_smiley['Image']; ?></th> |
---|
280 | <th scope="row"><?php echo $lang_smiley['Remove']; ?></th> |
---|
281 | </tr> |
---|
282 | </thead> |
---|
283 | <tbody> |
---|
284 | <?php while ($db_smilies = $db->fetch_assoc($result)) : ?> |
---|
285 | <tr> |
---|
286 | <td><input type="text" name="smilies_order[<?php echo $db_smilies['id']; ?>]" value="<?php echo $db_smilies['disp_position']; ?>" size="3" maxlength="3" /></td> |
---|
287 | <td><?php echo $db_smilies['image']; ?></td> |
---|
288 | <td><?php echo $db_smilies['text']; ?></td> |
---|
289 | <td><img src="img/smilies/<?php echo $db_smilies['image']; ?>" alt="<?php echo $db_smilies['text']; ?>" /></td> |
---|
290 | <td><input name="rem_smilies[<?php echo $db_smilies['id']; ?>]" type="checkbox" value="1" /></td> |
---|
291 | </tr> |
---|
292 | <?php endwhile; ?> |
---|
293 | </tbody> |
---|
294 | </table> |
---|
295 | </div> |
---|
296 | </fieldset> |
---|
297 | </div> |
---|
298 | <p class="submitend"><input name="reord" type="submit" value="<?php echo $lang_smiley['Change position']; ?>" /> <input name="remove" type="submit" value="<?php echo $lang_smiley['Remove Selected']; ?>" /></p> |
---|
299 | </form> |
---|
300 | <?php else : ?> |
---|
301 | <div class="fakeform"> |
---|
302 | <div class="inbox"> |
---|
303 | <p><?php echo $lang_smiley['No smiley']; ?></p> |
---|
304 | </div> |
---|
305 | </div> |
---|
306 | <?php endif; ?> |
---|
307 | |
---|
308 | <form method="post" action="<?php echo PLUGIN_URL; ?>"> |
---|
309 | <div class="inform"> |
---|
310 | <fieldset> |
---|
311 | <legend><?php echo $lang_smiley['Submit New Smiley'] ?></legend> |
---|
312 | <div class="infldset"> |
---|
313 | <table class="aligntop" cellspacing="0"> |
---|
314 | <tr> |
---|
315 | <th scope="row"><?php echo $lang_smiley['Smiley Code'] ?></th> |
---|
316 | <td> |
---|
317 | <input type="text" name="smiley_code" size="25" tabindex="1" /> |
---|
318 | <span><?php echo $lang_smiley['Smiley Code Description'] ?></span> |
---|
319 | </td> |
---|
320 | </tr> |
---|
321 | <tr> |
---|
322 | <th scope="row"><?php echo $lang_smiley['Smiley Image'] ?></th> |
---|
323 | <td> |
---|
324 | <input type="text" name="smiley_image" size="25" tabindex="1" /> |
---|
325 | <span><?php echo $lang_smiley['Smiley Image Description'] ?></span> |
---|
326 | </td> |
---|
327 | </tr> |
---|
328 | </table> |
---|
329 | </div> |
---|
330 | </fieldset> |
---|
331 | </div> |
---|
332 | <p class="submitend"><input type="submit" name="add_smiley" value="<?php echo $lang_smiley['Submit Smiley'] ?>" /></p> |
---|
333 | </form> |
---|
334 | </div> |
---|
335 | |
---|
336 | <h2 class="block2"><span>Liste des images actuellement disponibles</span></h2> |
---|
337 | <div class="box"> |
---|
338 | <form method="post" action="<?php echo PLUGIN_URL; ?>"> |
---|
339 | <div class="inform"> |
---|
340 | <fieldset> |
---|
341 | <legend><?php echo $lang_smiley['List Images Smilies'] ?></legend> |
---|
342 | <div class="infldset"> |
---|
343 | <?php |
---|
344 | $img_smilies = array(); |
---|
345 | $d = dir(PUN_ROOT.'img/smilies'); |
---|
346 | while (($entry = $d->read()) !== false) |
---|
347 | { |
---|
348 | if ($entry != '.' && $entry != '..' && $entry != 'index.html') |
---|
349 | $img_smilies[] = $entry; |
---|
350 | } |
---|
351 | $d->close(); |
---|
352 | @natsort($img_smilies); |
---|
353 | ?> |
---|
354 | <table> |
---|
355 | <thead> |
---|
356 | <tr> |
---|
357 | <th scope="row"><?php echo $lang_smiley['Image Filename']; ?></th> |
---|
358 | <th scope="row"><?php echo $lang_smiley['Image']; ?></th> |
---|
359 | <th scope="row"><?php echo $lang_smiley['Delete']; ?></th> |
---|
360 | </tr> |
---|
361 | </thead> |
---|
362 | <tbody> |
---|
363 | <?php |
---|
364 | $i = 0; |
---|
365 | foreach ($img_smilies as $img) : |
---|
366 | ?> |
---|
367 | <tr> |
---|
368 | <td><?php echo $img; ?></td> |
---|
369 | <td><img src="img/smilies/<?php echo $img; ?>" alt="" /></td> |
---|
370 | <td><input name="del_smilies[<?php echo $img; ?>]" type="checkbox" value="1" /></td> |
---|
371 | </tr> |
---|
372 | <?php |
---|
373 | $i++; |
---|
374 | endforeach; |
---|
375 | ?> |
---|
376 | </tbody> |
---|
377 | </table> |
---|
378 | </div> |
---|
379 | </fieldset> |
---|
380 | </div> |
---|
381 | <p class="submitend"><input name="delete" type="submit" value="<?php echo $lang_smiley['Delete Selected']; ?>" /></p> |
---|
382 | </form> |
---|
383 | |
---|
384 | <form method="post" enctype="multipart/form-data" action="<?php echo PLUGIN_URL; ?>"> |
---|
385 | <div class="inform"> |
---|
386 | <fieldset> |
---|
387 | <legend><?php echo $lang_smiley['Add Images Smilies'] ?></legend> |
---|
388 | <div class="infldset"> |
---|
389 | <label><?php echo $lang_smiley['Images file'] ?><br /><input name="req_file" type="file" size="40" /><br /></label> |
---|
390 | </div> |
---|
391 | </fieldset> |
---|
392 | </div> |
---|
393 | <p class="submitend"><input name="add_image" type="submit" value="<?php echo $lang_smiley['Upload']; ?>" /></p> |
---|
394 | </form> |
---|
395 | |
---|
396 | </div> |
---|
397 | </div> |
---|
398 | |
---|
399 | |
---|
400 | <?php |
---|
401 | |
---|
402 | } |
---|