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 / admin / RedirectRowActionsPresenter.php

RedirectRowActionsPresenter.php in 404 Solution trunk, at includes/admin/RedirectRowActionsPresenter.php

139 lines 4.8 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 * Presents the edit, logs, trash, restore, and delete actions for a redirect row.
9 */
10 class ABJ_404_Solution_RedirectRowActionsPresenter {
11
12 /** @var ABJ_404_Solution_Functions */
13 private $functions;
14
15 /** @var ABJ_404_Solution_View_Shared */
16 private $shared;
17
18 public function __construct(ABJ_404_Solution_Functions $functions, ABJ_404_Solution_View_Shared $shared) {
19 $this->functions = $functions;
20 $this->shared = $shared;
21 }
22
23 /**
24 * @param array<string, mixed> $row
25 * @param array<string, mixed> $tableOptions
26 * @return array{
27 * edit: string,
28 * logs: string,
29 * trash: string,
30 * delete: string,
31 * links: array{editlink: string, logslink: string, trashlink: string, ajaxTrashLink: string, trashtitle: string, deletelink: string}
32 * }
33 */
34 public function render(array $row, string $sub, array $tableOptions): array {
35 $links = $this->shared->buildTableActionLinks($row, $sub, $tableOptions, false);
36 $links = array(
37 'logslink' => $links['logslink'],
38 'trashlink' => $links['trashlink'],
39 'ajaxTrashLink' => $links['ajaxTrashLink'],
40 'trashtitle' => $links['trashtitle'],
41 'deletelink' => $links['deletelink'],
42 'editlink' => $links['editlink'],
43 );
44 $currentFilter = $tableOptions['filter'] ?? 0;
45 $logsId = is_scalar($row['logsid'] ?? 0) ? (int)($row['logsid'] ?? 0) : 0;
46
47 return array(
48 'edit' => $this->editActionLink($currentFilter, $links),
49 'logs' => $this->logsActionLink($logsId),
50 'trash' => $this->trashActionLink($currentFilter),
51 'delete' => $this->deleteActionLink($currentFilter),
52 'links' => $links,
53 );
54 }
55
56 /**
57 * @param mixed $currentFilter
58 * @param array<string, string> $links
59 */
60 private function editActionLink($currentFilter, array $links): string {
61 if ($currentFilter == ABJ404_TRASH_FILTER) {
62 return '';
63 }
64 return $this->actionLink('viewRedirectsTableActionLink.html', array(
65 'href' => esc_url($links['editlink']),
66 'class' => 'abj404-action-link',
67 'title' => '{Edit Redirect Details}',
68 'svg_path' => $this->tpl('viewRedirectsTableSvgEdit.html'),
69 'label' => '{Edit}',
70 ));
71 }
72
73 private function logsActionLink(int $logsId): string {
74 if ($logsId <= 0) {
75 return '';
76 }
77 return $this->actionLink('viewRedirectsTableActionLink.html', array(
78 'href' => '{logsLink}',
79 'class' => 'abj404-action-link',
80 'title' => '{View Redirect Logs}',
81 'svg_path' => $this->tpl('viewRedirectsTableSvgLogs.html'),
82 'label' => '{Logs}',
83 ));
84 }
85
86 /**
87 * @param mixed $currentFilter
88 */
89 private function trashActionLink($currentFilter): string {
90 if ($currentFilter == ABJ404_TRASH_FILTER) {
91 return $this->actionLink('viewRedirectsTableActionLink.html', array(
92 'href' => '{trashLink}',
93 'class' => 'abj404-action-link',
94 'title' => '{Restore}',
95 'svg_path' => $this->tpl('viewRedirectsTableSvgRestore.html'),
96 'label' => '{Restore}',
97 ));
98 }
99
100 return $this->actionLink('viewRedirectsTableActionLinkAjax.html', array(
101 'data_url' => '{ajaxTrashLink}',
102 'class' => 'abj404-action-link danger ajax-trash-link',
103 'title' => '{Trash Redirected URL}',
104 'svg_path' => $this->tpl('viewRedirectsTableSvgTrash.html'),
105 'label' => '{Trash}',
106 ));
107 }
108
109 /**
110 * @param mixed $currentFilter
111 */
112 private function deleteActionLink($currentFilter): string {
113 if ($currentFilter != ABJ404_TRASH_FILTER) {
114 return '';
115 }
116 return $this->actionLink('viewRedirectsTableActionLinkSeparated.html', array(
117 'href' => '{deletelink}',
118 'class' => 'abj404-action-link danger',
119 'title' => '{Delete Redirect Permanently}',
120 'svg_path' => $this->tpl('viewRedirectsTableSvgTrash.html'),
121 'label' => '{Delete}',
122 ));
123 }
124
125 /** @param array<string, string> $vars */
126 private function actionLink(string $tplName, array $vars): string {
127 $tpl = $this->tpl($tplName);
128 foreach ($vars as $key => $value) {
129 $tpl = $this->functions->str_replace('{' . $key . '}', $value, $tpl);
130 }
131 return $tpl;
132 }
133
134 private function tpl(string $name): string {
135 $raw = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . '/html/' . $name, false);
136 return rtrim((string)$raw, "\n");
137 }
138 }
139