| 1 |
<?php if (!defined('ABSPATH')) die('No direct access allowed'); ?> |
| 2 |
<div class="wpo_section wpo_group"> |
| 3 |
<form id="wpo-404-detector-form"> |
| 4 |
<div class="wpo-fieldgroup wpo-show"> |
| 5 |
<div class="switch-container"> |
| 6 |
<label class="switch"> |
| 7 |
<input |
| 8 |
name="404_detector" |
| 9 |
id="wpo_404_detector" |
| 10 |
class="wpo-save-settings" |
| 11 |
type="checkbox" |
| 12 |
value="1" |
| 13 |
<?php checked($is_enabled); ?> |
| 14 |
> |
| 15 |
<span class="slider round"></span> |
| 16 |
</label> |
| 17 |
<label for="wpo_404_detector"> |
| 18 |
<?php esc_html_e('Enable 404 Detector', 'wp-optimize');?> |
| 19 |
</label> |
| 20 |
</div> |
| 21 |
<div id="wpo-404-clear-logs"> |
| 22 |
<a href="#" class="button button-primary button-large"> |
| 23 |
<?php esc_html_e('Clear All Logs', 'wp-optimize');?> |
| 24 |
</a> |
| 25 |
</div> |
| 26 |
</div> |
| 27 |
</form> |
| 28 |
</div> |
| 29 |
<div id="wpo_404_detector_results" style="display: <?php echo $is_enabled ? 'block' : 'none'; ?>"> |
| 30 |
<?php |
| 31 |
add_thickbox(); |
| 32 |
|
| 33 |
$add_thickbox_for_urls = array(); |
| 34 |
|
| 35 |
?> |
| 36 |
<span class="dashicons dashicons-info-outline"></span> <span style="vertical-align:middle;"> |
| 37 |
<?php |
| 38 |
echo esc_html__('Here are the the most recent addresses requested that resulted in a 404 Not Found error a high number of times', 'wp-optimize'); |
| 39 |
echo ' ('; |
| 40 |
// translators: %s is a number |
| 41 |
printf(esc_html__('Over %s in a single hour', 'wp-optimize'), esc_html($suspicious_threshold)); |
| 42 |
echo ')'; |
| 43 |
?> |
| 44 |
</span> |
| 45 |
<?php |
| 46 |
|
| 47 |
if (0 === count($requests) || !$report_has_data) { |
| 48 |
?> |
| 49 |
<table class="wp-list-table widefat striped wpo-404-requests"> |
| 50 |
<tr><td><?php echo esc_html__('Nothing to show', 'wp-optimize'); ?></td></tr> |
| 51 |
</table> |
| 52 |
<?php |
| 53 |
} |
| 54 |
|
| 55 |
foreach ($requests as $url => $url_requests) { |
| 56 |
?> |
| 57 |
<h1><?php echo esc_html($url); ?></h1> |
| 58 |
<table class="wp-list-table widefat striped wpo-404-requests"> |
| 59 |
<tr> |
| 60 |
<th class="wpo-thin-header"><?php esc_html_e('Times accessed', 'wp-optimize'); ?></th> |
| 61 |
<th><?php esc_html_e('Referrer', 'wp-optimize'); ?></th> |
| 62 |
<th class="wpo-thin-header-2"><?php esc_html_e('First access', 'wp-optimize'); ?></th> |
| 63 |
<th class="wpo-thin-header-2"><?php esc_html_e('Last access', 'wp-optimize'); ?></th> |
| 64 |
</tr> |
| 65 |
<?php |
| 66 |
|
| 67 |
foreach ($url_requests as $row) { |
| 68 |
if (1 < $row->occurrences && 'grouped' === $row->row_type) { |
| 69 |
|
| 70 |
if (0 === (int) $row->non_suspicious_referrers && 1 === (int) $row->total_referrers) { |
| 71 |
// There is no additional information inside the group to be shown, no thickbox |
| 72 |
continue; |
| 73 |
} |
| 74 |
|
| 75 |
$tb_id = md5($row->url); |
| 76 |
$add_thickbox_for_urls[] = $tb_id; |
| 77 |
|
| 78 |
$row->referrer = '<a title="' . esc_attr($row->url) . '" href="#TB_inline?width=350&height=500&inlineId=requests-detail-' . esc_attr($tb_id) . '" class="thickbox">' . esc_html__('View all (including URLs with low 404 requests count)', 'wp-optimize') . '</a>'; |
| 79 |
} |
| 80 |
?> |
| 81 |
<tr> |
| 82 |
<td class="wpo-text-center"><?php echo sprintf('grouped' === $row->row_type ? '<b>%s</b>' : '%s', esc_html($row->total_count)); ?></td> |
| 83 |
<td><?php echo '' !== $row->referrer ? $row->referrer : ('<i>' . esc_html__('Not available', 'wp-optimize') . '</i>'); // phpcs:ignore WordPress.Security.EscapeOutput -- $row->referrer is already escaped ?></td> |
| 84 |
<td><?php echo esc_html(WP_Optimize()->format_date_time($row->first_access, ' ')); ?></td> |
| 85 |
<td><?php echo esc_html(WP_Optimize()->format_date_time($row->last_access, ' ')); ?></td> |
| 86 |
</tr> |
| 87 |
<?php |
| 88 |
} |
| 89 |
|
| 90 |
?> |
| 91 |
</table> |
| 92 |
<?php |
| 93 |
} |
| 94 |
|
| 95 |
foreach ($requests as $url => $url_requests) { |
| 96 |
foreach ($url_requests as $row) { |
| 97 |
$tb_id = md5($row->url); |
| 98 |
|
| 99 |
if (in_array($tb_id, $add_thickbox_for_urls) && (1 < $row->occurrences)) { |
| 100 |
?> |
| 101 |
<div id="requests-detail-<?php echo esc_attr($tb_id); ?>" style="display:none;"> |
| 102 |
<?php |
| 103 |
$url_requests = $obj_404_detector->get_url_requests_by_referrer($row->url); |
| 104 |
$table_body = array(); |
| 105 |
|
| 106 |
$requests_groups = array('over', 'under'); |
| 107 |
|
| 108 |
foreach ($requests_groups as $group) { |
| 109 |
if ('over' === $group && empty($url_requests['over'])) { |
| 110 |
// There are both over and under the threshold, split it with a title |
| 111 |
// translators: %s is a number |
| 112 |
$table_body[] = '<tr><td colspan=4><h4>' . esc_html__('No URLs with many 404 requests found', 'wp-optimize') . ' (' . sprintf(esc_html__('over %s hits in a single hour', 'wp-optimize'), $suspicious_threshold) . ')</h4></td></tr>'; |
| 113 |
} |
| 114 |
|
| 115 |
if ('under' === $group && (0 < count($url_requests['under']))) { |
| 116 |
// There are both over and under the threshold, split it with a title |
| 117 |
// translators: %s is a number |
| 118 |
$table_body[] = '<tr><td colspan=4><h4>' . esc_html__('URLs with few 404 requests', 'wp-optimize') . ' (' . sprintf(esc_html__('under %s hits in a single hour', 'wp-optimize'), $suspicious_threshold) . ')</h4></td></tr>'; |
| 119 |
} |
| 120 |
|
| 121 |
foreach ($url_requests[$group] as $item) { |
| 122 |
$table_body[] = '<tr> |
| 123 |
<td>' . ('' !== $item->referrer ? esc_html($item->referrer) : ('<i>' . esc_html__('Not available', 'wp-optimize') . '</i>')) . '</td> |
| 124 |
<td class="wpo-text-center"><b>' . $item->total_count . '</b></td> |
| 125 |
<td class="wpo-text-center">' . esc_html(WP_Optimize()->format_date_time($item->first_access, ' ')) . '</td> |
| 126 |
<td class="wpo-text-center">' . esc_html(WP_Optimize()->format_date_time($item->last_access, ' ')) . '</td> |
| 127 |
</tr>'; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
?> |
| 132 |
<table class="wpo_span_3_of_3"> |
| 133 |
<tr> |
| 134 |
<th><?php echo esc_html__('Referrer', 'wp-optimize'); ?></th> |
| 135 |
<th class="wpo-text-center"><?php echo esc_html__('Hits', 'wp-optimize'); ?></th> |
| 136 |
<th class="wpo-text-center"><?php echo esc_html__('First access', 'wp-optimize'); ?></th> |
| 137 |
<th class="wpo-text-center"><?php echo esc_html__('Last access', 'wp-optimize'); ?></th> |
| 138 |
</tr> |
| 139 |
<?php |
| 140 |
echo implode("", $table_body); // phpcs:ignore WordPress.Security.EscapeOutput -- Output is already escaped |
| 141 |
?> |
| 142 |
</table> |
| 143 |
</div> |
| 144 |
<?php |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
?> |
| 149 |
</div> |
| 150 |
|