PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / core / wpbm-js.php

wpbm-js.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0, at core/wpbm-js.php

313 lines 13.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @package Booking Manager
4 * @category JavaScript files and varibales
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 19.10.2015
11 */
12
13 class WPBM_JS extends WPBM_JS_CSS {
14
15 public function define() {
16
17 $this->setType('js');
18
19 /*
20 $this->add( array(
21 'handle' => 'wpbm-datepick',
22 'src' => wpbm_plugin_url( '/js/datepick/jquery.datepick.js'),
23 'deps' => array( 'wpbm-global-vars' ),
24 'version' => '1.1',
25 'where_to_load' => array( 'admin', 'client' ), //Usage: array( 'admin', 'client' )
26 'condition' => false
27 ) );
28 */
29 }
30
31 /** Enqueue Files and Varibales.
32 * Useful in case, if we use get_options and current user functions...
33 *
34 * @param type $where_to_load
35 */
36 public function enqueue( $where_to_load ) {
37
38 wpbm_js_load_vars( $where_to_load );
39
40 // Define JavaScript varibales in all other files
41 do_action( 'wpbm_define_js_vars', $where_to_load );
42
43 wpbm_js_load_libs( $where_to_load );
44 wpbm_js_load_files( $where_to_load );
45
46 if ( wpbm_is_new_wpbm_page() )
47 $where_to_load = 'both';
48
49 // Load JavaScript files in all other versions
50 do_action( 'wpbm_enqueue_js_files', $where_to_load );
51 }
52
53 /** Deregister some conflict scripts from other plugins.
54 *
55 * @param type $where_to_load
56 */
57 public function remove_conflicts( $where_to_load ) {
58
59 if ( wpbm_is_master_page() ) {
60 if (function_exists('wp_dequeue_script')) {
61
62 //wp_dequeue_script( 'jquery.cookie' );
63 //wp_dequeue_script( 'jquery-interdependencies' );
64 wp_dequeue_script( 'chosen' );
65 wp_dequeue_script( 'cs-framework' );
66 wp_dequeue_script( 'cgmp-jquery-tools-tooltip' ); // Remove this script jquery.tools.tooltip.min.js, which is load by the "Comprehensive Google Map Plugin"
67 }
68 }
69
70 }
71 }
72
73
74
75 /** Define JavaScript Varibales */
76 function wpbm_js_load_vars( $where_to_load ) {
77
78 ////////////////////////////////////////////////////////////////////////////
79 // JavaScripts Variables
80 ////////////////////////////////////////////////////////////////////////////
81
82 wp_enqueue_script( 'wpbm-global-vars', wpbm_plugin_url( '/js/wpbm_vars.js' ), array( 'jquery' ), '1.1' ); // Blank JS File
83
84 wp_localize_script( 'wpbm-global-vars'
85 , 'wpbm_global1', array(
86 'wpbm_ajaxurl' => admin_url( 'admin-ajax.php' )
87 , 'wpbm_plugin_url' => plugins_url( '' , WPBM_FILE )
88 , 'wpbm_today' => '[' . intval(date_i18n('Y')) //FixIn:6.1
89 .','. intval(date_i18n('m'))
90 .','. intval(date_i18n('d'))
91 .','. intval(date_i18n('H'))
92 .','. intval(date_i18n('i'))
93 .']'
94 , 'wpbm_plugin_filename' => WPBM_PLUGIN_FILENAME
95 , 'message_verif_requred' => esc_js(__('This field is required' , 'booking-manager'))
96 , 'message_verif_requred_for_check_box' => esc_js(__('This checkbox must be checked' , 'booking-manager'))
97 , 'message_verif_requred_for_radio_box' => esc_js(__('At least one option must be selected' , 'booking-manager'))
98 , 'message_verif_emeil' => esc_js(__('Incorrect email field' , 'booking-manager'))
99 , 'message_verif_same_emeil' => esc_js(__('Your emails do not match' , 'booking-manager')) // Email Addresses Do Not Match
100
101 , 'wpbm_active_locale' => wpbm_get_locale()
102 , 'wpbm_message_processing' => esc_js( __('Processing' , 'booking-manager') )
103 , 'wpbm_message_deleting' => esc_js( __('Deleting' , 'booking-manager') )
104 , 'wpbm_message_updating' => esc_js( __('Updating' , 'booking-manager') )
105 , 'wpbm_message_saving' => esc_js( __('Saving' , 'booking-manager') )
106 ));
107
108 }
109
110
111 /** Default JavaScripts Libraries */
112 function wpbm_js_load_libs( $where_to_load ) {
113
114 // jQuery
115 wp_enqueue_script( 'jquery' );
116
117 $version = wpbm_get_registered_jquery_version();
118
119 if ( $version !== false ) {
120
121 if ( version_compare( $version, '1.9.1', '<' ) ) { // load jQuery 1.7.1, if "Theme" load older jQuery //FixIn: 7.0.1.3
122 wp_deregister_script('jquery');
123 wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.9.1.min.js', false, '1.9.1' ); //FixIn: 7.0.1.3
124 // wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.min.js', false, false);
125 wp_enqueue_script('jquery');
126
127 wp_register_script('jquery-migrate', 'http://code.jquery.com/jquery-migrate-1.0.0.js', false, '1.0.0' ); //FixIn: 7.0.1.3
128 wp_enqueue_script( 'jquery-migrate' ); //FixIn: 7.0.1.3
129 }
130
131 ////////////////////////////////////////////////////////////////////////
132 // jQuery Migrate
133 if ( version_compare( $version, '1.9', '>=' ) ) { // if the jQuery newer then 1.9
134 wp_register_script('jquery-migrate', 'http://code.jquery.com/jquery-migrate-1.0.0.js', false, '1.0.0' );
135 wp_enqueue_script( 'jquery-migrate' );
136 }
137 }
138
139
140 // Default Admin Libs
141 if ( ( $where_to_load == 'admin' )
142 // || ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) )
143 ) {
144
145 wp_enqueue_media();
146
147 wp_enqueue_script('thickbox');
148 // Load thickbox CSS
149 wp_enqueue_style('thickbox');
150
151 wp_enqueue_style( 'wp-color-picker' ); // Color Picker
152 wp_enqueue_script( 'wp-color-picker' );
153 wp_enqueue_script( 'jquery-ui-sortable' ); // UI Sortable
154 // if ( wpbm_is_master_page() )
155 // wp_enqueue_script( 'jquery-ui-dialog' ); // UI Dialog - for payment request dialog
156 }
157
158 }
159
160
161 /** Load JavaScript Files */
162 function wpbm_js_load_files( $where_to_load ) {
163
164 // Bootstrap
165 if ( ( ( is_admin() ) && ( get_wpbm_option( 'wpbm_is_not_load_bs_script_in_admin' ) !== 'On') )
166 // || ( ( ! is_admin() ) && ( get_wpbm_option( 'wpbm_is_not_load_bs_script_in_client' ) !== 'On' ) )
167 ) {
168 wp_enqueue_script( 'wpdevelop-bootstrap', wpbm_plugin_url( '/assets/libs/bootstrap/js/bootstrap.js' ), array( 'wpbm-global-vars' ), '3.3.5.1');
169 }
170
171 // Datepicker
172 // wp_enqueue_script( 'wpbm-datepick', wpbm_plugin_url( '/js/datepick/jquery.datepick.js'), array( 'wpbm-global-vars' ), '1.1');
173
174 // Localization
175 // $calendar_localization_url = wpbm_get_calendar_localization_url();
176 // if ( ! empty( $calendar_localization_url ) )
177 // wp_enqueue_script( 'wpbm-datepick-localize', $calendar_localization_url, array( 'wpbm-datepick' ), '1.1');
178 //wpbm_load_calendar_localization_file();
179
180 if ( ( $where_to_load == 'client' ) || ( wpbm_is_new_wpbm_page() ) ) {
181
182 // Client
183 // wp_enqueue_script( 'wpbm-main-client', wpbm_plugin_url( '/js/client.js'), array( 'wpbm-datepick' ), '1.1');
184 }
185
186 if ( $where_to_load == 'admin' ) {
187
188 // Admin
189 wp_enqueue_script( 'wpbm-admin-main', wpbm_plugin_url( '/js/admin.js'), array( 'wpbm-global-vars' ), '1.1');
190 wp_enqueue_script( 'wpbm-admin-support', wpbm_plugin_url( '/core/any/js/admin-support.js'), array( 'wpbm-global-vars' ), '1.1');
191
192 // Chosen Library
193 wp_enqueue_script( 'wpbm-chosen', wpbm_plugin_url( '/assets/libs/chosen/chosen.jquery.min.js'), array( 'wpbm-global-vars' ), '1.1' );
194 }
195
196 }
197
198
199
200 ////////////////////////////////////////////////////////////////////////////////
201 // Support JavaScript functions
202 ////////////////////////////////////////////////////////////////////////////////
203
204 /** Load Datepicker Localization JS File */
205 /*
206 function wpbm_load_calendar_localization_file() {
207
208 // Datepicker Localization - translation for calendar. Example: $locale = 'fr_FR';
209 $locale = wpbm_get_locale();
210 if ( ! empty( $locale ) ) {
211
212 $locale_lang = substr( $locale, 0, 2 );
213 $locale_country = substr( $locale, 3 );
214
215 if ( ( $locale_lang !== 'en') && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-' . $locale_lang . '.js' ) ) ) {
216
217 wp_enqueue_script( 'wpbm-datepick-localize', wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_lang . '.js' ), array( 'wpbm-datepick' ), '1.1');
218
219 } else if ( ( ! in_array( $locale, array( 'en_US', 'en_CA', 'en_GB', 'en_AU' ) ) ) // English Exceptions
220 && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-'. $locale_country . '.js' ) )
221 ) {
222
223 wp_enqueue_script( 'wpbm-datepick-localize', wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_country . '.js' ), array( 'wpbm-datepick' ), '1.1');
224 }
225 }
226 }*/
227
228
229 /** Get URL Datepicker Localization JS File
230 *
231 * @return string - URL to calendar skin
232 */
233 /*
234 function wpbm_get_calendar_localization_url() {
235 // Datepicker Localization - translation for calendar. Example: $locale = 'fr_FR';
236 $locale = wpbm_get_locale();
237
238 $calendar_localization_url = false;
239
240 if ( ! empty( $locale ) ) {
241
242 $locale_lang = substr( $locale, 0, 2 );
243 $locale_country = substr( $locale, 3 );
244
245 if ( ( $locale_lang !== 'en') && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-' . $locale_lang . '.js' ) ) ) {
246
247 $calendar_localization_url = wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_lang . '.js' );
248
249 } else if ( ( ! in_array( $locale, array( 'en_US', 'en_CA', 'en_GB', 'en_AU' ) ) ) // English Exceptions
250 && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-'. $locale_country . '.js' ) )
251 ) {
252
253 $calendar_localization_url = wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_country . '.js' );
254 }
255 }
256
257 return $calendar_localization_url;
258 }
259 */
260
261 /** Get Registred jQuery version
262 *
263 * @global type $wp_scripts
264 * @return string - jQuery version
265 */
266 function wpbm_get_registered_jquery_version() {
267 global $wp_scripts;
268
269 $version = false;
270
271 if ( is_a( $wp_scripts, 'WP_Scripts' ) )
272 if (isset( $wp_scripts->registered['jquery'] ))
273 $version = $wp_scripts->registered['jquery']->ver;
274 return $version;
275 }
276
277
278 /** Check if we activated loading of JS/CSS only on specific pages and then load or no it
279 *
280 * @param boolean $is_load_scripts - Default: true
281 * @return boolean - true | false
282 */
283 function wpbm_is_load_css_js_on_client_page( $is_load_scripts ) {
284
285 return true;
286
287 if ( ! is_admin() ) { // Check on Client side only
288
289 $wpbm_is_load_js_css_on_specific_pages = get_wpbm_option( 'wpbm_is_load_js_css_on_specific_pages' );
290 if ( $wpbm_is_load_js_css_on_specific_pages == 'On' ) {
291
292 $wpbm_pages_for_load_js_css = get_wpbm_option( 'wpbm_pages_for_load_js_css' );
293
294 $wpbm_pages_for_load_js_css = preg_split('/[\r\n]+/', $wpbm_pages_for_load_js_css, -1, PREG_SPLIT_NO_EMPTY);
295
296 $request_uri = $_SERVER['REQUEST_URI']; // FixIn:5.4.1
297 if ( strpos( $request_uri, 'wpbm_hash=') !== false ) {
298 $request_uri = parse_url($request_uri);
299 if ( ( ! empty($request_uri ) ) && ( isset($request_uri['path'] ) ) ){
300 $request_uri = $request_uri['path'];
301 } else {
302 $request_uri = $_SERVER['REQUEST_URI'];
303 }
304 }
305
306 if ( ( ! empty($wpbm_pages_for_load_js_css ) ) && ( ! in_array( $request_uri, $wpbm_pages_for_load_js_css ) ) )
307 return false;
308 }
309 }
310 return true;
311 }
312 add_filter( 'wpbm_is_load_script_on_this_page', 'wpbm_is_load_css_js_on_client_page' );
313