PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / trunk
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar vtrunk
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 trunk, at core/wpbm-js.php

291 lines 12.0 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 https://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 address' , '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
118 // Default Admin Libs
119 if ( ( $where_to_load == 'admin' )
120 // || ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) )
121 ) {
122
123 wp_enqueue_media();
124
125 wp_enqueue_script('thickbox');
126 // Load thickbox CSS
127 wp_enqueue_style('thickbox');
128
129 wp_enqueue_style( 'wp-color-picker' ); // Color Picker
130 wp_enqueue_script( 'wp-color-picker' );
131 wp_enqueue_script( 'jquery-ui-sortable' ); // UI Sortable
132 // if ( wpbm_is_master_page() )
133 // wp_enqueue_script( 'jquery-ui-dialog' ); // UI Dialog - for payment request dialog
134 }
135
136 }
137
138
139 /** Load JavaScript Files */
140 function wpbm_js_load_files( $where_to_load ) {
141
142 // Bootstrap
143 if ( ( ( is_admin() ) && ( get_wpbm_option( 'wpbm_is_not_load_bs_script_in_admin' ) !== 'On') )
144 // || ( ( ! is_admin() ) && ( get_wpbm_option( 'wpbm_is_not_load_bs_script_in_client' ) !== 'On' ) )
145 ) {
146 wp_enqueue_script( 'wpdevelop-bootstrap', wpbm_plugin_url( '/assets/libs/bootstrap/js/bootstrap.js' ), array( 'wpbm-global-vars' ), '3.3.5.1');
147 }
148
149 // Datepicker
150 // wp_enqueue_script( 'wpbm-datepick', wpbm_plugin_url( '/js/datepick/jquery.datepick.js'), array( 'wpbm-global-vars' ), '1.1');
151
152 // Localization
153 // $calendar_localization_url = wpbm_get_calendar_localization_url();
154 // if ( ! empty( $calendar_localization_url ) )
155 // wp_enqueue_script( 'wpbm-datepick-localize', $calendar_localization_url, array( 'wpbm-datepick' ), '1.1');
156 //wpbm_load_calendar_localization_file();
157
158 if ( ( $where_to_load == 'client' ) || ( wpbm_is_new_wpbm_page() ) ) {
159
160 // Client
161 // wp_enqueue_script( 'wpbm-main-client', wpbm_plugin_url( '/js/client.js'), array( 'wpbm-datepick' ), '1.1');
162 }
163
164 if ( $where_to_load == 'admin' ) {
165
166 // Admin
167 wp_enqueue_script( 'wpbm-admin-main', wpbm_plugin_url( '/js/admin.js'), array( 'wpbm-global-vars' ), '1.1');
168 wp_enqueue_script( 'wpbm-admin-support', wpbm_plugin_url( '/core/any/js/admin-support.js'), array( 'wpbm-global-vars' ), '1.1');
169
170 // Chosen Library
171 //wp_enqueue_script( 'wpbm-chosen', wpbm_plugin_url( '/assets/libs/chosen/chosen.jquery.min.js'), array( 'wpbm-global-vars' ), '1.1' );
172 }
173
174 }
175
176
177
178 ////////////////////////////////////////////////////////////////////////////////
179 // Support JavaScript functions
180 ////////////////////////////////////////////////////////////////////////////////
181
182 /** Load Datepicker Localization JS File */
183 /*
184 function wpbm_load_calendar_localization_file() {
185
186 // Datepicker Localization - translation for calendar. Example: $locale = 'fr_FR';
187 $locale = wpbm_get_locale();
188 if ( ! empty( $locale ) ) {
189
190 $locale_lang = substr( $locale, 0, 2 );
191 $locale_country = substr( $locale, 3 );
192
193 if ( ( $locale_lang !== 'en') && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-' . $locale_lang . '.js' ) ) ) {
194
195 wp_enqueue_script( 'wpbm-datepick-localize', wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_lang . '.js' ), array( 'wpbm-datepick' ), '1.1');
196
197 } else if ( ( ! in_array( $locale, array( 'en_US', 'en_CA', 'en_GB', 'en_AU' ) ) ) // English Exceptions
198 && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-'. $locale_country . '.js' ) )
199 ) {
200
201 wp_enqueue_script( 'wpbm-datepick-localize', wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_country . '.js' ), array( 'wpbm-datepick' ), '1.1');
202 }
203 }
204 }*/
205
206
207 /** Get URL Datepicker Localization JS File
208 *
209 * @return string - URL to calendar skin
210 */
211 /*
212 function wpbm_get_calendar_localization_url() {
213 // Datepicker Localization - translation for calendar. Example: $locale = 'fr_FR';
214 $locale = wpbm_get_locale();
215
216 $calendar_localization_url = false;
217
218 if ( ! empty( $locale ) ) {
219
220 $locale_lang = substr( $locale, 0, 2 );
221 $locale_country = substr( $locale, 3 );
222
223 if ( ( $locale_lang !== 'en') && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-' . $locale_lang . '.js' ) ) ) {
224
225 $calendar_localization_url = wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_lang . '.js' );
226
227 } else if ( ( ! in_array( $locale, array( 'en_US', 'en_CA', 'en_GB', 'en_AU' ) ) ) // English Exceptions
228 && ( wpbm_is_file_exist( '/js/datepick/jquery.datepick-'. $locale_country . '.js' ) )
229 ) {
230
231 $calendar_localization_url = wpbm_plugin_url( '/js/datepick/jquery.datepick-'. $locale_country . '.js' );
232 }
233 }
234
235 return $calendar_localization_url;
236 }
237 */
238
239 /** Get Registred jQuery version
240 *
241 * @global type $wp_scripts
242 * @return string - jQuery version
243 */
244 function wpbm_get_registered_jquery_version() {
245 global $wp_scripts;
246
247 $version = false;
248
249 if ( is_a( $wp_scripts, 'WP_Scripts' ) )
250 if (isset( $wp_scripts->registered['jquery'] ))
251 $version = $wp_scripts->registered['jquery']->ver;
252 return $version;
253 }
254
255
256 /** Check if we activated loading of JS/CSS only on specific pages and then load or no it
257 *
258 * @param boolean $is_load_scripts - Default: true
259 * @return boolean - true | false
260 */
261 function wpbm_is_load_css_js_on_client_page( $is_load_scripts ) {
262
263 return true;
264
265 if ( ! is_admin() ) { // Check on Client side only
266
267 $wpbm_is_load_js_css_on_specific_pages = get_wpbm_option( 'wpbm_is_load_js_css_on_specific_pages' );
268 if ( $wpbm_is_load_js_css_on_specific_pages == 'On' ) {
269
270 $wpbm_pages_for_load_js_css = get_wpbm_option( 'wpbm_pages_for_load_js_css' );
271
272 $wpbm_pages_for_load_js_css = preg_split('/[\r\n]+/', $wpbm_pages_for_load_js_css, -1, PREG_SPLIT_NO_EMPTY);
273
274 $request_uri = $_SERVER['REQUEST_URI']; // FixIn:5.4.1
275 if ( strpos( $request_uri, 'wpbm_hash=') !== false ) {
276 $request_uri = parse_url($request_uri);
277 if ( ( ! empty($request_uri ) ) && ( isset($request_uri['path'] ) ) ){
278 $request_uri = $request_uri['path'];
279 } else {
280 $request_uri = $_SERVER['REQUEST_URI'];
281 }
282 }
283
284 if ( ( ! empty($wpbm_pages_for_load_js_css ) ) && ( ! in_array( $request_uri, $wpbm_pages_for_load_js_css ) ) )
285 return false;
286 }
287 }
288 return true;
289 }
290 add_filter( 'wpbm_is_load_script_on_this_page', 'wpbm_is_load_css_js_on_client_page' );
291