Query Monitor - Version 2.6.9

Version Description

  • New Scripts & Styles component; Support the new admin menu behaviour in WP 4.1; Fix the positioning of output when using the Twenty Fifteen theme.

=

Download this release

Release Info

Developer johnbillion
Plugin Icon 128x128 Query Monitor
Version 2.6.9
Comparing to
See all releases

Code changes from version 2.6.8 to 2.6.9

Backtrace.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@ GNU General Public License for more details.
14
 
15
  */
16
 
 
17
  class QM_Backtrace {
18
 
19
  protected static $ignore_class = array(
@@ -75,10 +76,12 @@ class QM_Backtrace {
75
  }
76
 
77
 
78
- if ( $args['ignore_items'] )
79
  $this->ignore( $args['ignore_items'] );
80
- if ( $args['ignore_current_filter'] )
 
81
  $this->ignore_current_filter();
 
82
 
83
  }
84
 
@@ -108,10 +111,12 @@ class QM_Backtrace {
108
  try {
109
 
110
  if ( isset( $item['class'] ) ) {
111
- if ( !is_object( $item['class'] ) and !class_exists( $item['class'], false ) )
112
  continue;
113
- if ( !method_exists( $item['class'], $item['function'] ) )
 
114
  continue;
 
115
  $ref = new ReflectionMethod( $item['class'], $item['function'] );
116
  $file = $ref->getFileName();
117
  } else if ( function_exists( $item['function'] ) ) {
@@ -132,8 +137,9 @@ class QM_Backtrace {
132
  }
133
 
134
  foreach ( QM_Util::get_file_dirs() as $type => $dir ) {
135
- if ( isset( $components[$type] ) )
136
  return $components[$type];
 
137
  }
138
 
139
  # This should not happen
@@ -151,7 +157,7 @@ class QM_Backtrace {
151
  $trace = array_map( array( $this, 'filter_trace' ), $this->trace );
152
  $trace = array_values( array_filter( $trace ) );
153
 
154
- if ( empty( $trace ) ) {
155
  $lowest = $this->trace[0];
156
  $file = QM_Util::standard_dir( $lowest['file'], '' );
157
  $lowest['calling_file'] = $lowest['file'];
@@ -172,8 +178,9 @@ class QM_Backtrace {
172
  }
173
 
174
  public function ignore( $num ) {
175
- for ( $i = 0; $i < absint( $num ); $i++ )
176
  unset( $this->trace[$i] );
 
177
  $this->trace = array_values( $this->trace );
178
  return $this;
179
  }
@@ -181,8 +188,9 @@ class QM_Backtrace {
181
  public function ignore_current_filter() {
182
 
183
  if ( isset( $this->trace[2] ) and isset( $this->trace[2]['function'] ) ) {
184
- if ( in_array( $this->trace[2]['function'], array( 'apply_filters', 'do_action' ) ) )
185
  $this->ignore( 3 ); # Ignore filter and action callbacks
 
186
  }
187
 
188
  }
@@ -227,7 +235,7 @@ class QM_Backtrace {
227
 
228
  if ( 'dir' === $show ) {
229
  if ( isset( $trace['args'][0] ) ) {
230
- $arg = QM_Util::standard_dir( $trace['args'][0], '&hellip;/' );
231
  $return['id'] = $trace['function'] . '()';
232
  $return['display'] = $trace['function'] . "('{$arg}')";
233
  }
@@ -257,13 +265,20 @@ class QM_Backtrace {
257
 
258
  }
259
 
260
- if ( isset( $trace['line'] ) )
261
  $this->calling_line = $trace['line'];
262
- if ( isset( $trace['file'] ) )
 
263
  $this->calling_file = $trace['file'];
 
264
 
265
  return $return;
266
 
267
  }
268
 
269
  }
 
 
 
 
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
14
 
15
  */
16
 
17
+ if ( ! class_exists( 'QM_Backtrace' ) ) {
18
  class QM_Backtrace {
19
 
20
  protected static $ignore_class = array(
76
  }
77
 
78
 
79
+ if ( $args['ignore_items'] ) {
80
  $this->ignore( $args['ignore_items'] );
81
+ }
82
+ if ( $args['ignore_current_filter'] ) {
83
  $this->ignore_current_filter();
84
+ }
85
 
86
  }
87
 
111
  try {
112
 
113
  if ( isset( $item['class'] ) ) {
114
+ if ( !is_object( $item['class'] ) and !class_exists( $item['class'], false ) ) {
115
  continue;
116
+ }
117
+ if ( !method_exists( $item['class'], $item['function'] ) ) {
118
  continue;
119
+ }
120
  $ref = new ReflectionMethod( $item['class'], $item['function'] );
121
  $file = $ref->getFileName();
122
  } else if ( function_exists( $item['function'] ) ) {
137
  }
138
 
139
  foreach ( QM_Util::get_file_dirs() as $type => $dir ) {
140
+ if ( isset( $components[$type] ) ) {
141
  return $components[$type];
142
+ }
143
  }
144
 
145
  # This should not happen
157
  $trace = array_map( array( $this, 'filter_trace' ), $this->trace );
158
  $trace = array_values( array_filter( $trace ) );
159
 
160
+ if ( empty( $trace ) && !empty($this->trace) ) {
161
  $lowest = $this->trace[0];
162
  $file = QM_Util::standard_dir( $lowest['file'], '' );
163
  $lowest['calling_file'] = $lowest['file'];
178
  }
179
 
180
  public function ignore( $num ) {
181
+ for ( $i = 0; $i < absint( $num ); $i++ ) {
182
  unset( $this->trace[$i] );
183
+ }
184
  $this->trace = array_values( $this->trace );
185
  return $this;
186
  }
188
  public function ignore_current_filter() {
189
 
190
  if ( isset( $this->trace[2] ) and isset( $this->trace[2]['function'] ) ) {
191
+ if ( in_array( $this->trace[2]['function'], array( 'apply_filters', 'do_action' ) ) ) {
192
  $this->ignore( 3 ); # Ignore filter and action callbacks
193
+ }
194
  }
195
 
196
  }
235
 
236
  if ( 'dir' === $show ) {
237
  if ( isset( $trace['args'][0] ) ) {
238
+ $arg = QM_Util::standard_dir( $trace['args'][0], '~/' );
239
  $return['id'] = $trace['function'] . '()';
240
  $return['display'] = $trace['function'] . "('{$arg}')";
241
  }
265
 
266
  }
267
 
268
+ if ( isset( $trace['line'] ) ) {
269
  $this->calling_line = $trace['line'];
270
+ }
271
+ if ( isset( $trace['file'] ) ) {
272
  $this->calling_file = $trace['file'];
273
+ }
274
 
275
  return $return;
276
 
277
  }
278
 
279
  }
280
+ } else {
281
+
282
+ add_action( 'init', 'QueryMonitor::symlink_warning' );
283
+
284
+ }
Collector.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -14,11 +14,12 @@ GNU General Public License for more details.
14
 
15
  */
16
 
 
17
  abstract class QM_Collector {
18
 
19
  protected $data = array();
20
 
21
- protected function __construct() {}
22
 
23
  final public function id() {
24
  return "qm-{$this->id}";
@@ -46,12 +47,16 @@ abstract class QM_Collector {
46
  }
47
 
48
  public static function sort_ltime( $a, $b ) {
49
- if ( $a['ltime'] == $b['ltime'] )
50
  return 0;
51
- else
52
  return ( $a['ltime'] > $b['ltime'] ) ? -1 : 1;
 
53
  }
54
 
55
  public function process() {}
56
 
 
 
 
57
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
14
 
15
  */
16
 
17
+ if ( ! class_exists( 'QM_Collector' ) ) {
18
  abstract class QM_Collector {
19
 
20
  protected $data = array();
21
 
22
+ public function __construct() {}
23
 
24
  final public function id() {
25
  return "qm-{$this->id}";
47
  }
48
 
49
  public static function sort_ltime( $a, $b ) {
50
+ if ( $a['ltime'] == $b['ltime'] ) {
51
  return 0;
52
+ } else {
53
  return ( $a['ltime'] > $b['ltime'] ) ? -1 : 1;
54
+ }
55
  }
56
 
57
  public function process() {}
58
 
59
+ public function tear_down() {}
60
+
61
+ }
62
  }
Dispatcher.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -15,6 +14,7 @@ GNU General Public License for more details.
15
 
16
  */
17
 
 
18
  abstract class QM_Dispatcher {
19
 
20
  public function __construct( QM_Plugin $qm ) {
@@ -55,3 +55,4 @@ abstract class QM_Dispatcher {
55
  }
56
 
57
  }
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
14
 
15
  */
16
 
17
+ if ( ! class_exists( 'QM_Dispatcher' ) ) {
18
  abstract class QM_Dispatcher {
19
 
20
  public function __construct( QM_Plugin $qm ) {
55
  }
56
 
57
  }
58
+ }
Output.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@ GNU General Public License for more details.
14
 
15
  */
16
 
 
17
  interface QM_Output {
18
 
19
  public function __construct( QM_Collector $collector );
@@ -21,3 +22,4 @@ interface QM_Output {
21
  public function output();
22
 
23
  }
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
14
 
15
  */
16
 
17
+ if ( ! class_exists( 'QM_Output' ) ) {
18
  interface QM_Output {
19
 
20
  public function __construct( QM_Collector $collector );
22
  public function output();
23
 
24
  }
25
+ }
Plugin.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@ GNU General Public License for more details.
14
 
15
  */
16
 
 
17
  abstract class QM_Plugin {
18
 
19
  /**
@@ -85,3 +86,4 @@ abstract class QM_Plugin {
85
  }
86
 
87
  }
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
14
 
15
  */
16
 
17
+ if ( ! class_exists( 'QM_Plugin' ) ) {
18
  abstract class QM_Plugin {
19
 
20
  /**
86
  }
87
 
88
  }
89
+ }
Util.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -15,6 +14,7 @@ GNU General Public License for more details.
15
 
16
  */
17
 
 
18
  class QM_Util {
19
 
20
  protected static $file_components = array();
@@ -34,8 +34,9 @@ class QM_Util {
34
  if ( $bytes ) {
35
  $last = strtolower( substr( $size, -1 ) );
36
  $pos = strpos( ' kmg', $last, 1);
37
- if ( $pos )
38
  $bytes *= pow( 1024, $pos );
 
39
  $bytes = round( $bytes );
40
  }
41
 
@@ -67,8 +68,9 @@ class QM_Util {
67
 
68
  # @TODO turn this into a class (eg QM_File_Component)
69
 
70
- if ( isset( self::$file_components[$file] ) )
71
  return self::$file_components[$file];
 
72
 
73
  if ( empty( self::$file_dirs ) ) {
74
  self::$file_dirs['plugin'] = self::standard_dir( WP_PLUGIN_DIR );
@@ -80,10 +82,13 @@ class QM_Util {
80
  }
81
 
82
  foreach ( self::$file_dirs as $type => $dir ) {
83
- if ( 0 === strpos( $file, $dir ) )
84
  break;
 
85
  }
86
 
 
 
87
  switch ( $type ) {
88
  case 'plugin':
89
  case 'muplugin':
@@ -94,7 +99,8 @@ class QM_Util {
94
  } else {
95
  $plug = basename( $plug );
96
  }
97
- $name = sprintf( __( 'Plugin: %s', 'query-monitor' ), $plug );
 
98
  break;
99
  case 'stylesheet':
100
  $name = __( 'Theme', 'query-monitor' );
@@ -103,7 +109,8 @@ class QM_Util {
103
  $name = __( 'Parent Theme', 'query-monitor' );
104
  break;
105
  case 'other':
106
- $name = self::standard_dir( $file, '' );
 
107
  break;
108
  case 'core':
109
  default:
@@ -111,7 +118,7 @@ class QM_Util {
111
  break;
112
  }
113
 
114
- return self::$file_components[$file] = (object) compact( 'type', 'name' );
115
 
116
  }
117
 
@@ -128,10 +135,11 @@ class QM_Util {
128
 
129
  if ( is_array( $callback['function'] ) ) {
130
 
131
- if ( is_object( $callback['function'][0] ) )
132
  $class = get_class( $callback['function'][0] );
133
- else
134
  $class = $callback['function'][0];
 
135
 
136
  $callback['name'] = $class . $access . $callback['function'][1] . '()';
137
  $ref = new ReflectionMethod( $class, $callback['function'][1] );
@@ -164,24 +172,28 @@ class QM_Util {
164
  }
165
 
166
  public static function is_ajax() {
167
- if ( defined( 'DOING_AJAX' ) and DOING_AJAX )
168
  return true;
 
169
  return false;
170
  }
171
 
172
  public static function is_async() {
173
- if ( self::is_ajax() )
174
  return true;
175
- if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and 'xmlhttprequest' == strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) )
 
176
  return true;
 
177
  return false;
178
  }
179
 
180
  public static function get_admins() {
181
- if ( is_multisite() )
182
  return false;
183
- else
184
  return get_role( 'administrator' );
 
185
  }
186
 
187
  public static function get_current_url() {
@@ -189,3 +201,4 @@ class QM_Util {
189
  }
190
 
191
  }
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
14
 
15
  */
16
 
17
+ if ( ! class_exists( 'QM_Util' ) ) {
18
  class QM_Util {
19
 
20
  protected static $file_components = array();
34
  if ( $bytes ) {
35
  $last = strtolower( substr( $size, -1 ) );
36
  $pos = strpos( ' kmg', $last, 1);
37
+ if ( $pos ) {
38
  $bytes *= pow( 1024, $pos );
39
+ }
40
  $bytes = round( $bytes );
41
  }
42
 
68
 
69
  # @TODO turn this into a class (eg QM_File_Component)
70
 
71
+ if ( isset( self::$file_components[$file] ) ) {
72
  return self::$file_components[$file];
73
+ }
74
 
75
  if ( empty( self::$file_dirs ) ) {
76
  self::$file_dirs['plugin'] = self::standard_dir( WP_PLUGIN_DIR );
82
  }
83
 
84
  foreach ( self::$file_dirs as $type => $dir ) {
85
+ if ( 0 === strpos( $file, $dir ) ) {
86
  break;
87
+ }
88
  }
89
 
90
+ $context = $type;
91
+
92
  switch ( $type ) {
93
  case 'plugin':
94
  case 'muplugin':
99
  } else {
100
  $plug = basename( $plug );
101
  }
102
+ $name = sprintf( __( 'Plugin: %s', 'query-monitor' ), $plug );
103
+ $context = $plug;
104
  break;
105
  case 'stylesheet':
106
  $name = __( 'Theme', 'query-monitor' );
109
  $name = __( 'Parent Theme', 'query-monitor' );
110
  break;
111
  case 'other':
112
+ $name = self::standard_dir( $file, '' );
113
+ $context = $file;
114
  break;
115
  case 'core':
116
  default:
118
  break;
119
  }
120
 
121
+ return self::$file_components[$file] = (object) compact( 'type', 'name', 'context' );
122
 
123
  }
124
 
135
 
136
  if ( is_array( $callback['function'] ) ) {
137
 
138
+ if ( is_object( $callback['function'][0] ) ) {
139
  $class = get_class( $callback['function'][0] );
140
+ } else {
141
  $class = $callback['function'][0];
142
+ }
143
 
144
  $callback['name'] = $class . $access . $callback['function'][1] . '()';
145
  $ref = new ReflectionMethod( $class, $callback['function'][1] );
172
  }
173
 
174
  public static function is_ajax() {
175
+ if ( defined( 'DOING_AJAX' ) and DOING_AJAX ) {
176
  return true;
177
+ }
178
  return false;
179
  }
180
 
181
  public static function is_async() {
182
+ if ( self::is_ajax() ) {
183
  return true;
184
+ }
185
+ if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and 'xmlhttprequest' == strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ) {
186
  return true;
187
+ }
188
  return false;
189
  }
190
 
191
  public static function get_admins() {
192
+ if ( is_multisite() ) {
193
  return false;
194
+ } else {
195
  return get_role( 'administrator' );
196
+ }
197
  }
198
 
199
  public static function get_current_url() {
201
  }
202
 
203
  }
204
+ }
assets/compat.css CHANGED
@@ -1,6 +1,5 @@
1
  /*
2
-
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
1
  /*
2
+ Copyright 2009-2015 John Blackbourn
 
3
 
4
  This program is free software; you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
assets/query-monitor.css CHANGED
@@ -1,6 +1,5 @@
1
  /*
2
-
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -18,6 +17,7 @@ GNU General Public License for more details.
18
  color: #8c8 !important;
19
  }
20
 
 
21
  #wpadminbar .quicklinks .menupop ul li.qm-true > a:hover {
22
  color: #4a4 !important;
23
  }
@@ -124,6 +124,11 @@ GNU General Public License for more details.
124
  display: none;
125
  }
126
 
 
 
 
 
 
127
  #qm.qm-show,
128
  .no-js #qm,
129
  .nojs #qm {
@@ -137,24 +142,21 @@ GNU General Public License for more details.
137
  height: 0 !important;
138
  }
139
 
140
- body.wp-admin #qm {
141
- margin: 0 !important;
142
  }
143
 
144
- body:not(.iframe).sticky-menu #qm {
145
- margin-left: 160px !important;
 
146
  }
147
 
148
- @media all and (max-width: 900px) {
149
- body:not(.iframe).sticky-menu #qm {
150
- margin-left: 36px !important;
151
  }
152
  }
153
 
154
- body:not(.iframe).sticky-menu.folded #qm {
155
- margin-left: 36px !important;
156
- }
157
-
158
  #qm-wrapper {
159
  margin: 0 auto;
160
  max-width: 100em;
@@ -183,6 +185,14 @@ body.js #qm-wrapper {
183
  clear: none !important;
184
  }
185
 
 
 
 
 
 
 
 
 
186
  .qm-clear {
187
  clear: left !important;
188
  }
@@ -193,6 +203,8 @@ body.js #qm-wrapper {
193
  border-style: hidden !important;
194
  box-shadow: 0 0 0 1px #ddd, 0 1px 2px 1px rgba(0,0,0,0.05) !important;
195
  width: 100% !important;
 
 
196
  }
197
 
198
  .qm td,
@@ -328,6 +340,7 @@ body.js #qm-wrapper {
328
  border: 1px solid transparent !important;
329
  }
330
 
 
331
  .qm a.qm-toggle:hover {
332
  text-decoration: none !important;
333
  border-color: #e1e1e1 !important;
@@ -390,8 +403,8 @@ select.qm-filter {
390
  .qm .qm-sort {
391
  color: #ddd !important;
392
  display: block !important;
393
- font-size: 11px !important;
394
- line-height: 9px !important;
395
  text-decoration: none !important;
396
  }
397
 
@@ -399,7 +412,7 @@ select.qm-filter {
399
  .qm .qm-sort:focus,
400
  .qm .qm-sorted-asc .qm-sort-asc,
401
  .qm .qm-sorted-desc .qm-sort-desc {
402
- color: #888 !important;
403
  text-decoration: none !important;
404
  }
405
 
1
  /*
2
+ Copyright 2009-2015 John Blackbourn
 
3
 
4
  This program is free software; you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
17
  color: #8c8 !important;
18
  }
19
 
20
+ #wpadminbar .quicklinks .menupop ul li.qm-true > a:focus,
21
  #wpadminbar .quicklinks .menupop ul li.qm-true > a:hover {
22
  color: #4a4 !important;
23
  }
124
  display: none;
125
  }
126
 
127
+ #qm.qm-absolute {
128
+ z-index: 9999 !important;
129
+ position: absolute !important;
130
+ }
131
+
132
  #qm.qm-show,
133
  .no-js #qm,
134
  .nojs #qm {
142
  height: 0 !important;
143
  }
144
 
145
+ body:not(.iframe).wp-admin #qm {
146
+ margin: 0 0 0 160px !important;
147
  }
148
 
149
+ body:not(.iframe).wp-admin.auto-fold #qm,
150
+ body:not(.iframe).wp-admin.folded #qm {
151
+ margin-left: 36px !important;
152
  }
153
 
154
+ @media screen and (max-width: 782px) {
155
+ body:not(.iframe).wp-admin #qm {
156
+ margin-left: 0 !important;
157
  }
158
  }
159
 
 
 
 
 
160
  #qm-wrapper {
161
  margin: 0 auto;
162
  max-width: 100em;
185
  clear: none !important;
186
  }
187
 
188
+ @media all and (max-width: 900px) {
189
+ .qm-half {
190
+ float: none !important;
191
+ width: 100% !important;
192
+ clear: both !important;
193
+ }
194
+ }
195
+
196
  .qm-clear {
197
  clear: left !important;
198
  }
203
  border-style: hidden !important;
204
  box-shadow: 0 0 0 1px #ddd, 0 1px 2px 1px rgba(0,0,0,0.05) !important;
205
  width: 100% !important;
206
+ table-layout: auto !important;
207
+ margin: 0 !important;
208
  }
209
 
210
  .qm td,
340
  border: 1px solid transparent !important;
341
  }
342
 
343
+ .qm a.qm-toggle:focus,
344
  .qm a.qm-toggle:hover {
345
  text-decoration: none !important;
346
  border-color: #e1e1e1 !important;
403
  .qm .qm-sort {
404
  color: #ddd !important;
405
  display: block !important;
406
+ font-size: 14px !important;
407
+ line-height: 11px !important;
408
  text-decoration: none !important;
409
  }
410
 
412
  .qm .qm-sort:focus,
413
  .qm .qm-sorted-asc .qm-sort-asc,
414
  .qm .qm-sorted-desc .qm-sort-desc {
415
+ color: #777 !important;
416
  text-decoration: none !important;
417
  }
418
 
assets/query-monitor.js CHANGED
@@ -1,6 +1,5 @@
1
  /*
2
-
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -93,6 +92,15 @@ jQuery( function($) {
93
  if ( is_admin ) {
94
  $('#wpfooter').css('position','relative');
95
  }
 
 
 
 
 
 
 
 
 
96
  $('#qm').show();
97
  });
98
 
@@ -179,6 +187,17 @@ jQuery( function($) {
179
  $('#qm').detach().appendTo('#wpwrap');
180
  }
181
 
 
 
 
 
 
 
 
 
 
 
 
182
  $.qm.tableSort({target: $('.qm-sortable'), debug: false});
183
 
184
  } );
1
  /*
2
+ Copyright 2009-2015 John Blackbourn
 
3
 
4
  This program is free software; you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
92
  if ( is_admin ) {
93
  $('#wpfooter').css('position','relative');
94
  }
95
+ if ( window.infinite_scroll && infinite_scroll.contentSelector ) {
96
+
97
+ $( infinite_scroll.contentSelector ).infinitescroll('pause');
98
+
99
+ if ( window.console ) {
100
+ console.log( qm_l10n.infinitescroll_paused );
101
+ }
102
+
103
+ }
104
  $('#qm').show();
105
  });
106
 
187
  $('#qm').detach().appendTo('#wpwrap');
188
  }
189
 
190
+ $('.qm-auth').on('click',function(e){
191
+ var action = $(this).data('action');
192
+ $.post(qm_l10n.ajaxurl,{
193
+ action : 'qm_auth_' + action,
194
+ nonce : qm_l10n.auth_nonce[action]
195
+ },function(response){
196
+ alert( response.data );
197
+ });
198
+ e.preventDefault();
199
+ })
200
+
201
  $.qm.tableSort({target: $('.qm-sortable'), debug: false});
202
 
203
  } );
collectors/admin.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -22,18 +22,15 @@ class QM_Collector_Admin extends QM_Collector {
22
  return __( 'Admin Screen', 'query-monitor' );
23
  }
24
 
25
- public function __construct() {
26
- parent::__construct();
27
- }
28
-
29
  public function process() {
30
 
31
  global $pagenow;
32
 
33
- if ( isset( $_GET['page'] ) )
34
  $this->data['base'] = get_current_screen()->base;
35
- else
36
  $this->data['base'] = $pagenow;
 
37
 
38
  $this->data['pagenow'] = $pagenow;
39
  $this->data['current_screen'] = get_current_screen();
@@ -43,8 +40,9 @@ class QM_Collector_Admin extends QM_Collector {
43
  }
44
 
45
  function register_qm_collector_admin( array $qm ) {
46
- if ( is_admin() )
47
  $qm['admin'] = new QM_Collector_Admin;
 
48
  return $qm;
49
  }
50
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
22
  return __( 'Admin Screen', 'query-monitor' );
23
  }
24
 
 
 
 
 
25
  public function process() {
26
 
27
  global $pagenow;
28
 
29
+ if ( isset( $_GET['page'] ) ) {
30
  $this->data['base'] = get_current_screen()->base;
31
+ } else {
32
  $this->data['base'] = $pagenow;
33
+ }
34
 
35
  $this->data['pagenow'] = $pagenow;
36
  $this->data['current_screen'] = get_current_screen();
40
  }
41
 
42
  function register_qm_collector_admin( array $qm ) {
43
+ if ( is_admin() ) {
44
  $qm['admin'] = new QM_Collector_Admin;
45
+ }
46
  return $qm;
47
  }
48
 
collectors/assets.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Copyright 2009-2015 John Blackbourn
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ */
16
+
17
+ class QM_Collector_Assets extends QM_Collector {
18
+
19
+ public $id = 'assets';
20
+
21
+ public function __construct() {
22
+ parent::__construct();
23
+ add_action( 'admin_print_footer_scripts', array( $this, 'action_print_footer_scripts' ) );
24
+ add_action( 'wp_print_footer_scripts', array( $this, 'action_print_footer_scripts' ) );
25
+ }
26
+
27
+ public function action_print_footer_scripts() {
28
+ global $wp_scripts, $wp_styles;
29
+
30
+ $this->data['raw_scripts'] = $wp_scripts;
31
+ $this->data['raw_styles'] = $wp_styles;
32
+
33
+ $this->data['header_scripts'] = array_diff( $wp_scripts->done, $wp_scripts->in_footer );
34
+ $this->data['footer_scripts'] = $wp_scripts->in_footer;
35
+ $this->data['header_styles'] = $wp_styles->done;
36
+
37
+ }
38
+
39
+ public function name() {
40
+ return __( 'Scripts & Styles', 'query-monitor' );
41
+ }
42
+
43
+ public function process() {
44
+
45
+ global $wp_scripts, $wp_styles;
46
+
47
+ // @TODO remove
48
+
49
+ }
50
+
51
+ }
52
+
53
+ function register_qm_collector_assets( array $qm ) {
54
+ $qm['assets'] = new QM_Collector_Assets;
55
+ return $qm;
56
+ }
57
+
58
+ add_filter( 'query_monitor_collectors', 'register_qm_collector_assets', 80 );
collectors/authentication.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -24,50 +24,74 @@ class QM_Collector_Authentication extends QM_Collector {
24
 
25
  public function __construct() {
26
  parent::__construct();
27
- add_action( 'plugins_loaded', array( $this, 'action_plugins_loaded' ) );
 
 
28
  }
29
 
30
  public function action_plugins_loaded() {
31
 
32
- if ( !defined( 'QM_COOKIE' ) )
33
  define( 'QM_COOKIE', 'query_monitor_' . COOKIEHASH );
 
34
 
35
  }
36
 
37
- public function user_verified() {
38
- if ( isset( $_COOKIE[QM_COOKIE] ) )
39
- return $this->verify_cookie( stripslashes( $_COOKIE[QM_COOKIE] ) );
40
- return false;
 
 
 
41
  }
42
 
43
- public function get_cookie_attributes() {
 
 
 
 
 
 
 
 
 
 
44
 
45
- return array(
46
- 'name' => QM_COOKIE,
47
- 'path' => COOKIEPATH,
48
- 'domain' => COOKIE_DOMAIN,
49
- );
50
 
51
  }
52
 
53
- public function get_cookie_content() {
 
 
 
 
 
 
 
 
54
 
55
- $expires = time() + 172800; # 48 hours
56
- $value = wp_generate_auth_cookie( get_current_user_id(), $expires, 'logged_in' );
57
- $secure = apply_filters( 'secure_logged_in_cookie', false, get_current_user_id(), is_ssl() );
58
 
59
- return compact( 'expires', 'value', 'secure' );
60
 
61
  }
62
 
63
- public function verify_cookie( $value ) {
 
 
 
 
 
64
 
 
65
  if ( $old_user_id = wp_validate_auth_cookie( $value, 'logged_in' ) ) {
66
  return user_can( $old_user_id, 'view_query_monitor' );
67
  }
68
-
69
  return false;
70
-
71
  }
72
 
73
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
24
 
25
  public function __construct() {
26
  parent::__construct();
27
+ add_action( 'plugins_loaded', array( $this, 'action_plugins_loaded' ) );
28
+ add_action( 'wp_ajax_qm_auth_on', array( $this, 'ajax_on' ) );
29
+ add_action( 'wp_ajax_qm_auth_off', array( $this, 'ajax_off' ) );
30
  }
31
 
32
  public function action_plugins_loaded() {
33
 
34
+ if ( !defined( 'QM_COOKIE' ) ) {
35
  define( 'QM_COOKIE', 'query_monitor_' . COOKIEHASH );
36
+ }
37
 
38
  }
39
 
40
+ /**
41
+ * Helper function. Should the authentication cookie be secure?
42
+ *
43
+ * @return bool Should the authentication cookie be secure?
44
+ */
45
+ public static function secure_cookie() {
46
+ return ( is_ssl() and ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ) );
47
  }
48
 
49
+ public function ajax_on() {
50
+
51
+ if ( ! current_user_can( 'view_query_monitor' ) or ! check_ajax_referer( 'qm-auth-on', 'nonce', false ) ) {
52
+ wp_send_json_error( __( 'Could not set authentication cookie.', 'query-monitor' ) );
53
+ }
54
+
55
+ $expiration = time() + 172800; # 48 hours
56
+ $secure = self::secure_cookie();
57
+ $cookie = wp_generate_auth_cookie( get_current_user_id(), $expiration, 'logged_in' );
58
+
59
+ setcookie( QM_COOKIE, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN, $secure, false );
60
 
61
+ $text = __( 'Authentication cookie set. You can now view Query Monitor output while logged out or while logged in as a different user.', 'query-monitor' );
62
+
63
+ wp_send_json_success( $text );
 
 
64
 
65
  }
66
 
67
+ public function ajax_off() {
68
+
69
+ if ( ! $this->user_verified() or ! check_ajax_referer( 'qm-auth-off', 'nonce', false ) ) {
70
+ wp_send_json_error( __( 'Could not clear authentication cookie.', 'query-monitor' ) );
71
+ }
72
+
73
+ $expiration = time() - 31536000;
74
+
75
+ setcookie( QM_COOKIE, ' ', $expiration, COOKIEPATH, COOKIE_DOMAIN );
76
 
77
+ $text = __( 'Authentication cookie cleared.', 'query-monitor' );
 
 
78
 
79
+ wp_send_json_success( $text );
80
 
81
  }
82
 
83
+ public function user_verified() {
84
+ if ( isset( $_COOKIE[QM_COOKIE] ) ) {
85
+ return $this->verify_cookie( stripslashes( $_COOKIE[QM_COOKIE] ) );
86
+ }
87
+ return false;
88
+ }
89
 
90
+ public static function verify_cookie( $value ) {
91
  if ( $old_user_id = wp_validate_auth_cookie( $value, 'logged_in' ) ) {
92
  return user_can( $old_user_id, 'view_query_monitor' );
93
  }
 
94
  return false;
 
95
  }
96
 
97
  }
collectors/conditionals.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -22,14 +22,10 @@ class QM_Collector_Conditionals extends QM_Collector {
22
  return __( 'Conditionals', 'query-monitor' );
23
  }
24
 
25
- public function __construct() {
26
- parent::__construct();
27
- }
28
-
29
  public function process() {
30
 
31
  $conds = apply_filters( 'query_monitor_conditionals', array(
32
- 'is_404', 'is_archive', 'is_admin', 'is_attachment', 'is_author', 'is_blog_admin', 'is_category', 'is_comments_popup', 'is_date',
33
  'is_day', 'is_feed', 'is_front_page', 'is_home', 'is_main_network', 'is_main_site', 'is_month', 'is_network_admin',
34
  'is_page', 'is_page_template', 'is_paged', 'is_post_type_archive', 'is_preview', 'is_robots', 'is_rtl', 'is_search', 'is_single',
35
  'is_singular', 'is_ssl', 'is_sticky', 'is_tag', 'is_tax', 'is_time', 'is_trackback', 'is_year'
@@ -47,10 +43,11 @@ class QM_Collector_Conditionals extends QM_Collector {
47
  # Special case for is_main_site to prevent it from being annoying on single site installs
48
  $na[] = $cond;
49
  } else {
50
- if ( call_user_func( $cond ) )
51
  $true[] = $cond;
52
- else
53
  $false[] = $cond;
 
54
  }
55
 
56
  } else {
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
22
  return __( 'Conditionals', 'query-monitor' );
23
  }
24
 
 
 
 
 
25
  public function process() {
26
 
27
  $conds = apply_filters( 'query_monitor_conditionals', array(
28
+ 'is_404', 'is_archive', 'is_admin', 'is_attachment', 'is_author', 'is_blog_admin', 'is_category', 'is_comments_popup', 'is_customize_preview', 'is_date',
29
  'is_day', 'is_feed', 'is_front_page', 'is_home', 'is_main_network', 'is_main_site', 'is_month', 'is_network_admin',
30
  'is_page', 'is_page_template', 'is_paged', 'is_post_type_archive', 'is_preview', 'is_robots', 'is_rtl', 'is_search', 'is_single',
31
  'is_singular', 'is_ssl', 'is_sticky', 'is_tag', 'is_tax', 'is_time', 'is_trackback', 'is_year'
43
  # Special case for is_main_site to prevent it from being annoying on single site installs
44
  $na[] = $cond;
45
  } else {
46
+ if ( call_user_func( $cond ) ) {
47
  $true[] = $cond;
48
+ } else {
49
  $false[] = $cond;
50
+ }
51
  }
52
 
53
  } else {
collectors/db_callers.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -22,10 +22,6 @@ class QM_Collector_DB_Callers extends QM_Collector {
22
  return __( 'Queries by Caller', 'query-monitor' );
23
  }
24
 
25
- public function __construct() {
26
- parent::__construct();
27
- }
28
-
29
  public function process() {
30
 
31
  if ( $dbq = QueryMonitor::get_collector( 'db_queries' ) ) {
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
22
  return __( 'Queries by Caller', 'query-monitor' );
23
  }
24
 
 
 
 
 
25
  public function process() {
26
 
27
  if ( $dbq = QueryMonitor::get_collector( 'db_queries' ) ) {
collectors/db_components.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -22,10 +22,6 @@ class QM_Collector_DB_Components extends QM_Collector {
22
  return __( 'Queries by Component', 'query-monitor' );
23
  }
24
 
25
- public function __construct() {
26
- parent::__construct();
27
- }
28
-
29
  public function process() {
30
 
31
  if ( $dbq = QueryMonitor::get_collector( 'db_queries' ) ) {
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
22
  return __( 'Queries by Component', 'query-monitor' );
23
  }
24
 
 
 
 
 
25
  public function process() {
26
 
27
  if ( $dbq = QueryMonitor::get_collector( 'db_queries' ) ) {
collectors/db_queries.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -28,19 +28,17 @@ class QM_Collector_DB_Queries extends QM_Collector {
28
  return __( 'Database Queries', 'query-monitor' );
29
  }
30
 
31
- public function __construct() {
32
- parent::__construct();
33
- }
34
-
35
  public function get_errors() {
36
- if ( !empty( $this->data['errors'] ) )
37
  return $this->data['errors'];
 
38
  return false;
39
  }
40
 
41
  public function get_expensive() {
42
- if ( !empty( $this->data['expensive'] ) )
43
  return $this->data['expensive'];
 
44
  return false;
45
  }
46
 
@@ -50,8 +48,9 @@ class QM_Collector_DB_Queries extends QM_Collector {
50
 
51
  public function process() {
52
 
53
- if ( !SAVEQUERIES )
54
  return;
 
55
 
56
  $this->data['total_qs'] = 0;
57
  $this->data['total_time'] = 0;
@@ -62,18 +61,20 @@ class QM_Collector_DB_Queries extends QM_Collector {
62
  ) );
63
 
64
  foreach ( $this->db_objects as $name => $db ) {
65
- if ( is_a( $db, 'wpdb' ) )
66
  $this->process_db_object( $name, $db );
 
67
  }
68
 
69
  }
70
 
71
  protected function log_type( $type ) {
72
 
73
- if ( isset( $this->data['types'][$type] ) )
74
  $this->data['types'][$type]++;
75
- else
76
  $this->data['types'][$type] = 1;
 
77
 
78
  }
79
 
@@ -91,10 +92,11 @@ class QM_Collector_DB_Queries extends QM_Collector {
91
  $this->data['times'][$caller]['calls']++;
92
  $this->data['times'][$caller]['ltime'] += $ltime;
93
 
94
- if ( isset( $this->data['times'][$caller]['types'][$type] ) )
95
  $this->data['times'][$caller]['types'][$type]++;
96
- else
97
  $this->data['times'][$caller]['types'][$type] = 1;
 
98
 
99
  }
100
 
@@ -112,10 +114,11 @@ class QM_Collector_DB_Queries extends QM_Collector {
112
  $this->data['component_times'][$component->name]['calls']++;
113
  $this->data['component_times'][$component->name]['ltime'] += $ltime;
114
 
115
- if ( isset( $this->data['component_times'][$component->name]['types'][$type] ) )
116
  $this->data['component_times'][$component->name]['types'][$type]++;
117
- else
118
  $this->data['component_times'][$component->name]['types'][$type] = 1;
 
119
 
120
  }
121
 
@@ -130,8 +133,9 @@ class QM_Collector_DB_Queries extends QM_Collector {
130
  foreach ( (array) $db->queries as $query ) {
131
 
132
  # @TODO: decide what I want to do with this:
133
- if ( false !== strpos( $query[2], 'wp_admin_bar' ) and !isset( $_REQUEST['qm_display_admin_bar'] ) )
134
  continue;
 
135
 
136
  $sql = $query[0];
137
  $ltime = $query[1];
@@ -139,10 +143,11 @@ class QM_Collector_DB_Queries extends QM_Collector {
139
  $has_trace = isset( $query['trace'] );
140
  $has_result = isset( $query['result'] );
141
 
142
- if ( isset( $query['result'] ) )
143
  $result = $query['result'];
144
- else
145
  $result = null;
 
146
 
147
  $total_time += $ltime;
148
 
@@ -161,10 +166,11 @@ class QM_Collector_DB_Queries extends QM_Collector {
161
  $callers = explode( ',', $stack );
162
  $caller = trim( end( $callers ) );
163
 
164
- if ( false !== strpos( $caller, '(' ) )
165
  $caller_name = substr( $caller, 0, strpos( $caller, '(' ) ) . '()';
166
- else
167
  $caller_name = $caller;
 
168
 
169
  }
170
 
@@ -175,26 +181,31 @@ class QM_Collector_DB_Queries extends QM_Collector {
175
  $this->log_type( $type );
176
  $this->log_caller( $caller_name, $ltime, $type );
177
 
178
- if ( $component )
179
  $this->log_component( $component, $ltime, $type );
 
180
 
181
- if ( !isset( $types[$type]['total'] ) )
182
  $types[$type]['total'] = 1;
183
- else
184
  $types[$type]['total']++;
 
185
 
186
- if ( !isset( $types[$type]['callers'][$caller] ) )
187
  $types[$type]['callers'][$caller] = 1;
188
- else
189
  $types[$type]['callers'][$caller]++;
 
190
 
191
  $row = compact( 'caller', 'caller_name', 'stack', 'sql', 'ltime', 'result', 'type', 'component', 'trace' );
192
 
193
- if ( is_wp_error( $result ) )
194
  $this->data['errors'][] = $row;
 
195
 
196
- if ( self::is_expensive( $row ) )
197
  $this->data['expensive'][] = $row;
 
198
 
199
  $rows[] = $row;
200
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
28
  return __( 'Database Queries', 'query-monitor' );
29
  }
30
 
 
 
 
 
31
  public function get_errors() {
32
+ if ( !empty( $this->data['errors'] ) ) {
33
  return $this->data['errors'];
34
+ }
35
  return false;
36
  }
37
 
38
  public function get_expensive() {
39
+ if ( !empty( $this->data['expensive'] ) ) {
40
  return $this->data['expensive'];
41
+ }
42
  return false;
43
  }
44
 
48
 
49
  public function process() {
50
 
51
+ if ( !SAVEQUERIES ) {
52
  return;
53
+ }
54
 
55
  $this->data['total_qs'] = 0;
56
  $this->data['total_time'] = 0;
61
  ) );
62
 
63
  foreach ( $this->db_objects as $name => $db ) {
64
+ if ( is_a( $db, 'wpdb' ) ) {
65
  $this->process_db_object( $name, $db );
66
+ }
67
  }
68
 
69
  }
70
 
71
  protected function log_type( $type ) {
72
 
73
+ if ( isset( $this->data['types'][$type] ) ) {
74
  $this->data['types'][$type]++;
75
+ } else {
76
  $this->data['types'][$type] = 1;
77
+ }
78
 
79
  }
80
 
92
  $this->data['times'][$caller]['calls']++;
93
  $this->data['times'][$caller]['ltime'] += $ltime;
94
 
95
+ if ( isset( $this->data['times'][$caller]['types'][$type] ) ) {
96
  $this->data['times'][$caller]['types'][$type]++;
97
+ } else {
98
  $this->data['times'][$caller]['types'][$type] = 1;
99
+ }
100
 
101
  }
102
 
114
  $this->data['component_times'][$component->name]['calls']++;
115
  $this->data['component_times'][$component->name]['ltime'] += $ltime;
116
 
117
+ if ( isset( $this->data['component_times'][$component->name]['types'][$type] ) ) {
118
  $this->data['component_times'][$component->name]['types'][$type]++;
119
+ } else {
120
  $this->data['component_times'][$component->name]['types'][$type] = 1;
121
+ }
122
 
123
  }
124
 
133
  foreach ( (array) $db->queries as $query ) {
134
 
135
  # @TODO: decide what I want to do with this:
136
+ if ( false !== strpos( $query[2], 'wp_admin_bar' ) and !isset( $_REQUEST['qm_display_admin_bar'] ) ) {
137
  continue;
138
+ }
139
 
140
  $sql = $query[0];
141
  $ltime = $query[1];
143
  $has_trace = isset( $query['trace'] );
144
  $has_result = isset( $query['result'] );
145
 
146
+ if ( isset( $query['result'] ) ) {
147
  $result = $query['result'];
148
+ } else {
149
  $result = null;
150
+ }
151
 
152
  $total_time += $ltime;
153
 
166
  $callers = explode( ',', $stack );
167
  $caller = trim( end( $callers ) );
168
 
169
+ if ( false !== strpos( $caller, '(' ) ) {
170
  $caller_name = substr( $caller, 0, strpos( $caller, '(' ) ) . '()';
171
+ } else {
172
  $caller_name = $caller;
173
+ }
174
 
175
  }
176
 
181
  $this->log_type( $type );
182
  $this->log_caller( $caller_name, $ltime, $type );
183
 
184
+ if ( $component ) {
185
  $this->log_component( $component, $ltime, $type );
186
+ }
187
 
188
+ if ( !isset( $types[$type]['total'] ) ) {
189
  $types[$type]['total'] = 1;
190
+ } else {
191
  $types[$type]['total']++;
192
+ }
193
 
194
+ if ( !isset( $types[$type]['callers'][$caller] ) ) {
195
  $types[$type]['callers'][$caller] = 1;
196
+ } else {
197
  $types[$type]['callers'][$caller]++;
198
+ }
199
 
200
  $row = compact( 'caller', 'caller_name', 'stack', 'sql', 'ltime', 'result', 'type', 'component', 'trace' );
201
 
202
+ if ( is_wp_error( $result ) ) {
203
  $this->data['errors'][] = $row;
204
+ }
205
 
206
+ if ( self::is_expensive( $row ) ) {
207
  $this->data['expensive'][] = $row;
208
+ }
209
 
210
  $rows[] = $row;
211
 
collectors/environment.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -40,10 +40,11 @@ class QM_Collector_Environment extends QM_Collector {
40
  # caught early before any plugins had a chance to alter them
41
 
42
  foreach ( $this->php_vars as $setting ) {
43
- if ( isset( $wpdb->qm_php_vars ) and isset( $wpdb->qm_php_vars[$setting] ) )
44
  $val = $wpdb->qm_php_vars[$setting];
45
- else
46
  $val = ini_get( $setting );
 
47
  $this->data['php']['variables'][$setting]['before'] = $val;
48
  }
49
 
@@ -75,8 +76,9 @@ class QM_Collector_Environment extends QM_Collector {
75
  foreach ( $constants as $level ) {
76
  if ( defined( $level ) ) {
77
  $c = constant( $level );
78
- if ( $error_reporting & $c )
79
  $levels[$c] = $level;
 
80
  }
81
  }
82
 
@@ -101,8 +103,9 @@ class QM_Collector_Environment extends QM_Collector {
101
 
102
  foreach ( $dbq->db_objects as $id => $db ) {
103
 
104
- if ( !is_a( $db, 'wpdb' ) )
105
  continue;
 
106
 
107
  $variables = $db->get_results( "
108
  SHOW VARIABLES
@@ -143,8 +146,9 @@ class QM_Collector_Environment extends QM_Collector {
143
  $this->data['php']['version'] = phpversion();
144
  $this->data['php']['user'] = self::get_current_user();
145
 
146
- foreach ( $this->php_vars as $setting )
147
  $this->data['php']['variables'][$setting]['after'] = ini_get( $setting );
 
148
 
149
  $this->data['php']['error_reporting'] = error_reporting();
150
 
@@ -160,21 +164,24 @@ class QM_Collector_Environment extends QM_Collector {
160
  'WP_LOCAL_DEV' => self::format_bool_constant( 'WP_LOCAL_DEV' ),
161
  );
162
 
163
- if ( is_multisite() )
164
  $this->data['wp']['blog_id'] = $blog_id;
 
165
 
166
  $server = explode( ' ', $_SERVER['SERVER_SOFTWARE'] );
167
  $server = explode( '/', reset( $server ) );
168
 
169
- if ( isset( $server[1] ) )
170
  $server_version = $server[1];
171
- else
172
  $server_version = null;
 
173
 
174
- if ( isset( $_SERVER['SERVER_ADDR'] ) )
175
  $address = $_SERVER['SERVER_ADDR'];
176
- else
177
  $address = null;
 
178
 
179
  $this->data['server'] = array(
180
  'name' => $server[0],
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
40
  # caught early before any plugins had a chance to alter them
41
 
42
  foreach ( $this->php_vars as $setting ) {
43
+ if ( isset( $wpdb->qm_php_vars ) and isset( $wpdb->qm_php_vars[$setting] ) ) {
44
  $val = $wpdb->qm_php_vars[$setting];
45
+ } else {
46
  $val = ini_get( $setting );
47
+ }
48
  $this->data['php']['variables'][$setting]['before'] = $val;
49
  }
50
 
76
  foreach ( $constants as $level ) {
77
  if ( defined( $level ) ) {
78
  $c = constant( $level );
79
+ if ( $error_reporting & $c ) {
80
  $levels[$c] = $level;
81
+ }
82
  }
83
  }
84
 
103
 
104
  foreach ( $dbq->db_objects as $id => $db ) {
105
 
106
+ if ( !is_a( $db, 'wpdb' ) ) {
107
  continue;
108
+ }
109
 
110
  $variables = $db->get_results( "
111
  SHOW VARIABLES
146
  $this->data['php']['version'] = phpversion();
147
  $this->data['php']['user'] = self::get_current_user();
148
 
149
+ foreach ( $this->php_vars as $setting ) {
150
  $this->data['php']['variables'][$setting]['after'] = ini_get( $setting );
151
+ }
152
 
153
  $this->data['php']['error_reporting'] = error_reporting();
154
 
164
  'WP_LOCAL_DEV' => self::format_bool_constant( 'WP_LOCAL_DEV' ),
165
  );
166
 
167
+ if ( is_multisite() ) {
168
  $this->data['wp']['blog_id'] = $blog_id;
169
+ }
170
 
171
  $server = explode( ' ', $_SERVER['SERVER_SOFTWARE'] );
172
  $server = explode( '/', reset( $server ) );
173
 
174
+ if ( isset( $server[1] ) ) {
175
  $server_version = $server[1];
176
+ } else {
177
  $server_version = null;
178
+ }
179
 
180
+ if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
181
  $address = $_SERVER['SERVER_ADDR'];
182
+ } else {
183
  $address = null;
184
+ }
185
 
186
  $this->data['server'] = array(
187
  'name' => $server[0],
collectors/hooks.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -22,26 +22,24 @@ class QM_Collector_Hooks extends QM_Collector {
22
  return __( 'Hooks', 'query-monitor' );
23
  }
24
 
25
- public function __construct() {
26
- parent::__construct();
27
- }
28
-
29
  public function process() {
30
 
31
  global $wp_actions, $wp_filter;
32
 
33
- if ( is_admin() and ( $admin = QueryMonitor::get_collector( 'admin' ) ) )
34
  $this->data['screen'] = $admin->data['base'];
35
- else
36
  $this->data['screen'] = '';
 
37
 
38
- $hooks = $parts = $components = array();
 
 
39
 
40
  foreach ( $wp_actions as $name => $count ) {
41
 
42
  $actions = array();
43
- # @TODO better variable name:
44
- $c = array();
45
 
46
  if ( isset( $wp_filter[$name] ) ) {
47
 
@@ -54,8 +52,13 @@ class QM_Collector_Hooks extends QM_Collector {
54
 
55
  $callback = QM_Util::populate_callback( $callback );
56
 
57
- if ( isset( $callback['component'] ) )
58
- $c[$callback['component']->name] = $callback['component']->name;
 
 
 
 
 
59
 
60
  $actions[] = array(
61
  'priority' => $priority,
@@ -68,22 +71,21 @@ class QM_Collector_Hooks extends QM_Collector {
68
 
69
  }
70
 
71
- # @TODO better variable name:
72
- $p = array_filter( preg_split( '/[_\/-]/', $name ) );
73
- $parts = array_merge( $parts, $p );
74
- $components = array_merge( $components, $c );
75
 
76
  $hooks[$name] = array(
77
  'name' => $name,
78
  'actions' => $actions,
79
- 'parts' => $p,
80
- 'components' => $c,
81
  );
82
 
83
  }
84
 
85
  $this->data['hooks'] = $hooks;
86
- $this->data['parts'] = array_unique( array_filter( $parts ) );
87
  $this->data['components'] = array_unique( array_filter( $components ) );
88
 
89
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
22
  return __( 'Hooks', 'query-monitor' );
23
  }
24
 
 
 
 
 
25
  public function process() {
26
 
27
  global $wp_actions, $wp_filter;
28
 
29
+ if ( is_admin() and ( $admin = QueryMonitor::get_collector( 'admin' ) ) ) {
30
  $this->data['screen'] = $admin->data['base'];
31
+ } else {
32
  $this->data['screen'] = '';
33
+ }
34
 
35
+ $hooks = $all_parts = $components = array();
36
+
37
+ $hide_qm = ( defined( 'QM_HIDE_SELF' ) and QM_HIDE_SELF );
38
 
39
  foreach ( $wp_actions as $name => $count ) {
40
 
41
  $actions = array();
42
+ $action_components = array();
 
43
 
44
  if ( isset( $wp_filter[$name] ) ) {
45
 
52
 
53
  $callback = QM_Util::populate_callback( $callback );
54
 
55
+ if ( isset( $callback['component'] ) ) {
56
+ if ( $hide_qm and ( 'query-monitor' === $callback['component']->context ) ) {
57
+ continue;
58
+ }
59
+
60
+ $action_components[$callback['component']->name] = $callback['component']->name;
61
+ }
62
 
63
  $actions[] = array(
64
  'priority' => $priority,
71
 
72
  }
73
 
74
+ $action_parts = array_filter( preg_split( '#[_/-]#', $name ) );
75
+ $all_parts = array_merge( $all_parts, $action_parts );
76
+ $components = array_merge( $components, $action_components );
 
77
 
78
  $hooks[$name] = array(
79
  'name' => $name,
80
  'actions' => $actions,
81
+ 'parts' => $action_parts,
82
+ 'components' => $action_components,
83
  );
84
 
85
  }
86
 
87
  $this->data['hooks'] = $hooks;
88
+ $this->data['parts'] = array_unique( array_filter( $all_parts ) );
89
  $this->data['components'] = array_unique( array_filter( $components ) );
90
 
91
  }
collectors/http.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -26,61 +26,97 @@ class QM_Collector_HTTP extends QM_Collector {
26
 
27
  parent::__construct();
28
 
29
- add_action( 'http_api_debug', array( $this, 'action_http_debug' ), 99, 5 );
30
- add_filter( 'http_request_args', array( $this, 'filter_http_request' ), 99, 2 );
31
- add_filter( 'http_response', array( $this, 'filter_http_response' ), 99, 3 );
32
- # http://core.trac.wordpress.org/ticket/25747
33
  add_filter( 'pre_http_request', array( $this, 'filter_pre_http_request' ), 99, 3 );
 
 
34
 
35
  }
36
 
37
- public function filter_http_request( array $args, $url ) {
 
 
 
 
 
 
 
 
 
38
  $trace = new QM_Backtrace;
39
  if ( isset( $args['_qm_key'] ) ) {
40
  // Something has triggered another HTTP request from within the `pre_http_request` filter
41
  // (eg. WordPress Beta Tester does this). This allows for one level of nested queries.
42
  $args['_qm_original_key'] = $args['_qm_key'];
43
- $m_start = $this->data['http'][$args['_qm_key']]['start'];
44
  } else {
45
- $m_start = microtime( true );
46
  }
47
- $x_start = microtime( true );
48
- $key = $x_start . $url;
49
  $this->data['http'][$key] = array(
50
  'url' => $url,
51
  'args' => $args,
52
- 'start' => $m_start,
53
  'trace' => $trace,
54
  );
55
  $args['_qm_key'] = $key;
56
  return $args;
57
  }
58
 
59
- public function action_http_debug( $param, $action ) {
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- switch ( $action ) {
 
 
 
62
 
63
- case 'response':
 
64
 
65
- $fga = func_get_args();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- list( $response, $action, $class ) = $fga;
68
 
69
- # http://core.trac.wordpress.org/ticket/18732
70
- if ( isset( $fga[3] ) )
71
- $args = $fga[3];
72
- if ( isset( $fga[4] ) )
73
- $url = $fga[4];
74
- if ( !isset( $args['_qm_key'] ) )
75
  return;
 
76
 
77
- if ( !empty( $class ) )
78
  $this->data['http'][$args['_qm_key']]['transport'] = str_replace( 'wp_http_', '', strtolower( $class ) );
79
- else
80
- $this->data['http'][$args['_qm_key']]['transport'] = false;
 
81
 
82
- if ( is_wp_error( $response ) )
83
  $this->filter_http_response( $response, $args, $url );
 
84
 
85
  break;
86
 
@@ -92,24 +128,14 @@ class QM_Collector_HTTP extends QM_Collector {
92
 
93
  }
94
 
95
- public function filter_pre_http_request( $response, array $args, $url ) {
96
-
97
- // All is well:
98
- if ( false === $response ) {
99
- return $response;
100
- }
101
-
102
- if ( is_wp_error( $response ) ) {
103
- return $response;
104
- }
105
-
106
- // Something has filtered `pre_http_request` and short-circuited the request.
107
- $this->data['http'][$args['_qm_key']]['end'] = $this->data['http'][$args['_qm_original_key']]['start'];
108
- $this->data['http'][$args['_qm_key']]['response'] = new WP_Error( 'http_request_not_executed', sprintf( __( 'Request not executed due to a filter on %s', 'query-monitor' ), 'pre_http_request' ) );
109
-
110
- return $response;
111
- }
112
-
113
  public function filter_http_response( $response, array $args, $url ) {
114
  $this->data['http'][$args['_qm_key']]['end'] = microtime( true );
115
  $this->data['http'][$args['_qm_key']]['response'] = $response;
@@ -123,13 +149,28 @@ class QM_Collector_HTTP extends QM_Collector {
123
 
124
  public function process() {
125
 
126
- foreach ( array( 'WP_PROXY_HOST', 'WP_PROXY_PORT', 'WP_PROXY_USERNAME', 'WP_PROXY_PASSWORD', 'WP_PROXY_BYPASS_HOSTS' ) as $var ) {
127
- if ( defined( $var ) and constant( $var ) )
 
 
 
 
 
 
128
  $this->data['vars'][$var] = constant( $var );
 
129
  }
130
 
131
- if ( ! isset( $this->data['http'] ) )
 
 
132
  return;
 
 
 
 
 
 
133
 
134
  foreach ( $this->data['http'] as $key => & $http ) {
135
 
@@ -140,18 +181,20 @@ class QM_Collector_HTTP extends QM_Collector {
140
  }
141
 
142
  if ( is_wp_error( $http['response'] ) ) {
143
- if ( 'http_request_not_executed' != $http['response']->get_error_code() )
144
  $this->data['errors']['error'][] = $key;
 
145
  } else {
146
- if ( intval( wp_remote_retrieve_response_code( $http['response'] ) ) >= 400 )
147
  $this->data['errors']['warning'][] = $key;
 
148
  }
149
 
150
  $http['ltime'] = ( $http['end'] - $http['start'] );
 
151
 
152
  }
153
 
154
-
155
  }
156
 
157
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
26
 
27
  parent::__construct();
28
 
29
+ add_filter( 'http_request_args', array( $this, 'filter_http_request_args' ), 99, 2 );
 
 
 
30
  add_filter( 'pre_http_request', array( $this, 'filter_pre_http_request' ), 99, 3 );
31
+ add_action( 'http_api_debug', array( $this, 'action_http_api_debug' ), 99, 5 );
32
+ add_filter( 'http_response', array( $this, 'filter_http_response' ), 99, 3 );
33
 
34
  }
35
 
36
+ /**
37
+ * Filter the arguments used in an HTTP request.
38
+ *
39
+ * Used to log the request, and to add the logging key to the arguments array.
40
+ *
41
+ * @param array $args HTTP request arguments.
42
+ * @param string $url The request URL.
43
+ * @return array HTTP request arguments.
44
+ */
45
+ public function filter_http_request_args( array $args, $url ) {
46
  $trace = new QM_Backtrace;
47
  if ( isset( $args['_qm_key'] ) ) {
48
  // Something has triggered another HTTP request from within the `pre_http_request` filter
49
  // (eg. WordPress Beta Tester does this). This allows for one level of nested queries.
50
  $args['_qm_original_key'] = $args['_qm_key'];
51
+ $start = $this->data['http'][$args['_qm_key']]['start'];
52
  } else {
53
+ $start = microtime( true );
54
  }
55
+ $key = microtime( true ) . $url;
 
56
  $this->data['http'][$key] = array(
57
  'url' => $url,
58
  'args' => $args,
59
+ 'start' => $start,
60
  'trace' => $trace,
61
  );
62
  $args['_qm_key'] = $key;
63
  return $args;
64
  }
65
 
66
+ /**
67
+ * Log the HTTP request's response if it's being short-circuited by another plugin.
68
+ * This is necessary due to https://core.trac.wordpress.org/ticket/25747
69
+ *
70
+ * $response should be one of boolean false, an array, or a `WP_Error`, but be aware that plugins
71
+ * which short-circuit the request using this filter may (incorrectly) return data of another type.
72
+ *
73
+ * @param bool|array|WP_Error $response The preemptive HTTP response. Default false.
74
+ * @param array $args HTTP request arguments.
75
+ * @param string $url The request URL.
76
+ * @return bool|array|WP_Error The preemptive HTTP response.
77
+ */
78
+ public function filter_pre_http_request( $response, array $args, $url ) {
79
 
80
+ // All is well:
81
+ if ( false === $response ) {
82
+ return $response;
83
+ }
84
 
85
+ // Something's filtering the response, so we'll log it
86
+ $this->filter_http_response( $response, $args, $url );
87
 
88
+ return $response;
89
+ }
90
+
91
+ /**
92
+ * Debugging action for the HTTP API.
93
+ *
94
+ * @param mixed $response A parameter which varies depending on $action.
95
+ * @param string $action The debug action. Currently one of 'response' or 'transports_list'.
96
+ * @param string $class The HTTP transport class name.
97
+ * @param array $args HTTP request arguments.
98
+ * @param string $url The request URL.
99
+ */
100
+ public function action_http_api_debug( $response, $action, $class = null, $args = null, $url = null ) {
101
+
102
+ switch ( $action ) {
103
 
104
+ case 'response':
105
 
106
+ # https://core.trac.wordpress.org/ticket/18732
107
+ if ( empty( $args ) or empty( $args['_qm_key'] ) ) {
 
 
 
 
108
  return;
109
+ }
110
 
111
+ if ( !empty( $class ) ) {
112
  $this->data['http'][$args['_qm_key']]['transport'] = str_replace( 'wp_http_', '', strtolower( $class ) );
113
+ } else {
114
+ $this->data['http'][$args['_qm_key']]['transport'] = null;
115
+ }
116
 
117
+ if ( is_wp_error( $response ) ) {
118
  $this->filter_http_response( $response, $args, $url );
119
+ }
120
 
121
  break;
122
 
128
 
129
  }
130
 
131
+ /**
132
+ * Filter the HTTP response in order to log the response.
133
+ *
134
+ * @param array|WP_Error $response The HTTP response.
135
+ * @param array $args HTTP request arguments.
136
+ * @param string $url The request URL.
137
+ * @return array|WP_Error The HTTP response.
138
+ */
 
 
 
 
 
 
 
 
 
 
139
  public function filter_http_response( $response, array $args, $url ) {
140
  $this->data['http'][$args['_qm_key']]['end'] = microtime( true );
141
  $this->data['http'][$args['_qm_key']]['response'] = $response;
149
 
150
  public function process() {
151
 
152
+ foreach ( array(
153
+ 'WP_PROXY_HOST',
154
+ 'WP_PROXY_PORT',
155
+ 'WP_PROXY_USERNAME',
156
+ 'WP_PROXY_PASSWORD',
157
+ 'WP_PROXY_BYPASS_HOSTS',
158
+ ) as $var ) {
159
+ if ( defined( $var ) and constant( $var ) ) {
160
  $this->data['vars'][$var] = constant( $var );
161
+ }
162
  }
163
 
164
+ $this->data['ltime'] = 0;
165
+
166
+ if ( ! isset( $this->data['http'] ) ) {
167
  return;
168
+ }
169
+
170
+ $silent = apply_filters( 'query_monitor_silent_http_error_codes', array(
171
+ 'http_request_not_executed',
172
+ 'airplane_mode_enabled'
173
+ ) );
174
 
175
  foreach ( $this->data['http'] as $key => & $http ) {
176
 
181
  }
182
 
183
  if ( is_wp_error( $http['response'] ) ) {
184
+ if ( !in_array( $http['response']->get_error_code(), $silent ) ) {
185
  $this->data['errors']['error'][] = $key;
186
+ }
187
  } else {
188
+ if ( intval( wp_remote_retrieve_response_code( $http['response'] ) ) >= 400 ) {
189
  $this->data['errors']['warning'][] = $key;
190
+ }
191
  }
192
 
193
  $http['ltime'] = ( $http['end'] - $http['start'] );
194
+ $this->data['ltime'] += $http['ltime'];
195
 
196
  }
197
 
 
198
  }
199
 
200
  }
collectors/overview.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -22,19 +22,16 @@ class QM_Collector_Overview extends QM_Collector {
22
  return __( 'Overview', 'query-monitor' );
23
  }
24
 
25
- public function __construct() {
26
- parent::__construct();
27
- }
28
-
29
  public function process() {
30
 
31
  $this->data['time'] = self::timer_stop_float();
32
  $this->data['time_limit'] = ini_get( 'max_execution_time' );
33
 
34
- if ( !empty( $this->data['time_limit'] ) )
35
  $this->data['time_usage'] = ( 100 / $this->data['time_limit'] ) * $this->data['time'];
36
- else
37
  $this->data['time_usage'] = 0;
 
38
 
39
  if ( function_exists( 'memory_get_peak_usage' ) ) {
40
  $this->data['memory'] = memory_get_peak_usage();
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
22
  return __( 'Overview', 'query-monitor' );
23
  }
24
 
 
 
 
 
25
  public function process() {
26
 
27
  $this->data['time'] = self::timer_stop_float();
28
  $this->data['time_limit'] = ini_get( 'max_execution_time' );
29
 
30
+ if ( !empty( $this->data['time_limit'] ) ) {
31
  $this->data['time_usage'] = ( 100 / $this->data['time_limit'] ) * $this->data['time'];
32
+ } else {
33
  $this->data['time_usage'] = 0;
34
+ }
35
 
36
  if ( function_exists( 'memory_get_peak_usage' ) ) {
37
  $this->data['memory'] = memory_get_peak_usage();
collectors/php_errors.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -15,15 +15,17 @@ GNU General Public License for more details.
15
  */
16
 
17
  # E_DEPRECATED and E_USER_DEPRECATED were introduced in PHP 5.3 so we need to use back-compat constants that work on 5.2.
18
- if ( defined( 'E_DEPRECATED' ) )
19
  define( 'QM_E_DEPRECATED', E_DEPRECATED );
20
- else
21
  define( 'QM_E_DEPRECATED', 0 );
 
22
 
23
- if ( defined( 'E_USER_DEPRECATED' ) )
24
  define( 'QM_E_USER_DEPRECATED', E_USER_DEPRECATED );
25
- else
26
  define( 'QM_E_USER_DEPRECATED', 0 );
 
27
 
28
  class QM_Collector_PHP_Errors extends QM_Collector {
29
 
@@ -105,7 +107,8 @@ class QM_Collector_PHP_Errors extends QM_Collector {
105
 
106
  }
107
 
108
- public function process() {
 
109
  restore_error_handler();
110
  }
111
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
15
  */
16
 
17
  # E_DEPRECATED and E_USER_DEPRECATED were introduced in PHP 5.3 so we need to use back-compat constants that work on 5.2.
18
+ if ( defined( 'E_DEPRECATED' ) ) {
19
  define( 'QM_E_DEPRECATED', E_DEPRECATED );
20
+ } else {
21
  define( 'QM_E_DEPRECATED', 0 );
22
+ }
23
 
24
+ if ( defined( 'E_USER_DEPRECATED' ) ) {
25
  define( 'QM_E_USER_DEPRECATED', E_USER_DEPRECATED );
26
+ } else {
27
  define( 'QM_E_USER_DEPRECATED', 0 );
28
+ }
29
 
30
  class QM_Collector_PHP_Errors extends QM_Collector {
31
 
107
 
108
  }
109
 
110
+ public function tear_down() {
111
+ parent::tear_down();
112
  restore_error_handler();
113
  }
114
 
collectors/redirects.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -29,8 +29,9 @@ class QM_Collector_Redirects extends QM_Collector {
29
 
30
  public function filter_wp_redirect( $location, $status ) {
31
 
32
- if ( !$location )
33
  return $location;
 
34
 
35
  $trace = new QM_Backtrace;
36
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
29
 
30
  public function filter_wp_redirect( $location, $status ) {
31
 
32
+ if ( !$location ) {
33
  return $location;
34
+ }
35
 
36
  $trace = new QM_Backtrace;
37
 
collectors/request.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -18,10 +18,6 @@ class QM_Collector_Request extends QM_Collector {
18
 
19
  public $id = 'request';
20
 
21
- public function __construct() {
22
- parent::__construct();
23
- }
24
-
25
  public function name() {
26
  return __( 'Request', 'query-monitor' );
27
  }
@@ -49,11 +45,13 @@ class QM_Collector_Request extends QM_Collector {
49
 
50
  foreach ( $qvars as $k => $v ) {
51
  if ( isset( $plugin_qvars[$k] ) ) {
52
- if ( '' !== $v )
53
  $query_vars[$k] = $v;
 
54
  } else {
55
- if ( !empty( $v ) )
56
  $query_vars[$k] = $v;
 
57
  }
58
  }
59
 
@@ -69,8 +67,9 @@ class QM_Collector_Request extends QM_Collector {
69
 
70
  # Now add all other vars to $this->data['qvars']:
71
  foreach ( $query_vars as $k => $v ) {
72
- if ( !isset( $plugin_qvars[$k] ) )
73
  $this->data['qvars'][$k] = $v;
 
74
  }
75
 
76
  switch ( true ) {
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
18
 
19
  public $id = 'request';
20
 
 
 
 
 
21
  public function name() {
22
  return __( 'Request', 'query-monitor' );
23
  }
45
 
46
  foreach ( $qvars as $k => $v ) {
47
  if ( isset( $plugin_qvars[$k] ) ) {
48
+ if ( '' !== $v ) {
49
  $query_vars[$k] = $v;
50
+ }
51
  } else {
52
+ if ( !empty( $v ) ) {
53
  $query_vars[$k] = $v;
54
+ }
55
  }
56
  }
57
 
67
 
68
  # Now add all other vars to $this->data['qvars']:
69
  foreach ( $query_vars as $k => $v ) {
70
+ if ( !isset( $plugin_qvars[$k] ) ) {
71
  $this->data['qvars'][$k] = $v;
72
+ }
73
  }
74
 
75
  switch ( true ) {
collectors/theme.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -48,16 +48,18 @@ class QM_Collector_Theme extends QM_Collector {
48
  $this->data['stylesheet'] = get_stylesheet();
49
  $this->data['template'] = get_template();
50
 
51
- if ( isset( $this->data['body_class'] ) )
52
  asort( $this->data['body_class'] );
 
53
 
54
  }
55
 
56
  }
57
 
58
  function register_qm_collector_theme( array $qm ) {
59
- if ( !is_admin() )
60
  $qm['theme'] = new QM_Collector_Theme;
 
61
  return $qm;
62
  }
63
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
48
  $this->data['stylesheet'] = get_stylesheet();
49
  $this->data['template'] = get_template();
50
 
51
+ if ( isset( $this->data['body_class'] ) ) {
52
  asort( $this->data['body_class'] );
53
+ }
54
 
55
  }
56
 
57
  }
58
 
59
  function register_qm_collector_theme( array $qm ) {
60
+ if ( !is_admin() ) {
61
  $qm['theme'] = new QM_Collector_Theme;
62
+ }
63
  return $qm;
64
  }
65
 
collectors/transients.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright 2014 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
@@ -29,6 +29,12 @@ class QM_Collector_Transients extends QM_Collector {
29
  add_action( 'setted_transient', array( $this, 'action_setted_blog_transient' ), 10, 3 );
30
  }
31
 
 
 
 
 
 
 
32
  public function action_setted_site_transient( $transient, $value = null, $expiration = null ) {
33
  $this->setted_transient( $transient, 'site', $value, $expiration );
34
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
29
  add_action( 'setted_transient', array( $this, 'action_setted_blog_transient' ), 10, 3 );
30
  }
31
 
32
+ public function tear_down() {
33
+ parent::tear_down();
34
+ remove_action( 'setted_site_transient', array( $this, 'action_setted_site_transient' ), 10 );
35
+ remove_action( 'setted_transient', array( $this, 'action_setted_blog_transient' ), 10 );
36
+ }
37
+
38
  public function action_setted_site_transient( $transient, $value = null, $expiration = null ) {
39
  $this->setted_transient( $transient, 'site', $value, $expiration );
40
  }
dispatchers/Headers.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -39,8 +38,12 @@ class QM_Dispatcher_Headers extends QM_Dispatcher {
39
 
40
  require_once $this->qm->plugin_path( 'output/Headers.php' );
41
 
42
- foreach ( glob( $this->qm->plugin_path( 'output/headers/*.php' ) ) as $output ) {
43
- include $output;
 
 
 
 
44
  }
45
 
46
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
38
 
39
  require_once $this->qm->plugin_path( 'output/Headers.php' );
40
 
41
+ # Using DirectoryIterator rather than glob in order to support Google App Engine (tested on v1.9.10)
42
+ $output_iterator = new DirectoryIterator( $this->qm->plugin_path( 'output/headers' ) );
43
+ foreach ( $output_iterator as $output ) {
44
+ if ( $output->getExtension() === 'php' ) {
45
+ include $output->getPathname();
46
+ }
47
  }
48
 
49
  }
dispatchers/Html.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -96,7 +95,13 @@ class QM_Dispatcher_Html extends QM_Dispatcher {
96
  'query-monitor',
97
  'qm_l10n',
98
  array(
99
- 'ajax_error' => __( 'PHP Error in AJAX Response', 'query-monitor' ),
 
 
 
 
 
 
100
  )
101
  );
102
 
@@ -115,16 +120,27 @@ class QM_Dispatcher_Html extends QM_Dispatcher {
115
 
116
  require_once $this->qm->plugin_path( 'output/Html.php' );
117
 
118
- foreach ( glob( $this->qm->plugin_path( 'output/html/*.php' ) ) as $output ) {
119
- include $output;
 
 
 
120
  }
121
 
122
- if ( !is_admin_bar_showing() )
123
- $class = 'qm-show';
124
- else
125
- $class = '';
 
 
 
 
126
 
127
- echo '<div id="qm" class="' . $class . '">';
 
 
 
 
128
  echo '<div id="qm-wrapper">';
129
  echo '<p>' . __( 'Query Monitor', 'query-monitor' ) . '</p>';
130
 
@@ -155,8 +171,9 @@ class QM_Dispatcher_Html extends QM_Dispatcher {
155
  $class = implode( ' ', apply_filters( 'query_monitor_class', array() ) );
156
  $title = implode( '&nbsp;&nbsp;&nbsp;', apply_filters( 'query_monitor_title', array() ) );
157
 
158
- if ( empty( $title ) )
159
  $title = __( 'Query Monitor', 'query-monitor' );
 
160
 
161
  $admin_bar_menu = array(
162
  'top' => array(
@@ -166,8 +183,9 @@ class QM_Dispatcher_Html extends QM_Dispatcher {
166
  'sub' => array()
167
  );
168
 
169
- foreach ( apply_filters( 'query_monitor_menus', array() ) as $menu )
170
  $admin_bar_menu['sub'][] = $menu;
 
171
 
172
  return $admin_bar_menu;
173
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
95
  'query-monitor',
96
  'qm_l10n',
97
  array(
98
+ 'ajax_error' => __( 'PHP Error in AJAX Response', 'query-monitor' ),
99
+ 'infinitescroll_paused' => __( 'Infinite Scroll has been paused by Query Monitor', 'query-monitor' ),
100
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
101
+ 'auth_nonce' => array(
102
+ 'on' => wp_create_nonce( 'qm-auth-on' ),
103
+ 'off' => wp_create_nonce( 'qm-auth-off' ),
104
+ ),
105
  )
106
  );
107
 
120
 
121
  require_once $this->qm->plugin_path( 'output/Html.php' );
122
 
123
+ $output_iterator = new DirectoryIterator( $this->qm->plugin_path( 'output/html' ) );
124
+ foreach ( $output_iterator as $output ) {
125
+ if ( $output->getExtension() === 'php' ) {
126
+ include $output->getPathname();
127
+ }
128
  }
129
 
130
+ $class = array();
131
+
132
+ if ( !is_admin() ) {
133
+ $absolute = function_exists( 'twentyfifteen_setup' );
134
+ if ( apply_filters( 'query_monitor_absolute_position', $absolute ) ) {
135
+ $class[] = 'qm-absolute';
136
+ }
137
+ }
138
 
139
+ if ( !is_admin_bar_showing() ) {
140
+ $class[] = 'qm-show';
141
+ }
142
+
143
+ echo '<div id="qm" class="' . implode( ' ', $class ) . '">';
144
  echo '<div id="qm-wrapper">';
145
  echo '<p>' . __( 'Query Monitor', 'query-monitor' ) . '</p>';
146
 
171
  $class = implode( ' ', apply_filters( 'query_monitor_class', array() ) );
172
  $title = implode( '&nbsp;&nbsp;&nbsp;', apply_filters( 'query_monitor_title', array() ) );
173
 
174
+ if ( empty( $title ) ) {
175
  $title = __( 'Query Monitor', 'query-monitor' );
176
+ }
177
 
178
  $admin_bar_menu = array(
179
  'top' => array(
183
  'sub' => array()
184
  );
185
 
186
+ foreach ( apply_filters( 'query_monitor_menus', array() ) as $menu ) {
187
  $admin_bar_menu['sub'][] = $menu;
188
+ }
189
 
190
  return $admin_bar_menu;
191
 
output/Headers.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
output/Html.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -31,12 +30,12 @@ class QM_Output_Html implements QM_Output {
31
  if ( empty( $data ) )
32
  return;
33
 
34
- echo '<div class="qm" id="' . $this->collector->id() . '">';
35
  echo '<table cellspacing="0">';
36
  if ( !empty( $name ) ) {
37
  echo '<thead>';
38
  echo '<tr>';
39
- echo '<th colspan="2">' . $name . '</th>';
40
  echo '</tr>';
41
  echo '</thead>';
42
  }
@@ -133,7 +132,7 @@ class QM_Output_Html implements QM_Output {
133
 
134
  foreach( array(
135
  'ALTER', 'AND', 'COMMIT', 'CREATE', 'DESCRIBE', 'DELETE', 'DROP', 'ELSE', 'END', 'FROM', 'GROUP',
136
- 'HAVING', 'INNER', 'INSERT', 'LIMIT', 'ON', 'OR', 'ORDER', 'REPLACE', 'ROLLBACK', 'SELECT', 'SET',
137
  'SHOW', 'START', 'THEN', 'TRUNCATE', 'UPDATE', 'VALUES', 'WHEN', 'WHERE'
138
  ) as $cmd )
139
  $sql = trim( str_replace( " $cmd ", "<br>$cmd ", $sql ) );
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
30
  if ( empty( $data ) )
31
  return;
32
 
33
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
34
  echo '<table cellspacing="0">';
35
  if ( !empty( $name ) ) {
36
  echo '<thead>';
37
  echo '<tr>';
38
+ echo '<th colspan="2">' . esc_html( $name ) . '</th>';
39
  echo '</tr>';
40
  echo '</thead>';
41
  }
132
 
133
  foreach( array(
134
  'ALTER', 'AND', 'COMMIT', 'CREATE', 'DESCRIBE', 'DELETE', 'DROP', 'ELSE', 'END', 'FROM', 'GROUP',
135
+ 'HAVING', 'INNER', 'INSERT', 'LEFT', 'LIMIT', 'ON', 'OR', 'ORDER', 'OUTER', 'REPLACE', 'RIGHT', 'ROLLBACK', 'SELECT', 'SET',
136
  'SHOW', 'START', 'THEN', 'TRUNCATE', 'UPDATE', 'VALUES', 'WHEN', 'WHERE'
137
  ) as $cmd )
138
  $sql = trim( str_replace( " $cmd ", "<br>$cmd ", $sql ) );
output/headers/php_errors.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -19,13 +18,15 @@ class QM_Output_Headers_PHP_Errors extends QM_Output_Headers {
19
 
20
  public function output() {
21
 
22
- if ( ! QM_Util::is_ajax() )
23
  return;
 
24
 
25
  $data = $this->collector->get_data();
26
 
27
- if ( empty( $data['errors'] ) )
28
  return;
 
29
 
30
  $count = 0;
31
 
@@ -40,7 +41,7 @@ class QM_Output_Headers_PHP_Errors extends QM_Output_Headers {
40
  $component = $error->trace->get_component();
41
  $output_error = array(
42
  'type' => $error->type,
43
- 'message' => $error->message,
44
  'file' => $error->file,
45
  'line' => $error->line,
46
  'stack' => $error->trace->get_stack(),
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
18
 
19
  public function output() {
20
 
21
+ if ( ! QM_Util::is_ajax() ) {
22
  return;
23
+ }
24
 
25
  $data = $this->collector->get_data();
26
 
27
+ if ( empty( $data['errors'] ) ) {
28
  return;
29
+ }
30
 
31
  $count = 0;
32
 
41
  $component = $error->trace->get_component();
42
  $output_error = array(
43
  'type' => $error->type,
44
+ 'message' => wp_strip_all_tags( $error->message ),
45
  'file' => $error->file,
46
  'line' => $error->line,
47
  'stack' => $error->trace->get_stack(),
output/headers/redirects.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -21,8 +20,9 @@ class QM_Output_Headers_Redirects extends QM_Output_Headers {
21
 
22
  $data = $this->collector->get_data();
23
 
24
- if ( empty( $data ) )
25
  return;
 
26
 
27
  header( sprintf( 'X-QM-Redirect-Trace: %s',
28
  implode( ', ', $data['trace']->get_stack() )
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
20
 
21
  $data = $this->collector->get_data();
22
 
23
+ if ( empty( $data ) ) {
24
  return;
25
+ }
26
 
27
  header( sprintf( 'X-QM-Redirect-Trace: %s',
28
  implode( ', ', $data['trace']->get_stack() )
output/html/admin.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,14 +25,15 @@ class QM_Output_Html_Admin extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- if ( empty( $data ) )
30
  return;
 
31
 
32
- echo '<div class="qm qm-half" id="' . $this->collector->id() . '">';
33
  echo '<table cellspacing="0">';
34
  echo '<thead>';
35
  echo '<tr>';
36
- echo '<th colspan="2">' . $this->collector->name() . '</th>';
37
  echo '</tr>';
38
  echo '</thead>';
39
  echo '<tbody>';
@@ -79,24 +79,27 @@ class QM_Output_Html_Admin extends QM_Output_Html {
79
 
80
  # And now, WordPress' legendary inconsistency comes into play:
81
 
82
- if ( !empty( $data['current_screen']->taxonomy ) )
83
  $col = $data['current_screen']->taxonomy;
84
- else if ( !empty( $data['current_screen']->post_type ) )
85
  $col = $data['current_screen']->post_type . '_posts';
86
- else
87
  $col = $data['current_screen']->base;
 
88
 
89
- if ( !empty( $data['current_screen']->post_type ) and empty( $data['current_screen']->taxonomy ) )
90
  $cols = $data['current_screen']->post_type . '_posts';
91
- else
92
  $cols = $data['current_screen']->id;
 
93
 
94
- if ( 'edit-comments' == $col )
95
  $col = 'comments';
96
- else if ( 'upload' == $col )
97
  $col = 'media';
98
- else if ( 'link-manager' == $col )
99
  $col = 'link';
 
100
 
101
  echo '<tr>';
102
  echo '<td rowspan="2">' . __( 'Column Filters', 'query-monitor' ) . '</td>';
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ if ( empty( $data ) ) {
29
  return;
30
+ }
31
 
32
+ echo '<div class="qm qm-half" id="' . esc_attr( $this->collector->id() ) . '">';
33
  echo '<table cellspacing="0">';
34
  echo '<thead>';
35
  echo '<tr>';
36
+ echo '<th colspan="2">' . esc_html( $this->collector->name() ) . '</th>';
37
  echo '</tr>';
38
  echo '</thead>';
39
  echo '<tbody>';
79
 
80
  # And now, WordPress' legendary inconsistency comes into play:
81
 
82
+ if ( !empty( $data['current_screen']->taxonomy ) ) {
83
  $col = $data['current_screen']->taxonomy;
84
+ } else if ( !empty( $data['current_screen']->post_type ) ) {
85
  $col = $data['current_screen']->post_type . '_posts';
86
+ } else {
87
  $col = $data['current_screen']->base;
88
+ }
89
 
90
+ if ( !empty( $data['current_screen']->post_type ) and empty( $data['current_screen']->taxonomy ) ) {
91
  $cols = $data['current_screen']->post_type . '_posts';
92
+ } else {
93
  $cols = $data['current_screen']->id;
94
+ }
95
 
96
+ if ( 'edit-comments' == $col ) {
97
  $col = 'comments';
98
+ } else if ( 'upload' == $col ) {
99
  $col = 'media';
100
+ } else if ( 'link-manager' == $col ) {
101
  $col = 'link';
102
+ }
103
 
104
  echo '<tr>';
105
  echo '<td rowspan="2">' . __( 'Column Filters', 'query-monitor' ) . '</td>';
output/html/assets.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Copyright 2009-2015 John Blackbourn
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ */
16
+
17
+ class QM_Output_Html_Assets extends QM_Output_Html {
18
+
19
+ public $id = 'hooks';
20
+
21
+ public function __construct( QM_Collector $collector ) {
22
+ parent::__construct( $collector );
23
+ add_filter( 'query_monitor_menus', array( $this, 'admin_menu' ), 70 );
24
+ }
25
+
26
+ public function output() {
27
+
28
+ $data = $this->collector->get_data();
29
+
30
+ if ( empty( $data ) ) {
31
+ return;
32
+ }
33
+
34
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
35
+ echo '<table cellspacing="0">';
36
+ echo '<thead>';
37
+ echo '<tr>';
38
+ echo '<th colspan="2">' . esc_html( $this->collector->name() ) . '</th>';
39
+ echo '<th>' . __( 'Dependencies', 'query-monitor' ) . '</th>';
40
+ // echo '<th>' . __( 'Component', 'query-monitor' ) . '</th>';
41
+ echo '<th>' . __( 'Version', 'query-monitor' ) . '</th>';
42
+ echo '</tr>';
43
+ echo '</thead>';
44
+ echo '<tbody>';
45
+
46
+ // @TODO concat, do_concat, concat_version
47
+
48
+ $rowspan = count( $data['header_scripts'] );
49
+
50
+ echo '<tr>';
51
+ echo "<td valign='top' rowspan='{$rowspan}'>" . __( 'Header&nbsp;Scripts', 'query-monitor' ) . "</td>";
52
+
53
+ $this->dependency_rows( $data['header_scripts'], $data['raw_scripts'] );
54
+
55
+ $rowspan = count( $data['footer_scripts'] );
56
+
57
+ echo '<tr>';
58
+ echo "<td valign='top' rowspan='{$rowspan}'>" . __( 'Footer&nbsp;Scripts', 'query-monitor' ) . "</td>";
59
+
60
+ $this->dependency_rows( $data['footer_scripts'], $data['raw_scripts'] );
61
+
62
+ $rowspan = count( $data['header_styles'] );
63
+
64
+ echo '<tr>';
65
+ echo "<td valign='top' rowspan='{$rowspan}'>" . __( 'Styles', 'query-monitor' ) . "</td>";
66
+
67
+ $this->dependency_rows( $data['header_styles'], $data['raw_styles'] );
68
+
69
+ echo '</tbody>';
70
+ echo '</table>';
71
+ echo '</div>';
72
+
73
+ }
74
+
75
+ protected function dependency_rows( array $handles, WP_Dependencies $dependencies ) {
76
+
77
+ $first = true;
78
+
79
+ foreach ( $handles as $handle ) {
80
+ if ( !$first ) {
81
+ echo '<tr>';
82
+ }
83
+
84
+ $this->dependency_row( $dependencies->registered[$handle], $dependencies );
85
+
86
+ echo '</tr>';
87
+ $first = false;
88
+ }
89
+
90
+ }
91
+
92
+ protected function dependency_row( _WP_Dependency $script, WP_Dependencies $dependencies ) {
93
+
94
+ // $path = $script->src;
95
+
96
+ // if ( preg_match( '#^//#', $path ) ) {
97
+ // $path = is_ssl() ? 'https:' . $path : 'http:' . $path;
98
+ // } else if ( preg_match( '#^/#', $path ) ) {
99
+ // $path = home_url( $path );
100
+ // } else {
101
+ // $path = set_url_scheme( $path );
102
+ // }
103
+
104
+ // $path = str_replace( set_url_scheme( WP_PLUGIN_URL ), WP_PLUGIN_DIR, $path );
105
+ // $path = str_replace( set_url_scheme( WP_CONTENT_URL ), WP_CONTENT_DIR, $path );
106
+ // $component = QM_Util::get_file_component( $path );
107
+
108
+ if ( empty( $script->ver ) ) {
109
+ $ver = '<em class="qm-info">' . $dependencies->default_version . '</em>';
110
+ } else {
111
+ $ver = esc_html( $script->ver );
112
+ }
113
+
114
+ if ( empty( $script->src ) ) {
115
+ $src = '&nbsp;';
116
+ } else {
117
+ $src = $script->src;
118
+ }
119
+
120
+ echo '<td valign="top">' . $script->handle . '<br><span class="qm-info">' . $src . '</span></td>';
121
+ echo '<td valign="top">' . implode( '<br>', $script->deps ) . '</td>';
122
+ // echo '<td valign="top">' . $component->name . '</td>';
123
+ echo '<td valign="top">' . $ver . '</td>';
124
+
125
+ }
126
+
127
+ public function admin_menu( array $menu ) {
128
+
129
+ $menu[] = $this->menu( array(
130
+ 'title' => $this->collector->name(),
131
+ ) );
132
+ return $menu;
133
+
134
+ }
135
+
136
+ }
137
+
138
+ function register_qm_output_html_assets( QM_Output $output = null, QM_Collector $collector ) {
139
+ return new QM_Output_Html_Assets( $collector );
140
+ }
141
+
142
+ add_filter( 'query_monitor_output_html_assets', 'register_qm_output_html_assets', 10, 2 );
output/html/authentication.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -19,45 +18,31 @@ class QM_Output_Html_Authentication extends QM_Output_Html {
19
 
20
  public function output() {
21
 
22
- echo '<div class="qm qm-half" id="' . $this->collector->id() . '">';
23
  echo '<table cellspacing="0">';
24
  echo '<thead>';
25
  echo '<tr>';
26
- echo '<th>' . $this->collector->name() . '</th>';
27
  echo '</tr>';
28
  echo '</thead>';
29
  echo '<tbody>';
30
 
31
- $atts = $this->collector->get_cookie_attributes();
32
-
33
  if ( !$this->collector->user_verified() ) {
34
 
35
- $cookie = $this->collector->get_cookie_content();
36
- $text = esc_js( __( 'Authentication cookie set. You can now view Query Monitor output while logged out or while logged in as a different user.', 'query-monitor' ) );
37
- $value = "{$atts['name']}={$cookie['value']}; domain={$atts['domain']}; path={$atts['path']}";
38
- if ( $cookie['secure'] ) {
39
- $value .= '; secure';
40
- }
41
- $link = "document.cookie='{$value}'; alert('{$text}'); return false;";
42
-
43
  echo '<tr>';
44
  echo '<td>' . __( 'You can set an authentication cookie which allows you to view Query Monitor output when you&rsquo;re not logged in.', 'query-monitor' ) . '</td>';
45
  echo '</tr>';
46
  echo '<tr>';
47
- echo '<td><a href="#" onclick="' . $link . '">' . __( 'Set authentication cookie', 'query-monitor' ) . '</a></td>';
48
  echo '</tr>';
49
 
50
  } else {
51
 
52
- $text = esc_js( __( 'Authentication cookie cleared.', 'query-monitor' ) );
53
- $value = "{$atts['name']}=; expires=' + new Date(0).toUTCString() + '; domain={$atts['domain']}; path={$atts['path']}";
54
- $link = "document.cookie='{$value}'; alert('{$text}'); return false;";
55
-
56
  echo '<tr>';
57
  echo '<td>' . __( 'You currently have an authentication cookie which allows you to view Query Monitor output.', 'query-monitor' ) . '</td>';
58
  echo '</tr>';
59
  echo '<tr>';
60
- echo '<td><a href="#" onclick="' . $link . '">' . __( 'Clear authentication cookie', 'query-monitor' ) . '</a></td>';
61
  echo '</tr>';
62
 
63
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
18
 
19
  public function output() {
20
 
21
+ echo '<div class="qm qm-half" id="' . esc_attr( $this->collector->id() ) . '">';
22
  echo '<table cellspacing="0">';
23
  echo '<thead>';
24
  echo '<tr>';
25
+ echo '<th>' . esc_html( $this->collector->name() ) . '</th>';
26
  echo '</tr>';
27
  echo '</thead>';
28
  echo '<tbody>';
29
 
 
 
30
  if ( !$this->collector->user_verified() ) {
31
 
 
 
 
 
 
 
 
 
32
  echo '<tr>';
33
  echo '<td>' . __( 'You can set an authentication cookie which allows you to view Query Monitor output when you&rsquo;re not logged in.', 'query-monitor' ) . '</td>';
34
  echo '</tr>';
35
  echo '<tr>';
36
+ echo '<td><a href="#" class="qm-auth" data-action="on">' . __( 'Set authentication cookie', 'query-monitor' ) . '</a></td>';
37
  echo '</tr>';
38
 
39
  } else {
40
 
 
 
 
 
41
  echo '<tr>';
42
  echo '<td>' . __( 'You currently have an authentication cookie which allows you to view Query Monitor output.', 'query-monitor' ) . '</td>';
43
  echo '</tr>';
44
  echo '<tr>';
45
+ echo '<td><a href="#" class="qm-auth" data-action="off">' . __( 'Clear authentication cookie', 'query-monitor' ) . '</a></td>';
46
  echo '</tr>';
47
 
48
  }
output/html/conditionals.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -30,31 +29,35 @@ class QM_Output_Html_Conditionals extends QM_Output_Html {
30
  $i = 0;
31
  $w = floor( 100 / $cols );
32
 
33
- echo '<div class="qm" id="' . $this->collector->id() . '">';
34
  echo '<table cellspacing="0">';
35
  echo '<thead>';
36
  echo '<tr>';
37
- echo '<th colspan="' . $cols . '">' . $this->collector->name() . '</th>';
38
  echo '</tr>';
39
  echo '</thead>';
40
  echo '<tbody>';
41
 
42
  foreach ( $data['conds']['true'] as $cond ) {
43
  $i++;
44
- if ( 1 === $i%$cols )
45
  echo '<tr>';
 
46
  echo '<td class="qm-ltr qm-true" width="' . $w . '%">' . $cond . '()</td>';
47
- if ( 0 === $i%$cols )
48
  echo '</tr>';
 
49
  }
50
 
51
  foreach ( $data['conds']['false'] as $cond ) {
52
  $i++;
53
- if ( 1 === $i%$cols )
54
  echo '<tr>';
 
55
  echo '<td class="qm-ltr qm-false" width="' . $w . '%">' . $cond . '()</td>';
56
- if ( 0 === $i%$cols )
57
  echo '</tr>';
 
58
  }
59
 
60
  $fill = ( $cols - ( $i % $cols ) );
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
29
  $i = 0;
30
  $w = floor( 100 / $cols );
31
 
32
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
33
  echo '<table cellspacing="0">';
34
  echo '<thead>';
35
  echo '<tr>';
36
+ echo '<th colspan="' . $cols . '">' . esc_html( $this->collector->name() ) . '</th>';
37
  echo '</tr>';
38
  echo '</thead>';
39
  echo '<tbody>';
40
 
41
  foreach ( $data['conds']['true'] as $cond ) {
42
  $i++;
43
+ if ( 1 === $i%$cols ) {
44
  echo '<tr>';
45
+ }
46
  echo '<td class="qm-ltr qm-true" width="' . $w . '%">' . $cond . '()</td>';
47
+ if ( 0 === $i%$cols ) {
48
  echo '</tr>';
49
+ }
50
  }
51
 
52
  foreach ( $data['conds']['false'] as $cond ) {
53
  $i++;
54
+ if ( 1 === $i%$cols ) {
55
  echo '<tr>';
56
+ }
57
  echo '<td class="qm-ltr qm-false" width="' . $w . '%">' . $cond . '()</td>';
58
+ if ( 0 === $i%$cols ) {
59
  echo '</tr>';
60
+ }
61
  }
62
 
63
  $fill = ( $cols - ( $i % $cols ) );
output/html/db_callers.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,24 +25,26 @@ class QM_Output_Html_DB_Callers extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- if ( empty( $data ) )
30
  return;
 
31
 
32
  $total_time = 0;
33
  $span = count( $data['types'] ) + 2;
34
 
35
- echo '<div class="qm qm-half" id="' . $this->collector->id() . '">';
36
  echo '<table cellspacing="0" class="qm-sortable">';
37
  echo '<thead>';
38
  echo '<tr>';
39
- echo '<th colspan="' . $span . '">' . $this->collector->name() . '</th>';
40
  echo '</tr>';
41
  echo '<tr>';
42
  echo '<th>' . _x( 'Caller', 'Query caller', 'query-monitor' ) . '</th>';
43
 
44
  if ( !empty( $data['types'] ) ) {
45
- foreach ( $data['types'] as $type_name => $type_count )
46
  echo '<th class="qm-num">' . $type_name . $this->build_sorter() . '</th>';
 
47
  }
48
 
49
  echo '<th class="qm-num qm-sorted-desc">' . __( 'Time', 'query-monitor' ) . $this->build_sorter() . '</th>';
@@ -62,10 +63,11 @@ class QM_Output_Html_DB_Callers extends QM_Output_Html {
62
  echo "<td valign='top' class='qm-ltr'>{$row['caller']}</td>";
63
 
64
  foreach ( $data['types'] as $type_name => $type_count ) {
65
- if ( isset( $row['types'][$type_name] ) )
66
  echo "<td valign='top'>{$row['types'][$type_name]}</td>";
67
- else
68
  echo "<td valign='top'>&nbsp;</td>";
 
69
  }
70
 
71
  echo "<td valign='top'>{$stime}</td>";
@@ -81,8 +83,9 @@ class QM_Output_Html_DB_Callers extends QM_Output_Html {
81
  echo '<tr>';
82
  echo '<td>&nbsp;</td>';
83
 
84
- foreach ( $data['types'] as $type_name => $type_count )
85
  echo '<td>' . number_format_i18n( $type_count ) . '</td>';
 
86
 
87
  echo "<td>{$total_stime}</td>";
88
  echo '</tr>';
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ if ( empty( $data ) ) {
29
  return;
30
+ }
31
 
32
  $total_time = 0;
33
  $span = count( $data['types'] ) + 2;
34
 
35
+ echo '<div class="qm qm-half" id="' . esc_attr( $this->collector->id() ) . '">';
36
  echo '<table cellspacing="0" class="qm-sortable">';
37
  echo '<thead>';
38
  echo '<tr>';
39
+ echo '<th colspan="' . $span . '">' . esc_html( $this->collector->name() ) . '</th>';
40
  echo '</tr>';
41
  echo '<tr>';
42
  echo '<th>' . _x( 'Caller', 'Query caller', 'query-monitor' ) . '</th>';
43
 
44
  if ( !empty( $data['types'] ) ) {
45
+ foreach ( $data['types'] as $type_name => $type_count ) {
46
  echo '<th class="qm-num">' . $type_name . $this->build_sorter() . '</th>';
47
+ }
48
  }
49
 
50
  echo '<th class="qm-num qm-sorted-desc">' . __( 'Time', 'query-monitor' ) . $this->build_sorter() . '</th>';
63
  echo "<td valign='top' class='qm-ltr'>{$row['caller']}</td>";
64
 
65
  foreach ( $data['types'] as $type_name => $type_count ) {
66
+ if ( isset( $row['types'][$type_name] ) ) {
67
  echo "<td valign='top'>{$row['types'][$type_name]}</td>";
68
+ } else {
69
  echo "<td valign='top'>&nbsp;</td>";
70
+ }
71
  }
72
 
73
  echo "<td valign='top'>{$stime}</td>";
83
  echo '<tr>';
84
  echo '<td>&nbsp;</td>';
85
 
86
+ foreach ( $data['types'] as $type_name => $type_count ) {
87
  echo '<td>' . number_format_i18n( $type_count ) . '</td>';
88
+ }
89
 
90
  echo "<td>{$total_stime}</td>";
91
  echo '</tr>';
output/html/db_components.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,25 +25,27 @@ class QM_Output_Html_DB_Components extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- if ( empty( $data ) )
30
  return;
 
31
 
32
  $total_time = 0;
33
  $total_calls = 0;
34
  $span = count( $data['types'] ) + 2;
35
 
36
- echo '<div class="qm qm-half" id="' . $this->collector->id() . '">';
37
  echo '<table cellspacing="0" class="qm-sortable">';
38
  echo '<thead>';
39
  echo '<tr>';
40
- echo '<th colspan="' . $span . '">' . $this->collector->name() . '</th>';
41
  echo '</tr>';
42
  echo '<tr>';
43
  echo '<th>' . _x( 'Component', 'Query component', 'query-monitor' ) . '</th>';
44
 
45
  if ( !empty( $data['types'] ) ) {
46
- foreach ( $data['types'] as $type_name => $type_count )
47
  echo '<th class="qm-num">' . $type_name . $this->build_sorter() . '</th>';
 
48
  }
49
 
50
  echo '<th class="qm-num qm-sorted-desc">' . __( 'Time', 'query-monitor' ) . $this->build_sorter() . '</th>';
@@ -64,10 +65,11 @@ class QM_Output_Html_DB_Components extends QM_Output_Html {
64
  echo "<td valign='top'>{$row['component']}</td>";
65
 
66
  foreach ( $data['types'] as $type_name => $type_count ) {
67
- if ( isset( $row['types'][$type_name] ) )
68
  echo "<td valign='top'>{$row['types'][$type_name]}</td>";
69
- else
70
  echo "<td valign='top'>&nbsp;</td>";
 
71
  }
72
 
73
  echo "<td valign='top'>{$stime}</td>";
@@ -83,8 +85,9 @@ class QM_Output_Html_DB_Components extends QM_Output_Html {
83
  echo '<tr>';
84
  echo '<td>&nbsp;</td>';
85
 
86
- foreach ( $data['types'] as $type_name => $type_count )
87
  echo '<td>' . number_format_i18n( $type_count ) . '</td>';
 
88
 
89
  echo "<td>{$total_stime}</td>";
90
  echo '</tr>';
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ if ( empty( $data ) ) {
29
  return;
30
+ }
31
 
32
  $total_time = 0;
33
  $total_calls = 0;
34
  $span = count( $data['types'] ) + 2;
35
 
36
+ echo '<div class="qm qm-half" id="' . esc_attr( $this->collector->id() ) . '">';
37
  echo '<table cellspacing="0" class="qm-sortable">';
38
  echo '<thead>';
39
  echo '<tr>';
40
+ echo '<th colspan="' . $span . '">' . esc_html( $this->collector->name() ) . '</th>';
41
  echo '</tr>';
42
  echo '<tr>';
43
  echo '<th>' . _x( 'Component', 'Query component', 'query-monitor' ) . '</th>';
44
 
45
  if ( !empty( $data['types'] ) ) {
46
+ foreach ( $data['types'] as $type_name => $type_count ) {
47
  echo '<th class="qm-num">' . $type_name . $this->build_sorter() . '</th>';
48
+ }
49
  }
50
 
51
  echo '<th class="qm-num qm-sorted-desc">' . __( 'Time', 'query-monitor' ) . $this->build_sorter() . '</th>';
65
  echo "<td valign='top'>{$row['component']}</td>";
66
 
67
  foreach ( $data['types'] as $type_name => $type_count ) {
68
+ if ( isset( $row['types'][$type_name] ) ) {
69
  echo "<td valign='top'>{$row['types'][$type_name]}</td>";
70
+ } else {
71
  echo "<td valign='top'>&nbsp;</td>";
72
+ }
73
  }
74
 
75
  echo "<td valign='top'>{$stime}</td>";
85
  echo '<tr>';
86
  echo '<td>&nbsp;</td>';
87
 
88
+ foreach ( $data['types'] as $type_name => $type_count ) {
89
  echo '<td>' . number_format_i18n( $type_count ) . '</td>';
90
+ }
91
 
92
  echo "<td>{$total_stime}</td>";
93
  echo '</tr>';
output/html/db_queries.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -51,7 +50,7 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
51
 
52
  protected function output_empty_queries() {
53
 
54
- echo '<div class="qm qm-queries" id="' . $this->collector->id() . '-wpdb">';
55
  echo '<table cellspacing="0">';
56
  echo '<thead>';
57
  echo '<tr>';
@@ -87,8 +86,9 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
87
  echo '</thead>';
88
  echo '<tbody>';
89
 
90
- foreach ( $errors as $row )
91
  $this->output_query_row( $row, array( 'sql', 'stack', 'component', 'result' ) );
 
92
 
93
  echo '</tbody>';
94
  echo '</table>';
@@ -110,19 +110,22 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
110
  echo '<th scope="col">' . __( 'Query', 'query-monitor' ) . '</th>';
111
  echo '<th scope="col">' . __( 'Caller', 'query-monitor' ) . '</th>';
112
 
113
- if ( isset( $expensive[0]['component'] ) )
114
  echo '<th scope="col">' . __( 'Component', 'query-monitor' ) . '</th>';
 
115
 
116
- if ( isset( $expensive[0]['result'] ) )
117
  echo '<th scope="col">' . __( 'Affected Rows', 'query-monitor' ) . '</th>';
 
118
 
119
  echo '<th class="qm-num">' . __( 'Time', 'query-monitor' ) . '</th>';
120
  echo '</tr>';
121
  echo '</thead>';
122
  echo '<tbody>';
123
 
124
- foreach ( $expensive as $row )
125
  $this->output_query_row( $row, array( 'sql', 'caller', 'component', 'result', 'time' ) );
 
126
 
127
  echo '</tbody>';
128
  echo '</table>';
@@ -134,12 +137,14 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
134
 
135
  $span = 4;
136
 
137
- if ( $db->has_result )
138
  $span++;
139
- if ( $db->has_trace )
 
140
  $span++;
 
141
 
142
- echo '<div class="qm qm-queries" id="' . $this->collector->id() . '-' . sanitize_title( $name ) . '">';
143
  echo '<table cellspacing="0" class="qm-sortable">';
144
  echo '<thead>';
145
  echo '<tr>';
@@ -161,11 +166,13 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
161
  echo '<th scope="col">' . __( 'Query', 'query-monitor' ) . $this->build_filter( 'type', array_keys( $db->types ) ) . '</th>';
162
  echo '<th scope="col">' . __( 'Caller', 'query-monitor' ) . $this->build_filter( 'caller', wp_list_pluck( $data['times'], 'caller' ) ) . '</th>';
163
 
164
- if ( $db->has_trace )
165
  echo '<th scope="col">' . __( 'Component', 'query-monitor' ) . $this->build_filter( 'component', wp_list_pluck( $data['component_times'], 'component' ) ) . '</th>';
 
166
 
167
- if ( $db->has_result )
168
  echo '<th scope="col">' . __( 'Rows', 'query-monitor' ) . $this->build_sorter() . '</th>';
 
169
 
170
  echo '<th scope="col" class="qm-num">' . __( 'Time', 'query-monitor' ) . $this->build_sorter() . '</th>';
171
  echo '</tr>';
@@ -178,8 +185,9 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
178
 
179
  echo '<tbody>';
180
 
181
- foreach ( $db->rows as $row )
182
  $this->output_query_row( $row, array( 'row', 'sql', 'caller', 'component', 'result', 'time' ) );
 
183
 
184
  echo '</tbody>';
185
  echo '<tfoot>';
@@ -216,12 +224,15 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
216
 
217
  $cols = array_flip( $cols );
218
 
219
- if ( !isset( $row['component'] ) )
220
  unset( $cols['component'] );
221
- if ( !isset( $row['result'] ) )
 
222
  unset( $cols['result'] );
223
- if ( !isset( $row['stack'] ) )
 
224
  unset( $cols['stack'] );
 
225
 
226
  $row_attr = array();
227
  $stime = number_format_i18n( $row['ltime'], 4 );
@@ -229,8 +240,9 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
229
 
230
  $sql = self::format_sql( $row['sql'] );
231
 
232
- if ( 'SELECT' != $row['type'] )
233
  $sql = "<span class='qm-nonselectsql'>{$sql}</span>";
 
234
 
235
  if ( is_wp_error( $row['result'] ) ) {
236
  $error = $row['result']->get_error_message();
@@ -261,12 +273,15 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
261
 
262
  }
263
 
264
- if ( isset( $cols['sql'] ) )
265
  $row_attr['data-qm-db_queries-type'] = $row['type'];
266
- if ( isset( $cols['component'] ) )
 
267
  $row_attr['data-qm-db_queries-component'] = $row['component']->name;
268
- if ( isset( $cols['caller'] ) )
 
269
  $row_attr['data-qm-db_queries-caller'] = $row['caller_name'];
 
270
  if ( isset( $cols['time'] ) ) {
271
  $row_attr['data-qm-db_queries-time'] = $row['ltime'];
272
  $row_attr['data-qm-time'] = $row['ltime'];
@@ -274,8 +289,9 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
274
 
275
  $attr = '';
276
 
277
- foreach ( $row_attr as $a => $v )
278
  $attr .= ' ' . $a . '="' . esc_attr( $v ) . '"';
 
279
 
280
  echo "<tr{$attr}>";
281
 
@@ -283,8 +299,9 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
283
  echo "<td valign='top'>" . ++$this->query_row . "</td>";
284
  }
285
 
286
- if ( isset( $cols['sql'] ) )
287
  echo "<td valign='top' class='qm-row-sql qm-ltr qm-sql'>{$sql}</td>";
 
288
 
289
  if ( isset( $cols['caller'] ) ) {
290
  echo "<td valign='top' class='qm-row-caller qm-ltr qm-has-toggle'>";
@@ -303,14 +320,17 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
303
  echo '<td valign="top" class="qm-row-caller qm-row-stack qm-ltr">' . implode( '<br>', $stack ) . '</td>';
304
  }
305
 
306
- if ( isset( $cols['component'] ) )
307
  echo "<td valign='top' class='qm-row-component'>{$row['component']->name}</td>\n";
 
308
 
309
- if ( isset( $cols['result'] ) )
310
  echo $result;
 
311
 
312
- if ( isset( $cols['time'] ) )
313
  echo "<td valign='top' class='qm-row-time{$td}'>{$stime}</td>\n";
 
314
 
315
  echo '</tr>';
316
 
@@ -337,10 +357,12 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
337
 
338
  public function admin_class( array $class ) {
339
 
340
- if ( $this->collector->get_errors() )
341
  $class[] = 'qm-error';
342
- if ( $this->collector->get_expensive() )
 
343
  $class[] = 'qm-expensive';
 
344
  return $class;
345
 
346
  }
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
50
 
51
  protected function output_empty_queries() {
52
 
53
+ echo '<div class="qm qm-queries" id="' . esc_attr( $this->collector->id() ) . '-wpdb">';
54
  echo '<table cellspacing="0">';
55
  echo '<thead>';
56
  echo '<tr>';
86
  echo '</thead>';
87
  echo '<tbody>';
88
 
89
+ foreach ( $errors as $row ) {
90
  $this->output_query_row( $row, array( 'sql', 'stack', 'component', 'result' ) );
91
+ }
92
 
93
  echo '</tbody>';
94
  echo '</table>';
110
  echo '<th scope="col">' . __( 'Query', 'query-monitor' ) . '</th>';
111
  echo '<th scope="col">' . __( 'Caller', 'query-monitor' ) . '</th>';
112
 
113
+ if ( isset( $expensive[0]['component'] ) ) {
114
  echo '<th scope="col">' . __( 'Component', 'query-monitor' ) . '</th>';
115
+ }
116
 
117
+ if ( isset( $expensive[0]['result'] ) ) {
118
  echo '<th scope="col">' . __( 'Affected Rows', 'query-monitor' ) . '</th>';
119
+ }
120
 
121
  echo '<th class="qm-num">' . __( 'Time', 'query-monitor' ) . '</th>';
122
  echo '</tr>';
123
  echo '</thead>';
124
  echo '<tbody>';
125
 
126
+ foreach ( $expensive as $row ) {
127
  $this->output_query_row( $row, array( 'sql', 'caller', 'component', 'result', 'time' ) );
128
+ }
129
 
130
  echo '</tbody>';
131
  echo '</table>';
137
 
138
  $span = 4;
139
 
140
+ if ( $db->has_result ) {
141
  $span++;
142
+ }
143
+ if ( $db->has_trace ) {
144
  $span++;
145
+ }
146
 
147
+ echo '<div class="qm qm-queries" id="' . esc_attr( $this->collector->id() ) . '-' . sanitize_title( $name ) . '">';
148
  echo '<table cellspacing="0" class="qm-sortable">';
149
  echo '<thead>';
150
  echo '<tr>';
166
  echo '<th scope="col">' . __( 'Query', 'query-monitor' ) . $this->build_filter( 'type', array_keys( $db->types ) ) . '</th>';
167
  echo '<th scope="col">' . __( 'Caller', 'query-monitor' ) . $this->build_filter( 'caller', wp_list_pluck( $data['times'], 'caller' ) ) . '</th>';
168
 
169
+ if ( $db->has_trace ) {
170
  echo '<th scope="col">' . __( 'Component', 'query-monitor' ) . $this->build_filter( 'component', wp_list_pluck( $data['component_times'], 'component' ) ) . '</th>';
171
+ }
172
 
173
+ if ( $db->has_result ) {
174
  echo '<th scope="col">' . __( 'Rows', 'query-monitor' ) . $this->build_sorter() . '</th>';
175
+ }
176
 
177
  echo '<th scope="col" class="qm-num">' . __( 'Time', 'query-monitor' ) . $this->build_sorter() . '</th>';
178
  echo '</tr>';
185
 
186
  echo '<tbody>';
187
 
188
+ foreach ( $db->rows as $row ) {
189
  $this->output_query_row( $row, array( 'row', 'sql', 'caller', 'component', 'result', 'time' ) );
190
+ }
191
 
192
  echo '</tbody>';
193
  echo '<tfoot>';
224
 
225
  $cols = array_flip( $cols );
226
 
227
+ if ( !isset( $row['component'] ) ) {
228
  unset( $cols['component'] );
229
+ }
230
+ if ( !isset( $row['result'] ) ) {
231
  unset( $cols['result'] );
232
+ }
233
+ if ( !isset( $row['stack'] ) ) {
234
  unset( $cols['stack'] );
235
+ }
236
 
237
  $row_attr = array();
238
  $stime = number_format_i18n( $row['ltime'], 4 );
240
 
241
  $sql = self::format_sql( $row['sql'] );
242
 
243
+ if ( 'SELECT' != $row['type'] ) {
244
  $sql = "<span class='qm-nonselectsql'>{$sql}</span>";
245
+ }
246
 
247
  if ( is_wp_error( $row['result'] ) ) {
248
  $error = $row['result']->get_error_message();
273
 
274
  }
275
 
276
+ if ( isset( $cols['sql'] ) ) {
277
  $row_attr['data-qm-db_queries-type'] = $row['type'];
278
+ }
279
+ if ( isset( $cols['component'] ) ) {
280
  $row_attr['data-qm-db_queries-component'] = $row['component']->name;
281
+ }
282
+ if ( isset( $cols['caller'] ) ) {
283
  $row_attr['data-qm-db_queries-caller'] = $row['caller_name'];
284
+ }
285
  if ( isset( $cols['time'] ) ) {
286
  $row_attr['data-qm-db_queries-time'] = $row['ltime'];
287
  $row_attr['data-qm-time'] = $row['ltime'];
289
 
290
  $attr = '';
291
 
292
+ foreach ( $row_attr as $a => $v ) {
293
  $attr .= ' ' . $a . '="' . esc_attr( $v ) . '"';
294
+ }
295
 
296
  echo "<tr{$attr}>";
297
 
299
  echo "<td valign='top'>" . ++$this->query_row . "</td>";
300
  }
301
 
302
+ if ( isset( $cols['sql'] ) ) {
303
  echo "<td valign='top' class='qm-row-sql qm-ltr qm-sql'>{$sql}</td>";
304
+ }
305
 
306
  if ( isset( $cols['caller'] ) ) {
307
  echo "<td valign='top' class='qm-row-caller qm-ltr qm-has-toggle'>";
320
  echo '<td valign="top" class="qm-row-caller qm-row-stack qm-ltr">' . implode( '<br>', $stack ) . '</td>';
321
  }
322
 
323
+ if ( isset( $cols['component'] ) ) {
324
  echo "<td valign='top' class='qm-row-component'>{$row['component']->name}</td>\n";
325
+ }
326
 
327
+ if ( isset( $cols['result'] ) ) {
328
  echo $result;
329
+ }
330
 
331
+ if ( isset( $cols['time'] ) ) {
332
  echo "<td valign='top' class='qm-row-time{$td}'>{$stime}</td>\n";
333
+ }
334
 
335
  echo '</tr>';
336
 
357
 
358
  public function admin_class( array $class ) {
359
 
360
+ if ( $this->collector->get_errors() ) {
361
  $class[] = 'qm-error';
362
+ }
363
+ if ( $this->collector->get_expensive() ) {
364
  $class[] = 'qm-expensive';
365
+ }
366
  return $class;
367
 
368
  }
output/html/environment.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,7 +25,7 @@ class QM_Output_Html_Environment extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- echo '<div id="' . $this->collector->id() . '">';
30
 
31
  echo '<div class="qm qm-half">';
32
  echo '<table cellspacing="0">';
@@ -54,8 +53,9 @@ class QM_Output_Html_Environment extends QM_Output_Html {
54
 
55
  $append = '';
56
 
57
- if ( $val['after'] != $val['before'] )
58
  $append .= '<br><span class="qm-info">' . sprintf( __( 'Overridden at runtime from %s', 'query-monitor' ), $val['before'] ) . '</span>';
 
59
 
60
  echo '<tr>';
61
  echo "<td>{$key}</td>";
@@ -78,10 +78,11 @@ class QM_Output_Html_Environment extends QM_Output_Html {
78
 
79
  foreach ( $data['db'] as $id => $db ) {
80
 
81
- if ( 1 == count( $data['db'] ) )
82
- $name = 'MySQL';
83
- else
84
- $name = 'MySQL: ' . $id;
 
85
 
86
  echo '<div class="qm qm-half">';
87
  echo '<table cellspacing="0">';
@@ -93,13 +94,13 @@ class QM_Output_Html_Environment extends QM_Output_Html {
93
  echo '<tbody>';
94
 
95
  echo '<tr>';
96
- echo '<td>version</td>';
97
- echo '<td>' . $db['version'] . '</td>';
98
  echo '</tr>';
99
 
100
  echo '<tr>';
101
- echo '<td>driver</td>';
102
- echo '<td>' . $db['driver'] . '</td>';
103
  echo '</tr>';
104
 
105
  echo '<tr>';
@@ -130,21 +131,25 @@ class QM_Output_Html_Environment extends QM_Output_Html {
130
  $prepend = '';
131
  $show_warning = false;
132
 
133
- if ( ( true === $db['vars'][$key] ) and empty( $val ) )
134
  $show_warning = true;
135
- else if ( is_string( $db['vars'][$key] ) and ( $val !== $db['vars'][$key] ) )
136
  $show_warning = true;
 
137
 
138
- if ( $show_warning )
139
  $prepend .= '&nbsp;<span class="qm-info">(<a href="' . esc_url( sprintf( $search, $key ) ) . '" target="_blank" title="' . esc_attr( sprintf( $warn, $key ) ) . '">' . __( 'Help', 'query-monitor' ) . '</a>)</span>';
 
140
 
141
- if ( is_numeric( $val ) and ( $val >= ( 1024*1024 ) ) )
142
  $prepend .= '<br><span class="qm-info">~' . size_format( $val ) . '</span>';
 
143
 
144
  $class = ( $show_warning ) ? 'qm-warn' : '';
145
 
146
- if ( !$first )
147
  echo "<tr class='{$class}'>";
 
148
 
149
  $key = esc_html( $key );
150
  $val = esc_html( $val );
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ echo '<div id="' . esc_attr( $this->collector->id() ) . '">';
29
 
30
  echo '<div class="qm qm-half">';
31
  echo '<table cellspacing="0">';
53
 
54
  $append = '';
55
 
56
+ if ( $val['after'] != $val['before'] ) {
57
  $append .= '<br><span class="qm-info">' . sprintf( __( 'Overridden at runtime from %s', 'query-monitor' ), $val['before'] ) . '</span>';
58
+ }
59
 
60
  echo '<tr>';
61
  echo "<td>{$key}</td>";
78
 
79
  foreach ( $data['db'] as $id => $db ) {
80
 
81
+ if ( 1 == count( $data['db'] ) ) {
82
+ $name = 'Database';
83
+ } else {
84
+ $name = 'Database: ' . $id;
85
+ }
86
 
87
  echo '<div class="qm qm-half">';
88
  echo '<table cellspacing="0">';
94
  echo '<tbody>';
95
 
96
  echo '<tr>';
97
+ echo '<td>driver</td>';
98
+ echo '<td>' . $db['driver'] . '</td>';
99
  echo '</tr>';
100
 
101
  echo '<tr>';
102
+ echo '<td>version</td>';
103
+ echo '<td>' . $db['version'] . '</td>';
104
  echo '</tr>';
105
 
106
  echo '<tr>';
131
  $prepend = '';
132
  $show_warning = false;
133
 
134
+ if ( ( true === $db['vars'][$key] ) and empty( $val ) ) {
135
  $show_warning = true;
136
+ } else if ( is_string( $db['vars'][$key] ) and ( $val !== $db['vars'][$key] ) ) {
137
  $show_warning = true;
138
+ }
139
 
140
+ if ( $show_warning ) {
141
  $prepend .= '&nbsp;<span class="qm-info">(<a href="' . esc_url( sprintf( $search, $key ) ) . '" target="_blank" title="' . esc_attr( sprintf( $warn, $key ) ) . '">' . __( 'Help', 'query-monitor' ) . '</a>)</span>';
142
+ }
143
 
144
+ if ( is_numeric( $val ) and ( $val >= ( 1024*1024 ) ) ) {
145
  $prepend .= '<br><span class="qm-info">~' . size_format( $val ) . '</span>';
146
+ }
147
 
148
  $class = ( $show_warning ) ? 'qm-warn' : '';
149
 
150
+ if ( !$first ) {
151
  echo "<tr class='{$class}'>";
152
+ }
153
 
154
  $key = esc_html( $key );
155
  $val = esc_html( $val );
output/html/hooks.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -28,17 +27,19 @@ class QM_Output_Html_Hooks extends QM_Output_Html {
28
 
29
  $data = $this->collector->get_data();
30
 
31
- if ( empty( $data ) )
32
  return;
 
33
 
34
  $row_attr = array();
35
 
36
- if ( is_multisite() and is_network_admin() )
37
  $screen = preg_replace( '|-network$|', '', $data['screen'] );
38
- else
39
  $screen = $data['screen'];
 
40
 
41
- echo '<div class="qm" id="' . $this->collector->id() . '">';
42
  echo '<table cellspacing="0">';
43
  echo '<thead>';
44
  echo '<tr>';
@@ -52,10 +53,11 @@ class QM_Output_Html_Hooks extends QM_Output_Html {
52
 
53
  if ( !empty( $screen ) ) {
54
 
55
- if ( false !== strpos( $hook['name'], $screen . '.php' ) )
56
  $hook['name'] = str_replace( '-' . $screen . '.php', '-<span class="qm-current">' . $screen . '.php</span>', $hook['name'] );
57
- else
58
  $hook['name'] = str_replace( '-' . $screen, '-<span class="qm-current">' . $screen . '</span>', $hook['name'] );
 
59
 
60
  }
61
 
@@ -64,13 +66,15 @@ class QM_Output_Html_Hooks extends QM_Output_Html {
64
 
65
  $attr = '';
66
 
67
- if ( !empty( $hook['actions'] ) )
68
  $rowspan = count( $hook['actions'] );
69
- else
70
  $rowspan = 1;
 
71
 
72
- foreach ( $row_attr as $a => $v )
73
  $attr .= ' ' . $a . '="' . esc_attr( $v ) . '"';
 
74
 
75
  echo "<tr{$attr}>";
76
 
@@ -81,13 +85,15 @@ class QM_Output_Html_Hooks extends QM_Output_Html {
81
 
82
  foreach ( $hook['actions'] as $action ) {
83
 
84
- if ( isset( $action['callback']['component'] ) )
85
  $component = $action['callback']['component']->name;
86
- else
87
  $component = '';
 
88
 
89
- if ( !$first )
90
  echo "<tr{$attr}>";
 
91
 
92
  echo '<td valign="top" class="qm-priority">' . $action['priority'] . '</td>';
93
  echo '<td valign="top" class="qm-ltr">';
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
27
 
28
  $data = $this->collector->get_data();
29
 
30
+ if ( empty( $data ) ) {
31
  return;
32
+ }
33
 
34
  $row_attr = array();
35
 
36
+ if ( is_multisite() and is_network_admin() ) {
37
  $screen = preg_replace( '|-network$|', '', $data['screen'] );
38
+ } else {
39
  $screen = $data['screen'];
40
+ }
41
 
42
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
43
  echo '<table cellspacing="0">';
44
  echo '<thead>';
45
  echo '<tr>';
53
 
54
  if ( !empty( $screen ) ) {
55
 
56
+ if ( false !== strpos( $hook['name'], $screen . '.php' ) ) {
57
  $hook['name'] = str_replace( '-' . $screen . '.php', '-<span class="qm-current">' . $screen . '.php</span>', $hook['name'] );
58
+ } else {
59
  $hook['name'] = str_replace( '-' . $screen, '-<span class="qm-current">' . $screen . '</span>', $hook['name'] );
60
+ }
61
 
62
  }
63
 
66
 
67
  $attr = '';
68
 
69
+ if ( !empty( $hook['actions'] ) ) {
70
  $rowspan = count( $hook['actions'] );
71
+ } else {
72
  $rowspan = 1;
73
+ }
74
 
75
+ foreach ( $row_attr as $a => $v ) {
76
  $attr .= ' ' . $a . '="' . esc_attr( $v ) . '"';
77
+ }
78
 
79
  echo "<tr{$attr}>";
80
 
85
 
86
  foreach ( $hook['actions'] as $action ) {
87
 
88
+ if ( isset( $action['callback']['component'] ) ) {
89
  $component = $action['callback']['component']->name;
90
+ } else {
91
  $component = '';
92
+ }
93
 
94
+ if ( !$first ) {
95
  echo "<tr{$attr}>";
96
+ }
97
 
98
  echo '<td valign="top" class="qm-priority">' . $action['priority'] . '</td>';
99
  echo '<td valign="top" class="qm-ltr">';
output/html/http.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -29,7 +28,7 @@ class QM_Output_Html_HTTP extends QM_Output_Html {
29
 
30
  $total_time = 0;
31
 
32
- echo '<div class="qm" id="' . $this->collector->id() . '">';
33
  echo '<table cellspacing="0">';
34
  echo '<thead>';
35
  echo '<tr>';
@@ -59,40 +58,44 @@ class QM_Output_Html_HTTP extends QM_Output_Html {
59
 
60
  foreach ( $data['http'] as $key => $row ) {
61
  $ltime = $row['ltime'];
62
- $total_time += $ltime;
63
 
64
- if ( empty( $ltime ) )
65
  $stime = '';
66
- else
67
  $stime = number_format_i18n( $ltime, 4 );
 
68
 
69
  if ( is_wp_error( $row['response'] ) ) {
70
- $response = $row['response']->get_error_message();
71
  $css = 'qm-warn';
72
  } else {
73
  $response = wp_remote_retrieve_response_code( $row['response'] );
74
  $msg = wp_remote_retrieve_response_message( $row['response'] );
75
  $css = '';
76
 
77
- if ( empty( $response ) )
78
  $response = __( 'n/a', 'query-monitor' );
79
- else
80
  $response = esc_html( $response . ' ' . $msg );
 
81
 
82
- if ( intval( $response ) >= 400 )
83
  $css = 'qm-warn';
 
84
 
85
  }
86
 
87
  $method = $row['args']['method'];
88
- if ( !$row['args']['blocking'] )
89
  $method .= '&nbsp;' . _x( '(non-blocking)', 'non-blocking HTTP transport', 'query-monitor' );
 
90
  $url = self::format_url( $row['url'] );
91
 
92
- if ( isset( $row['transport'] ) )
93
  $transport = $row['transport'];
94
- else
95
  $transport = '';
 
96
 
97
  $stack = $row['trace']->get_stack();
98
  $component = $row['trace']->get_component();
@@ -114,7 +117,7 @@ class QM_Output_Html_HTTP extends QM_Output_Html {
114
  echo '</tbody>';
115
  echo '<tfoot>';
116
 
117
- $total_stime = number_format_i18n( $total_time, 4 );
118
 
119
  echo '<tr>';
120
  echo '<td colspan="6">' . $vars . '</td>';
@@ -146,10 +149,11 @@ class QM_Output_Html_HTTP extends QM_Output_Html {
146
 
147
  $data = $this->collector->get_data();
148
 
149
- if ( isset( $data['errors']['error'] ) )
150
  $class[] = 'qm-error';
151
- else if ( isset( $data['errors']['warning'] ) )
152
  $class[] = 'qm-warning';
 
153
 
154
  return $class;
155
 
@@ -169,10 +173,11 @@ class QM_Output_Html_HTTP extends QM_Output_Html {
169
  'title' => sprintf( $title, number_format_i18n( $count ) ),
170
  );
171
 
172
- if ( isset( $data['errors']['error'] ) )
173
  $args['meta']['classname'] = 'qm-error';
174
- else if ( isset( $data['errors']['warning'] ) )
175
  $args['meta']['classname'] = 'qm-warning';
 
176
 
177
  $menu[] = $this->menu( $args );
178
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
28
 
29
  $total_time = 0;
30
 
31
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
32
  echo '<table cellspacing="0">';
33
  echo '<thead>';
34
  echo '<tr>';
58
 
59
  foreach ( $data['http'] as $key => $row ) {
60
  $ltime = $row['ltime'];
 
61
 
62
+ if ( empty( $ltime ) ) {
63
  $stime = '';
64
+ } else {
65
  $stime = number_format_i18n( $ltime, 4 );
66
+ }
67
 
68
  if ( is_wp_error( $row['response'] ) ) {
69
+ $response = esc_html( $row['response']->get_error_message() );
70
  $css = 'qm-warn';
71
  } else {
72
  $response = wp_remote_retrieve_response_code( $row['response'] );
73
  $msg = wp_remote_retrieve_response_message( $row['response'] );
74
  $css = '';
75
 
76
+ if ( empty( $response ) ) {
77
  $response = __( 'n/a', 'query-monitor' );
78
+ } else {
79
  $response = esc_html( $response . ' ' . $msg );
80
+ }
81
 
82
+ if ( intval( $response ) >= 400 ) {
83
  $css = 'qm-warn';
84
+ }
85
 
86
  }
87
 
88
  $method = $row['args']['method'];
89
+ if ( !$row['args']['blocking'] ) {
90
  $method .= '&nbsp;' . _x( '(non-blocking)', 'non-blocking HTTP transport', 'query-monitor' );
91
+ }
92
  $url = self::format_url( $row['url'] );
93
 
94
+ if ( isset( $row['transport'] ) ) {
95
  $transport = $row['transport'];
96
+ } else {
97
  $transport = '';
98
+ }
99
 
100
  $stack = $row['trace']->get_stack();
101
  $component = $row['trace']->get_component();
117
  echo '</tbody>';
118
  echo '<tfoot>';
119
 
120
+ $total_stime = number_format_i18n( $data['ltime'], 4 );
121
 
122
  echo '<tr>';
123
  echo '<td colspan="6">' . $vars . '</td>';
149
 
150
  $data = $this->collector->get_data();
151
 
152
+ if ( isset( $data['errors']['error'] ) ) {
153
  $class[] = 'qm-error';
154
+ } else if ( isset( $data['errors']['warning'] ) ) {
155
  $class[] = 'qm-warning';
156
+ }
157
 
158
  return $class;
159
 
173
  'title' => sprintf( $title, number_format_i18n( $count ) ),
174
  );
175
 
176
+ if ( isset( $data['errors']['error'] ) ) {
177
  $args['meta']['classname'] = 'qm-error';
178
+ } else if ( isset( $data['errors']['warning'] ) ) {
179
  $args['meta']['classname'] = 'qm-warning';
180
+ }
181
 
182
  $menu[] = $this->menu( $args );
183
 
output/html/overview.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -41,7 +40,7 @@ class QM_Output_Html_Overview extends QM_Output_Html {
41
 
42
  $total_stime = number_format_i18n( $data['time'], 4 );
43
 
44
- echo '<div class="qm" id="' . $this->collector->id() . '">';
45
  echo '<table cellspacing="0">';
46
 
47
  $memory_usage = '<br><span class="qm-info">' . sprintf( __( '%1$s%% of %2$s kB limit', 'query-monitor' ), number_format_i18n( $data['memory_usage'], 1 ), number_format_i18n( $data['memory_limit'] / 1024 ) ) . '</span>';
@@ -73,8 +72,9 @@ class QM_Output_Html_Overview extends QM_Output_Html {
73
  echo "<td>{$db_stime}</td>";
74
  echo '<td>';
75
 
76
- foreach ( $db_query_num as $type_name => $type_count )
77
  $db_query_types[] = sprintf( '%1$s: %2$s', $type_name, number_format_i18n( $type_count ) );
 
78
 
79
  echo implode( '<br>', $db_query_types );
80
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
40
 
41
  $total_stime = number_format_i18n( $data['time'], 4 );
42
 
43
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
44
  echo '<table cellspacing="0">';
45
 
46
  $memory_usage = '<br><span class="qm-info">' . sprintf( __( '%1$s%% of %2$s kB limit', 'query-monitor' ), number_format_i18n( $data['memory_usage'], 1 ), number_format_i18n( $data['memory_limit'] / 1024 ) ) . '</span>';
72
  echo "<td>{$db_stime}</td>";
73
  echo '<td>';
74
 
75
+ foreach ( $db_query_num as $type_name => $type_count ) {
76
  $db_query_types[] = sprintf( '%1$s: %2$s', $type_name, number_format_i18n( $type_count ) );
77
+ }
78
 
79
  echo implode( '<br>', $db_query_types );
80
 
output/html/php_errors.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -27,10 +26,11 @@ class QM_Output_Html_PHP_Errors extends QM_Output_Html {
27
 
28
  $data = $this->collector->get_data();
29
 
30
- if ( empty( $data['errors'] ) )
31
  return;
 
32
 
33
- echo '<div class="qm" id="' . $this->collector->id() . '">';
34
  echo '<table cellspacing="0">';
35
  echo '<thead>';
36
  echo '<tr>';
@@ -60,11 +60,17 @@ class QM_Output_Html_PHP_Errors extends QM_Output_Html {
60
 
61
  foreach ( $data['errors'][$type] as $error ) {
62
 
63
- if ( !$first )
64
  echo '<tr>';
 
65
 
66
  $stack = $error->trace->get_stack();
67
  $component = $error->trace->get_component();
 
 
 
 
 
68
  $stack = implode( '<br>', $stack );
69
  $message = str_replace( "href='function.", "target='_blank' href='http://php.net/function.", $error->message );
70
 
@@ -76,7 +82,7 @@ class QM_Output_Html_PHP_Errors extends QM_Output_Html {
76
  echo self::output_filename( $output, $error->file, $error->line );
77
  echo '</td>';
78
  echo '<td class="qm-ltr">' . $stack . '</td>';
79
- echo '<td>' . $component->name . '</td>';
80
  echo '</tr>';
81
 
82
  $first = false;
@@ -97,14 +103,15 @@ class QM_Output_Html_PHP_Errors extends QM_Output_Html {
97
 
98
  $data = $this->collector->get_data();
99
 
100
- if ( isset( $data['errors']['warning'] ) )
101
  $class[] = 'qm-warning';
102
- else if ( isset( $data['errors']['notice'] ) )
103
  $class[] = 'qm-notice';
104
- else if ( isset( $data['errors']['strict'] ) )
105
  $class[] = 'qm-strict';
106
- else if ( isset( $data['errors']['deprecated'] ) )
107
  $class[] = 'qm-deprecated';
 
108
 
109
  return $class;
110
 
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
26
 
27
  $data = $this->collector->get_data();
28
 
29
+ if ( empty( $data['errors'] ) ) {
30
  return;
31
+ }
32
 
33
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
34
  echo '<table cellspacing="0">';
35
  echo '<thead>';
36
  echo '<tr>';
60
 
61
  foreach ( $data['errors'][$type] as $error ) {
62
 
63
+ if ( !$first ) {
64
  echo '<tr>';
65
+ }
66
 
67
  $stack = $error->trace->get_stack();
68
  $component = $error->trace->get_component();
69
+ if ( $component ) {
70
+ $name = $component->name;
71
+ } else {
72
+ $name = '<em>' . __( 'Unknown', 'query-monitor' ) . '</em>';
73
+ }
74
  $stack = implode( '<br>', $stack );
75
  $message = str_replace( "href='function.", "target='_blank' href='http://php.net/function.", $error->message );
76
 
82
  echo self::output_filename( $output, $error->file, $error->line );
83
  echo '</td>';
84
  echo '<td class="qm-ltr">' . $stack . '</td>';
85
+ echo '<td>' . $name . '</td>';
86
  echo '</tr>';
87
 
88
  $first = false;
103
 
104
  $data = $this->collector->get_data();
105
 
106
+ if ( isset( $data['errors']['warning'] ) ) {
107
  $class[] = 'qm-warning';
108
+ } else if ( isset( $data['errors']['notice'] ) ) {
109
  $class[] = 'qm-notice';
110
+ } else if ( isset( $data['errors']['strict'] ) ) {
111
  $class[] = 'qm-strict';
112
+ } else if ( isset( $data['errors']['deprecated'] ) ) {
113
  $class[] = 'qm-deprecated';
114
+ }
115
 
116
  return $class;
117
 
output/html/request.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,7 +25,7 @@ class QM_Output_Html_Request extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- echo '<div class="qm qm-half" id="' . $this->collector->id() . '">';
30
  echo '<table cellspacing="0">';
31
  echo '<tbody>';
32
 
@@ -37,8 +36,9 @@ class QM_Output_Html_Request extends QM_Output_Html {
37
  'query_string' => __( 'Query String', 'query-monitor' ),
38
  ) as $item => $name ) {
39
 
40
- if ( !isset( $data['request'][$item] ) )
41
  continue;
 
42
 
43
  if ( ! empty( $data['request'][$item] ) ) {
44
  if ( in_array( $item, array( 'request', 'matched_query', 'query_string' ) ) ) {
@@ -67,13 +67,15 @@ class QM_Output_Html_Request extends QM_Output_Html {
67
 
68
  foreach( $data['qvars'] as $var => $value ) {
69
 
70
- if ( !$first )
71
  echo '<tr>';
 
72
 
73
- if ( isset( $data['plugin_qvars'][$var] ) )
74
  echo "<td valign='top'><span class='qm-current'>{$var}</span></td>";
75
- else
76
  echo "<td valign='top'>{$var}</td>";
 
77
 
78
  if ( is_array( $value ) or is_object( $value ) ) {
79
  echo '<td valign="top"><pre>';
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ echo '<div class="qm qm-half" id="' . esc_attr( $this->collector->id() ) . '">';
29
  echo '<table cellspacing="0">';
30
  echo '<tbody>';
31
 
36
  'query_string' => __( 'Query String', 'query-monitor' ),
37
  ) as $item => $name ) {
38
 
39
+ if ( !isset( $data['request'][$item] ) ) {
40
  continue;
41
+ }
42
 
43
  if ( ! empty( $data['request'][$item] ) ) {
44
  if ( in_array( $item, array( 'request', 'matched_query', 'query_string' ) ) ) {
67
 
68
  foreach( $data['qvars'] as $var => $value ) {
69
 
70
+ if ( !$first ) {
71
  echo '<tr>';
72
+ }
73
 
74
+ if ( isset( $data['plugin_qvars'][$var] ) ) {
75
  echo "<td valign='top'><span class='qm-current'>{$var}</span></td>";
76
+ } else {
77
  echo "<td valign='top'>{$var}</td>";
78
+ }
79
 
80
  if ( is_array( $value ) or is_object( $value ) ) {
81
  echo '<td valign="top"><pre>';
output/html/theme.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,10 +25,11 @@ class QM_Output_Html_Theme extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- if ( empty( $data ) )
30
  return;
 
31
 
32
- echo '<div class="qm qm-half" id="' . $this->collector->id() . '">';
33
  echo '<table cellspacing="0">';
34
  echo '<tbody>';
35
 
@@ -58,8 +58,9 @@ class QM_Output_Html_Theme extends QM_Output_Html {
58
 
59
  foreach ( $data['body_class'] as $class ) {
60
 
61
- if ( !$first )
62
  echo '<tr>';
 
63
 
64
  echo '<td>' . esc_html( $class ) . '</td>';
65
  echo '</tr>';
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ if ( empty( $data ) ) {
29
  return;
30
+ }
31
 
32
+ echo '<div class="qm qm-half" id="' . esc_attr( $this->collector->id() ) . '">';
33
  echo '<table cellspacing="0">';
34
  echo '<tbody>';
35
 
58
 
59
  foreach ( $data['body_class'] as $class ) {
60
 
61
+ if ( !$first ) {
62
  echo '<tr>';
63
+ }
64
 
65
  echo '<td>' . esc_html( $class ) . '</td>';
66
  echo '</tr>';
output/html/transients.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
-
4
- Copyright 2014 John Blackbourn
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -26,15 +25,17 @@ class QM_Output_Html_Transients extends QM_Output_Html {
26
 
27
  $data = $this->collector->get_data();
28
 
29
- echo '<div class="qm" id="' . $this->collector->id() . '">';
30
  echo '<table cellspacing="0">';
31
  echo '<thead>';
32
  echo '<tr>';
33
  echo '<th>' . __( 'Transient Set', 'query-monitor' ) . '</th>';
34
- if ( is_multisite() )
35
  echo '<th>' . __( 'Type', 'query-monitor' ) . '</th>';
36
- if ( !empty( $data['trans'] ) and isset( $data['trans'][0]['expiration'] ) )
 
37
  echo '<th>' . __( 'Expiration', 'query-monitor' ) . '</th>';
 
38
  echo '<th>' . __( 'Call Stack', 'query-monitor' ) . '</th>';
39
  echo '<th>' . __( 'Component', 'query-monitor' ) . '</th>';
40
  echo '</tr>';
@@ -51,8 +52,9 @@ class QM_Output_Html_Transients extends QM_Output_Html {
51
  '_transient_'
52
  ), '', $row['transient'] );
53
  $type = ( is_multisite() ) ? "<td valign='top'>{$row['type']}</td>\n" : '';
54
- if ( 0 === $row['expiration'] )
55
  $row['expiration'] = '<em>' . __( 'none', 'query-monitor' ) . '</em>';
 
56
  $expiration = ( isset( $row['expiration'] ) ) ? "<td valign='top'>{$row['expiration']}</td>\n" : '';
57
 
58
  $component = $row['trace']->get_component();
1
  <?php
2
  /*
3
+ Copyright 2009-2015 John Blackbourn
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
25
 
26
  $data = $this->collector->get_data();
27
 
28
+ echo '<div class="qm" id="' . esc_attr( $this->collector->id() ) . '">';
29
  echo '<table cellspacing="0">';
30
  echo '<thead>';
31
  echo '<tr>';
32
  echo '<th>' . __( 'Transient Set', 'query-monitor' ) . '</th>';
33
+ if ( is_multisite() ) {
34
  echo '<th>' . __( 'Type', 'query-monitor' ) . '</th>';
35
+ }
36
+ if ( !empty( $data['trans'] ) and isset( $data['trans'][0]['expiration'] ) ) {
37
  echo '<th>' . __( 'Expiration', 'query-monitor' ) . '</th>';
38
+ }
39
  echo '<th>' . __( 'Call Stack', 'query-monitor' ) . '</th>';
40
  echo '<th>' . __( 'Component', 'query-monitor' ) . '</th>';
41
  echo '</tr>';
52
  '_transient_'
53
  ), '', $row['transient'] );
54
  $type = ( is_multisite() ) ? "<td valign='top'>{$row['type']}</td>\n" : '';
55
+ if ( 0 === $row['expiration'] ) {
56
  $row['expiration'] = '<em>' . __( 'none', 'query-monitor' ) . '</em>';
57
+ }
58
  $expiration = ( isset( $row['expiration'] ) ) ? "<td valign='top'>{$row['expiration']}</td>\n" : '';
59
 
60
  $component = $row['trace']->get_component();
query-monitor.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Query Monitor
4
  Description: Monitoring of database queries, hooks, conditionals and more.
5
- Version: 2.6.8
6
  Plugin URI: https://querymonitor.com/
7
  Author: John Blackbourn
8
  Author URI: https://johnblackbourn.com/
@@ -10,7 +10,7 @@ Text Domain: query-monitor
10
  Domain Path: /languages/
11
  License: GPL v2 or later
12
 
13
- Copyright 2014 John Blackbourn
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License as published by
@@ -26,13 +26,15 @@ GNU General Public License for more details.
26
 
27
  defined( 'ABSPATH' ) or die();
28
 
29
- if ( defined( 'QM_DISABLED' ) and QM_DISABLED )
30
  return;
 
31
 
32
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
33
  $qm_dir = dirname( __FILE__ );
34
- foreach ( array( 'Backtrace', 'Collector', 'Plugin', 'Util', 'Dispatcher', 'Output' ) as $qm_class )
35
  require_once "{$qm_dir}/{$qm_class}.php";
 
36
 
37
  class QueryMonitor extends QM_Plugin {
38
 
@@ -58,22 +60,32 @@ class QueryMonitor extends QM_Plugin {
58
  parent::__construct( $file );
59
 
60
  # Collectors:
61
- foreach ( glob( $this->plugin_path( 'collectors/*.php' ) ) as $collector )
62
- include $collector;
 
 
 
 
63
 
64
- foreach ( apply_filters( 'query_monitor_collectors', array() ) as $collector )
65
  $this->add_collector( $collector );
 
66
 
67
  }
68
 
69
  public function action_plugins_loaded() {
70
 
71
  # Dispatchers:
72
- foreach ( glob( $this->plugin_path( 'dispatchers/*.php' ) ) as $dispatcher )
73
- include $dispatcher;
 
 
 
 
74
 
75
- foreach ( apply_filters( 'query_monitor_dispatchers', array(), $this ) as $dispatcher )
76
  $this->add_dispatcher( $dispatcher );
 
77
 
78
  }
79
 
@@ -87,8 +99,9 @@ class QueryMonitor extends QM_Plugin {
87
 
88
  public static function get_collector( $id ) {
89
  $qm = self::init();
90
- if ( isset( $qm->collectors[$id] ) )
91
  return $qm->collectors[$id];
 
92
  return false;
93
  }
94
 
@@ -102,41 +115,48 @@ class QueryMonitor extends QM_Plugin {
102
 
103
  public function activate( $sitewide = false ) {
104
 
105
- if ( $admins = QM_Util::get_admins() )
106
  $admins->add_cap( 'view_query_monitor' );
 
107
 
108
- if ( ! file_exists( $db = WP_CONTENT_DIR . '/db.php' ) and function_exists( 'symlink' ) )
109
  @symlink( $this->plugin_path( 'wp-content/db.php' ), $db );
 
110
 
111
- if ( $sitewide )
112
  update_site_option( 'active_sitewide_plugins', get_site_option( 'active_sitewide_plugins' ) );
113
- else
114
  update_option( 'active_plugins', get_option( 'active_plugins' ) );
 
115
 
116
  }
117
 
118
  public function deactivate() {
119
 
120
- if ( $admins = QM_Util::get_admins() )
121
  $admins->remove_cap( 'view_query_monitor' );
 
122
 
123
  # Only delete db.php if it belongs to Query Monitor
124
- if ( class_exists( 'QueryMonitorDB' ) )
125
  unlink( WP_CONTENT_DIR . '/db.php' );
 
126
 
127
  }
128
 
129
  public function user_can_view() {
130
 
131
- if ( !did_action( 'plugins_loaded' ) )
132
  return false;
 
133
 
134
  if ( current_user_can( 'view_query_monitor' ) ) {
135
  return true;
136
  }
137
 
138
- if ( $auth = self::get_collector( 'authentication' ) )
139
  return $auth->user_verified();
 
140
 
141
  return false;
142
 
@@ -187,6 +207,7 @@ class QueryMonitor extends QM_Plugin {
187
  }
188
 
189
  foreach ( $this->get_collectors() as $collector ) {
 
190
  $collector->process();
191
  }
192
 
@@ -218,7 +239,11 @@ class QueryMonitor extends QM_Plugin {
218
 
219
  }
220
 
221
- public function filter_active_plugins( array $plugins ) {
 
 
 
 
222
 
223
  $f = preg_quote( basename( $this->plugin_base() ) );
224
 
@@ -229,7 +254,11 @@ class QueryMonitor extends QM_Plugin {
229
 
230
  }
231
 
232
- public function filter_active_sitewide_plugins( array $plugins ) {
 
 
 
 
233
 
234
  $f = $this->plugin_base();
235
 
@@ -247,12 +276,18 @@ class QueryMonitor extends QM_Plugin {
247
 
248
  }
249
 
 
 
 
 
 
250
  public static function init( $file = null ) {
251
 
252
  static $instance = null;
253
 
254
- if ( ! $instance )
255
  $instance = new QueryMonitor( $file );
 
256
 
257
  return $instance;
258
 
2
  /*
3
  Plugin Name: Query Monitor
4
  Description: Monitoring of database queries, hooks, conditionals and more.
5
+ Version: 2.6.9
6
  Plugin URI: https://querymonitor.com/
7
  Author: John Blackbourn
8
  Author URI: https://johnblackbourn.com/
10
  Domain Path: /languages/
11
  License: GPL v2 or later
12
 
13
+ Copyright 2009-2015 John Blackbourn
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License as published by
26
 
27
  defined( 'ABSPATH' ) or die();
28
 
29
+ if ( defined( 'QM_DISABLED' ) and QM_DISABLED ) {
30
  return;
31
+ }
32
 
33
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
34
  $qm_dir = dirname( __FILE__ );
35
+ foreach ( array( 'Backtrace', 'Collector', 'Plugin', 'Util', 'Dispatcher', 'Output' ) as $qm_class ) {
36
  require_once "{$qm_dir}/{$qm_class}.php";
37
+ }
38
 
39
  class QueryMonitor extends QM_Plugin {
40
 
60
  parent::__construct( $file );
61
 
62
  # Collectors:
63
+ $collector_iterator = new DirectoryIterator( $this->plugin_path( 'collectors' ) );
64
+ foreach ( $collector_iterator as $collector ) {
65
+ if ( $collector->getExtension() === 'php' ) {
66
+ include $collector->getPathname();
67
+ }
68
+ }
69
 
70
+ foreach ( apply_filters( 'query_monitor_collectors', array() ) as $collector ) {
71
  $this->add_collector( $collector );
72
+ }
73
 
74
  }
75
 
76
  public function action_plugins_loaded() {
77
 
78
  # Dispatchers:
79
+ $dispatcher_iterator = new DirectoryIterator( $this->plugin_path( 'dispatchers' ) );
80
+ foreach ( $dispatcher_iterator as $dispatcher ) {
81
+ if ( $dispatcher->getExtension() === 'php' ) {
82
+ include $dispatcher->getPathname();
83
+ }
84
+ }
85
 
86
+ foreach ( apply_filters( 'query_monitor_dispatchers', array(), $this ) as $dispatcher ) {
87
  $this->add_dispatcher( $dispatcher );
88
+ }
89
 
90
  }
91
 
99
 
100
  public static function get_collector( $id ) {
101
  $qm = self::init();
102
+ if ( isset( $qm->collectors[$id] ) ) {
103
  return $qm->collectors[$id];
104
+ }
105
  return false;
106
  }
107
 
115
 
116
  public function activate( $sitewide = false ) {
117
 
118
+ if ( $admins = QM_Util::get_admins() ) {
119
  $admins->add_cap( 'view_query_monitor' );
120
+ }
121
 
122
+ if ( ! file_exists( $db = WP_CONTENT_DIR . '/db.php' ) and function_exists( 'symlink' ) ) {
123
  @symlink( $this->plugin_path( 'wp-content/db.php' ), $db );
124
+ }
125
 
126
+ if ( $sitewide ) {
127
  update_site_option( 'active_sitewide_plugins', get_site_option( 'active_sitewide_plugins' ) );
128
+ } else {
129
  update_option( 'active_plugins', get_option( 'active_plugins' ) );
130
+ }
131
 
132
  }
133
 
134
  public function deactivate() {
135
 
136
+ if ( $admins = QM_Util::get_admins() ) {
137
  $admins->remove_cap( 'view_query_monitor' );
138
+ }
139
 
140
  # Only delete db.php if it belongs to Query Monitor
141
+ if ( class_exists( 'QueryMonitorDB' ) ) {
142
  unlink( WP_CONTENT_DIR . '/db.php' );
143
+ }
144
 
145
  }
146
 
147
  public function user_can_view() {
148
 
149
+ if ( !did_action( 'plugins_loaded' ) ) {
150
  return false;
151
+ }
152
 
153
  if ( current_user_can( 'view_query_monitor' ) ) {
154
  return true;
155
  }
156
 
157
+ if ( $auth = self::get_collector( 'authentication' ) ) {
158
  return $auth->user_verified();
159
+ }
160
 
161
  return false;
162
 
207
  }
208
 
209
  foreach ( $this->get_collectors() as $collector ) {
210
+ $collector->tear_down();
211
  $collector->process();
212
  }
213
 
239
 
240
  }
241
 
242
+ public function filter_active_plugins( $plugins ) {
243
+
244
+ if ( empty( $plugins ) ) {
245
+ return $plugins;
246
+ }
247
 
248
  $f = preg_quote( basename( $this->plugin_base() ) );
249
 
254
 
255
  }
256
 
257
+ public function filter_active_sitewide_plugins( $plugins ) {
258
+
259
+ if ( empty( $plugins ) ) {
260
+ return $plugins;
261
+ }
262
 
263
  $f = $this->plugin_base();
264
 
276
 
277
  }
278
 
279
+ public static function symlink_warning() {
280
+ $db = WP_CONTENT_DIR . '/db.php';
281
+ trigger_error( sprintf( __( 'The symlink at <code>%s</code> is no longer pointing to the correct location. Please remove the symlink, then deactivate and reactivate Query Monitor.', 'query-monitor' ), $db ), E_USER_WARNING );
282
+ }
283
+
284
  public static function init( $file = null ) {
285
 
286
  static $instance = null;
287
 
288
+ if ( ! $instance ) {
289
  $instance = new QueryMonitor( $file );
290
+ }
291
 
292
  return $instance;
293
 
readme.txt CHANGED
@@ -3,16 +3,16 @@ Contributors: johnbillion
3
  Tags: debug, debugging, development, developer, performance, profiler, profiling, queries, query monitor
4
  Requires at least: 3.5
5
  Tested up to: 4.1
6
- Stable tag: 2.6.8
7
  License: GPLv2 or later
8
 
9
- View debugging and performance information on database queries, hooks, conditionals, HTTP requests, redirects and more.
10
 
11
  == Description ==
12
 
13
  Query Monitor is a debugging plugin for anyone developing with WordPress. It has some advanced features not available in other debugging plugins, including automatic AJAX debugging and the ability to narrow down things by plugin or theme.
14
 
15
- For complete information, please see [the Query Monitor home page](https://querymonitor.com/) or [Query Monitor's GitHub repo](https://github.com/johnbillion/QueryMonitor).
16
 
17
  Here's an overview of what's shown:
18
 
@@ -105,7 +105,7 @@ You can install this plugin directly from your WordPress dashboard:
105
  3. Click *Install Now* next to the Query Monitor plugin.
106
  4. Activate the plugin.
107
 
108
- Alternatively, see the guide to [Manually Installing Plugins](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation).
109
 
110
  == Screenshots ==
111
 
@@ -143,15 +143,27 @@ Please use [the issue tracker on Query Monitor's GitHub repo](https://github.com
143
 
144
  = Do you accept donations? =
145
 
146
- No, I do not accept donations. If you like the plugin, I'd love for you to [leave a review](http://wordpress.org/support/view/plugin-reviews/query-monitor). Tell all your friends about the plugin too!
147
 
148
  == Upgrade Notice ==
149
 
150
- = 2.6.8 =
151
- * Misc minor bugfixes. Nothing to get excited about.
152
 
153
  == Changelog ==
154
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  = 2.6.8 =
156
  * RTL layout tweaks
157
  * Correct the component detection logic so it's more accurate
3
  Tags: debug, debugging, development, developer, performance, profiler, profiling, queries, query monitor
4
  Requires at least: 3.5
5
  Tested up to: 4.1
6
+ Stable tag: 2.6.9
7
  License: GPLv2 or later
8
 
9
+ View debugging and performance information on database queries, hooks, conditionals, HTTP requests, redirects and more.
10
 
11
  == Description ==
12
 
13
  Query Monitor is a debugging plugin for anyone developing with WordPress. It has some advanced features not available in other debugging plugins, including automatic AJAX debugging and the ability to narrow down things by plugin or theme.
14
 
15
+ For complete information, please see [Query Monitor's GitHub repo](https://github.com/johnbillion/query-monitor).
16
 
17
  Here's an overview of what's shown:
18
 
105
  3. Click *Install Now* next to the Query Monitor plugin.
106
  4. Activate the plugin.
107
 
108
+ Alternatively, see the guide to [Manually Installing Plugins](https://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation).
109
 
110
  == Screenshots ==
111
 
143
 
144
  = Do you accept donations? =
145
 
146
+ No, I do not accept donations. If you like the plugin, I'd love for you to [leave a review](https://wordpress.org/support/view/plugin-reviews/query-monitor). Tell all your friends about the plugin too!
147
 
148
  == Upgrade Notice ==
149
 
150
+ = 2.6.9 =
151
+ * New Scripts & Styles component; Support the new admin menu behaviour in WP 4.1; Fix the positioning of output when using the Twenty Fifteen theme.
152
 
153
  == Changelog ==
154
 
155
+ = 2.6.9 =
156
+ * New Scripts & Styles component
157
+ * Support for the new `is_customize_preview()` conditional
158
+ * More robust handling of HTTP requests short-circuited with `pre_http_request`
159
+ * Introduce a `query_monitor_silent_http_error_codes` filter to allow certain `WP_Error` codes to be silenced in HTTP requests
160
+ * Split SQL queries on LEFT, OUTER, and RIGHT too
161
+ * Gracefully avoid fatal errors if a site is moved and the db.php symlink is no longer pointing to the correct location
162
+ * Pause Infinite Scroll when Query Monitor is viewed
163
+ * Support the new admin menu behaviour in WP 4.1
164
+ * Fix the positioning of output when using the Twenty Fifteen theme
165
+ * Switch to an AJAX call for setting and clearing QM's authentication cookie
166
+
167
  = 2.6.8 =
168
  * RTL layout tweaks
169
  * Correct the component detection logic so it's more accurate
wp-content/db.php CHANGED
@@ -9,7 +9,7 @@ additional database query information in Query Monitor's output.
9
 
10
  *********************************************************************
11
 
12
- Copyright 2014 John Blackbourn
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License as published by
@@ -25,19 +25,22 @@ GNU General Public License for more details.
25
 
26
  defined( 'ABSPATH' ) or die();
27
 
28
- if ( defined( 'QM_DISABLED' ) and QM_DISABLED )
29
  return;
 
30
 
31
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
32
  $qm_dir = dirname( dirname( __FILE__ ) );
33
  foreach ( array( 'Backtrace', 'Collector', 'Plugin', 'Util' ) as $qm_class ) {
34
- if ( ! is_readable( $qm_file = "{$qm_dir}/{$qm_class}.php" ) )
35
  return;
 
36
  require_once $qm_file;
37
  }
38
 
39
- if ( !defined( 'SAVEQUERIES' ) )
40
  define( 'SAVEQUERIES', true );
 
41
 
42
  class QueryMonitorDB extends wpdb {
43
 
@@ -55,8 +58,9 @@ class QueryMonitorDB extends wpdb {
55
  */
56
  function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
57
 
58
- foreach ( $this->qm_php_vars as $setting => &$val )
59
  $val = ini_get( $setting );
 
60
 
61
  parent::__construct( $dbuser, $dbpassword, $dbname, $dbhost );
62
 
@@ -71,26 +75,30 @@ class QueryMonitorDB extends wpdb {
71
  * @return int|false Number of rows affected/selected or false on error
72
  */
73
  function query( $query ) {
74
- if ( ! $this->ready )
75
  return false;
 
76
 
77
- if ( $this->show_errors )
78
  $this->hide_errors();
 
79
 
80
  $result = parent::query( $query );
81
 
82
- if ( ! SAVEQUERIES )
83
  return $result;
 
84
 
85
  $i = $this->num_queries - 1;
86
  $this->queries[$i]['trace'] = new QM_Backtrace( array(
87
  'ignore_items' => 1,
88
  ) );
89
 
90
- if ( $this->last_error )
91
  $this->queries[$i]['result'] = new WP_Error( 'qmdb', $this->last_error );
92
- else
93
  $this->queries[$i]['result'] = $result;
 
94
 
95
  return $result;
96
  }
9
 
10
  *********************************************************************
11
 
12
+ Copyright 2009-2015 John Blackbourn
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License as published by
25
 
26
  defined( 'ABSPATH' ) or die();
27
 
28
+ if ( defined( 'QM_DISABLED' ) and QM_DISABLED ) {
29
  return;
30
+ }
31
 
32
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
33
  $qm_dir = dirname( dirname( __FILE__ ) );
34
  foreach ( array( 'Backtrace', 'Collector', 'Plugin', 'Util' ) as $qm_class ) {
35
+ if ( ! is_readable( $qm_file = "{$qm_dir}/{$qm_class}.php" ) ) {
36
  return;
37
+ }
38
  require_once $qm_file;
39
  }
40
 
41
+ if ( !defined( 'SAVEQUERIES' ) ) {
42
  define( 'SAVEQUERIES', true );
43
+ }
44
 
45
  class QueryMonitorDB extends wpdb {
46
 
58
  */
59
  function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
60
 
61
+ foreach ( $this->qm_php_vars as $setting => &$val ) {
62
  $val = ini_get( $setting );
63
+ }
64
 
65
  parent::__construct( $dbuser, $dbpassword, $dbname, $dbhost );
66
 
75
  * @return int|false Number of rows affected/selected or false on error
76
  */
77
  function query( $query ) {
78
+ if ( ! $this->ready ) {
79
  return false;
80
+ }
81
 
82
+ if ( $this->show_errors ) {
83
  $this->hide_errors();
84
+ }
85
 
86
  $result = parent::query( $query );
87
 
88
+ if ( ! SAVEQUERIES ) {
89
  return $result;
90
+ }
91
 
92
  $i = $this->num_queries - 1;
93
  $this->queries[$i]['trace'] = new QM_Backtrace( array(
94
  'ignore_items' => 1,
95
  ) );
96
 
97
+ if ( $this->last_error ) {
98
  $this->queries[$i]['result'] = new WP_Error( 'qmdb', $this->last_error );
99
+ } else {
100
  $this->queries[$i]['result'] = $result;
101
+ }
102
 
103
  return $result;
104
  }