From 3dad8ba1aac71fd090f6a83182d243fdb7982a14 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Fri, 11 Apr 2014 12:36:41 +1000 Subject: [PATCH] Display system report in SP submenu --- assets/css/admin.css | 30 + includes/admin/class-sp-admin-addons.php | 62 +++ includes/admin/class-sp-admin-menus.php | 36 ++ includes/admin/class-sp-admin-status.php | 86 +++ includes/admin/sp-admin-functions.php | 1 + .../admin/views/html-admin-page-addons.php | 35 ++ .../admin/views/html-admin-page-status.php | 523 ++++++++++++++++++ includes/sp-formatting-functions.php | 27 + 8 files changed, 800 insertions(+) create mode 100644 includes/admin/class-sp-admin-addons.php create mode 100644 includes/admin/class-sp-admin-status.php create mode 100644 includes/admin/views/html-admin-page-addons.php create mode 100644 includes/admin/views/html-admin-page-status.php diff --git a/assets/css/admin.css b/assets/css/admin.css index 32d4fe7f..bf7d1093 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -381,6 +381,36 @@ table.widefat select.sp-outcome { border-left-color: #464646; } +#debug-report { + display: none; + margin: 10px 0; + padding: 0; + position: relative; +} + +#debug-report textarea { + font-family: monospace; + width: 100%; + margin: 0; + height: 300px; + padding: 20px; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + resize: none; + font-size: 12px; + line-height: 20px; + outline: 0; +} + +table.sp_status_table td mark { + background: transparent none; +} + +table.sp_status_table td mark.yes { + color: #7ad03a; +} + /* Media Queries */ @media only screen and (max-width: 782px) { diff --git a/includes/admin/class-sp-admin-addons.php b/includes/admin/class-sp-admin-addons.php new file mode 100644 index 00000000..40cff639 --- /dev/null +++ b/includes/admin/class-sp-admin-addons.php @@ -0,0 +1,62 @@ + 'sportspress-addons-page', + 'timeout' => 3 + ) ); + + if ( ! is_wp_error( $raw_addons ) ) { + + $raw_addons = wp_remote_retrieve_body( $raw_addons ); + + // Get Products + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML( $raw_addons ); + + $addons = ''; + $xpath = new DOMXPath( $dom ); + $tags = $xpath->query('//ul[@class="products"]'); + foreach ( $tags as $tag ) { + $addons = $tag->ownerDocument->saveXML( $tag ); + break; + } + + if ( $addons ) + set_transient( 'sportspress_addons_html_' . $view, wp_kses_post( $addons ), 60*60*24*7 ); // Cached for a week + } + } + + include_once( 'views/html-admin-page-addons.php' ); + } +} + +endif; + +return new SP_Admin_Addons(); \ No newline at end of file diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php index 371cf007..a12ae47a 100644 --- a/includes/admin/class-sp-admin-menus.php +++ b/includes/admin/class-sp-admin-menus.php @@ -22,6 +22,11 @@ class SP_Admin_Menus { */ public function __construct() { add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 ); + add_action( 'admin_menu', array( $this, 'status_menu' ), 60 ); + + if ( apply_filters( 'sportspress_show_addons_page', false ) ) // Make true to display by default + add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 ); + add_action( 'admin_head', array( $this, 'menu_highlight' ) ); add_filter( 'menu_order', array( $this, 'menu_order' ) ); add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) ); @@ -39,6 +44,21 @@ class SP_Admin_Menus { $main_page = add_menu_page( __( 'SportsPress Settings', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), null, '51.5' ); } + /** + * Add menu item + */ + public function status_menu() { + add_submenu_page( 'sportspress', __( 'SportsPress Status', 'sportspress' ), __( 'System Status', 'sportspress' ) , 'manage_sportspress', 'sp-status', array( $this, 'status_page' ) ); + register_setting( 'sportspress_status_settings_fields', 'sportspress_status_options' ); + } + + /** + * Addons menu item + */ + public function addons_menu() { + add_submenu_page( 'sportspress', __( 'SportsPress Add-ons/Extensions', 'sportspress' ), __( 'Add-ons', 'sportspress' ) , 'manage_sportspress', 'sp-addons', array( $this, 'addons_page' ) ); + } + /** * Highlights the correct top level admin menu item for post type add screens. * @@ -117,6 +137,22 @@ class SP_Admin_Menus { return true; } + /** + * Init the status page + */ + public function status_page() { + $page = include( 'class-sp-admin-status.php' ); + $page->output(); + } + + /** + * Init the addons page + */ + public function addons_page() { + $page = include( 'class-sp-admin-addons.php' ); + $page->output(); + } + /** * Clean the SP menu items in admin. */ diff --git a/includes/admin/class-sp-admin-status.php b/includes/admin/class-sp-admin-status.php new file mode 100644 index 00000000..658b6069 --- /dev/null +++ b/includes/admin/class-sp-admin-status.php @@ -0,0 +1,86 @@ + 'Header Name') + */ + public function get_file_version( $file ) { + // We don't need to write to the file, so just open for reading. + $fp = fopen( $file, 'r' ); + + // Pull only the first 8kiB of the file in. + $file_data = fread( $fp, 8192 ); + + // PHP will close file handle, but we are good citizens. + fclose( $fp ); + + // Make sure we catch CR-only line endings. + $file_data = str_replace( "\r", "\n", $file_data ); + $version = ''; + + if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) + $version = _cleanup_header_comment( $match[1] ); + + return $version ; + } + + /** + * Scan the template files + * + * @access public + * @param string $template_path + * @return array + */ + public function scan_template_files( $template_path ) { + $files = scandir( $template_path ); + $result = array(); + if ( $files ) { + foreach ( $files as $key => $value ) { + if ( ! in_array( $value, array( ".",".." ) ) ) { + if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { + $sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); + foreach ( $sub_files as $sub_file ) { + $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; + } + } else { + $result[] = $value; + } + } + } + } + return $result; + } +} + +endif; + +return new SP_Admin_Status(); diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index dcc607a4..b33a2377 100644 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -19,6 +19,7 @@ function sp_get_screen_ids() { return apply_filters( 'sportspress_screen_ids', array( 'dashboard_page_sp-about', 'toplevel_page_sportspress', + 'sportspress_page_sp-status', 'edit-sp_result', 'sp_result', 'edit-sp_outcome', diff --git a/includes/admin/views/html-admin-page-addons.php b/includes/admin/views/html-admin-page-addons.php new file mode 100644 index 00000000..8653939c --- /dev/null +++ b/includes/admin/views/html-admin-page-addons.php @@ -0,0 +1,35 @@ +
+

+ + + +

+ + +
+ + + +

SportsPress Extensions Catalog', 'sportspress' ), 'http://themeboy.com/sportspress/extensions/' ); ?>

+ + +
\ No newline at end of file diff --git a/includes/admin/views/html-admin-page-status.php b/includes/admin/views/html-admin-page-status.php new file mode 100644 index 00000000..02d84c7f --- /dev/null +++ b/includes/admin/views/html-admin-page-status.php @@ -0,0 +1,523 @@ +
+

+
+
+

+

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '; + $posting['fsockopen_curl']['success'] = false; + } + + // SOAP + $posting['soap_client']['name'] = __( 'SOAP Client','sportspress' ); + if ( class_exists( 'SoapClient' ) ) { + $posting['soap_client']['note'] = __('Your server has the SOAP Client class enabled.', 'sportspress' ); + $posting['soap_client']['success'] = true; + } else { + $posting['soap_client']['note'] = sprintf( __( 'Your server does not have the SOAP Client class enabled - some gateway plugins which use SOAP may not work as expected.', 'sportspress' ), 'http://php.net/manual/en/class.soapclient.php' ) . ''; + $posting['soap_client']['success'] = false; + } + + $posting = apply_filters( 'sportspress_debug_posting', $posting ); + + foreach( $posting as $post ) { $mark = ( isset( $post['success'] ) && $post['success'] == true ) ? 'yes' : 'error'; + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {'Author URI'} == 'http://themeboy.com' ) : + + $theme_dir = substr( strtolower( str_replace( ' ','', $active_theme->Name ) ), 0, 45 ); + + if ( false === ( $theme_version_data = get_transient( $theme_dir . '_version_data' ) ) ) : + + $theme_changelog = wp_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $theme_dir . '/changelog.txt' ); + $cl_lines = explode( "\n", wp_remote_retrieve_body( $theme_changelog ) ); + if ( ! empty( $cl_lines ) ) : + + foreach ( $cl_lines as $line_num => $cl_line ) { + if ( preg_match( '/^[0-9]/', $cl_line ) ) : + + $theme_date = str_replace( '.' , '-' , trim( substr( $cl_line , 0 , strpos( $cl_line , '-' ) ) ) ); + $theme_version = preg_replace( '~[^0-9,.]~' , '' ,stristr( $cl_line , "version" ) ); + $theme_update = trim( str_replace( "*" , "" , $cl_lines[ $line_num + 1 ] ) ); + $theme_version_data = array( 'date' => $theme_date , 'version' => $theme_version , 'update' => $theme_update , 'changelog' => $theme_changelog ); + set_transient( $theme_dir . '_version_data', $theme_version_data , 60*60*12 ); + break; + + endif; + } + + endif; + + endif; + + endif; + ?> + + + + + + + + + + + + + + + + + + + + + + + + SP()->plugin_path() . '/templates/' ) ); + $found_files = array(); + + foreach ( $template_paths as $plugin_name => $template_path ) + $scanned_files[ $plugin_name ] = $this->scan_template_files( $template_path ); + + foreach ( $scanned_files as $plugin_name => $files ) { + foreach ( $files as $file ) { + if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { + $theme_file = get_stylesheet_directory() . '/' . $file; + } elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) { + $theme_file = get_stylesheet_directory() . '/sportspress/' . $file; + } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { + $theme_file = get_template_directory() . '/' . $file; + } elseif( file_exists( get_template_directory() . '/sportspress/' . $file ) ) { + $theme_file = get_template_directory() . '/sportspress/' . $file; + } else { + $theme_file = false; + } + + if ( $theme_file ) { + $core_version = $this->get_file_version( SP()->plugin_path() . '/templates/' . $file ); + $theme_version = $this->get_file_version( $theme_file ); + + if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { + $found_files[ $plugin_name ][] = sprintf( __( '%s version %s is out of date. The core version is %s', 'sportspress' ), basename( $theme_file ), $theme_version ? $theme_version : '-', $core_version ); + } else { + $found_files[ $plugin_name ][] = sprintf( '%s', basename( $theme_file ) ); + } + } + } + } + + if ( $found_files ) { + foreach ( $found_files as $plugin_name => $found_plugin_files ) { + ?> + + + + + + + + + +
:
:
:version ); ?>
:
:
:
:
:
:' . sprintf( __( '%s - We recommend setting memory to at least 64MB. See: Increasing memory allocated to PHP', 'sportspress' ), size_format( $memory ), 'http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP' ) . ''; + } else { + echo '' . size_format( $memory ) . ''; + } + ?>
:' . __( 'Yes', 'sportspress' ) . ''; else echo '' . __( 'No', 'sportspress' ) . ''; ?>
:
:
:
:
:
:
:' . sprintf( __( 'Default timezone is %s - it should be UTC', 'sportspress' ), $default_timezone ) . ''; + } else { + echo '' . sprintf( __( 'Default timezone is %s', 'sportspress' ), $default_timezone ) . ''; + } ?> +
: + + + +
:' . $plugin_name . ''; + } + + if ( strstr( $dirname, 'sportspress' ) ) { + + if ( false === ( $version_data = get_transient( md5( $plugin ) . '_version_data' ) ) ) { + $changelog = wp_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $dirname . '/changelog.txt' ); + $cl_lines = explode( "\n", wp_remote_retrieve_body( $changelog ) ); + if ( ! empty( $cl_lines ) ) { + foreach ( $cl_lines as $line_num => $cl_line ) { + if ( preg_match( '/^[0-9]/', $cl_line ) ) { + + $date = str_replace( '.' , '-' , trim( substr( $cl_line , 0 , strpos( $cl_line , '-' ) ) ) ); + $version = preg_replace( '~[^0-9,.]~' , '' ,stristr( $cl_line , "version" ) ); + $update = trim( str_replace( "*" , "" , $cl_lines[ $line_num + 1 ] ) ); + $version_data = array( 'date' => $date , 'version' => $version , 'update' => $update , 'changelog' => $changelog ); + set_transient( md5( $plugin ) . '_version_data', $version_data, 60*60*12 ); + break; + } + } + } + } + + if ( ! empty( $version_data['version'] ) && version_compare( $version_data['version'], $plugin_data['Version'], '>' ) ) + $version_string = ' – ' . $version_data['version'] . ' ' . __( 'is available', 'sportspress' ) . ''; + } + + $sp_plugins[] = $plugin_name . ' ' . __( 'by', 'sportspress' ) . ' ' . $plugin_data['Author'] . ' ' . __( 'version', 'sportspress' ) . ' ' . $plugin_data['Version'] . $version_string; + + } + } + + if ( sizeof( $sp_plugins ) == 0 ) + echo '-'; + else + echo implode( ',
', $sp_plugins ); + + ?>
:
: 'sp_result', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, 'post_status' => 'any' ) ); + foreach ( $posts as $post ) + $display_posts[] = $post->post_title . ' (' . $post->post_name . ') [' . $post->menu_order . ']'; + echo implode( ', ', array_map( 'esc_html', $display_posts ) ); + ?>
: 'sp_outcome', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, 'post_status' => 'any' ) ); + foreach ( $posts as $post ) + $display_posts[] = $post->post_title . ' (' . $post->post_name . ') [' . $post->menu_order . ']'; + echo implode( ', ', array_map( 'esc_html', $display_posts ) ); + ?>
: 'sp_column', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, 'post_status' => 'any' ) ); + foreach ( $posts as $post ) + $display_posts[] = $post->post_title . ' (' . $post->post_name . ') [' . $post->menu_order . ']'; + echo implode( ', ', array_map( 'esc_html', $display_posts ) ); + ?>
: 'sp_metric', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, 'post_status' => 'any' ) ); + foreach ( $posts as $post ) + $display_posts[] = $post->post_title . ' (' . $post->post_name . ') [' . $post->menu_order . ']'; + echo implode( ', ', array_map( 'esc_html', $display_posts ) ); + ?>
: 'sp_performance', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, 'post_status' => 'any' ) ); + foreach ( $posts as $post ) + $display_posts[] = $post->post_title . ' (' . $post->post_name . ') [' . $post->menu_order . ']'; + echo implode( ', ', array_map( 'esc_html', $display_posts ) ); + ?>
: 0 ) ); + foreach ( $terms as $term ) + $display_terms[] = $term->name . ' (' . $term->slug . ')'; + echo implode( ', ', array_map( 'esc_html', $display_terms ) ); + ?>
: 0 ) ); + foreach ( $terms as $term ) + $display_terms[] = $term->name . ' (' . $term->slug . ')'; + echo implode( ', ', array_map( 'esc_html', $display_terms ) ); + ?>
: 0 ) ); + foreach ( $terms as $term ) + $display_terms[] = $term->name . ' (' . $term->slug . ')'; + echo implode( ', ', array_map( 'esc_html', $display_terms ) ); + ?>
: 0 ) ); + foreach ( $terms as $term ) + $display_terms[] = $term->name . ' (' . $term->slug . ')'; + echo implode( ', ', array_map( 'esc_html', $display_terms ) ); + ?>
:Name; + ?>
:Version; + + if ( ! empty( $theme_version_data['version'] ) && version_compare( $theme_version_data['version'], $active_theme->Version, '!=' ) ) + echo ' – ' . $theme_version_data['version'] . ' ' . __( 'is available', 'sportspress' ) . ''; + ?>
:{'Author URI'}; + ?>
():', $found_plugin_files ); ?>:
+ + diff --git a/includes/sp-formatting-functions.php b/includes/sp-formatting-functions.php index 94083045..4316b5af 100644 --- a/includes/sp-formatting-functions.php +++ b/includes/sp-formatting-functions.php @@ -63,6 +63,33 @@ function sp_array_overlay( $a1, $a2 ) { return $a1; } +/** + * let_to_num function. + * + * This function transforms the php.ini notation for numbers (like '2M') to an integer. + * + * @access public + * @param $size + * @return int + */ +function sp_let_to_num( $size ) { + $l = substr( $size, -1 ); + $ret = substr( $size, 0, -1 ); + switch( strtoupper( $l ) ) { + case 'P': + $ret *= 1024; + case 'T': + $ret *= 1024; + case 'G': + $ret *= 1024; + case 'M': + $ret *= 1024; + case 'K': + $ret *= 1024; + } + return $ret; +} + /** * SportsPress Date Format - Allows to change date format for everything SportsPress *