PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.7
VikBooking Hotel Booking Engine & PMS v1.6.7
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / admin / helpers / src / mail / parser.php

parser.php in VikBooking Hotel Booking Engine & PMS 1.6.7, at admin/helpers/src/mail/parser.php

108 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Parses the email content for special elements.
16 *
17 * @since 1.5.5
18 */
19 final class VBOMailParser
20 {
21 /**
22 * @var string the default mail wrapper regex pattern (HTML tag in visual editor)
23 */
24 private static $wrapper_pattern = "/<hr class=\"vbo-editor-hl-mailwrapper\"\s*\/?>/";
25
26 /**
27 * Checks for any content wrapper HTML tags applied through
28 * the Visual Editor during the composing of an email message.
29 *
30 * @param string $content the full email content.
31 *
32 * @return string
33 */
34 public static function checkWrapperSymbols($content)
35 {
36 $chunks = preg_split(static::$wrapper_pattern, (string)$content);
37
38 if (count($chunks) < 2) {
39 // no content wrapper used in email message
40 return $content;
41 }
42
43 $layout_opening = self::getWrapperLayout(true);
44 $layout_closing = self::getWrapperLayout(false);
45
46 $final_content = '';
47 foreach ($chunks as $piece => $part) {
48 $is_even = ($piece === 0 || (($piece % 2) === 0));
49 if (strlen(trim($part)) && !$is_even) {
50 $final_content .= $layout_opening . $part . $layout_closing;
51 } else {
52 $final_content .= $part;
53 }
54 }
55
56 return $final_content;
57 }
58
59 /**
60 * Returns the current mail wrapper layout HTML code.
61 *
62 * @param bool $opening whether to get the opening or closing HTML.
63 *
64 * @return string
65 */
66 public static function getWrapperLayout($opening = true)
67 {
68 // configuration field name
69 $opt_name = 'mail_wrapper_layout_' . ($opening ? 'opening' : 'closing');
70
71 // access the configuration object
72 $config = VBOFactory::getConfig();
73
74 // get the current configuration value
75 $layout = $config->get($opt_name);
76
77 if (!$layout) {
78 // set and get default layout
79 $layout = self::getWrapperDefaultLayout($opening);
80 $config->set($opt_name, $layout);
81 }
82
83 return $layout;
84 }
85
86 /**
87 * Returns the default mail wrapper layout HTML code.
88 *
89 * @param bool $opening whether to get the opening or closing HTML.
90 *
91 * @return string
92 */
93 private static function getWrapperDefaultLayout($opening = true)
94 {
95 $layout_opening = "\n";
96 $layout_opening .= "<div style=\"background: #fdfdfd;padding: 30px 0;\">";
97 $layout_opening .= "\n\t";
98 $layout_opening .= "<div style=\"max-width: 600px;margin: 0 auto;background: #fff;padding: 30px;border: 1px solid #eee;border-radius: 6px\">";
99 $layout_opening .= "\n";
100
101 $layout_closing = "\n";
102 $layout_closing .= "\t</div>\n";
103 $layout_closing .= "</div>\n";
104
105 return $opening ? $layout_opening : $layout_closing;
106 }
107 }
108