[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/config/ -> post_icons.php (source)

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref