C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\amp\src\DevTools\ErrorPage.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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php
/**
 * Class ErrorPage.
 *
 * @package AmpProject\AmpWP
 */

namespace AmpProject\AmpWP\DevTools;

use 
AmpProject\AmpWP\Infrastructure\Service;
use 
Exception;

/**
 * Produces an error page similar to wp_die().
 *
 * The actual wp_die() function cannot be used within the AMP response
 * preparation code, as its 'exit' argument is only usable from WP 5.1 onwards.
 *
 * @see wp_die()
 * @package AmpProject\AmpWP
 * @since   2.0.1
 * @internal
 */
final class ErrorPage implements Service {

    
/**
     * Title of the error page.
     *
     * @var string
     */
    
private $title '';

    
/**
     * Message of the error page.
     *
     * @var string
     */
    
private $message '';

    
/**
     * Back link URL.
     *
     * @var string
     */
    
private $link_url '';

    
/**
     * Back link text.
     *
     * @var string
     */
    
private $link_text '';

    
/**
     * Exception of the error page.
     *
     * @var Exception
     */
    
private $exception;

    
/**
     * Response code of the error page.
     *
     * @var int
     */
    
private $response_code 500;

    
/**
     * Culprit detection to use.
     *
     * @var LikelyCulpritDetector
     */
    
private $likely_culprit_detector;

    
/**
     * ErrorPage constructor.
     *
     * @param LikelyCulpritDetector $likely_culprit_detector Culprit detection
     *                                                       to use.
     */
    
public function __constructLikelyCulpritDetector $likely_culprit_detector ) {
        
$this->likely_culprit_detector $likely_culprit_detector;
    }

    
/**
     * Set the title of the error page.
     *
     * @param string $title Title to use.
     * @return self
     */
    
public function with_title$title ) {
        
$this->title $title;
        return 
$this;
    }

    
/**
     * Set the message of the error page.
     *
     * @param string $message Message to use.
     * @return self
     */
    
public function with_message$message ) {
        
$this->message $message;
        return 
$this;
    }

    
/**
     * Set the message of the error page.
     *
     * @param string $link_url  Link URL.
     * @param string $link_text Link text.
     * @return self
     */
    
public function with_back_link$link_url$link_text ) {
        
$this->link_url  $link_url;
        
$this->link_text $link_text;
        return 
$this;
    }

    
/**
     * Set the exception of the error page.
     *
     * @param Exception $exception Exception to use.
     * @return self
     */
    
public function with_exceptionException $exception ) {
        
$this->exception $exception;
        return 
$this;
    }

    
/**
     * Set the response_code of the error page.
     *
     * @param int $response_code Response code to use.
     * @return self
     */
    
public function with_response_code$response_code ) {
        
$this->response_code $response_code;
        return 
$this;
    }

    
/**
     * Render the error page.
     *
     * This first sets the required headers and then returns the HTML to send as
     * output.
     *
     * @return string
     */
    
public function render() {
        
$this->send_to_error_log();

        
$this->set_headers();

        
$text_direction function_exists'is_rtl' ) && is_rtl()
            ? 
'rtl'
            
'ltr';

        
$styles $this->get_styles$text_direction );
        
$html   $this->get_html$styles$text_direction );

        return 
$html;
    }

    
/**
     * Send the exception that was caught to the error log.
     */
    
private function send_to_error_log() {
        
// Don't send to error log if fatal errors are not to be reported.
        
$error_level error_reporting(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting,WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
        
if ( ! (bool) ( $error_level E_ERROR ) ) {
            return;
        }

        
error_log// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
            
sprintf(
                
"%s - %s (%s) [%s]\n%s",
                
$this->message,
                
$this->exception->getMessage(),
                
$this->exception->getCode(),
                
get_class$this->exception ),
                
$this->exception->getTraceAsString()
            )
        );
    }

    
/**
     * Sets the required headers.
     *
     * This will only adapt the headers if they haven't yet been sent.
     */
    
private function set_headers() {
        if ( ! 
headers_sent() ) {
            
// Define the content type for the error page.
            
header'Content-Type: text/html; charset=utf-8' );

            
// Mark the page as a server failure so it won't get indexed.
            
status_header$this->response_code );

            
// Let the browser know this result shouldn't get cached.
            
nocache_headers();
        }
    }

    
/**
     * Get the HTML output for the error page.
     *
     * @param string $styles         CSS styles to use.
     * @param string $text_direction Text direction. Can be 'ltr' or 'rtl'.
     * @return string HTML output.
     */
    
private function get_html$styles$text_direction ) {
        
$no_robots get_option'blog_public' )
            ? 
"<meta name='robots' content='noindex,follow' />\n"
            
"<meta name='robots' content='noindex,nofollow' />\n";

        return <<<HTML
<!DOCTYPE html>
<html dir="
{$text_direction}">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width">
        
{$no_robots}
        <title>
{$this->render_title()}</title>
        
{$styles}
    </head>
    <body id="error-page">
        <h1>
{$this->render_title()}</h1>
        <p>
{$this->render_message()}</p>
        
{$this->render_source()}
        
{$this->render_exception()}
        
{$this->render_back_link()}
    </body>
</html>
HTML;
    }

    
/**
     * Render title.
     *
     * @return string HTML-escaped title.
     */
    
private function render_title() {
        return 
esc_html$this->title );
    }

    
/**
     * Render message.
     *
     * @return string KSES-sanitized message.
     */
    
private function render_message() {
        return 
wp_kses_post$this->message );
    }

    
/**
     * Render the source of the exception file.
     *
     * @return string File source data.
     */
    
private function render_source() {
        
$source $this->likely_culprit_detector->analyze_exception$this->exception );

        if ( ! empty( 
$source['type'] ) && ! empty( $source['name'] ) ) {
            
$name_markup "<strong><code>{$source['name']}</code></strong>";

            switch ( 
$source['type'] ) {
                case 
'plugin':
                    
/* translators: placeholder is the slug of the plugin */
                    
$message sprintf__'It appears the plugin with slug %s is responsible; please contact the author.''amp' ), $name_markup );
                    break;
                case 
'mu-plugin':
                    
/* translators: placeholder is the slug of the must-use plugin */
                    
$message sprintf__'It appears the must-use plugin with slug %s is responsible; please contact the author.''amp' ), $name_markup );
                    break;
                case 
'theme':
                    
/* translators: placeholder is the slug of the theme */
                    
$message sprintf__'It appears the theme with slug %s is responsible; please contact the author.''amp' ), $name_markup );
                    break;
                default:
                    return 
'';
            }

            return 
wp_kses(
                
"<p>{$message}</p>",
                
array_fill_keys( [ 'p''strong''code' ], [] )
            );
        }

        return 
'';
    }

    
/**
     * Render the exception of the error page.
     *
     * The exception details are only rendered if both WP_DEBUG and
     * WP_DEBUG_DISPLAY are true.
     *
     * @return string HTML describing the exception that was thrown.
     */
    
private function render_exception() {
        if ( 
null === $this->exception ) {
            return 
'';
        }

        if (
            ! 
defined'WP_DEBUG' )
            || ! 
WP_DEBUG
            
|| ! defined'WP_DEBUG_DISPLAY' )
            || ! 
WP_DEBUG_DISPLAY
        
) {
            return 
wpautop(
                
wp_kses_post(
                    
__'The exact details of the error are hidden for security reasons. To learn more about this error, enable the WordPress debugging display (by setting both <code>WP_DEBUG</code> and <code>WP_DEBUG_DISPLAY</code> to <code>true</code>), or look into the PHP error log. Learn more about <a href="https://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a>.''amp' )
                )
            );
        }

        
$contents implode(
            
"\n",
            [
                
sprintf(
                    
'<strong>%s</strong> (%s) [<em>%s</em>]',
                    
esc_html$this->exception->getMessage() ),
                    
esc_html$this->exception->getCode() ),
                    
esc_htmlget_class$this->exception ) )
                ),
                
