[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 // Disallow direct access to this file for security reasons 12 if(!defined("IN_MYBB")) 13 { 14 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 15 } 16 17 $page->add_breadcrumb_item($lang->thread_prefixes, 'index.php?module=config-thread_prefixes'); 18 19 $sub_tabs = array( 20 "thread_prefixes" => array( 21 'title' => $lang->thread_prefixes, 22 'link' => 'index.php?module=config-thread_prefixes', 23 'description' => $lang->thread_prefixes_desc 24 ), 25 "add_prefix" => array( 26 'title'=> $lang->add_new_thread_prefix, 27 'link' => 'index.php?module=config-thread_prefixes&action=add_prefix', 28 'description' => $lang->add_new_thread_prefix_desc 29 ) 30 ); 31 32 $plugins->run_hooks('admin_config_thread_prefixes_begin'); 33 34 if($mybb->input['action'] == 'add_prefix') 35 { 36 $plugins->run_hooks('admin_config_thread_prefixes_add_prefix'); 37 38 if($mybb->request_method == 'post') 39 { 40 if(trim($mybb->input['prefix']) == '') 41 { 42 $errors[] = $lang->error_missing_prefix; 43 } 44 45 if(trim($mybb->input['displaystyle']) == '') 46 { 47 $errors[] = $lang->error_missing_display_style; 48 } 49 50 if($mybb->input['forum_type'] == 2) 51 { 52 if(is_array($mybb->input['forum_1_forums']) && count($mybb->input['forum_1_forums']) < 1) 53 { 54 $errors[] = $lang->error_no_forums_selected; 55 } 56 57 $forum_checked[2] = "checked=\"checked\""; 58 } 59 else 60 { 61 $forum_checked[1] = "checked=\"checked\""; 62 $mybb->input['forum_1_forums'] = ''; 63 } 64 65 if($mybb->input['group_type'] == 2) 66 { 67 if(is_array($mybb->input['group_1_groups']) && count($mybb->input['group_1_groups']) < 1) 68 { 69 $errors[] = $lang->error_no_groups_selected; 70 } 71 72 $group_checked[2] = "checked=\"checked\""; 73 } 74 else 75 { 76 $group_checked[1] = "checked=\"checked\""; 77 $mybb->input['group_1_forums'] = ''; 78 } 79 80 if(!$errors) 81 { 82 $new_prefix = array( 83 'prefix' => $db->escape_string($mybb->input['prefix']), 84 'displaystyle' => $db->escape_string($mybb->input['displaystyle']) 85 ); 86 87 if($mybb->input['forum_type'] == 2) 88 { 89 if(is_array($mybb->input['forum_1_forums'])) 90 { 91 $checked = array(); 92 foreach($mybb->input['forum_1_forums'] as $fid) 93 { 94 $checked[] = (int)$fid; 95 } 96 97 $new_prefix['forums'] = implode(',', $checked); 98 } 99 } 100 else 101 { 102 $new_prefix['forums'] = '-1'; 103 } 104 105 if($mybb->input['group_type'] == 2) 106 { 107 if(is_array($mybb->input['group_1_groups'])) 108 { 109 $checked = array(); 110 foreach($mybb->input['group_1_groups'] as $gid) 111 { 112 $checked[] = (int)$gid; 113 } 114 115 $new_prefix['groups'] = implode(',', $checked); 116 } 117 } 118 else 119 { 120 $new_prefix['groups'] = '-1'; 121 } 122 123 $pid = $db->insert_query('threadprefixes', $new_prefix); 124 125 $plugins->run_hooks('admin_config_thread_prefixes_add_prefix_commit'); 126 127 // Log admin action 128 log_admin_action($pid, $mybb->input['prefix']); 129 $cache->update_threadprefixes(); 130 131 flash_message($lang->success_thread_prefix_created, 'success'); 132 admin_redirect('index.php?module=config-thread_prefixes'); 133 } 134 } 135 136 $page->add_breadcrumb_item($lang->add_new_thread_prefix); 137 $page->output_header($lang->thread_prefixes." - ".$lang->add_new_thread_prefix); 138 $page->output_nav_tabs($sub_tabs, 'add_prefix'); 139 140 $form = new Form('index.php?module=config-thread_prefixes&action=add_prefix', 'post'); 141 142 if($errors) 143 { 144 $page->output_inline_error($errors); 145 } 146 else 147 { 148 $mybb->input['prefix'] = ''; 149 $mybb->input['displaystyle'] = ''; 150 $mybb->input['forum_1_forums'] = ''; 151 $forum_checked[1] = "checked=\"checked\""; 152 $forum_checked[2] = ''; 153 $mybb->input['group_1_groups'] = ''; 154 $group_checked[1] = "checked=\"checked\""; 155 $group_checked[2] = ''; 156 } 157 158 $form_container = new FormContainer($lang->prefix_options); 159 $form_container->output_row($lang->prefix.' <em>*</em>', $lang->prefix_desc, $form->generate_text_box('prefix', $mybb->input['prefix'], array('id' => 'prefix')), 'prefix'); 160 $form_container->output_row($lang->display_style.' <em>*</em>', $lang->display_style_desc, $form->generate_text_box('displaystyle', $mybb->input['displaystyle'], array('id' => 'displaystyle')), 'displaystyle'); 161 162 $actions = "<script type=\"text/javascript\"> 163 function checkAction(id) 164 { 165 var checked = ''; 166 167 $('.'+id+'s_check').each(function(e, val) 168 { 169 if($(this).prop('checked') == true) 170 { 171 checked = $(this).val(); 172 } 173 }); 174 $('.'+id+'s').each(function(e) 175 { 176 $(this).hide(); 177 }); 178 if($('#'+id+'_'+checked)) 179 { 180 $('#'+id+'_'+checked).show(); 181 } 182 } 183 </script> 184 <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 185 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt> 186 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt> 187 <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\"> 188 <table cellpadding=\"4\"> 189 <tr> 190 <td valign=\"top\"><small>{$lang->forums_colon}</small></td> 191 <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td> 192 </tr> 193 </table> 194 </dd> 195 </dl> 196 <script type=\"text/javascript\"> 197 checkAction('forum'); 198 </script>"; 199 $form_container->output_row($lang->available_in_forums.' <em>*</em>', '', $actions); 200 201 $group_select = " 202 <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\"> 203 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt> 204 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt> 205 <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\"> 206 <table cellpadding=\"4\"> 207 <tr> 208 <td valign=\"top\"><small>{$lang->groups_colon}</small></td> 209 <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td> 210 </tr> 211 </table> 212 </dd> 213 </dl> 214 <script type=\"text/javascript\"> 215 checkAction('group'); 216 </script>"; 217 $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $group_select); 218 219 $form_container->end(); 220 221 $buttons[] = $form->generate_submit_button($lang->save_thread_prefix); 222 223 $form->output_submit_wrapper($buttons); 224 $form->end(); 225 226 $page->output_footer(); 227 } 228 229 if($mybb->input['action'] == 'edit_prefix') 230 { 231 $prefix = build_prefixes($mybb->input['pid']); 232 if(empty($prefix['pid'])) 233 { 234 flash_message($lang->error_invalid_prefix, 'error'); 235 admin_redirect('index.php?module=config-thread_prefixes'); 236 } 237 238 $plugins->run_hooks('admin_config_thread_prefixes_edit_prefix_start'); 239 240 if($mybb->request_method == 'post') 241 { 242 if(trim($mybb->input['prefix']) == '') 243 { 244 $errors[] = $lang->error_missing_prefix; 245 } 246 247 if(trim($mybb->input['displaystyle']) == '') 248 { 249 $errors[] = $lang->error_missing_display_style; 250 } 251 252 if($mybb->input['forum_type'] == 2) 253 { 254 if(is_array($mybb->input['forum_1_forums']) && count($mybb->input['forum_1_forums']) < 1) 255 { 256 $errors[] = $lang->error_no_forums_selected; 257 } 258 259 $forum_checked[2] = "checked=\"checked\""; 260 } 261 else 262 { 263 $forum_checked[1] = "checked=\"checked\""; 264 $mybb->input['forum_1_forums'] = ''; 265 } 266 267 if($mybb->input['group_type'] == 2) 268 { 269 if(is_array($mybb->input['group_1_groups']) && count($mybb->input['group_1_groups']) < 1) 270 { 271 $errors[] = $lang->error_no_groups_selected; 272 } 273 274 $group_checked[2] = "checked=\"checked\""; 275 } 276 else 277 { 278 $group_checked[1] = "checked=\"checked\""; 279 $mybb->input['group_1_forums'] = ''; 280 } 281 282 if(!$errors) 283 { 284 $update_prefix = array( 285 'prefix' => $db->escape_string($mybb->input['prefix']), 286 'displaystyle' => $db->escape_string($mybb->input['displaystyle']) 287 ); 288 289 if($mybb->input['forum_type'] == 2) 290 { 291 if(is_array($mybb->input['forum_1_forums'])) 292 { 293 $checked = array(); 294 foreach($mybb->input['forum_1_forums'] as $fid) 295 { 296 $checked[] = (int)$fid; 297 } 298 299 $update_prefix['forums'] = implode(',', $checked); 300 } 301 } 302 else 303 { 304 $update_prefix['forums'] = '-1'; 305 } 306 307 if($mybb->input['group_type'] == 2) 308 { 309 if(is_array($mybb->input['group_1_groups'])) 310 { 311 $checked = array(); 312 foreach($mybb->input['group_1_groups'] as $gid) 313 { 314 $checked[] = (int)$gid; 315 } 316 317 $update_prefix['groups'] = implode(',', $checked); 318 } 319 } 320 else 321 { 322 $update_prefix['groups'] = '-1'; 323 } 324 325 $plugins->run_hooks('admin_config_thread_prefixes_edit_prefix_commit'); 326 327 $db->update_query('threadprefixes', $update_prefix, "pid='{$prefix['pid']}'"); 328 329 // Log admin action 330 log_admin_action($prefix['pid'], $mybb->input['prefix']); 331 $cache->update_threadprefixes(); 332 333 flash_message($lang->success_thread_prefix_updated, 'success'); 334 admin_redirect('index.php?module=config-thread_prefixes'); 335 } 336 } 337 338 $page->add_breadcrumb_item($lang->edit_thread_prefix); 339 $page->output_header($lang->thread_prefixes.' - '.$lang->edit_thread_prefix); 340 341 // Setup the edit prefix tab 342 unset($sub_tabs); 343 $sub_tabs['edit_prefix'] = array( 344 "title" => $lang->edit_prefix, 345 "link" => "index.php?module=config-thread_prefixes", 346 "description" => $lang->edit_prefix_desc 347 ); 348 $page->output_nav_tabs($sub_tabs, "edit_prefix"); 349 350 $form = new Form('index.php?module=config-thread_prefixes&action=edit_prefix', 'post'); 351 echo $form->generate_hidden_field('pid', $prefix['pid']); 352 353 if($errors) 354 { 355 $page->output_inline_error($errors); 356 } 357 else 358 { 359 $query = $db->simple_select('threadprefixes', '*', "pid = '{$prefix['pid']}'"); 360 $threadprefix = $db->fetch_array($query); 361 362 $mybb->input['prefix'] = $threadprefix['prefix']; 363 $mybb->input['displaystyle'] = $threadprefix['displaystyle']; 364 $mybb->input['forum_1_forums'] = explode(",", $threadprefix['forums']); 365 366 if(!$threadprefix['forums'] || $threadprefix['forums'] == -1) 367 { 368 $forum_checked[1] = "checked=\"checked\""; 369 $forum_checked[2] = ''; 370 } 371 else 372 { 373 $forum_checked[1] = ''; 374 $forum_checked[2] = "checked=\"checked\""; 375 } 376 377 $mybb->input['group_1_groups'] = explode(",", $threadprefix['groups']); 378 379 if(!$threadprefix['groups'] || $threadprefix['groups'] == -1) 380 { 381 $group_checked[1] = "checked=\"checked\""; 382 $group_checked[2] = ''; 383 } 384 else 385 { 386 $group_checked[1] = ''; 387 $group_checked[2] = "checked=\"checked\""; 388 } 389 } 390 391 $form_container = new FormContainer($lang->prefix_options); 392 $form_container->output_row($lang->prefix.' <em>*</em>', $lang->prefix_desc, $form->generate_text_box('prefix', $mybb->input['prefix'], array('id' => 'prefix')), 'prefix'); 393 $form_container->output_row($lang->display_style.' <em>*</em>', $lang->display_style_desc, $form->generate_text_box('displaystyle', $mybb->input['displaystyle'], array('id' => 'displaystyle')), 'displaystyle'); 394 395 $actions = "<script type=\"text/javascript\"> 396 function checkAction(id) 397 { 398 var checked = ''; 399 400 $('.'+id+'s_check').each(function(e, val) 401 { 402 if($(this).prop('checked') == true) 403 { 404 checked = $(this).val(); 405 } 406 }); 407 $('.'+id+'s').each(function(e) 408 { 409 $(this).hide(); 410 }); 411 if($('#'+id+'_'+checked)) 412 { 413 $('#'+id+'_'+checked).show(); 414 } 415 } 416 </script> 417 <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 418 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt> 419 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt> 420 <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\"> 421 <table cellpadding=\"4\"> 422 <tr> 423 <td valign=\"top\"><small>{$lang->forums_colon}</small></td> 424 <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td> 425 </tr> 426 </table> 427 </dd> 428 </dl> 429 <script type=\"text/javascript\"> 430 checkAction('forum'); 431 </script>"; 432 $form_container->output_row($lang->available_in_forums.' <em>*</em>', '', $actions); 433 434 $group_select = " 435 <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\"> 436 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt> 437 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt> 438 <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\"> 439 <table cellpadding=\"4\"> 440 <tr> 441 <td valign=\"top\"><small>{$lang->groups_colon}</small></td> 442 <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td> 443 </tr> 444 </table> 445 </dd> 446 </dl> 447 <script type=\"text/javascript\"> 448 checkAction('group'); 449 </script>"; 450 $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $group_select); 451 452 $form_container->end(); 453 454 $buttons[] = $form->generate_submit_button($lang->save_thread_prefix); 455 456 $form->output_submit_wrapper($buttons); 457 $form->end(); 458 459 $page->output_footer(); 460 } 461 462 if($mybb->input['action'] == 'delete_prefix') 463 { 464 $prefix = build_prefixes($mybb->input['pid']); 465 if(empty($prefix['pid'])) 466 { 467 flash_message($lang->error_invalid_thread_prefix, 'error'); 468 admin_redirect('index.php?module=config-thread_prefixes'); 469 } 470 471 // User clicked no 472 if($mybb->get_input('no')) 473 { 474 admin_redirect('index.php?module=config-thread_prefixes'); 475 } 476 477 $plugins->run_hooks('admin_config_thread_prefixes_delete_prefix'); 478 479 if($mybb->request_method == 'post') 480 { 481 // Remove prefix from existing threads 482 $update_threads = array('prefix' => 0); 483 484 // Delete prefix 485 $db->delete_query('threadprefixes', "pid='{$prefix['pid']}'"); 486 487 $plugins->run_hooks('admin_config_thread_prefixes_delete_thread_prefix_commit'); 488 489 $db->update_query('threads', $update_threads, "prefix='{$prefix['pid']}'"); 490 491 // Log admin action 492 log_admin_action($prefix['pid'], $prefix['prefix']); 493 $cache->update_threadprefixes(); 494 495 flash_message($lang->success_thread_prefix_deleted, 'success'); 496 admin_redirect('index.php?module=config-thread_prefixes'); 497 } 498 else 499 { 500 $page->output_confirm_action("index.php?module=config-thread_prefixes&action=delete_prefix&pid={$prefix['pid']}", $lang->confirm_thread_prefix_deletion); 501 } 502 } 503 504 if(!$mybb->input['action']) 505 { 506 $plugins->run_hooks('admin_config_thread_prefixes_start'); 507 508 $page->output_header($lang->thread_prefixes); 509 $page->output_nav_tabs($sub_tabs, 'thread_prefixes'); 510 511 $table = new Table; 512 $table->construct_header($lang->prefix); 513 $table->construct_header($lang->forums); 514 $table->construct_header($lang->controls, array('class' => 'align_center', 'colspan' => 2)); 515 516 $prefixes = build_prefixes(); 517 518 if(!empty($prefixes)) 519 { 520 foreach($prefixes as &$prefix) 521 { 522 $prefix['forum_fids'] = explode(',', $prefix['forums']); 523 } 524 unset($prefix); 525 526 $fid = $mybb->get_input('fid', MyBB::INPUT_INT); 527 528 if($fid) 529 { 530 $forum = get_forum($fid, 1); 531 532 if(!empty($forum)) 533 { 534 $title = $lang->sprintf($lang->thread_prefixes_in, $forum['name']); 535 536 foreach($prefixes as $key => $prefix) 537 { 538 if($prefix['forums'] !== '-1' && !in_array($fid, $prefix['forum_fids'])) 539 { 540 unset($prefixes[$key]); 541 } 542 } 543 } 544 } 545 546 usort($prefixes, 'thread_prefix_sort'); 547 548 foreach($prefixes as $prefix) 549 { 550 if($prefix['forums'] === '-1') 551 { 552 $forum_names = $lang->all_forums; 553 } 554 else 555 { 556 $forum_names = array(); 557 558 foreach($prefix['forum_fids'] as $fid) 559 { 560 $forum = get_forum($fid, 1); 561 562 if(!empty($forum)) 563 { 564 $forum_names[] = '<a href="index.php?module=config-thread_prefixes&fid='.(int)$fid.'">'.$forum['name'].'</a>'; 565 } 566 } 567 568 $forum_names = implode($lang->comma, $forum_names); 569 } 570 571 $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&action=edit_prefix&pid={$prefix['pid']}\" style=\"color: inherit;\" title=\"".htmlspecialchars_uni($prefix['prefix'])."\">".$prefix['displaystyle']."</a>"); 572 $table->construct_cell($forum_names); 573 $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&action=edit_prefix&pid={$prefix['pid']}\">{$lang->edit}</a>", array('width' => 100, 'class' => "align_center")); 574 $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&action=delete_prefix&pid={$prefix['pid']}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_thread_prefix_deletion}')\">{$lang->delete}</a>", array('width' => 100, 'class' => 'align_center')); 575 $table->construct_row(); 576 } 577 } 578 579 if($table->num_rows() == 0) 580 { 581 $table->construct_cell($lang->no_thread_prefixes, array('colspan' => 3)); 582 $table->construct_row(); 583 } 584 585 586 if(!isset($title)) 587 { 588 $title = $lang->thread_prefixes; 589 } 590 591 $table->output($title); 592 593 $page->output_footer(); 594 } 595 596 function thread_prefix_sort($a, $b) 597 { 598 // all forums 599 if($a['forums'] === '-1' && $b['forums'] !== '-1') 600 { 601 return -1; 602 } 603 if($a['forums'] !== '-1' && $b['forums'] === '-1') 604 { 605 return 1; 606 } 607 608 // multiple forums 609 if(count($a['forum_fids']) > 1 xor count($b['forum_fids']) > 1) 610 { 611 return count($b['forum_fids']) - count($a['forum_fids']); 612 } 613 // natural sort order: forum name 614 elseif( 615 count($a['forum_fids']) === 1 && count($b['forum_fids']) === 1 && 616 $a['forum_fids'][0] !== $b['forum_fids'][0] 617 ) 618 { 619 $forum_a = get_forum($a['forum_fids'][0], 1); 620 $forum_b = get_forum($b['forum_fids'][0], 1); 621 622 if($forum_a !== false && $forum_b !== false) 623 { 624 return strnatcmp($forum_a['name'], $forum_b['name']); 625 } 626 } 627 628 // natural sort order: prefix 629 return strnatcmp($a['prefix'], $b['prefix']); 630 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |