PluginProbe
WP Debugging / 2.11.13
WP Debugging v2.11.13
2.12.6 2.12.5 trunk 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.11.10 2.11.11 2.11.12 2.11.13 2.11.14 2.11.15 2.11.16 2.11.17 2.11.18 2.11.19 2.11.2 2.11.20 2.11.21 2.11.22 2.11.23 2.11.24 2.11.3 All 59 releases
wp-debugging / vendor / norcross / debug-quick-look / includes / handler.php

handler.php in WP Debugging 2.11.13, at vendor/norcross/debug-quick-look/includes/handler.php

261 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Our custom wp_die handler.
4 *
5 * @package DebugQuickLook
6 */
7
8 // Call our namepsace.
9 namespace DebugQuickLook\Handler;
10
11 // Set our alias items.
12 use DebugQuickLook as Core;
13 use DebugQuickLook\Helpers as Helpers;
14 use DebugQuickLook\Formatting as Formatting;
15
16 /**
17 * Output the custom wp_die display we built.
18 *
19 * @param mixed $message The data to display
20 * @param string $title Our file title.
21 * @param array $args Any additional args passed.
22 *
23 * @return void
24 */
25 function build_handler( $message, $title = '', $args = array() ) {
26
27 // Set an empty.
28 $build = '';
29
30 // Set the doctype.
31 $build .= '<!DOCTYPE html>';
32
33 // Set the opening HTML tag.
34 $build .= '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">';
35
36 // Output the head tag.
37 $build .= handler_head_tag( $title, $args );
38
39 // Output the body.
40 $build .= handler_body_tag( $message, $args );
41
42 // Close out the final HTML tag.
43 $build .= '</html>';
44
45 // Echo out the display.
46 echo $build;
47
48 // Then a regular die() to finish.
49 die();
50 }
51
52 /**
53 * Set up the <head> tag.
54 *
55 * @param string $title The title to output.
56 * @param array $args The optional args that were passed.
57 * @param boolean $echo Whether to echo or return.
58 *
59 * @return mixed
60 */
61 function handler_head_tag( $title = '', $args = array(), $echo = false ) {
62
63 // Determine the page title.
64 $title = ! empty( $title ) ? sanitize_text_field( $title ) : __( 'View Your File', 'debug-quick-look' );
65
66 // Set an empty.
67 $build = '';
68
69 // Set the opening head tag.
70 $build .= '<head>' . "\n";
71
72 // Include our action to run after we opened the head tag.
73 $build .= do_action( Core\HOOK_PREFIX . 'after_head_tag_open', $args );
74
75 // Include the basic meta tags.
76 $build .= '<meta charset="utf-8">' . "\n";
77 $build .= '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />' . "\n";
78 $build .= '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>' . "\n";
79
80 // Check the 'no robots', but output ourselves since the function only echos.
81 if ( function_exists( 'wp_no_robots' ) ) {
82 $build .= '<meta name="robots" content="noindex,follow" />' . "\n";
83 }
84
85 // Load our CSS.
86 $build .= load_handler_css();
87
88 // Output the title tag.
89 $build .= '<title>' . esc_html( $title ) . '</title>' . "\n";
90
91 // Include our action to run before we close the head tag.
92 $build .= do_action( Core\HOOK_PREFIX . 'before_head_tag_close', $args );
93
94 // Close out the head tag.
95 $build .= '</head>';
96
97 // Echo if requested.
98 if ( $echo ) {
99 echo $build;
100 }
101
102 // Just return the build.
103 return $build;
104 }
105
106 /**
107 * Set up the <body> tag.
108 *
109 * @param string $message The total message output.
110 * @param array $args The optional args that were passed.
111 * @param boolean $echo Whether to echo or return.
112 *
113 * @return mixed
114 */
115 function handler_body_tag( $message = '', $args = array(), $echo = false ) {
116
117 // Set an empty.
118 $build = '';
119
120 // Set the opening body tag.
121 $build .= '<body class="debug-quick-look">' . "\n";
122
123 // Include our action to run after we opened the body tag.
124 $build .= do_action( Core\HOOK_PREFIX . 'after_body_tag_open', $args );
125
126 // Set the intro
127 $build .= load_handler_intro( $args );
128
129 // Output the message.
130 $build .= load_handler_message( $message );
131
132 // Include our action to run before we close the body tag.
133 $build .= do_action( Core\HOOK_PREFIX . 'before_body_tag_close', $args );
134
135 // Close out the body tag.
136 $build .= '</body>';
137
138 // Echo if requested.
139 if ( $echo ) {
140 echo $build;
141 }
142
143 // Just return the build.
144 return $build;
145 }
146
147 /**
148 * Load our CSS to display.
149 *
150 * @return mixed
151 */
152 function load_handler_css() {
153
154 // Set my stylesheet URL.
155 $stylesheet = apply_filters( Core\HOOK_PREFIX . 'stylesheet', Core\ASSETS_URL . '/css/debug-quick-look.css' );
156
157 // If we haven't already run the admin_head function, output the file.
158 if ( ! did_action( 'admin_head' ) ) {
159
160 // Set my stylesheet URL.
161 $stylesheet = add_query_arg( array( 'ver' => time() ), $stylesheet );
162
163 // And just return
164 return '<link href="' . esc_url( $stylesheet ) . '" rel="stylesheet" type="text/css">' . "\n";
165 }
166
167 // Get my raw CSS.
168 $style = @file_get_contents( $stylesheet );
169
170 // Set it displayed via filter.
171 $display = apply_filters( Core\HOOK_PREFIX . 'raw_css', $style );
172
173 // Wrap it in a style tag and return it.
174 return ! $display ? false : '<style type="text/css">' . $display . '</style>' . "\n";
175 }
176
177 /**
178 * Load our introduction to display.
179 *
180 * @param array $args The optional args that were passed.
181 *
182 * @return mixed
183 */
184 function load_handler_intro( $args = array() ) {
185
186 // Bail if we said to skip the intro.
187 if ( ! empty( $args['skip-intro'] ) ) {
188 return;
189 }
190
191 // Set my purge URL.
192 $purge = Helpers\build_quicklook_url( 'purge' );
193
194 // Set the totals variable.
195 $ttlnum = ! empty( $args['totals'] ) ? $args['totals'] : 0;
196
197 // Set the totals display string.
198 $totals = sprintf( __( 'Total log entries: %s', 'debug-quick-look' ), '<strong>' . absint( $ttlnum ) . '</strong>' );
199
200 // Set an empty.
201 $build = '';
202
203 // Set the opening div.
204 $build .= '<div class="debug-quick-look-intro">' . "\n";
205
206 // Output the paragraph wrapper.
207 $build .= '<p>';
208
209 // Handle the return link output.
210 $build .= '<a class="debug-intro-link debug-intro-return-link" href="' . admin_url( '/' ) . '">&laquo; ' . esc_html__( 'Return To Admin Dashboard', 'debug-quick-look' ) . '</a>';
211
212 // Output the entry count.
213 $build .= '<span class="debug-quick-look-intro-count">' . $totals . '</span>';
214
215 // Handle the purge links output.
216 $build .= '<a class="debug-intro-link debug-intro-purge-link" href="' . esc_url( $purge ) . '">&times; ' . esc_html__( 'Purge File', 'debug-quick-look' ) . '</a>';
217
218 // Display log file path.
219 $build .= '<span class="debug-intro-error-file">' . Core\DEBUG_FILE . '</span>';
220
221 // Close the paragraph
222 $build .= '</p>' . "\n";
223
224 // Include our action to run inside the div.
225 $build .= do_action( Core\HOOK_PREFIX . 'inside_intro_block', $args );
226
227 // Close out the div tag.
228 $build .= '</div>' . "\n";
229
230 // Include our action to run after the div.
231 $build .= do_action( Core\HOOK_PREFIX . 'after_intro_block', $args );
232
233 // Just return the build.
234 return $build;
235 }
236
237 /**
238 * Load our message to display.
239 *
240 * @param string $message The total message output.
241 *
242 * @return mixed
243 */
244 function load_handler_message( $message ) {
245
246 // Set an empty.
247 $build = '';
248
249 // Set the opening div.
250 $build .= '<div class="debug-quick-look-block-list">' . "\n";
251
252 // Output the actual link.
253 $build .= $message . "\n";
254
255 // Close out the div tag.
256 $build .= '</div>' . "\n";
257
258 // Just return the build.
259 return $build;
260 }
261