From 5607e2ca79c2d20259286662a030a8877abeb615 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Mon, 25 Sep 2023 20:45:58 -0400 Subject: [PATCH] reestablish testable structure closes #67 --- acf/qmx-acf-collector.php | 345 ++++----- acf/qmx-acf-data.php | 41 +- acf/qmx-acf-output.php | 860 ++++++++++------------ constants/qmx-constants-collector.php | 68 +- constants/qmx-constants-data.php | 27 +- constants/qmx-constants-output.php | 172 ++--- files/qmx-files-collector.php | 88 +-- files/qmx-files-data.php | 27 +- files/qmx-files-output.php | 328 ++++----- heartbeat/qmx-heartbeat-collector.php | 316 ++++---- heartbeat/qmx-heartbeat-output.php | 168 ++--- image-sizes/qmx-image-sizes-collector.php | 462 ++++++------ image-sizes/qmx-image-sizes-data.php | 29 +- image-sizes/qmx-image-sizes-output.php | 254 +++---- paths/qmx-paths-collector.php | 288 ++++---- paths/qmx-paths-data.php | 27 +- paths/qmx-paths-output.php | 190 ++--- qmx-conditionals.php | 11 +- query-monitor-extend.php | 31 +- time/qmx-time-collector.php | 146 ++-- time/qmx-time-data.php | 27 +- time/qmx-time-output.php | 268 +++---- 22 files changed, 1707 insertions(+), 2466 deletions(-) diff --git a/acf/qmx-acf-collector.php b/acf/qmx-acf-collector.php index 578b3e3..4dbeead 100644 --- a/acf/qmx-acf-collector.php +++ b/acf/qmx-acf-collector.php @@ -1,259 +1,224 @@ data->local_json['save'] = get_stylesheet_directory() . '/acf-json'; } - if ( constant( 'QMX_DISABLED' ) ) { - return; + public function get_storage(): QM_Data { + require_once 'qmx-acf-data.php'; + return new QMX_Data_ACF(); } - class QMX_Collector_ACF extends QM_DataCollector { - - public $id = 'acf'; - - function __construct() { - parent::__construct(); - - add_action( 'acf/init', array( $this, 'action__acf_init' ) ); - - add_filter( 'acf/settings/load_json', array( $this, 'filter__acf_settings_load_json' ), 99999 ); - add_filter( 'acf/pre_load_value', array( $this, 'filter__acf_pre_load_value' ), 10, 3); - add_filter( 'acf/load_field_groups', array( $this, 'filter__acf_load_field_groups' ) ); - - // Set default value. Filter applied in output. - $this->data->local_json['save'] = get_stylesheet_directory() . '/acf-json'; - } + public function process() {} - public function get_storage(): QM_Data { - do_action( 'qmx/load_data/acf' ); - return new QMX_Data_ACF(); + public static function get_fields_group( $parent ) { + if ( is_null( $parent ) ) { + return null; } - public function process() {} + $group = acf_get_field_group( $parent ); - public static function get_fields_group( $parent ) { - if ( is_null( $parent ) ) { - return null; - } - - $group = acf_get_field_group( $parent ); - - if ( false === $group ) { - $field = acf_get_field( $parent ); - return static::get_fields_group( $field['parent'] ); - } - - return $group; + if ( false === $group ) { + $field = acf_get_field( $parent ); + return static::get_fields_group( $field['parent'] ); } - public function action__acf_init() : void { - $files = acf_get_local_json_files(); - $groups = array(); + return $group; + } - foreach ( $files as $group_key => $filepath ) { - $groups[ $group_key ] = acf_get_field_group( $group_key ); - } + public function action__acf_init() : void { + $files = acf_get_local_json_files(); + $groups = array(); - $this->data->local_json['groups'] = $groups; + foreach ( $files as $group_key => $filepath ) { + $groups[ $group_key ] = acf_get_field_group( $group_key ); } - public function filter__acf_settings_load_json( $paths ) { - if ( did_action( 'qm/cease' ) ) { - return $paths; - } - - $this->data->local_json['load'] = $paths; + $this->data->local_json['groups'] = $groups; + } + public function filter__acf_settings_load_json( $paths ) { + if ( did_action( 'qm/cease' ) ) { return $paths; } - protected static function get_start_trace_functions() { - $functions = null; + $this->data->local_json['load'] = $paths; - if ( ! is_null( $functions ) ) { - return $functions; - } + return $paths; + } - $functions = apply_filters( 'qmx/collector/acf/start_trace_functions', array( - 'get_field', - 'get_field_object', - 'have_rows', - ) ); + protected static function get_start_trace_functions() { + $functions = null; + if ( ! is_null( $functions ) ) { return $functions; } - public function filter__acf_pre_load_value( $short_circuit, $post_id, $field ) { - if ( did_action( 'qm/cease' ) ) { - return $short_circuit; - } - - $full_stack_trace = apply_filters( 'qmx/collector/acf/full_stack_trace', is_admin(), $post_id, $field ); - $trace = new QM_Backtrace( array( 'ignore_current_filter' => ! $full_stack_trace ) ); - - if ( false === $full_stack_trace ) { - foreach ($trace->get_trace() as $frame) { - if ( - in_array( $frame['function'], static::get_start_trace_functions() ) - && false === stripos( $frame['file'], ACF_PATH ) - ) { - break; - } - - if ( ! empty( $trace->get_trace()[1] ) ) { - $trace->ignore( 1 ); - } - } - } - - $row = array( - 'field' => $field, - 'post_id' => acf_get_valid_post_id( $post_id ), - 'trace' => $trace, - 'exists' => ! empty( $field['key'] ), - 'caller' => $trace->get_trace()[0], - 'group' => null, - 'hash' => null, - 'duplicate' => false, - ); + $functions = apply_filters( 'qmx/collector/acf/start_trace_functions', array( + 'get_field', + 'get_field_object', + 'have_rows', + ) ); - if ( ! empty( $field['key'] ) ) { - $row['group'] = static::get_fields_group( $field['parent'] ); - } + return $functions; + } - $hash = md5( json_encode( $row ) ); - $row['hash'] = $hash; + public function filter__acf_pre_load_value( $short_circuit, $post_id, $field ) { + if ( did_action( 'qm/cease' ) ) { + return $short_circuit; + } - if ( array_key_exists( $hash, $this->data->counts ) ) { - $this->data->counts[ $hash ]++; + $full_stack_trace = apply_filters( 'qmx/collector/acf/full_stack_trace', is_admin(), $post_id, $field ); + $trace = new QM_Backtrace( array( 'ignore_current_filter' => ! $full_stack_trace ) ); - if ( apply_filters( 'qmx/collector/acf/hide_duplicates', false ) ) { - return $short_circuit; + if ( false === $full_stack_trace ) { + foreach ($trace->get_trace() as $frame) { + if ( + in_array( $frame['function'], static::get_start_trace_functions() ) + && false === stripos( $frame['file'], ACF_PATH ) + ) { + break; } - $row['duplicate'] = true; + if ( ! empty( $trace->get_trace()[1] ) ) { + $trace->ignore( 1 ); + } } + } - if ( ! empty( $field['key'] ) ) { - $this->data->field_keys[ $field['key'] ] = $field['name']; - } else { - $this->data->field_keys[ $field['name'] ] = $field['name']; - } + $row = array( + 'field' => $field, + 'post_id' => acf_get_valid_post_id( $post_id ), + 'trace' => $trace, + 'exists' => ! empty( $field['key'] ), + 'caller' => $trace->get_trace()[0], + 'group' => null, + 'hash' => null, + 'duplicate' => false, + ); + + if ( ! empty( $field['key'] ) ) { + $row['group'] = static::get_fields_group( $field['parent'] ); + } - if ( ! empty( $row['group'] ) ) { - $this->data->field_groups[ $row['group']['key'] ] = $row['group']['title']; - } + $hash = md5( json_encode( $row ) ); + $row['hash'] = $hash; - $this->data->post_ids[ ( string ) $post_id ] = $post_id; - $this->data->callers[ $row['caller']['function'] . '()' ] = 1; - $this->data->counts[ $hash ] = 1; + if ( array_key_exists( $hash, $this->data->counts ) ) { + $this->data->counts[ $hash ]++; - $this->data->fields[] = $row; + if ( apply_filters( 'qmx/collector/acf/hide_duplicates', false ) ) { + return $short_circuit; + } - return $short_circuit; + $row['duplicate'] = true; } - public function filter__acf_load_field_groups( $field_groups ) { - static $processed = array(); - - if ( empty( $field_groups ) ) { - return $field_groups; - } - - $hash = wp_hash( json_encode( $field_groups ) ); + if ( ! empty( $field['key'] ) ) { + $this->data->field_keys[ $field['key'] ] = $field['name']; + } else { + $this->data->field_keys[ $field['name'] ] = $field['name']; + } - if ( in_array( $hash, $processed ) ) { - return; - } + if ( ! empty( $row['group'] ) ) { + $this->data->field_groups[ $row['group']['key'] ] = $row['group']['title']; + } - $processed[] = $hash; + $this->data->post_ids[ ( string ) $post_id ] = $post_id; + $this->data->callers[ $row['caller']['function'] . '()' ] = 1; + $this->data->counts[ $hash ] = 1; - foreach ( $field_groups as $field_group ) { - $key = wp_hash( json_encode( $field_group ) ); + $this->data->fields[] = $row; - if ( array_key_exists( $key, $this->data->loaded_field_groups ) ) { - continue; - } + return $short_circuit; + } - $this->data->loaded_field_groups[ $key ] = array( - 'id' => $field_group['ID'], - 'group' => $field_group['key'], - 'title' => $field_group['title'], - 'rules' => $field_group['location'], - ); - } + public function filter__acf_load_field_groups( $field_groups ) { + static $processed = array(); + if ( empty( $field_groups ) ) { return $field_groups; } - public function get_concerned_actions() { - $actions = array( - 'acf/init', - ); + $hash = wp_hash( json_encode( $field_groups ) ); - return $actions; + if ( in_array( $hash, $processed ) ) { + return; } - public function get_concerned_filters() { - $filters = array( - 'acf/is_field_group_key', - 'acf/is_field_key', - 'acf/load_field_group', - 'acf/pre_load_post_id', - 'acf/validate_post_id', - 'acf/pre_load_value', - 'acf/load_value', - 'acf/settings/load_json', - ); + $processed[] = $hash; - if ( is_admin() ) { - $filters = array_merge( $filters, array( - 'acf/settings/save_json', - 'acf/load_field_groups', - ) ); - } + foreach ( $field_groups as $field_group ) { + $key = wp_hash( json_encode( $field_group ) ); - sort( $filters, SORT_STRING ); + if ( array_key_exists( $key, $this->data->loaded_field_groups ) ) { + continue; + } - return $filters; + $this->data->loaded_field_groups[ $key ] = array( + 'id' => $field_group['ID'], + 'group' => $field_group['key'], + 'title' => $field_group['title'], + 'rules' => $field_group['location'], + ); } - public function get_concerned_constants() { - return array( - 'ACF_LITE', - ); + return $field_groups; + } + + public function get_concerned_actions() { + $actions = array( + 'acf/init', + ); + + return $actions; + } + + public function get_concerned_filters() { + $filters = array( + 'acf/is_field_group_key', + 'acf/is_field_key', + 'acf/load_field_group', + 'acf/pre_load_post_id', + 'acf/validate_post_id', + 'acf/pre_load_value', + 'acf/load_value', + 'acf/settings/load_json', + ); + + if ( is_admin() ) { + $filters = array_merge( $filters, array( + 'acf/settings/save_json', + 'acf/load_field_groups', + ) ); } + sort( $filters, SORT_STRING ); + + return $filters; + } + + public function get_concerned_constants() { + return array( + 'ACF_LITE', + ); } - QM_Collectors::add( new QMX_Collector_ACF ); } + +QM_Collectors::add( new QMX_Collector_ACF ); \ No newline at end of file diff --git a/acf/qmx-acf-data.php b/acf/qmx-acf-data.php index c3559ef..9f1301c 100644 --- a/acf/qmx-acf-data.php +++ b/acf/qmx-acf-data.php @@ -1,37 +1,16 @@ plugin_path( 'assets/query-monitor.css' ); + $bool = apply_filters( 'qmx/output/acf/identify_duplicates', false ); - if ( ! file_exists( $qm ) ) { - return; + return $bool; } - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); - - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) { - return; - } + public function output() { + $data = $this->collector->get_data(); - require_once $qm_dir . 'output/Html.php'; + $this->output_fields_table(); + $this->output_local_json(); + $this->output_concerns(); - class QMX_Output_Html_ACF extends QM_Output_Html { - - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - - add_filter( 'qm/output/panel_menus', array( $this, 'panel_menu' ), 60 ); + if ( is_admin() ) { + $this->output_field_groups_table(); } + } - public function name() { - return __( 'Advanced Custom Fields', 'query-monitor-extend' ); - } - - protected static function identify_duplicates() { - $bool = null; - - if ( ! is_null( $bool) ) { - return $bool; - } - - $bool = apply_filters( 'qmx/output/acf/identify_duplicates', false ); - - return $bool; - } - - public function output() { - $data = $this->collector->get_data(); - - $this->output_fields_table(); - $this->output_local_json(); - $this->output_concerns(); + protected function output_fields_table() { + $data = $this->collector->get_data(); - if ( is_admin() ) { - $this->output_field_groups_table(); - } + if ( empty( $data->fields ) ) { + $this->before_non_tabular_output(); + echo '

No Advanced Custom Fields found.

'; + $this->after_non_tabular_output(); + return; } - protected function output_fields_table() { - $data = $this->collector->get_data(); + echo ''; - if ( empty( $data->fields ) ) { - $this->before_non_tabular_output(); - echo '

No Advanced Custom Fields found.

'; - $this->after_non_tabular_output(); - return; - } - - echo ''; - - natsort( $data->field_keys ); - natsort( $data->post_ids ); - natsort( $data->field_groups ); - natsort( $data->callers ); + natsort( $data->field_keys ); + natsort( $data->post_ids ); + natsort( $data->field_groups ); + natsort( $data->callers ); - $this->before_tabular_output(); + $this->before_tabular_output(); - echo ''; - - echo ''; + echo ''; - echo ''; - echo $this->build_sorter( '#' ); - echo ''; - - echo ''; - echo $this->build_filter( - 'acf-field', - $data->field_keys, - __( 'Field', 'query-monitor' ), - array( - 'prepend' => array( - 'qmx-acf-no-field' => 'Missing', - ), - ) - ); - echo ''; + echo ''; - echo ''; - echo $this->build_filter( 'acf-post', $data->post_ids, __( 'Post ID', 'query-monitor' ) ); - echo ''; + echo ''; + echo $this->build_sorter( '#' ); + echo ''; - echo ''; - echo $this->build_filter( 'acf-group', $data->field_groups, __( 'Group', 'query-monitor' ) ); - echo ''; + echo ''; + echo $this->build_filter( + 'acf-field', + $data->field_keys, + __( 'Field', 'query-monitor' ), + array( + 'prepend' => array( + 'qmx-acf-no-field' => 'Missing', + ), + ) + ); + echo ''; - echo ''; - echo $this->build_filter( 'acf-caller', array_keys( $data->callers ), __( 'Caller', 'query-monitor' ) ); - echo ''; + echo ''; + echo $this->build_filter( 'acf-post', $data->post_ids, __( 'Post ID', 'query-monitor' ) ); + echo ''; - echo ''; + echo ''; + echo $this->build_filter( 'acf-group', $data->field_groups, __( 'Group', 'query-monitor' ) ); + echo ''; - echo ''; + echo ''; + echo $this->build_filter( 'acf-caller', array_keys( $data->callers ), __( 'Caller', 'query-monitor' ) ); + echo ''; - echo ''; + echo ''; - foreach ( $data->fields as $row_num => $row ) { - $row_attr = array( - 'class' => '', - ); + echo ''; - if ( ! $row['exists'] ) { - $row_attr['class'] .= ' qm-warn'; - } + echo ''; - $row_attr['data-qm-acf-field'] = $row['field']['name'] . ' ' . $row['field']['key']; - $row_attr['data-qm-acf-post'] = $row['post_id']; - $row_attr['data-qm-acf-caller'] = $row['caller']['function'] . '()'; - $row_attr['data-qm-acf-group'] = 'qmx-acf-no-group'; + foreach ( $data->fields as $row_num => $row ) { + $row_attr = array( + 'class' => '', + ); - if ( empty( $row['field']['key'] ) ) { - $row_attr['data-qm-acf-field'] .= ' qmx-acf-no-field'; - } + if ( ! $row['exists'] ) { + $row_attr['class'] .= ' qm-warn'; + } - if ( ! empty( $row['group'] ) ) { - $row_attr['data-qm-acf-group'] = $row['group']['key']; - } + $row_attr['data-qm-acf-field'] = $row['field']['name'] . ' ' . $row['field']['key']; + $row_attr['data-qm-acf-post'] = $row['post_id']; + $row_attr['data-qm-acf-caller'] = $row['caller']['function'] . '()'; + $row_attr['data-qm-acf-group'] = 'qmx-acf-no-group'; - if ( - ! empty( $row['duplicate'] ) - && static::identify_duplicates() - ) { - $row_attr['class'] .= ' qm-highlight'; - } + if ( empty( $row['field']['key'] ) ) { + $row_attr['data-qm-acf-field'] .= ' qmx-acf-no-field'; + } - $attr = ''; + if ( ! empty( $row['group'] ) ) { + $row_attr['data-qm-acf-group'] = $row['group']['key']; + } - foreach ( $row_attr as $a => $v ) { - $attr .= ' ' . $a . '="' . esc_attr( trim( $v ) ) . '"'; - } + if ( + ! empty( $row['duplicate'] ) + && static::identify_duplicates() + ) { + $row_attr['class'] .= ' qm-highlight'; + } - echo ''; + $attr = ''; - # Number - echo '' . esc_html( $row_num + 1 ) . ''; + foreach ( $row_attr as $a => $v ) { + $attr .= ' ' . $a . '="' . esc_attr( trim( $v ) ) . '"'; + } - # Field name - echo ''; - $this->output_column_field_name( $row ); - echo ''; + echo ''; - # Post ID - echo '' . esc_html( $row['post_id'] ) . ''; + # Number + echo '' . esc_html( $row_num + 1 ) . ''; - # Field group - echo ''; - $this->output_column_field_group( $row ); - echo ''; + # Field name + echo ''; + $this->output_column_field_name( $row ); + echo ''; - # Caller - echo ''; - $this->output_column_caller( $row ); - echo ''; + # Post ID + echo '' . esc_html( $row['post_id'] ) . ''; - echo ''; - } + # Field group + echo ''; + $this->output_column_field_group( $row ); + echo ''; - echo ''; + # Caller + echo ''; + $this->output_column_caller( $row ); + echo ''; - echo ''; - echo ''; - printf( 'Total: %d', count( $data->fields ) ); echo ''; - echo ''; - - echo ''; - echo ''; } - protected function output_field_groups_table() { - $id = 'qm-acf-loaded_field_groups'; - $name = 'Advanced Custom Fields: Loaded Field Groups'; - $data = $this->collector->get_data(); + echo ''; - printf( - '
', - esc_attr( $id ) - ); + echo ''; + echo ''; + printf( 'Total: %d', count( $data->fields ) ); + echo ''; + echo ''; - echo ''; + echo '
'; + echo '
'; + } - printf( - '

%2$s

', - esc_attr( $id ), - esc_html( $name ) - ); + protected function output_field_groups_table() { + $id = 'qm-acf-loaded_field_groups'; + $name = 'Advanced Custom Fields: Loaded Field Groups'; + $data = $this->collector->get_data(); - echo ''; + printf( + '
', + esc_attr( $id ) + ); - echo ''; + echo ''; - echo ''; + printf( + '', + esc_attr( $id ), + esc_html( $name ) + ); - echo ''; + echo ''; - echo ''; + echo ''; - echo ''; + echo ''; - echo ''; + echo ''; - echo ''; + echo ''; - $row_num = 1; + echo ''; - foreach ( $data->loaded_field_groups as $row ) { - $class = ''; + echo ''; - if ( 1 === $row_num % 2 ) { - $class = ' class="qm-odd"'; - } + echo ''; - echo ''; + $row_num = 1; - # Field group name - echo ''; + foreach ( $data->loaded_field_groups as $row ) { + $class = ''; - # Field group key - echo ''; + if ( 1 === $row_num % 2 ) { + $class = ' class="qm-odd"'; + } - # Field group rules - echo ''; + echo ''; - echo ''; - } + # Field group name + echo ''; - echo ''; + # Field group key + echo ''; - echo ''; - echo ''; - printf( '', count( $data->loaded_field_groups ) ); - echo ''; - echo ''; + # Field group rules + echo ''; - echo '
'; - echo esc_html__( 'Field Group', 'query-monitor-extend' ); - echo '

%2$s

'; - echo esc_html__( 'Key', 'query-monitor-extend' ); - echo '
'; - echo esc_html__( 'Rules', 'query-monitor-extend' ); - echo '
'; + echo esc_html__( 'Field Group', 'query-monitor-extend' ); + echo '
'; + echo esc_html__( 'Key', 'query-monitor-extend' ); + echo '
'; + echo esc_html__( 'Rules', 'query-monitor-extend' ); + echo '
'; - $this->output_column_field_group_title( $row ); - echo ''; - $this->output_column_field_group_key( $row ); - echo ''; - $this->output_column_field_group_rules( $row ); - echo '
'; + $this->output_column_field_group_title( $row ); + echo '
'; + $this->output_column_field_group_key( $row ); + echo '
Total: %d
'; + $this->output_column_field_group_rules( $row ); + echo '
'; - echo '
'; + echo ''; } - protected function output_column_field_name( array $row ) { - echo esc_html( $row['field']['name'] ); + echo ''; - if ( ! $row['exists'] ) { - echo ' (Missing)'; - return; - } + echo ''; + echo ''; + printf( 'Total: %d', count( $data->loaded_field_groups ) ); + echo ''; + echo ''; - if ( - ! empty( $row['duplicate'] ) - && static::identify_duplicates() - ) { - echo ' (Duplicate)'; - } + echo ''; + echo ''; + } - $parent = $row['field']['parent']; + protected function output_column_field_name( array $row ) { + echo esc_html( $row['field']['name'] ); - if ( ! empty( $row['group'] ) ) { - $parent = $row['group']['key']; - } + if ( ! $row['exists'] ) { + echo ' (Missing)'; + return; + } - echo self::build_toggler(); + if ( + ! empty( $row['duplicate'] ) + && static::identify_duplicates() + ) { + echo ' (Duplicate)'; + } - echo '
'; - echo esc_html( 'Key: ' . $row['field']['key'] ); - echo '
' . esc_html( 'Parent: ' . $parent ); - echo '
'; + $parent = $row['field']['parent']; + + if ( ! empty( $row['group'] ) ) { + $parent = $row['group']['key']; } - protected function output_column_field_group_title( array $row ) { - $title = $row['title']; + echo self::build_toggler(); - if ( empty( $title ) ) { - return; - } + echo '
'; + echo esc_html( 'Key: ' . $row['field']['key'] ); + echo '
' . esc_html( 'Parent: ' . $parent ); + echo '
'; + } - if ( empty( $row['id'] ) || ! current_user_can( 'edit_post', $row['id'] ) ) { - echo esc_html( $title ); - return; - } + protected function output_column_field_group_title( array $row ) { + $title = $row['title']; - $url = add_query_arg( array( - 'post' => $row['id'], - 'action' => 'edit', - ), admin_url( 'post.php' ) ); + if ( empty( $title ) ) { + return; + } - printf( - '%2$s%3$s', - esc_url( $url ), - esc_html( $title ), - QueryMonitor::icon( 'edit' ) - ); + if ( empty( $row['id'] ) || ! current_user_can( 'edit_post', $row['id'] ) ) { + echo esc_html( $title ); + return; } - protected function output_column_field_group_key( array $row ) { - $data = $this->collector->get_data(); - $group = $row['group']; + $url = add_query_arg( array( + 'post' => $row['id'], + 'action' => 'edit', + ), admin_url( 'post.php' ) ); + + printf( + '%2$s%3$s', + esc_url( $url ), + esc_html( $title ), + QueryMonitor::icon( 'edit' ) + ); + } - if ( empty( $group ) ) { - return; - } + protected function output_column_field_group_key( array $row ) { + $data = $this->collector->get_data(); + $group = $row['group']; - if ( - ! acf_is_local_field_group( $group ) - || ! array_key_exists( $group, $data->local_json['groups'] ) - ) { - echo esc_html( $group ); - return; - } + if ( empty( $group ) ) { + return; + } - $filepath = $data->local_json['groups'][ $group ]['local_file']; + if ( + ! acf_is_local_field_group( $group ) + || ! array_key_exists( $group, $data->local_json['groups'] ) + ) { + echo esc_html( $group ); + return; + } - if ( ! file_exists( $filepath ) ) { - echo esc_html( $group ); - return; - } + $filepath = $data->local_json['groups'][ $group ]['local_file']; - echo QM_Output_Html::output_filename( $group, $filepath ); + if ( ! file_exists( $filepath ) ) { + echo esc_html( $group ); + return; } - protected function output_column_field_group( array $row ) { - $group = $row['group']; - - if ( empty( $group ) ) { - return; - } + echo QM_Output_Html::output_filename( $group, $filepath ); + } - if ( empty( $group['ID'] ) || ! current_user_can( 'edit_post', $group['ID'] ) ) { - echo esc_html( $group['title'] ); - return; - } + protected function output_column_field_group( array $row ) { + $group = $row['group']; - $url = add_query_arg( array( - 'post' => $group['ID'], - 'action' => 'edit', - ), admin_url( 'post.php' ) ); + if ( empty( $group ) ) { + return; + } - printf( - '%2$s%3$s', - esc_url( $url ), - esc_html( $group['title'] ), - QueryMonitor::icon( 'edit' ) - ); + if ( empty( $group['ID'] ) || ! current_user_can( 'edit_post', $group['ID'] ) ) { + echo esc_html( $group['title'] ); + return; } - protected function output_column_field_group_rules( array $row ) { - $rules = $row['rules']; + $url = add_query_arg( array( + 'post' => $group['ID'], + 'action' => 'edit', + ), admin_url( 'post.php' ) ); + + printf( + '%2$s%3$s', + esc_url( $url ), + esc_html( $group['title'] ), + QueryMonitor::icon( 'edit' ) + ); + } - if ( empty( $rules ) ) { - return; - } + protected function output_column_field_group_rules( array $row ) { + $rules = $row['rules']; - echo '
';
-			print_r( $rules );
-			echo '
'; + if ( empty( $rules ) ) { + return; } - protected function output_column_caller( array $row ) { - $trace = $row['trace']; - $filtered_trace = $trace->get_display_trace(); - $caller_name = self::output_filename( $row['caller']['function'] . '()', $row['caller']['file'], $row['caller']['line'] ); - $stack = array(); - array_shift( $filtered_trace ); - - foreach ( $filtered_trace as $item ) { - $item = wp_parse_args( $item, array( - 'file' => '', - 'line' => '', - ) ); - - if ( empty( $item['display'] ) ) { - continue; - } - - $stack[] = self::output_filename( $item['display'], $item['file'], $item['line'] ); - } - - if ( 1 < count( $stack ) ) { - echo self::build_toggler(); - } + echo '
';
+		print_r( $rules );
+		echo '
'; + } - echo '
    '; - printf( '
  1. %s
  2. ', $caller_name ); + protected function output_column_caller( array $row ) { + $trace = $row['trace']; + $filtered_trace = $trace->get_display_trace(); + $caller_name = self::output_filename( $row['caller']['function'] . '()', $row['caller']['file'], $row['caller']['line'] ); + $stack = array(); + array_shift( $filtered_trace ); + + foreach ( $filtered_trace as $item ) { + $item = wp_parse_args( $item, array( + 'file' => '', + 'line' => '', + ) ); - if ( 1 < count( $stack ) ) { - echo '
  3. ' . implode( '
  4. ', $stack ) . '
  5. '; + if ( empty( $item['display'] ) ) { + continue; } - echo '
'; + $stack[] = self::output_filename( $item['display'], $item['file'], $item['line'] ); } - protected function output_local_json() { - $id = 'qm-acf-local_json'; - $name = 'Advanced Custom Fields: Local JSON'; - $data = $this->collector->get_data(); + if ( 1 < count( $stack ) ) { + echo self::build_toggler(); + } - printf( - '
', - esc_attr( $id ) - ); + echo '
    '; + printf( '
  1. %s
  2. ', $caller_name ); - echo ''; + if ( 1 < count( $stack ) ) { + echo '
  3. ' . implode( '
  4. ', $stack ) . '
  5. '; + } - printf( - '', - esc_attr( $id ), - esc_html( $name ), - 'Documentation' - ); + echo ''; + } - echo ''; + protected function output_local_json() { + $id = 'qm-acf-local_json'; + $name = 'Advanced Custom Fields: Local JSON'; + $data = $this->collector->get_data(); + + printf( + '
    ', + esc_attr( $id ) + ); + + echo '

    %2$s
    %3$s

    '; + + printf( + '', + esc_attr( $id ), + esc_html( $name ), + 'Documentation' + ); + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + + if ( ! empty( $data->local_json['save'] ) ) { + $directory = apply_filters( 'acf/settings/save_json', $data->local_json['save'] ); echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; echo ''; - echo ''; + } - echo ''; + if ( ! empty( $data->local_json['load'] ) ) { + $i = 0; - if ( ! empty( $data->local_json['save'] ) ) { - $directory = apply_filters( 'acf/settings/save_json', $data->local_json['save'] ); + foreach ( $data->local_json['load'] as $path ) { echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - if ( ! empty( $data->local_json['load'] ) ) { - $i = 0; - - foreach ( $data->local_json['load'] as $path ) { - echo ''; - - if ( 0 === $i ) { - echo ''; - echo ''; - } + if ( 0 === $i ) { + echo ''; + echo ''; + } - echo ''; - echo ''; + echo ''; + echo ''; - echo ''; + echo ''; - $i++; - } + $i++; } + } - echo ''; - echo '

    %2$s
    %3$s

    ActionHookPaths
    ActionHookPathsSaveacf/settings/save_json' . QM_Output_Html::output_filename( $this->remove_abspath( $directory ), $directory ) . '
    Saveacf/settings/save_json' . QM_Output_Html::output_filename( $this->remove_abspath( $directory ), $directory ) . '
    Loadacf/settings/load_jsonLoadacf/settings/load_json' . esc_html( $i ) . '' . QM_Output_Html::output_filename( $this->remove_abspath( $path ), $path ) . '' . esc_html( $i ) . '' . QM_Output_Html::output_filename( $this->remove_abspath( $path ), $path ) . '
    '; + echo ''; + echo ''; - $this->output_local_json_field_groups(); + $this->output_local_json_field_groups(); - echo '
'; - } + echo ''; + } - protected function output_local_json_field_groups() { - $data = $this->collector->get_data(); + protected function output_local_json_field_groups() { + $data = $this->collector->get_data(); - if ( empty( $data->local_json['groups'] ) ) { - echo '

No local JSON field groups found.

'; - return; - } + if ( empty( $data->local_json['groups'] ) ) { + echo '

No local JSON field groups found.

'; + return; + } - $groups = array(); + $groups = array(); - foreach ( $data->local_json['groups'] as $group ) { - $groups[ $group['title'] ] = $group; - } + foreach ( $data->local_json['groups'] as $group ) { + $groups[ $group['title'] ] = $group; + } - ksort( $groups, SORT_NATURAL ); + ksort( $groups, SORT_NATURAL ); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - foreach ( $groups as $group ) { - printf( - '', - esc_html( $group['title'] ), - esc_html( $group['key'] ), - QM_Output_HTML::output_filename( $this->remove_abspath( $group['local_file'] ), $group['local_file'] ) - ); - } + echo '

Field Groups

TitleKeyFile
%s%s%s
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - echo ''; - printf( '', count( $data->local_json['groups'] ) ); - echo '

Field Groups

TitleKeyFile
Total: %d
'; + foreach ( $groups as $group ) { + printf( + '%s%s%s', + esc_html( $group['title'] ), + esc_html( $group['key'] ), + QM_Output_HTML::output_filename( $this->remove_abspath( $group['local_file'] ), $group['local_file'] ) + ); } - public function remove_abspath( string $path ) : string { - return str_replace( ABSPATH, '', $path ); - } + echo ''; + printf( 'Total: %d', count( $data->local_json['groups'] ) ); + echo ''; + } - public function panel_menu( array $menu ) { - $data = $this->collector->get_data(); + public function remove_abspath( string $path ) : string { + return str_replace( ABSPATH, '', $path ); + } - if ( empty( $data->local_json['groups'] ) ) { - $data->local_json['groups'] = array(); - } + public function panel_menu( array $menu ) { + $data = $this->collector->get_data(); - $menu['qm-acf'] = $this->menu( array( - 'title' => esc_html__( 'Advanced Custom Fields', 'query-monitor-extend' ), - 'id' => 'query-monitor-extend-acf', - ) ); + if ( empty( $data->local_json['groups'] ) ) { + $data->local_json['groups'] = array(); + } - if ( is_admin() ) { - $menu['qm-acf']['children']['loaded_field_groups'] = array( - 'title' => esc_html__( 'Field Groups', 'query-monitor-extend' ) . sprintf( ' (%d)', count( $data->loaded_field_groups ) ), - 'href' => '#qm-acf-loaded_field_groups', - 'id' => 'query-monitor-extend-acf-loaded_field_groups', - ); - } + $menu['qm-acf'] = $this->menu( array( + 'title' => esc_html__( 'Advanced Custom Fields', 'query-monitor-extend' ), + 'id' => 'query-monitor-extend-acf', + ) ); - $menu['qm-acf']['children']['local_json'] = array( - 'title' => esc_html__('Local JSON', 'query-monitor-extend') . sprintf( ' (%d)', count( $data->local_json['groups'] ) ), - 'href' => '#qm-acf-local_json', - 'id' => 'query-monitor-extend-acf-local_json', + if ( is_admin() ) { + $menu['qm-acf']['children']['loaded_field_groups'] = array( + 'title' => esc_html__( 'Field Groups', 'query-monitor-extend' ) . sprintf( ' (%d)', count( $data->loaded_field_groups ) ), + 'href' => '#qm-acf-loaded_field_groups', + 'id' => 'query-monitor-extend-acf-loaded_field_groups', ); + } - return $menu; + $menu['qm-acf']['children']['local_json'] = array( + 'title' => esc_html__('Local JSON', 'query-monitor-extend') . sprintf( ' (%d)', count( $data->local_json['groups'] ) ), + 'href' => '#qm-acf-local_json', + 'id' => 'query-monitor-extend-acf-local_json', + ); - } + return $menu; } - add_filter( 'qm/outputter/html', static function( array $output ) : array { - if ( $collector = QM_Collectors::get( 'acf' ) ) { - $output['acf'] = new QMX_Output_Html_ACF( $collector ); - } +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function( array $output ) : array { + if ( $collector = QM_Collectors::get( 'acf' ) ) { + $output['acf'] = new QMX_Output_Html_ACF( $collector ); + } -}, 9 ); + return $output; +}, 70 ); \ No newline at end of file diff --git a/constants/qmx-constants-collector.php b/constants/qmx-constants-collector.php index fa716af..f9ec601 100644 --- a/constants/qmx-constants-collector.php +++ b/constants/qmx-constants-collector.php @@ -1,66 +1,32 @@ data['constants'] = $constants['user']; + public function process() { + if ( did_action( 'qm/cease' ) ) + return; - } + $constants = get_defined_constants( true ); + $this->data['constants'] = $constants['user']; } - add_filter( 'qm/collectors', static function ( array $collectors ) : array { - $collectors['constants'] = new QMX_Collector_Constants; - return $collectors; - } ); +} -} \ No newline at end of file +add_filter( 'qm/collectors', static function ( array $collectors ) : array { + $collectors['constants'] = new QMX_Collector_Constants; + return $collectors; +} ); \ No newline at end of file diff --git a/constants/qmx-constants-data.php b/constants/qmx-constants-data.php index c935c93..d687608 100644 --- a/constants/qmx-constants-data.php +++ b/constants/qmx-constants-data.php @@ -1,30 +1,9 @@ collector->get_data(); - /** Back-compat filter. Please use `qm/dispatch/html` instead */ - if ( ! apply_filters( 'qm/process', true, is_admin_bar_showing() ) ) { - return; - } + echo '
'; - $qm = QueryMonitor::init()->plugin_path( 'assets/query-monitor.css' ); + if ( !empty( $data->constants ) ) { + echo ''; + echo ''; + echo ''; + echo ''; - if ( ! file_exists( $qm ) ) { - return; - } + echo ''; - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); + echo ''; - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) - return; + echo ''; - require_once $qm_dir . 'output/Html.php'; + echo ''; - class QMX_Output_Html_Constants extends QM_Output_Html { + echo ''; + echo ''; - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); - } + echo ''; - public function output() { - $data = $this->collector->get_data(); + $i = 1; + $bools = array( true => 'true', false => 'false' ); - echo '
'; - - if ( !empty( $data->constants ) ) { - echo '
' . esc_html( $this->collector->name() ) . '
'; + echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_sorter( __( 'Constant', 'query-monitor-extend' ) ); + echo ''; + echo __( 'Value', 'query-monitor-extend' ); + echo ''; + echo $this->build_sorter( __( 'Type', 'query-monitor-extend' ) ); + echo '
'; - echo ''; - echo ''; + foreach ( $data->constants as $constant => $value ) { echo ''; - - echo ''; - - echo ''; - - echo ''; - - echo ''; - + echo ''; + echo ''; + echo ''; + echo ''; echo ''; - echo ''; - - echo ''; + } - $i = 1; - $bools = array( true => 'true', false => 'false' ); + echo ''; + echo ''; - foreach ( $data->constants as $constant => $value ) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } + echo ''; + echo '
' . esc_html( $this->collector->name() ) . '
'; - echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); - echo ''; - echo $this->build_sorter( __( 'Constant', 'query-monitor-extend' ) ); - echo ''; - echo __( 'Value', 'query-monitor-extend' ); - echo ''; - echo $this->build_sorter( __( 'Type', 'query-monitor-extend' ) ); - echo '' . $i++ . '' . esc_html( $constant ) . '' . esc_html( QM_Util::display_variable( $value ) ) . '' . esc_html( gettype( $value ) ) . '
' . $i++ . '' . esc_html( $constant ) . '' . esc_html( QM_Util::display_variable( $value ) ) . '' . esc_html( gettype( $value ) ) . '
'; - echo ''; - echo ''; + } else { - echo ''; - echo ''; + echo '
'; + echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; + echo '
'; - } else { + } - echo '
'; - echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; - echo '
'; - - } - - echo '
'; - } - - public function panel_menu( array $menu ) { - $menu['constants'] = $this->menu( array( - 'title' => esc_html__( 'Constants', 'query-monitor-extend' ), - 'id' => 'query-monitor-extend-constants', - ) ); + echo ''; + } - return $menu; - } + public function panel_menu( array $menu ) { + $menu['constants'] = $this->menu( array( + 'title' => esc_html__( 'Constants', 'query-monitor-extend' ), + 'id' => 'query-monitor-extend-constants', + ) ); + return $menu; } - add_filter( 'qm/outputter/html', static function ( array $output ) : array { - if ( $collector = QM_Collectors::get( 'constants' ) ) - $output['constants'] = new QMX_Output_Html_Constants( $collector ); +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function ( array $output ) : array { + if ( $collector = QM_Collectors::get( 'constants' ) ) + $output['constants'] = new QMX_Output_Html_Constants( $collector ); -}, 9 ); \ No newline at end of file + return $output; +}, 70 ); \ No newline at end of file diff --git a/files/qmx-files-collector.php b/files/qmx-files-collector.php index 38a666e..75bb2ec 100644 --- a/files/qmx-files-collector.php +++ b/files/qmx-files-collector.php @@ -1,78 +1,44 @@ get_data(); - $files_with_errors = array(); + public function process() { + if ( did_action( 'qm/cease' ) ) + return; - if ( !empty( $php_errors['errors'] ) ) - foreach ( $php_errors['errors'] as $type => $errors ) - foreach ( $errors as $error ) - $files_with_errors[$error['file']] = 1; + $php_errors = QM_Collectors::get( 'php_errors' )->get_data(); + $files_with_errors = array(); - foreach ( get_included_files() as $i => $filepath ) - $this->data->files[] = array( - 'path' => $filepath, - 'component' => QM_Util::get_file_component( $filepath ), - 'has_error' => array_key_exists( $filepath, $files_with_errors ), - ); + if ( !empty( $php_errors['errors'] ) ) + foreach ( $php_errors['errors'] as $type => $errors ) + foreach ( $errors as $error ) + $files_with_errors[$error['file']] = 1; - } + foreach ( get_included_files() as $i => $filepath ) + $this->data->files[] = array( + 'path' => $filepath, + 'component' => QM_Util::get_file_component( $filepath ), + 'has_error' => array_key_exists( $filepath, $files_with_errors ), + ); } - add_filter( 'qm/collectors', static function ( array $collectors ) : array { - $collectors['files'] = new QMX_Collector_Files; - return $collectors; - } ); +} -} \ No newline at end of file +add_filter( 'qm/collectors', static function ( array $collectors ) : array { + $collectors['files'] = new QMX_Collector_Files; + return $collectors; +} ); \ No newline at end of file diff --git a/files/qmx-files-data.php b/files/qmx-files-data.php index bfb5345..cb6e2d8 100644 --- a/files/qmx-files-data.php +++ b/files/qmx-files-data.php @@ -1,30 +1,9 @@ plugin_path( 'assets/query-monitor.css' ); - - if ( ! file_exists( $qm ) ) { - return; - } - - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); + public function output() { + $data = $this->collector->get_data(); - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) - return; + echo '
'; - require_once $qm_dir . 'output/Html.php'; - - class QMX_Output_Html_Files extends QM_Output_Html { - - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - - add_filter( 'qm/output/title', array( &$this, 'admin_title' ), 40 ); - add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); - } - - public function output() { - $data = $this->collector->get_data(); - - echo '
'; - - if ( !empty( $data->files ) ) { - $files_with_errors = 0; - $path_components = $components = array(); - - $largest_file = array( - 'path' => null, - 'size' => 0 - ); - - foreach ( $data->files as &$file ) { - $file['_path_components'] = array(); - - foreach ( array_filter( explode( '/', str_replace( ABSPATH, '', dirname( $file['path'] ) ) ) ) as $path_component ) { - $path_components[$path_component] - = $file['_path_components'][$path_component] + if ( !empty( $data->files ) ) { + $files_with_errors = 0; + $path_components = $components = array(); + + $largest_file = array( + 'path' => null, + 'size' => 0 + ); + + foreach ( $data->files as &$file ) { + $file['_path_components'] = array(); + + foreach ( array_filter( explode( '/', str_replace( ABSPATH, '', dirname( $file['path'] ) ) ) ) as $path_component ) { + $path_components[$path_component] + = $file['_path_components'][$path_component] + = 1; + foreach ( explode( '-', $path_component ) as $smaller_path_component ) + $path_components[$smaller_path_component] + = $file['_path_components'][$smaller_path_component] = 1; - foreach ( explode( '-', $path_component ) as $smaller_path_component ) - $path_components[$smaller_path_component] - = $file['_path_components'][$smaller_path_component] - = 1; - } - - $filesize = @filesize( $file['path'] ); + } - if ( empty( $filesize ) ) { - $filesize = 0; - } + $filesize = @filesize( $file['path'] ); - if ( $filesize > $largest_file['size'] ) { - $largest_file = array( - 'path' => $file['path'], - 'size' => filesize( $file['path'] ), - ); - } - - $components[$file['component']->name] = 1; + if ( empty( $filesize ) ) { + $filesize = 0; } - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; + if ( $filesize > $largest_file['size'] ) { + $largest_file = array( + 'path' => $file['path'], + 'size' => filesize( $file['path'] ), + ); + } - echo ''; + $components[$file['component']->name] = 1; + } - echo ''; + echo '
' . esc_html( $this->collector->name() ) . '
'; - echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); - echo ''; - echo $this->build_filter( 'path', array_map( 'esc_attr', array_keys( $path_components ) ), __( 'Path', 'query-monitor-extend' ) ); - echo ''; - echo $this->build_sorter( __( 'Filesize', 'query-monitor-extend' ) ); - echo '
'; + echo ''; + echo ''; + echo ''; - echo ''; + echo ''; - echo ''; - echo ''; + echo ''; - echo ''; + echo ''; - $total_file_size = 0; + echo ''; - foreach ( $data->files as $i => $file ) { + echo ''; + echo ''; - $filesize = @filesize( $file['path'] ); + echo ''; - if ( empty( $filesize ) ) { - $filesize = 0; - } + $total_file_size = 0; - $total_file_size += $filesize; + foreach ( $data->files as $i => $file ) { - if ( !empty( $file['has_error'] ) ) - $files_with_errors++; + $filesize = @filesize( $file['path'] ); - echo ''; + if ( empty( $filesize ) ) { + $filesize = 0; + } - echo ''; - echo ''; - echo ''; + $total_file_size += $filesize; - echo ''; - echo ''; - } + if ( !empty( $file['has_error'] ) ) + $files_with_errors++; - echo ''; - echo ''; + echo ''; - echo ''; - echo ''; + echo ''; + echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; echo ''; + } - echo ''; - echo '
' . esc_html( $this->collector->name() ) . '
'; - echo $this->build_filter( 'component', array_map( 'esc_attr', array_keys( $components ) ), __( 'Component', 'query-monitor-extend' ) ); - echo ''; + echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); + echo '
'; + echo $this->build_filter( 'path', array_map( 'esc_attr', array_keys( $path_components ) ), __( 'Path', 'query-monitor-extend' ) ); + echo '
'; + echo $this->build_sorter( __( 'Filesize', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_filter( 'component', array_map( 'esc_attr', array_keys( $components ) ), __( 'Component', 'query-monitor-extend' ) ); + echo '
' . ( $i + 1 ) . '' . QM_Output_Html::output_filename( str_replace( ABSPATH, '', $file['path'] ), $file['path'] ) . ''; - echo ! empty( $filesize ) ? $this->human_file_size( $filesize ) : '—'; - echo '' . esc_html( $file['component']->name ) . '
'; - printf( - esc_html__( 'Files in filter: %s', 'query-monitor-extend' ), - '' . esc_html( number_format_i18n( count( $data->files ) ) ) . '' - ); + echo '' . ( $i + 1 ) . '' . QM_Output_Html::output_filename( str_replace( ABSPATH, '', $file['path'] ), $file['path'] ) . ''; + echo ! empty( $filesize ) ? $this->human_file_size( $filesize ) : '—'; echo '
' . - 'Total: ' . esc_html( number_format_i18n( count( $data->files ) ) ) . '' . - ( - !empty( $files_with_errors ) - ? ', With error(s): ' . esc_html( number_format_i18n( $files_with_errors ) ) . '' - : '' - ) . - '=' . $this->human_file_size( $total_file_size ) . 'Components: ' . count( $components ) . '' . esc_html( $file['component']->name ) . '
'; + echo ''; + echo ''; - echo ''; + echo ''; + echo ''; + printf( + esc_html__( 'Files in filter: %s', 'query-monitor-extend' ), + '' . esc_html( number_format_i18n( count( $data->files ) ) ) . '' + ); + echo ''; + echo ''; - } else { + echo ''; + echo '' . + 'Total: ' . esc_html( number_format_i18n( count( $data->files ) ) ) . '' . + ( + !empty( $files_with_errors ) + ? ', With error(s): ' . esc_html( number_format_i18n( $files_with_errors ) ) . '' + : '' + ) . + ''; + echo '=' . $this->human_file_size( $total_file_size ) . ''; + echo 'Components: ' . count( $components ) . ''; + echo ''; - echo '
'; - echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; - echo '
'; + echo ''; + echo ''; - } + echo ''; - echo '
'; - } + } else { - public function admin_title( array $title ) { - $data = $this->collector->get_data(); + echo '
'; + echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; + echo '
'; - if ( !empty( $data->files ) ) { - $_title = sprintf( esc_html_x( '%s F', 'Files count', 'query-monitor-extend' ), number_format_i18n( count( $data->files ) ) ); - $_title = preg_replace( '#\s?([^0-9,\.]+)#', '$1', $_title ); - $title[] = $_title; } - return $title; + echo '
'; + } + + public function admin_title( array $title ) { + $data = $this->collector->get_data(); + if ( !empty( $data->files ) ) { + $_title = sprintf( esc_html_x( '%s F', 'Files count', 'query-monitor-extend' ), number_format_i18n( count( $data->files ) ) ); + $_title = preg_replace( '#\s?([^0-9,\.]+)#', '$1', $_title ); + $title[] = $_title; } - public function panel_menu( array $menu ) { + return $title; - $menu['files'] = $this->menu( array( - 'title' => esc_html__( 'Files', 'query-monitor-extend' ), - 'id' => 'query-monitor-extend-files', - ) ); + } - return $menu; + public function panel_menu( array $menu ) { - } + $menu['files'] = $this->menu( array( + 'title' => esc_html__( 'Files', 'query-monitor-extend' ), + 'id' => 'query-monitor-extend-files', + ) ); - private function human_file_size( $bytes ) { - $filesize_units = 'BKMGTP'; - $factor = ( int ) floor( ( strlen( $bytes ) - 1 ) / 3 ); - return sprintf( "%.2f", $bytes / pow( 1024, $factor ) ) . @$filesize_units[$factor]; - } + return $menu; + + } + private function human_file_size( $bytes ) { + $filesize_units = 'BKMGTP'; + $factor = ( int ) floor( ( strlen( $bytes ) - 1 ) / 3 ); + return sprintf( "%.2f", $bytes / pow( 1024, $factor ) ) . @$filesize_units[$factor]; } - add_filter( 'qm/outputter/html', static function ( array $output ) : array { - if ( $collector = QM_Collectors::get( 'files' ) ) - $output['files'] = new QMX_Output_Html_Files( $collector ); +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function ( array $output ) : array { + if ( $collector = QM_Collectors::get( 'files' ) ) + $output['files'] = new QMX_Output_Html_Files( $collector ); -}, 9 ); \ No newline at end of file + return $output; +}, 70 ); \ No newline at end of file diff --git a/heartbeat/qmx-heartbeat-collector.php b/heartbeat/qmx-heartbeat-collector.php index 5e7454a..b39fd19 100644 --- a/heartbeat/qmx-heartbeat-collector.php +++ b/heartbeat/qmx-heartbeat-collector.php @@ -1,214 +1,180 @@ qm_no_jquery() ) + return; - remove_action( 'plugin_loaded', __FUNCTION__ ); + add_action( 'wp_enqueue_scripts', array( &$this, 'add_inline_script' ) ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_inline_script' ) ); + } - if ( !class_exists( 'QueryMonitor' ) ) - return; + public function add_inline_script() { + if ( did_action( 'qm/cease' ) ) + return; - if ( defined( 'QM_DISABLED' ) && constant( 'QM_DISABLED' ) ) { - return; + wp_add_inline_script( 'heartbeat', $this->_inlineScript_heartbeat() ); } - if ( constant( 'QMX_DISABLED' ) ) { - return; - } + public function _inlineScript_heartbeat() { + ob_start(); + ?> - class QMX_Collector_Heartbeat extends QM_Collector { + var qmx_heartbeat = { - public $id = 'heartbeat'; + _beat: null, + _beats: [], + _start: 0, + _table: null, + _tab: null, + _table_ready: false, - function __construct() { - parent::__construct(); + _prev_dub: 0, - if ( $this->qm_no_jquery() ) - return; + init: function() { - add_action( 'wp_enqueue_scripts', array( &$this, 'add_inline_script' ) ); - add_action( 'admin_enqueue_scripts', array( &$this, 'add_inline_script' ) ); - } + var that = this; + var d = new Date(); + this._start = d.getTime(); - public function add_inline_script() { - if ( did_action( 'qm/cease' ) ) - return; + jQuery( document ).on( 'heartbeat-send', function() { + var d = new Date(); + var lub = d.getTime(); - wp_add_inline_script( 'heartbeat', $this->_inlineScript_heartbeat() ); - } + if ( !that._table_ready ) { + that._beat = { lub: lub }; + return; + } - public function _inlineScript_heartbeat() { - ob_start(); - ?> + var count = ( that._beats.find( 'tr' ).length + 1 ); - var qmx_heartbeat = { + if ( + 2 == count + && that._beats.find( 'tr' ).hasClass( 'listening' ) + ) { + that._beats.html( '' ); + count = 1; + } - _beat: null, - _beats: [], - _start: 0, - _table: null, - _tab: null, - _table_ready: false, + that.add_table_row( that.get_table_row( + count, + lub, + '', + ( + 0 == that._prev_dub + ? '-' + : ( lub - that._prev_dub ) + ), + '-' + ) ); + that.update_tab( count ); + that._beat = that._beats.find( 'tr:first-child' ); + } ); + + jQuery( document ).on( 'heartbeat-tick', function() { + var d = new Date(); + var dub = d.getTime(); - _prev_dub: 0, + if ( !that._table_ready ) { + that._beat.dub = dub; + that['_beats'].push( that._beat ); + that._beat = null; + return; + } - init: function() { + var dub_secs = ( dub - that._start ) / 1000; + var duration = ( ( ( dub - that._start ) / 1000 ) - parseFloat( that._beat.find( 'td.lub' ).text() ) ); - var that = this; - var d = new Date(); - this._start = d.getTime(); - - jQuery( document ).on( 'heartbeat-send', function() { - var d = new Date(); - var lub = d.getTime(); - - if ( !that._table_ready ) { - that._beat = { lub: lub }; - return; - } - - var count = ( that._beats.find( 'tr' ).length + 1 ); - - if ( - 2 == count - && that._beats.find( 'tr' ).hasClass( 'listening' ) - ) { - that._beats.html( '' ); - count = 1; - } - - that.add_table_row( that.get_table_row( - count, - lub, - '', - ( - 0 == that._prev_dub - ? '-' - : ( lub - that._prev_dub ) - ), - '-' - ) ); - that.update_tab( count ); - that._beat = that._beats.find( 'tr:first-child' ); - } ); - - jQuery( document ).on( 'heartbeat-tick', function() { - var d = new Date(); - var dub = d.getTime(); - - if ( !that._table_ready ) { - that._beat.dub = dub; - that['_beats'].push( that._beat ); - that._beat = null; - return; - } - - var dub_secs = ( dub - that._start ) / 1000; - var duration = ( ( ( dub - that._start ) / 1000 ) - parseFloat( that._beat.find( 'td.lub' ).text() ) ); - - that._beat.find( 'td.dub' ).html( dub_secs.toFixed( 3 ) ); - that._beat.find( 'td.dur' ).html( duration.toFixed( 3 ) ); - that._prev_dub = dub; - } ); - - }, - - populate_table: function() { - this._table_ready = true; - this._table = jQuery( id() ) . ' > table' ) ?> ); - this._beats = this._table.find( 'tbody' ); - }, - - add_table_row: function( tr ) { - this._table.find( 'tbody' ).prepend( tr ); - }, - - get_table_row: function( index, lub, dub, since_last, duration ) { - var lub_diff = ( lub - this._start ) / 1000; - var dub_diff = '-'; - var duration_secs = '-'; - - if ( '' !== dub ) { - dub_diff = ( dub - this._start ) / 1000; - dub_diff = dub_diff.toFixed( 3 ); - } + that._beat.find( 'td.dub' ).html( dub_secs.toFixed( 3 ) ); + that._beat.find( 'td.dur' ).html( duration.toFixed( 3 ) ); + that._prev_dub = dub; + } ); - if ( !isNaN( duration ) ) { - duration_secs = duration / 1000; - duration_secs = duration_secs.toFixed( 3 ); - } + }, - var since_last_secs = '-' != since_last ? since_last / 1000 : '-'; - since_last_secs = '-' != since_last_secs ? since_last_secs.toFixed( 3 ) : '-'; + populate_table: function() { + this._table_ready = true; + this._table = jQuery( id() ) . ' > table' ) ?> ); + this._beats = this._table.find( 'tbody' ); + }, - return '' + - '' + index + '' + - '' + lub_diff.toFixed( 3 ) + '' + - '' + dub_diff + '' + - '' + since_last_secs + '' + - '' + duration_secs + '' + - ''; - }, - - update_tab: function( count ) { - this._tab = jQuery( '#qm-panel-menu button[data-qm-href=id() ) ) ?>]' ); - this._tab.html( 'Heartbeats (' + count + ')' ); - } + add_table_row: function( tr ) { + this._table.find( 'tbody' ).prepend( tr ); + }, - }; + get_table_row: function( index, lub, dub, since_last, duration ) { + var lub_diff = ( lub - this._start ) / 1000; + var dub_diff = '-'; + var duration_secs = '-'; - qmx_heartbeat.init(); + if ( '' !== dub ) { + dub_diff = ( dub - this._start ) / 1000; + dub_diff = dub_diff.toFixed( 3 ); + } - ' + + '' + index + '' + + '' + lub_diff.toFixed( 3 ) + '' + + '' + dub_diff + '' + + '' + since_last_secs + '' + + '' + duration_secs + '' + + ''; + }, + + update_tab: function( count ) { + this._tab = jQuery( '#qm-panel-menu button[data-qm-href=id() ) ) ?>]' ); + this._tab.html( 'Heartbeats (' + count + ')' ); + } + + }; + + qmx_heartbeat.init(); + + plugin_path( 'assets/query-monitor.css' ); - - if ( ! file_exists( $qm ) ) { - return; + public function name() : string { + return __( 'Heartbeat', 'query-monitor-extend' ); } - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); - - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) - return; - - require_once $qm_dir . 'output/Html.php'; - - class QMX_Output_Html_Heartbeat extends QM_Output_Html { - - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); - } + public function output() { + $data = $this->collector->get_data(); - public function name() : string { - return __( 'Heartbeat', 'query-monitor-extend' ); - } + echo '
'; - public function output() { - $data = $this->collector->get_data(); + if ( $this->collector->qm_no_jquery() ) { - echo '
'; + echo '
'; + echo '

Heartbeat logging requires jQuery, which has been prevented by QM_NO_JQUERY.

'; + echo '
'; - if ( $this->collector->qm_no_jquery() ) { + } else if ( wp_script_is( 'heartbeat', 'done' ) ) { + echo ''; + echo ''; - echo '
'; - echo '

Heartbeat logging requires jQuery, which has been prevented by QM_NO_JQUERY.

'; - echo '
'; + echo ''; + echo ''; - } else if ( wp_script_is( 'heartbeat', 'done' ) ) { - echo '
' . esc_html( $this->collector->name() ) . '
'; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - echo ''; - echo ''; + echo ''; + echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - echo ''; - echo ''; + echo '
' . esc_html( $this->collector->name() ) . '
LubDubTime since previousDuration
LubDubTime since previousDuration
'; + echo '

Listening for first heartbeat...

'; + echo '
'; + echo ''; + } else { - echo ''; - echo ''; - echo ''; - echo '

Listening for first heartbeat...

'; - echo ''; - echo ''; - echo ''; + echo '
'; + echo '

' . esc_html__( 'No heartbeat detected.', 'query-monitor' ) . '

'; + echo '
'; - echo ''; - echo ''; - } else { + } - echo '
'; - echo '

' . esc_html__( 'No heartbeat detected.', 'query-monitor' ) . '

