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