PluginProbe
404 Solution / trunk
404 Solution vtrunk
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 / view / CapturedRowActionButtonsRenderer.php

CapturedRowActionButtonsRenderer.php in 404 Solution trunk, at includes/view/CapturedRowActionButtonsRenderer.php

131 lines 6.3 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 * Builds the per-row action button HTML (edit/logs/trash/delete/ignore/later/
9 * dismiss/create-redirect) for the Captured 404 URLs table. Supports both
10 * Simple and Advanced settings modes and the Trash filter variant. Extracted
11 * from View_CapturedURLsTable because building action-button HTML for a row
12 * is a distinct responsibility from assembling the row's other presentation
13 * fields.
14 */
15 class ABJ_404_Solution_CapturedRowActionButtonsRenderer {
16
17 /** @var ABJ_404_Solution_Functions */
18 private $f;
19
20 public function __construct(ABJ_404_Solution_Functions $functions) {
21 $this->f = $functions;
22 }
23
24 private function tpl(string $name): string {
25 $raw = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . '/html/' . $name, false);
26 return rtrim((string)$raw, "\n");
27 }
28
29 /**
30 * Build an action link with SVG icon.
31 *
32 * @param array<string,string> $vars
33 */
34 private function buildActionLink(string $tplName, array $vars): string {
35 $tpl = $this->tpl($tplName);
36 foreach ($vars as $k => $v) {
37 $tpl = $this->f->str_replace('{' . $k . '}', $v, $tpl);
38 }
39 return $tpl;
40 }
41
42 /**
43 * @param array<string, mixed> $row
44 * @param array<string, mixed> $tableOptions
45 * @param array<string, string> $links Pre-built action URLs / titles.
46 * @return array{edit:string,logs:string,trash:string,delete:string,ignore:string,later:string}
47 */
48 public function build(array $row, array $tableOptions, array $links): array {
49 $svgEdit = $this->tpl('viewRedirectsTableSvgEdit.html');
50 $svgDismiss = $this->tpl('viewRedirectsTableSvgDismiss.html');
51 $svgLogs = $this->tpl('viewRedirectsTableSvgLogs.html');
52 $svgTrash = $this->tpl('viewRedirectsTableSvgTrash.html');
53 $svgRestore = $this->tpl('viewRedirectsTableSvgRestore.html');
54 $svgX = $this->tpl('viewRedirectsTableSvgX.html');
55 $svgClock = $this->tpl('viewRedirectsTableSvgClock.html');
56
57 $edit = $logs = $trash = $delete = $ignore = $later = '';
58
59 $currentFilter = $tableOptions['filter'] ?? 0;
60 $isSimpleModeRow = abj_service('settings_mode_preference')->getMode() === 'simple';
61
62 if ($isSimpleModeRow) {
63 $edit = $this->buildActionLink('viewRedirectsTableActionLink.html', array(
64 'href' => esc_url($links['editlink']), 'class' => 'abj404-action-link',
65 'title' => esc_attr__('Create Redirect', '404-solution'),
66 'svg_path' => $svgEdit, 'label' => esc_html__('Create Redirect', '404-solution'),
67 ));
68 if ($row['status'] != ABJ404_STATUS_IGNORED) {
69 $ignore = $this->buildActionLink('viewRedirectsTableActionLinkSeparated.html', array(
70 'href' => esc_url($links['ignorelink']), 'class' => 'abj404-action-link',
71 'title' => esc_attr__('Dismiss', '404-solution'),
72 'svg_path' => $svgDismiss, 'label' => esc_html__('Dismiss', '404-solution'),
73 ));
74 }
75 return ['edit'=>$edit,'logs'=>$logs,'trash'=>$trash,'delete'=>$delete,'ignore'=>$ignore,'later'=>$later];
76 }
77
78 if ($currentFilter != ABJ404_TRASH_FILTER) {
79 $edit = $this->buildActionLink('viewRedirectsTableActionLink.html', array(
80 'href' => esc_url($links['editlink']), 'class' => 'abj404-action-link',
81 'title' => esc_attr__('Edit', '404-solution'),
82 'svg_path' => $svgEdit, 'label' => esc_html__('Edit', '404-solution'),
83 ));
84 }
85 if (($row['logsid'] ?? 0) > 0) {
86 $logs = $this->buildActionLink('viewRedirectsTableActionLink.html', array(
87 'href' => esc_url($links['logslink']), 'class' => 'abj404-action-link',
88 'title' => esc_attr__('View Logs', '404-solution'),
89 'svg_path' => $svgLogs, 'label' => esc_html__('Logs', '404-solution'),
90 ));
91 }
92 if ($currentFilter != ABJ404_TRASH_FILTER) {
93 $trash = $this->buildActionLink('viewRedirectsTableActionLink.html', array(
94 'href' => esc_url($links['trashlink']), 'class' => 'abj404-action-link danger',
95 'title' => esc_attr($links['trashtitle']),
96 'svg_path' => $svgTrash, 'label' => esc_html__('Trash', '404-solution'),
97 ));
98 }
99
100 if ($currentFilter == ABJ404_TRASH_FILTER) {
101 $trash = $this->buildActionLink('viewRedirectsTableActionLink.html', array(
102 'href' => esc_url($links['trashlink']), 'class' => 'abj404-action-link',
103 'title' => esc_attr__('Restore', '404-solution'),
104 'svg_path' => $svgRestore, 'label' => esc_html__('Restore', '404-solution'),
105 ));
106 $delete = $this->buildActionLink('viewRedirectsTableActionLinkConfirm.html', array(
107 'href' => esc_url($links['deletelink']), 'class' => 'abj404-action-link danger',
108 'title' => esc_attr__('Delete Permanently', '404-solution'),
109 'confirm_js' => esc_js(__('Are you sure you want to permanently delete this item?', '404-solution')),
110 'svg_path' => $svgX, 'label' => esc_html__('Delete', '404-solution'),
111 ));
112 } else {
113 if ($row['status'] != ABJ404_STATUS_IGNORED) {
114 $ignore = $this->buildActionLink('viewRedirectsTableActionLinkSeparated.html', array(
115 'href' => esc_url($links['ignorelink']), 'class' => 'abj404-action-link',
116 'title' => esc_attr($links['ignoretitle']),
117 'svg_path' => $svgDismiss, 'label' => esc_html__('Ignore', '404-solution'),
118 ));
119 }
120 if ($row['status'] != ABJ404_STATUS_LATER) {
121 $later = $this->buildActionLink('viewRedirectsTableActionLinkSeparated.html', array(
122 'href' => esc_url($links['laterlink']), 'class' => 'abj404-action-link',
123 'title' => esc_attr($links['latertitle']),
124 'svg_path' => $svgClock, 'label' => esc_html__('Later', '404-solution'),
125 ));
126 }
127 }
128 return ['edit'=>$edit,'logs'=>$logs,'trash'=>$trash,'delete'=>$delete,'ignore'=>$ignore,'later'=>$later];
129 }
130 }
131