/var/www/html_de/wp-content/plugins/query-monitor/classes/Collector.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php declare(strict_types 1);
/**
 * Abstract data collector.
 *
 * @package query-monitor
 */

if ( ! class_exists'QM_Collector' ) ) {
abstract class 
QM_Collector {

    
/**
     * @var QM_Timer|null
     */
    
protected $timer;

    
/**
     * @var QM_Data
     */
    
protected $data;

    
/**
     * @var bool|null
     */
    
protected static $hide_qm null;

    
/**
     * @var array<string, array<string, mixed>>
     */
    
public $concerned_actions = array();

    
/**
     * @var array<string, array<string, mixed>>
     */
    
public $concerned_filters = array();

    
/**
     * @var array<string, array<string, mixed>>
     */
    
public $concerned_constants = array();

    
/**
     * @var array<int, string>
     */
    
public $tracked_hooks = array();

    
/**
     * @var string
     */
    
public $id '';

    public function 
__construct() {
        
$this->data $this->get_storage();
    }

    
/**
     * @return void
     */
    
public function set_up() {}

    
/**
     * @return string
     */
    
final public function id() {
        return 
"qm-{$this->id}";
    }

    
/**
     * @param string $type
     * @return void
     */
    
protected function log_type$type ) {
        if ( isset( 
$this->data->types$type ] ) ) {
            
$this->data->types$type ]++;
        } else {
            
$this->data->types$type ] = 1;
        }
    }

    
/**
     * @param QM_Component $component
     * @param float $ltime
     * @param string|int $type
     * @return void
     */
    
protected function log_component$component$ltime$type ) {
        if ( ! isset( 
$this->data->component_times$component->name ] ) ) {
            
$this->data->component_times$component->name ] = array(
                
'component' => $component->name,
                
'ltime' => 0,
                
'types' => array(),
            );
        }

        
$this->data->component_times$component->name ]['ltime'] += $ltime;

        if ( isset( 
$this->data->component_times$component->name ]['types'][ $type ] ) ) {
            
$this->data->component_times$component->name ]['types'][ $type ]++;
        } else {
            
$this->data->component_times$component->name ]['types'][ $type ] = 1;
        }

    }

    
/**
     * @return float
     */
    
public static function timer_stop_float() {
        return 
microtimetrue ) - $_SERVER['REQUEST_TIME_FLOAT'];
    }

    
/**
     * @param string $constant
     * @return string
     */
    
public static function format_bool_constant$constant ) {
        
// @TODO this should be in QM_Util

        
if ( ! defined$constant ) ) {
            
/* translators: Undefined PHP constant */
            
return __'undefined''query-monitor' );
        } elseif ( 
constant$constant ) === '' ) {
            return 
__'empty string''query-monitor' );
        } elseif ( 
is_stringconstant$constant ) ) && ! is_numericconstant$constant ) ) ) {
            return 
constant$constant );
        } elseif ( ! 
constant$constant ) ) {
            return 
'false';
        } else {
            return 
'true';
        }
    }

    
/**
     * @return QM_Data
     */
    
public function get_data() {
        return 
$this->data;
    }

    
/**
     * @return QM_Data
     */
    
public function get_storage(): QM_Data {
        return new 
QM_Data_Fallback();
    }

    
/**
     * @return void
     */
    
final public function discard_data() {
        
$this->data $this->get_storage();
    }

    
/**
     * @param string $id
     * @return void
     */
    
final public function set_id$id ) {
        
$this->id $id;
    }

    
/**
     * @return void
     */
    
final public function process_concerns() {
        global 
$wp_filter;

        
$tracked = array();
        
$id $this->id;

        
/**
         * Filters the concerned actions for the given panel.
         *
         * The dynamic portion of the hook name, `$id`, refers to the collector ID, which is typically the `$id`
         * property of the collector class.
         *
         * @since 3.3.0
         *
         * @param array<int, string> $actions Array of action names that this panel concerns itself with.
         */
        
$concerned_actions apply_filters"qm/collect/concerned_actions/{$id}"$this->get_concerned_actions() );

        
/**
         * Filters the concerned filters for the given panel.
         *
         * The dynamic portion of the hook name, `$id`, refers to the collector ID, which is typically the `$id`
         * property of the collector class.
         *
         * @since 3.3.0
         *
         * @param array<int, string> $filters Array of filter names that this panel concerns itself with.
         */
        
$concerned_filters apply_filters"qm/collect/concerned_filters/{$id}"$this->get_concerned_filters() );

        
/**
         * Filters the concerned options for the given panel.
         *
         * The dynamic portion of the hook name, `$id`, refers to the collector ID, which is typically the `$id`
         * property of the collector class.
         *
         * @since 3.3.0
         *
         * @param array<int, string> $options Array of option names that this panel concerns itself with.
         */
        
