PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.9
VikBooking Hotel Booking Engine & PMS v1.8.9
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 / platform / org / wordpress / uri.php

uri.php in VikBooking Hotel Booking Engine & PMS 1.8.9, at admin/helpers/src/platform/org/wordpress/uri.php

233 lines 5.5 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 * Implements the URI interface for the WordPress platform.
16 *
17 * @since 1.5
18 */
19 class VBOPlatformOrgWordpressUri extends VBOPlatformUriAware
20 {
21 /**
22 * Rewrites an internal URI that needs to be used outside of the website.
23 * This means that the routed URI MUST start with the base path of the site.
24 *
25 * @param mixed $query The query string or an associative array of data.
26 * @param boolean $xhtml Replace & by &amp; for XML compliance.
27 * @param mixed $itemid The itemid to use. If null, the current one will be used.
28 *
29 * @return string The complete routed URI.
30 */
31 public function route($query = '', $xhtml = true, $itemid = null)
32 {
33 $app = JFactory::getApplication();
34
35 if (is_array($query))
36 {
37 // make sure the array is not empty
38 if ($query)
39 {
40 $query = '?' . http_build_query($query);
41 }
42 else
43 {
44 $query = '';
45 }
46
47 // the query is an array, build the query string
48 $query = 'index.php' . $query;
49 }
50
51 if (is_null($itemid) && $app->isClient('site'))
52 {
53 // no item id, get it from the request
54 $itemid = $app->input->getInt('Itemid', 0);
55 }
56
57 if ($itemid)
58 {
59 if ($query)
60 {
61 // check if the query string contains a '?'
62 if (strpos($query, '?') !== false)
63 {
64 // the query already starts with 'index.php?' or '?'
65 $query .= '&';
66 }
67 else
68 {
69 // the query string is probably equals to 'index.php'
70 $query .= '?';
71 }
72 }
73 else
74 {
75 // empty query, create the default string
76 $query = 'index.php?';
77 }
78
79 // the item id is set, append it at the end of the query string
80 $query .= 'Itemid=' . $itemid;
81 }
82
83 // check if the query already specifies the Itemid
84 if (!preg_match("/&Itemid=[\d]*/", $query))
85 {
86 // try to extract view from query
87 if (preg_match("/&view=([a-z0-9_]+)(?:&|$)/", $query, $match))
88 {
89 $view = end($match);
90 }
91 else
92 {
93 $view = null;
94 }
95
96 // import shortcodes model
97 $model = JModel::getInstance('vikbooking', 'shortcodes', 'admin');
98 $itemid = $model->best($view);
99
100 if ($itemid)
101 {
102 // update query with Itemid found
103 $query .= (strpos($query, '?') === false ? '?' : '&') . 'Itemid=' . $itemid;
104 }
105 }
106
107 // route URL
108 return JRoute::rewrite($query, false);
109 }
110
111 /**
112 * Routes an admin URL for being used outside from the website (complete URI).
113 *
114 * @param mixed $query The query string or an associative array of data.
115 * @param boolean $xhtml Replace & by &amp; for XML compliance.
116 *
117 * @return string The complete routed URI.
118 */
119 public function admin($query = '', $xhtml = true)
120 {
121 $app = JFactory::getApplication();
122
123 if (is_array($query))
124 {
125 // make sure the array is not empty
126 if ($query)
127 {
128 $query = '?' . http_build_query($query);
129 }
130 else
131 {
132 $query = '';
133 }
134
135 // the query is an array, build the query string
136 $query = 'index.php' . $query;
137 }
138
139 // replace initial index.php with admin.php
140 $query = preg_replace("/^index\.php/", 'admin.php', $query);
141
142 // replace option=com_vikbooking with page=vikbooking
143 $query = preg_replace("/(&|\?)option=com_vikbooking/", '$1page=vikbooking', $query);
144
145 // replace option=com_vikchannelmanager with page=vikchannelmanager
146 $query = preg_replace("/(&|\?)option=com_vikchannelmanager/", '$1page=vikchannelmanager', $query);
147
148 // finalise admin URI
149 $uri = admin_url($query);
150
151 if ($xhtml)
152 {
153 // try to make "&" XML safe
154 $uri = preg_replace("/&(?!amp;)/", '&amp;', $uri);
155 }
156
157 return $uri;
158 }
159
160 /**
161 * Prepares a plain/routed URL to be used for an AJAX request.
162 *
163 * @param mixed $query The query string or a routed URL.
164 * @param boolean $xhtml Replace & by &amp; for XML compliance.
165 *
166 * @return string The AJAX end-point URI.
167 */
168 public function ajax($query = '', $xhtml = false)
169 {
170 // instantiate path based on specified query
171 $path = new JUri($query);
172
173 // delete option var from query
174 $path->delVar('option');
175
176 // force action in query
177 $plugin_action = strpos($query, 'vikchannelmanager') !== false ? 'vikchannelmanager' : 'vikbooking';
178 $path->setVar('action', $plugin_action);
179
180 // force application client in case of front-end
181 if (JFactory::getApplication()->isClient('site'))
182 {
183 $path->setVar('vik_ajax_client', 'site');
184 }
185
186 // create AJAX URI
187 $uri = admin_url('admin-ajax.php') . '?' . $path->getQuery();
188
189 if ($xhtml)
190 {
191 // try to make "&" XML safe
192 $uri = preg_replace("/&(?!amp;)/", '&amp;', $uri);
193 }
194
195 return $uri;
196 }
197
198 /**
199 * Includes the CSRF-proof token within the specified query string/URL.
200 *
201 * @param mixed $query The query string or a routed URL.
202 * @param boolean $xhtml Replace & by &amp; for XML compliance.
203 *
204 * @return string The resulting path.
205 */
206 public function addCSRF($query = '', $xhtml = false)
207 {
208 JLoader::import('adapter.session.session');
209
210 // safely append the CSRF token within the query string
211 $uri = JUri::getInstance($query);
212 $uri->setVar(JSession::getFormTokenName(), JSession::getFormToken());
213
214 if ($xhtml)
215 {
216 // try to make "&" XML safe
217 $uri = preg_replace("/&(?!amp;)/", '&amp;', (string) $uri);
218 }
219
220 return (string) $uri;
221 }
222
223 /**
224 * Returns the platform base path.
225 *
226 * @return string
227 */
228 public function getAbsolutePath()
229 {
230 return ABSPATH;
231 }
232 }
233