PluginProbe
YayMail – WooCommerce Email Customizer / 3.3
YayMail – WooCommerce Email Customizer v3.3
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / includes / Helper / Helper.php

Helper.php in YayMail – WooCommerce Email Customizer 3.3, at includes/Helper/Helper.php

325 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Helper;
4
5 defined( 'ABSPATH' ) || exit;
6 class Helper {
7
8
9 public static function checkNonce() {
10 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
11 if ( ! wp_verify_nonce( $nonce, 'email-nonce' ) ) {
12 wp_send_json_error( array( 'mess' => __( 'Nonce is invalid', 'yaymail' ) ) );
13 }
14 }
15
16 public static function sanitize_array( $var ) {
17 if ( is_array( $var ) ) {
18 return array_map( 'self::sanitize_array', $var );
19 } else {
20 return is_scalar( $var ) ? wp_kses_allowed_html( $var ) : $var;
21 }
22 }
23
24 public static function unsanitize_array( $var ) {
25 if ( is_array( $var ) ) {
26 return array_map( 'self::unsanitize_array', $var );
27 } else {
28 return html_entity_decode( $var, ENT_QUOTES, 'UTF-8' );
29 }
30 }
31
32 // Fix bugs for only Customer Invoice (core code of Woocommerce)
33 public static function getCustomerInvoiceSubject( $objEmail ) {
34 if ( $objEmail->object && $objEmail->object->has_status( array( 'completed', 'processing' ) ) ) {
35 $subject = $objEmail->get_option( 'subject_paid', $objEmail->get_default_subject( true ) );
36 return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $objEmail->format_string( $subject ), $objEmail->object, $objEmail );
37 }
38
39 $subject = $objEmail->get_option( 'subject', $objEmail->get_default_subject() );
40 return apply_filters( 'woocommerce_email_subject_customer_invoice', $objEmail->format_string( $subject ), $objEmail->object, $objEmail );
41 }
42
43 // Get Subject for email WC_Email_New_Booking (Woo Bookings plugin)
44 public static function getNewBookingSubject( $objEmail ) {
45 $subject = $objEmail->get_option( 'subject', $objEmail->subject );
46 return apply_filters( 'woocommerce_email_subject_' . $objEmail->id, $objEmail->format_string( $subject ), $objEmail->object );
47 }
48
49 // Check Key Exist
50 public static function checkKeyExist( $array, $key, $valueDefault ) {
51 if ( isset( $array->$key ) ) {
52 return $key;
53 } else {
54 return $valueDefault;
55 }
56 }
57
58 public static function preventXSS( $yaymail_elements ) {
59 foreach ( $yaymail_elements as $key => $value ) {
60 if ( isset( $value['settingRow']['content'] ) ) {
61 $yaymail_elements[ $key ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $value['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
62 }
63 if ( isset( $value['settingRow']['contentTitle'] ) ) {
64 $yaymail_elements[ $key ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $value['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
65 }
66 if ( isset( $value['settingRow']['contentAfter'] ) ) {
67 $yaymail_elements[ $key ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $value['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
68 }
69 if ( isset( $value['settingRow']['contentBefore'] ) ) {
70 $yaymail_elements[ $key ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $value['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
71 }
72 if ( isset( $value['settingRow']['col1TtContent'] ) ) {
73 $yaymail_elements[ $key ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $value['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
74 }
75 if ( isset( $value['settingRow']['col2TtContent'] ) ) {
76 $yaymail_elements[ $key ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $value['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
77 }
78 if ( isset( $value['settingRow']['col3TtContent'] ) ) {
79 $yaymail_elements[ $key ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $value['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
80 }
81 if ( isset( $value['settingRow']['HTMLContent'] ) ) {
82 $yaymail_elements[ $key ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $value['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
83 }
84 if ( isset( $value['settingRow']['col2Content'] ) ) {
85 $yaymail_elements[ $key ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $value['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
86 }
87
88 // for column
89 // column1
90 if ( isset( $value['settingRow']['column1'] ) ) {
91 foreach ( $value['settingRow']['column1'] as $key1 => $value1 ) {
92 if ( isset( $value1['settingRow']['content'] ) ) {
93 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
94 }
95 if ( isset( $value1['settingRow']['contentTitle'] ) ) {
96 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
97 }
98 if ( isset( $value1['settingRow']['contentAfter'] ) ) {
99 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
100 }
101 if ( isset( $value1['settingRow']['contentBefore'] ) ) {
102 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
103 }
104 if ( isset( $value1['settingRow']['col1TtContent'] ) ) {
105 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
106 }
107 if ( isset( $value1['settingRow']['col2TtContent'] ) ) {
108 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
109 }
110 if ( isset( $value1['settingRow']['col3TtContent'] ) ) {
111 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
112 }
113 if ( isset( $value1['settingRow']['HTMLContent'] ) ) {
114 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
115 }
116 if ( isset( $value1['settingRow']['col2Content'] ) ) {
117 $yaymail_elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
118 }
119 }
120 }
121 // column2
122 if ( isset( $value['settingRow']['column2'] ) ) {
123 foreach ( $value['settingRow']['column2'] as $key1 => $value1 ) {
124 if ( isset( $value1['settingRow']['content'] ) ) {
125 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
126 }
127 if ( isset( $value1['settingRow']['contentTitle'] ) ) {
128 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
129 }
130 if ( isset( $value1['settingRow']['contentAfter'] ) ) {
131 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
132 }
133 if ( isset( $value1['settingRow']['contentBefore'] ) ) {
134 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
135 }
136 if ( isset( $value1['settingRow']['col1TtContent'] ) ) {
137 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
138 }
139 if ( isset( $value1['settingRow']['col2TtContent'] ) ) {
140 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
141 }
142 if ( isset( $value1['settingRow']['col3TtContent'] ) ) {
143 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
144 }
145 if ( isset( $value1['settingRow']['HTMLContent'] ) ) {
146 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
147 }
148 if ( isset( $value1['settingRow']['col2Content'] ) ) {
149 $yaymail_elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
150 }
151 }
152 }
153 // column3
154 if ( isset( $value['settingRow']['column3'] ) ) {
155 foreach ( $value['settingRow']['column3'] as $key1 => $value1 ) {
156 if ( isset( $value1['settingRow']['content'] ) ) {
157 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
158 }
159 if ( isset( $value1['settingRow']['contentTitle'] ) ) {
160 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
161 }
162 if ( isset( $value1['settingRow']['contentAfter'] ) ) {
163 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
164 }
165 if ( isset( $value1['settingRow']['contentBefore'] ) ) {
166 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
167 }
168 if ( isset( $value1['settingRow']['col1TtContent'] ) ) {
169 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
170 }
171 if ( isset( $value1['settingRow']['col2TtContent'] ) ) {
172 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
173 }
174 if ( isset( $value1['settingRow']['col3TtContent'] ) ) {
175 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
176 }
177 if ( isset( $value1['settingRow']['HTMLContent'] ) ) {
178 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
179 }
180 if ( isset( $value1['settingRow']['col2Content'] ) ) {
181 $yaymail_elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
182 }
183 }
184 }
185
186 // column4
187 if ( isset( $value['settingRow']['column4'] ) ) {
188 foreach ( $value['settingRow']['column4'] as $key1 => $value1 ) {
189 if ( isset( $value1['settingRow']['content'] ) ) {
190 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
191 }
192 if ( isset( $value1['settingRow']['contentTitle'] ) ) {
193 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
194 }
195 if ( isset( $value1['settingRow']['contentAfter'] ) ) {
196 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
197 }
198 if ( isset( $value1['settingRow']['contentBefore'] ) ) {
199 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $value1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
200 }
201 if ( isset( $value1['settingRow']['col1TtContent'] ) ) {
202 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
203 }
204 if ( isset( $value1['settingRow']['col2TtContent'] ) ) {
205 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
206 }
207 if ( isset( $value1['settingRow']['col3TtContent'] ) ) {
208 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
209 }
210 if ( isset( $value1['settingRow']['HTMLContent'] ) ) {
211 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $value1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
212 }
213 if ( isset( $value1['settingRow']['col2Content'] ) ) {
214 $yaymail_elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $value1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
215 }
216 }
217 }
218 }
219 return $yaymail_elements;
220 }
221
222 public static function isPreview( $is_preview = true ) {
223 if ( $is_preview ) {
224 return true;
225 }
226 return false;
227 }
228
229 public static function OrderItemsTitle() {
230 $orderTitle = array(
231 'order_title' => __( '[Order #', 'yaymail' ) . wp_kses_post( do_shortcode( '[yaymail_order_id]' ) . '] (' ) . wp_kses_post( do_shortcode( '[yaymail_order_date]' ) . ')' ),
232 'product_title' => __( 'Product', 'yaymail' ),
233 'cost_title' => __( 'Cost', 'yaymail' ),
234 'quantity_title' => __( 'Quantity', 'yaymail' ),
235 'price_title' => __( 'Price', 'yaymail' ),
236 'subtoltal_title' => __( 'Subtotal:', 'yaymail' ),
237 'discount_title' => __( 'Discount:', 'yaymail' ),
238 'shipping_title' => __( 'Shipping:', 'yaymail' ),
239 'payment_method_title' => __( 'Payment method:', 'yaymail' ),
240 'fully_refunded' => __( 'Order fully refunded.', 'yaymail' ),
241 'customer_note' => __( 'Note:', 'yaymail' ),
242 'total_title' => __( 'Total:', 'yaymail' ),
243 'subscript_id' => __( 'ID', 'yaymail' ),
244 'subscript_start_date' => __( 'Start date', 'yaymail' ),
245 'subscript_end_date' => __( 'End date', 'yaymail' ),
246 'subscript_recurring_total' => __( 'Recurring total', 'yaymail' ),
247 'subscript_subscription' => __( 'Subscription', 'yaymail' ),
248 'subscript_price' => __( 'Price', 'yaymail' ),
249 'subscript_last_order_date' => __( 'Last Order Date', 'yaymail' ),
250 'subscript_end_of_prepaid_term' => __( 'End of Prepaid Term', 'yaymail' ),
251 'subscript_date_suspended' => __( 'Date Suspended', 'yaymail' ),
252 );
253 return $orderTitle;
254 }
255
256 public static function OrderItemsDownloadsTitle() {
257 $orderTitle = array(
258 'items_download_header_title' => __( 'Downloads', 'yaymail' ),
259 'items_download_product_title' => __( 'Product', 'yaymail' ),
260 'items_download_expires_title' => __( 'Expires', 'yaymail' ),
261 'items_download_download_title' => __( 'Download', 'yaymail' ),
262 );
263 return $orderTitle;
264 }
265
266 public static function inforShortcode( $postID, $template, $order ) {
267 $yaymail_settings = get_option( 'yaymail_settings' );
268 $yaymail_informations = array(
269 'post_id' => $postID,
270 'template' => $template,
271 'order' => $order,
272 'yaymail_elements' => get_post_meta( $postID, '_yaymail_elements', true ),
273 'general_settings' => array(
274 'tableWidth' => $yaymail_settings['container_width'],
275 'emailBackgroundColor' => get_post_meta( $postID, '_email_backgroundColor_settings', true ) ? get_post_meta( $postID, '_email_backgroundColor_settings', true ) : '#ECECEC',
276 'textLinkColor' => get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3',
277 ),
278 );
279 return $yaymail_informations;
280 }
281
282 /**
283 * This function returns an array of allowed HTML tags for a WordPress post, including any custom tags
284 * specified by the user.
285 *
286 * @param cusTags An array of custom HTML tags and their attributes that should be allowed in addition
287 * to the default allowed HTML tags.
288 *
289 * @return an array of allowed HTML tags for a WordPress post, with any custom HTML tags added to the
290 * list. The custom HTML tags are passed as an argument to the function.
291 */
292 public static function customAllowedHTMLTags( $cusTags = array() ) {
293 $customs_html_attr = $cusTags;
294 $allowed_html_tags = wp_kses_allowed_html( 'post' );
295 return array_map(
296 function ( $item ) use ( $customs_html_attr ) {
297 return is_array( $item ) ? array_merge( $item, $customs_html_attr ) : $item;
298 },
299 $allowed_html_tags
300 );
301 }
302
303 /**
304 * It replaces the string 'yaymail-style' with ':style' in all the values of an array
305 *
306 * @param value The value to be sanitized.
307 *
308 * @return The value of the array.
309 */
310 public static function replaceCustomAllowedHTMLTags( $value ) {
311 if ( is_string( $value ) ) {
312 return str_replace( ':style', 'yaymail-style', $value );
313 } else {
314 array_walk_recursive(
315 $value,
316 function ( &$item, $key ) {
317 $item = str_replace( 'yaymail-style', ':style', $item );
318 }
319 );
320 return $value;
321 }
322 }
323
324 }
325