[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 $page->add_breadcrumb_item($lang->post_icons, "index.php?module=config-post_icons"); 19 20 $plugins->run_hooks("admin_config_post_icons_begin"); 21 22 if($mybb->input['action'] == "add") 23 { 24 $plugins->run_hooks("admin_config_post_icons_add"); 25 26 if($mybb->request_method == "post") 27 { 28 if(!trim($mybb->input['name'])) 29 { 30 $errors[] = $lang->error_missing_name; 31 } 32 33 if(!trim($mybb->input['path'])) 34 { 35 $errors[] = $lang->error_missing_path; 36 } 37 38 if(!$errors) 39 { 40 $new_icon = array( 41 'name' => $db->escape_string($mybb->input['name']), 42 'path' => $db->escape_string($mybb->input['path']) 43 ); 44 45 $iid = $db->insert_query("icons", $new_icon); 46 47 $cache->update_posticons(); 48 49 $plugins->run_hooks("admin_config_post_icons_add_commit"); 50 51 // Log admin action 52 log_admin_action($iid, $mybb->input['name']); 53 54 flash_message($lang->success_post_icon_added, 'success'); 55 admin_redirect('index.php?module=config-post_icons'); 56 } 57 } 58 59 $page->add_breadcrumb_item($lang->add_post_icon); 60 $page->output_header($lang->post_icons." - ".$lang->add_post_icon); 61 62 $sub_tabs['manage_icons'] = array( 63 'title' => $lang->manage_post_icons, 64 'link' => "index.php?module=config-post_icons" 65 ); 66 67 $sub_tabs['add_icon'] = array( 68 'title' => $lang->add_post_icon, 69 'link' => "index.php?module=config-post_icons&action=add", 70 'description' => $lang->add_post_icon_desc 71 ); 72 73 $sub_tabs['add_multiple'] = array( 74 'title' => $lang->add_multiple_post_icons, 75 'link' => "index.php?module=config-post_icons&action=add_multiple" 76 ); 77 78 $page->output_nav_tabs($sub_tabs, 'add_icon'); 79 80 if($errors) 81 { 82 $page->output_inline_error($errors); 83 } 84 else 85 { 86 $mybb->input['path'] = 'images/icons/'; 87 } 88 89 $form = new Form("index.php?module=config-post_icons&action=add", "post", "add"); 90 $form_container = new FormContainer($lang->add_post_icon); 91 $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 92 $form_container->output_row($lang->image_path." <em>*</em>", $lang->image_path_desc, $form->generate_text_box('path', $mybb->input['path'], array('id' => 'path')), 'path'); 93 $form_container->end(); 94 95 $buttons[] = $form->generate_submit_button($lang->save_post_icon); 96 97 $form->output_submit_wrapper($buttons); 98 99 $form->end(); 100 101 $page->output_footer(); 102 } 103 104 if($mybb->input['action'] == "add_multiple") 105 { 106 $plugins->run_hooks("admin_config_post_icons_add_multiple"); 107 108 if($mybb->request_method == "post") 109 { 110 if($mybb->input['step'] == 1) 111 { 112 if(!trim($mybb->input['pathfolder'])) 113 { 114 $errors[] = $lang->error_missing_path_multiple; 115 } 116 117 $path = $mybb->input['pathfolder']; 118 $dir = @opendir(MYBB_ROOT.$path); 119 if(!$dir) 120 { 121 $errors[] = $lang->error_invalid_path; 122 } 123 124 if(substr($path, -1, 1) !== "/") 125 { 126 $path .= "/"; 127 } 128 129 $query = $db->simple_select("icons"); 130 while($icon = $db->fetch_array($query)) 131 { 132 $aicons[$icon['path']] = 1; 133 } 134 135 if(!$errors) 136 { 137 while($file = readdir($dir)) 138 { 139 if($file != ".." && $file != ".") 140 { 141 $ext = get_extension($file); 142 if($ext == "gif" || $ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "bmp") 143 { 144 if(!$aicons[$path.$file]) 145 { 146 $icons[] = $file; 147 } 148 } 149 } 150 } 151 closedir($dir); 152 153 if(count($icons) == 0) 154 { 155 $errors[] = $lang->error_no_images; 156 } 157 } 158 159 // Check for errors again (from above statement)! 160 if(!$errors) 161 { 162 // We have no errors so let's proceed! 163 $page->add_breadcrumb_item($lang->add_multiple_post_icons); 164 $page->output_header($lang->post_icons." - ".$lang->add_multiple_post_icons); 165 166 $sub_tabs['manage_icons'] = array( 167 'title' => $lang->manage_post_icons, 168 'link' => "index.php?module=config-post_icons" 169 ); 170 171 $sub_tabs['add_icon'] = array( 172 'title' => $lang->add_post_icon, 173 'link' => "index.php?module=config-post_icons&action=add" 174 ); 175 176 $sub_tabs['add_multiple'] = array( 177 'title' => $lang->add_multiple_post_icons, 178 'link' => "index.php?module=config-post_icons&action=add_multiple", 179 'description' => $lang->add_multiple_post_icons_desc 180 ); 181 182 $page->output_nav_tabs($sub_tabs, 'add_multiple'); 183 184 $form = new Form("index.php?module=config-post_icons&action=add_multiple", "post", "add_multiple"); 185 echo $form->generate_hidden_field("step", "2"); 186 echo $form->generate_hidden_field("pathfolder", $path); 187 188 $form_container = new FormContainer($lang->add_multiple_post_icons); 189 $form_container->output_row_header($lang->image, array("class" => "align_center", 'width' => '10%')); 190 $form_container->output_row_header($lang->name); 191 $form_container->output_row_header($lang->add, array("class" => "align_center", 'width' => '5%')); 192 193 foreach($icons as $key => $file) 194 { 195 $ext = get_extension($file); 196 $find = str_replace(".".$ext, "", $file); 197 $name = ucfirst($find); 198 199 $form_container->output_cell("<img src=\"../".$path.$file."\" alt=\"\" /><br /><small>{$file}</small>", array("class" => "align_center", "width" => 1)); 200 $form_container->output_cell($form->generate_text_box("name[{$file}]", $name, array('id' => 'name', 'style' => 'width: 98%'))); 201 $form_container->output_cell($form->generate_check_box("include[{$file}]", 1, "", array('checked' => 1)), array("class" => "align_center")); 202 $form_container->construct_row(); 203 } 204 205 if($form_container->num_rows() == 0) 206 { 207 flash_message($lang->error_no_images, 'error'); 208 admin_redirect("index.php?module=config-post_icons&action=add_multiple"); 209 } 210 211 $form_container->end(); 212 213 $buttons[] = $form->generate_submit_button($lang->save_post_icons); 214 $form->output_submit_wrapper($buttons); 215 216 $form->end(); 217 218 $page->output_footer(); 219 exit; 220 } 221 } 222 else 223 { 224 $path = $mybb->input['pathfolder']; 225 reset($mybb->input['include']); 226 $name = $mybb->input['name']; 227 228 if(empty($mybb->input['include'])) 229 { 230 flash_message($lang->error_none_included, 'error'); 231 admin_redirect("index.php?module=config-post_icons&action=add_multiple"); 232 } 233 234 foreach($mybb->input['include'] as $image => $insert) 235 { 236 if($insert) 237 { 238 $new_icon = array( 239 'name' => $db->escape_string($name[$image]), 240 'path' => $db->escape_string($path.$image) 241 ); 242 243 $db->insert_query("icons", $new_icon); 244 } 245 } 246 247 $cache->update_posticons(); 248 249 $plugins->run_hooks("admin_config_post_icons_add_multiple_commit"); 250 251 // Log admin action 252 log_admin_action(); 253 254 flash_message($lang->success_post_icons_added, 'success'); 255 admin_redirect("index.php?module=config-post_icons"); 256 } 257 } 258 259 $page->add_breadcrumb_item($lang->add_multiple_post_icons); 260 $page->output_header($lang->post_icons." - ".$lang->add_multiple_post_icons); 261 262 $sub_tabs['manage_icons'] = array( 263 'title' => $lang->manage_post_icons, 264 'link' => "index.php?module=config-post_icons" 265 ); 266 267 $sub_tabs['add_icon'] = array( 268 'title' => $lang->add_post_icon, 269 'link' => "index.php?module=config-post_icons&action=add" 270 ); 271 272 $sub_tabs['add_multiple'] = array( 273 'title' => $lang->add_multiple_post_icons, 274 'link' => "index.php?module=config-post_icons&action=add_multiple", 275 'description' => $lang->add_multiple_post_icons_desc 276 ); 277 278 $page->output_nav_tabs($sub_tabs, 'add_multiple'); 279 280 $form = new Form("index.php?module=config-post_icons&action=add_multiple", "post", "add_multiple"); 281 echo $form->generate_hidden_field("step", "1"); 282 283 if($errors) 284 { 285 $page->output_inline_error($errors); 286 } 287 288 $form_container = new FormContainer($lang->add_multiple_post_icons); 289 $form_container->output_row($lang->path_to_images." <em>*</em>", $lang->path_to_images_desc, $form->generate_text_box('pathfolder', $mybb->input['pathfolder'], array('id' => 'pathfolder')), 'pathfolder'); 290 $form_container->end(); 291 292 $buttons[] = $form->generate_submit_button($lang->show_post_icons); 293 294 $form->output_submit_wrapper($buttons); 295 $form->end(); 296 297 $page->output_footer(); 298 } 299 300 if($mybb->input['action'] == "edit") 301 { 302 $plugins->run_hooks("admin_config_post_icons_edit"); 303 304 $query = $db->simple_select("icons", "*", "iid='".intval($mybb->input['iid'])."'"); 305 $icon = $db->fetch_array($query); 306 307 if(!$icon['iid']) 308 { 309 flash_message($lang->error_invalid_post_icon, 'error'); 310 admin_redirect("index.php?module=config-post_icons"); 311 } 312 313 if($mybb->request_method == "post") 314 { 315 if(!trim($mybb->input['name'])) 316 { 317 $errors[] = $lang->error_missing_name; 318 } 319 320 if(!trim($mybb->input['path'])) 321 { 322 $errors[] = $lang->error_missing_path; 323 } 324 325 if(!$errors) 326 { 327 $updated_icon = array( 328 'name' => $db->escape_string($mybb->input['name']), 329 'path' => $db->escape_string($mybb->input['path']) 330 ); 331 332 $db->update_query("icons", $updated_icon, "iid='".intval($mybb->input['iid'])."'"); 333 334 $cache->update_posticons(); 335 336 $plugins->run_hooks("admin_config_post_icons_edit_commit"); 337 338 // Log admin action 339 log_admin_action($icon['iid'], $mybb->input['name']); 340 341 flash_message($lang->success_post_icon_updated, 'success'); 342 admin_redirect('index.php?module=config-post_icons'); 343 } 344 } 345 346 $page->add_breadcrumb_item($lang->edit_post_icon); 347 $page->output_header($lang->post_icons." - ".$lang->edit_post_icon); 348 349 $sub_tabs['edit_icon'] = array( 350 'title' => $lang->edit_post_icon, 351 'link' => "index.php?module=config-post_icons", 352 'description' => $lang->edit_post_icon_desc 353 ); 354 355 $page->output_nav_tabs($sub_tabs, 'edit_icon'); 356 357 $form = new Form("index.php?module=config-post_icons&action=edit", "post", "edit"); 358 echo $form->generate_hidden_field("iid", $icon['iid']); 359 360 if($errors) 361 { 362 $page->output_inline_error($errors); 363 } 364 else 365 { 366 $mybb->input = $icon; 367 } 368 369 $form_container = new FormContainer($lang->edit_post_icon); 370 $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 371 $form_container->output_row($lang->image_path." <em>*</em>", $lang->image_path_desc, $form->generate_text_box('path', $mybb->input['path'], array('id' => 'path')), 'path'); 372 $form_container->end(); 373 374 $buttons[] = $form->generate_submit_button($lang->save_post_icon); 375 $buttons[] = $form->generate_reset_button($lang->reset); 376 377 $form->output_submit_wrapper($buttons); 378 $form->end(); 379 380 $page->output_footer(); 381 } 382 383 if($mybb->input['action'] == "delete") 384 { 385 $plugins->run_hooks("admin_config_post_icons_delete"); 386 387 $query = $db->simple_select("icons", "*", "iid='".intval($mybb->input['iid'])."'"); 388 $icon = $db->fetch_array($query); 389 390 if(!$icon['iid']) 391 { 392 flash_message($lang->error_invalid_post_icon, 'error'); 393 admin_redirect("index.php?module=config-post_icons"); 394 } 395 396 // User clicked no 397 if($mybb->input['no']) 398 { 399 admin_redirect("index.php?module=config-post_icons"); 400 } 401 402 if($mybb->request_method == "post") 403 { 404 $db->delete_query("icons", "iid='{$icon['iid']}'"); 405 406 $cache->update_posticons(); 407 408 $plugins->run_hooks("admin_config_post_icons_delete_commit"); 409 410 // Log admin action 411 log_admin_action($icon['iid'], $icon['name']); 412 413 flash_message($lang->success_post_icon_deleted, 'success'); 414 admin_redirect("index.php?module=config-post_icons"); 415 } 416 else 417 { 418 $page->output_confirm_action("index.php?module=config-post_icons&action=delete&iid={$icon['iid']}", $lang->confirm_post_icon_deletion); 419 } 420 } 421 422 if(!$mybb->input['action']) 423 { 424 $plugins->run_hooks("admin_config_post_icons_start"); 425 426 $page->output_header($lang->post_icons); 427 428 $sub_tabs['manage_icons'] = array( 429 'title' => $lang->manage_post_icons, 430 'link' => "index.php?module=config-post_icons", 431 'description' => $lang->manage_post_icons_desc 432 ); 433 434 $sub_tabs['add_icon'] = array( 435 'title' => $lang->add_post_icon, 436 'link' => "index.php?module=config-post_icons&action=add" 437 ); 438 439 $sub_tabs['add_multiple'] = array( 440 'title' => $lang->add_multiple_post_icons, 441 'link' => "index.php?module=config-post_icons&action=add_multiple" 442 ); 443 444 $page->output_nav_tabs($sub_tabs, 'manage_icons'); 445 446 $pagenum = intval($mybb->input['page']); 447 if($pagenum) 448 { 449 $start = ($pagenum - 1) * 20; 450 } 451 else 452 { 453 $start = 0; 454 $pagenum = 1; 455 } 456 457 $table = new Table; 458 $table->construct_header($lang->image, array('class' => "align_center", 'width' => 1)); 459 $table->construct_header($lang->name, array('width' => "70%")); 460 $table->construct_header($lang->controls, array('class' => "align_center", 'colspan' => 2)); 461 462 $query = $db->simple_select("icons", "*", "", array('limit_start' => $start, 'limit' => 20, 'order_by' => 'name')); 463 while($icon = $db->fetch_array($query)) 464 { 465 if(my_strpos($icon['path'], "p://") || substr($icon['path'], 0, 1) == "/") 466 { 467 $image = $icon['path']; 468 } 469 else 470 { 471 $image = "../".$icon['path']; 472 } 473 474 $table->construct_cell("<img src=\"{$image}\" alt=\"\" />", array("class" => "align_center")); 475 $table->construct_cell(htmlspecialchars_uni($icon['name'])); 476 477 $table->construct_cell("<a href=\"index.php?module=config-post_icons&action=edit&iid={$icon['iid']}\">{$lang->edit}</a>", array("class" => "align_center")); 478 $table->construct_cell("<a href=\"index.php?module=config-post_icons&action=delete&iid={$icon['iid']}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_post_icon_deletion}')\">{$lang->delete}</a>", array("class" => "align_center")); 479 $table->construct_row(); 480 } 481 482 if($table->num_rows() == 0) 483 { 484 $table->construct_cell($lang->no_post_icons, array('colspan' => 4)); 485 $table->construct_row(); 486 } 487 488 $table->output($lang->manage_post_icons); 489 490 $query = $db->simple_select("icons", "COUNT(iid) AS icons"); 491 $total_rows = $db->fetch_field($query, "icons"); 492 493 echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-post_icons&page={page}"); 494 495 $page->output_footer(); 496 } 497 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |