PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.5
VikBooking Hotel Booking Engine & PMS v1.6.5
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.6.5, at admin/controllers/mail.php

157 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 $clauses = [
46 "`status`='confirmed'",
47 "`closure`=0",
48 ];
49 if (!empty($bid)) {
50 $clauses[] = "`id`=" . $bid;
51 }
52 $q = "SELECT * FROM `#__vikbooking_orders` WHERE " . implode(' AND ', $clauses) . " ORDER BY `id` DESC";
53 $dbo->setQuery($q, 0, 1);
54 $dbo->execute();
55 if ($dbo->getNumRows()) {
56 $booking = $dbo->loadAssoc();
57 $booking_rooms = VikBooking::loadOrdersRoomsData($booking['id']);
58 // inject properties for parsing the conditional text rules later
59 VikBooking::getConditionalRulesInstance()->set(['booking', 'rooms'], [$booking, $booking_rooms]);
60 }
61
62 // wrap dummy mail data with proper content
63 $mail_data = new VBOMailWrapper([
64 'sender' => ['[email protected]', __METHOD__],
65 'recipient' => '[email protected]',
66 'bcc' => [],
67 'reply' => null,
68 'subject' => __METHOD__,
69 'content' => $content,
70 'attachments' => null,
71 ]);
72
73 // prepare the final email content
74 $mail_content = VBOFactory::getPlatform()->getMailer()->prepare($mail_data);
75
76 // send JSON response to output
77 VBOHttpDocument::getInstance($app)->json([$mail_content]);
78 }
79
80 /**
81 * AJAX request made by the configuration page when updating the
82 * visual editor mail content wrapper symbols (HTML code). From
83 * a whole HTML string, we need to be able to detect the opening
84 * and closing HTML tags, usually DIV tags with inline styles.
85 *
86 * @return void
87 */
88 public function update_ve_contwraper()
89 {
90 $app = JFactory::getApplication();
91 $input = $app->input;
92
93 // the raw wrapper content HTML code
94 $wrapper_content = $input->get('wrapper_content', '', 'raw');
95
96 if (empty($wrapper_content)) {
97 VBOHttpDocument::getInstance()->close(500, 'Empty mail content wrapper HTML code');
98 }
99
100 // regex pattern to match only HTML tags, inclusive of tab and new line feeds
101 $rgx_pattern = '/(\t*<\/?[a-z]+\s?[A-Za-z0-9=:"%;#\- ]*?>\n?)/';
102
103 // find occurrences
104 preg_match_all($rgx_pattern, $wrapper_content, $matches);
105
106 if (empty($matches[1]) || (count($matches[1]) % 2) !== 0) {
107 // no matches or odd matches count, this is an error
108 VBOHttpDocument::getInstance()->close(500, 'Invalid HTML code detected. Make sure to open and close all the HTML tags.');
109 }
110
111 // split the HTML tags in half to get the opening and closing content wrapper code
112 $tags_per_layout = floor(count($matches[1]) / 2);
113
114 $opening_tags = array_slice($matches[1], 0, $tags_per_layout);
115 $closing_tags = array_slice($matches[1], $tags_per_layout, $tags_per_layout);
116
117 $opening_layout = implode('', $opening_tags);
118 $closing_layout = implode('', $closing_tags);
119
120 // access the configuration object
121 $config = VBOFactory::getConfig();
122
123 // update opening and closing layouts
124 $config->set('mail_wrapper_layout_opening', $opening_layout);
125 $config->set('mail_wrapper_layout_closing', $closing_layout);
126
127 // send JSON confirmation response to output
128 VBOHttpDocument::getInstance($app)->json([$opening_layout, $closing_layout]);
129 }
130
131 /**
132 * AJAX endpoint for the visual editor to get the default logo URL.
133 *
134 * @return void
135 */
136 public function get_default_logo()
137 {
138 $app = JFactory::getApplication();
139 $logo_info = new stdClass;
140 $logo_info->url = null;
141
142 $sitelogo = VikBooking::getSiteLogo();
143 $backlogo = VikBooking::getBackendLogo();
144 if (!empty($sitelogo) && is_file(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources'. DIRECTORY_SEPARATOR . $sitelogo)) {
145 $logo_info->url = VBO_ADMIN_URI . 'resources/' . $sitelogo;
146 } elseif (!empty($backlogo) && is_file(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources'. DIRECTORY_SEPARATOR . $backlogo)) {
147 $logo_info->url = VBO_ADMIN_URI . 'resources/' . $backlogo;
148 } else {
149 // default logo
150 $logo_info->url = VBO_ADMIN_URI . 'vikbooking.png';
151 }
152
153 // send JSON response to output
154 VBOHttpDocument::getInstance($app)->json($logo_info);
155 }
156 }
157