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