PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / admin / AdminLogsPageShell.php

AdminLogsPageShell.php in 404 Solution 4.3.0, at includes/admin/AdminLogsPageShell.php

133 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 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Renders the static Redirect Logs admin page shell.
9 */
10 class ABJ_404_Solution_AdminLogsPageShell {
11
12 /** @var ABJ_404_Solution_Functions */
13 private $f;
14 /** @var ABJ_404_Solution_PluginLogic */
15 private $logic;
16 /** @var ABJ_404_Solution_View_Shared */
17 private $shared;
18
19 public function __construct(ABJ_404_Solution_Functions $functions,
20 ABJ_404_Solution_PluginLogic $pluginLogic, ABJ_404_Solution_View_Shared $shared) {
21 $this->f = $functions;
22 $this->logic = $pluginLogic;
23 $this->shared = $shared;
24 }
25
26 /** @return string */
27 public function render(): string {
28 $sub = 'abj404_logs';
29 $tableOptions = $this->logic->settingsUpdate()->getTableOptions($sub);
30 $tableOptions = $this->logic->settingsUpdate()->sanitizePostData($tableOptions);
31
32 $perpage = array_key_exists('perpage', $tableOptions) && is_scalar($tableOptions['perpage']) ? $tableOptions['perpage'] : 25;
33 $orderby = array_key_exists('orderby', $tableOptions) && is_string($tableOptions['orderby']) ? $tableOptions['orderby'] : 'timestamp';
34 $order = array_key_exists('order', $tableOptions) && is_string($tableOptions['order']) ? $tableOptions['order'] : 'DESC';
35 $paginationNonce = wp_create_nonce('abj404_updatePaginationLink');
36 $inflightNonce = wp_create_nonce('abj404_fetchInflightStage');
37
38 $perpageOptionsHtml = $this->renderPerPageOptions($perpage);
39 $searchForm = $this->renderSearchForm();
40 $warmup = ABJ_404_Solution_FileSystemService::readFileContents(__DIR__ . '/../html/tableWarmupPlaceholder.html');
41
42 return $this->f->str_replace(
43 $this->wrapperTokens(),
44 $this->wrapperValues($sub, $paginationNonce, $inflightNonce, $orderby, $order,
45 $searchForm, $perpageOptionsHtml, $warmup),
46 $this->tpl('viewLogsPageWrapper.html')
47 );
48 }
49
50 /** @return array<int, string> */
51 private function wrapperTokens(): array {
52 return array(
53 '{logs_title}',
54 '{data-pagination-ajax-url}',
55 '{data-pagination-ajax-subpage}',
56 '{data-pagination-ajax-nonce}',
57 '{data-pagination-inflight-nonce}',
58 '{data-pagination-current-orderby}',
59 '{data-pagination-current-order}',
60 '{data-pagination-current-logsid}',
61 '{refresh_available_text}',
62 '{search_form}',
63 '{rows_per_page_label}',
64 '{perpage_options}',
65 '{warmup_placeholder}',
66 '{loading_badge_text}',
67 );
68 }
69
70 /** @return array<int, mixed> */
71 private function wrapperValues(string $sub, string $paginationNonce, string $inflightNonce, string $orderby,
72 string $order, string $searchForm, string $perpageOptionsHtml, string $warmup): array {
73 $currentLogsId = $this->shared->viewGetPostOrGetSanitize('redirect_to_data_field_id');
74 return array(
75 __('Redirect Logs', '404-solution'),
76 esc_attr(admin_url('admin-ajax.php')),
77 esc_attr($sub),
78 esc_attr($paginationNonce),
79 esc_attr($inflightNonce),
80 esc_attr($orderby),
81 esc_attr($order),
82 esc_attr(is_scalar($currentLogsId) ? (string)$currentLogsId : ''),
83 esc_attr(__('Refresh available', '404-solution')),
84 $searchForm,
85 __('Rows per page:', '404-solution'),
86 $perpageOptionsHtml,
87 $warmup,
88 esc_html__('Loading...', '404-solution'),
89 );
90 }
91
92 /** @param mixed $perpage */
93 private function renderPerPageOptions($perpage): string {
94 $optionTpl = $this->tpl('viewLogsPerpageOption.html');
95 $html = '';
96 foreach (array(10, 25, 50, 100, 250) as $opt) {
97 $selected = ($perpage == $opt) ? ' selected' : '';
98 $html .= $this->f->str_replace(
99 array('{value}', '{selected_attr}'),
100 array((string)$opt, $selected),
101 $optionTpl
102 ) . "\n";
103 }
104 return $html;
105 }
106
107 private function renderSearchForm(): string {
108 $searchBox = ABJ_404_Solution_FileSystemService::readFileContents(__DIR__ . '/../html/viewLogsForSearchBox.html');
109 $redirectPageTitle = $this->shared->viewGetPostOrGetSanitize('redirect_to_data_field_title');
110 $pageIDAndType = $this->shared->viewGetPostOrGetSanitize('redirect_to_data_field_id');
111 $searchBox = $this->f->str_replace('{redirect_to_label}', __('View logs for', '404-solution'), $searchBox);
112 $searchBox = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}', __('(Begin typing a URL)', '404-solution'), $searchBox);
113 $searchBox = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}', __('(A page has been selected.)', '404-solution'), $searchBox);
114 $searchBox = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_CUSTOM_STRING}', __('(A custom string has been entered.)', '404-solution'), $searchBox);
115 $searchBox = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}', __('(Please choose from the dropdown list instead of typing your own URL.)', '404-solution'), $searchBox);
116 $searchBox = $this->f->str_replace('{pageIDAndType}', esc_attr($pageIDAndType), $searchBox);
117 $searchBox = $this->f->str_replace('{redirectPageTitle}', esc_attr($redirectPageTitle), $searchBox);
118 $searchBox = $this->f->str_replace('{data-url}', 'admin-ajax.php?action=echoViewLogsFor&nonce=' . wp_create_nonce('abj404_ajax'), $searchBox);
119 $searchBox = $this->f->doNormalReplacements($searchBox);
120
121 return $this->f->str_replace(
122 array('{page_constant}', '{search_dropdown}'),
123 array(ABJ404_PP, $searchBox),
124 $this->tpl('viewLogsSearchFormShell.html')
125 );
126 }
127
128 private function tpl(string $name): string {
129 $raw = ABJ_404_Solution_FileSystemService::readFileContents(__DIR__ . '/../html/' . $name, false);
130 return rtrim((string)$raw, "\n");
131 }
132 }
133