[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

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

   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: attachment_types.php 5297 2010-12-28 22:01:14Z 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->attachment_types, "index.php?module=config-attachment_types");
  19  
  20  $plugins->run_hooks("admin_config_attachment_types_begin");
  21  
  22  if($mybb->input['action'] == "add")
  23  {
  24      $plugins->run_hooks("admin_config_attachment_types_add");
  25      
  26      if($mybb->request_method == "post")
  27      {
  28          if(!trim($mybb->input['mimetype']) && !trim($mybb->input['extension']))
  29          {
  30              $errors[] = $lang->error_missing_mime_type;
  31          }
  32  
  33          if(!trim($mybb->input['extension']) && !trim($mybb->input['mimetype']))
  34          {
  35              $errors[] = $lang->error_missing_extension;
  36          }
  37  
  38          if(!$errors)
  39          {
  40              if($mybb->input['mimetype'] == "images/attachtypes/")
  41              {
  42                  $mybb->input['mimetype'] = '';
  43              }
  44              
  45              if(substr($mybb->input['extension'], 0, 1) == '.')
  46              {
  47                  $mybb->input['extension'] = substr($mybb->input['extension'], 1);
  48              }
  49              
  50              $maxsize = intval($mybb->input['maxsize']);
  51              
  52              if($maxsize == 0)
  53              {
  54                  $maxsize = "";
  55              }
  56  
  57              $new_type = array(
  58                  "mimetype" => $db->escape_string($mybb->input['mimetype']),
  59                  "extension" => $db->escape_string($mybb->input['extension']),
  60                  "maxsize" => $maxsize,
  61                  "icon" => $db->escape_string($mybb->input['icon'])
  62              );
  63  
  64              $atid = $db->insert_query("attachtypes", $new_type);
  65              
  66              $plugins->run_hooks("admin_config_attachment_types_add_commit");
  67  
  68              // Log admin action
  69              log_admin_action($atid, $mybb->input['extension']);
  70  
  71              $cache->update_attachtypes();
  72  
  73              flash_message($lang->success_attachment_type_created, 'success');
  74              admin_redirect("index.php?module=config-attachment_types");
  75          }
  76      }
  77  
  78      
  79      $page->add_breadcrumb_item($lang->add_new_attachment_type);
  80      $page->output_header($lang->attachment_types." - ".$lang->add_new_attachment_type);
  81      
  82      $sub_tabs['attachment_types'] = array(
  83          'title' => $lang->attachment_types,
  84          'link' => "index.php?module=config-attachment_types"
  85      );
  86      
  87      $sub_tabs['add_attachment_type'] = array(
  88          'title' => $lang->add_new_attachment_type,
  89          'link' => "index.php?module=config-attachment_types&amp;action=add",
  90          'description' => $lang->add_attachment_type_desc
  91      );
  92      
  93      $page->output_nav_tabs($sub_tabs, 'add_attachment_type');
  94  
  95      $form = new Form("index.php?module=config-attachment_types&amp;action=add", "post", "add");
  96      
  97      if($errors)
  98      {
  99          $page->output_inline_error($errors);
 100      }
 101      else
 102      {
 103          $mybb->input['maxsize'] = '1024';
 104          $mybb->input['icon'] = "images/attachtypes/";
 105      }
 106      
 107      // PHP settings
 108      $upload_max_filesize = @ini_get('upload_max_filesize');
 109      $post_max_size = @ini_get('post_max_size');
 110      $limit_string = '';
 111      if($upload_max_filesize || $post_max_size)
 112      {
 113          $limit_string = '<br /><br />'.$lang->limit_intro;
 114          if($upload_max_filesize)
 115          {
 116              $limit_string .= '<br />'.$lang->sprintf($lang->limit_upload_max_filesize, $upload_max_filesize);
 117          }
 118          if($post_max_size)
 119          {
 120              $limit_string .= '<br />'.$lang->sprintf($lang->limit_post_max_size, $post_max_size);
 121          }
 122      }
 123      
 124      $form_container = new FormContainer($lang->add_new_attachment_type);
 125      $form_container->output_row($lang->file_extension." <em>*</em>", $lang->file_extension_desc, $form->generate_text_box('extension', $mybb->input['extension'], array('id' => 'extension')), 'extension');
 126      $form_container->output_row($lang->mime_type." <em>*</em>", $lang->mime_type_desc, $form->generate_text_box('mimetype', $mybb->input['mimetype'], array('id' => 'mimetype')), 'mimetype');
 127      $form_container->output_row($lang->maximum_file_size, $lang->maximum_file_size_desc.$limit_string, $form->generate_text_box('maxsize', $mybb->input['maxsize'], array('id' => 'maxsize')), 'maxsize');
 128      $form_container->output_row($lang->attachment_icon, $lang->attachment_icon_desc, $form->generate_text_box('icon', $mybb->input['icon'], array('id' => 'icon')), 'icon');
 129  
 130      $form_container->end();
 131  
 132      $buttons[] = $form->generate_submit_button($lang->save_attachment_type);
 133  
 134      $form->output_submit_wrapper($buttons);
 135      $form->end();
 136  
 137      $page->output_footer();
 138  }
 139  
 140  if($mybb->input['action'] == "edit")
 141  {
 142      $plugins->run_hooks("admin_config_attachment_types_edit");
 143      
 144      $query = $db->simple_select("attachtypes", "*", "atid='".intval($mybb->input['atid'])."'");
 145      $attachment_type = $db->fetch_array($query);
 146      
 147      if(!$attachment_type['atid'])
 148      {
 149          flash_message($lang->error_invalid_attachment_type, 'error');
 150          admin_redirect("index.php?module=config-attachment_types");
 151      }
 152          
 153      if($mybb->request_method == "post")
 154      {
 155          if(!trim($mybb->input['mimetype']) && !trim($mybb->input['extension']))
 156          {
 157              $errors[] = $lang->error_missing_mime_type;
 158          }
 159  
 160          if(!trim($mybb->input['extension']) && !trim($mybb->input['mimetype']))
 161          {
 162              $errors[] = $lang->error_missing_extension;
 163          }
 164  
 165          if(!$errors)
 166          {
 167              if($mybb->input['mimetype'] == "images/attachtypes/")
 168              {
 169                  $mybb->input['mimetype'] = '';
 170              }
 171              
 172              if(substr($mybb->input['extension'], 0, 1) == '.')
 173              {
 174                  $mybb->input['extension'] = substr($mybb->input['extension'], 1);
 175              }
 176  
 177              $updated_type = array(
 178                  "mimetype" => $db->escape_string($mybb->input['mimetype']),
 179                  "extension" => $db->escape_string($mybb->input['extension']),
 180                  "maxsize" => intval($mybb->input['maxsize']),
 181                  "icon" => $db->escape_string($mybb->input['icon'])
 182              );
 183  
 184              $db->update_query("attachtypes", $updated_type, "atid='{$attachment_type['atid']}'");
 185              
 186              $plugins->run_hooks("admin_config_attachment_types_edit_commit");
 187  
 188              // Log admin action
 189              log_admin_action($attachment_type['atid'], $mybb->input['extension']);
 190  
 191              $cache->update_attachtypes();
 192  
 193              flash_message($lang->success_attachment_type_updated, 'success');
 194              admin_redirect("index.php?module=config-attachment_types");
 195          }
 196      }
 197      
 198      $page->add_breadcrumb_item($lang->edit_attachment_type);
 199      $page->output_header($lang->attachment_types." - ".$lang->edit_attachment_type);
 200      
 201      $sub_tabs['edit_attachment_type'] = array(
 202          'title' => $lang->edit_attachment_type,
 203          'link' => "index.php?module=config-attachment_types&amp;action=edit&amp;atid={$attachment_type['atid']}",
 204          'description' => $lang->edit_attachment_type_desc
 205      );
 206      
 207      $page->output_nav_tabs($sub_tabs, 'edit_attachment_type');
 208  
 209      $form = new Form("index.php?module=config-attachment_types&amp;action=edit&amp;atid={$attachment_type['atid']}", "post", "add");
 210  
 211      if($errors)
 212      {
 213          $page->output_inline_error($errors);
 214      }
 215      else
 216      {
 217          $mybb->input = $attachment_type;
 218      }
 219      
 220      // PHP settings
 221      $upload_max_filesize = @ini_get('upload_max_filesize');
 222      $post_max_size = @ini_get('post_max_size');
 223      $limit_string = '';
 224      if($upload_max_filesize || $post_max_size)
 225      {
 226          $limit_string = '<br /><br />'.$lang->limit_intro;
 227          if($upload_max_filesize)
 228          {
 229              $limit_string .= '<br />'.$lang->sprintf($lang->limit_upload_max_filesize, $upload_max_filesize);
 230          }
 231          if($post_max_size)
 232          {
 233              $limit_string .= '<br />'.$lang->sprintf($lang->limit_post_max_size, $post_max_size);
 234          }
 235      }
 236      
 237      $form_container = new FormContainer($lang->edit_attachment_type);
 238      $form_container->output_row($lang->file_extension." <em>*</em>", $lang->file_extension_desc, $form->generate_text_box('extension', $mybb->input['extension'], array('id' => 'extension')), 'extension');
 239      $form_container->output_row($lang->mime_type." <em>*</em>", $lang->mime_type_desc, $form->generate_text_box('mimetype', $mybb->input['mimetype'], array('id' => 'mimetype')), 'mimetype');
 240      $form_container->output_row($lang->maximum_file_size, $lang->maximum_file_size_desc.$limit_string, $form->generate_text_box('maxsize', $mybb->input['maxsize'], array('id' => 'maxsize')), 'maxsize');
 241      $form_container->output_row($lang->attachment_icon, $lang->attachment_icon_desc, $form->generate_text_box('icon', $mybb->input['icon'], array('id' => 'icon')), 'icon');
 242  
 243      $form_container->end();
 244  
 245      $buttons[] = $form->generate_submit_button($lang->save_attachment_type);
 246  
 247      $form->output_submit_wrapper($buttons);
 248      $form->end();
 249  
 250      $page->output_footer();
 251  }
 252  
 253  if($mybb->input['action'] == "delete")
 254  {
 255      $plugins->run_hooks("admin_config_attachment_types_delete");
 256      
 257      if($mybb->input['no']) 
 258      { 
 259          admin_redirect("index.php?module=config-attachment_types"); 
 260      }
 261      
 262      $query = $db->simple_select("attachtypes", "*", "atid='".intval($mybb->input['atid'])."'");
 263      $attachment_type = $db->fetch_array($query);
 264      
 265      if(!$attachment_type['atid'])
 266      {
 267          flash_message($lang->error_invalid_attachment_type, 'error');
 268          admin_redirect("index.php?module=config-attachment_types");
 269      }
 270      
 271      if($mybb->request_method == "post")
 272      {
 273          $db->delete_query("attachtypes", "atid='{$attachment_type['atid']}'");
 274  
 275          $cache->update_attachtypes();
 276          
 277          $plugins->run_hooks("admin_config_attachment_types_delete_commit");
 278  
 279          // Log admin action
 280          log_admin_action($attachment_type['atid'], $attachment_type['extension']);
 281  
 282          flash_message($lang->success_attachment_type_deleted, 'success');
 283          admin_redirect("index.php?module=config-attachment_types");
 284      }
 285      else
 286      {
 287          $page->output_confirm_action("index.php?module=config-attachment_types&amp;action=delete&amp;atid={$attachment_type['atid']}", $lang->confirm_attachment_type_deletion); 
 288      }
 289  }
 290  
 291  if(!$mybb->input['action'])
 292  {
 293      $plugins->run_hooks("admin_config_attachment_types_start");
 294      
 295      $page->output_header($lang->attachment_types);
 296  
 297      $sub_tabs['attachment_types'] = array(
 298          'title' => $lang->attachment_types,
 299          'link' => "index.php?module=config-attachment_types",
 300          'description' => $lang->attachment_types_desc
 301      );
 302      $sub_tabs['add_attachment_type'] = array(
 303          'title' => $lang->add_new_attachment_type,
 304          'link' => "index.php?module=config-attachment_types&amp;action=add",
 305      );
 306  
 307      $page->output_nav_tabs($sub_tabs, 'attachment_types');
 308      
 309      $table = new Table;
 310      $table->construct_header($lang->extension, array("colspan" => 2));
 311      $table->construct_header($lang->mime_type);
 312      $table->construct_header($lang->maximum_size, array("class" => "align_center"));
 313      $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2));
 314      
 315      $query = $db->simple_select("attachtypes", "*", "", array('order_by' => 'extension'));
 316      while($attachment_type = $db->fetch_array($query))
 317      {
 318          // Just show default icons in ACP        
 319          $attachment_type['icon'] = str_replace("{theme}", "images", $attachment_type['icon']);
 320          if(!$attachment_type['icon'] || $attachment_type['icon'] == "images/attachtypes/")
 321          {
 322              $attachment_type['icon'] = "&nbsp;";
 323          }
 324          else
 325          {
 326              $attachment_type['icon'] = "<img src=\"../{$attachment_type['icon']}\" alt=\"\" />";
 327          }
 328          
 329          $table->construct_cell($attachment_type['icon'], array("width" => 1));
 330          $table->construct_cell("<strong>.{$attachment_type['extension']}</strong>");
 331          $table->construct_cell($attachment_type['mimetype']);
 332          $table->construct_cell(get_friendly_size(($attachment_type['maxsize']*1024)), array("class" => "align_center"));
 333          $table->construct_cell("<a href=\"index.php?module=config-attachment_types&amp;action=edit&amp;atid={$attachment_type['atid']}\">{$lang->edit}</a>", array("class" => "align_center"));
 334          $table->construct_cell("<a href=\"index.php?module=config-attachment_types&amp;action=delete&amp;atid={$attachment_type['atid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_attachment_type_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
 335          $table->construct_row();
 336      }
 337      
 338      if($table->num_rows() == 0)
 339      {
 340          $table->construct_cell($lang->no_attachment_types, array('colspan' => 6));
 341          $table->construct_row();
 342      }
 343      
 344      $table->output($lang->attachment_types);
 345      
 346      $page->output_footer();
 347  }
 348  
 349  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1