PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ljmc-admin/admin.php

https://bitbucket.org/lpservice-it/ljmc
PHP | 361 lines | 159 code | 54 blank | 148 comment | 62 complexity | 821a10518b114f700faff557403c521f MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, MIT
  1. <?php
  2. /**
  3. * system Administration Bootstrap
  4. *
  5. * @package system
  6. * @subpackage Administration
  7. */
  8. /**
  9. * In system Administration Screens
  10. *
  11. * @since 2.3.2
  12. */
  13. if ( ! defined( 'LJMC_ADMIN' ) ) {
  14. define( 'LJMC_ADMIN', true );
  15. }
  16. if ( ! defined('LJMC_NETWORK_ADMIN') )
  17. define('LJMC_NETWORK_ADMIN', false);
  18. if ( ! defined('LJMC_USER_ADMIN') )
  19. define('LJMC_USER_ADMIN', false);
  20. if ( ! LJMC_NETWORK_ADMIN && ! LJMC_USER_ADMIN ) {
  21. define('LJMC_BLOG_ADMIN', true);
  22. }
  23. if ( isset($_GET['import']) && !defined('LJMC_LOAD_IMPORTERS') )
  24. define('LJMC_LOAD_IMPORTERS', true);
  25. require_once(dirname(dirname(__FILE__)) . '/load.php');
  26. nocache_headers();
  27. if ( get_option('db_upgraded') ) {
  28. flush_rewrite_rules();
  29. update_option( 'db_upgraded', false );
  30. /**
  31. * Fires on the next page load after a successful DB upgrade.
  32. *
  33. * @since 2.8.0
  34. */
  35. do_action( 'after_db_upgrade' );
  36. } elseif ( get_option('db_version') != $ljmc_db_version && empty($_POST) ) {
  37. if ( !is_multisite() ) {
  38. ljmc_redirect( admin_url( 'upgrade.php?_ljmc_http_referer=' . urlencode( ljmc_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
  39. exit;
  40. /**
  41. * Filter whether to attempt to perform the multisite DB upgrade routine.
  42. *
  43. * In single site, the user would be redirected to ljmc-admin/upgrade.php.
  44. * In multisite, the DB upgrade routine is automatically fired, but only
  45. * when this filter returns true.
  46. *
  47. * If the network is 50 sites or less, it will run every time. Otherwise,
  48. * it will throttle itself to reduce load.
  49. *
  50. * @since 3.0.0
  51. *
  52. * @param bool true Whether to perform the Multisite upgrade routine. Default true.
  53. */
  54. } elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
  55. $c = get_blog_count();
  56. /*
  57. * If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load:
  58. * attempt to do no more than threshold value, with some +/- allowed.
  59. */
  60. if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
  61. require_once( ABSPATH . LJMCINC . '/http.php' );
  62. $response = ljmc_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) );
  63. /** This action is documented in ljmc-admin/network/upgrade.php */
  64. do_action( 'after_mu_upgrade', $response );
  65. unset($response);
  66. }
  67. unset($c);
  68. }
  69. }
  70. require_once(ABSPATH . 'ljmc-admin/includes/admin.php');
  71. auth_redirect();
  72. // Schedule trash collection
  73. if ( !ljmc_next_scheduled('ljmc_scheduled_delete') && !defined('LJMC_INSTALLING') )
  74. ljmc_schedule_event(time(), 'daily', 'ljmc_scheduled_delete');
  75. set_screen_options();
  76. $date_format = get_option('date_format');
  77. $time_format = get_option('time_format');
  78. ljmc_enqueue_script( 'common' );
  79. // $pagenow is set in vars.php
  80. // $ljmc_importers is sometimes set in ljmc-admin/includes/import.php
  81. //
  82. // The remaining variables are imported as globals elsewhere,
  83. // declared as globals here
  84. global $pagenow, $ljmc_importers, $hook_suffix, $plugin_page, $typenow, $taxnow;
  85. $page_hook = null;
  86. $editing = false;
  87. if ( isset($_GET['page']) ) {
  88. $plugin_page = ljmc_unslash( $_GET['page'] );
  89. $plugin_page = plugin_basename($plugin_page);
  90. }
  91. if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
  92. $typenow = $_REQUEST['post_type'];
  93. else
  94. $typenow = '';
  95. if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
  96. $taxnow = $_REQUEST['taxonomy'];
  97. else
  98. $taxnow = '';
  99. if ( LJMC_NETWORK_ADMIN )
  100. require(ABSPATH . 'ljmc-admin/network/menu.php');
  101. elseif ( LJMC_USER_ADMIN )
  102. require(ABSPATH . 'ljmc-admin/user/menu.php');
  103. else
  104. require(ABSPATH . 'ljmc-admin/menu.php');
  105. if ( current_user_can( 'manage_options' ) ) {
  106. /**
  107. * Filter the maximum memory limit available for administration screens.
  108. *
  109. * This only applies to administrators, who may require more memory for tasks like updates.
  110. * Memory limits when processing images (uploaded or edited by users of any role) are
  111. * handled separately.
  112. *
  113. * The LJMC_MAX_MEMORY_LIMIT constant specifically defines the maximum memory limit available
  114. * when in the administration back-end. The default is 256M, or 256 megabytes of memory.
  115. *
  116. * @since 3.0.0
  117. *
  118. * @param string 'LJMC_MAX_MEMORY_LIMIT' The maximum system memory limit. Default 256M.
  119. */
  120. @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', LJMC_MAX_MEMORY_LIMIT ) );
  121. }
  122. /**
  123. * Fires as an admin screen or script is being initialized.
  124. *
  125. * Note, this does not just run on user-facing admin screens.
  126. * It runs on admin-ajax.php and admin-post.php as well.
  127. *
  128. * This is roughly analgous to the more general 'init' hook, which fires earlier.
  129. *
  130. * @since 2.5.0
  131. */
  132. do_action( 'admin_init' );
  133. if ( isset($plugin_page) ) {
  134. if ( !empty($typenow) )
  135. $the_parent = $pagenow . '?post_type=' . $typenow;
  136. else
  137. $the_parent = $pagenow;
  138. if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
  139. $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
  140. // Backwards compatibility for plugins using add_management_page().
  141. if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
  142. // There could be plugin specific params on the URL, so we need the whole query string
  143. if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
  144. $query_string = $_SERVER[ 'QUERY_STRING' ];
  145. else
  146. $query_string = 'page=' . $plugin_page;
  147. ljmc_redirect( admin_url('tools.php?' . $query_string) );
  148. exit;
  149. }
  150. }
  151. unset($the_parent);
  152. }
  153. $hook_suffix = '';
  154. if ( isset( $page_hook ) ) {
  155. $hook_suffix = $page_hook;
  156. } elseif ( isset( $plugin_page ) ) {
  157. $hook_suffix = $plugin_page;
  158. } elseif ( isset( $pagenow ) ) {
  159. $hook_suffix = $pagenow;
  160. }
  161. set_current_screen();
  162. // Handle plugin admin pages.
  163. if ( isset($plugin_page) ) {
  164. if ( $page_hook ) {
  165. /**
  166. * Fires before a particular screen is loaded.
  167. *
  168. * The load-* hook fires in a number of contexts. This hook is for plugin screens
  169. * where a callback is provided when the screen is registered.
  170. *
  171. * The dynamic portion of the hook name, `$page_hook`, refers to a mixture of plugin
  172. * page information including:
  173. * 1. The page type. If the plugin page is registered as a submenu page, such as for
  174. * Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'.
  175. * 2. A separator of '_page_'.
  176. * 3. The plugin basename minus the file extension.
  177. *
  178. * Together, the three parts form the `$page_hook`. Citing the example above,
  179. * the hook name used would be 'load-settings_page_pluginbasename'.
  180. *
  181. * @see get_plugin_page_hook()
  182. *
  183. * @since 2.1.0
  184. */
  185. do_action( 'load-' . $page_hook );
  186. if (! isset($_GET['noheader']))
  187. require_once(ABSPATH . 'ljmc-admin/admin-header.php');
  188. /**
  189. * Used to call the registered callback for a plugin screen.
  190. *
  191. * @ignore
  192. * @since 1.5.0
  193. */
  194. do_action( $page_hook );
  195. } else {
  196. if ( validate_file($plugin_page) )
  197. ljmc_die(__('Invalid plugin page'));
  198. if ( !( file_exists(LJMC_PLUGIN_DIR . "/$plugin_page") && is_file(LJMC_PLUGIN_DIR . "/$plugin_page") ) && !( file_exists(LJMCMU_PLUGIN_DIR . "/$plugin_page") && is_file(LJMCMU_PLUGIN_DIR . "/$plugin_page") ) )
  199. ljmc_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
  200. /**
  201. * Fires before a particular screen is loaded.
  202. *
  203. * The load-* hook fires in a number of contexts. This hook is for plugin screens
  204. * where the file to load is directly included, rather than the use of a function.
  205. *
  206. * The dynamic portion of the hook name, `$plugin_page`, refers to the plugin basename.
  207. *
  208. * @see plugin_basename()
  209. *
  210. * @since 1.5.0
  211. */
  212. do_action( 'load-' . $plugin_page );
  213. if ( !isset($_GET['noheader']))
  214. require_once(ABSPATH . 'ljmc-admin/admin-header.php');
  215. if ( file_exists(LJMCMU_PLUGIN_DIR . "/$plugin_page") )
  216. include(LJMCMU_PLUGIN_DIR . "/$plugin_page");
  217. else
  218. include(LJMC_PLUGIN_DIR . "/$plugin_page");
  219. }
  220. include(ABSPATH . 'ljmc-admin/admin-footer.php');
  221. exit();
  222. } elseif ( isset( $_GET['import'] ) ) {
  223. $importer = $_GET['import'];
  224. if ( ! current_user_can('import') )
  225. ljmc_die(__('You are not allowed to import.'));
  226. if ( validate_file($importer) ) {
  227. ljmc_redirect( admin_url( 'import.php?invalid=' . $importer ) );
  228. exit;
  229. }
  230. if ( ! isset($ljmc_importers[$importer]) || ! is_callable($ljmc_importers[$importer][2]) ) {
  231. ljmc_redirect( admin_url( 'import.php?invalid=' . $importer ) );
  232. exit;
  233. }
  234. /**
  235. * Fires before an importer screen is loaded.
  236. *
  237. * The dynamic portion of the hook name, `$importer`, refers to the importer slug.
  238. *
  239. * @since 3.5.0
  240. */
  241. do_action( 'load-importer-' . $importer );
  242. $parent_file = 'tools.php';
  243. $submenu_file = 'import.php';
  244. $title = __('Import');
  245. if (! isset($_GET['noheader']))
  246. require_once(ABSPATH . 'ljmc-admin/admin-header.php');
  247. require_once(ABSPATH . 'ljmc-admin/includes/upgrade.php');
  248. define('LJMC_IMPORTING', true);
  249. /**
  250. * Whether to filter imported data through kses on import.
  251. *
  252. * Multisite uses this hook to filter all data through kses by default,
  253. * as a super administrator may be assisting an untrusted user.
  254. *
  255. * @since 3.1.0
  256. *
  257. * @param bool false Whether to force data to be filtered through kses. Default false.
  258. */
  259. if ( apply_filters( 'force_filtered_html_on_import', false ) ) {
  260. kses_init_filters(); // Always filter imported data with kses on multisite.
  261. }
  262. call_user_func($ljmc_importers[$importer][2]);
  263. include(ABSPATH . 'ljmc-admin/admin-footer.php');
  264. // Make sure rules are flushed
  265. flush_rewrite_rules(false);
  266. exit();
  267. } else {
  268. /**
  269. * Fires before a particular screen is loaded.
  270. *
  271. * The load-* hook fires in a number of contexts. This hook is for core screens.
  272. *
  273. * The dynamic portion of the hook name, `$pagenow`, is a global variable
  274. * referring to the filename of the current page, such as 'admin.php',
  275. * 'post-new.php' etc. A complete hook for the latter would be
  276. * 'load-post-new.php'.
  277. *
  278. * @since 2.1.0
  279. */
  280. do_action( 'load-' . $pagenow );
  281. /*
  282. * The following hooks are fired to ensure backward compatibility.
  283. * In all other cases, 'load-' . $pagenow should be used instead.
  284. */
  285. if ( $typenow == 'page' ) {
  286. if ( $pagenow == 'post-new.php' )
  287. do_action( 'load-page-new.php' );
  288. elseif ( $pagenow == 'post.php' )
  289. do_action( 'load-page.php' );
  290. } elseif ( $pagenow == 'edit-tags.php' ) {
  291. if ( $taxnow == 'category' )
  292. do_action( 'load-categories.php' );
  293. elseif ( $taxnow == 'link_category' )
  294. do_action( 'load-edit-link-categories.php' );
  295. }
  296. }
  297. if ( ! empty( $_REQUEST['action'] ) ) {
  298. /**
  299. * Fires when an 'action' request variable is sent.
  300. *
  301. * The dynamic portion of the hook name, `$_REQUEST['action']`,
  302. * refers to the action derived from the `GET` or `POST` request.
  303. *
  304. * @since 2.6.0
  305. */
  306. do_action( 'admin_action_' . $_REQUEST['action'] );
  307. }