| 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 |
require __DIR__.'/class-logs.php'; |
| 22 |
|
| 23 |
// Delete the log? |
| 24 |
if (! empty( $_POST['cp-delete-log'] ) ) { |
| 25 |
if ( empty( $_POST['cp_nonce'] ) || ! wp_verify_nonce( $_POST['cp_nonce'], 'cp_delete_log') ) { |
| 26 |
printf( |
| 27 |
CODE_PROFILER_ERROR_NOTICE, |
| 28 |
esc_html__('Security nonce is missing, try to reload the page.', 'code-profiler') |
| 29 |
); |
| 30 |
|
| 31 |
} else { |
| 32 |
$res = file_put_contents( CODE_PROFILER_LOG, "<?php exit; ?>\n"); |
| 33 |
if ( $res !== false ) { |
| 34 |
printf( |
| 35 |
CODE_PROFILER_UPDATE_NOTICE, |
| 36 |
esc_html__('The log was deleted.', 'code-profiler') |
| 37 |
); |
| 38 |
} else { |
| 39 |
printf( |
| 40 |
CODE_PROFILER_ERROR_NOTICE, |
| 41 |
esc_html__('Cannot delete the log, make sure it is writable.', 'code-profiler') |
| 42 |
); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
?> |
| 47 |
<script> |
| 48 |
'use strict'; |
| 49 |
var cplog_array = new Array(); |
| 50 |
<?php |
| 51 |
$info = 0; $warn = 0; $error = 0; $debug = 0; $logline = ''; |
| 52 |
if ( file_exists( CODE_PROFILER_LOG ) ) { |
| 53 |
|
| 54 |
$lines = array(); |
| 55 |
$lines = file( CODE_PROFILER_LOG, FILE_SKIP_EMPTY_LINES ); |
| 56 |
$i = 0; |
| 57 |
$facility = array( 1 => 'INFO ', 2 => 'WARN ', 4 => 'ERROR', 8 => 'DEBUG'); |
| 58 |
foreach( $lines as $line ) { |
| 59 |
if ( $line[0] == '<') { continue; } |
| 60 |
list( $date, $level, $string ) = explode('~~', $line, 3 ); |
| 61 |
if (! isset( $facility[$level] ) ) { |
| 62 |
continue; |
| 63 |
} |
| 64 |
$date = date('d-M-y H:i:s', $date ); |
| 65 |
echo 'cplog_array[' . $i . '] = "' . |
| 66 |
rawurlencode( "$level~~$date {$facility[$level]} $string" ) ."\";\n"; |
| 67 |
++$i; |
| 68 |
if ( $level == 1 ) { |
| 69 |
$info = 1; |
| 70 |
} elseif ( $level == 2 ) { |
| 71 |
$warn = 1; |
| 72 |
} elseif ( $level == 4 ) { |
| 73 |
$error = 1; |
| 74 |
} elseif ( $level == 8 ) { |
| 75 |
$debug = 1; |
| 76 |
continue; |
| 77 |
} |
| 78 |
$logline .= "$date {$facility[$level]} $string"; |
| 79 |
} |
| 80 |
} |
| 81 |
?> |
| 82 |
</script> |
| 83 |
<?php |
| 84 |
|
| 85 |
if ( defined('CODE_PROFILER_TEXTAREA_HEIGHT') ) { |
| 86 |
$th = (int) CODE_PROFILER_TEXTAREA_HEIGHT; |
| 87 |
} else { |
| 88 |
$th = '450'; |
| 89 |
} |
| 90 |
|
| 91 |
echo code_profiler_display_tabs( 4 ); |
| 92 |
?> |
| 93 |
<h3><?php esc_html_e('Code Profiler log', 'code-profiler'); ?></h3> |
| 94 |
<form name="cplogform" method="post"> |
| 95 |
<table class="form-table"> |
| 96 |
<tr> |
| 97 |
<td width="100%"> |
| 98 |
<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 |
| 99 |
if (! empty( $logline ) ) { |
| 100 |
echo esc_textarea( $logline ); |
| 101 |
$disabled = ''; |
| 102 |
} else { |
| 103 |
echo "\n\n > " . esc_html__("Code Profiler's log is empty.", 'code-profiler'); |
| 104 |
$disabled = ' disabled'; |
| 105 |
} |
| 106 |
if (! $error ) { |
| 107 |
$error_checked = ''; |
| 108 |
} else { |
| 109 |
$error_checked = ' checked'; |
| 110 |
} |
| 111 |
if (! $warn ) { |
| 112 |
$warn_checked = ''; |
| 113 |
} else { |
| 114 |
$warn_checked = ' checked'; |
| 115 |
} |
| 116 |
?></textarea> |
| 117 |
<p style="text-align:center"> |
| 118 |
<label for="cxinfo"> |
| 119 |
<input id="cxinfo" type="checkbox" name="info" checked="checked"<?php disabled( $info, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> /> |
| 120 |
<span style="display: inline-block"><?php esc_html_e('Info', 'code-profiler') ?></span> |
| 121 |
</label> |
| 122 |
|
| 123 |
<label for="cxwarn"> |
| 124 |
<input id="cxwarn" type="checkbox" name="warn"<?php echo $warn_checked ?><?php disabled( $warn, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> /> |
| 125 |
<span style="display: inline-block"><?php esc_html_e('Warning', 'code-profiler') ?></span> |
| 126 |
</label> |
| 127 |
|
| 128 |
<label for="cxerror"> |
| 129 |
<input id="cxerror" type="checkbox" name="error"<?php echo $error_checked ?><?php disabled( $error, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> /> |
| 130 |
<span style="display: inline-block"><?php esc_html_e('Error', 'code-profiler') ?></span> |
| 131 |
</label> |
| 132 |
|
| 133 |
<label for="cxdebug"> |
| 134 |
<input id="cxdebug" type="checkbox" name="debug"<?php disabled( $debug, 0 ) ?> onClick="cpjs_filter_log();"<?php echo $disabled ?> /> |
| 135 |
<span style="display: inline-block"><?php esc_html_e('Debug', 'code-profiler') ?></span> |
| 136 |
</label> |
| 137 |
</p> |
| 138 |
<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, '') ?> /> |
| 139 |
<?php wp_nonce_field('cp_delete_log', 'cp_nonce', 0); ?> |
| 140 |
<p class="description"><?php esc_html_e('The log is deleted automatically when it reaches 100KB.', 'code-profiler') ?></p> |
| 141 |
</td> |
| 142 |
</tr> |
| 143 |
</table> |
| 144 |
</form> |
| 145 |
|
| 146 |
<h3><?php esc_html_e('HTTP response log', 'code-profiler'); ?></h3> |
| 147 |
<table class="form-table"> |
| 148 |
<tr> |
| 149 |
<td width="100%"> |
| 150 |
<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 |
| 151 |
/** |
| 152 |
* Display the last HTTP response log. |
| 153 |
*/ |
| 154 |
$log = CodeProfiler_Logs::get_HTTP_log(); |
| 155 |
if ( $log === false ) { |
| 156 |
echo "\n\n > " . esc_html__('The HTTP response log is empty.', 'code-profiler'); |
| 157 |
} else { |
| 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 |
|