[ Index ] |
PHP Cross Reference of phpBB-3.1.12-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, $auth, $template, $cache; 32 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; 33 global $request, $phpbb_container; 34 35 $user->add_lang('acp/posting'); 36 37 // Set up general vars 38 $action = request_var('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_var('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 (sizeof($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 $display = 0; 202 $order_lists = array('', ''); 203 $add_order_lists = array('', ''); 204 $display_count = 0; 205 206 while ($row = $db->sql_fetchrow($result)) 207 { 208 if ($action == 'add') 209 { 210 unset($_images[$row[$fields . '_url']]); 211 } 212 213 if ($row[$fields . '_id'] == $icon_id) 214 { 215 $after = true; 216 $display = $row['display_on_posting']; 217 $data[$row[$fields . '_url']] = $row; 218 } 219 else 220 { 221 if ($action == 'edit' && !$icon_id) 222 { 223 $data[$row[$fields . '_url']] = $row; 224 } 225 226 $selected = ''; 227 if (!empty($after)) 228 { 229 $selected = ' selected="selected"'; 230 $after = false; 231 } 232 if ($row['display_on_posting']) 233 { 234 $display_count++; 235 } 236 $after_txt = ($mode == 'smilies') ? $row['code'] : $row['icons_url']; 237 $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']]; 238 239 if (!empty($default_row)) 240 { 241 $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']]; 242 } 243 } 244 } 245 $db->sql_freeresult($result); 246 247 $order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>'; 248 $add_order_list = '<option value="1">' . $user->lang['FIRST'] . '</option>'; 249 250 if ($action == 'add') 251 { 252 $data = $_images; 253 } 254 255 $colspan = (($mode == 'smilies') ? 7 : 5); 256 $colspan += ($icon_id) ? 1 : 0; 257 $colspan += ($action == 'add') ? 2 : 0; 258 259 $template->assign_vars(array( 260 'S_EDIT' => true, 261 'S_SMILIES' => ($mode == 'smilies') ? true : false, 262 'S_ADD' => ($action == 'add') ? true : false, 263 264 'S_ORDER_LIST_DISPLAY' => $order_list . $order_lists[1], 265 'S_ORDER_LIST_UNDISPLAY' => $order_list . $order_lists[0], 266 'S_ORDER_LIST_DISPLAY_COUNT' => $display_count + 1, 267 268 'L_TITLE' => $user->lang['ACP_' . $lang], 269 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 270 'L_CONFIG' => $user->lang[$lang . '_CONFIG'], 271 'L_URL' => $user->lang[$lang . '_URL'], 272 'L_LOCATION' => $user->lang[$lang . '_LOCATION'], 273 'L_WIDTH' => $user->lang[$lang . '_WIDTH'], 274 'L_HEIGHT' => $user->lang[$lang . '_HEIGHT'], 275 'L_ORDER' => $user->lang[$lang . '_ORDER'], 276 'L_NO_ICONS' => $user->lang['NO_' . $lang . '_' . strtoupper($action)], 277 278 'COLSPAN' => $colspan, 279 'ID' => $icon_id, 280 281 'U_BACK' => $this->u_action, 282 'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify'), 283 )); 284 285 foreach ($data as $img => $img_row) 286 { 287 $template->assign_block_vars('items', array( 288 'IMG' => $img, 289 'A_IMG' => addslashes($img), 290 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $img, 291 292 'CODE' => ($mode == 'smilies' && isset($img_row['code'])) ? $img_row['code'] : '', 293 'EMOTION' => ($mode == 'smilies' && isset($img_row['emotion'])) ? $img_row['emotion'] : '', 294 295 'S_ID' => (isset($img_row[$fields . '_id'])) ? true : false, 296 'ID' => (isset($img_row[$fields . '_id'])) ? $img_row[$fields . '_id'] : 0, 297 'WIDTH' => (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'], 298 'HEIGHT' => (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'], 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' && sizeof($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_var('image', array('' => 0))) : array(); 339 340 // Now really get the items 341 $image_id = (isset($_POST['id'])) ? request_var('id', array('' => 0)) : array(); 342 $image_order = (isset($_POST['order'])) ? request_var('order', array('' => 0)) : array(); 343 $image_width = (isset($_POST['width'])) ? request_var('width', array('' => 0)) : array(); 344 $image_height = (isset($_POST['height'])) ? request_var('height', array('' => 0)) : array(); 345 $image_add = (isset($_POST['add_img'])) ? request_var('add_img', array('' => 0)) : array(); 346 $image_emotion = utf8_normalize_nfc(request_var('emotion', array('' => ''), true)); 347 $image_code = utf8_normalize_nfc(request_var('code', array('' => ''), true)); 348 $image_display_on_posting = (isset($_POST['display_on_posting'])) ? request_var('display_on_posting', array('' => 0)) : array(); 349 350 // Ok, add the relevant bits if we are adding new codes to existing emoticons... 351 if ($request->variable('add_additional_code', false, false, \phpbb\request\request_interface::POST)) 352 { 353 $add_image = request_var('add_image', ''); 354 $add_code = utf8_normalize_nfc(request_var('add_code', '', true)); 355 $add_emotion = utf8_normalize_nfc(request_var('add_emotion', '', true)); 356 357 if ($add_image && $add_emotion && $add_code) 358 { 359 $images[] = $add_image; 360 $image_add[$add_image] = true; 361 362 $image_code[$add_image] = $add_code; 363 $image_emotion[$add_image] = $add_emotion; 364 $image_width[$add_image] = request_var('add_width', 0); 365 $image_height[$add_image] = request_var('add_height', 0); 366 367 if ($request->variable('add_display_on_posting', false, false, \phpbb\request\request_interface::POST)) 368 { 369 $image_display_on_posting[$add_image] = 1; 370 } 371 372 $image_order[$add_image] = request_var('add_order', 0); 373 } 374 } 375 376 if ($mode == 'smilies' && $action == 'create') 377 { 378 $smiley_count = $this->item_count($table); 379 380 $addable_smileys_count = sizeof($images); 381 foreach ($images as $image) 382 { 383 if (!isset($image_add[$image])) 384 { 385 --$addable_smileys_count; 386 } 387 } 388 389 if ($smiley_count + $addable_smileys_count > SMILEY_LIMIT) 390 { 391 trigger_error($user->lang('TOO_MANY_SMILIES', SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING); 392 } 393 } 394 395 $icons_updated = 0; 396 $errors = array(); 397 foreach ($images as $image) 398 { 399 if ($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == '')) 400 { 401 $errors[$image] = 'SMILIE_NO_' . (($image_emotion[$image] == '') ? 'EMOTION' : 'CODE'); 402 } 403 else if ($action == 'create' && !isset($image_add[$image])) 404 { 405 // skip images where add wasn't checked 406 } 407 else if (!file_exists($phpbb_root_path . $img_path . '/' . $image)) 408 { 409 $errors[$image] = 'SMILIE_NO_FILE'; 410 } 411 else 412 { 413 if ($image_width[$image] == 0 || $image_height[$image] == 0) 414 { 415 $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $image); 416 $image_width[$image] = $img_size[0]; 417 $image_height[$image] = $img_size[1]; 418 } 419 420 // Adjust image width/height for icons 421 if ($mode == 'icons') 422 { 423 if ($image_width[$image] > 127 && $image_width[$image] > $image_height[$image]) 424 { 425 $image_height[$image] = (int) ($image_height[$image] * (127 / $image_width[$image])); 426 $image_width[$image] = 127; 427 } 428 else if ($image_height[$image] > 127) 429 { 430 $image_width[$image] = (int) ($image_width[$image] * (127 / $image_height[$image])); 431 $image_height[$image] = 127; 432 } 433 } 434 435 $img_sql = array( 436 $fields . '_url' => $image, 437 $fields . '_width' => $image_width[$image], 438 $fields . '_height' => $image_height[$image], 439 'display_on_posting' => (isset($image_display_on_posting[$image])) ? 1 : 0, 440 ); 441 442 if ($mode == 'smilies') 443 { 444 $img_sql = array_merge($img_sql, array( 445 'emotion' => $image_emotion[$image], 446 'code' => $image_code[$image]) 447 ); 448 } 449 450 // Image_order holds the 'new' order value 451 if (!empty($image_order[$image])) 452 { 453 $img_sql = array_merge($img_sql, array( 454 $fields . '_order' => $image_order[$image]) 455 ); 456 457 // Since we always add 'after' an item, we just need to increase all following + the current by one 458 $sql = "UPDATE $table 459 SET {$fields}_order = {$fields}_order + 1 460 WHERE {$fields}_order >= {$image_order[$image]}"; 461 $db->sql_query($sql); 462 463 // If we adjust the order, we need to adjust all other orders too - they became inaccurate... 464 foreach ($image_order as $_image => $_order) 465 { 466 if ($_image == $image) 467 { 468 continue; 469 } 470 471 if ($_order >= $image_order[$image]) 472 { 473 $image_order[$_image]++; 474 } 475 } 476 } 477 478 if ($action == 'modify' && !empty($image_id[$image])) 479 { 480 $sql = "UPDATE $table 481 SET " . $db->sql_build_array('UPDATE', $img_sql) . " 482 WHERE {$fields}_id = " . $image_id[$image]; 483 $db->sql_query($sql); 484 $icons_updated++; 485 } 486 else if ($action !== 'modify') 487 { 488 $sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql); 489 $db->sql_query($sql); 490 $icons_updated++; 491 } 492 493 } 494 } 495 496 $cache->destroy('_icons'); 497 $cache->destroy('sql', $table); 498 499 $level = ($icons_updated) ? E_USER_NOTICE : E_USER_WARNING; 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($lang . '_EDITED', $icons_updated) . $errormsgs . adm_back_link($this->u_action), $level); 508 } 509 else 510 { 511 trigger_error($user->lang($lang . '_ADDED', $icons_updated) . $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 (!check_form_key($form_key)) 526 { 527 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 528 } 529 530 if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak))) 531 { 532 trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING); 533 } 534 535 // Make sure the pak_ary is valid 536 foreach ($pak_ary as $pak_entry) 537 { 538 if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data)) 539 { 540 if ((sizeof($data[1]) != 4 && $mode == 'icons') || 541 ((sizeof($data[1]) != 6 || (empty($data[1][4]) || empty($data[1][5]))) && $mode == 'smilies' )) 542 { 543 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); 544 } 545 } 546 else 547 { 548 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); 549 } 550 } 551 552 // The user has already selected a smilies_pak file 553 if ($current == 'delete') 554 { 555 switch ($db->get_sql_layer()) 556 { 557 case 'sqlite': 558 case 'sqlite3': 559 $db->sql_query('DELETE FROM ' . $table); 560 break; 561 562 default: 563 $db->sql_query('TRUNCATE TABLE ' . $table); 564 break; 565 } 566 567 switch ($mode) 568 { 569 case 'smilies': 570 break; 571 572 case 'icons': 573 // Reset all icon_ids 574 $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0'); 575 $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0'); 576 break; 577 } 578 } 579 else 580 { 581 $cur_img = array(); 582 583 $field_sql = ($mode == 'smilies') ? 'code' : 'icons_url'; 584 585 $sql = "SELECT $field_sql 586 FROM $table"; 587 $result = $db->sql_query($sql); 588 589 while ($row = $db->sql_fetchrow($result)) 590 { 591 ++$order; 592 $cur_img[$row[$field_sql]] = 1; 593 } 594 $db->sql_freeresult($result); 595 } 596 597 if ($mode == 'smilies') 598 { 599 $smiley_count = $this->item_count($table); 600 if ($smiley_count + sizeof($pak_ary) > SMILEY_LIMIT) 601 { 602 trigger_error($user->lang('TOO_MANY_SMILIES', SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING); 603 } 604 } 605 606 foreach ($pak_ary as $pak_entry) 607 { 608 $data = array(); 609 if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data)) 610 { 611 if ((sizeof($data[1]) != 4 && $mode == 'icons') || 612 (sizeof($data[1]) != 6 && $mode == 'smilies')) 613 { 614 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); 615 } 616 617 // Stripslash here because it got addslashed before... (on export) 618 $img = stripslashes($data[1][0]); 619 $width = stripslashes($data[1][1]); 620 $height = stripslashes($data[1][2]); 621 $display_on_posting = stripslashes($data[1][3]); 622 623 if (isset($data[1][4]) && isset($data[1][5])) 624 { 625 $emotion = stripslashes($data[1][4]); 626 $code = stripslashes($data[1][5]); 627 } 628 629 if ($current == 'replace' && 630 (($mode == 'smilies' && !empty($cur_img[$code])) || 631 ($mode == 'icons' && !empty($cur_img[$img])))) 632 { 633 $replace_sql = ($mode == 'smilies') ? $code : $img; 634 $sql = array( 635 $fields . '_url' => $img, 636 $fields . '_height' => (int) $height, 637 $fields . '_width' => (int) $width, 638 'display_on_posting' => (int) $display_on_posting, 639 ); 640 641 if ($mode == 'smilies') 642 { 643 $sql = array_merge($sql, array( 644 'emotion' => $emotion, 645 )); 646 } 647 648 $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql) . " 649 WHERE $field_sql = '" . $db->sql_escape($replace_sql) . "'"; 650 $db->sql_query($sql); 651 } 652 else 653 { 654 ++$order; 655 656 $sql = array( 657 $fields . '_url' => $img, 658 $fields . '_height' => (int) $height, 659 $fields . '_width' => (int) $width, 660 $fields . '_order' => (int) $order, 661 'display_on_posting'=> (int) $display_on_posting, 662 ); 663 664 if ($mode == 'smilies') 665 { 666 $sql = array_merge($sql, array( 667 'code' => $code, 668 'emotion' => $emotion, 669 )); 670 } 671 $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql)); 672 } 673 } 674 } 675 676 $cache->destroy('_icons'); 677 $cache->destroy('sql', $table); 678 679 trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action)); 680 } 681 else 682 { 683 $pak_options = ''; 684 685 foreach ($_paks as $pak) 686 { 687 $pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>'; 688 } 689 690 $template->assign_vars(array( 691 'S_CHOOSE_PAK' => true, 692 'S_PAK_OPTIONS' => $pak_options, 693 694 'L_TITLE' => $user->lang['ACP_' . $lang], 695 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 696 'L_NO_PAK_OPTIONS' => $user->lang['NO_' . $lang . '_PAK'], 697 'L_CURRENT' => $user->lang['CURRENT_' . $lang], 698 'L_CURRENT_EXPLAIN' => $user->lang['CURRENT_' . $lang . '_EXPLAIN'], 699 'L_IMPORT_SUBMIT' => $user->lang['IMPORT_' . $lang], 700 701 'U_BACK' => $this->u_action, 702 'U_ACTION' => $this->u_action . '&action=import', 703 ) 704 ); 705 } 706 break; 707 708 case 'export': 709 710 $this->page_title = 'EXPORT_' . $lang; 711 $this->tpl_name = 'message_body'; 712 713 $template->assign_vars(array( 714 'MESSAGE_TITLE' => $user->lang['EXPORT_' . $lang], 715 'MESSAGE_TEXT' => sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '<a href="' . $this->u_action . '&action=send&hash=' . generate_link_hash('acp_icons') . '">', '</a>'), 716 717 'S_USER_NOTICE' => true, 718 ) 719 ); 720 721 return; 722 723 break; 724 725 case 'send': 726 727 if (!check_link_hash($request->variable('hash', ''), 'acp_icons')) 728 { 729 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 730 } 731 732 $sql = "SELECT * 733 FROM $table 734 ORDER BY {$fields}_order"; 735 $result = $db->sql_query($sql); 736 737 $pak = ''; 738 while ($row = $db->sql_fetchrow($result)) 739 { 740 $pak .= "'" . addslashes($row[$fields . '_url']) . "', "; 741 $pak .= "'" . addslashes($row[$fields . '_width']) . "', "; 742 $pak .= "'" . addslashes($row[$fields . '_height']) . "', "; 743 $pak .= "'" . addslashes($row['display_on_posting']) . "', "; 744 745 if ($mode == 'smilies') 746 { 747 $pak .= "'" . addslashes($row['emotion']) . "', "; 748 $pak .= "'" . addslashes($row['code']) . "', "; 749 } 750 751 $pak .= "\n"; 752 } 753 $db->sql_freeresult($result); 754 755 if ($pak != '') 756 { 757 garbage_collection(); 758 759 header('Cache-Control: public'); 760 761 // Send out the Headers 762 header('Content-Type: text/x-delimtext; name="' . $mode . '.pak"'); 763 header('Content-Disposition: inline; filename="' . $mode . '.pak"'); 764 echo $pak; 765 766 flush(); 767 exit; 768 } 769 else 770 { 771 trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING); 772 } 773 774 break; 775 776 case 'delete': 777 778 if (confirm_box(true)) 779 { 780 $sql = "DELETE FROM $table 781 WHERE {$fields}_id = $icon_id"; 782 $db->sql_query($sql); 783 784 switch ($mode) 785 { 786 case 'smilies': 787 break; 788 789 case 'icons': 790 // Reset appropriate icon_ids 791 $db->sql_query('UPDATE ' . TOPICS_TABLE . " 792 SET icon_id = 0 793 WHERE icon_id = $icon_id"); 794 795 $db->sql_query('UPDATE ' . POSTS_TABLE . " 796 SET icon_id = 0 797 WHERE icon_id = $icon_id"); 798 break; 799 } 800 801 $notice = $user->lang[$lang . '_DELETED']; 802 803 $cache->destroy('_icons'); 804 $cache->destroy('sql', $table); 805 806 if ($request->is_ajax()) 807 { 808 $json_response = new \phpbb\json_response; 809 $json_response->send(array( 810 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 811 'MESSAGE_TEXT' => $notice, 812 'REFRESH_DATA' => array( 813 'time' => 3 814 ) 815 )); 816 } 817 } 818 else 819 { 820 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( 821 'i' => $id, 822 'mode' => $mode, 823 'id' => $icon_id, 824 'action' => 'delete', 825 ))); 826 } 827 828 break; 829 830 case 'move_up': 831 case 'move_down': 832 833 if (!check_link_hash($request->variable('hash', ''), 'acp_icons')) 834 { 835 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 836 } 837 838 // Get current order id... 839 $sql = "SELECT {$fields}_order as current_order 840 FROM $table 841 WHERE {$fields}_id = $icon_id"; 842 $result = $db->sql_query($sql); 843 $current_order = (int) $db->sql_fetchfield('current_order'); 844 $db->sql_freeresult($result); 845 846 if ($current_order == 0 && $action == 'move_up') 847 { 848 break; 849 } 850 851 // on move_down, switch position with next order_id... 852 // on move_up, switch position with previous order_id... 853 $switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1; 854 855 // 856 $sql = "UPDATE $table 857 SET {$fields}_order = $current_order 858 WHERE {$fields}_order = $switch_order_id 859 AND {$fields}_id <> $icon_id"; 860 $db->sql_query($sql); 861 $move_executed = (bool) $db->sql_affectedrows(); 862 863 // Only update the other entry too if the previous entry got updated 864 if ($move_executed) 865 { 866 $sql = "UPDATE $table 867 SET {$fields}_order = $switch_order_id 868 WHERE {$fields}_order = $current_order 869 AND {$fields}_id = $icon_id"; 870 $db->sql_query($sql); 871 } 872 873 $cache->destroy('_icons'); 874 $cache->destroy('sql', $table); 875 876 if ($request->is_ajax()) 877 { 878 $json_response = new \phpbb\json_response; 879 $json_response->send(array( 880 'success' => $move_executed, 881 )); 882 } 883 884 break; 885 } 886 887 // By default, check that image_order is valid and fix it if necessary 888 $sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order 889 FROM $table 890 ORDER BY display_on_posting DESC, {$fields}_order"; 891 $result = $db->sql_query($sql); 892 893 if ($row = $db->sql_fetchrow($result)) 894 { 895 $order = 0; 896 do 897 { 898 ++$order; 899 if ($row['fields_order'] != $order) 900 { 901 $db->sql_query("UPDATE $table 902 SET {$fields}_order = $order 903 WHERE {$fields}_id = " . $row['order_id']); 904 } 905 } 906 while ($row = $db->sql_fetchrow($result)); 907 } 908 $db->sql_freeresult($result); 909 910 $template->assign_vars(array( 911 'L_TITLE' => $user->lang['ACP_' . $lang], 912 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 913 'L_IMPORT' => $user->lang['IMPORT_' . $lang], 914 'L_EXPORT' => $user->lang['EXPORT_' . $lang], 915 'L_NOT_DISPLAYED' => $user->lang[$lang . '_NOT_DISPLAYED'], 916 'L_ICON_ADD' => $user->lang['ADD_' . $lang], 917 'L_ICON_EDIT' => $user->lang['EDIT_' . $lang], 918 919 'NOTICE' => $notice, 920 'COLSPAN' => ($mode == 'smilies') ? 5 : 3, 921 922 'S_SMILIES' => ($mode == 'smilies') ? true : false, 923 924 'U_ACTION' => $this->u_action, 925 'U_IMPORT' => $this->u_action . '&action=import', 926 'U_EXPORT' => $this->u_action . '&action=export', 927 ) 928 ); 929 930 $spacer = false; 931 $pagination = $phpbb_container->get('pagination'); 932 $pagination_start = request_var('start', 0); 933 934 $item_count = $this->item_count($table); 935 936 $sql = "SELECT * 937 FROM $table 938 ORDER BY {$fields}_order ASC"; 939 $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $pagination_start); 940 941 while ($row = $db->sql_fetchrow($result)) 942 { 943 $alt_text = ($mode == 'smilies') ? $row['code'] : ''; 944 945 $template->assign_block_vars('items', array( 946 'S_SPACER' => (!$spacer && !$row['display_on_posting']) ? true : false, 947 'ALT_TEXT' => $alt_text, 948 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'], 949 'WIDTH' => $row[$fields . '_width'], 950 'HEIGHT' => $row[$fields . '_height'], 951 'CODE' => (isset($row['code'])) ? $row['code'] : '', 952 'EMOTION' => (isset($row['emotion'])) ? $row['emotion'] : '', 953 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row[$fields . '_id'], 954 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row[$fields . '_id'], 955 'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row[$fields . '_id'] . '&start=' . $pagination_start . '&hash=' . generate_link_hash('acp_icons'), 956 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row[$fields . '_id'] . '&start=' . $pagination_start . '&hash=' . generate_link_hash('acp_icons'), 957 )); 958 959 if (!$spacer && !$row['display_on_posting']) 960 { 961 $spacer = true; 962 } 963 } 964 $db->sql_freeresult($result); 965 966 $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start); 967 } 968 969 /** 970 * Returns the count of smilies or icons in the database 971 * 972 * @param string $table The table of items to count. 973 * @return int number of items 974 */ 975 /* private */ function item_count($table) 976 { 977 global $db; 978 979 $sql = "SELECT COUNT(*) AS item_count 980 FROM $table"; 981 $result = $db->sql_query($sql); 982 $item_count = (int) $db->sql_fetchfield('item_count'); 983 $db->sql_freeresult($result); 984 985 return $item_count; 986 } 987 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |