Initial commit

This commit is contained in:
Felix Förtsch
2020-10-20 14:39:50 +02:00
commit 648ded8896
1225 changed files with 216511 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
/**
* Constants collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Constants extends QMX_Collector {
public $id = 'constants';
public function name() {
return __( 'Constants', 'query-monitor-extend' );
}
public function process() {
$constants = get_defined_constants( true );
$this->data['constants'] = $constants['user'];
}
}
function register_qmx_collector_constants( array $collectors, QueryMonitorExtend $qmx ) {
$collectors['constants'] = new QMX_Collector_Constants;
return $collectors;
}
add_filter( 'qmx/collectors', 'register_qmx_collector_constants', 10, 2 );

View File

@@ -0,0 +1,41 @@
<?php
/**
* Files collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Files extends QMX_Collector {
public $id = 'files';
public function name() {
return __( 'Files', 'query-monitor-extend' );
}
public function process() {
$php_errors = QM_Collectors::get( 'php_errors' )->get_data();
$files_with_errors = array();
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 ),
);
}
}
function register_qmx_collector_files( array $collectors, QueryMonitorExtend $qmx ) {
$collectors['files'] = new QMX_Collector_Files;
return $collectors;
}
add_filter( 'qmx/collectors', 'register_qmx_collector_files', 10, 2 );

View File

@@ -0,0 +1,165 @@
<?php
/**
* Heartbeat collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Heartbeat extends QMX_Collector {
public $id = 'heartbeat';
function __construct() {
parent::__construct();
if ( $this->qm_no_jquery() )
return;
add_action( 'wp_enqueue_scripts', array( &$this, 'add_inline_script' ) );
add_action( 'admin_enqueue_scripts', array( &$this, 'add_inline_script' ) );
}
public function add_inline_script() {
wp_add_inline_script( 'heartbeat', $this->_inlineScript_heartbeat() );
}
public function _inlineScript_heartbeat() {
ob_start();
?>
var qmx_heartbeat = {
_beat: null,
_beats: [],
_start: 0,
_table: null,
_tab: null,
_table_ready: false,
_prev_dub: 0,
init: function() {
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();
var count = ( that._beats.find( 'tr' ).length + 1 );
if (
2 == count
&& that._beats.find( 'tr' ).hasClass( 'listening' )
) {
that._beats.html( '' );
count = 1;
}
if ( !that._table_ready ) {
that._beat = { lub: lub };
return;
}
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:last-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( <?php echo json_encode( '#' . esc_attr( $this->id() ) . ' > table' ) ?> );
this._beats = this._table.find( 'tbody' );
},
add_table_row: function( tr ) {
this._table.find( 'tbody:last-child' ).append( tr );
},
get_table_row: function( index, lub, dub, since_last, duration ) {
var lub_diff = ( lub - this._start ) / 1000;
var dub_diff = ( dub - this._start ) / 1000;
var duration_secs = duration / 1000;
var since_last_secs = '-' != since_last ? since_last / 1000 : '-';
since_last_secs = '-' != since_last_secs ? since_last_secs.toFixed( 3 ) : '-';
return '<tr' +
(
1 == ( index % 2 )
? ' class="qm-odd"'
: ''
) +
'>' +
'<td class="qm-num">' + index + '</td>' +
'<td class="qm-num lub">' + lub_diff.toFixed( 3 ) + '</td>' +
'<td class="qm-num dub">' + dub_diff.toFixed( 3 ) + '</td>' +
'<td class="qm-num since">' + since_last_secs + '</td>' +
'<td class="qm-num dur">' + duration_secs.toFixed( 3 ) + '</td>' +
'</tr>';
},
update_tab: function( count ) {
this._tab = jQuery( '#qm-panel-menu button[data-qm-href=<?php echo json_encode( '#' . esc_attr( $this->id() ) ) ?>]' );
this._tab.html( 'Heartbeats (' + count + ')' );
}
};
qmx_heartbeat.init();
<?php
return ob_get_clean();
}
public function name() {
return __( 'Heartbeat', 'query-monitor-extend' );
}
public function process() {
}
public function qm_no_jquery() {
return defined( 'QM_NO_JQUERY' ) && QM_NO_JQUERY;
}
}
function register_qmx_collector_heartbeat( array $collectors, QueryMonitorExtend $qmx ) {
$collectors['heartbeat'] = new QMX_Collector_Heartbeat;
return $collectors;
}
add_filter( 'qmx/collectors', 'register_qmx_collector_heartbeat', 10, 2 );

View File

@@ -0,0 +1,195 @@
<?php
/**
* Image sizes collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Image_Sizes extends QMX_Collector {
public $id = 'image_sizes';
public function __construct() {
$this->data['sizes'] = array(
'thumbnail' => array(
'width' => intval( get_option( 'thumbnail_size_w' ) ),
'height' => intval( get_option( 'thumbnail_size_h' ) ),
'source' => 'native',
'crop' => true,
'num' => 1,
),
'medium' => array(
'width' => intval( get_option( 'medium_size_w' ) ),
'height' => intval( get_option( 'medium_size_h' ) ),
'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' ) ),
'source' => 'native',
'crop' => false,
'num' => 3,
),
'large' => array(
'width' => intval( get_option( 'large_size_w' ) ),
'height' => intval( get_option( 'large_size_h' ) ),
'source' => 'native',
'crop' => false,
'num' => 4,
),
);
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 );
}
function action__plugins_loaded() {
if ( 'plugins_loaded' !== current_action() )
return;
$this->_process_added_image_sizes( 'plugin' );
}
function action__after_setup_theme() {
if ( 'after_setup_theme' !== current_action() )
return;
$this->_process_added_image_sizes( 'theme' );
}
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 )
),
$size
);
}
public function name() {
return __( 'Image Sizes', 'query-monitor-extend' );
}
public function process() {
$this->_process_added_image_sizes();
$this->data['sizes'] = array_map( array( &$this, 'add_ratio' ), $this->data['sizes'] );
$counts = array( 'dimensions' => array(), 'ratios' => array() );
foreach ( $this->data['sizes'] as $size ) {
$key = $size['width'] . ':' . $size['height'] . ' - ' . $size['crop'];
array_key_exists( $key, $counts['dimensions'] )
? $counts['dimensions'][$key]++
: $counts['dimensions'][$key] = 1;
$key = $size['ratio'] . ' - ' . $size['crop'];
if ( 0 !== $size['ratio'] )
array_key_exists( $key, $counts['ratios'] )
? $counts['ratios'][$key]++
: $counts['ratios'][$key] = 1;
}
foreach ( array( 'dimensions', 'ratios' ) as $type )
$counts[$type] = array_filter( $counts[$type], function( $v ) { return $v > 1; } );
$this->data['_duplicates'] = $counts;
}
private function add_ratio( array $size ) {
if (
!array_key_exists( 'width', $size )
|| !array_key_exists( 'height', $size )
)
return $size;
$num1 = $size['width'];
$num2 = $size['height'];
while ( 0 !== $num2 ) {
$t = $num1 % $num2;
$num1 = $num2;
$num2 = $t;
}
$size['_gcd'] = $num1; // greatest common denominator
unset( $num1, $num2 );
$size['ratio'] = (
0 === $size['height']
? 0
: $size['width'] / $size['height']
);
return $size;
}
public function add_inline_script() {
wp_add_inline_script( 'query-monitor', $this->_inlineScript_queryMonitor() );
}
protected function _inlineScript_queryMonitor() {
ob_start();
?>
if ( window.jQuery ) {
jQuery( function( $ ) {
$( '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 ); } );
$( '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__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' );
}
}
<?php
return ob_get_clean();
}
}
QMX_Collectors::add( new QMX_Collector_Image_Sizes );
?>

View File

@@ -0,0 +1,79 @@
<?php
/**
* Paths collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Paths extends QMX_Collector {
public $id = 'paths';
public function name() {
return __( 'Paths', 'query-monitor-extend' );
}
function process() {
$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(),
) );
ksort( $this->data['paths'] );
}
}
function register_qmx_collector_paths( array $collectors, QueryMonitorExtend $qmx ) {
$collectors['paths'] = new QMX_Collector_Paths;
return $collectors;
}
add_filter( 'qmx/collectors', 'register_qmx_collector_paths', 10, 2 );

View File

@@ -0,0 +1,70 @@
<?php
/**
* Time collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Time extends QMX_Collector {
public $id = 'time';
public function name() {
return __( 'Time', 'query-monitor-extend' );
}
function process() {
$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' ) );
if ( !empty( ini_get( 'date.timezone' ) ) )
$datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) );
return $datetime->format( 'D, M j, Y H:i:s' );
}
function get_server_offset() {
$datetime = date_create( "now", new DateTimeZone( 'UTC' ) );
if ( !empty( ini_get( 'date.timezone' ) ) )
$datetime->setTimezone( new DateTimeZone( ini_get( 'date.timezone' ) ) );
return $datetime->format( 'Z' );
}
function get_wp() {
return current_time( 'D, M j, Y H:i:s' );
}
function get_wp_offset() {
return get_option( 'gmt_offset' );
}
function get_browser() {
return '-';
}
}
function register_qmx_collector_time( array $collectors, QueryMonitorExtend $qmx ) {
$collectors['time'] = new QMX_Collector_Time;
return $collectors;
}
add_filter( 'qmx/collectors', 'register_qmx_collector_time', 10, 2 );

View File

@@ -0,0 +1,51 @@
<?php
/**
* Var dumps collector.
*
* @package query-monitor-extend
*/
class QMX_Collector_Var_Dumps extends QMX_Collector {
public $id = 'var_dumps';
function __construct() {
add_action( 'qmx/var_dump', array( &$this, 'collect' ), 10, 2 );
parent::__construct();
$this->data['vars'] = array();
}
public function name() {
return __( 'Var Dumps', 'query-monitor-extend' );
}
public function collect( $var, $label = null ) {
if ( is_null( $label ) )
$label = time();
else if ( array_key_exists( $label, $this->data['vars'] ) )
$label .= ' (' . time() . ')';
$this->data['vars'][$label] = $var;
}
}
QMX_Collectors::add( new QMX_Collector_Var_Dumps );
// Backwards compatibility
if ( !function_exists( 'qmx_dump' ) ) {
function qmx_dump( $var, $label = null ) {
if ( QMX_Collectors::get( 'var_dumps' ) )
QMX_Collectors::get( 'var_dumps' )->collect( $var, $label );
}
}
if ( !function_exists( 'qm_dump' ) ) {
function qm_dump( $var, $label = null ) {
qmx_dump( $var, $label );
}
}