sprintf(
                    
'<em>%s:%d</em>',
                    
esc_html$this->exception->getFile() ),
                    
esc_html$this->exception->getLine() )
                ),
                
'',
                
sprintf(
                    
'<small>%s</small>',
                    
esc_html$this->exception->getTraceAsString() )
                ),
            ]
        );

        return 
"<hr><pre class='exception'>{$contents}</pre>";
    }

    
/**
     * Render back link.
     *
     * @return string Back link.
     */
    
private function render_back_link() {
        if ( empty( 
$this->link_text ) || empty( $this->link_url ) ) {
            return 
'';
        }
        return 
sprintf(
            
'<p><a href="%s" class="button button-large">%s</a></p>',
            
esc_url$this->link_url ),
            
esc_html$this->link_text )
        );
    }

    
/**
     * Get the CSS styles to use for the error page.
     *
     * @see _default_wp_die_handler() Where styles are adapted from.
     *
     * @param string $text_direction Text direction. Can be 'ltr' or 'rtl'.
     * @return string CSS styles to use.
     */
    
private function get_styles$text_direction ) {
        
$rtl_font_tweak 'rtl' === $text_direction
            
'body { font-family: Tahoma, Arial; }'
            
'';

        return <<<STYLES
<style type="text/css">
    html {
        background: #f1f1f1;
    }
    body {
        background: #fff;
        color: #444;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
        margin: 2em auto;
        padding: 1em 2em;
        max-width: 700px;
        -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13);
    }
    h1 {
        border-bottom: 1px solid #dadada;
        clear: both;
        color: #666;
        font-size: 24px;
        margin: 30px 0 0 0;
        padding: 0;
        padding-bottom: 7px;
    }
    hr {
        margin: 20px 0;
        border: none;
        border-top: 1px solid #dadada;
    }
    #error-page {
        margin-top: 50px;
    }
    #error-page p,
    #error-page .wp-die-message {
        font-size: 14px;
        line-height: 1.5;
        margin: 25px 0 20px;
    }
    #error-page .exception,
    code {
        font-family: Consolas, Monaco, monospace;
        overflow-x: auto;
    }
    ul li {
        margin-bottom: 10px;
        font-size: 14px ;
    }
    a {
        color: #0073aa;
    }
    a:hover,
    a:active {
        color: #006799;
    }
    a:focus {
        color: #124964;
        -webkit-box-shadow:
            0 0 0 1px #5b9dd9,
            0 0 2px 1px rgba(30, 140, 190, 0.8);
        box-shadow:
            0 0 0 1px #5b9dd9,
            0 0 2px 1px rgba(30, 140, 190, 0.8);
        outline: none;
    }
    .button {
        background: #f7f7f7;
        border: 1px solid #ccc;
        color: #555;
        display: inline-block;
        text-decoration: none;
        font-size: 13px;
        line-height: 2;
        height: 28px;
        margin: 0;
        padding: 0 10px 1px;
        cursor: pointer;
        -webkit-border-radius: 3px;
        -webkit-appearance: none;
        border-radius: 3px;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        -moz-box-sizing:    border-box;
        box-sizing:         border-box;

        -webkit-box-shadow: 0 1px 0 #ccc;
        box-shadow: 0 1px 0 #ccc;
        vertical-align: top;
    }

    .button.button-large {
        height: 30px;
        line-height: 2.15384615;
        padding: 0 12px 2px;
    }

    .button:hover,
    .button:focus {
        background: #fafafa;
        border-color: #999;
        color: #23282d;
    }

    .button:focus {
        border-color: #5b9dd9;
        -webkit-box-shadow: 0 0 3px rgba(0, 115, 170, 0.8);
        box-shadow: 0 0 3px rgba(0, 115, 170, 0.8);
        outline: none;
    }

    .button:active {
        background: #eee;
        border-color: #999;
        -webkit-box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
        box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
    }

    
{$rtl_font_tweak}
</style>
STYLES;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586