PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.4
VikBooking Hotel Booking Engine & PMS v1.6.4
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 / urihandler.php

urihandler.php in VikBooking Hotel Booking Engine & PMS 1.6.4, at admin/helpers/urihandler.php

230 lines 5.1 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 com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 // No direct access to this file
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * This class is used to handle the extra query field for the extension updates.
16 *
17 * USAGE:
18 *
19 * $update = new UriUpdateHandler(); // or new UriUpdateHandler('com_example')
20 *
21 * $update->addExtraField('order_number', $order_number);
22 * $update->addExtraField('domain', $domain);
23 *
24 * // OR
25 *
26 * $update->setExtraFields(array(
27 * 'order_number' => $order_number,
28 * 'domain' => $domain,
29 * ));
30 *
31 * $update->register();
32 *
33 * @since 1.0
34 */
35 class UriUpdateHandler
36 {
37 /**
38 * The component (or plugin/module) instance that need to be updated.
39 *
40 * @var mixed
41 */
42 private $component = null;
43
44 /**
45 * The query string containing the extra fields to append to the update URI.
46 *
47 * @var string
48 */
49 private $extraFields = '';
50
51 /**
52 * Class constructor.
53 * @param mixed $element The element to load. Null to load the current component.
54 *
55 * @uses getComponent() Load the specified/current component.
56 */
57 public function __construct($element = null)
58 {
59 $this->getComponent($element);
60 }
61
62 /**
63 * Load the specified/current component.
64 *
65 * @param mixed $element The element to load. Null to load the current component.
66 *
67 * @return mixed The loaded component.
68 */
69 public function getComponent($element = null)
70 {
71 if ($element === null) {
72 $element = JFactory::getApplication()->input->get('option');
73 }
74
75 jimport('joomla.application.component.helper');
76 $this->component = JComponentHelper::getComponent($element);
77
78 return $this->component;
79 }
80
81 /**
82 * Set the parameters into the additional query string.
83 *
84 * @param array $params The associative array to push.
85 *
86 * @return UriUpdateHandler This object to support chaining.
87 *
88 * @uses addExtraField() Append a single parameter to the query string.
89 */
90 public function setExtraFields(array $params = array())
91 {
92 $this->extraFields = '';
93
94 foreach ($params as $key => $val ) {
95 $this->addExtraField($key, $val);
96 }
97
98 return $this;
99 }
100
101 /**
102 * Push a single value into the additional query string.
103 *
104 * @param string $key The name of the query param.
105 * @param string $val The value of the query param.
106 *
107 * @return UriUpdateHandler This object to support chaining.
108 */
109 public function addExtraField($key, $val)
110 {
111 if (is_scalar($val)) {
112 $this->extraFields .= (empty($this->extraFields) ? '' : '&amp;') . $key."=".urlencode($val);
113 }
114
115 return $this;
116 }
117
118 /**
119 * Commit the changes by updating the extra_fields column of the
120 * #__update_sites_extensions database table.
121 *
122 * @return boolean True on success, otherwise false.
123 */
124 public function register()
125 {
126 if (!$this->component) {
127 return false;
128 }
129
130 $dbo = JFactory::getDbo();
131
132 // load the update site record, if it exists
133 $q = $dbo->getQuery(true);
134
135 $q->select('update_site_id')
136 ->from('#__update_sites_extensions')
137 ->where('extension_id = '.$dbo->q($this->component->id));
138
139 $dbo->setQuery($q);
140 $dbo->execute();
141
142 $updateSite = $dbo->loadResult();
143
144 $success = false;
145
146 if ($updateSite) {
147 // update the update site record
148 $q = $dbo->getQuery(true);
149
150 $q->update($dbo->qn('#__update_sites'))
151 ->set($dbo->qn('extra_query') . ' = ' . $dbo->q($this->extraFields))
152 ->set($dbo->qn('enabled') . ' = 1')
153 ->set($dbo->qn('last_check_timestamp') . ' = 0')
154 ->where($dbo->qn('update_site_id') .' = '.$dbo->q($updateSite));
155
156 $dbo->setQuery($q);
157 $dbo->execute();
158
159 $success = (bool) $dbo->getAffectedRows();
160
161 // Delete any existing updates (essentially flushes the updates cache for this update site)
162 $q = $dbo->getQuery(true);
163
164 $q->delete('#__updates')
165 ->where('update_site_id = '.$dbo->q($updateSite));
166
167 $dbo->setQuery($q);
168 $dbo->execute();
169 }
170
171 return $success;
172 }
173
174 /**
175 * Check the schema of the extension to make sure the system will use
176 * the current version.
177 *
178 * @param string $version The current version of the component.
179 *
180 * @return UriUpdateHandler This object to support chaining.
181 */
182 public function checkSchema($version)
183 {
184 if (!$this->component) {
185 return false;
186 }
187
188 $ok = false;
189
190 $dbo = JFactory::getDbo();
191
192 $q = $dbo->getQuery(true);
193
194 $q->select('version_id')
195 ->from('#__schemas')
196 ->where('extension_id = ' . $this->component->id);
197
198 $dbo->setQuery($q, 0, 1);
199 $dbo->execute();
200
201 if ($dbo->getNumRows()) {
202
203 if ($dbo->loadResult() == $version) {
204 $ok = true;
205 } else {
206 $q->clear()
207 ->delete('#__schemas')
208 ->where('extension_id = ' . $this->component->id);
209
210 $dbo->setQuery($q);
211 $dbo->execute();
212 }
213
214 }
215
216 if (!$ok) {
217 $q->clear()
218 ->insert('#__schemas')
219 ->columns(array('extension_id', 'version_id'))
220 ->values($this->component->id . ', ' . $dbo->q($version));
221
222 $dbo->setQuery($q);
223 $ok = (bool) $dbo->execute();
224 }
225
226 return $ok;
227 }
228
229 }
230