PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Upload/admin/modules/config/attachment_types.php

https://gitlab.com/mybbpl/ppm-1.8
PHP | 360 lines | 272 code | 73 blank | 15 comment | 53 complexity | 5c07add9ef21448fe38d9ee196721cac MD5 | raw file
  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. // Disallow direct access to this file for security reasons
  11. if(!defined("IN_MYBB"))
  12. {
  13. die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  14. }
  15. $page->add_breadcrumb_item($lang->attachment_types, "index.php?module=config-attachment_types");
  16. $plugins->run_hooks("admin_config_attachment_types_begin");
  17. if($mybb->input['action'] == "add")
  18. {
  19. $plugins->run_hooks("admin_config_attachment_types_add");
  20. if($mybb->request_method == "post")
  21. {
  22. if(!trim($mybb->input['mimetype']) && !trim($mybb->input['extension']))
  23. {
  24. $errors[] = $lang->error_missing_mime_type;
  25. }
  26. if(!trim($mybb->input['extension']) && !trim($mybb->input['mimetype']))
  27. {
  28. $errors[] = $lang->error_missing_extension;
  29. }
  30. if(!$errors)
  31. {
  32. if($mybb->input['mimetype'] == "images/attachtypes/")
  33. {
  34. $mybb->input['mimetype'] = '';
  35. }
  36. if(substr($mybb->input['extension'], 0, 1) == '.')
  37. {
  38. $mybb->input['extension'] = substr($mybb->input['extension'], 1);
  39. }
  40. $maxsize = $mybb->get_input('maxsize', MyBB::INPUT_INT);
  41. if($maxsize == 0)
  42. {
  43. $maxsize = "";
  44. }
  45. $new_type = array(
  46. "name" => $db->escape_string($mybb->input['name']),
  47. "mimetype" => $db->escape_string($mybb->input['mimetype']),
  48. "extension" => $db->escape_string($mybb->input['extension']),
  49. "maxsize" => $maxsize,
  50. "icon" => $db->escape_string($mybb->input['icon'])
  51. );
  52. $atid = $db->insert_query("attachtypes", $new_type);
  53. $plugins->run_hooks("admin_config_attachment_types_add_commit");
  54. // Log admin action
  55. log_admin_action($atid, htmlspecialchars_uni($mybb->input['extension']));
  56. $cache->update_attachtypes();
  57. flash_message($lang->success_attachment_type_created, 'success');
  58. admin_redirect("index.php?module=config-attachment_types");
  59. }
  60. }
  61. $page->add_breadcrumb_item($lang->add_new_attachment_type);
  62. $page->output_header($lang->attachment_types." - ".$lang->add_new_attachment_type);
  63. $sub_tabs['attachment_types'] = array(
  64. 'title' => $lang->attachment_types,
  65. 'link' => "index.php?module=config-attachment_types"
  66. );
  67. $sub_tabs['add_attachment_type'] = array(
  68. 'title' => $lang->add_new_attachment_type,
  69. 'link' => "index.php?module=config-attachment_types&amp;action=add",
  70. 'description' => $lang->add_attachment_type_desc
  71. );
  72. $page->output_nav_tabs($sub_tabs, 'add_attachment_type');
  73. $form = new Form("index.php?module=config-attachment_types&amp;action=add", "post", "add");
  74. if($errors)
  75. {
  76. $page->output_inline_error($errors);
  77. }
  78. else
  79. {
  80. $mybb->input['maxsize'] = '1024';
  81. $mybb->input['icon'] = "images/attachtypes/";
  82. }
  83. // PHP settings
  84. $upload_max_filesize = @ini_get('upload_max_filesize');
  85. $post_max_size = @ini_get('post_max_size');
  86. $limit_string = '';
  87. if($upload_max_filesize || $post_max_size)
  88. {
  89. $limit_string = '<br /><br />'.$lang->limit_intro;
  90. if($upload_max_filesize)
  91. {
  92. $limit_string .= '<br />'.$lang->sprintf($lang->limit_upload_max_filesize, $upload_max_filesize);
  93. }
  94. if($post_max_size)
  95. {
  96. $limit_string .= '<br />'.$lang->sprintf($lang->limit_post_max_size, $post_max_size);
  97. }
  98. }
  99. $form_container = new FormContainer($lang->add_new_attachment_type);
  100. $form_container->output_row($lang->name, $lang->name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name');
  101. $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');
  102. $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');
  103. $form_container->output_row($lang->maximum_file_size, $lang->maximum_file_size_desc.$limit_string, $form->generate_numeric_field('maxsize', $mybb->input['maxsize'], array('id' => 'maxsize', 'min' => 0)), 'maxsize');
  104. $form_container->output_row($lang->attachment_icon, $lang->attachment_icon_desc, $form->generate_text_box('icon', $mybb->input['icon'], array('id' => 'icon')), 'icon');
  105. $form_container->end();
  106. $buttons[] = $form->generate_submit_button($lang->save_attachment_type);
  107. $form->output_submit_wrapper($buttons);
  108. $form->end();
  109. $page->output_footer();
  110. }
  111. if($mybb->input['action'] == "edit")
  112. {
  113. $query = $db->simple_select("attachtypes", "*", "atid='".$mybb->get_input('atid', MyBB::INPUT_INT)."'");
  114. $attachment_type = $db->fetch_array($query);
  115. if(!$attachment_type['atid'])
  116. {
  117. flash_message($lang->error_invalid_attachment_type, 'error');
  118. admin_redirect("index.php?module=config-attachment_types");
  119. }
  120. $plugins->run_hooks("admin_config_attachment_types_edit");
  121. if($mybb->request_method == "post")
  122. {
  123. if(!trim($mybb->input['mimetype']) && !trim($mybb->input['extension']))
  124. {
  125. $errors[] = $lang->error_missing_mime_type;
  126. }
  127. if(!trim($mybb->input['extension']) && !trim($mybb->input['mimetype']))
  128. {
  129. $errors[] = $lang->error_missing_extension;
  130. }
  131. if(!$errors)
  132. {
  133. if($mybb->input['mimetype'] == "images/attachtypes/")
  134. {
  135. $mybb->input['mimetype'] = '';
  136. }
  137. if(substr($mybb->input['extension'], 0, 1) == '.')
  138. {
  139. $mybb->input['extension'] = substr($mybb->input['extension'], 1);
  140. }
  141. $updated_type = array(
  142. "name" => $db->escape_string($mybb->input['name']),
  143. "mimetype" => $db->escape_string($mybb->input['mimetype']),
  144. "extension" => $db->escape_string($mybb->input['extension']),
  145. "maxsize" => $mybb->get_input('maxsize', MyBB::INPUT_INT),
  146. "icon" => $db->escape_string($mybb->input['icon'])
  147. );
  148. $plugins->run_hooks("admin_config_attachment_types_edit_commit");
  149. $db->update_query("attachtypes", $updated_type, "atid='{$attachment_type['atid']}'");
  150. // Log admin action
  151. log_admin_action($attachment_type['atid'], htmlspecialchars_uni($mybb->input['extension']));
  152. $cache->update_attachtypes();
  153. flash_message($lang->success_attachment_type_updated, 'success');
  154. admin_redirect("index.php?module=config-attachment_types");
  155. }
  156. }
  157. $page->add_breadcrumb_item($lang->edit_attachment_type);
  158. $page->output_header($lang->attachment_types." - ".$lang->edit_attachment_type);
  159. $sub_tabs['edit_attachment_type'] = array(
  160. 'title' => $lang->edit_attachment_type,
  161. 'link' => "index.php?module=config-attachment_types&amp;action=edit&amp;atid={$attachment_type['atid']}",
  162. 'description' => $lang->edit_attachment_type_desc
  163. );
  164. $page->output_nav_tabs($sub_tabs, 'edit_attachment_type');
  165. $form = new Form("index.php?module=config-attachment_types&amp;action=edit&amp;atid={$attachment_type['atid']}", "post", "add");
  166. if($errors)
  167. {
  168. $page->output_inline_error($errors);
  169. }
  170. else
  171. {
  172. $mybb->input = array_merge($mybb->input, $attachment_type);
  173. }
  174. // PHP settings
  175. $upload_max_filesize = @ini_get('upload_max_filesize');
  176. $post_max_size = @ini_get('post_max_size');
  177. $limit_string = '';
  178. if($upload_max_filesize || $post_max_size)
  179. {
  180. $limit_string = '<br /><br />'.$lang->limit_intro;
  181. if($upload_max_filesize)
  182. {
  183. $limit_string .= '<br />'.$lang->sprintf($lang->limit_upload_max_filesize, $upload_max_filesize);
  184. }
  185. if($post_max_size)
  186. {
  187. $limit_string .= '<br />'.$lang->sprintf($lang->limit_post_max_size, $post_max_size);
  188. }
  189. }
  190. $form_container = new FormContainer($lang->edit_attachment_type);
  191. $form_container->output_row($lang->name, $lang->name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name');
  192. $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');
  193. $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');
  194. $form_container->output_row($lang->maximum_file_size, $lang->maximum_file_size_desc.$limit_string, $form->generate_numeric_field('maxsize', $mybb->input['maxsize'], array('id' => 'maxsize', 'min' => 0)), 'maxsize');
  195. $form_container->output_row($lang->attachment_icon, $lang->attachment_icon_desc, $form->generate_text_box('icon', $mybb->input['icon'], array('id' => 'icon')), 'icon');
  196. $form_container->end();
  197. $buttons[] = $form->generate_submit_button($lang->save_attachment_type);
  198. $form->output_submit_wrapper($buttons);
  199. $form->end();
  200. $page->output_footer();
  201. }
  202. if($mybb->input['action'] == "delete")
  203. {
  204. if($mybb->input['no'])
  205. {
  206. admin_redirect("index.php?module=config-attachment_types");
  207. }
  208. $query = $db->simple_select("attachtypes", "*", "atid='".$mybb->get_input('atid', MyBB::INPUT_INT)."'");
  209. $attachment_type = $db->fetch_array($query);
  210. if(!$attachment_type['atid'])
  211. {
  212. flash_message($lang->error_invalid_attachment_type, 'error');
  213. admin_redirect("index.php?module=config-attachment_types");
  214. }
  215. $plugins->run_hooks("admin_config_attachment_types_delete");
  216. if($mybb->request_method == "post")
  217. {
  218. $db->delete_query("attachtypes", "atid='{$attachment_type['atid']}'");
  219. $plugins->run_hooks("admin_config_attachment_types_delete_commit");
  220. $cache->update_attachtypes();
  221. // Log admin action
  222. log_admin_action($attachment_type['atid'], htmlspecialchars_uni($attachment_type['extension']));
  223. flash_message($lang->success_attachment_type_deleted, 'success');
  224. admin_redirect("index.php?module=config-attachment_types");
  225. }
  226. else
  227. {
  228. $page->output_confirm_action("index.php?module=config-attachment_types&amp;action=delete&amp;atid={$attachment_type['atid']}", $lang->confirm_attachment_type_deletion);
  229. }
  230. }
  231. if(!$mybb->input['action'])
  232. {
  233. $page->output_header($lang->attachment_types);
  234. $sub_tabs['attachment_types'] = array(
  235. 'title' => $lang->attachment_types,
  236. 'link' => "index.php?module=config-attachment_types",
  237. 'description' => $lang->attachment_types_desc
  238. );
  239. $sub_tabs['add_attachment_type'] = array(
  240. 'title' => $lang->add_new_attachment_type,
  241. 'link' => "index.php?module=config-attachment_types&amp;action=add",
  242. );
  243. $plugins->run_hooks("admin_config_attachment_types_start");
  244. $page->output_nav_tabs($sub_tabs, 'attachment_types');
  245. $table = new Table;
  246. $table->construct_header($lang->extension, array("colspan" => 2));
  247. $table->construct_header($lang->mime_type);
  248. $table->construct_header($lang->maximum_size, array("class" => "align_center"));
  249. $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2));
  250. $query = $db->simple_select("attachtypes", "*", "", array('order_by' => 'extension'));
  251. while($attachment_type = $db->fetch_array($query))
  252. {
  253. // Just show default icons in ACP
  254. $attachment_type['icon'] = htmlspecialchars_uni(str_replace("{theme}", "images", $attachment_type['icon']));
  255. if(my_strpos($attachment_type['icon'], "p://") || substr($attachment_type['icon'], 0, 1) == "/")
  256. {
  257. $image = $attachment_type['icon'];
  258. }
  259. else
  260. {
  261. $image = "../".$attachment_type['icon'];
  262. }
  263. if(!$attachment_type['icon'] || $attachment_type['icon'] == "images/attachtypes/")
  264. {
  265. $attachment_type['icon'] = "&nbsp;";
  266. }
  267. else
  268. {
  269. $attachment_type['name'] = htmlspecialchars_uni($attachment_type['name']);
  270. $attachment_type['icon'] = "<img src=\"{$image}\" title=\"{$attachment_type['name']}\" alt=\"\" />";
  271. }
  272. $table->construct_cell($attachment_type['icon'], array("width" => 1));
  273. $table->construct_cell("<strong>.{$attachment_type['extension']}</strong>");
  274. $table->construct_cell(htmlspecialchars_uni($attachment_type['mimetype']));
  275. $table->construct_cell(get_friendly_size(($attachment_type['maxsize']*1024)), array("class" => "align_center"));
  276. $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"));
  277. $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"));
  278. $table->construct_row();
  279. }
  280. if($table->num_rows() == 0)
  281. {
  282. $table->construct_cell($lang->no_attachment_types, array('colspan' => 6));
  283. $table->construct_row();
  284. }
  285. $table->output($lang->attachment_types);
  286. $page->output_footer();
  287. }