PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.1
VikBooking Hotel Booking Engine & PMS v1.7.1
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 / controllers / mail.php

mail.php in VikBooking Hotel Booking Engine & PMS 1.7.1, at admin/controllers/mail.php

161 lines 5.0 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 * VikBooking mail controller.
16 *
17 * @since 1.15.2 (J) - 1.5.5 (WP)
18 */
19 class VikBookingControllerMail extends JControllerAdmin
20 {
21 /**
22 * Given the content received through the AJAX request,
23 * parses the visual editor wrapper symbols and contents.
24 *
25 * @return void
26 */
27 public function preview_visual_editor()
28 {
29 $dbo = JFactory::getDbo();
30 $app = JFactory::getApplication();
31 $input = $app->input;
32
33 // the raw email content
34 $content = $input->get('content', '', 'raw');
35
36 // an optional booking ID to use for the simulation
37 $bid = $input->getInt('bid', 0);
38
39 // replace visual editor placeholders for special tags and conditional text rules
40 $content = preg_replace_callback("/(<strong class=\"vbo-editor-hl-specialtag\">)([^<]+)(<\/strong>)/", function($match) {
41 return $match[2];
42 }, $content);
43
44 // grab the latest confirmed reservation
45 $q = $dbo->getQuery(true)
46 ->select('*')
47 ->from($dbo->qn('#__vikbooking_orders'))
48 ->where($dbo->qn('status') . ' = ' . $dbo->q('confirmed'))
49 ->where($dbo->qn('closure') . ' = 0');
50
51 if (!empty($bid)) {
52 $q->where($dbo->qn('id') . ' = ' . $bid);
53 }
54
55 $q->order($dbo->qn('id') . ' DESC');
56
57 $dbo->setQuery($q, 0, 1);
58 $booking = $dbo->loadAssoc();
59
60 if ($booking) {
61 $booking_rooms = VikBooking::loadOrdersRoomsData($booking['id']);
62 // inject properties for parsing the conditional text rules later
63 VikBooking::getConditionalRulesInstance()->set(['booking', 'rooms'], [$booking, $booking_rooms]);
64 }
65
66 // wrap dummy mail data with proper content
67 $mail_data = new VBOMailWrapper([
68 'sender' => ['[email protected]', __METHOD__],
69 'recipient' => '[email protected]',
70 'bcc' => [],
71 'reply' => null,
72 'subject' => __METHOD__,
73 'content' => $content,
74 'attachments' => null,
75 ]);
76
77 // prepare the final email content
78 $mail_content = VBOFactory::getPlatform()->getMailer()->prepare($mail_data);
79
80 // send JSON response to output
81 VBOHttpDocument::getInstance($app)->json([$mail_content]);
82 }
83
84 /**
85 * AJAX request made by the configuration page when updating the
86 * visual editor mail content wrapper symbols (HTML code). From
87 * a whole HTML string, we need to be able to detect the opening
88 * and closing HTML tags, usually DIV tags with inline styles.
89 *
90 * @return void
91 */
92 public function update_ve_contwraper()
93 {
94 $app = JFactory::getApplication();
95 $input = $app->input;
96
97 // the raw wrapper content HTML code
98 $wrapper_content = $input->get('wrapper_content', '', 'raw');
99
100 if (empty($wrapper_content)) {
101 VBOHttpDocument::getInstance()->close(500, 'Empty mail content wrapper HTML code');
102 }
103
104 // regex pattern to match only HTML tags, inclusive of tab and new line feeds
105 $rgx_pattern = '/(\t*<\/?[a-z]+\s?[A-Za-z0-9=:"%;#\- ]*?>\n?)/';
106
107 // find occurrences
108 preg_match_all($rgx_pattern, $wrapper_content, $matches);
109
110 if (empty($matches[1]) || (count($matches[1]) % 2) !== 0) {
111 // no matches or odd matches count, this is an error
112 VBOHttpDocument::getInstance()->close(500, 'Invalid HTML code detected. Make sure to open and close all the HTML tags.');
113 }
114
115 // split the HTML tags in half to get the opening and closing content wrapper code
116 $tags_per_layout = floor(count($matches[1]) / 2);
117
118 $opening_tags = array_slice($matches[1], 0, $tags_per_layout);
119 $closing_tags = array_slice($matches[1], $tags_per_layout, $tags_per_layout);
120
121 $opening_layout = implode('', $opening_tags);
122 $closing_layout = implode('', $closing_tags);
123
124 // access the configuration object
125 $config = VBOFactory::getConfig();
126
127 // update opening and closing layouts
128 $config->set('mail_wrapper_layout_opening', $opening_layout);
129 $config->set('mail_wrapper_layout_closing', $closing_layout);
130
131 // send JSON confirmation response to output
132 VBOHttpDocument::getInstance($app)->json([$opening_layout, $closing_layout]);
133 }
134
135 /**
136 * AJAX endpoint for the visual editor to get the default logo URL.
137 *
138 * @return void
139 */
140 public function get_default_logo()
141 {
142 $app = JFactory::getApplication();
143 $logo_info = new stdClass;
144 $logo_info->url = null;
145
146 $sitelogo = VikBooking::getSiteLogo();
147 $backlogo = VikBooking::getBackendLogo();
148 if (!empty($sitelogo) && is_file(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources'. DIRECTORY_SEPARATOR . $sitelogo)) {
149 $logo_info->url = VBO_ADMIN_URI . 'resources/' . $sitelogo;
150 } elseif (!empty($backlogo) && is_file(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources'. DIRECTORY_SEPARATOR . $backlogo)) {
151 $logo_info->url = VBO_ADMIN_URI . 'resources/' . $backlogo;
152 } else {
153 // default logo
154 $logo_info->url = VBO_ADMIN_URI . 'vikbooking.png';
155 }
156
157 // send JSON response to output
158 VBOHttpDocument::getInstance($app)->json($logo_info);
159 }
160 }
161