[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package acp 5 * @version $Id: acp_icons.php,v 1.19 2006/10/14 14:56:43 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 * @todo [smilies] check regular expressions for special char replacements (stored specialchared in db) 13 * @package acp 14 */ 15 class acp_icons 16 { 17 var $u_action; 18 19 function main($id, $mode) 20 { 21 global $db, $user, $auth, $template, $cache; 22 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; 23 24 $user->add_lang('acp/posting'); 25 26 // Set up general vars 27 $action = request_var('action', ''); 28 $action = (isset($_POST['add'])) ? 'add' : $action; 29 $action = (isset($_POST['edit'])) ? 'edit' : $action; 30 $action = (isset($_POST['import'])) ? 'import' : $action; 31 $icon_id = request_var('id', 0); 32 33 $this->tpl_name = 'acp_icons'; 34 35 // What are we working on? 36 switch ($mode) 37 { 38 case 'smilies': 39 $table = SMILIES_TABLE; 40 $lang = 'SMILIES'; 41 $fields = 'smiley'; 42 $img_path = $config['smilies_path']; 43 break; 44 45 case 'icons': 46 $table = ICONS_TABLE; 47 $lang = 'ICONS'; 48 $fields = 'icons'; 49 $img_path = $config['icons_path']; 50 break; 51 } 52 53 $this->page_title = 'ACP_' . $lang; 54 55 // Clear some arrays 56 $_images = $_paks = array(); 57 $notice = ''; 58 59 // Grab file list of paks and images 60 if ($action == 'edit' || $action == 'add' || $action == 'import') 61 { 62 $imglist = filelist($phpbb_root_path . $img_path, ''); 63 64 foreach ($imglist as $path => $img_ary) 65 { 66 foreach ($img_ary as $img) 67 { 68 $img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $path . $img); 69 70 if (!$img_size[0] || !$img_size[1]) 71 { 72 continue; 73 } 74 75 $_images[$path . $img]['file'] = $path . $img; 76 $_images[$path . $img]['width'] = $img_size[0]; 77 $_images[$path . $img]['height'] = $img_size[1]; 78 } 79 } 80 unset($imglist); 81 82 $dir = @opendir($phpbb_root_path . $img_path); 83 while (($file = @readdir($dir)) !== false) 84 { 85 if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\.pak$#i', $file)) 86 { 87 $_paks[] = $file; 88 } 89 } 90 @closedir($dir); 91 } 92 93 // What shall we do today? Oops, I believe that's trademarked ... 94 switch ($action) 95 { 96 case 'edit': 97 unset($_images); 98 $_images = array(); 99 100 // no break; 101 102 case 'add': 103 104 $order_list = ''; 105 106 $sql = "SELECT * 107 FROM $table 108 ORDER BY {$fields}_order " . (($icon_id || $action == 'add') ? 'DESC' : 'ASC'); 109 $result = $db->sql_query($sql); 110 111 $data = array(); 112 while ($row = $db->sql_fetchrow($result)) 113 { 114 if ($action == 'add') 115 { 116 unset($_images[$row[$fields . '_url']]); 117 } 118 119 if ($row[$fields . '_id'] == $icon_id) 120 { 121 $after = true; 122 $data[$row[$fields . '_url']] = $row; 123 } 124 else 125 { 126 if ($action == 'edit' && !$icon_id) 127 { 128 $data[$row[$fields . '_url']] = $row; 129 } 130 131 $selected = ''; 132 if (!empty($after)) 133 { 134 $selected = ' selected="selected"'; 135 $after = false; 136 } 137 138 $after_txt = ($mode == 'smilies') ? $row['code'] : $row['icons_url']; 139 $order_list = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . $selected . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . htmlspecialchars($after_txt)) . '</option>' . $order_list; 140 } 141 } 142 $db->sql_freeresult($result); 143 144 $order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>' . $order_list; 145 146 if ($action == 'add') 147 { 148 $data = $_images; 149 } 150 151 $colspan = (($mode == 'smilies') ? '7' : '5'); 152 $colspan += ($icon_id) ? 1 : 0; 153 $colspan += ($action == 'add') ? 2 : 0; 154 155 $template->assign_vars(array( 156 'S_EDIT' => true, 157 'S_SMILIES' => ($mode == 'smilies') ? true : false, 158 'S_ADD' => ($action == 'add') ? true : false, 159 'S_ORDER_LIST' => $order_list, 160 161 'L_TITLE' => $user->lang['ACP_' . $lang], 162 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 163 'L_CONFIG' => $user->lang[$lang . '_CONFIG'], 164 'L_URL' => $user->lang[$lang . '_URL'], 165 'L_LOCATION' => $user->lang[$lang . '_LOCATION'], 166 'L_WIDTH' => $user->lang[$lang . '_WIDTH'], 167 'L_HEIGHT' => $user->lang[$lang . '_HEIGHT'], 168 'L_ORDER' => $user->lang[$lang . '_ORDER'], 169 170 'COLSPAN' => $colspan, 171 'ID' => $icon_id, 172 173 'U_BACK' => $this->u_action, 174 'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify'), 175 ) 176 ); 177 178 foreach ($data as $img => $img_row) 179 { 180 $template->assign_block_vars('items', array( 181 'IMG' => $img, 182 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $img, 183 184 'CODE' => ($mode == 'smilies' && isset($img_row['code'])) ? $img_row['code'] : '', 185 'EMOTION' => ($mode == 'smilies' && isset($img_row['emotion'])) ? $img_row['emotion'] : '', 186 187 'S_ID' => (isset($img_row[$fields . '_id'])) ? true : false, 188 'ID' => (isset($img_row[$fields . '_id'])) ? $img_row[$fields . '_id'] : 0, 189 'WIDTH' => (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'], 190 'HEIGHT' => (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'], 191 'POSTING_CHECKED' => (!empty($img_row['display_on_posting']) || $action == 'add') ? ' checked="checked"' : '') 192 ); 193 } 194 195 return; 196 197 break; 198 199 case 'create': 200 case 'modify': 201 202 // Get items to create/modify 203 $images = (isset($_POST['image'])) ? array_keys(request_var('image', array('' => 0))) : array(); 204 205 // Now really get the items 206 $image_id = (isset($_POST['id'])) ? array_map('intval', $_POST['id']) : array(); 207 $image_order = (isset($_POST['order'])) ? array_map('intval', $_POST['order']) : array(); 208 $image_width = (isset($_POST['width'])) ? array_map('intval', $_POST['width']) : array(); 209 $image_height = (isset($_POST['height'])) ? array_map('intval', $_POST['height']) : array(); 210 $image_add = (isset($_POST['add_img'])) ? array_map('intval', $_POST['add_img']) : array(); 211 $image_emotion = request_var('emotion', array('' => '')); 212 $image_code = request_var('code', array('' => '')); 213 $image_display_on_posting = (isset($_POST['display_on_posting'])) ? array_map('intval', $_POST['display_on_posting']) : array(); 214 215 foreach ($images as $image) 216 { 217 if (($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == '')) || 218 ($action == 'create' && !isset($image_add[$image]))) 219 { 220 } 221 else 222 { 223 if ($image_width[$image] == 0 || $image_height[$image] == 0) 224 { 225 $img_size = @getimagesize($phpbb_root_path . $img_path . '/' . $image); 226 $image_width[$image] = $img_size[0]; 227 $image_height[$image] = $img_size[1]; 228 } 229 230 $img_sql = array( 231 $fields . '_url' => $image, 232 $fields . '_width' => $image_width[$image], 233 $fields . '_height' => $image_height[$image], 234 'display_on_posting' => (isset($image_display_on_posting[$image])) ? 1 : 0, 235 ); 236 237 if ($mode == 'smilies') 238 { 239 $img_sql = array_merge($img_sql, array( 240 'emotion' => $image_emotion[$image], 241 'code' => $image_code[$image]) 242 ); 243 } 244 245 // Image_order holds the 'new' order value 246 if (!empty($image_order[$image])) 247 { 248 $img_sql = array_merge($img_sql, array( 249 $fields . '_order' => $image_order[$image]) 250 ); 251 252 // Since we always add 'after' an item, we just need to increase all following + the current by one 253 $sql = "UPDATE $table 254 SET {$fields}_order = {$fields}_order + 1 255 WHERE {$fields}_order >= {$image_order[$image]}"; 256 $db->sql_query($sql); 257 258 // If we adjust the order, we need to adjust all other orders too - they became inaccurate... 259 foreach ($image_order as $_image => $_order) 260 { 261 if ($_image == $image) 262 { 263 continue; 264 } 265 266 if ($_order >= $image_order[$image]) 267 { 268 $image_order[$_image]++; 269 } 270 } 271 } 272 273 if ($action == 'modify') 274 { 275 $sql = "UPDATE $table 276 SET " . $db->sql_build_array('UPDATE', $img_sql) . " 277 WHERE {$fields}_id = " . $image_id[$image]; 278 $db->sql_query($sql); 279 } 280 else 281 { 282 $sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql); 283 $db->sql_query($sql); 284 } 285 } 286 } 287 288 $cache->destroy('icons'); 289 $cache->destroy('sql', $table); 290 291 if ($action == 'modify') 292 { 293 trigger_error($user->lang[$lang . '_EDITED'] . adm_back_link($this->u_action)); 294 } 295 else 296 { 297 trigger_error($user->lang[$lang . '_ADDED'] . adm_back_link($this->u_action)); 298 } 299 300 break; 301 302 case 'import': 303 304 $pak = request_var('pak', ''); 305 $current = request_var('current', ''); 306 307 if ($pak != '') 308 { 309 $order = 0; 310 311 // The user has already selected a smilies_pak file 312 if ($current == 'delete') 313 { 314 $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . $table); 315 316 switch ($mode) 317 { 318 case 'smilies': 319 break; 320 321 case 'icons': 322 // Reset all icon_ids 323 $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0'); 324 $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0'); 325 break; 326 } 327 } 328 else 329 { 330 $cur_img = array(); 331 332 $field_sql = ($mode == 'smilies') ? 'code' : 'icons_url'; 333 334 $sql = "SELECT $field_sql 335 FROM $table"; 336 $result = $db->sql_query($sql); 337 338 while ($row = $db->sql_fetchrow($result)) 339 { 340 ++$order; 341 $cur_img[$row[$field_sql]] = 1; 342 } 343 $db->sql_freeresult($result); 344 } 345 346 if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak))) 347 { 348 trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING); 349 } 350 351 foreach ($pak_ary as $pak_entry) 352 { 353 $data = array(); 354 if (preg_match_all("#'(.*?)', #", $pak_entry, $data)) 355 { 356 if ((sizeof($data[1]) != 4 && $mode == 'icons') || 357 (sizeof($data[1]) != 6 && $mode == 'smilies')) 358 { 359 trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); 360 } 361 362 // Stripslash here because it got addslashed before... (on export) 363 $img = stripslashes($data[1][0]); 364 $width = stripslashes($data[1][1]); 365 $height = stripslashes($data[1][2]); 366 $display_on_posting = stripslashes($data[1][3]); 367 368 if (isset($data[1][4]) && isset($data[1][5])) 369 { 370 $emotion = stripslashes($data[1][4]); 371 $code = stripslashes($data[1][5]); 372 } 373 374 if ($current == 'replace' && 375 (($mode == 'smilies' && !empty($cur_img[$code])) || 376 ($mode == 'icons' && !empty($cur_img[$img])))) 377 { 378 $replace_sql = ($mode == 'smilies') ? $code : $img; 379 $sql = array( 380 $fields . '_url' => $img, 381 $fields . '_height' => (int) $height, 382 $fields . '_width' => (int) $width, 383 'display_on_posting' => (int) $display_on_posting, 384 ); 385 386 if ($mode == 'smilies') 387 { 388 $sql = array_merge($sql, array( 389 'emotion' => $emotion, 390 )); 391 } 392 393 $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql) . " 394 WHERE $field_sql = '" . $db->sql_escape($replace_sql) . "'"; 395 $db->sql_query($sql); 396 } 397 else 398 { 399 ++$order; 400 401 $sql = array( 402 $fields . '_url' => $img, 403 $fields . '_height' => (int) $height, 404 $fields . '_width' => (int) $width, 405 $fields . '_order' => (int) $order, 406 'display_on_posting'=> (int) $display_on_posting, 407 ); 408 409 if ($mode == 'smilies') 410 { 411 $sql = array_merge($sql, array( 412 'code' => $code, 413 'emotion' => $emotion, 414 )); 415 } 416 $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql)); 417 } 418 } 419 } 420 421 $cache->destroy('icons'); 422 $cache->destroy('sql', $table); 423 424 trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action)); 425 } 426 else 427 { 428 $pak_options = ''; 429 430 foreach ($_paks as $pak) 431 { 432 $pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>'; 433 } 434 435 $template->assign_vars(array( 436 'S_CHOOSE_PAK' => true, 437 'S_PAK_OPTIONS' => $pak_options, 438 439 'L_TITLE' => $user->lang['ACP_' . $lang], 440 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 441 'L_NO_PAK_OPTIONS' => $user->lang['NO_' . $lang . '_PAK'], 442 'L_CURRENT' => $user->lang['CURRENT_' . $lang], 443 'L_CURRENT_EXPLAIN' => $user->lang['CURRENT_' . $lang . '_EXPLAIN'], 444 'L_IMPORT_SUBMIT' => $user->lang['IMPORT_' . $lang], 445 446 'U_BACK' => $this->u_action, 447 'U_ACTION' => $this->u_action . '&action=import', 448 ) 449 ); 450 } 451 break; 452 453 case 'export': 454 455 $this->page_title = 'EXPORT_' . $lang; 456 $this->tpl_name = 'message_body'; 457 458 $template->assign_vars(array( 459 'MESSAGE_TITLE' => $user->lang['EXPORT_' . $lang], 460 'MESSAGE_TEXT' => sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '<a href="' . $this->u_action . '&action=send">', '</a>')) 461 ); 462 463 return; 464 465 break; 466 467 case 'send': 468 469 $sql = "SELECT * 470 FROM $table 471 ORDER BY {$fields}_order"; 472 $result = $db->sql_query($sql); 473 474 $pak = ''; 475 while ($row = $db->sql_fetchrow($result)) 476 { 477 $pak .= "'" . addslashes($row[$fields . '_url']) . "', "; 478 $pak .= "'" . addslashes($row[$fields . '_width']) . "', "; 479 $pak .= "'" . addslashes($row[$fields . '_height']) . "', "; 480 $pak .= "'" . addslashes($row['display_on_posting']) . "', "; 481 482 if ($mode == 'smilies') 483 { 484 $pak .= "'" . addslashes($row['emotion']) . "', "; 485 $pak .= "'" . addslashes($row['code']) . "', "; 486 } 487 488 $pak .= "\n"; 489 } 490 $db->sql_freeresult($result); 491 492 if ($pak != '') 493 { 494 garbage_collection(); 495 496 header('Pragma: public'); 497 498 // Send out the Headers 499 header('Content-Type: text/x-delimtext; name="' . $fields . '.pak"'); 500 header('Content-Disposition: inline; filename="' . $fields . '.pak"'); 501 echo $pak; 502 503 flush(); 504 exit; 505 } 506 else 507 { 508 trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING); 509 } 510 511 break; 512 513 case 'delete': 514 515 $sql = "DELETE FROM $table 516 WHERE {$fields}_id = $icon_id"; 517 $db->sql_query($sql); 518 519 switch ($mode) 520 { 521 case 'smilies': 522 break; 523 524 case 'icons': 525 // Reset appropriate icon_ids 526 $db->sql_query('UPDATE ' . TOPICS_TABLE . " 527 SET icon_id = 0 528 WHERE icon_id = $icon_id"); 529 530 $db->sql_query('UPDATE ' . POSTS_TABLE . " 531 SET icon_id = 0 532 WHERE icon_id = $icon_id"); 533 534 break; 535 } 536 537 $notice = $user->lang[$lang . '_DELETED']; 538 539 $cache->destroy('icons'); 540 $cache->destroy('sql', $table); 541 542 break; 543 544 case 'move_up': 545 case 'move_down': 546 547 // Get current order id... 548 $sql = "SELECT {$fields}_order as current_order 549 FROM $table 550 WHERE {$fields}_id = $icon_id"; 551 $result = $db->sql_query($sql); 552 $current_order = (int) $db->sql_fetchfield('current_order'); 553 $db->sql_freeresult($result); 554 555 if ($current_order == 0 && $action == 'move_up') 556 { 557 break; 558 } 559 560 // on move_down, switch position with next order_id... 561 // on move_up, switch position with previous order_id... 562 $switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1; 563 564 // 565 $sql = "UPDATE $table 566 SET {$fields}_order = $current_order 567 WHERE {$fields}_order = $switch_order_id 568 AND {$fields}_id <> $icon_id"; 569 $db->sql_query($sql); 570 571 // Only update the other entry too if the previous entry got updated 572 if ($db->sql_affectedrows()) 573 { 574 $sql = "UPDATE $table 575 SET {$fields}_order = $switch_order_id 576 WHERE {$fields}_order = $current_order 577 AND {$fields}_id = $icon_id"; 578 $db->sql_query($sql); 579 } 580 581 $cache->destroy('icons'); 582 $cache->destroy('sql', $table); 583 584 break; 585 } 586 587 // By default, check that image_order is valid and fix it if necessary 588 $sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order 589 FROM $table 590 ORDER BY display_on_posting DESC, {$fields}_order"; 591 $result = $db->sql_query($sql); 592 593 if ($row = $db->sql_fetchrow($result)) 594 { 595 $order = 0; 596 do 597 { 598 ++$order; 599 if ($row['fields_order'] != $order) 600 { 601 $db->sql_query("UPDATE $table 602 SET {$fields}_order = $order 603 WHERE {$fields}_id = " . $row['order_id']); 604 } 605 } 606 while ($row = $db->sql_fetchrow($result)); 607 } 608 $db->sql_freeresult($result); 609 610 $template->assign_vars(array( 611 'L_TITLE' => $user->lang['ACP_' . $lang], 612 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 613 'L_IMPORT' => $user->lang['IMPORT_' . $lang], 614 'L_EXPORT' => $user->lang['EXPORT_' . $lang], 615 'L_NOT_DISPLAYED' => $user->lang[$lang . '_NOT_DISPLAYED'], 616 'L_ICON_ADD' => $user->lang['ADD_' . $lang], 617 'L_ICON_EDIT' => $user->lang['EDIT_' . $lang], 618 619 'NOTICE' => $notice, 620 'COLSPAN' => ($mode == 'smilies') ? 5 : 3, 621 622 'S_SMILIES' => ($mode == 'smilies') ? true : false, 623 624 'U_ACTION' => $this->u_action, 625 'U_IMPORT' => $this->u_action . '&action=import', 626 'U_EXPORT' => $this->u_action . '&action=export', 627 ) 628 ); 629 630 $spacer = false; 631 632 $sql = "SELECT * 633 FROM $table 634 ORDER BY {$fields}_order ASC"; 635 $result = $db->sql_query($sql); 636 637 while ($row = $db->sql_fetchrow($result)) 638 { 639 $alt_text = ($mode == 'smilies') ? $row['code'] : ''; 640 641 $template->assign_block_vars('items', array( 642 'S_SPACER' => (!$spacer && !$row['display_on_posting']) ? true : false, 643 'ALT_TEXT' => $alt_text, 644 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'], 645 'WIDTH' => $row[$fields . '_width'], 646 'HEIGHT' => $row[$fields . '_height'], 647 'CODE' => (isset($row['code'])) ? $row['code'] : '', 648 'EMOTION' => (isset($row['emotion'])) ? $row['emotion'] : '', 649 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row[$fields . '_id'], 650 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row[$fields . '_id'], 651 'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row[$fields . '_id'], 652 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row[$fields . '_id']) 653 ); 654 655 if (!$spacer && !$row['display_on_posting']) 656 { 657 $spacer = true; 658 } 659 } 660 $db->sql_freeresult($result); 661 } 662 } 663 664 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |