PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.5
EmailKit – Email Customizer for WooCommerce & WP v1.5.5
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / Emails / Helpers / Utils.php

Utils.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.5, at includes/Admin/Emails/Helpers/Utils.php

291 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\Emails\Helpers;
4
5 defined("ABSPATH") || exit;
6
7 class Utils
8 {
9 public static function get_kses_array()
10 {
11 return array(
12 'html' => array(),
13 'head' => array(),
14 'body' => array(),
15 'hr' => array(),
16 'address' => array(),
17 'a' => array(
18 'class' => array(),
19 'href' => array(),
20 'rel' => array(),
21 'title' => array(),
22 'target' => array(),
23 'style' => array(),
24 ),
25 'abbr' => array(
26 'title' => array(),
27 'style' => array(),
28 ),
29 'b' => array(
30 'class' => array(),
31 'style' => array(),
32 ),
33 'blockquote' => array(
34 'cite' => array(),
35 'style' => array(),
36 ),
37 'cite' => array(
38 'title' => array(),
39 'style' => array(),
40 ),
41 'code' => array(
42 'style' => array(),
43 ),
44 'pre' => array(
45 'style' => array(),
46 ),
47 'del' => array(
48 'datetime' => array(),
49 'title' => array(),
50 'style' => array(),
51 ),
52 'dd' => array(
53 'style' => array(),
54 ),
55 'div' => array(
56 'class' => array(),
57 'title' => array(),
58 'style' => array(),
59 ),
60 'dl' => array(
61 'style' => array(),
62 ),
63 'dt' => array(
64 'style' => array(),
65 ),
66 'em' => array(
67 'style' => array(),
68 ),
69 'strong' => array(
70 'style' => array(),
71 ),
72 'h1' => array(
73 'class' => array(),
74 'style' => array(),
75 ),
76 'h2' => array(
77 'class' => array(),
78 'style' => array(),
79 ),
80 'h3' => array(
81 'class' => array(),
82 'style' => array(),
83 ),
84 'h4' => array(
85 'class' => array(),
86 'style' => array(),
87 ),
88 'h5' => array(
89 'class' => array(),
90 'style' => array(),
91 ),
92 'h6' => array(
93 'class' => array(),
94 'style' => array(),
95 ),
96 'i' => array(
97 'class' => array(),
98 'style' => array(),
99 ),
100 'img' => array(
101 'alt' => array(),
102 'class' => array(),
103 'height' => array(),
104 'src' => array(),
105 'width' => array(),
106 'style' => array(),
107 'title' => array(),
108 'srcset' => array(),
109 'loading' => array(),
110 'sizes' => array(),
111 'style' => array(),
112 ),
113 'figure' => array(
114 'class' => array(),
115 'style' => array(),
116 ),
117 'li' => array(
118 'class' => array(),
119 'style' => array(),
120 ),
121 'ol' => array(
122 'class' => array(),
123 'style' => array(),
124 ),
125 'p' => array(
126 'class' => array(),
127 'style' => array(),
128 ),
129 'q' => array(
130 'cite' => array(),
131 'title' => array(),
132 'style' => array(),
133 ),
134 'span' => array(
135 'class' => array(),
136 'title' => array(),
137 'style' => array(),
138 ),
139 'iframe' => array(
140 'width' => array(),
141 'height' => array(),
142 'scrolling' => array(),
143 'frameborder' => array(),
144 'allow' => array(),
145 'src' => array(),
146 'style' => array(),
147 ),
148 'strike' => array(),
149 'br' => array(),
150 'table' => array(),
151 'thead' => array(),
152 'tbody' => array(
153 'width' => array(),
154 'height' => array(),
155 'scrolling' => array(),
156 'frameborder' => array(),
157 'allow' => array(),
158 'src' => array(),
159 'style' => array()
160 ),
161 'tfoot' => array(),
162 'tr' => array(
163 'width' => array(),
164 'height' => array(),
165 'scrolling' => array(),
166 'frameborder' => array(),
167 'allow' => array(),
168 'src' => array(),
169 'style' => array()
170 ),
171 'td' => array(
172 'class' => array(),
173 ),
174 'th' => array(),
175 'colgroup' => array(),
176 'col' => array(),
177 'strong' => array(),
178 'data-wow-duration' => array(),
179 'data-wow-delay' => array(),
180 'data-wallpaper-options' => array(),
181 'data-stellar-background-ratio' => array(),
182 'ul' => array(
183 'class' => array(),
184 ),
185 'button' => array(
186 'disabled' => array(),
187 'id' => array(),
188 'class' => array(),
189 'style' => array(),
190 'target' => array(),
191 'href' => array(),
192 'data-editor-template-url' => array(),
193 'data-emailkit-email-type' => array(),
194 'data-emailkit-template-title' => array(),
195 'data-emailkit-template-type' => array(),
196 'data-emailkit-template' => array(),
197 ),
198 'svg' => array(
199 'class' => true,
200 'aria-hidden' => true,
201 'aria-labelledby' => true,
202 'role' => true,
203 'xmlns' => true,
204 'width' => true,
205 'height' => true,
206 'viewbox' => true, // <= Must be lower case!
207 'preserveaspectratio' => true,
208 ),
209 'g' => array('fill' => true),
210 'title' => array('title' => true),
211 'path' => array(
212 'd' => true,
213 'fill' => true,
214 ),
215 'input' => array(
216 'class' => array(),
217 'type' => array(),
218 'value' => array()
219 )
220 );
221 }
222
223 public static function kses($raw)
224 {
225
226 $allowed_tags = self::get_kses_array();
227
228 if (function_exists('wp_kses')) { // WP is here
229 return wp_kses($raw, $allowed_tags);
230 } else {
231 return $raw;
232 }
233 }
234
235 public static function mail_shortcode_filter(string $input) : string {
236
237 // find the shortcode
238 $pattern = '/<span data-shortcode="{{([^<>]+)}}">([^<>]+)<\/span>/';
239
240 // getting all shortcode matches from mail content
241 preg_match_all($pattern, $input, $matches, PREG_SET_ORDER);
242
243 // Loop through each match and replace the content inside the span tag
244 foreach ($matches as $match) {
245 $shortcode = $match[1]; // Content inside the data-shortcode attribute
246 $oldContent = $match[2]; // Content inside the span tag
247
248 // replaceing the shortcode
249 $replacement = '<span>{{' . $shortcode . '}}</span>';
250 $input = str_replace($match[0], $replacement, $input);
251 }
252
253 return $input;
254 }
255
256 public static function order_items_replace(string $document, array $replacements ){
257
258 $pattern = '/<tr[^>]*class="order_items"[^>]*>.*?<\/tr>/s';
259 preg_match_all($pattern, $document, $matches);
260
261 if (!empty($matches[0])) {
262 $row = '';
263 // Iterate through each matched row
264 foreach ($matches[0] as $originalRow) {
265 // Duplicate the row $n times
266 $duplicatedRow = $originalRow;
267
268 // Replace placeholders in the duplicated row
269 $placeholders = ["{{product_name}}", "{{quantity}}", "{{total}}", "{{product_price}}"];
270
271 // Replace placeholders in each duplicated row
272 foreach ($replacements as $replacement) {
273 $row .= str_replace($placeholders, $replacement, $duplicatedRow);
274 }
275 }
276 return preg_replace($pattern, $row, $document);
277 }
278
279 return $document;
280 }
281
282 // Helper function to escape quotes
283 public static function escape_quotes($data) {
284 if (is_string($data)) {
285 return addslashes($data);
286 } elseif (is_array($data)) {
287 return array_map('escape_quotes', $data);
288 }
289 return $data;
290 }
291 }