PluginProbe
Sendy / trunk
Sendy vtrunk
3.4.6 3.4.7 trunk 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 All 32 releases
sendy / lib / Utils / View.php

View.php in Sendy trunk, at lib/Utils/View.php

187 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sendy\WooCommerce\Utils;
4
5 use InvalidArgumentException;
6
7 class View
8 {
9 private string $filename;
10
11 private const VIEW_PATH = '/resources/views/';
12
13 public const ALLOWED_TAGS = [
14 'a' => [
15 'class' => [],
16 'href' => [],
17 'rel' => [],
18 'title' => [],
19 'target' => [],
20 ],
21 'abbr' => [
22 'title' => [],
23 ],
24 'b' => [],
25 'blockquote' => [
26 'cite' => [],
27 ],
28 'br' => [],
29 'button' => [
30 'class' => [],
31 'id' => [],
32 'disabled' => [],
33 'data-carrier' => [],
34 'data-order-id' => [],
35 ],
36 'cite' => [
37 'title' => [],
38 ],
39 'code' => [],
40 'del' => [
41 'datetime' => [],
42 'title' => [],
43 ],
44 'dd' => [],
45 'div' => [
46 'class' => [],
47 'id' => [],
48 'title' => [],
49 'style' => [],
50 ],
51 'dl' => [],
52 'dt' => [],
53 'em' => [],
54 'form' => [
55 'action' => [],
56 'method' => [],
57 ],
58 'h1' => [],
59 'h2' => [],
60 'h3' => [],
61 'h4' => [],
62 'h5' => [],
63 'h6' => [],
64 'hr' => [
65 'class' => [],
66 ],
67 'i' => [
68 'class' => [],
69 ],
70 'img' => [
71 'alt' => [],
72 'class' => [],
73 'height' => [],
74 'src' => [],
75 'width' => [],
76 ],
77 'input' => [
78 'id' => [],
79 'class' => [],
80 'name' => [],
81 'value' => [],
82 'type' => [],
83 'style' => [],
84 'step' => [],
85 'checked' => [],
86 ],
87 'li' => [
88 'class' => [],
89 ],
90 'label' => [],
91 'mark' => [
92 'class' => [],
93 ],
94 'ol' => [
95 'class' => [],
96 ],
97 'option' => [
98 'value' => [],
99 'selected' => [],
100 ],
101 'p' => [
102 'class' => [],
103 ],
104 'path' => [
105 'fill' => [],
106 'd' => [],
107 'class' => [],
108 'data-v-19c3f3ae' => [],
109 ],
110 'q' => [
111 'cite' => [],
112 'title' => [],
113 ],
114 'script' => [
115 'type' => [],
116 'id' => [],
117 ],
118 'span' => [
119 'class' => [],
120 'title' => [],
121 'style' => [],
122 'data-tip' => [],
123 'data-target' => [],
124 ],
125 'select' => [
126 'id' => [],
127 'class' => [],
128 'name' => [],
129 'style' => [],
130 ],
131 'strike' => [],
132 'strong' => [],
133 'table' => [
134 'class' => [],
135 ],
136 'tbody' => [
137 'class' => [],
138 ],
139 'thead' => [
140 'class' => [],
141 ],
142 'tr' => [
143 'class' => [],
144 'data-name' => [],
145 ],
146 'th' => [
147 'class' => [],
148 'colspan' => [],
149 ],
150 'td' => [
151 'class' => [],
152 'colspan' => [],
153 ],
154 'ul' => [
155 'id' => [],
156 'class' => [],
157 ],
158 ];
159
160 public function __construct(string $filename)
161 {
162 $this->filename = $filename;
163 }
164
165 public static function fromTemplate(string $template): self
166 {
167 $file = SENDY_WC_PLUGIN_DIR_PATH . self::VIEW_PATH . $template;
168
169 if (file_exists($file)) {
170 return new self($file);
171 }
172
173 throw new InvalidArgumentException('Cannot find template: ' . esc_html($template));
174 }
175
176 public function render($data = []): string
177 {
178 ob_start();
179
180 extract($data);
181
182 require $this->filename;
183
184 return ob_get_clean();
185 }
186 }
187