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