| [ Index ] |
PHP Cross Reference of MyBB 1.6.7 |
[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: post_icons.php 5459 2011-05-10 10:47:56Z Tomm $ 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 while($file = readdir($dir)) 136 { 137 if($file != ".." && $file != ".") 138 { 139 $ext = get_extension($file); 140 if($ext == "gif" || $ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "bmp") 141 { 142 if(!$aicons[$path.$file]) 143 { 144 $icons[] = $file; 145 } 146 } 147 } 148 } 149 closedir($dir); 150 151 if(count($icons) == 0) 152 { 153 $errors[] = $lang->error_no_images; 154 } 155 156 if(!$errors) 157 { 158 // We have no errors so let's proceed! 159 $page->add_breadcrumb_item($lang->add_multiple_post_icons); 160 $page->output_header($lang->post_icons." - ".$lang->add_multiple_post_icons); 161 162 $sub_tabs['manage_icons'] = array( 163 'title' => $lang->manage_post_icons, 164 'link' => "index.php?module=config-post_icons" 165 ); 166 167 $sub_tabs['add_icon'] = array( 168 'title' => $lang->add_post_icon, 169 'link' => "index.php?module=config-post_icons&action=add" 170 ); 171 172 $sub_tabs['add_multiple'] = array( 173 'title' => $lang->add_multiple_post_icons, 174 'link' => "index.php?module=config-post_icons&action=add_multiple", 175 'description' => $lang->add_multiple_post_icons_desc 176 ); 177 178 $page->output_nav_tabs($sub_tabs, 'add_multiple'); 179 180 $form = new Form("index.php?module=config-post_icons&action=add_multiple", "post", "add_multiple"); 181 echo $form->generate_hidden_field("step", "2"); 182 echo $form->generate_hidden_field("pathfolder", $path); 183 184 $form_container = new FormContainer($lang->add_multiple_post_icons); 185 $form_container->output_row_header($lang->image, array("class" => "align_center", 'width' => '10%')); 186 $form_container->output_row_header($lang->name); 187 $form_container->output_row_header($lang->add, array("class" => "align_center", 'width' => '5%')); 188 189 foreach($icons as $key => $file) 190 { 191 $ext = get_extension($file); 192 $find = str_replace(".".$ext, "", $file); 193 $name = ucfirst($find); 194 195 $form_container->output_cell("<img src=\"../".$path.$file."\" alt=\"\" /><br /><small>{$file}</small>", array("class" => "align_center", "width" => 1)); 196 $form_container->output_cell($form->generate_text_box("name[{$file}]", $name, array('id' => 'name', 'style' => 'width: 98%'))); 197 $form_container->output_cell($form->generate_check_box("include[{$file}]", 1, "", array('checked' => 1)), array("class" => "align_center")); 198 $form_container->construct_row(); 199 } 200 201 if($form_container->num_rows() == 0) 202 { 203 flash_message($lang->error_no_images, 'error'); 204 admin_redirect("index.php?module=config-post_icons&action=add_multiple"); 205 } 206 207 $form_container->end(); 208 209 $buttons[] = $form->generate_submit_button($lang->save_post_icons); 210 $form->output_submit_wrapper($buttons); 211 212 $form->end(); 213 214 $page->output_footer(); 215 exit; 216 } 217 } 218 else 219 { 220 $path = $mybb->input['pathfolder']; 221 reset($mybb->input['include']); 222 $name = $mybb->input['name']; 223 224 if(empty($mybb->input['include'])) 225 { 226 flash_message($lang->error_none_included, 'error'); 227 admin_redirect("index.php?module=config-post_icons&action=add_multiple"); 228 } 229 230 foreach($mybb->input['include'] as $image => $insert) 231 { 232 if($insert) 233 { 234 $new_icon = array( 235 'name' => $db->escape_string($name[$image]), 236 'path' => $db->escape_string($path.$image) 237 ); 238 239 $db->insert_query("icons", $new_icon); 240 } 241 } 242 243 $cache->update_posticons(); 244 245 $plugins->run_hooks("admin_config_post_icons_add_multiple_commit"); 246 247 // Log admin action 248 log_admin_action(); 249 250 flash_message($lang->success_post_icons_added, 'success'); 251 admin_redirect("index.php?module=config-post_icons"); 252 } 253 } 254 255 $page->add_breadcrumb_item($lang->add_multiple_post_icons); 256 $page->output_header($lang->post_icons." - ".$lang->add_multiple_post_icons); 257 258 $sub_tabs['manage_icons'] = array( 259 'title' => $lang->manage_post_icons, 260 'link' => "index.php?module=config-post_icons" 261 ); 262 263 $sub_tabs['add_icon'] = array( 264 'title' => $lang->add_post_icon, 265 'link' => "index.php?module=config-post_icons&action=add" 266 ); 267 268 $sub_tabs['add_multiple'] = array( 269 'title' => $lang->add_multiple_post_icons, 270 'link' => "index.php?module=config-post_icons&action=add_multiple", 271 'description' => $lang->add_multiple_post_icons_desc 272 ); 273 274 $page->output_nav_tabs($sub_tabs, 'add_multiple'); 275 276 $form = new Form("index.php?module=config-post_icons&action=add_multiple", "post", "add_multiple"); 277 echo $form->generate_hidden_field("step", "1"); 278 279 if($errors) 280 { 281 $page->output_inline_error($errors); 282 } 283 284 $form_container = new FormContainer($lang->add_multiple_post_icons); 285 $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'); 286 $form_container->end(); 287 288 $buttons[] = $form->generate_submit_button($lang->show_post_icons); 289 290 $form->output_submit_wrapper($buttons); 291 $form->end(); 292 293 $page->output_footer(); 294 } 295 296 if($mybb->input['action'] == "edit") 297 { 298 $plugins->run_hooks("admin_config_post_icons_edit"); 299 300 $query = $db->simple_select("icons", "*", "iid='".intval($mybb->input['iid'])."'"); 301 $icon = $db->fetch_array($query); 302 303 if(!$icon['iid']) 304 { 305 flash_message($lang->error_invalid_post_icon, 'error'); 306 admin_redirect("index.php?module=config-post_icons"); 307 } 308 309 if($mybb->request_method == "post") 310 { 311 if(!trim($mybb->input['name'])) 312 { 313 $errors[] = $lang->error_missing_name; 314 } 315 316 if(!trim($mybb->input['path'])) 317 { 318 $errors[] = $lang->error_missing_path; 319 } 320 321 if(!$errors) 322 { 323 $icon = array( 324 'name' => $db->escape_string($mybb->input['name']), 325 'path' => $db->escape_string($mybb->input['path']) 326 ); 327 328 $db->update_query("icons", $icon, "iid='".intval($mybb->input['iid'])."'"); 329 330 $cache->update_posticons(); 331 332 $plugins->run_hooks("admin_config_post_icons_edit_commit"); 333 334 // Log admin action 335 log_admin_action($icon['iid'], $mybb->input['name']); 336 337 flash_message($lang->success_post_icon_updated, 'success'); 338 admin_redirect('index.php?module=config-post_icons'); 339 } 340 } 341 342 $page->add_breadcrumb_item($lang->edit_post_icon); 343 $page->output_header($lang->post_icons." - ".$lang->edit_post_icon); 344 345 $sub_tabs['edit_icon'] = array( 346 'title' => $lang->edit_post_icon, 347 'link' => "index.php?module=config-post_icons", 348 'description' => $lang->edit_post_icon_desc 349 ); 350 351 $page->output_nav_tabs($sub_tabs, 'edit_icon'); 352 353 $form = new Form("index.php?module=config-post_icons&action=edit", "post", "edit"); 354 echo $form->generate_hidden_field("iid", $icon['iid']); 355 356 if($errors) 357 { 358 $page->output_inline_error($errors); 359 } 360 else 361 { 362 $mybb->input = $icon; 363 } 364 365 $form_container = new FormContainer($lang->edit_post_icon); 366 $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 367 $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'); 368 $form_container->end(); 369 370 $buttons[] = $form->generate_submit_button($lang->save_post_icon); 371 $buttons[] = $form->generate_reset_button($lang->reset); 372 373 $form->output_submit_wrapper($buttons); 374 $form->end(); 375 376 $page->output_footer(); 377 } 378 379 if($mybb->input['action'] == "delete") 380 { 381 $plugins->run_hooks("admin_config_post_icons_delete"); 382 383 $query = $db->simple_select("icons", "*", "iid='".intval($mybb->input['iid'])."'"); 384 $icon = $db->fetch_array($query); 385 386 if(!$icon['iid']) 387 { 388 flash_message($lang->error_invalid_post_icon, 'error'); 389 admin_redirect("index.php?module=config-post_icons"); 390 } 391 392 // User clicked no 393 if($mybb->input['no']) 394 { 395 admin_redirect("index.php?module=config-post_icons"); 396 } 397 398 if($mybb->request_method == "post") 399 { 400 $db->delete_query("icons", "iid='{$icon['iid']}'"); 401 402 $cache->update_posticons(); 403 404 $plugins->run_hooks("admin_config_post_icons_delete_commit"); 405 406 // Log admin action 407 log_admin_action($icon['iid'], $icon['name']); 408 409 flash_message($lang->success_post_icon_deleted, 'success'); 410 admin_redirect("index.php?module=config-post_icons"); 411 } 412 else 413 { 414 $page->output_confirm_action("index.php?module=config-post_icons&action=delete&iid={$icon['iid']}", $lang->confirm_post_icon_deletion); 415 } 416 } 417 418 if(!$mybb->input['action']) 419 { 420 $plugins->run_hooks("admin_config_post_icons_start"); 421 422 $page->output_header($lang->post_icons); 423 424 $sub_tabs['manage_icons'] = array( 425 'title' => $lang->manage_post_icons, 426 'link' => "index.php?module=config-post_icons", 427 'description' => $lang->manage_post_icons_desc 428 ); 429 430 $sub_tabs['add_icon'] = array( 431 'title' => $lang->add_post_icon, 432 'link' => "index.php?module=config-post_icons&action=add" 433 ); 434 435 $sub_tabs['add_multiple'] = array( 436 'title' => $lang->add_multiple_post_icons, 437 'link' => "index.php?module=config-post_icons&action=add_multiple" 438 ); 439 440 $page->output_nav_tabs($sub_tabs, 'manage_icons'); 441 442 $pagenum = intval($mybb->input['page']); 443 if($pagenum) 444 { 445 $start = ($pagenum - 1) * 20; 446 } 447 else 448 { 449 $start = 0; 450 $pagenum = 1; 451 } 452 453 $table = new Table; 454 $table->construct_header($lang->image, array('class' => "align_center", 'width' => 1)); 455 $table->construct_header($lang->name, array('width' => "70%")); 456 $table->construct_header($lang->controls, array('class' => "align_center", 'colspan' => 2)); 457 458 $query = $db->simple_select("icons", "*", "", array('limit_start' => $start, 'limit' => 20, 'order_by' => 'name')); 459 while($icon = $db->fetch_array($query)) 460 { 461 if(my_strpos($icon['path'], "p://") || substr($icon['path'], 0, 1) == "/") 462 { 463 $image = $icon['path']; 464 } 465 else 466 { 467 $image = "../".$icon['path']; 468 } 469 470 $table->construct_cell("<img src=\"{$image}\" alt=\"\" />", array("class" => "align_center")); 471 $table->construct_cell(htmlspecialchars_uni($icon['name'])); 472 473 $table->construct_cell("<a href=\"index.php?module=config-post_icons&action=edit&iid={$icon['iid']}\">{$lang->edit}</a>", array("class" => "align_center")); 474 $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")); 475 $table->construct_row(); 476 } 477 478 if($table->num_rows() == 0) 479 { 480 $table->construct_cell($lang->no_post_icons, array('colspan' => 4)); 481 $table->construct_row(); 482 } 483 484 $table->output($lang->manage_post_icons); 485 486 $query = $db->simple_select("icons", "COUNT(iid) AS icons"); 487 $total_rows = $db->fetch_field($query, "icons"); 488 489 echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-post_icons&page={page}"); 490 491 $page->output_footer(); 492 } 493 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Mar 31 17:55:03 2012 | Cross-referenced by PHPXref 0.7.1 |