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