$concerned_options apply_filters"qm/collect/concerned_options/{$id}"$this->get_concerned_options() );

        
/**
         * Filters the concerned constants for the given panel.
         *
         * The dynamic portion of the hook name, `$id`, refers to the collector ID, which is typically the `$id`
         * property of the collector class.
         *
         * @since 3.3.0
         *
         * @param array<int, string> $constants Array of constant names that this panel concerns itself with.
         */
        
$concerned_constants apply_filters"qm/collect/concerned_constants/{$id}"$this->get_concerned_constants() );

        foreach ( 
$concerned_actions as $action ) {
            if ( 
has_action$action ) ) {
                
$this->concerned_actions$action ] = QM_Hook::process$action'action'$wp_filtertruefalse );
            }
            
$tracked[] = $action;
        }

        foreach ( 
$concerned_filters as $filter ) {
            if ( 
has_filter$filter ) ) {
                
$this->concerned_filters$filter ] = QM_Hook::process$filter'filter'$wp_filtertruefalse );
            }
            
$tracked[] = $filter;
        }

        
$option_filters = array(
            
// Should this include the pre_delete_ and pre_update_ filters too?
            
'pre_option_%s',
            
'default_option_%s',
            
'option_%s',
            
'pre_site_option_%s',
            
'default_site_option_%s',
            
'site_option_%s',
        );

        foreach ( 
$concerned_options as $option ) {
            foreach ( 
$option_filters as $option_filter ) {
                
$filter sprintf(
                    
$option_filter,
                    
$option
                
);
                if ( 
has_filter$filter ) ) {
                    
$this->concerned_filters$filter ] = QM_Hook::process$filter'filter'$wp_filtertruefalse );
                }
                
$tracked[] = $filter;
            }
        }

        
$this->concerned_actions array_filter$this->concerned_actions, array( $this'filter_concerns' ) );
        
$this->concerned_filters array_filter$this->concerned_filters, array( $this'filter_concerns' ) );

        foreach ( 
$concerned_constants as $constant ) {
            if ( 
defined$constant ) ) {
                
$this->concerned_constants$constant ] = constant$constant );
            }
        }

        
sort$tracked );

        
$this->tracked_hooks $tracked;
    }

    
/**
     * @param array<string, mixed> $concerns
     * @return bool
     */
    
public function filter_concerns$concerns ) {
        return ! empty( 
$concerns['actions'] );
    }

    
/**
     * @param WP_User $user_object
     * @return array<string, mixed>
     */
    
public static function format_userWP_User $user_object ) {
        
$user get_object_vars$user_object->data );
        unset(
            
$user['user_pass'],
            
$user['user_activation_key']
        );
        
$user['roles'] = $user_object->roles;

        return 
$user;
    }

    
/**
     * @return bool
     */
    
public static function enabled() {
        return 
true;
    }

    
/**
     * @return bool
     */
    
public static function hide_qm() {
        if ( ! 
defined'QM_HIDE_SELF' ) ) {
            return 
false;
        }

        if ( 
null === self::$hide_qm ) {
            
self::$hide_qm QM_HIDE_SELF;
        }

        return 
self::$hide_qm;
    }

    
/**
     * @param array<string, mixed> $item
     * @phpstan-param array{
     *   component: QM_Component,
     * } $item
     * @return bool
     */
    
public function filter_remove_qm( array $item ) {
        return ( 
'query-monitor' !== $item['component']->context );
    }

    
/**
     * @param mixed[] $items
     * @return bool
     */
    
public function filter_dupe_items$items ) {
        return ( 
count$items ) > );
    }

    
/**
     * @return void
     */
    
public function process() {}

    
/**
     * @return void
     */
    
public function post_process() {}

    
/**
     * @return void
     */
    
public function tear_down() {}

    
/**
     * @return QM_Timer|null
     */
    
public function get_timer() {
        return 
$this->timer;
    }

    
/**
     * @param QM_Timer $timer
     * @return void
     */
    
public function set_timerQM_Timer $timer ) {
        
$this->timer $timer;
    }

    
/**
     * @return array<int, string>
     */
    
public function get_concerned_actions() {
        return array();
    }

    
/**
     * @return array<int, string>
     */
    
public function get_concerned_filters() {
        return array();
    }

    
/**
     * @return array<int, string>
     */
    
public function get_concerned_options() {
        return array();
    }

    
/**
     * @return array<int, string>
     */
    
public function get_concerned_constants() {
        return array();
    }
}
}