/var/www/html_de/wp-content/plugins/query-monitor/output/html/db_callers.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
<?php declare(strict_types 1);
/**
 * Database query calling function output for HTML pages.
 *
 * @package query-monitor
 */

if ( ! defined'ABSPATH' ) ) {
    exit;
}

class 
QM_Output_Html_DB_Callers extends QM_Output_Html {

    
/**
     * Collector instance.
     *
     * @var QM_Collector_DB_Callers Collector.
     */
    
protected $collector;

    public function 
__constructQM_Collector $collector ) {
        
parent::__construct$collector );
        
add_filter'qm/output/panel_menus', array( $this'panel_menu' ), 30 );
    }

    
/**
     * @return string
     */
    
public function name() {
        return 
__'Queries by Caller''query-monitor' );
    }

    
/**
     * @return void
     */
    
public function output() {
        
/** @var QM_Data_DB_Callers $data */
        
$data $this->collector->get_data();

        if ( empty( 
$data->types ) ) {
            return;
        }

        
$total_time 0;

        if ( ! empty( 
$data->times ) ) {
            
$this->before_tabular_output();

            echo 
'<thead>';
            echo 
'<tr>';
            echo 
'<th scope="col">' esc_html__'Caller''query-monitor' ) . '</th>';

            foreach ( 
array_keys$data->types ) as $type_name ) {
                echo 
'<th scope="col" class="qm-num qm-ltr qm-sortable-column" role="columnheader">';
                echo 
$this->build_sorter$type_name ); // WPCS: XSS ok;
                
echo '</th>';
            }

            echo 
'<th scope="col" class="qm-num qm-sorted-desc qm-sortable-column" role="columnheader" aria-sort="descending">';
            echo 
$this->build_sorter__'Time''query-monitor' ) ); // WPCS: XSS ok;
            
echo '</th>';
            echo 
'</tr>';
            echo 
'</thead>';

            echo 
'<tbody>';

            foreach ( 
$data->times as $row ) {
                
$total_time += $row['ltime'];
                
$stime number_format_i18n$row['ltime'], );

                echo 
'<tr>';
                echo 
'<td class="qm-ltr">';
                echo 
self::build_filter_trigger'db_queries''caller'$row['caller'], '<code>' esc_html$row['caller'] ) . '</code>' ); // WPCS: XSS ok;
                
echo '</td>';

                foreach ( 
array_keys$data->types ) as $type_name ) {
                    if ( isset( 
$row['types'][ $type_name ] ) ) {
                        echo 
"<td class='qm-num'>" esc_htmlnumber_format_i18n$row['types'][ $type_name ] ) ) . '</td>';
                    } else {
                        echo 
"<td class='qm-num'></td>";
                    }
                }

                echo 
'<td class="qm-num" data-qm-sort-weight="' esc_attr( (string) $row['ltime'] ) . '">' esc_html$stime ) . '</td>';
                echo 
'</tr>';

            }

            echo 
'</tbody>';
            echo 
'<tfoot>';

            
$total_stime number_format_i18n$total_time);

            echo 
'<tr>';
            echo 
'<td></td>';

            foreach ( 
$data->types as $type_name => $type_count ) {
                echo 
'<td class="qm-num">' esc_htmlnumber_format_i18n$type_count ) ) . '</td>';
            }

            echo 
'<td class="qm-num">' esc_html$total_stime ) . '</td>';
            echo 
'</tr>';

            echo 
'</tfoot>';

            
$this->after_tabular_output();
        } else {
            
$this->before_non_tabular_output();

            echo 
'<div class="qm-none">';
            echo 
'<p>' esc_html__'None''query-monitor' ) . '</p>';
            echo 
'</div>';

            
$this->after_non_tabular_output();
        }
    }

    
/**
     * @param array<string, mixed[]> $menu
     * @return array<string, mixed[]>
     */
    
public function panel_menu( array $menu ) {
        
/** @var QM_Collector_DB_Queries|null $dbq */
        
$dbq QM_Collectors::get'db_queries' );

        if ( 
$dbq ) {
            
/** @var QM_Data_DB_Queries $dbq_data */
            
$dbq_data $dbq->get_data();
            if ( ! empty( 
$dbq_data->times ) ) {
                
$menu['qm-db_queries']['children'][] = $this->menu( array(
                    
'title' => esc_html__'Queries by Caller''query-monitor' ),
                ) );
            }
        }
        return 
$menu;

    }

}

/**
 * @param array<string, QM_Output> $output
 * @param QM_Collectors $collectors
 * @return array<string, QM_Output>
 */
function register_qm_output_html_db_callers( array $outputQM_Collectors $collectors ) {
    
$collector QM_Collectors::get'db_callers' );
    if ( 
$collector ) {
        
$output['db_callers'] = new QM_Output_Html_DB_Callers$collector );
    }
    return 
$output;
}

add_filter'qm/outputter/html''register_qm_output_html_db_callers'30);