PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/jigoshop-admin.php

https://github.com/ThemesWpFr/jigoshop
PHP | 341 lines | 194 code | 82 blank | 65 comment | 45 complexity | 9010fa45ef71845b3c6914fea0c773c9 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Main admin file which loads all settings panels and sets up the menus.
  4. *
  5. * DISCLAIMER
  6. *
  7. * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
  8. * versions in the future. If you wish to customise Jigoshop core for your needs,
  9. * please use our GitHub repository to publish essential changes for consideration.
  10. *
  11. * @package Jigoshop
  12. * @category Admin
  13. * @author Jigowatt
  14. * @copyright Copyright Š 2011-2012 Jigowatt Ltd.
  15. * @license http://jigoshop.com/license/commercial-edition
  16. */
  17. require_once( 'jigoshop-install.php' );
  18. require_once( 'jigoshop-write-panels.php' );
  19. require_once( 'jigoshop-admin-settings-api.php' );
  20. require_once( 'jigoshop-admin-attributes.php' );
  21. require_once( 'jigoshop-admin-post-types.php' );
  22. require_once( 'jigoshop-admin-product-quick-bulk-edit.php' );
  23. require_once( 'jigoshop-admin-taxonomies.php' );
  24. // Contextual help only works for 3.3 due to updated API
  25. if ( get_bloginfo('version') >= '3.3' ) {
  26. require_once( 'jigoshop-admin-help.php' );
  27. }
  28. add_action('admin_notices', 'jigoshop_update');
  29. function jigoshop_update() {
  30. // Run database upgrade if required
  31. if ( is_admin() && get_site_option('jigoshop_db_version') < JIGOSHOP_VERSION ) {
  32. if ( isset($_GET['jigoshop_update_db']) && (bool) $_GET['jigoshop_update_db'] ) {
  33. require_once( jigoshop::plugin_path().'/jigoshop_upgrade.php' );
  34. $response = jigoshop_upgrade();
  35. } else {
  36. // Display upgrade nag
  37. echo '
  38. <div class="update-nag">
  39. '.sprintf(__('Your database needs an update for Jigoshop. Please <strong>backup</strong> &amp; %s.', 'jigoshop'), '<a href="' . add_query_arg('jigoshop_update_db', 'true') . '">' . __('update now', 'jigoshop') . '</a>').'
  40. </div>
  41. ';
  42. }
  43. }
  44. }
  45. /**
  46. * Admin Menus
  47. *
  48. * Sets up the admin menus in wordpress.
  49. *
  50. * @since 1.0
  51. */
  52. add_action('admin_menu', 'jigoshop_before_admin_menu', 9);
  53. function jigoshop_before_admin_menu() {
  54. global $menu;
  55. if ( current_user_can( 'manage_jigoshop' ) )
  56. $menu[54] = array( '', 'read', 'separator-jigoshop', '', 'wp-menu-separator jigoshop' );
  57. add_menu_page( __('Jigoshop'), __('Jigoshop'), 'manage_jigoshop', 'jigoshop', 'jigoshop_dashboard', null, 55);
  58. add_submenu_page('jigoshop', __('Dashboard', 'jigoshop'), __('Dashboard', 'jigoshop'), 'manage_jigoshop', 'jigoshop', 'jigoshop_dashboard');
  59. add_submenu_page('jigoshop', __('Reports','jigoshop'), __('Reports','jigoshop'), 'view_jigoshop_reports', 'jigoshop_reports', 'jigoshop_reports');
  60. add_submenu_page('edit.php?post_type=product', __('Attributes','jigoshop'), __('Attributes','jigoshop'), 'manage_product_terms', 'jigoshop_attributes', 'jigoshop_attributes');
  61. do_action('jigoshop_before_admin_menu');
  62. }
  63. add_action('admin_menu', 'jigoshop_after_admin_menu', 50);
  64. function jigoshop_after_admin_menu() {
  65. $admin_page = add_submenu_page( 'jigoshop', __( 'Settings' ), __( 'Settings' ), 'manage_jigoshop', 'jigoshop_settings', array( Jigoshop_Admin_Settings::instance(), 'output_markup' ) );
  66. add_action( 'admin_print_scripts-' . $admin_page, array( Jigoshop_Admin_Settings::instance(), 'settings_scripts' ) );
  67. add_action( 'admin_print_styles-' . $admin_page, array( Jigoshop_Admin_Settings::instance(), 'settings_styles' ) );
  68. add_submenu_page( 'jigoshop', __('System Information','jigoshop'), __('System Info','jigoshop'), 'manage_jigoshop', 'jigoshop_system_info', 'jigoshop_system_info');
  69. do_action('jigoshop_after_admin_menu');
  70. }
  71. function jigoshop_reports() {
  72. require_once( 'jigoshop-admin-reports.php' );
  73. $jigoshop_dashboard = new Jigoshop_reports();
  74. }
  75. function jigoshop_dashboard() {
  76. require_once( 'jigoshop-admin-dashboard.php' );
  77. $jigoshop_dashboard = new jigoshop_dashboard();
  78. }
  79. /**
  80. * Admin Head
  81. *
  82. * Outputs some styles in the admin <head> to show icons on the jigoshop admin pages
  83. *
  84. * @since 1.0
  85. */
  86. function jigoshop_admin_head() {
  87. ?>
  88. <style type="text/css">
  89. <?php if ( isset($_GET['taxonomy']) && $_GET['taxonomy']=='product_cat' ) : ?>
  90. .icon32-posts-product { background-position: -243px -5px !important; }
  91. <?php elseif ( isset($_GET['taxonomy']) && $_GET['taxonomy']=='product_tag' ) : ?>
  92. .icon32-posts-product { background-position: -301px -5px !important; }
  93. <?php endif; ?>
  94. </style>
  95. <?php
  96. }
  97. add_action('admin_head', 'jigoshop_admin_head');
  98. /**
  99. * System info
  100. *
  101. * Shows the system info panel which contains version data and debug info
  102. *
  103. * @since 1.0
  104. * @usedby jigoshop_settings()
  105. */
  106. function jigoshop_system_info() {
  107. ?>
  108. <div class="wrap jigoshop">
  109. <div class="icon32 icon32-jigoshop-debug" id="icon-jigoshop"><br/></div>
  110. <h2><?php _e('System Information','jigoshop') ?></h2>
  111. <p>Use the information below when submitting technical support requests via <a href="http://jigoshop.com/support/" title="Jigoshop Support" target="_blank">Jigoshop Support</a>.</p>
  112. <textarea readonly="readonly" id="system-info-textarea" title="To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).">
  113. ### Begin System Info ###
  114. Multi-site: <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
  115. SITE_URL: <?php echo site_url() . "\n"; ?>
  116. HOME_URL: <?php echo home_url() . "\n"; ?>
  117. Jigoshop Version: <?php echo jigoshop_get_plugin_data() . "\n"; ?>
  118. WordPress Version: <?php echo get_bloginfo('version') . "\n"; ?>
  119. <?php require_once('browser.php'); $browser = new Browser(); echo $browser ; ?>
  120. PHP Version: <?php echo PHP_VERSION . "\n"; ?>
  121. MySQL Version: <?php echo mysql_get_server_info() . "\n"; ?>
  122. Web Server Info: <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
  123. PHP Memory Limit: <?php echo ini_get('memory_limit') . "\n"; ?>
  124. PHP Post Max Size: <?php echo ini_get('post_max_size') . "\n"; ?>
  125. WP_DEBUG: <?php echo defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
  126. WP Table Prefix: <?php global $wpdb; echo "Length: ". strlen($wpdb->prefix); echo " Status:"; if (strlen($wpdb->prefix)>16){echo " ERROR: Too Long";} else {echo " Acceptable";} echo "\n"; ?>
  127. Show On Front: <?php echo get_option('show_on_front') . "\n" ?>
  128. Page On Front: <?php echo get_option('page_on_front') . "\n" ?>
  129. Page For Posts: <?php echo get_option('page_for_posts') . "\n" ?>
  130. Session: <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
  131. Session Name: <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
  132. Cookie Path: <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
  133. Save Path: <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
  134. Use Cookies: <?php echo (ini_get('session.use_cookies') ? 'On' : 'Off'); ?><?php echo "\n"; ?>
  135. Use Only Cookies: <?php echo (ini_get('session.use_only_cookies') ? 'On' : 'Off'); ?><?php echo "\n"; ?>
  136. UPLOAD_MAX_FILESIZE: <?php if(function_exists('phpversion')) echo (jigoshop_let_to_num(ini_get('upload_max_filesize'))/(1024*1024))."MB"; ?><?php echo "\n"; ?>
  137. POST_MAX_SIZE: <?php if(function_exists('phpversion')) echo (jigoshop_let_to_num(ini_get('post_max_size'))/(1024*1024))."MB"; ?><?php echo "\n"; ?>
  138. WordPress Memory Limit: <?php echo (jigoshop_let_to_num(WP_MEMORY_LIMIT)/(1024*1024))."MB"; ?><?php echo "\n"; ?>
  139. WP_DEBUG: <?php echo (WP_DEBUG) ? __('On', 'jigoshop') : __('Off', 'jigoshop'); ?><?php echo "\n"; ?>
  140. DISPLAY ERRORS: <?php echo (ini_get('display_errors')) ? 'On (' . ini_get('display_errors') . ')' : 'N/A'; ?><?php echo "\n"; ?>
  141. FSOCKOPEN: <?php echo (function_exists('fsockopen')) ? __('Your server supports fsockopen.', 'jigoshop') : __('Your server does not support fsockopen.', 'jigoshop'); ?><?php echo "\n"; ?>
  142. ACTIVE PLUGINS:
  143. <?php
  144. $plugins = get_plugins();
  145. $active_plugins = get_option('active_plugins', array());
  146. foreach ( $plugins as $plugin_path => $plugin ):
  147. //If the plugin isn't active, don't show it.
  148. if ( !in_array($plugin_path, $active_plugins) )
  149. continue;
  150. ?>
  151. <?php echo $plugin['Name']; ?>: <?php echo $plugin['Version']; ?>
  152. <?php endforeach; ?>
  153. CURRENT THEME:
  154. <?php
  155. if ( get_bloginfo('version') < '3.4' ) {
  156. $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css');
  157. echo $theme_data['Name'] . ': ' . $theme_data['Version'];
  158. } else {
  159. $theme_data = wp_get_theme();
  160. echo $theme_data->Name . ': ' . $theme_data->Version;
  161. }
  162. ?>
  163. ### End System Info ###
  164. </textarea>
  165. </div>
  166. </div>
  167. <?php
  168. }
  169. function jigoshop_get_plugin_data( $key = 'Version' ) {
  170. $data = get_plugin_data( jigoshop::plugin_path().'/jigoshop.php' );
  171. return $data[$key];
  172. }
  173. function jigoshop_feature_product() {
  174. if( !is_admin() ) die;
  175. if( !current_user_can('edit_posts') ) wp_die( __('You do not have sufficient permissions to access this page.') );
  176. // if( !check_admin_referer()) wp_die( __('You have taken too long. Please go back and retry.', 'jigoshop') );
  177. $post_id = isset($_GET['product_id']) && (int)$_GET['product_id'] ? (int)$_GET['product_id'] : '';
  178. if(!$post_id) die;
  179. $post = get_post($post_id);
  180. if(!$post) die;
  181. if($post->post_type !== 'product') die;
  182. $product = new jigoshop_product($post->ID);
  183. update_post_meta( $post->ID, 'featured', ! $product->is_featured() );
  184. $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
  185. wp_redirect( $sendback );
  186. exit;
  187. }
  188. add_action('wp_ajax_jigoshop-feature-product', 'jigoshop_feature_product');
  189. /**
  190. * Returns proper post_type
  191. */
  192. function jigoshop_get_current_post_type() {
  193. global $post, $typenow, $current_screen;
  194. if( $current_screen && @$current_screen->post_type ) return $current_screen->post_type;
  195. if( $typenow ) return $typenow;
  196. if( !empty($_REQUEST['post_type']) ) return sanitize_key( $_REQUEST['post_type'] );
  197. if ( !empty($post) && !empty($post->post_type) ) return $post->post_type;
  198. if( ! empty($_REQUEST['post']) && (int)$_REQUEST['post'] ) {
  199. $p = get_post( $_REQUEST['post'] );
  200. return $p ? $p->post_type : '';
  201. }
  202. return '';
  203. }
  204. /**
  205. * Categories ordering
  206. */
  207. /**
  208. * Load needed scripts to order categories
  209. */
  210. function jigoshop_categories_scripts() {
  211. if( !isset($_GET['taxonomy']) || $_GET['taxonomy'] !== 'product_cat') return;
  212. wp_register_script('jigoshop-categories-ordering', jigoshop::assets_url() . '/assets/js/categories-ordering.js', array('jquery-ui-sortable'));
  213. wp_print_scripts('jigoshop-categories-ordering');
  214. }
  215. add_action('admin_footer-edit-tags.php', 'jigoshop_categories_scripts');
  216. /**
  217. * Ajax request handling for categories ordering
  218. */
  219. function jigoshop_categories_ordering() {
  220. global $wpdb;
  221. $id = (int)$_POST['id'];
  222. $next_id = isset($_POST['nextid']) && (int) $_POST['nextid'] ? (int) $_POST['nextid'] : null;
  223. if( ! $id || ! $term = get_term_by('id', $id, 'product_cat') ) die(0);
  224. jigoshop_order_categories( $term, $next_id);
  225. $children = get_terms('product_cat', "child_of=$id&menu_order=ASC&hide_empty=0");
  226. if( $term && sizeof($children) ) {
  227. echo 'children';
  228. die;
  229. }
  230. }
  231. add_action('wp_ajax_jigoshop-categories-ordering', 'jigoshop_categories_ordering');
  232. if (!function_exists('boolval')) {
  233. /**
  234. * Helper function to get the boolean value of a variable. If not strict, this function will return true
  235. * if the variable is not false and not empty. If strict, the value of the variable must exactly match a
  236. * value in the true test array to evaluate to true
  237. *
  238. * @param $in The input variable
  239. * @param bool $strict
  240. * @return bool|null|string
  241. */
  242. function boolval($in, $strict = false) {
  243. if (is_bool($in)){
  244. return $in;
  245. }
  246. $in = strtolower($in);
  247. $out = null;
  248. if (in_array($in, array('false', 'no', 'n', 'off', '0', 0, null), true)) {
  249. $out = false;
  250. } else if ($strict) {
  251. if (in_array($in, array('true', 'yes', 'y', 'on', '1', 1), true)) {
  252. $out = true;
  253. }
  254. } else {
  255. $out = ($in ? true : false);
  256. }
  257. return $out;
  258. }
  259. }