source: trunk/forum/includes/acp/acp_icons.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 26.7 KB
Line 
1<?php
2/**
3*
4* @package acp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* @todo [smilies] check regular expressions for special char replacements (stored specialchared in db)
21* @package acp
22*/
23class acp_icons
24{
25 var $u_action;
26
27 function main($id, $mode)
28 {
29 global $db, $user, $auth, $template, $cache;
30 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
31
32 $user->add_lang('acp/posting');
33
34 // Set up general vars
35 $action = request_var('action', '');
36 $action = (isset($_POST['add'])) ? 'add' : $action;
37 $action = (isset($_POST['edit'])) ? 'edit' : $action;
38 $action = (isset($_POST['import'])) ? 'import' : $action;
39 $icon_id = request_var('id', 0);
40
41 $mode = ($mode == 'smilies') ? 'smilies' : 'icons';
42
43 $this->tpl_name = 'acp_icons';
44
45 // What are we working on?
46 switch ($mode)
47 {
48 case 'smilies':
49 $table = SMILIES_TABLE;
50 $lang = 'SMILIES';
51 $fields = 'smiley';
52 $img_path = $config['smilies_path'];
53 break;
54
55 case 'icons':
56 $table = ICONS_TABLE;
57 $lang = 'ICONS';
58 $fields = 'icons';
59 $img_path = $config['icons_path'];
60 break;
61 }
62
63 $this->page_title = 'ACP_' . $lang;
64
65 // Clear some arrays
66 $_images = $_paks = array();
67 $notice = '';
68
69 // Grab file list of paks and images
70 if ($action == 'edit' || $action == 'add' || $action == 'import')
71 {
72 $imglist = filelist($phpbb_root_path . $img_path, '');
73
74 foreach ($imglist as $path => $img_ary)
75 {
76 if (empty($img_ary))
77 {
78 continue;
79 }
80
81 asort($img_ary, SORT_STRING);
82
83 foreach ($img_ary as $img)
84 {
85 $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $path . $img);
86
87 if (!$img_size[0] || !$img_size[1] || strlen($img) > 255)
88 {
89 continue;
90 }
91
92 // adjust the width and height to be lower than 128px while perserving the aspect ratio (for icons)
93 if ($mode == 'icons')
94 {
95 if ($img_size[0] > 127 && $img_size[0] > $img_size[1])
96 {
97 $img_size[1] = (int) ($img_size[1] * (127 / $img_size[0]));
98 $img_size[0] = 127;
99 }
100 else if ($img_size[1] > 127)
101 {
102 $img_size[0] = (int) ($img_size[0] * (127 / $img_size[1]));
103 $img_size[1] = 127;
104 }
105 }
106
107 $_images[$path . $img]['file'] = $path . $img;
108 $_images[$path . $img]['width'] = $img_size[0];
109 $_images[$path . $img]['height'] = $img_size[1];
110 }
111 }
112 unset($imglist);
113
114 if ($dir = @opendir($phpbb_root_path . $img_path))
115 {
116 while (($file = readdir($dir)) !== false)
117 {
118 if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\.pak$#i', $file))
119 {
120 $_paks[] = $file;
121 }
122 }
123 closedir($dir);
124
125 if (!empty($_paks))
126 {
127 asort($_paks, SORT_STRING);
128 }
129 }
130 }
131
132 // What shall we do today? Oops, I believe that's trademarked ...
133 switch ($action)
134 {
135 case 'edit':
136 unset($_images);
137 $_images = array();
138
139 // no break;
140
141 case 'add':
142
143 $smilies = $default_row = array();
144 $smiley_options = $order_list = $add_order_list = '';
145
146 if ($action == 'add' && $mode == 'smilies')
147 {
148 $sql = 'SELECT *
149 FROM ' . SMILIES_TABLE . '
150 ORDER BY smiley_order';
151 $result = $db->sql_query($sql);
152
153 while ($row = $db->sql_fetchrow($result))
154 {
155 if (empty($smilies[$row['smiley_url']]))
156 {
157 $smilies[$row['smiley_url']] = $row;
158 }
159 }
160 $db->sql_freeresult($result);
161
162 if (sizeof($smilies))
163 {
164 foreach ($smilies as $row)
165 {
166 $selected = false;
167
168 if (!$smiley_options)
169 {
170 $selected = true;
171 $default_row = $row;
172 }
173 $smiley_options .= '<option value="' . $row['smiley_url'] . '"' . (($selected) ? ' selected="selected"' : '') . '>' . $row['smiley_url'] . '</option>';
174
175 $template->assign_block_vars('smile', array(
176 'SMILEY_URL' => addslashes($row['smiley_url']),
177 'CODE' => addslashes($row['code']),
178 'EMOTION' => addslashes($row['emotion']),
179 'WIDTH' => $row['smiley_width'],
180 'HEIGHT' => $row['smiley_height'],
181 'ORDER' => $row['smiley_order'] + 1,
182 ));
183 }
184 }
185 }
186
187 $sql = "SELECT *
188 FROM $table
189 ORDER BY {$fields}_order " . (($icon_id || $action == 'add') ? 'DESC' : 'ASC');
190 $result = $db->sql_query($sql);
191
192 $data = array();
193 $after = false;
194 $display = 0;
195 $order_lists = array('', '');
196 $add_order_lists = array('', '');
197 $display_count = 0;
198
199 while ($row = $db->sql_fetchrow($result))
200 {
201 if ($action == 'add')
202 {
203 unset($_images[$row[$fields . '_url']]);
204 }
205
206
207 if ($row[$fields . '_id'] == $icon_id)
208 {
209 $after = true;
210 $display = $row['display_on_posting'];
211 $data[$row[$fields . '_url']] = $row;
212 }
213 else
214 {
215 if ($action == 'edit' && !$icon_id)
216 {
217 $data[$row[$fields . '_url']] = $row;
218 }
219
220 $selected = '';
221 if (!empty($after))
222 {
223 $selected = ' selected="selected"';
224 $after = false;
225 }
226 if ($row['display_on_posting'])
227 {
228 $display_count++;
229 }
230 $after_txt = ($mode == 'smilies') ? $row['code'] : $row['icons_url'];
231 $order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . $selected . '>' . sprintf($user->lang['AFTER_' . $lang], ' -&gt; ' . $after_txt) . '</option>' . $order_lists[$row['display_on_posting']];
232
233 if (!empty($default_row))
234 {
235 $add_order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . (($row[$fields . '_id'] == $default_row['smiley_id']) ? ' selected="selected"' : '') . '>' . sprintf($user->lang['AFTER_' . $lang], ' -&gt; ' . $after_txt) . '</option>' . $add_order_lists[$row['display_on_posting']];
236 }
237 }
238 }
239 $db->sql_freeresult($result);
240
241 $order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>';
242 $add_order_list = '<option value="1">' . $user->lang['FIRST'] . '</option>';
243
244 if ($action == 'add')
245 {
246 $data = $_images;
247 }
248
249 $colspan = (($mode == 'smilies') ? 7 : 5);
250 $colspan += ($icon_id) ? 1 : 0;
251 $colspan += ($action == 'add') ? 2 : 0;
252
253 $template->assign_vars(array(
254 'S_EDIT' => true,
255 'S_SMILIES' => ($mode == 'smilies') ? true : false,
256 'S_ADD' => ($action == 'add') ? true : false,
257
258 'S_ORDER_LIST_DISPLAY' => $order_list . $order_lists[1],
259 'S_ORDER_LIST_UNDISPLAY' => $order_list . $order_lists[0],
260 'S_ORDER_LIST_DISPLAY_COUNT' => $display_count + 1,
261
262 'L_TITLE' => $user->lang['ACP_' . $lang],
263 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'],
264 'L_CONFIG' => $user->lang[$lang . '_CONFIG'],
265 'L_URL' => $user->lang[$lang . '_URL'],
266 'L_LOCATION' => $user->lang[$lang . '_LOCATION'],
267 'L_WIDTH' => $user->lang[$lang . '_WIDTH'],
268 'L_HEIGHT' => $user->lang[$lang . '_HEIGHT'],
269 'L_ORDER' => $user->lang[$lang . '_ORDER'],
270 'L_NO_ICONS' => $user->lang['NO_' . $lang . '_' . strtoupper($action)],
271
272 'COLSPAN' => $colspan,
273 'ID' => $icon_id,
274
275 'U_BACK' => $this->u_action,
276 'U_ACTION' => $this->u_action . '&amp;action=' . (($action == 'add') ? 'create' : 'modify'),
277 ));
278
279 foreach ($data as $img => $img_row)
280 {
281 $template->assign_block_vars('items', array(
282 'IMG' => $img,
283 'A_IMG' => addslashes($img),
284 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $img,
285
286 'CODE' => ($mode == 'smilies' && isset($img_row['code'])) ? $img_row['code'] : '',
287 'EMOTION' => ($mode == 'smilies' && isset($img_row['emotion'])) ? $img_row['emotion'] : '',
288
289 'S_ID' => (isset($img_row[$fields . '_id'])) ? true : false,
290 'ID' => (isset($img_row[$fields . '_id'])) ? $img_row[$fields . '_id'] : 0,
291 'WIDTH' => (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'],
292 'HEIGHT' => (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'],
293 'POSTING_CHECKED' => (!empty($img_row['display_on_posting']) || $action == 'add') ? ' checked="checked"' : '',
294 ));
295 }
296
297 // Ok, another row for adding an addition code for a pre-existing image...
298 if ($action == 'add' && $mode == 'smilies' && sizeof($smilies))
299 {
300 $template->assign_vars(array(
301 'S_ADD_CODE' => true,
302
303 'S_IMG_OPTIONS' => $smiley_options,
304
305 'S_ADD_ORDER_LIST_DISPLAY' => $add_order_list . $add_order_lists[1],
306 'S_ADD_ORDER_LIST_UNDISPLAY' => $add_order_list . $add_order_lists[0],
307
308 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $default_row['smiley_url'],
309 'IMG_PATH' => $img_path,
310 'PHPBB_ROOT_PATH' => $phpbb_root_path,
311
312 'CODE' => $default_row['code'],
313 'EMOTION' => $default_row['emotion'],
314
315 'WIDTH' => $default_row['smiley_width'],
316 'HEIGHT' => $default_row['smiley_height'],
317 ));
318 }
319
320 return;
321
322 break;
323
324 case 'create':
325 case 'modify':
326
327 // Get items to create/modify
328 $images = (isset($_POST['image'])) ? array_keys(request_var('image', array('' => 0))) : array();
329
330 // Now really get the items
331 $image_id = (isset($_POST['id'])) ? request_var('id', array('' => 0)) : array();
332 $image_order = (isset($_POST['order'])) ? request_var('order', array('' => 0)) : array();
333 $image_width = (isset($_POST['width'])) ? request_var('width', array('' => 0)) : array();
334 $image_height = (isset($_POST['height'])) ? request_var('height', array('' => 0)) : array();
335 $image_add = (isset($_POST['add_img'])) ? request_var('add_img', array('' => 0)) : array();
336 $image_emotion = utf8_normalize_nfc(request_var('emotion', array('' => ''), true));
337 $image_code = utf8_normalize_nfc(request_var('code', array('' => ''), true));
338 $image_display_on_posting = (isset($_POST['display_on_posting'])) ? request_var('display_on_posting', array('' => 0)) : array();
339
340 // Ok, add the relevant bits if we are adding new codes to existing emoticons...
341 if (!empty($_POST['add_additional_code']))
342 {
343 $add_image = request_var('add_image', '');
344 $add_code = utf8_normalize_nfc(request_var('add_code', '', true));
345 $add_emotion = utf8_normalize_nfc(request_var('add_emotion', '', true));
346
347 if ($add_image && $add_emotion && $add_code)
348 {
349 $images[] = $add_image;
350 $image_add[$add_image] = true;
351
352 $image_code[$add_image] = $add_code;
353 $image_emotion[$add_image] = $add_emotion;
354 $image_width[$add_image] = request_var('add_width', 0);
355 $image_height[$add_image] = request_var('add_height', 0);
356
357 if (!empty($_POST['add_display_on_posting']))
358 {
359 $image_display_on_posting[$add_image] = 1;
360 }
361
362 $image_order[$add_image] = request_var('add_order', 0);
363 }
364 }
365
366 if ($mode == 'smilies' && $action == 'create')
367 {
368 $smiley_count = $this->item_count($table);
369
370 $addable_smileys_count = sizeof($images);
371 foreach ($images as $image)
372 {
373 if (!isset($image_add[$image]))
374 {
375 --$addable_smileys_count;
376 }
377 }
378
379 if ($smiley_count + $addable_smileys_count > SMILEY_LIMIT)
380 {
381 trigger_error(sprintf($user->lang['TOO_MANY_SMILIES'], SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
382 }
383 }
384
385 $icons_updated = 0;
386 $errors = array();
387 foreach ($images as $image)
388 {
389 if ($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == ''))
390 {
391 $errors[$image] = 'SMILIE_NO_' . (($image_emotion[$image] == '') ? 'EMOTION' : 'CODE');
392 }
393 else if ($action == 'create' && !isset($image_add[$image]))
394 {
395 // skip images where add wasn't checked
396 }
397 else
398 {
399 if ($image_width[$image] == 0 || $image_height[$image] == 0)
400 {
401 $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $image);
402 $image_width[$image] = $img_size[0];
403 $image_height[$image] = $img_size[1];
404 }
405
406 // Adjust image width/height for icons
407 if ($mode == 'icons')
408 {
409 if ($image_width[$image] > 127 && $image_width[$image] > $image_height[$image])
410 {
411 $image_height[$image] = (int) ($image_height[$image] * (127 / $image_width[$image]));
412 $image_width[$image] = 127;
413 }
414 else if ($image_height[$image] > 127)
415 {
416 $image_width[$image] = (int) ($image_width[$image] * (127 / $image_height[$image]));
417 $image_height[$image] = 127;
418 }
419 }
420
421 $img_sql = array(
422 $fields . '_url' => $image,
423 $fields . '_width' => $image_width[$image],
424 $fields . '_height' => $image_height[$image],
425 'display_on_posting' => (isset($image_display_on_posting[$image])) ? 1 : 0,
426 );
427
428 if ($mode == 'smilies')
429 {
430 $img_sql = array_merge($img_sql, array(
431 'emotion' => $image_emotion[$image],
432 'code' => $image_code[$image])
433 );
434 }
435
436 // Image_order holds the 'new' order value
437 if (!empty($image_order[$image]))
438 {
439 $img_sql = array_merge($img_sql, array(
440 $fields . '_order' => $image_order[$image])
441 );
442
443 // Since we always add 'after' an item, we just need to increase all following + the current by one
444 $sql = "UPDATE $table
445 SET {$fields}_order = {$fields}_order + 1
446 WHERE {$fields}_order >= {$image_order[$image]}";
447 $db->sql_query($sql);
448
449 // If we adjust the order, we need to adjust all other orders too - they became inaccurate...
450 foreach ($image_order as $_image => $_order)
451 {
452 if ($_image == $image)
453 {
454 continue;
455 }
456
457 if ($_order >= $image_order[$image])
458 {
459 $image_order[$_image]++;
460 }
461 }
462 }
463
464 if ($action == 'modify' && !empty($image_id[$image]))
465 {
466 $sql = "UPDATE $table
467 SET " . $db->sql_build_array('UPDATE', $img_sql) . "
468 WHERE {$fields}_id = " . $image_id[$image];
469 $db->sql_query($sql);
470 $icons_updated++;
471 }
472 else if ($action !== 'modify')
473 {
474 $sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql);
475 $db->sql_query($sql);
476 $icons_updated++;
477 }
478
479 }
480 }
481
482 $cache->destroy('_icons');
483 $cache->destroy('sql', $table);
484
485 $level = E_USER_NOTICE;
486 switch ($icons_updated)
487 {
488 case 0:
489 $suc_lang = "{$lang}_NONE";
490 $level = E_USER_WARNING;
491 break;
492
493 case 1:
494 $suc_lang = "{$lang}_ONE";
495 break;
496
497 default:
498 $suc_lang = $lang;
499 }
500 $errormsgs = '';
501 foreach ($errors as $img => $error)
502 {
503 $errormsgs .= '<br />' . sprintf($user->lang[$error], $img);
504 }
505 if ($action == 'modify')
506 {
507 trigger_error($user->lang[$suc_lang . '_EDITED'] . $errormsgs . adm_back_link($this->u_action), $level);
508 }
509 else
510 {
511 trigger_error($user->lang[$suc_lang . '_ADDED'] . $errormsgs . adm_back_link($this->u_action), $level);
512 }
513
514 break;
515
516 case 'import':
517
518 $pak = request_var('pak', '');
519 $current = request_var('current', '');
520
521 if ($pak != '')
522 {
523 $order = 0;
524
525 if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak)))
526 {
527 trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
528 }
529
530 // Make sure the pak_ary is valid
531 foreach ($pak_ary as $pak_entry)
532 {
533 if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data))
534 {
535 if ((sizeof($data[1]) != 4 && $mode == 'icons') ||
536 ((sizeof($data[1]) != 6 || (empty($data[1][4]) || empty($data[1][5]))) && $mode == 'smilies' ))
537 {
538 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
539 }
540 }
541 else
542 {
543 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
544 }
545 }
546
547 // The user has already selected a smilies_pak file
548 if ($current == 'delete')
549 {
550 switch ($db->sql_layer)
551 {
552 case 'sqlite':
553 case 'firebird':
554 $db->sql_query('DELETE FROM ' . $table);
555 break;
556
557 default:
558 $db->sql_query('TRUNCATE TABLE ' . $table);
559 break;
560 }
561
562 switch ($mode)
563 {
564 case 'smilies':
565 break;
566
567 case 'icons':
568 // Reset all icon_ids
569 $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0');
570 $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0');
571 break;
572 }
573 }
574 else
575 {
576 $cur_img = array();
577
578 $field_sql = ($mode == 'smilies') ? 'code' : 'icons_url';
579
580 $sql = "SELECT $field_sql
581 FROM $table";
582 $result = $db->sql_query($sql);
583
584 while ($row = $db->sql_fetchrow($result))
585 {
586 ++$order;
587 $cur_img[$row[$field_sql]] = 1;
588 }
589 $db->sql_freeresult($result);
590 }
591
592 if ($mode == 'smilies')
593 {
594 $smiley_count = $this->item_count($table);
595 if ($smiley_count + sizeof($pak_ary) > SMILEY_LIMIT)
596 {
597 trigger_error(sprintf($user->lang['TOO_MANY_SMILIES'], SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
598 }
599 }
600
601 foreach ($pak_ary as $pak_entry)
602 {
603 $data = array();
604 if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data))
605 {
606 if ((sizeof($data[1]) != 4 && $mode == 'icons') ||
607 (sizeof($data[1]) != 6 && $mode == 'smilies'))
608 {
609 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
610 }
611
612 // Stripslash here because it got addslashed before... (on export)
613 $img = stripslashes($data[1][0]);
614 $width = stripslashes($data[1][1]);
615 $height = stripslashes($data[1][2]);
616 $display_on_posting = stripslashes($data[1][3]);
617
618 if (isset($data[1][4]) && isset($data[1][5]))
619 {
620 $emotion = stripslashes($data[1][4]);
621 $code = stripslashes($data[1][5]);
622 }
623
624 if ($current == 'replace' &&
625 (($mode == 'smilies' && !empty($cur_img[$code])) ||
626 ($mode == 'icons' && !empty($cur_img[$img]))))
627 {
628 $replace_sql = ($mode == 'smilies') ? $code : $img;
629 $sql = array(
630 $fields . '_url' => $img,
631 $fields . '_height' => (int) $height,
632 $fields . '_width' => (int) $width,
633 'display_on_posting' => (int) $display_on_posting,
634 );
635
636 if ($mode == 'smilies')
637 {
638 $sql = array_merge($sql, array(
639 'emotion' => $emotion,
640 ));
641 }
642
643 $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql) . "
644 WHERE $field_sql = '" . $db->sql_escape($replace_sql) . "'";
645 $db->sql_query($sql);
646 }
647 else
648 {
649 ++$order;
650
651 $sql = array(
652 $fields . '_url' => $img,
653 $fields . '_height' => (int) $height,
654 $fields . '_width' => (int) $width,
655 $fields . '_order' => (int) $order,
656 'display_on_posting'=> (int) $display_on_posting,
657 );
658
659 if ($mode == 'smilies')
660 {
661 $sql = array_merge($sql, array(
662 'code' => $code,
663 'emotion' => $emotion,
664 ));
665 }
666 $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql));
667 }
668 }
669 }
670
671 $cache->destroy('_icons');
672 $cache->destroy('sql', $table);
673
674 trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action));
675 }
676 else
677 {
678 $pak_options = '';
679
680 foreach ($_paks as $pak)
681 {
682 $pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>';
683 }
684
685 $template->assign_vars(array(
686 'S_CHOOSE_PAK' => true,
687 'S_PAK_OPTIONS' => $pak_options,
688
689 'L_TITLE' => $user->lang['ACP_' . $lang],
690 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'],
691 'L_NO_PAK_OPTIONS' => $user->lang['NO_' . $lang . '_PAK'],
692 'L_CURRENT' => $user->lang['CURRENT_' . $lang],
693 'L_CURRENT_EXPLAIN' => $user->lang['CURRENT_' . $lang . '_EXPLAIN'],
694 'L_IMPORT_SUBMIT' => $user->lang['IMPORT_' . $lang],
695
696 'U_BACK' => $this->u_action,
697 'U_ACTION' => $this->u_action . '&amp;action=import',
698 )
699 );
700 }
701 break;
702
703 case 'export':
704
705 $this->page_title = 'EXPORT_' . $lang;
706 $this->tpl_name = 'message_body';
707
708 $template->assign_vars(array(
709 'MESSAGE_TITLE' => $user->lang['EXPORT_' . $lang],
710 'MESSAGE_TEXT' => sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '<a href="' . $this->u_action . '&amp;action=send">', '</a>'),
711
712 'S_USER_NOTICE' => true,
713 )
714 );
715
716 return;
717
718 break;
719
720 case 'send':
721
722 $sql = "SELECT *
723 FROM $table
724 ORDER BY {$fields}_order";
725 $result = $db->sql_query($sql);
726
727 $pak = '';
728 while ($row = $db->sql_fetchrow($result))
729 {
730 $pak .= "'" . addslashes($row[$fields . '_url']) . "', ";
731 $pak .= "'" . addslashes($row[$fields . '_width']) . "', ";
732 $pak .= "'" . addslashes($row[$fields . '_height']) . "', ";
733 $pak .= "'" . addslashes($row['display_on_posting']) . "', ";
734
735 if ($mode == 'smilies')
736 {
737 $pak .= "'" . addslashes($row['emotion']) . "', ";
738 $pak .= "'" . addslashes($row['code']) . "', ";
739 }
740
741 $pak .= "\n";
742 }
743 $db->sql_freeresult($result);
744
745 if ($pak != '')
746 {
747 garbage_collection();
748
749 header('Pragma: public');
750
751 // Send out the Headers
752 header('Content-Type: text/x-delimtext; name="' . $mode . '.pak"');
753 header('Content-Disposition: inline; filename="' . $mode . '.pak"');
754 echo $pak;
755
756 flush();
757 exit;
758 }
759 else
760 {
761 trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING);
762 }
763
764 break;
765
766 case 'delete':
767
768 if (confirm_box(true))
769 {
770 $sql = "DELETE FROM $table
771 WHERE {$fields}_id = $icon_id";
772 $db->sql_query($sql);
773
774 switch ($mode)
775 {
776 case 'smilies':
777 break;
778
779 case 'icons':
780 // Reset appropriate icon_ids
781 $db->sql_query('UPDATE ' . TOPICS_TABLE . "
782 SET icon_id = 0
783 WHERE icon_id = $icon_id");
784
785 $db->sql_query('UPDATE ' . POSTS_TABLE . "
786 SET icon_id = 0
787 WHERE icon_id = $icon_id");
788 break;
789 }
790
791 $notice = $user->lang[$lang . '_DELETED'];
792
793 $cache->destroy('_icons');
794 $cache->destroy('sql', $table);
795 }
796 else
797 {
798 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
799 'i' => $id,
800 'mode' => $mode,
801 'id' => $icon_id,
802 'action' => 'delete',
803 )));
804 }
805
806 break;
807
808 case 'move_up':
809 case 'move_down':
810
811 // Get current order id...
812 $sql = "SELECT {$fields}_order as current_order
813 FROM $table
814 WHERE {$fields}_id = $icon_id";
815 $result = $db->sql_query($sql);
816 $current_order = (int) $db->sql_fetchfield('current_order');
817 $db->sql_freeresult($result);
818
819 if ($current_order == 0 && $action == 'move_up')
820 {
821 break;
822 }
823
824 // on move_down, switch position with next order_id...
825 // on move_up, switch position with previous order_id...
826 $switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1;
827
828 //
829 $sql = "UPDATE $table
830 SET {$fields}_order = $current_order
831 WHERE {$fields}_order = $switch_order_id
832 AND {$fields}_id <> $icon_id";
833 $db->sql_query($sql);
834
835 // Only update the other entry too if the previous entry got updated
836 if ($db->sql_affectedrows())
837 {
838 $sql = "UPDATE $table
839 SET {$fields}_order = $switch_order_id
840 WHERE {$fields}_order = $current_order
841 AND {$fields}_id = $icon_id";
842 $db->sql_query($sql);
843 }
844
845 $cache->destroy('_icons');
846 $cache->destroy('sql', $table);
847
848 break;
849 }
850
851 // By default, check that image_order is valid and fix it if necessary
852 $sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order
853 FROM $table
854 ORDER BY display_on_posting DESC, {$fields}_order";
855 $result = $db->sql_query($sql);
856
857 if ($row = $db->sql_fetchrow($result))
858 {
859 $order = 0;
860 do
861 {
862 ++$order;
863 if ($row['fields_order'] != $order)
864 {
865 $db->sql_query("UPDATE $table
866 SET {$fields}_order = $order
867 WHERE {$fields}_id = " . $row['order_id']);
868 }
869 }
870 while ($row = $db->sql_fetchrow($result));
871 }
872 $db->sql_freeresult($result);
873
874 $template->assign_vars(array(
875 'L_TITLE' => $user->lang['ACP_' . $lang],
876 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'],
877 'L_IMPORT' => $user->lang['IMPORT_' . $lang],
878 'L_EXPORT' => $user->lang['EXPORT_' . $lang],
879 'L_NOT_DISPLAYED' => $user->lang[$lang . '_NOT_DISPLAYED'],
880 'L_ICON_ADD' => $user->lang['ADD_' . $lang],
881 'L_ICON_EDIT' => $user->lang['EDIT_' . $lang],
882
883 'NOTICE' => $notice,
884 'COLSPAN' => ($mode == 'smilies') ? 5 : 3,
885
886 'S_SMILIES' => ($mode == 'smilies') ? true : false,
887
888 'U_ACTION' => $this->u_action,
889 'U_IMPORT' => $this->u_action . '&amp;action=import',
890 'U_EXPORT' => $this->u_action . '&amp;action=export',
891 )
892 );
893
894 $spacer = false;
895 $pagination_start = request_var('start', 0);
896
897 $item_count = $this->item_count($table);
898
899 $sql = "SELECT *
900 FROM $table
901 ORDER BY {$fields}_order ASC";
902 $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $pagination_start);
903
904 while ($row = $db->sql_fetchrow($result))
905 {
906 $alt_text = ($mode == 'smilies') ? $row['code'] : '';
907
908 $template->assign_block_vars('items', array(
909 'S_SPACER' => (!$spacer && !$row['display_on_posting']) ? true : false,
910 'ALT_TEXT' => $alt_text,
911 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'],
912 'WIDTH' => $row[$fields . '_width'],
913 'HEIGHT' => $row[$fields . '_height'],
914 'CODE' => (isset($row['code'])) ? $row['code'] : '',
915 'EMOTION' => (isset($row['emotion'])) ? $row['emotion'] : '',
916 'U_EDIT' => $this->u_action . '&amp;action=edit&amp;id=' . $row[$fields . '_id'],
917 'U_DELETE' => $this->u_action . '&amp;action=delete&amp;id=' . $row[$fields . '_id'],
918 'U_MOVE_UP' => $this->u_action . '&amp;action=move_up&amp;id=' . $row[$fields . '_id'] . '&amp;start=' . $pagination_start,
919 'U_MOVE_DOWN' => $this->u_action . '&amp;action=move_down&amp;id=' . $row[$fields . '_id'] . '&amp;start=' . $pagination_start,
920 ));
921
922 if (!$spacer && !$row['display_on_posting'])
923 {
924 $spacer = true;
925 }
926 }
927 $db->sql_freeresult($result);
928
929 $template->assign_var('PAGINATION',
930 generate_pagination($this->u_action, $item_count, $config['smilies_per_page'], $pagination_start, true)
931 );
932 }
933
934 /**
935 * Returns the count of smilies or icons in the database
936 *
937 * @param string $table The table of items to count.
938 * @return int number of items
939 */
940 /* private */ function item_count($table)
941 {
942 global $db;
943
944 $sql = "SELECT COUNT(*) AS item_count
945 FROM $table";
946 $result = $db->sql_query($sql);
947 $item_count = (int) $db->sql_fetchfield('item_count');
948 $db->sql_freeresult($result);
949
950 return $item_count;
951 }
952}
953
954?>
Note: See TracBrowser for help on using the repository browser.