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 / libraries / system / assets.php

assets.php in VikBooking Hotel Booking Engine & PMS 1.6.4, at libraries/system/assets.php

252 lines 8.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 - Libraries
4 * @subpackage system
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2018 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 * Class used to provide support for the <head> of the page.
16 *
17 * @since 1.0
18 */
19 class VikBookingAssets
20 {
21 /**
22 * A list containing all the methods already used.
23 *
24 * @var array
25 */
26 protected static $loaded = array();
27
28 /**
29 * Loads all the assets required for the plugin.
30 *
31 * @return void
32 */
33 public static function load()
34 {
35 // loads only once
36 if (static::isLoaded(__METHOD__))
37 {
38 return;
39 }
40
41 $document = JFactory::getDocument();
42
43 $internalFilesOptions = array('version' => VIKBOOKING_SOFTWARE_VERSION);
44
45 // include localised strings for script files
46 JText::script('CONNECTION_LOST');
47
48 // system.js must be loaded on both front-end and back-end for tmpl=component support
49 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'js/system.js', $internalFilesOptions, array('id' => 'vbo-sys-script'));
50
51 if (JFactory::getApplication()->isAdmin())
52 {
53 /* Load assets for CSS and JS */
54 VikBooking::loadFontAwesome(true);
55
56 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'vikbooking.css', $internalFilesOptions, array('id' => 'vbo-style'));
57 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'fonts/vboicomoon.css', $internalFilesOptions, array('id' => 'vbo-icomoon-style'));
58 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'vikbooking_backendcustom.css', $internalFilesOptions, array('id' => 'vbo-custom-style'));
59
60 VikBooking::getVboApplication()->normalizeBackendStyles();
61
62 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'css/system.css', $internalFilesOptions, array('id' => 'vbo-sys-style'));
63 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'css/bootstrap.lite.css', $internalFilesOptions, array('id' => 'bootstrap-lite-style'));
64 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'js/bootstrap.min.js', $internalFilesOptions, array('id' => 'bootstrap-script'));
65
66 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'js/admin.js', $internalFilesOptions, array('id' => 'vbo-admin-script'));
67
68 /**
69 * Include the VBOCore JS class.
70 *
71 * @since 1.5.0
72 */
73 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'vbocore.js', $internalFilesOptions, array('id' => 'vbo-core-script'));
74
75 /**
76 * Always prepare AJAX requests to pass a CSRF token.
77 *
78 * @since 1.6.0
79 */
80 JHtml::fetch('vbohtml.scripts.ajaxcsrf');
81
82 /**
83 * Include the Toast JS class.
84 *
85 * @since 1.5.0
86 */
87 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'toast.js', $internalFilesOptions, array('id' => 'vbo-toast-script'));
88 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'toast.css', $internalFilesOptions, array('id' => 'vbo-toast-style'));
89
90 $document->addScriptDeclaration(
91 <<<JS
92 (function($) {
93 'use strict';
94
95 $(function() {
96 VBOToast.create(VBOToast.POSITION_TOP_RIGHT);
97 });
98 })(jQuery);
99 JS
100 );
101
102 /**
103 * Load necessary assets for WordPress >= 5.3
104 *
105 * @since 1.2.10
106 */
107 JLoader::import('adapter.application.version');
108 $wpv = new JVersion;
109 if (version_compare($wpv->getShortVersion(), '5.3', '>=')) {
110 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'css/bc/wp5.3.css', $internalFilesOptions, array('id' => 'vbo-wp-bc-style'));
111 }
112
113 /**
114 * Load the proper CSS file according to the appearance preferences.
115 *
116 * @since 1.5.0
117 */
118 VikBooking::loadAppearancePreferenceAssets();
119 }
120 else
121 {
122 if (VikBooking::loadBootstrap())
123 {
124 $document->addStyleSheet(VIKBOOKING_SITE_ASSETS_URI.'bootstrap.min.css', $internalFilesOptions, array('id' => 'vbo-bs-style'));
125 $document->addStyleSheet(VIKBOOKING_SITE_ASSETS_URI.'bootstrap-theme.min.css', $internalFilesOptions, array('id' => 'vbo-bstheme-style'));
126 }
127
128 VikBooking::loadFontAwesome();
129 $document->addStyleSheet(VIKBOOKING_SITE_ASSETS_URI.'vikbooking_styles.css', $internalFilesOptions, array('id' => 'vbo-style'));
130
131 /**
132 * Load the proper CSS file according to the appearance preferences.
133 * This is made after the main stylesheet and before the custom one.
134 *
135 * @since 1.5.0
136 */
137 VikBooking::loadAppearancePreferenceAssets();
138
139 $document->addStyleSheet(VIKBOOKING_SITE_ASSETS_URI.'vikbooking_custom.css', $internalFilesOptions, array('id' => 'vbo-custom-style'));
140 }
141 }
142
143 /**
144 * This method should be called only within the wp-admin section when
145 * the active page does not belong to the plugin Vik Booking. It loads
146 * the necessary CSS and JS assets to support browser notifications.
147 *
148 * @return void
149 *
150 * @since 1.5.0
151 */
152 public static function loadForExternal()
153 {
154 // loads only once
155 if (static::isLoaded(__METHOD__))
156 {
157 return;
158 }
159
160 // main library
161 require_once VBO_SITE_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'lib.vikbooking.php';
162
163 // load the necessary JS and CSS assets
164 $document = JFactory::getDocument();
165 $internalFilesOptions = array('version' => VIKBOOKING_SOFTWARE_VERSION);
166
167 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'vbocore.js', $internalFilesOptions, array('id' => 'vbo-core-script'));
168 $document->addScript(VIKBOOKING_ADMIN_ASSETS_URI . 'toast.js', $internalFilesOptions, array('id' => 'vbo-toast-script'));
169 $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'toast.css', $internalFilesOptions, array('id' => 'vbo-toast-style'));
170
171 /**
172 * Always prepare AJAX requests to pass a CSRF token.
173 *
174 * @since 1.6.0
175 */
176 JHtml::fetch('vbohtml.scripts.ajaxcsrf');
177
178 // build AJAX uri endpoints
179 $widget_ajax_uri = VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=exec_admin_widget');
180 $assets_ajax_uri = VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=widgets_get_assets');
181 $multitask_ajax_uri = VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=exec_multitask_widgets');
182 $watchdata_ajax_uri = VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=widgets_watch_data');
183 $current_page_uri = htmlspecialchars((string) JUri::getInstance(), ENT_QUOTES);
184
185 // check if the notification audio file exists within VCM
186 $notif_audio_path = implode(DIRECTORY_SEPARATOR, [VCM_ADMIN_PATH, 'assets', 'css', 'audio', 'new_notification.mp3']);
187 $notif_audio_url = is_file($notif_audio_path) ? (VCM_ADMIN_URI . implode('/', ['assets', 'css', 'audio', 'new_notification.mp3'])) : null;
188
189 // add the necessary script declaration
190 $document->addScriptDeclaration(
191 <<<JS
192 (function($) {
193 'use strict';
194
195 $(function() {
196
197 VBOToast.create(VBOToast.POSITION_TOP_RIGHT);
198
199 VBOCore.setOptions({
200 widget_ajax_uri: "$widget_ajax_uri",
201 assets_ajax_uri: "$assets_ajax_uri",
202 multitask_ajax_uri: "$multitask_ajax_uri",
203 watchdata_ajax_uri: "$watchdata_ajax_uri",
204 current_page: "wp-admin",
205 current_page_uri: "$current_page_uri",
206 notif_audio_url: "$notif_audio_url",
207 });
208
209 });
210 })(jQuery);
211 JS
212 );
213
214 // finally, preload the admin widgets
215 VikBooking::getAdminWidgetsInstance()->getWidgetNames($preload = true);
216
217 return;
218 }
219
220 /**
221 * Checks if the method has been already loaded.
222 * This function assumes that after this check we are going
223 * to use the specified method.
224 *
225 * A method is considered loaded only if the arguments used are the same.
226 *
227 * @param string $method The method to check for.
228 * @param array $args The list of arguments.
229 *
230 * @return boolean True if already used, otherwise false.
231 */
232 protected static function isLoaded($method, array $args = array())
233 {
234 // generate a unique signature containing the method name
235 // and the list of arguments to use
236 $sign = serialize(array($method, $args));
237
238 // check if the method has been already loaded
239 if (isset(static::$loaded[$sign]))
240 {
241 // already loaded
242 return true;
243 }
244
245 // mark the method as loaded
246 static::$loaded[$sign] = 1;
247
248 // not loaded
249 return false;
250 }
251 }
252