'; - echo '
'; + echo '
'; - } + $this->current_id = 'qm-heartbeat'; + $this->current_name = 'Heartbeat'; - echo '
'; - - $this->current_id = 'qm-heartbeat'; - $this->current_name = 'Heartbeat'; - - $this->output_concerns(); - } - - public function panel_menu( array $menu ) { - $menu['qm-heartbeat'] = $this->menu( array( - 'title' => esc_html__( 'Heartbeats (0)' ), - 'id' => 'query-monitor-extend-heartbeat', - ) ); + $this->output_concerns(); + } - return $menu; - } + public function panel_menu( array $menu ) { + $menu['qm-heartbeat'] = $this->menu( array( + 'title' => esc_html__( 'Heartbeats (0)' ), + 'id' => 'query-monitor-extend-heartbeat', + ) ); + return $menu; } - add_filter( 'qm/outputter/html', static function ( array $output ) : array { - if ( $collector = QM_Collectors::get( 'heartbeat' ) ) - $output['heartbeat'] = new QMX_Output_Html_Heartbeat( $collector ); +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function ( array $output ) : array { + if ( $collector = QM_Collectors::get( 'heartbeat' ) ) + $output['heartbeat'] = new QMX_Output_Html_Heartbeat( $collector ); -}, 9 ); \ No newline at end of file + return $output; +}, 70 ); \ No newline at end of file diff --git a/image-sizes/qmx-image-sizes-collector.php b/image-sizes/qmx-image-sizes-collector.php index 825f39a..7622f56 100644 --- a/image-sizes/qmx-image-sizes-collector.php +++ b/image-sizes/qmx-image-sizes-collector.php @@ -1,313 +1,277 @@ data->sizes = array( + 'thumbnail' => array( + 'width' => intval( get_option( 'thumbnail_size_w' ) ), + 'height' => intval( get_option( 'thumbnail_size_h' ) ), + 'used' => 0, + 'source' => 'native', + 'crop' => true, + 'num' => 1, + ), + 'medium' => array( + 'width' => intval( get_option( 'medium_size_w' ) ), + 'height' => intval( get_option( 'medium_size_h' ) ), + 'used' => 0, + 'source' => 'native', + 'crop' => false, + 'num' => 2, + ), + 'medium_large' => array( + 'width' => intval( get_option( 'medium_large_size_w' ) ), + 'height' => intval( get_option( 'medium_large_size_h' ) ), + 'used' => 0, + 'source' => 'native', + 'crop' => false, + 'num' => 3, + ), + 'large' => array( + 'width' => intval( get_option( 'large_size_w' ) ), + 'height' => intval( get_option( 'large_size_h' ) ), + 'used' => 0, + 'source' => 'native', + 'crop' => false, + 'num' => 4, + ), + + /** + * @see _wp_add_additional_image_sizes() + * @since WP 5.3.0 + */ + '1536x1536' => array( + 'width' => 1536, + 'height' => 1536, + 'used' => 0, + 'source' => 'native', + 'crop' => false, + 'num' => 5, + ), + '2048x2048' => array( + 'width' => 2048, + 'height' => 2048, + 'used' => 0, + 'source' => 'native', + 'crop' => false, + 'num' => 6, + ), + ); + + add_action( 'plugins_loaded', array( &$this, 'action__plugins_loaded' ) ); + add_action( 'after_setup_theme', array( &$this, 'action__after_setup_theme' ) ); + add_action( 'wp_enqueue_scripts', array( &$this, 'add_inline_script' ), -998 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_inline_script' ), -998 ); + add_action( 'login_enqueue_scripts', array( &$this, 'add_inline_script' ), -998 ); + add_action( 'enqueue_embed_scripts', array( &$this, 'add_inline_script' ), -998 ); + + add_action( 'wp', array( $this, 'action__wp' ) ); + add_filter( 'wp_get_attachment_image_src', array( $this, 'filter__wp_get_attachment_image_src' ), 10, 3 ); -add_action( 'plugin_loaded', 'load_qmx_image_sizes_collector' ); - -function load_qmx_image_sizes_collector( string $file ) { - - if ( 'query-monitor/query-monitor.php' !== plugin_basename( $file ) ) - return; - - remove_action( 'plugin_loaded', __FUNCTION__ ); - - if ( !class_exists( 'QueryMonitor' ) ) - return; - - if ( defined( 'QM_DISABLED' ) && constant( 'QM_DISABLED' ) ) { - return; } - if ( constant( 'QMX_DISABLED' ) ) { - return; + public function get_storage(): QM_Data { + require_once 'qmx-image-sizes-data.php'; + return new QMX_Data_Image_Sizes(); } - class QMX_Collector_Image_Sizes extends QM_DataCollector { - - public $id = 'image_sizes'; - - public function __construct() { - parent::__construct(); - - $this->data->sizes = array( - 'thumbnail' => array( - 'width' => intval( get_option( 'thumbnail_size_w' ) ), - 'height' => intval( get_option( 'thumbnail_size_h' ) ), - 'used' => 0, - 'source' => 'native', - 'crop' => true, - 'num' => 1, - ), - 'medium' => array( - 'width' => intval( get_option( 'medium_size_w' ) ), - 'height' => intval( get_option( 'medium_size_h' ) ), - 'used' => 0, - 'source' => 'native', - 'crop' => false, - 'num' => 2, - ), - 'medium_large' => array( - 'width' => intval( get_option( 'medium_large_size_w' ) ), - 'height' => intval( get_option( 'medium_large_size_h' ) ), - 'used' => 0, - 'source' => 'native', - 'crop' => false, - 'num' => 3, - ), - 'large' => array( - 'width' => intval( get_option( 'large_size_w' ) ), - 'height' => intval( get_option( 'large_size_h' ) ), - 'used' => 0, - 'source' => 'native', - 'crop' => false, - 'num' => 4, - ), - - /** - * @see _wp_add_additional_image_sizes() - * @since WP 5.3.0 - */ - '1536x1536' => array( - 'width' => 1536, - 'height' => 1536, - 'used' => 0, - 'source' => 'native', - 'crop' => false, - 'num' => 5, - ), - '2048x2048' => array( - 'width' => 2048, - 'height' => 2048, - 'used' => 0, - 'source' => 'native', - 'crop' => false, - 'num' => 6, - ), - ); - - add_action( 'plugins_loaded', array( &$this, 'action__plugins_loaded' ) ); - add_action( 'after_setup_theme', array( &$this, 'action__after_setup_theme' ) ); - add_action( 'wp_enqueue_scripts', array( &$this, 'add_inline_script' ), -998 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'add_inline_script' ), -998 ); - add_action( 'login_enqueue_scripts', array( &$this, 'add_inline_script' ), -998 ); - add_action( 'enqueue_embed_scripts', array( &$this, 'add_inline_script' ), -998 ); - - add_action( 'wp', array( $this, 'action__wp' ) ); - add_filter( 'wp_get_attachment_image_src', array( $this, 'filter__wp_get_attachment_image_src' ), 10, 3 ); - - } - - public function get_storage(): QM_Data { - do_action( 'qmx/load_data/image_sizes' ); - return new QMX_Data_Image_Sizes(); - } - - public function get_concerned_filters() { - return array( - 'wp_get_attachment_image_src', - ); - } - - function action__plugins_loaded() { - if ( 'plugins_loaded' !== current_action() || did_action( 'qm/cease' ) ) - return; - - $this->_process_added_image_sizes( 'plugin' ); - } - - function action__after_setup_theme() { - if ( 'after_setup_theme' !== current_action() || did_action( 'qm/cease' ) ) - return; - - $this->_process_added_image_sizes( 'theme' ); - } + public function get_concerned_filters() { + return array( + 'wp_get_attachment_image_src', + ); + } - function action__wp() : void { - if ( did_action( 'qm/cease' ) ) - return; + function action__plugins_loaded() { + if ( 'plugins_loaded' !== current_action() || did_action( 'qm/cease' ) ) + return; - $post = get_queried_object(); + $this->_process_added_image_sizes( 'plugin' ); + } - if ( empty( $post ) ) - return; + function action__after_setup_theme() { + if ( 'after_setup_theme' !== current_action() || did_action( 'qm/cease' ) ) + return; - $blocks = parse_blocks( $post->post_content ); + $this->_process_added_image_sizes( 'theme' ); + } - if ( empty( $blocks ) ) - return; + function action__wp() : void { + if ( did_action( 'qm/cease' ) ) + return; - foreach ( $blocks as $block ) { - if ( 'core/image' !== $block['blockName'] ) - continue; + $post = get_queried_object(); - $size = $block['attrs']['sizeSlug']; + if ( empty( $post ) ) + return; - if ( !array_key_exists( $size, $this->data->sizes ) ) - continue; + $blocks = parse_blocks( $post->post_content ); - $this->data->sizes[ $size ]['used']++; - } - } + if ( empty( $blocks ) ) + return; - function filter__wp_get_attachment_image_src( $image, $attachment_id, $size ) { - if ( did_action( 'qm/cease' ) ) - return $image; + foreach ( $blocks as $block ) { + if ( 'core/image' !== $block['blockName'] ) + continue; - # If specifying custom dimensions, bail. - if ( is_array( $size ) ) - return $image; + $size = $block['attrs']['sizeSlug']; - # If size is not registered, bail. if ( !array_key_exists( $size, $this->data->sizes ) ) - return $image; + continue; $this->data->sizes[ $size ]['used']++; + } + } + function filter__wp_get_attachment_image_src( $image, $attachment_id, $size ) { + if ( did_action( 'qm/cease' ) ) return $image; - } - protected function _process_added_image_sizes( $source = 'unknown' ) { - global $_wp_additional_image_sizes; - - $num = count( $this->data->sizes ); - - if ( - is_array( $_wp_additional_image_sizes ) - && !empty( $_wp_additional_image_sizes ) - ) - foreach ( $_wp_additional_image_sizes as $id => $size ) - if ( !array_key_exists( $id, $this->data->sizes ) ) - $this->data->sizes[$id] = array_merge( - array( - 'num' => ++$num, - 'source' => apply_filters( 'qmx/image-size/source', $source, $id, $size ), - 'used' => 0, - ), - $size - ); - } + # If specifying custom dimensions, bail. + if ( is_array( $size ) ) + return $image; - public function process() { - if ( did_action( 'qm/cease' ) ) - return; + # If size is not registered, bail. + if ( !array_key_exists( $size, $this->data->sizes ) ) + return $image; - $this->_process_added_image_sizes(); + $this->data->sizes[ $size ]['used']++; - $this->data->sizes = array_map( array( &$this, 'add_ratio' ), $this->data->sizes ); + return $image; + } - $counts = array( 'dimensions' => array(), 'ratios' => array() ); + protected function _process_added_image_sizes( $source = 'unknown' ) { + global $_wp_additional_image_sizes; + + $num = count( $this->data->sizes ); + + if ( + is_array( $_wp_additional_image_sizes ) + && !empty( $_wp_additional_image_sizes ) + ) + foreach ( $_wp_additional_image_sizes as $id => $size ) + if ( !array_key_exists( $id, $this->data->sizes ) ) + $this->data->sizes[$id] = array_merge( + array( + 'num' => ++$num, + 'source' => apply_filters( 'qmx/image-size/source', $source, $id, $size ), + 'used' => 0, + ), + $size + ); + } - foreach ( $this->data->sizes as $size ) { - $key = $size['width'] . ':' . $size['height'] . ' - ' . ( bool ) $size['crop']; - array_key_exists( $key, $counts['dimensions'] ) - ? $counts['dimensions'][$key]++ - : $counts['dimensions'][$key] = 1; + public function process() { + if ( did_action( 'qm/cease' ) ) + return; - $key = $size['ratio'] . ' - ' . ( bool ) $size['crop']; - if ( 0 !== $size['ratio'] ) - array_key_exists( $key, $counts['ratios'] ) - ? $counts['ratios'][$key]++ - : $counts['ratios'][$key] = 1; - } + $this->_process_added_image_sizes(); - foreach ( array( 'dimensions', 'ratios' ) as $type ) - $counts[$type] = array_filter( $counts[$type], function( $v ) { return $v > 1; } ); + $this->data->sizes = array_map( array( &$this, 'add_ratio' ), $this->data->sizes ); - $this->data->duplicates = $counts; + $counts = array( 'dimensions' => array(), 'ratios' => array() ); + foreach ( $this->data->sizes as $size ) { + $key = $size['width'] . ':' . $size['height'] . ' - ' . ( bool ) $size['crop']; + array_key_exists( $key, $counts['dimensions'] ) + ? $counts['dimensions'][$key]++ + : $counts['dimensions'][$key] = 1; + + $key = $size['ratio'] . ' - ' . ( bool ) $size['crop']; + if ( 0 !== $size['ratio'] ) + array_key_exists( $key, $counts['ratios'] ) + ? $counts['ratios'][$key]++ + : $counts['ratios'][$key] = 1; } - private function add_ratio( array $size ) { - if ( - !array_key_exists( 'width', $size ) - || !array_key_exists( 'height', $size ) - ) - return $size; + foreach ( array( 'dimensions', 'ratios' ) as $type ) + $counts[$type] = array_filter( $counts[$type], function( $v ) { return $v > 1; } ); - $num1 = $size['width']; - $num2 = $size['height']; + $this->data->duplicates = $counts; - while ( 0 !== $num2 ) { - $t = $num1 % $num2; - $num1 = $num2; - $num2 = $t; - } + } - $size['_gcd'] = $num1; // greatest common denominator - unset( $num1, $num2 ); + private function add_ratio( array $size ) { + if ( + !array_key_exists( 'width', $size ) + || !array_key_exists( 'height', $size ) + ) + return $size; - $size['ratio'] = ( - 0 === $size['height'] - ? 0 - : $size['width'] / $size['height'] - ); + $num1 = $size['width']; + $num2 = $size['height']; - return $size; + while ( 0 !== $num2 ) { + $t = $num1 % $num2; + $num1 = $num2; + $num2 = $t; } - public function add_inline_script() { - if ( did_action( 'qm/cease' ) ) - return; + $size['_gcd'] = $num1; // greatest common denominator + unset( $num1, $num2 ); - wp_add_inline_script( 'query-monitor', $this->_inlineScript_queryMonitor() ); - } + $size['ratio'] = ( + 0 === $size['height'] + ? 0 + : $size['width'] / $size['height'] + ); + + return $size; + } - protected function _inlineScript_queryMonitor() { - ob_start(); - ?> + public function add_inline_script() { + if ( did_action( 'qm/cease' ) ) + return; - if ( window.jQuery ) { + wp_add_inline_script( 'query-monitor', $this->_inlineScript_queryMonitor() ); + } - jQuery( function( $ ) { + protected function _inlineScript_queryMonitor() { + ob_start(); + ?> - $( 'td[data-qmx-image-size-width]' ) - .on( 'mouseenter', function() { qmx_image_size_highlighter__mouseenter( 'width', this ); } ) - .on( 'mouseleave', function() { qmx_image_size_highlighter__mouseleave( 'width', this ); } ); + if ( window.jQuery ) { - $( 'td[data-qmx-image-size-height]' ) - .on( 'mouseenter', function() { qmx_image_size_highlighter__mouseenter( 'height', this ); } ) - .on( 'mouseleave', function() { qmx_image_size_highlighter__mouseleave( 'height', this ); } ); + jQuery( function( $ ) { - $( 'td[data-qmx-image-size-ratio]' ) - .on( 'mouseenter', function() { qmx_image_size_highlighter__mouseenter( 'ratio', this ); } ) - .on( 'mouseleave', function() { qmx_image_size_highlighter__mouseleave( 'ratio', this ); } ); + $( 'td[data-qmx-image-size-width]' ) + .on( 'mouseenter', function() { qmx_image_size_highlighter__mouseenter( 'width', this ); } ) + .on( 'mouseleave', function() { qmx_image_size_highlighter__mouseleave( 'width', this ); } ); - } ); + $( 'td[data-qmx-image-size-height]' ) + .on( 'mouseenter', function() { qmx_image_size_highlighter__mouseenter( 'height', this ); } ) + .on( 'mouseleave', function() { qmx_image_size_highlighter__mouseleave( 'height', this ); } ); - function qmx_image_size_highlighter__mouseenter( prop, el ) { - jQuery( el ).addClass( 'qm-highlight' ); - var tr = jQuery( el ).closest( 'tr' ); - var value = jQuery( el ).attr( 'data-qmx-image-size-' + prop ); - var table = jQuery( el ).closest( 'table' ).find( 'tr[data-qmx-image-size-' + prop + '="' + value + '"]' ).not( tr ).addClass( 'qm-highlight' ); - } + $( 'td[data-qmx-image-size-ratio]' ) + .on( 'mouseenter', function() { qmx_image_size_highlighter__mouseenter( 'ratio', this ); } ) + .on( 'mouseleave', function() { qmx_image_size_highlighter__mouseleave( 'ratio', this ); } ); - function qmx_image_size_highlighter__mouseleave( prop, el ) { - jQuery( el ).removeClass( 'qm-highlight' ); - jQuery( el ).closest( 'table' ).find( 'tr.qm-highlight' ).removeClass( 'qm-highlight' ); - } + } ); + function qmx_image_size_highlighter__mouseenter( prop, el ) { + jQuery( el ).addClass( 'qm-highlight' ); + var tr = jQuery( el ).closest( 'tr' ); + var value = jQuery( el ).attr( 'data-qmx-image-size-' + prop ); + var table = jQuery( el ).closest( 'table' ).find( 'tr[data-qmx-image-size-' + prop + '="' + value + '"]' ).not( tr ).addClass( 'qm-highlight' ); + } + + function qmx_image_size_highlighter__mouseleave( prop, el ) { + jQuery( el ).removeClass( 'qm-highlight' ); + jQuery( el ).closest( 'table' ).find( 'tr.qm-highlight' ).removeClass( 'qm-highlight' ); } - \ No newline at end of file +QM_Collectors::add( new QMX_Collector_Image_Sizes ); \ No newline at end of file diff --git a/image-sizes/qmx-image-sizes-data.php b/image-sizes/qmx-image-sizes-data.php index 0a60f50..d4b0043 100644 --- a/image-sizes/qmx-image-sizes-data.php +++ b/image-sizes/qmx-image-sizes-data.php @@ -1,31 +1,10 @@ plugin_path( 'assets/query-monitor.css' ); + public function output() { + $data = $this->collector->get_data(); - if ( ! file_exists( $qm ) ) { - return; - } + echo '
'; - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); + if ( !empty( $data->sizes ) ) { + echo ''; + echo ''; + echo ''; + echo ''; - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) - return; + echo ''; - require_once $qm_dir . 'output/Html.php'; + echo ''; - class QMX_Output_Html_Image_Sizes extends QM_Output_Html { + echo ''; - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); - } + echo ''; - public function name() { - return __( 'Image Sizes', 'query-monitor-extend' ); - } + echo ''; - public function output() { - $data = $this->collector->get_data(); + echo ''; - echo '
'; + echo '
'; - if ( !empty( $data->sizes ) ) { - echo '
' . esc_html( $this->name() ) . '
'; + echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_sorter( __( 'ID', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_sorter( __( 'Uses', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_sorter( __( 'Width', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_sorter( __( 'Height', 'query-monitor-extend' ) ); + echo ''; + echo $this->build_sorter( __( 'Ratio', 'query-monitor-extend' ) ); + echo ''; + echo __( 'Cropped', 'query-monitor-extend' ); + echo '
'; - echo ''; - echo ''; - echo ''; + echo ''; - echo ''; + echo ''; + echo ''; - echo ''; + echo ''; - echo ''; + $sources = array(); + $uses = 0; - echo ''; + foreach ( $data->sizes as $id => $row ) { + $ratio = array( $row['width'], $row['height'] ); - echo ''; + if ( + !empty( $row['width'] ) + && !empty( $row['height'] ) + ) + $ratio = array( $row['width'] / $row['_gcd'], $row['height'] / $row['_gcd'] ); - echo ''; + if ( $ratio === array( $row['width'], $row['height'] ) ) + $ratio = array( '—' ); - echo ''; - - echo ''; + $uses += $row['used']; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; - echo ''; - echo ''; + array_key_exists( $row['source'], $sources ) ? $sources[$row['source']]++ : $sources[$row['source']] = 1; + } - $sources = array(); - $uses = 0; + echo ''; + echo ''; - foreach ( $data->sizes as $id => $row ) { - $ratio = array( $row['width'], $row['height'] ); + if ( !empty( $sources ) ) + $sources = array_map( function( $k, $v ) { return ucwords( $k ) . ': ' . $v; }, array_keys( $sources ), $sources ); - if ( - !empty( $row['width'] ) - && !empty( $row['height'] ) - ) - $ratio = array( $row['width'] / $row['_gcd'], $row['height'] / $row['_gcd'] ); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - if ( $ratio === array( $row['width'], $row['height'] ) ) - $ratio = array( '—' ); + echo ''; + echo '
' . esc_html( $this->name() ) . '
'; + echo $this->build_sorter( __( 'Source', 'query-monitor-extend' ) ); + echo ''; - echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); - echo '
'; - echo $this->build_sorter( __( 'ID', 'query-monitor-extend' ) ); - echo '
'; - echo $this->build_sorter( __( 'Uses', 'query-monitor-extend' ) ); - echo ''; - echo $this->build_sorter( __( 'Width', 'query-monitor-extend' ) ); - echo ''; - echo $this->build_sorter( __( 'Height', 'query-monitor-extend' ) ); - echo ''; - echo $this->build_sorter( __( 'Ratio', 'query-monitor-extend' ) ); - echo ''; - echo __( 'Cropped', 'query-monitor-extend' ); - echo ''; - echo $this->build_sorter( __( 'Source', 'query-monitor-extend' ) ); - echo '
' . esc_html( $row['num'] ) . '' . esc_html( $id ) . '' . esc_html( $row['used'] ) . '' . esc_html( $row['width'] ) . '' . esc_html( $row['height'] ) . '' . esc_html( implode( ':', $ratio ) ) . '' . ( $row['crop'] ? '' : '' ) . '' . esc_html( $row['source'] ) . '
Total: ' . esc_html( number_format_i18n( count( $data->sizes ) ) ) . 'Uses: ' . esc_html( number_format_i18n( $uses ) ) . 'Duplicates: ' . esc_html( number_format_i18n( array_sum( $data->duplicates['dimensions'] ) ) ) . 'Duplicates: ' . esc_html( number_format_i18n( array_sum( $data->duplicates['ratios'] ) ) ) . '' . implode( ', ', $sources ) . '
'; - $uses += $row['used']; + } else { - echo ''; - echo '' . esc_html( $row['num'] ) . ''; - echo '' . esc_html( $id ) . ''; - echo '' . esc_html( $row['used'] ) . ''; - echo '' . esc_html( $row['width'] ) . ''; - echo '' . esc_html( $row['height'] ) . ''; - echo '' . esc_html( implode( ':', $ratio ) ) . ''; - echo '' . ( $row['crop'] ? '' : '' ) . ''; - echo '' . esc_html( $row['source'] ) . ''; - echo ''; + echo '
'; + echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; + echo '
'; - array_key_exists( $row['source'], $sources ) ? $sources[$row['source']]++ : $sources[$row['source']] = 1; - } + } - echo ''; - echo ''; + echo '
'; - if ( !empty( $sources ) ) - $sources = array_map( function( $k, $v ) { return ucwords( $k ) . ': ' . $v; }, array_keys( $sources ), $sources ); + $this->current_id = 'qm-image_sizes'; + $this->current_name = 'Image Sizes'; - echo ''; - echo 'Total: ' . esc_html( number_format_i18n( count( $data->sizes ) ) ) . ''; - echo 'Uses: ' . esc_html( number_format_i18n( $uses ) ) . ''; - echo 'Duplicates: ' . esc_html( number_format_i18n( array_sum( $data->duplicates['dimensions'] ) ) ) . ''; - echo 'Duplicates: ' . esc_html( number_format_i18n( array_sum( $data->duplicates['ratios'] ) ) ) . ''; - echo '' . implode( ', ', $sources ) . ''; - echo ''; - - echo ''; - echo ''; - - } else { - - echo '
'; - echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; - echo '
'; - - } - - echo ''; - - $this->current_id = 'qm-image_sizes'; - $this->current_name = 'Image Sizes'; - - $this->output_concerns(); - } - - public function panel_menu( array $menu ) { + $this->output_concerns(); + } - $menu['qm-image_sizes'] = $this->menu( array( - 'title' => esc_html__( 'Image Sizes', 'query-monitor-extend' ), - 'id' => 'query-monitor-extend-image_sizes', - ) ); + public function panel_menu( array $menu ) { - return $menu; + $menu['qm-image_sizes'] = $this->menu( array( + 'title' => esc_html__( 'Image Sizes', 'query-monitor-extend' ), + 'id' => 'query-monitor-extend-image_sizes', + ) ); - } + return $menu; } - add_filter( 'qm/outputter/html', static function ( array $output ) : array { - if ( $collector = QM_Collectors::get( 'image_sizes' ) ) - $output['image_sizes'] = new QMX_Output_Html_Image_Sizes( $collector ); +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function ( array $output ) : array { + if ( $collector = QM_Collectors::get( 'image_sizes' ) ) + $output['image_sizes'] = new QMX_Output_Html_Image_Sizes( $collector ); -}, 9 ); \ No newline at end of file + return $output; +}, 70 ); \ No newline at end of file diff --git a/paths/qmx-paths-collector.php b/paths/qmx-paths-collector.php index 4d4ed59..4232909 100644 --- a/paths/qmx-paths-collector.php +++ b/paths/qmx-paths-collector.php @@ -1,178 +1,144 @@ data->paths = apply_filters( 'qmx/collector/paths', array( + 'ABSPATH' => ABSPATH, + 'COOKIEPATH' => COOKIEPATH, + 'SITECOOKIEPATH' => SITECOOKIEPATH, + 'DOMAIN_CURRENT_SITE' => defined( 'DOMAIN_CURRENT_SITE' ) ? DOMAIN_CURRENT_SITE : 'undefined', + 'PATH_CURRENT_SITE' => defined( 'PATH_CURRENT_SITE' ) ? PATH_CURRENT_SITE : 'undefined', + 'WP_SITEURL' => defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined', + 'site_url()' => site_url(), + 'get_site_url()' => get_site_url(), + 'network_site_url()' => network_site_url(), + 'WP_HOME' => defined( 'WP_HOME' ) ? WP_HOME : 'undefined', + 'home_url()' => home_url(), + 'get_home_url()' => get_home_url(), + 'network_home_url()' => network_home_url(), + 'get_home_path()' => function_exists( 'get_home_path' ) ? get_home_path() : '', + 'WP_CONTENT_URL' => WP_CONTENT_URL, + 'WP_CONTENT_DIR' => WP_CONTENT_DIR, + 'content_url()' => content_url(), + 'WP_PLUGIN_URL' => WP_PLUGIN_URL, + 'WP_PLUGIN_DIR' => WP_PLUGIN_DIR, + 'PLUGINS_COOKIE_PATH' => PLUGINS_COOKIE_PATH, + 'plugins_url()' => plugins_url(), + 'plugin_dir_url( __FILE__ )' => plugin_dir_url( __FILE__ ), + 'plugin_dir_path( __FILE__ )' => plugin_dir_path( __FILE__ ), + 'plugin_basename( __FILE__ )' => plugin_basename( __FILE__ ), + 'WPMU_PLUGIN_DIR' => WPMU_PLUGIN_DIR, + 'WPMU_PLUGIN_URL' => WPMU_PLUGIN_URL, + 'get_theme_root()' => get_theme_root(), + 'get_theme_roots()' => get_theme_roots(), + 'get_theme_root_uri()' => get_theme_root_uri(), + 'get_template_directory()' => get_template_directory(), + 'TEMPLATEPATH' => TEMPLATEPATH, + 'get_template_directory_uri()' => get_template_directory_uri(), + 'get_stylesheet_uri()' => get_stylesheet_uri(), + 'get_stylesheet_directory()' => get_stylesheet_directory(), + 'STYLESHEETPATH' => STYLESHEETPATH, + 'get_stylesheet_directory_uri()' => get_stylesheet_directory_uri(), + 'admin_url()' => admin_url(), + 'get_admin_url()' => get_admin_url(), + 'network_admin_url()' => network_admin_url(), + 'ADMIN_COOKIE_PATH' => ADMIN_COOKIE_PATH, + 'WPINC' => WPINC, + 'includes_url()' => includes_url(), + 'WP_LANG_DIR' => WP_LANG_DIR, + 'BLOGUPLOADDIR' => defined( 'BLOGUPLOADDIR' ) ? BLOGUPLOADDIR : 'undefined', + 'UPLOADBLOGSDIR' => defined( 'UPLOADBLOGSDIR' ) ? UPLOADBLOGSDIR : 'undefined', + 'UPLOADS' => defined( 'UPLOADS' ) ? UPLOADS : 'undefined', + 'wp_upload_dir()' => wp_upload_dir(), + 'get_theme_file_path()' => get_theme_file_path(), + 'get_theme_file_uri()' => get_theme_file_uri(), + ) ); + + if ( defined( 'WP_DEBUG_LOG' ) && is_string( WP_DEBUG_LOG ) ) + $this->data->paths['WP_DEBUG_LOG'] = WP_DEBUG_LOG; + + ksort( $this->data->paths, SORT_FLAG_CASE | SORT_STRING ); - $this->data->paths = apply_filters( 'qmx/collector/paths', array( - 'ABSPATH' => ABSPATH, - 'COOKIEPATH' => COOKIEPATH, - 'SITECOOKIEPATH' => SITECOOKIEPATH, - 'DOMAIN_CURRENT_SITE' => defined( 'DOMAIN_CURRENT_SITE' ) ? DOMAIN_CURRENT_SITE : 'undefined', - 'PATH_CURRENT_SITE' => defined( 'PATH_CURRENT_SITE' ) ? PATH_CURRENT_SITE : 'undefined', - 'WP_SITEURL' => defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined', - 'site_url()' => site_url(), - 'get_site_url()' => get_site_url(), - 'network_site_url()' => network_site_url(), - 'WP_HOME' => defined( 'WP_HOME' ) ? WP_HOME : 'undefined', - 'home_url()' => home_url(), - 'get_home_url()' => get_home_url(), - 'network_home_url()' => network_home_url(), - 'get_home_path()' => function_exists( 'get_home_path' ) ? get_home_path() : '', - 'WP_CONTENT_URL' => WP_CONTENT_URL, - 'WP_CONTENT_DIR' => WP_CONTENT_DIR, - 'content_url()' => content_url(), - 'WP_PLUGIN_URL' => WP_PLUGIN_URL, - 'WP_PLUGIN_DIR' => WP_PLUGIN_DIR, - 'PLUGINS_COOKIE_PATH' => PLUGINS_COOKIE_PATH, - 'plugins_url()' => plugins_url(), - 'plugin_dir_url( __FILE__ )' => plugin_dir_url( __FILE__ ), - 'plugin_dir_path( __FILE__ )' => plugin_dir_path( __FILE__ ), - 'plugin_basename( __FILE__ )' => plugin_basename( __FILE__ ), - 'WPMU_PLUGIN_DIR' => WPMU_PLUGIN_DIR, - 'WPMU_PLUGIN_URL' => WPMU_PLUGIN_URL, - 'get_theme_root()' => get_theme_root(), - 'get_theme_roots()' => get_theme_roots(), - 'get_theme_root_uri()' => get_theme_root_uri(), - 'get_template_directory()' => get_template_directory(), - 'TEMPLATEPATH' => TEMPLATEPATH, - 'get_template_directory_uri()' => get_template_directory_uri(), - 'get_stylesheet_uri()' => get_stylesheet_uri(), - 'get_stylesheet_directory()' => get_stylesheet_directory(), - 'STYLESHEETPATH' => STYLESHEETPATH, - 'get_stylesheet_directory_uri()' => get_stylesheet_directory_uri(), - 'admin_url()' => admin_url(), - 'get_admin_url()' => get_admin_url(), - 'network_admin_url()' => network_admin_url(), - 'ADMIN_COOKIE_PATH' => ADMIN_COOKIE_PATH, - 'WPINC' => WPINC, - 'includes_url()' => includes_url(), - 'WP_LANG_DIR' => WP_LANG_DIR, - 'BLOGUPLOADDIR' => defined( 'BLOGUPLOADDIR' ) ? BLOGUPLOADDIR : 'undefined', - 'UPLOADBLOGSDIR' => defined( 'UPLOADBLOGSDIR' ) ? UPLOADBLOGSDIR : 'undefined', - 'UPLOADS' => defined( 'UPLOADS' ) ? UPLOADS : 'undefined', - 'wp_upload_dir()' => wp_upload_dir(), - 'get_theme_file_path()' => get_theme_file_path(), - 'get_theme_file_uri()' => get_theme_file_uri(), - ) ); - - if ( defined( 'WP_DEBUG_LOG' ) && is_string( WP_DEBUG_LOG ) ) - $this->data->paths['WP_DEBUG_LOG'] = WP_DEBUG_LOG; - - ksort( $this->data->paths, SORT_FLAG_CASE | SORT_STRING ); - - } - - public function get_concerned_filters() { - return array( - 'admin_url', - 'content_url', - 'home_url', - 'includes_url', - 'plugins_url', - 'network_admin_url', - 'network_home_url', - 'network_site_url', - 'site_url', - 'stylesheet_directory', - 'stylesheet_directory_uri', - 'stylesheet_uri', - 'template_directory', - 'template_directory_uri', - 'theme_file_path', - 'theme_file_uri', - 'theme_root', - 'theme_root_uri', - 'upload_dir', - ); - } + } - public function get_concerned_constants() { - return array( - 'ABSPATH', - 'COOKIEPATH', - 'SITECOOKIEPATH', - 'DOMAIN_CURRENT_SITE', - 'PATH_CURRENT_SITE', - 'WP_SITEURL', - 'WP_HOME', - 'WP_CONTENT_URL', - 'WP_CONTENT_DIR', - 'WP_PLUGIN_URL', - 'WP_PLUGIN_DIR', - 'PLUGINS_COOKIE_PATH', - 'WPMU_PLUGIN_DIR', - 'WPMU_PLUGIN_URL', - 'TEMPLATEPATH', - 'STYLESHEETPATH', - 'ADMIN_COOKIE_PATH', - 'WPINC', - 'WP_LANG_DIR', - 'BLOGUPLOADDIR', - 'UPLOADBLOGSDIR', - 'UPLOADS', - ); - } + public function get_concerned_filters() { + return array( + 'admin_url', + 'content_url', + 'home_url', + 'includes_url', + 'plugins_url', + 'network_admin_url', + 'network_home_url', + 'network_site_url', + 'site_url', + 'stylesheet_directory', + 'stylesheet_directory_uri', + 'stylesheet_uri', + 'template_directory', + 'template_directory_uri', + 'theme_file_path', + 'theme_file_uri', + 'theme_root', + 'theme_root_uri', + 'upload_dir', + ); + } - public function get_concerned_options() { - return array( - 'siteurl', - 'home', - ); - } + public function get_concerned_constants() { + return array( + 'ABSPATH', + 'COOKIEPATH', + 'SITECOOKIEPATH', + 'DOMAIN_CURRENT_SITE', + 'PATH_CURRENT_SITE', + 'WP_SITEURL', + 'WP_HOME', + 'WP_CONTENT_URL', + 'WP_CONTENT_DIR', + 'WP_PLUGIN_URL', + 'WP_PLUGIN_DIR', + 'PLUGINS_COOKIE_PATH', + 'WPMU_PLUGIN_DIR', + 'WPMU_PLUGIN_URL', + 'TEMPLATEPATH', + 'STYLESHEETPATH', + 'ADMIN_COOKIE_PATH', + 'WPINC', + 'WP_LANG_DIR', + 'BLOGUPLOADDIR', + 'UPLOADBLOGSDIR', + 'UPLOADS', + ); + } + public function get_concerned_options() { + return array( + 'siteurl', + 'home', + ); } - add_filter( 'qm/collectors', static function ( array $collectors ) : array { - $collectors['paths'] = new QMX_Collector_Paths; - return $collectors; - } ); +} -} \ No newline at end of file +add_filter( 'qm/collectors', static function ( array $collectors ) : array { + $collectors['paths'] = new QMX_Collector_Paths; + return $collectors; +} ); \ No newline at end of file diff --git a/paths/qmx-paths-data.php b/paths/qmx-paths-data.php index 819e139..55c23e6 100644 --- a/paths/qmx-paths-data.php +++ b/paths/qmx-paths-data.php @@ -1,30 +1,9 @@ plugin_path( 'assets/query-monitor.css' ); - - if ( ! file_exists( $qm ) ) { - return; + public function name() { + return __( 'Paths', 'query-monitor-extend' ); } - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); + public function output() { + $data = $this->collector->get_data(); - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) - return; + echo '
'; - require_once $qm_dir . 'output/Html.php'; + if ( !empty( $data->paths ) ) { + echo ''; + echo ''; + echo ''; + echo ''; - class QMX_Output_Html_Paths extends QM_Output_Html { + echo ''; - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); - } + echo ''; - public function name() { - return __( 'Paths', 'query-monitor-extend' ); - } + echo ''; + echo ''; - public function output() { - $data = $this->collector->get_data(); + echo ''; - echo '
'; - - if ( !empty( $data->paths ) ) { - echo '
' . esc_html( $this->collector->name() ) . '
'; + echo $this->build_sorter( __( 'Constant/Function', 'query-monitor-extend' ) ); + echo ''; + echo __( 'Path', 'query-monitor-extend' ); + echo '
'; - echo ''; - echo ''; + foreach ( $data->paths as $var => $value ) { echo ''; + echo ''; - echo ''; - - echo ''; - - echo ''; - echo ''; - - echo ''; + if ( is_string( $value ) ) { - foreach ( $data->paths as $var => $value ) { - echo ''; - echo ''; + # Remove ABSPATH and add back to support paths without ABSPATH. + $possible_path = str_replace( ABSPATH, '', $value ); + $possible_path = ABSPATH . $possible_path; - if ( is_string( $value ) ) { + if ( file_exists( $possible_path ) ) + $value = QM_Output_Html::output_filename( $value, $possible_path ); + else + $value = esc_html( $value ); - # Remove ABSPATH and add back to support paths without ABSPATH. - $possible_path = str_replace( ABSPATH, '', $value ); - $possible_path = ABSPATH . $possible_path; + echo ''; - if ( file_exists( $possible_path ) ) - $value = QM_Output_Html::output_filename( $value, $possible_path ); - else - $value = esc_html( $value ); + } else { - echo ''; + echo ''; - } else { - - echo ''; - - } - echo ''; - } - - echo ''; - echo ''; + } + echo ''; + } - echo ''; - echo '
' . esc_html( $this->collector->name() ) . '
' . esc_html( $var ) . ''; - echo $this->build_sorter( __( 'Constant/Function', 'query-monitor-extend' ) ); - echo ''; - echo __( 'Path', 'query-monitor-extend' ); - echo '
' . esc_html( $var ) . '' . $value . '' . $value . ''; + self::output_inner( $value ); + echo ''; - self::output_inner( $value ); - echo '
'; + echo ''; + echo ''; - } else { + echo ''; + echo ''; - echo '
'; - echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; - echo '
'; + } else { - } + echo '
'; + echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; + echo '
'; - echo '
'; + } - $this->current_id = 'qm-paths'; - $this->current_name = 'Paths'; + echo ''; - $this->output_concerns(); - } + $this->current_id = 'qm-paths'; + $this->current_name = 'Paths'; - public function panel_menu( array $menu ) { + $this->output_concerns(); + } - $menu['qm-paths'] = $this->menu( array( - 'title' => esc_html__( 'Paths', 'query-monitor-extend' ), - 'id' => 'query-monitor-extend-paths', - ) ); + public function panel_menu( array $menu ) { - return $menu; + $menu['qm-paths'] = $this->menu( array( + 'title' => esc_html__( 'Paths', 'query-monitor-extend' ), + 'id' => 'query-monitor-extend-paths', + ) ); - } + return $menu; } - add_filter( 'qm/outputter/html', static function ( array $output ) : array { - if ( $collector = QM_Collectors::get( 'paths' ) ) - $output['paths'] = new QMX_Output_Html_Paths( $collector ); +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function ( array $output ) : array { + if ( $collector = QM_Collectors::get( 'paths' ) ) + $output['paths'] = new QMX_Output_Html_Paths( $collector ); -}, 9 ); \ No newline at end of file + return $output; +}, 70 ); \ No newline at end of file diff --git a/qmx-conditionals.php b/qmx-conditionals.php index 9049899..ee2a005 100644 --- a/qmx-conditionals.php +++ b/qmx-conditionals.php @@ -1,13 +1,6 @@ data['functions'] = array( - 'UTC' => 'get_utc', - 'Server' => 'get_server', - 'WordPress' => 'get_wp', - 'Browser' => 'get_browser', - ); + function process() { + if ( did_action( 'qm/cease' ) ) + return; - } + $this->data['functions'] = array( + 'UTC' => 'get_utc', + 'Server' => 'get_server', + 'WordPress' => 'get_wp', + 'Browser' => 'get_browser', + ); - function get_utc() { - $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); - $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); - return $datetime->format( 'D, M j, Y H:i:s' ); - } + } - function get_server() { - $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); + function get_utc() { + $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); + $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); + return $datetime->format( 'D, M j, Y H:i:s' ); + } - if ( !empty( ini_get( 'date.timezone' ) ) ) - $datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) ); + function get_server() { + $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); - return $datetime->format( 'D, M j, Y H:i:s T' ); - } + if ( !empty( ini_get( 'date.timezone' ) ) ) + $datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) ); - function get_server_offset() { - $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); + return $datetime->format( 'D, M j, Y H:i:s T' ); + } - if ( !empty( ini_get( 'date.timezone' ) ) ) - $datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) ); + function get_server_offset() { + $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); - return $datetime->format( 'Z' ); - } + if ( !empty( ini_get( 'date.timezone' ) ) ) + $datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) ); - function get_server_timezone() { - $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); + return $datetime->format( 'Z' ); + } - if ( !empty( ini_get( 'date.timezone' ) ) ) - $datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) ); + function get_server_timezone() { + $datetime = date_create( "now", new DateTimeZone( 'UTC' ) ); - return $datetime->format( 'T' ); - } + if ( !empty( ini_get( 'date.timezone' ) ) ) + $datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) ); - function get_wp() { - return current_time( 'D, M j, Y H:i:s T' ); - } + return $datetime->format( 'T' ); + } - function get_wp_offset() { - return get_option( 'gmt_offset' ); - } + function get_wp() { + return current_time( 'D, M j, Y H:i:s T' ); + } - function get_wp_timezone() { - return current_time( 'T' ); - } + function get_wp_offset() { + return get_option( 'gmt_offset' ); + } - function get_browser() { - return '-'; - } + function get_wp_timezone() { + return current_time( 'T' ); + } + function get_browser() { + return '-'; } - add_filter( 'qm/collectors', static function ( array $collectors ) : array { - $collectors['time'] = new QMX_Collector_Time; - return $collectors; - } ); +} -} \ No newline at end of file +add_filter( 'qm/collectors', static function ( array $collectors ) : array { + $collectors['time'] = new QMX_Collector_Time; + return $collectors; +} ); \ No newline at end of file diff --git a/time/qmx-time-data.php b/time/qmx-time-data.php index 4a1eb90..99c9907 100644 --- a/time/qmx-time-data.php +++ b/time/qmx-time-data.php @@ -1,30 +1,9 @@ plugin_path( 'assets/query-monitor.css' ); - - if ( ! file_exists( $qm ) ) { - return; + public function __construct( QM_Collector $collector ) { + parent::__construct( $collector ); + add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); } - $qm_dir = trailingslashit( dirname( dirname( $qm ) ) ); - - if ( ! file_exists( $qm_dir . 'output/Html.php' ) ) - return; - - require_once $qm_dir . 'output/Html.php'; - - class QMX_Output_Html_Time extends QM_Output_Html { + public function output() { + $data = $this->collector->get_data(); + $wp_offset = get_option( 'gmt_offset' ); - public function __construct( QM_Collector $collector ) { - parent::__construct( $collector ); - add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); - } + echo '
' . + '
'; - public function output() { - $data = $this->collector->get_data(); - $wp_offset = get_option( 'gmt_offset' ); + foreach ( $data->functions as $label => $function ) { + if ( is_callable( array( $this->collector, $function ) ) ) + echo '
' . + '

' . esc_html( $label ) . '

' . + '

' . $this->collector->$function() . '

' . + '
'; + } - echo '
' . - '
'; + echo '
'; + ?> - foreach ( $data->functions as $label => $function ) { - if ( is_callable( array( $this->collector, $function ) ) ) - echo '
' . - '

' . esc_html( $label ) . '

' . - '

' . $this->collector->$function() . '

' . - '
'; - } + + + '; - var qmx_time_interval = 0; - - var observer = new IntersectionObserver( function( entries, observer ) { - if ( !entries[0].isIntersecting ) { - clearInterval( qmx_time_interval ); - return; - } - - var qmx_time_months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; - var qmx_time_days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; - - var qmx_time_container = document.getElementById( 'qm-time' ); - var qmx_time_utc = document.getElementById( 'qm-time-utc' ); - var qmx_time_server = document.getElementById( 'qm-time-server' ); - var qmx_time_wp = document.getElementById( 'qm-time-wordpress' ); - var qmx_time_browser = document.getElementById( 'qm-time-browser' ); - - if ( qmx_time_container ) { - qmx_time_interval = setInterval( function() { - var d = new Date(); - var UTC_string = d.toUTCString(); - var utc_time = d.getTime() + ( d.getTimezoneOffset() * 60 * 1000 ); - var server = new Date( utc_time + ( collector->get_server_offset() ) ?> * 1000 ) ); - var wp = new Date( utc_time + ( collector->get_wp_offset() * HOUR_IN_SECONDS ) ?> * 1000 ) ); - - qmx_time_utc.innerHTML = - qmx_time_days[d.getUTCDay()] + ', ' - + qmx_time_months[d.getUTCMonth()] + ' ' - + d.getUTCDate() + ', ' - + d.getUTCFullYear() + ' ' - + ( 10 > d.getUTCHours() ? '0' : '' ) + d.getUTCHours() - + ':' + ( 10 > d.getUTCMinutes() ? '0' : '' ) + d.getUTCMinutes() - + ':' + ( 10 > d.getUTCSeconds() ? '0' : '' ) + d.getUTCSeconds(); - - qmx_time_server.innerHTML = - qmx_time_days[server.getDay()] + ', ' - + qmx_time_months[server.getMonth()] + ' ' - + server.getDate() + ', ' - + server.getFullYear() + ' ' - + ( 10 > server.getHours() ? '0' : '' ) + server.getHours() - + ':' + ( 10 > server.getMinutes() ? '0' : '' ) + server.getMinutes() - + ':' + ( 10 > server.getSeconds() ? '0' : '' ) + server.getSeconds() - + ' collector->get_server_timezone() ) ?>'; - - qmx_time_wp.innerHTML = - qmx_time_days[wp.getDay()] + ', ' - + qmx_time_months[wp.getMonth()] + ' ' - + wp.getDate() + ', ' - + wp.getFullYear() + ' ' - + ( 10 > wp.getHours() ? '0' : '' ) + wp.getHours() - + ':' + ( 10 > wp.getMinutes() ? '0' : '' ) + wp.getMinutes() - + ':' + ( 10 > wp.getSeconds() ? '0' : '' ) + wp.getSeconds() - + ' collector->get_wp_timezone() ) ?>'; - - qmx_time_browser.innerHTML = - qmx_time_days[d.getDay()] + ', ' - + qmx_time_months[d.getMonth()] + ' ' - + d.getDate() + ', ' - + d.getFullYear() + ' ' - + ( 10 > d.getHours() ? '0' : '' ) + d.getHours() - + ':' + ( 10 > d.getMinutes() ? '0' : '' ) + d.getMinutes() - + ':' + ( 10 > d.getSeconds() ? '0' : '' ) + d.getSeconds(); - }, 1000 ); - } - } ); - - observer.observe( document.getElementById( 'qm-time' ) ); - - } () ); - - - '; - - } - - public function panel_menu( array $menu ) { + } - $menu['time'] = $this->menu( array( - 'title' => esc_html__( 'Time', 'query-monitor-extend' ), - 'id' => 'query-monitor-extend-time', - ) ); + public function panel_menu( array $menu ) { - return $menu; + $menu['time'] = $this->menu( array( + 'title' => esc_html__( 'Time', 'query-monitor-extend' ), + 'id' => 'query-monitor-extend-time', + ) ); - } + return $menu; } - add_filter( 'qm/outputter/html', static function ( array $output ) : array { - if ( $collector = QM_Collectors::get( 'time' ) ) - $output['time'] = new QMX_Output_Html_Time( $collector ); +} - return $output; - }, 70 ); +add_filter( 'qm/outputter/html', static function ( array $output ) : array { + if ( $collector = QM_Collectors::get( 'time' ) ) + $output['time'] = new QMX_Output_Html_Time( $collector ); -}, 9 ); \ No newline at end of file + return $output; +}, 70 ); \ No newline at end of file