PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.7.7
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.7.7
1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 All 40 releases
code-profiler / lib / menu_log.php

menu_log.php in Code Profiler – WordPress Performance Profiling and Debugging Made Easy 1.7.7, at lib/menu_log.php

169 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +=====================================================================+
4 | ____ _ ____ __ _ _ |
5 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 | |
10 | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
11 +=====================================================================+
12 */
13
14 if (! defined('ABSPATH') ) {
15 die('Forbidden');
16 }
17
18 // =====================================================================
19 // Display the profiler's log.
20
21 // Delete the log?
22 if (! empty( $_POST['cp-delete-log'] ) ) {
23 if ( empty( $_POST['cp_nonce'] ) || ! wp_verify_nonce( $_POST['cp_nonce'], 'cp_delete_log') ) {
24 printf(
25 CODE_PROFILER_ERROR_NOTICE,
26 esc_html__('Security nonce is missing, try to reload the page.', 'code-profiler')
27 );
28
29 } else {
30 $res = file_put_contents( CODE_PROFILER_LOG, "<?php exit; ?>\n");
31 if ( $res !== false ) {
32 printf(
33 CODE_PROFILER_UPDATE_NOTICE,
34 esc_html__('The log was deleted.', 'code-profiler')
35 );
36 } else {
37 printf(
38 CODE_PROFILER_ERROR_NOTICE,
39 esc_html__('Cannot delete the log, make sure it is writable.', 'code-profiler')
40 );
41 }
42 }
43 }
44 ?>
45 <script>
46 'use strict';
47 var cplog_array = new Array();
48 <?php
49 $info = 0; $warn = 0; $error = 0; $debug = 0; $logline = '';
50 if ( file_exists( CODE_PROFILER_LOG ) ) {
51
52 $lines = array();
53 $lines = file( CODE_PROFILER_LOG, FILE_SKIP_EMPTY_LINES );
54 $i = 0;
55 $facility = array( 1 => 'INFO ', 2 => 'WARN ', 4 => 'ERROR', 8 => 'DEBUG');
56 foreach( $lines as $line ) {
57 if ( $line[0] == '<') { continue; }
58 list( $date, $level, $string ) = explode('~~', $line, 3 );
59 if (! isset( $facility[$level] ) ) {
60 continue;
61 }
62 $date = date('d-M-y H:i:s', $date );
63 echo 'cplog_array[' . $i . '] = "' .
64 rawurlencode( "$level~~$date {$facility[$level]} $string" ) ."\";\n";
65 ++$i;
66 if ( $level == 1 ) {
67 $info = 1;
68 } elseif ( $level == 2 ) {
69 $warn = 1;
70 } elseif ( $level == 4 ) {
71 $error = 1;
72 } elseif ( $level == 8 ) {
73 $debug = 1;
74 continue;
75 }
76 $logline .= "$date {$facility[$level]} $string";
77 }
78 }
79 ?>
80 </script>
81 <?php
82
83 if ( defined('CODE_PROFILER_TEXTAREA_HEIGHT') ) {
84 $th = (int) CODE_PROFILER_TEXTAREA_HEIGHT;
85 } else {
86 $th = '450';
87 }
88
89 echo code_profiler_display_tabs( 4 );
90 ?>
91 <h3><?php esc_html_e('Code Profiler log', 'code-profiler'); ?></h3>
92 <form name="cplogform" method="post">
93 <table class="form-table">
94 <tr>
95 <td width="100%">
96 <textarea dir="auto" name="cptxtlog" class="large-text code" style="height:<?php echo (int)$th; ?>px;" wrap="off" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"><?php
97 if (! empty( $logline ) ) {
98 echo esc_textarea( $logline );
99 $disabled = '';
100 } else {
101 echo "\n\n > " . esc_html__("Code Profiler's log is empty.", 'code-profiler');
102 $disabled = ' disabled';
103 }
104 if (! $error ) {
105 $error_checked = '';
106 } else {
107 $error_checked = ' checked';
108 }
109 if (! $warn ) {
110 $warn_checked = '';
111 } else {
112 $warn_checked = ' checked';
113 }
114 ?></textarea>
115 <p style="text-align:center">
116 <label for="cxinfo">
117 <input id="cxinfo" type="checkbox" name="info" checked="checked"<?php disabled( $info, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> />
118 <span style="display: inline-block"><?php esc_html_e('Info', 'code-profiler') ?></span>&nbsp;
119 </label>
120 &nbsp;&nbsp;&nbsp;&nbsp;
121 <label for="cxwarn">
122 <input id="cxwarn" type="checkbox" name="warn"<?php echo $warn_checked ?><?php disabled( $warn, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> />
123 <span style="display: inline-block"><?php esc_html_e('Warning', 'code-profiler') ?></span>&nbsp;
124 </label>
125 &nbsp;&nbsp;&nbsp;&nbsp;
126 <label for="cxerror">
127 <input id="cxerror" type="checkbox" name="error"<?php echo $error_checked ?><?php disabled( $error, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> />
128 <span style="display: inline-block"><?php esc_html_e('Error', 'code-profiler') ?></span>&nbsp;
129 </label>
130 &nbsp;&nbsp;&nbsp;&nbsp;
131 <label for="cxdebug">
132 <input id="cxdebug" type="checkbox" name="debug"<?php disabled( $debug, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> />
133 <span style="display: inline-block"><?php esc_html_e('Debug', 'code-profiler') ?></span>&nbsp;
134 </label>
135 </p>
136 <input type="submit" onclick="return cpjs_delete_log();" name="cp-delete-log" class="button button-primary" value="<?php esc_attr_e('Delete log', 'code-profiler') ?>"<?php disabled( $logline, '') ?> />
137 <?php wp_nonce_field('cp_delete_log', 'cp_nonce', 0); ?>
138 <p class="description"><?php esc_html_e('The log is deleted automatically when it reaches 100KB.', 'code-profiler') ?></p>
139 </td>
140 </tr>
141 </table>
142 </form>
143
144 <h3><?php esc_html_e('HTTP response log', 'code-profiler'); ?></h3>
145 <table class="form-table">
146 <tr>
147 <td width="100%">
148 <textarea dir="auto" name="cptxtlog" class="large-text code" style="height:<?php echo $th; ?>px;" wrap="off" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"><?php
149
150 /**
151 * Search for an eventual "last_request.1727412303.5681.log" file.
152 */
153 $file = code_profiler_glob( CODE_PROFILER_UPLOAD_DIR, '^last_request\.\d+?\.\d+?\.log$', true );
154 if ( empty( $file[0] ) ) {
155 echo "\n\n > " . esc_html__('The HTTP response log is empty.', 'code-profiler');
156 } else {
157 $log = file_get_contents( $file[0] );
158 echo esc_textarea( $log );
159 }
160 ?></textarea>
161 <p class="description"><?php esc_html_e('The log shows the HTTP request and its payload, the response headers and body for the last profile.', 'code-profiler') ?></p>
162 </td>
163 </tr>
164 </table>
165 <?php
166
167 // =====================================================================
168 // EOF
169