PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.1.7
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.1.7
2.1.22 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 All 56 releases
booking-manager / core / wpbm-functions.php

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

2,192 lines 75.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Manager
5 * @subpackage Support Functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://oplugins.com/
10 * @email [email protected]
11 *
12 * @modified 29.09.2015
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17
18 // <editor-fold defaultstate="collapsed" desc=" V e r s i o n s " >
19 ////////////////////////////////////////////////////////////////////////////////
20 // V e r s i o n s
21 ////////////////////////////////////////////////////////////////////////////////
22
23 /** Get version
24 *
25 * @return string
26 */
27 function get_wpbm_version(){
28 $version = 'free';
29 return $version;
30 }
31
32 /** Check if user accidentially update Booking Manager Paid version to Free
33 *
34 * @return bool
35 */
36 function wpbm_is_updated_paid_to_free() {
37
38 if ( ( wpbm_is_table_exists('wpbm_log') ) && ( ! class_exists('wpbm_personal') ) )
39 return true;
40 else
41 return false;
42 }
43
44 function wpbm_get_ver_sufix() {
45
46 if ( strpos( strtolower( WPBM_VERSION ), 'multisite' ) !== false ) {
47 $v_type = '-multi';
48 } else if ( strpos( strtolower( WPBM_VERSION ), 'develop' ) !== false ) {
49 $v_type = '-dev';
50 } else {
51 $v_type = '';
52 }
53 $v = '';
54 if ( class_exists( 'wpbm_personal' ) )
55 $v = 'ps' . $v_type;
56 if ( class_exists( 'wpbm_pro' ) )
57 $v = '';
58 return $v;
59 }
60
61 function wpbm_up_link() {
62 if ( ! wpbm_is_this_demo() )
63 $v = wpbm_get_ver_sufix();
64 else $v = '';
65 return 'https://oplugins.com/plugins/booking-manager/' . ( ( empty($v) ) ? '' : 'upgrade-' . $v . '/' ) ;
66 }
67
68 /** Check if this demo website
69 *
70 * @return bool
71 */
72 function wpbm_is_this_demo() {
73 //return ! true; //TODO: comment it. 2016-09-27 // Replaced!
74 if (
75 ( ( isset( $_SERVER['SCRIPT_FILENAME'] ) ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'oplugins.com' ) !== false ) )
76 || ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( strpos( $_SERVER['HTTP_HOST'], 'oplugins.com' ) !== false ) )
77 )
78 return true;
79 else
80 return false;
81 }
82
83 /** Get Warning Text for Demo websites */
84 function wpbm_get_warning_text_in_demo_mode() {
85
86 return '<div class="wpbm-settings-notice notice-warning"><strong>Warning!</strong> Demo test version does not allow changes to these items.</div>';
87 }
88
89 /** Show System Info (status) at item > Settings General page
90 * Link: http://server.com/wp-admin/admin.php?page=wpbm-settings&system_info=show#wpbm_general_settings_system_info_metabox
91 */
92 function wpbm_system_info() {
93
94 if ( wpbm_is_this_demo() ) return;
95
96 if ( current_user_can( 'activate_plugins' ) ) { // Only for Administrator or Super admin. More here: https://codex.wordpress.org/Roles_and_Capabilities
97
98 global $wpdb, $wp_version;
99
100 $all_plugins = get_plugins();
101 $active_plugins = get_option( 'active_plugins' );
102
103 $mysql_info = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
104 if ( is_array( $mysql_info ) ) $sql_mode = $mysql_info[0]->Value;
105 if ( empty( $sql_mode ) ) $sql_mode = 'Not set';
106
107 $safe_mode = ( ini_get( 'safe_mode' ) ) ? 'On' : 'Off';
108 $allow_url_fopen = ( ini_get( 'allow_url_fopen' ) ) ? 'On' : 'Off';
109 $upload_max_filesize = ( ini_get( 'upload_max_filesize' ) ) ? ini_get( 'upload_max_filesize' ) : 'N/A';
110 $post_max_size = ( ini_get( 'post_max_size' ) ) ? ini_get( 'post_max_size' ) : 'N/A';
111 $max_execution_time = ( ini_get( 'max_execution_time' ) ) ? ini_get( 'max_execution_time' ) : 'N/A';
112 $memory_limit = ( ini_get( 'memory_limit' ) ) ? ini_get( 'memory_limit' ) : 'N/A';
113 $memory_usage = ( function_exists( 'memory_get_usage' ) ) ? round( memory_get_usage() / 1024 / 1024, 2 ) . ' Mb' : 'N/A';
114 $exif_read_data = ( is_callable( 'exif_read_data' ) ) ? 'Yes' . " ( V" . substr( phpversion( 'exif' ), 0, 4 ) . ")" : 'No';
115 $iptcparse = ( is_callable( 'iptcparse' ) ) ? 'Yes' : 'No';
116 $xml_parser_create = ( is_callable( 'xml_parser_create' ) ) ? 'Yes' : 'No';
117 $theme = ( function_exists( 'wp_get_theme' ) ) ? wp_get_theme() : get_theme( get_current_theme() );
118
119 if ( function_exists( 'is_multisite' ) ) {
120 if ( is_multisite() ) $multisite = 'Yes';
121 else $multisite = 'No';
122 } else { $multisite = 'N/A';
123 }
124
125 $system_info = array(
126 'system_info' => '',
127 'php_info' => '',
128 'active_plugins' => array(), //FixIn: 2.0.25.1
129 'inactive_plugins' => array() //FixIn: 2.0.25.1
130 );
131
132 $ver_small_name = get_wpbm_version();
133 if ( class_exists( 'wpbm_multiuser' ) ) $ver_small_name = 'multiuser';
134
135 $system_info['system_info'] = array(
136 'Plugin Update' => ( defined( 'WPBM_VERSION' ) ) ? WPBM_VERSION : 'N/A',
137 'Plugin Version' => ucwords( $ver_small_name ),
138 'Plugin Update Date' => date( "Y-m-d", filemtime( WPBM_FILE ) ),
139
140 'WP Version' => $wp_version,
141 'WP DEBUG' => ( ( defined('WP_DEBUG') ) && ( WP_DEBUG ) ) ? 'On' : 'Off',
142 'WP DB Version' => get_option( 'db_version' ),
143 'Operating System' => PHP_OS,
144 'Server' => $_SERVER["SERVER_SOFTWARE"],
145 'PHP Version' => PHP_VERSION,
146 'PHP Safe Mode' => $safe_mode,
147 'MYSQL Version' => $wpdb->get_var( "SELECT VERSION() AS version" ),
148 'SQL Mode' => $sql_mode,
149 'Memory usage' => $memory_usage,
150 'Site URL' => get_option( 'siteurl' ),
151 'Home URL' => home_url(),
152 'SERVER[HTTP_HOST]' => $_SERVER['HTTP_HOST'],
153 'SERVER[SERVER_NAME]' => $_SERVER['SERVER_NAME'],
154 'Multisite' => $multisite,
155 'Active Theme' => $theme['Name'] . ' ' . $theme['Version']
156 );
157
158 $system_info['php_info'] = array(
159 'PHP Version' => PHP_VERSION,
160 'PHP Safe Mode' => $safe_mode,
161 'PHP Memory Limit' => '<strong>' . $memory_limit . '</strong>',
162 'PHP Max Script Execute Time' => '<strong>' . $max_execution_time . '</strong>',
163
164 'PHP Max Post Size' => '<strong>' . $post_max_size . '</strong>',
165 'PHP MAX Input Vars' => '<strong>' . ( ( ini_get( 'max_input_vars' ) ) ? ini_get( 'max_input_vars' ) : 'N/A' ) . '</strong>', //How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately).
166
167 'PHP Max Upload Size' => $upload_max_filesize,
168 'PHP Allow URL fopen' => $allow_url_fopen,
169 'PHP Exif support' => $exif_read_data,
170 'PHP IPTC support' => $iptcparse,
171 'PHP XML support' => $xml_parser_create
172 );
173
174 $system_info['php_info']['PHP cURL'] = ( function_exists('curl_init') ) ? 'On' : 'Off';
175 $system_info['php_info']['Max Nesting Level'] = ( ( ini_get( 'max_input_nesting_level' ) ) ? ini_get( 'max_input_nesting_level' ) : 'N/A' );
176 $system_info['php_info']['Max Time 4 script'] = ( ( ini_get( 'max_input_time' ) ) ? ini_get( 'max_input_time' ) : 'N/A' ); //Maximum amount of time each script may spend parsing request data
177 $system_info['php_info']['Log'] = ( ( ini_get( 'error_log' ) ) ? ini_get( 'error_log' ) : 'N/A' );
178
179 if ( ini_get( "suhosin.get.max_value_length" ) ) {
180
181 $system_info['suhosin_info'] = array();
182 $system_info['suhosin_info']['POST max_array_index_length'] = ( ( ini_get( 'suhosin.post.max_array_index_length' ) ) ? ini_get( 'suhosin.post.max_array_index_length' ) : 'N/A' );
183 $system_info['suhosin_info']['REQUEST max_array_index_length'] = ( ( ini_get( 'suhosin.request.max_array_index_length' ) ) ? ini_get( 'suhosin.request.max_array_index_length' ) : 'N/A' );
184
185 $system_info['suhosin_info']['POST max_totalname_length'] = ( ( ini_get( 'suhosin.post.max_totalname_length' ) ) ? ini_get( 'suhosin.post.max_totalname_length' ) : 'N/A' );
186 $system_info['suhosin_info']['REQUEST max_totalname_length'] = ( ( ini_get( 'suhosin.request.max_totalname_length' ) ) ? ini_get( 'suhosin.request.max_totalname_length' ) : 'N/A' );
187
188 $system_info['suhosin_info']['POST max_vars'] = ( ( ini_get( 'suhosin.post.max_vars' ) ) ? ini_get( 'suhosin.post.max_vars' ) : 'N/A' );
189 $system_info['suhosin_info']['REQUEST max_vars'] = ( ( ini_get( 'suhosin.request.max_vars' ) ) ? ini_get( 'suhosin.request.max_vars' ) : 'N/A' );
190
191 $system_info['suhosin_info']['POST max_value_length'] = ( ( ini_get( 'suhosin.post.max_value_length' ) ) ? ini_get( 'suhosin.post.max_value_length' ) : 'N/A' );
192 $system_info['suhosin_info']['REQUEST max_value_length'] = ( ( ini_get( 'suhosin.request.max_value_length' ) ) ? ini_get( 'suhosin.request.max_value_length' ) : 'N/A' );
193
194 $system_info['suhosin_info']['POST max_name_length'] = ( ( ini_get( 'suhosin.post.max_name_length' ) ) ? ini_get( 'suhosin.post.max_name_length' ) : 'N/A' );
195 $system_info['suhosin_info']['REQUEST max_varname_length'] = ( ( ini_get( 'suhosin.request.max_varname_length' ) ) ? ini_get( 'suhosin.request.max_varname_length' ) : 'N/A' );
196
197 $system_info['suhosin_info']['POST max_array_depth'] = ( ( ini_get( 'suhosin.post.max_array_depth' ) ) ? ini_get( 'suhosin.post.max_array_depth' ) : 'N/A' );
198 $system_info['suhosin_info']['REQUEST max_array_depth'] = ( ( ini_get( 'suhosin.request.max_array_depth' ) ) ? ini_get( 'suhosin.request.max_array_depth' ) : 'N/A' );
199 }
200
201
202 if ( function_exists('gd_info') ) {
203 $gd_info = gd_info();
204 if ( isset( $gd_info['GD Version'] ) )
205 $gd_info = $gd_info['GD Version'];
206 else
207 $gd_info = json_encode( $gd_info );
208 } else {
209 $gd_info = 'Off';
210 }
211 $system_info['php_info']['PHP GD'] = $gd_info;
212
213 // More here https://docs.woocommerce.com/document/problems-with-large-amounts-of-data-not-saving-variations-rates-etc/
214
215
216 foreach ( $all_plugins as $path => $plugin ) {
217
218 if ( is_plugin_active( $path ) ) {
219 $system_info['active_plugins'][ $plugin['Name'] ] = $plugin['Version'];
220 } else {
221 $system_info['inactive_plugins'][ $plugin['Name'] ] = $plugin['Version'];
222 }
223 }
224
225 // Showing
226 foreach ( $system_info as $section_name => $section_values ) {
227 ?>
228 <span class="wpdevelop">
229 <table class="table table-striped table-bordered">
230 <thead><tr><th colspan="2" style="border-bottom: 1px solid #eeeeee;padding: 10px;"><?php echo strtoupper( $section_name ); ?></th></tr></thead>
231 <tbody>
232 <?php
233 if ( !empty( $section_values ) ) {
234 foreach ( $section_values as $key => $value ) {
235 ?>
236 <tr>
237 <td scope="row" style="width:18em;padding:4px 8px;"><?php echo $key; ?></td>
238 <td scope="row" style="padding:4px 8px;"><?php echo $value; ?></td>
239 </tr>
240 <?php
241 }
242 }
243 ?>
244 </tbody>
245 </table>
246 </span>
247 <div class="clear"></div>
248 <?php
249 }
250 ?>
251 <hr>
252 <div style="color:#777;">
253 <h4 style="font-size:1.1em;">Commonly required configuration vars in php.ini file:</h4>
254 <h4>General section:</h4>
255 <pre><code>memory_limit = 256M
256 max_execution_time = 120
257 post_max_size = 8M
258 upload_max_filesize = 8M
259 max_input_vars = 20480
260 post_max_size = 64M</code></pre>
261 <h4>Suhosin section (if installed):</h4>
262 <pre><code>suhosin.post.max_array_index_length = 1024
263 suhosin.post.max_totalname_length = 65535
264 suhosin.post.max_vars = 2048
265 suhosin.post.max_value_length = 1000000
266 suhosin.post.max_name_length = 256
267 suhosin.post.max_array_depth = 1000
268 suhosin.request.max_array_index_length = 1024
269 suhosin.request.max_totalname_length = 65535
270 suhosin.request.max_vars = 2048
271 suhosin.request.max_value_length = 1000000
272 suhosin.request.max_varname_length = 256
273 suhosin.request.max_array_depth = 1000</code></pre>
274 </div>
275 <?php
276 // phpinfo();
277 }
278 }
279
280
281
282 /** Check if "Booking Calendar" installed/activated and return version number
283 *
284 * @return string - 0 if not installed, otherwise version num
285 */
286 function wpbm_get_wpbc_version() {
287
288 if ( ! defined( 'WP_BK_VERSION_NUM' ) )
289 return 0;
290 else
291 return WP_BK_VERSION_NUM;
292 }
293
294 /** Is activated Booking Calendar support WPBM
295 *
296 * @return boolean
297 */
298 function wpbm_is_wpbc_supported() {
299
300 // 7.2.1 - its start version of Booking Calendar which support integration with Booking Manager 2.0
301
302 if ( version_compare( wpbm_get_wpbc_version(), '9.8') >= 0 ) {
303 return true;
304 } else {
305 return false;
306 }
307 }
308
309 // </editor-fold>
310
311
312 // <editor-fold defaultstate="collapsed" desc=" F o r m a t t i n g " >
313 ////////////////////////////////////////////////////////////////////////////////
314 // F o r m a t t i n g
315 ////////////////////////////////////////////////////////////////////////////////
316 /**
317 * Sanitize term to Slug format (no spaces, lowercase).
318 * urldecode - reverse munging of UTF8 characters.
319 *
320 * @param mixed $value
321 * @return string
322 */
323 function wpbm_get_slug_format( $value ) {
324 return urldecode( sanitize_title( $value ) );
325 }
326
327 /**
328 * Get Slug Format Option Value for saving to the options table.
329 * Replacing - to _ and restrict length to 64 characters.
330 *
331 * @param string $value
332 * @return string
333 */
334 function wpbm_get_slug_format_4_option_name( $value ) {
335
336 $value = wpbm_get_slug_format( $value );
337 $value = str_replace('-', '_', $value);
338 $value = substr($value, 0, 64);
339 return $value;
340 }
341
342 /** Insert New Line symbols after <br> tags. Usefull for the settings pages to show in redable view
343 *
344 * @param type $param
345 * @return type
346 */
347 function wpbm_nl_after_br($param) {
348
349 $value = preg_replace( "@(&lt;|<)br\s*/?(&gt;|>)(\r\n)?@", "<br/>", $param );
350
351 return $value;
352 }
353
354 /**
355 * Replace ** to <strong> and * to <em>
356 *
357 * @param String $text
358 * @return string
359 */
360 if ( ! function_exists( 'wpbm_recheck_strong_symbols' ) ) {
361 function wpbm_recheck_strong_symbols( $text ){
362
363 $patterns = '/(\*\*)(\s*[^\*\*]*)(\*\*)/';
364 $replacement = '<strong>${2}</strong>';
365 $value_return = preg_replace($patterns, $replacement, $text);
366
367 $patterns = '/(\*)(\s*[^\*]*)(\*)/';
368 $replacement = '<em>${2}</em>';
369 $value_return = preg_replace($patterns, $replacement, $value_return);
370
371 return $value_return;
372 }
373 }
374
375
376 /** Esacpe and replace any HTML entities
377 *
378 * @param type $string
379 * @return string
380 */
381 function wpbm_esc_to_plain_text( $string ) {
382
383 // //Replace <a href="http://server.com">Link</a> to Link( http://server.com )
384 // $pattern = "/<a(.*)+href=[\"|']+([^\"']+)(?=(\"|'))[^>]*>(.*)<\/a>/" ; //"/(?<=href=(\"|'))[^\"']+(?=(\"|'))/i";
385 // $newurl = "$4 ($2)";
386 // $string = preg_replace($pattern,$newurl,$string);
387
388
389 // List of preg* regular expression patterns to search for replace in plain emails. More: https://raw.github.com/ushahidi/wp-silcc/master/class.html2text.inc
390 $plain_search_array = array(
391 "/\r/", // Non-legal carriage return
392 '/&(nbsp|#160);/i', // Non-breaking space
393 '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148|#34|#034);/i', // Double quotes //FixIn: 2.0.1.6
394 '/&(apos|rsquo|lsquo|#8216|#8217|#39|#039);/i', // Single quotes //FixIn: 2.0.1.6
395 '/&gt;/i', // Greater-than
396 '/&lt;/i', // Less-than
397 '/&#38;/i', // Ampersand
398 '/&#038;/i', // Ampersand
399 '/&amp;/i', // Ampersand
400 '/&(copy|#169);/i', // Copyright
401 '/&(trade|#8482|#153);/i', // Trademark
402 '/&(reg|#174);/i', // Registered
403 '/&(mdash|#151|#8212);/i', // mdash
404 '/&(ndash|minus|#8211|#8722);/i', // ndash
405 '/&(bull|#149|#8226);/i', // Bullet
406 '/&(pound|#163);/i', // Pound sign
407 '/&(euro|#8364);/i', // Euro sign
408 '/&#36;/', // Dollar sign
409 '/&[^&;]+;/i', // Unknown/unhandled entities
410 '/[ ]{2,}/' // Runs of spaces, post-handling
411 );
412
413 // List of symbols for Replace
414 $get_plain_replace_array = array(
415 '', // Non-legal carriage return
416 ' ', // Non-breaking space
417 '"', // Double quotes
418 "'", // Single quotes
419 '>', // Greater-than
420 '<', // Less-than
421 '&', // Ampersand
422 '&', // Ampersand
423 '&', // Ampersand
424 '(c)', // Copyright
425 '(tm)', // Trademark
426 '(R)', // Registered
427 '--', // mdash
428 '-', // ndash
429 '*', // Bullet
430 '£', // Pound sign
431 'EUR', // Euro sign. € ?
432 '$', // Dollar sign
433 '', // Unknown/unhandled entities
434 ' ' // Runs of spaces, post-handling
435 );
436
437 $newstring = preg_replace( $plain_search_array, $get_plain_replace_array, strip_tags( $string ) );
438
439 return $newstring;
440 }
441 // </editor-fold>
442
443
444 // <editor-fold defaultstate="collapsed" desc=" S u p p o r t " >
445 ////////////////////////////////////////////////////////////////////////////////
446 // S u p p o r t Functions
447 ////////////////////////////////////////////////////////////////////////////////
448
449 /** Replace shortcodes in string
450 *
451 * @param string $subject - string to manipulate
452 * @param array $replace_array - array with values to replace // array( [wpbm_id] => 9, [id] => 9, [dates] => July 3, 2016 14:00 - July 4, 2016 16:00, .... )
453 * @param mixed $replace_unknown_shortcodes - replace unknown params, if false, then no replace unknown params
454 * @return string
455 */
456 function wpbm_replace_shortcodes( $subject, $replace_array , $replace_unknown_shortcodes = ' ' ) {
457
458 $defaults = array(
459 'ip' => apply_wpbm_filter( 'wpbm_get_user_ip' )
460 , 'blogname' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES )
461 , 'siteurl' => get_site_url()
462 );
463
464 $replace = wp_parse_args( $replace_array, $defaults );
465
466 foreach ( $replace as $replace_shortcode => $replace_value ) {
467
468 $subject = str_replace( array( '[' . $replace_shortcode . ']'
469 , '{' . $replace_shortcode . '}' )
470 , $replace_value
471 , $subject );
472 }
473
474 // Remove all shortcodes, which is not replaced early.
475 if ( $replace_unknown_shortcodes !== false )
476 $subject = preg_replace( '/[\s]{0,}[\[\{]{1}[a-zA-Z][0-9a-zA-Z:._-]{0,}[\]\}]{1}[\s]{0,}/', $replace_unknown_shortcodes, $subject );
477
478
479 return $subject;
480 }
481
482 /** Simple hack to make array strings lowercase
483 *
484 * @param type $array
485 * @return type
486 */
487 function wpbm_arraytolower( $array ){
488 return unserialize( strtolower( serialize( $array ) ) );
489 }
490
491 /** Support 'hash_equals' this function at older servers than PHP 5.6.0 */
492 if ( !function_exists( 'hash_equals' ) ) {
493 function hash_equals( $known_string, $user_string ) {
494 $ret = 0;
495
496 if ( strlen( $known_string ) !== strlen( $user_string ) ) {
497 $user_string = $known_string;
498 $ret = 1;
499 }
500
501 $res = $known_string ^ $user_string;
502
503 for ( $i = strlen( $res ) - 1; $i >= 0; --$i ) {
504 $ret |= ord( $res[$i] );
505 }
506
507 return !$ret;
508 }
509 }
510
511 /** Check if this valid timestamp
512 *
513 * @param string|int $timestamp
514 * @return bool
515 */
516 function wpbm_is_valid_timestamp( $timestamp ) {
517 return ( ( (string) (int) $timestamp === $timestamp)
518 && ($timestamp <= PHP_INT_MAX)
519 && ($timestamp >= ~PHP_INT_MAX)
520 );
521 }
522 // </editor-fold>
523
524
525 // <editor-fold defaultstate="collapsed" desc=" F i l e s && U R L s " >
526 ////////////////////////////////////////////////////////////////////////////////
527 // F i l e s && U R L s
528 ////////////////////////////////////////////////////////////////////////////////
529
530 /** Get absolute URL to relative plugin path.
531 * Depend from the WPBM_MIN contant can be load minified version of file, if its exist
532 * @param string $path - path
533 * @return string
534 */
535 function wpbm_plugin_url( $path ) {
536
537 if ( ( defined( 'WPBM_MIN' ) ) && ( WPBM_MIN ) ){
538 $path_min = $path;
539 if ( substr( $path_min , -3 ) === '.js' ) {
540 $path_min = substr( $path_min , 0, -3 ) . '.min.js';
541 }
542 if ( substr( $path_min , -4 ) === '.css' ) {
543 $path_min = substr( $path_min , 0, -4 ) . '.min.css';
544 }
545 if ( file_exists( trailingslashit( WPBM_PLUGIN_DIR ) . ltrim( $path_min, '/\\' ) ) ) // check if this file exist
546 return trailingslashit( WPBM_PLUGIN_URL ) . ltrim( $path_min, '/\\' );
547 }
548 return trailingslashit( WPBM_PLUGIN_URL ) . ltrim( $path, '/\\' );
549 }
550
551 /** Check if such file exist or not.
552 *
553 * @param string $path - relative path to file (relative to plugin folder).
554 * @return boolean true | false
555 */
556 function wpbm_is_file_exist( $path ) {
557
558 if ( file_exists( trailingslashit( WPBM_PLUGIN_DIR ) . ltrim( $path, '/\\' ) ) ) // check if this file exist
559 return true;
560 else
561 return false;
562 }
563
564 /** Set URL from absolute to relative (starting from /)
565 *
566 * @param type $url
567 * @return type
568 */
569 function wpbm_set_relative_url( $url ){
570
571 $url = esc_url_raw($url);
572
573 $url_path = parse_url($url, PHP_URL_PATH);
574 $url_path = ( empty($url_path) ? $url : $url_path );
575
576 $url = trim($url_path, '/');
577 return '/' . $url;
578 }
579
580 /** Get Correct Relative URL
581 *
582 * @param type $link
583 * @return string
584 */
585 function wpbm_make_link_relative( $link ){
586
587 if ( $link == get_option('siteurl') )
588 $link = '/';
589 $link = '/' . trim( wp_make_link_relative( $link ), '/' );
590
591 return $link;
592 }
593
594 /** Get Correct Absolute URL
595 *
596 * @param string $link
597 * @return type
598 */
599 function wpbm_make_link_absolute( $link ){
600
601 if ( ( $link != get_option('siteurl') ) && ( strpos($link, 'http') !== 0 ) )
602 $link = get_option('siteurl') . '/' . trim( wp_make_link_relative( $link ), '/' );
603 return esc_js( $link ) ;
604 }
605
606
607 if (!function_exists ('get_file_data_wpdev')) {
608
609 /** Get header info from this file, just for compatibility with WordPress 2.8 and older versions
610 *
611 * @param type $file
612 * @param type $default_headers
613 * @param type $context
614 * @return type
615 */
616 function get_file_data_wpdev( $file, $default_headers, $context = '' ) {
617 // We don't need to write to the file, so just open for reading.
618 $fp = fopen( $file, 'r' );
619
620 // Pull only the first 8kiB of the file in.
621 $file_data = fread( $fp, 8192 );
622
623 // PHP will close file handle, but we are good citizens.
624 fclose( $fp );
625
626 if( $context != '' ) {
627 $extra_headers = array(); //apply_filters( "extra_$context".'_headers', array() );
628
629 $extra_headers = array_flip( $extra_headers );
630 foreach( $extra_headers as $key=>$value ) {
631 $extra_headers[$key] = $key;
632 }
633 $all_headers = array_merge($extra_headers, $default_headers);
634 } else {
635 $all_headers = $default_headers;
636 }
637
638 foreach ( $all_headers as $field => $regex ) {
639 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
640 if ( !empty( ${$field} ) )
641 ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] ));
642 else
643 ${$field} = '';
644 }
645
646 $file_data = compact( array_keys( $all_headers ) );
647
648 return $file_data;
649 }
650 }
651
652
653 /** Get content from specific URL
654 *
655 * @param string $url
656 * @return string|boolean (false on error)
657 */
658 function wpbm_get_ssl_page_content( $url ) {
659
660 $request = new WP_Http();
661
662 $result = $request->request( $url
663 , array( // Default Parameters
664 'reject_unsafe_urls' => true, //FixIn: 2.0.29.1
665 'user-agent' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405' //FixIn: 2.0.12.1
666 // 'method' => 'GET',
667 // 'timeout' => 5, // timeout value for an HTTP request.
668 // 'redirection' => 5, // number of redirects allowed during an HTTP request.
669 // 'httpversion' => '1.0',
670 // 'user-agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ),
671 // 'reject_unsafe_urls' => false,
672 // 'blocking' => true,
673 // 'headers' => array(),
674 // 'cookies' => array(),
675 // 'body' => null,
676 // 'compress' => false,
677 // 'decompress' => true,
678 // 'sslverify' => true,
679 // 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
680 // 'stream' => false,
681 // 'filename' => null,
682 // 'limit_response_size' => null
683 )
684 );
685
686 if (
687 ( ! is_wp_error( $result ) )
688 && ( $result[ 'response' ][ 'code' ] == '200' )
689 ) {
690
691 return $result[ 'body' ];
692
693 } else {
694
695 //FixIn: 2.0.2.2
696 if ( is_wp_error( $result ) ) {
697 $error_message = $result->get_error_message();
698 } else {
699 $error_message = __( 'Unknown error during downloading feed', 'booking-manager' );
700
701 // Show more detail info of not ability to download .ics feeds. //FixIn: 2.0.10.5
702 $error_message .= $result[ 'body' ];
703 //do_action( 'wpbc_admin_show_top_notice', $error_message, 'error', 5000 );
704 //die;
705 }
706 do_action( 'wpbc_admin_show_top_notice', $error_message, 'error', 5000 ); // N_O_T_I_C_E in H_E_A_D_E_R
707 // debuge($error_message); //FixIn: 2.0.1.3 //FixIn: 2.0.8.2
708
709 return false;
710 }
711 }
712
713
714
715 /** Count the number of bytes of a given string.
716 * Input string is expected to be ASCII or UTF-8 encoded.
717 * Warning: the function doesn't return the number of chars
718 * in the string, but the number of bytes.
719 * See http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
720 * for information on UTF-8.
721 *
722 * @param string $str The string to compute number of bytes
723 *
724 * @return The length in bytes of the given string.
725 */
726 function wpbm_get_bytes_from_str( $str ) {
727 // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
728 // Number of characters in string
729 $strlen_var = strlen( $str );
730
731 $d = 0; // string bytes counter
732
733 // Iterate over every character in the string, escaping with a slash or encoding to UTF-8 where necessary
734 for ( $c = 0; $c < $strlen_var; ++ $c ) {
735 $ord_var_c = ord( $str[$c] ); //FixIn: 2.0.17.1
736 switch ( true ) {
737 case(($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): // characters U-00000000 - U-0000007F (same as ASCII)
738 $d ++;
739 break;
740 case(($ord_var_c & 0xE0) == 0xC0): // characters U-00000080 - U-000007FF, mask 110XXXXX
741 $d += 2;
742 break;
743 case(($ord_var_c & 0xF0) == 0xE0): // characters U-00000800 - U-0000FFFF, mask 1110XXXX
744 $d += 3;
745 break;
746 case(($ord_var_c & 0xF8) == 0xF0): // characters U-00010000 - U-001FFFFF, mask 11110XXX
747 $d += 4;
748 break;
749 case(($ord_var_c & 0xFC) == 0xF8): // characters U-00200000 - U-03FFFFFF, mask 111110XX
750 $d += 5;
751 break;
752 case(($ord_var_c & 0xFE) == 0xFC): // characters U-04000000 - U-7FFFFFFF, mask 1111110X
753 $d += 6;
754 break;
755 default:
756 $d ++;
757 }
758 }
759 return $d;
760 }
761
762
763 // </editor-fold>
764
765
766 // <editor-fold defaultstate="collapsed" desc=" A d m i n M e n u L i n k s " >
767 ////////////////////////////////////////////////////////////////////////////
768 // A d m i n M e n u L i n k s
769 ////////////////////////////////////////////////////////////////////////////
770
771 /** Get URL to specific Admin Menu page
772 *
773 * @param string $menu_type - { item | add | resources | settings }
774 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
775 * @return string - URL to menu
776 */
777 function wpbm_get_menu_url( $menu_type, $is_absolute_url = true ) {
778
779 switch ( $menu_type) {
780
781 case 'master': // Master
782 $link = 'oplugins&tab=wpbm';
783 break;
784
785 case 'add': // Add New
786 case 'new': // Add New
787 $link = 'oplugins&wpbm-new';
788 break;
789
790 case 'settings': // Settings
791 case 'options':
792 $link = 'oplugins&tab=wpbm-settings';
793 break;
794
795 default: // Master
796 $link = 'oplugins';
797 break;
798 }
799
800 if ( $is_absolute_url ) {
801 $link = admin_url( 'admin.php' ) . '?page=' . $link ;
802 }
803
804 return $link;
805 }
806
807 // // // // // // // // // // // // // // // // // // // // // // // // // /
808
809 /** Get URL of item Listing or Calendar Overview page
810 *
811 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
812 * @param boolean $is_old - { default: true }
813 * @return string - URL to menu
814 */
815 function wpbm_get_master_url( $is_absolute_url = true ) {
816 return wpbm_get_menu_url( 'master', $is_absolute_url );
817 }
818
819 /** Get URL of item > Add item page
820 *
821 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
822 * @param boolean $is_old - { default: true }
823 * @return string - URL to menu
824 */
825 function wpbm_get_new_wpbm_url( $is_absolute_url = true ) {
826 return wpbm_get_menu_url( 'add', $is_absolute_url );
827 }
828
829 /** Get URL of item > Settings page
830 *
831 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
832 * @param boolean $is_old - { default: true }
833 * @return string - URL to menu
834 */
835 function wpbm_get_settings_url( $is_absolute_url = true ) {
836 return wpbm_get_menu_url( 'settings', $is_absolute_url );
837 }
838
839 // // // // // // // // // // // // // // // // // // // // // // // // // /
840
841 /** Check if this item Listing or Calendar Overview page
842 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
843 * @return boolean true | false
844 */
845 function wpbm_is_master_page( $server_param = 'REQUEST_URI' ) {
846
847 if ( ( is_admin() ) &&
848 ( strpos($_SERVER[ $server_param ],'page=oplugins') !== false ) &&
849 ( strpos($_SERVER[ $server_param ],'tab=wpbm-') === false ) && // not the settings
850 ( ( strpos($_SERVER[ $server_param ],'tab=wpbm') !== false ) // tab specified
851 || ( strpos($_SERVER[ $server_param ],'tab=') === false ) ) // or tab not specified at all
852 ) {
853 return true;
854 }
855 return false;
856 }
857
858 /** Check if this item > Add item page
859 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
860 * @return boolean true | false
861 */
862 function wpbm_is_new_wpbm_page( $server_param = 'REQUEST_URI' ) {
863
864 if ( ( is_admin() ) &&
865 ( strpos($_SERVER[ $server_param ],'page=oplugins') !== false ) &&
866 ( strpos($_SERVER[ $server_param ],'tab=wpbm-new') !== false )
867 ) {
868 return true;
869 }
870 return false;
871 }
872
873
874 /** Check if this item > Settings page
875 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
876 * @return boolean true | false
877 */
878 function wpbm_is_settings_page( $server_param = 'REQUEST_URI' ) {
879
880 if ( ( is_admin() ) &&
881 ( strpos($_SERVER[ $server_param ],'page=oplugins') !== false ) &&
882 ( strpos($_SERVER[ $server_param ],'tab=wpbm-settings') !== false )
883 ) {
884 return true;
885 }
886 return false;
887 }
888
889 // </editor-fold>
890
891
892 // <editor-fold defaultstate="collapsed" desc=" A d m i n U I E l e m e n t s " >
893 ////////////////////////////////////////////////////////////////////////////
894 // A d m i n U I E l e m e n t s
895 ////////////////////////////////////////////////////////////////////////////
896
897 /** Get Number of new items
898 *
899 * @return int
900 */
901 function wpbm_get_number_new_items(){
902 return 0;
903 }
904
905
906 /** Show Admin B A R .
907 *
908 * @global type $wp_admin_bar
909 * @return type
910 */
911 function wp_admin_bar_items_menu(){
912
913 global $wp_admin_bar;
914
915 $current_user = wp_get_current_user();
916
917 $curr_user_role = get_wpbm_option( 'wpbm_user_role_master' );
918 $level = 10;
919 if ($curr_user_role == 'administrator') $level = 10;
920 else if ($curr_user_role == 'editor') $level = 7;
921 else if ($curr_user_role == 'author') $level = 2;
922 else if ($curr_user_role == 'contributor') $level = 1;
923 else if ($curr_user_role == 'subscriber') $level = 0;
924
925 if ( ( $current_user->user_level < $level ) || ! is_admin_bar_showing() )
926 return;
927
928
929 $update_count = wpbm_get_number_new_items(); // 0
930
931 $title = 'Booking Manager';
932 $update_title = $title;
933
934
935 if ( $update_count > 0 ) {
936 $update_count_title = "&nbsp;<span class='wpbm-count bk-update-count' style='background: #f0f0f1;color: #2c3338;display: inline;padding: 2px 5px;font-weight: 600;border-radius: 10px;'>" . number_format_i18n($update_count) . "</span>" ; //id='wpbm-count'
937 $update_title .= $update_count_title;
938 }
939
940 $link_items = wpbm_get_master_url();
941 $link_settings = wpbm_get_settings_url();
942
943
944 $wp_admin_bar->add_menu(
945 array(
946 'id' => 'bar_wpbm',
947 'title' => $update_title ,
948 'href' => wpbm_get_master_url()
949 )
950 );
951
952
953 $curr_user_role_settings = get_wpbm_option( 'wpbm_user_role_settings' );
954 $level = 10;
955 if ($curr_user_role_settings == 'administrator') $level = 10;
956 else if ($curr_user_role_settings == 'editor') $level = 7;
957 else if ($curr_user_role_settings == 'author') $level = 2;
958 else if ($curr_user_role_settings == 'contributor') $level = 1;
959 else if ($curr_user_role_settings == 'subscriber') $level = 0;
960
961 if ( ( ($current_user->user_level < $level) ) || !is_admin_bar_showing() ) return;
962
963 $wp_admin_bar->add_menu(
964 array(
965 'id' => 'bar_wpbm_new',
966 'title' => __( 'Add New', 'booking-manager'),
967 'href' => wpbm_get_new_wpbm_url(),
968 'parent' => 'bar_wpbm',
969 )
970 );
971
972
973
974 $wp_admin_bar->add_menu(
975 array(
976 'id' => 'bar_wpbm_settings',
977 'title' => __( 'Settings', 'booking-manager'),
978 'href' => wpbm_get_settings_url(),
979 'parent' => 'bar_wpbm',
980 )
981 );
982
983 $wp_admin_bar->add_menu(
984 array(
985 'id' => 'bar_wpbm_settings_email',
986 'title' => __( 'Emails', 'booking-manager'),
987 'href' => $link_settings . '&tab=email',
988 'parent' => 'bar_wpbm_settings'
989 )
990 );
991
992 }
993 // add_action( 'admin_bar_menu', 'wp_admin_bar_items_menu', 70 ); // Add Admin Bar
994
995
996 /** Show Rating link at footer */
997 function wpbm_show_wpbm_footer(){
998
999 if ( ! wpbm_is_this_demo() ) {
1000
1001 $message = sprintf( __( 'If you like %s please leave us a %s rating. A huge thank you in advance!', 'booking-manager')
1002 , '<strong>Booking Manager</strong>' . ' ' . WPBM_VERSION_NUM
1003 , '<a href="https://wordpress.org/support/plugin/booking-manager/reviews/#new-post" target="_blank" title="' . esc_attr__( 'Thanks :)', 'booking-manager') . '">'
1004 . '&#9733;&#9733;&#9733;&#9733;&#9733;'
1005 . '</a>'
1006 );
1007
1008 echo '<div id="wpbm-footer" style="position:absolute;bottom:40px;text-align:left;width:95%;font-size:0.9em;text-shadow:0 1px 0 #fff;margin:0;color:#888;">' . $message . '</div>';
1009 ?>
1010 <script type="text/javascript">
1011 jQuery(document).ready(function(){
1012 jQuery('#wpfooter').append( jQuery('#wpbm-footer') );
1013 });
1014 </script>
1015 <?php
1016 }
1017 }
1018 // </editor-fold>
1019
1020
1021 // <editor-fold defaultstate="collapsed" desc=" DB - cheking if table, field or index exists " >
1022 ////////////////////////////////////////////////////////////////////////////
1023 // DB - cheking if table, field or index exists
1024 ////////////////////////////////////////////////////////////////////////////
1025
1026 /**
1027 * Check if table exist
1028 *
1029 * @global type $wpdb
1030 * @param string $tablename
1031 * @return 0|1
1032 */
1033 function wpbm_is_table_exists( $tablename ) {
1034
1035 global $wpdb;
1036
1037 if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) )
1038 $tablename = $wpdb->prefix . $tablename ;
1039
1040 $sql_check_table = $wpdb->prepare("SHOW TABLES LIKE %s" , $tablename ); //FixIn 5.4.3
1041
1042 $res = $wpdb->get_results( $sql_check_table );
1043
1044 return count($res); //FixIn 5.4.3
1045 /*
1046 $sql_check_table = $wpdb->prepare("
1047 SELECT COUNT(*) AS count
1048 FROM information_schema.tables
1049 WHERE table_schema = '". DB_NAME ."'
1050 AND table_name = %s " , $tablename );
1051
1052 $res = $wpdb->get_results( $sql_check_table );
1053 return $res[0]->count;*/
1054 }
1055
1056
1057 /**
1058 * Check if table exist
1059 *
1060 * @global type $wpdb
1061 * @param string $tablename
1062 * @param type $fieldname
1063 * @return 0|1
1064 */
1065 function wpbm_is_field_in_table_exists( $tablename , $fieldname) {
1066 global $wpdb;
1067 if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) ) $tablename = $wpdb->prefix . $tablename ;
1068 $sql_check_table = "SHOW COLUMNS FROM {$tablename}" ;
1069
1070 $res = $wpdb->get_results( $sql_check_table );
1071
1072 foreach ($res as $fld) {
1073 if ($fld->Field == $fieldname) return 1;
1074 }
1075
1076 return 0;
1077 }
1078
1079
1080 /**
1081 * Check if index exist
1082 *
1083 * @global type $wpdb
1084 * @param string $tablename
1085 * @param type $fieldindex
1086 * @return 0|1
1087 */
1088 function wpbm_is_index_in_table_exists( $tablename , $fieldindex) {
1089 global $wpdb;
1090 if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) ) $tablename = $wpdb->prefix . $tablename ;
1091 $sql_check_table = $wpdb->prepare("SHOW INDEX FROM {$tablename} WHERE Key_name = %s", $fieldindex );
1092 $res = $wpdb->get_results( $sql_check_table );
1093 if (count($res)>0) return 1;
1094 else return 0;
1095 }
1096
1097 // </editor-fold>
1098
1099
1100 // <editor-fold defaultstate="collapsed" desc=" E s c a p i n g " >
1101 ////////////////////////////////////////////////////////////////////////////
1102 // E s c a p i n g
1103 ////////////////////////////////////////////////////////////////////////////
1104
1105 /** Transform the REQESTS parameters (GET and POST) into URL
1106 *
1107 * @param type $page_param
1108 * @param array $exclude_params
1109 * @param type $only_these_parameters
1110 * @return type
1111 */
1112 function wpbm_get_params_in_url( $page_param , $exclude_params = array(), $only_these_parameters = false, $is_escape_url = false, $only_get = false ){
1113
1114 $exclude_params[] = 'page';
1115
1116 if ( isset( $_GET['page'] ) )
1117 $page_param = $_GET['page'];
1118
1119 $get_paramaters = array( 'page' => $page_param );
1120
1121 if ( $only_get )
1122 $check_params = $_GET;
1123 else
1124 $check_params = $_REQUEST;
1125 //debuge($check_params);
1126 foreach ( $check_params as $prm_key => $prm_value ) {
1127
1128 // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 )
1129 if (
1130 ( is_string( $prm_value ) )
1131 || ( is_numeric( $prm_value ) )
1132 ) {
1133
1134 if ( strlen( $prm_value ) > 1000 ) { // Check about TOOO long parameters, if it exist then reset it.
1135 $prm_value = '';
1136 }
1137
1138 if ( ! in_array( $prm_key, $exclude_params ) )
1139 if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) )
1140 $get_paramaters[ $prm_key ] = $prm_value;
1141 }
1142 }
1143 //debuge($check_params, $get_paramaters, $exclude_params );
1144 $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) );
1145
1146 if ( $is_escape_url )
1147 $url = esc_url( $url );
1148
1149 return $url;
1150
1151 /* // Old variant:
1152 if ( isset( $_GET['page'] ) ) $page_param = $_GET['page'];
1153
1154 $url_start = 'admin.php?page=' . $page_param . '&';
1155 $exclude_params[] = 'page';
1156 foreach ( $_REQUEST as $prm_key => $prm_value ) {
1157
1158 if ( !in_array( $prm_key, $exclude_params ) )
1159 if ( ($only_these_parameters === false) || ( in_array( $prm_key, $only_these_parameters ) ) )
1160
1161 $url_start .= $prm_key . '=' . $prm_value . '&';
1162
1163 }
1164 $url_start = substr( $url_start, 0, -1 );
1165
1166 return $url_start;
1167 */
1168 }
1169
1170
1171 /** Clean Request Parameters
1172 *
1173 */
1174 function wpbm_check_request_paramters() {
1175
1176 $clean_params = array();
1177
1178 $clean_params[ 'wh_wpbm_id' ] = 'digit_or_csd'; // '0' | '1' | ''
1179 $clean_params[ 'wh_wpbm_date' ] = 'digit_or_date'; // number | date 2016-07-20
1180 $clean_params[ 'wh_wpbm_datenext' ] = 'd'; // '1' | '2' ....
1181 $clean_params[ 'wh_pay_statuscustom' ] = 's'; //string !!! LIKE !!!
1182 $clean_params[ 'wh_pay_status' ] = array( 'all', 'group_ok', 'group_unknown', 'group_pending', 'group_failed' );
1183
1184 foreach ( $clean_params as $request_key => $clean_type ) {
1185
1186 // elements only listed in array::
1187 if ( is_array( $clean_type ) ) { // check only values from the list in this array
1188
1189 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( ! in_array( $_REQUEST[ $request_key ], $clean_type ) ) )
1190 $clean_type = 's';
1191 else
1192 $clean_type = 'checked_skip_it';
1193 }
1194
1195 switch ( $clean_type ) {
1196
1197 case 'checked_skip_it':
1198
1199 break;
1200
1201 case 'digit_or_date': // digit or comma separated digit
1202 if ( isset( $_REQUEST[ $request_key ] ) )
1203 $_REQUEST[ $request_key ] = wpbm_clean_digit_or_date( $_REQUEST[ $request_key ] ); // nums
1204
1205 break;
1206
1207 case 'digit_or_csd': // digit or comma separated digit
1208 if ( isset( $_REQUEST[ $request_key ] ) )
1209 $_REQUEST[ $request_key ] = wpbm_clean_digit_or_csd( $_REQUEST[ $request_key ] ); // nums
1210
1211 break;
1212
1213 case 's': // string
1214 if ( isset( $_REQUEST[ $request_key ] ) )
1215 $_REQUEST[ $request_key ] = wpbm_clean_like_string_for_db( $_REQUEST[ $request_key ] );
1216
1217 break;
1218
1219 case 'd': // digit
1220 if ( isset( $_REQUEST[ $request_key ] ) )
1221 if ( $_REQUEST[ $request_key ] !== '' )
1222 $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] );
1223
1224 break;
1225
1226 default:
1227 if ( isset( $_REQUEST[ $request_key ] ) ) {
1228 $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] );
1229 }
1230 break;
1231 }
1232
1233
1234 }
1235
1236 }
1237
1238
1239 /** Check paramter if it number or comma separated list of numbers
1240 *
1241 * @global type $wpdb
1242 * @param string $value
1243 * @return string
1244 *
1245 * Exmaple:
1246 wpbm_clean_digit_or_csd( '12,a,45,9' ) => '12,0,45,9'
1247 * or
1248 wpbm_clean_digit_or_csd( '10a' ) => '10
1249 * or
1250 wpbm_clean_digit_or_csd( array( '12,a,45,9', '10a' ) ) => array ( '12,0,45,9', '10' )
1251 */
1252 function wpbm_clean_digit_or_csd( $value ) { //FixIn:6.2.1.4
1253
1254 if ( $value === '' ) return $value;
1255
1256
1257 if ( is_array( $value ) ) {
1258 foreach ( $value as $key => $check_value ) {
1259 $value[ $key ] = wpbm_clean_digit_or_csd( $check_value );
1260 }
1261 return $value;
1262 }
1263
1264
1265 global $wpdb;
1266
1267 $value = str_replace( ';', ',', $value );
1268
1269 $array_of_nums = explode(',', $value);
1270
1271 $result = array();
1272 foreach ($array_of_nums as $check_element) {
1273 $result[] = $wpdb->prepare( "%d", $check_element );
1274 }
1275 $result = implode(',', $result );
1276 return $result;
1277 }
1278
1279
1280 /** Cehck about Valid date, like 2016-07-20 or digit
1281 *
1282 * @param string $value
1283 * @return string or int
1284 */
1285 function wpbm_clean_digit_or_date( $value ) { //FixIn:6.2.1.4
1286
1287 if ( $value === '' ) return $value;
1288
1289 if ( preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $value ) ) {
1290
1291 return $value; // Date is valid in format: 2016-07-20
1292 } else {
1293 return intval( $value );
1294 }
1295
1296 }
1297
1298
1299 /** Check $value for injection here
1300 *
1301 * @param type $value
1302 * @return type
1303 */
1304 function wpbm_clean_parameter( $value ) {
1305
1306 $value = preg_replace( '/<[^>]*>/', '', $value ); // clean any tags
1307 $value = str_replace( '<', ' ', $value );
1308 $value = str_replace( '>', ' ', $value );
1309 $value = strip_tags( $value );
1310
1311 // Clean SQL injection
1312 $value = esc_sql( $value );
1313
1314 return $value;
1315 }
1316
1317
1318 function wpbm_esc_like( $value_trimmed ) {
1319
1320 global $wpdb;
1321 if ( method_exists( $wpdb ,'esc_like' ) )
1322 return $wpdb->esc_like( $value_trimmed ); // Its require minimum WP 4.0.0
1323 else
1324 return addcslashes( $value_trimmed, '_%\\' ); // Direct implementation from $wpdb->esc_like(
1325 }
1326
1327
1328 /** Clean user string for using in SQL LIKE statement - append to LIKE sql
1329 *
1330 * @param string $value - to clean
1331 * @return string - escaped
1332 * Exmaple:
1333 * $search_escaped_like_title = wpbm_clean_like_string_for_append_in_sql_for_db( $input_var );
1334 *
1335 * $where_sql = " WHERE title LIKE ". $search_escaped_like_title ." ";
1336 */
1337 function wpbm_clean_like_string_for_append_in_sql_for_db( $value ) {
1338 global $wpdb;
1339
1340 $value_trimmed = trim( stripslashes( $value ) );
1341 $wild = '%';
1342 $like = $wild . wpbm_esc_like( $value_trimmed ) . $wild;
1343 $sql = $wpdb->prepare( "'%s'", $like );
1344
1345 return $sql;
1346
1347
1348 /* Help:
1349 * First half of escaping for LIKE special characters % and _ before preparing for MySQL.
1350 * Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security.
1351 *
1352 * Example Prepared Statement:
1353 *
1354 * $wild = '%';
1355 * $find = 'only 43% of planets';
1356 * $like = $wild . wpbm_esc_like( $find ) . $wild;
1357 * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like );
1358 *
1359 * Example Escape Chain:
1360 *
1361 * $sql = esc_sql( wpbm_esc_like( $input ) );
1362 */
1363
1364 }
1365
1366
1367 /** Clean string for using in SQL LIKE requests inside single quotes: WHERE title LIKE '%". $escaped_search_title ."%'
1368 * Replaced _ to \_ % to \% \ to \\
1369 * @param string $value - to clean
1370 * @return string - escaped
1371 * Exmaple:
1372 * $search_escaped_like_title = wpbm_clean_like_string_for_db( $input_var );
1373 *
1374 * $where_sql = " WHERE title LIKE '%". $search_escaped_like_title ."%' ";
1375 *
1376 * Important! Use SINGLE quotes after in SQL query: LIKE '%".$data."%'
1377 */
1378 function wpbm_clean_like_string_for_db( $value ){
1379
1380 global $wpdb;
1381
1382 $value_trimmed = trim( stripslashes( $value ) );
1383
1384 $value_trimmed = wpbm_esc_like( $value_trimmed );
1385
1386 $value = trim( $wpdb->prepare( "'%s'", $value_trimmed ) , "'" );
1387
1388 return $value;
1389
1390 /* Help:
1391 * First half of escaping for LIKE special characters % and _ before preparing for MySQL.
1392 * Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security.
1393 *
1394 * Example Prepared Statement:
1395 *
1396 * $wild = '%';
1397 * $find = 'only 43% of planets';
1398 * $like = $wild . wpbm_esc_like( $find ) . $wild;
1399 * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like );
1400 *
1401 * Example Escape Chain:
1402 *
1403 * $sql = esc_sql( wpbm_esc_like( $input ) );
1404 */
1405 }
1406
1407
1408 /** Escape string from SQL for the HTML form field
1409 *
1410 * @param string $value
1411 * @return string
1412 *
1413 * Used: esc_sql function.
1414 *
1415 * https://codex.wordpress.org/Function_Reference/esc_sql
1416 * Note: Be careful to use this function correctly. It will only escape values to be used in strings in the query.
1417 * That is, it only provides escaping for values that will be within quotes in the SQL (as in field = '{$escaped_value}').
1418 * If your value is not going to be within quotes, your code will still be vulnerable to SQL injection.
1419 * For example, this is vulnerable, because the escaped value is not surrounded by quotes in the SQL query:
1420 * ORDER BY {$escaped_value}. As such, this function does not escape unquoted numeric values, field names, or SQL keywords.
1421 *
1422 */
1423 function wpbm_clean_string_for_form( $value ){
1424
1425 global $wpdb;
1426
1427 $value_trimmed = trim( stripslashes( $value ) );
1428
1429 $esc_sql_value = esc_sql( $value_trimmed );
1430
1431 //$value = trim( $wpdb->prepare( "'%s'", $esc_sql_value ) , "'" );
1432
1433 $esc_sql_value = trim( stripslashes( $esc_sql_value ) );
1434
1435 return $esc_sql_value;
1436
1437 }
1438 // </editor-fold>
1439
1440
1441 // <editor-fold defaultstate="collapsed" desc=" U s e r s " >
1442 ////////////////////////////////////////////////////////////////////////////////
1443 // U s e r s
1444 ////////////////////////////////////////////////////////////////////////////////
1445
1446 /** Get ID of active user
1447 *
1448 * @return type
1449 */
1450 function get_wpbm_current_user_id() {
1451 $user = wp_get_current_user();
1452 return ( isset( $user->ID ) ? (int) $user->ID : 0 );
1453 }
1454
1455
1456 /** Check if Current User have specific Role
1457 *
1458 * @return bool Whether the current user has the given capability.
1459 */
1460 function wpbm_is_current_user_have_this_role( $user_role ) {
1461
1462 if ( $user_role == 'administrator' ) $user_role = 'activate_plugins';
1463 if ( $user_role == 'editor' ) $user_role = 'publish_pages';
1464 if ( $user_role == 'author' ) $user_role = 'publish_posts';
1465 if ( $user_role == 'contributor' ) $user_role = 'edit_posts';
1466 if ( $user_role == 'subscriber') $user_role = 'read';
1467
1468 return current_user_can( $user_role );
1469 }
1470
1471
1472 function wpbm_get_user_ip() {
1473 //return '84.243.195.114' ; // Test //90.36.89.174
1474 if (isset($_SERVER['HTTP_CLIENT_IP'])) {
1475 $userIP = $_SERVER['HTTP_CLIENT_IP'] ;
1476 } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
1477 $userIP = $_SERVER['HTTP_X_FORWARDED_FOR'] ;
1478 } elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
1479 $userIP = $_SERVER['HTTP_X_FORWARDED'] ;
1480 } elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
1481 $userIP = $_SERVER['HTTP_FORWARDED_FOR'] ;
1482 } elseif (isset($_SERVER['HTTP_FORWARDED'])) {
1483 $userIP = $_SERVER['HTTP_FORWARDED'] ;
1484 } elseif (isset($_SERVER['REMOTE_ADDR'])) {
1485 $userIP = $_SERVER['REMOTE_ADDR'] ;
1486 } else {
1487 $userIP = "" ;
1488 }
1489
1490 $userIP = explode( ',', $userIP );
1491 $userIP = array_map( 'trim', $userIP );
1492
1493 return $userIP[0] ;
1494 }
1495 add_wpbm_filter( 'wpbm_get_user_ip', 'wpbm_get_user_ip' );
1496 // </editor-fold>
1497
1498
1499 // <editor-fold defaultstate="collapsed" desc=" Mesages for Admin panel " >
1500 ////////////////////////////////////////////////////////////////////////////////
1501 // Mesages for Admin panel
1502 ////////////////////////////////////////////////////////////////////////////////
1503
1504 function wpbm_show_fixed_message( $message, $time_to_show , $message_type = 'updated' , $notice_id = 0, $is_dismissible = false ) {
1505
1506 // Generate unique HTML ID for the message
1507 if ( $notice_id == 0 )
1508 $notice_id = intval( time() * rand(10, 100) );
1509
1510 $notice_id = 'wpbm_system_notice_' . $notice_id;
1511
1512 $is_dismissible = false;
1513
1514 if (
1515 ( ( $is_dismissible ) && ( ! wpbm_section_is_dismissed( $notice_id ) ) )
1516 || ( ! $is_dismissible )
1517 // || true
1518 ){
1519
1520 ?><div id="<?php echo $notice_id; ?>"
1521 class="wpbm_system_notice wpbm_is_dismissible wpbm_is_hideable <?php echo $message_type; ?>"
1522 data-nonce="<?php echo wp_create_nonce( $nonce_name = $notice_id . '_wpbmnonce' ); ?>"
1523 data-user-id="<?php echo get_current_user_id(); ?>"
1524 ><?php
1525
1526 wpbm_x_dismiss_button();
1527
1528 echo $message;
1529
1530 ?></div><?php
1531
1532 // Get the time of message showing
1533 $time_to_show = intval( $time_to_show ) * 1000;
1534
1535 if ( $time_to_show > 0 ) {
1536 ?> <script type="text/javascript">
1537 jQuery('#<?php echo $notice_id; ?>').animate({opacity: 1},<?php echo $time_to_show; ?>).fadeOut( 2000 );
1538 </script> <?php
1539 }
1540 }
1541 }
1542
1543
1544 /** Show Ajax message at the top of page
1545 *
1546 * @param type $message
1547 * @param type $time_to_show
1548 * @param type $is_error
1549 */
1550 function wpbm_show_ajax_message( $message, $time_to_show = 3000, $is_error = false ) {
1551
1552 // Recheck for any "lang" shortcodes for replacing to correct language
1553 $message = apply_wpbm_filter('wpbm_check_for_active_language', $message );
1554
1555 // Escape any JavaScript from message
1556 $notice = html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
1557
1558 ?><script type="text/javascript">
1559 var my_message = '<?php echo $notice; ?>';
1560 wpbm_admin_show_message( my_message, '<?php echo ( $is_error ? 'error' : 'success' ); ?>', <?php echo $time_to_show; ?> );
1561 </script><?php
1562 }
1563
1564
1565 /** Show "Saved Changes" message at the top of settings page.
1566 *
1567 */
1568 function wpbm_show_changes_saved_message() {
1569 wpbm_show_message ( __('Changes saved.', 'booking-manager'), 5 );
1570 }
1571
1572
1573 /** Show Message at Top of Admin Pages
1574 *
1575 * @param type $message - mesage to show
1576 * @param type $time_to_show - number of seconds to show, if 0 or skiped, then unlimited time.
1577 * @param type $message_type - Default: updated { updated | error | notice }
1578 */
1579 function wpbm_show_message ( $message, $time_to_show , $message_type = 'updated') {
1580
1581 // Generate unique HTML ID for the message
1582 $inner_message_id = intval( time() * rand(10, 100) );
1583
1584 // Get formated HTML message
1585 $notice = wpbm_get_formated_message( $message, $message_type, $inner_message_id );
1586
1587 // Get the time of message showing
1588 $time_to_show = intval( $time_to_show ) * 1000;
1589
1590 // Show this Message
1591 ?> <script type="text/javascript">
1592 if ( jQuery('.wpbm_admin_message').length ) {
1593 jQuery('.wpbm_admin_message').append( '<?php echo $notice; ?>' );
1594 <?php if ( $time_to_show > 0 ) { ?>
1595 jQuery('#wpbm_inner_message_<?php echo $inner_message_id; ?>').animate({opacity: 1},<?php echo $time_to_show; ?>).fadeOut( 2000 );
1596 <?php } ?>
1597 }
1598 </script> <?php
1599 }
1600
1601
1602 /** Escape and prepare message to show it
1603 *
1604 * @param type $message - message
1605 * @param type $message_type - Default: updated { updated | error | notice }
1606 * @param string $inner_message_id - ID of message DIV, can be skipped
1607 * @return string
1608 */
1609 function wpbm_get_formated_message ( $message, $message_type = 'updated', $inner_message_id = '') {
1610
1611
1612 // Recheck for any "lang" shortcodes for replacing to correct language
1613 $message = apply_wpbm_filter('wpbm_check_for_active_language', $message );
1614
1615 // Escape any JavaScript from message
1616 $notice = html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
1617
1618 $notice .= '<a class="close tooltip_left" rel="tooltip" title="'. esc_js(__("Hide", 'booking-manager')). '" data-dismiss="alert" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().hide();">&times;</a>';
1619
1620 if (! empty( $inner_message_id ))
1621 $inner_message_id = 'id="wpbm_inner_message_'. $inner_message_id .'"';
1622
1623 $notice = '<div '.$inner_message_id.' class="wpbm_inner_message '. $message_type . '">' . $notice . '</div>';
1624
1625 return $notice;
1626 }
1627
1628
1629 /** Show system info in settings page
1630 *
1631 * @param string $message ...
1632 * @param string $message_type 'info' | 'warning' | 'error'
1633 * @param string $title __('Important!' , 'booking-manager') | __('Note' , 'booking-manager')
1634 *
1635 * Exmaple: wpbm_show_message_in_settings( __( 'Nothing Found', 'booking-manager'), 'warning', __('Important!' , 'booking-manager') );
1636 */
1637 function wpbm_show_message_in_settings( $message, $message_type = 'info', $title = '' , $is_echo = true ) {
1638
1639 $message_content = '';
1640
1641 $message_content .= '<div class="clear"></div>';
1642
1643 $message_content .= '<div class="wpbm-settings-notice notice-' . $message_type . '" style="text-align:left;">';
1644
1645 if ( ! empty( $title ) )
1646 $message_content .= '<strong>' . esc_js( $title ) . '</strong> ';
1647
1648 $message_content .= html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
1649
1650 $message_content .= '</div>';
1651
1652 $message_content .= '<div class="clear"></div>';
1653
1654 if ( $is_echo )
1655 echo $message_content;
1656 else
1657 return $message_content;
1658
1659 }
1660 // </editor-fold>
1661
1662
1663 // <editor-fold defaultstate="collapsed" desc=" Settings Meta Boxes " >
1664 ////////////////////////////////////////////////////////////////////////////////
1665 // Settings Meta Boxes
1666 ////////////////////////////////////////////////////////////////////////////////
1667 function wpbm_open_meta_box_section( $metabox_id, $title ) {
1668
1669 $my_close_open_win_id = $metabox_id . '_metabox';
1670 //FixIn: 2.0.16.1
1671 ?>
1672 <div class='meta-box'>
1673 <div
1674 id="<?php echo $my_close_open_win_id; ?>"
1675 class="postbox <?php if ( '1' == get_user_option( 'wpbm_win_' . $my_close_open_win_id ) ) echo 'closed'; ?>"
1676 ><div class="postbox-header" style="display: flex;flex-flow: row nowrap;border-bottom: 1px solid #ccd0d4;"><?php //FixIn: 8.7.8.1 ?>
1677 <h3 class='hndle' style="flex: 1 1 auto;border: none;">
1678 <span><?php echo wp_kses_post( $title ); ?></span>
1679 </h3>
1680 <div title="<?php _e('Click to toggle','booking-manager'); ?>"
1681 class="handlediv"
1682 onclick="javascript:wpbm_verify_window_opening(<?php echo get_wpbm_current_user_id(); ?>, '<?php echo $my_close_open_win_id; ?>');"
1683 ><br/></div>
1684 </div>
1685 <div class="inside">
1686 <?php
1687 }
1688
1689 function wpbm_close_meta_box_section() {
1690 ?>
1691 </div>
1692 </div>
1693 </div>
1694 <?php
1695 }
1696 // </editor-fold>
1697
1698
1699 // from Toolbar
1700 // <editor-fold defaultstate="collapsed" desc=" M o d a l s " >
1701 ////////////////////////////////////////////////////////////////////////////////
1702 // M o d a l s
1703 ////////////////////////////////////////////////////////////////////////////////
1704
1705 /** Start Loyouts - Modal Window structure */
1706 function wpbm_write_content_for_modals_start_here() {
1707
1708 ?><span id="wpbm_content_for_modals"></span><?php
1709 }
1710 add_wpbm_action( 'wpbm_write_content_for_modals', 'wpbm_write_content_for_modals_start_here');
1711 // </editor-fold>
1712
1713
1714 // <editor-fold defaultstate="collapsed" desc=" Inline JavaScript " >
1715 ////////////////////////////////////////////////////////////////////////////////
1716 // Inline J a v a S c r i p t to Footer page
1717 ////////////////////////////////////////////////////////////////////////////////
1718 /**
1719 * Queue JavaScript for later output at footer
1720 *
1721 * @param string $code
1722 */
1723 function wpbm_enqueue_js( $code ) {
1724 global $wpbm_queued_js;
1725
1726 if ( empty( $wpbm_queued_js ) ) {
1727 $wpbm_queued_js = '';
1728 }
1729
1730 $wpbm_queued_js .= "\n" . $code . "\n";
1731 }
1732
1733
1734 /**
1735 * Output any queued javascript code in the footer.
1736 */
1737 function wpbm_print_js() {
1738
1739 global $wpbm_queued_js;
1740
1741 if ( ! empty( $wpbm_queued_js ) ) {
1742
1743 echo "<!-- WPBM JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) {";
1744
1745 $wpbm_queued_js = wp_check_invalid_utf8( $wpbm_queued_js );
1746
1747 $wpbm_queued_js = wp_specialchars_decode( $wpbm_queued_js , ENT_COMPAT); // Converts double quotes '&quot;' => '"'
1748
1749 $wpbm_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $wpbm_queued_js );
1750 $wpbm_queued_js = str_replace( "\r", '', $wpbm_queued_js );
1751
1752 echo $wpbm_queued_js . "});\n</script>\n<!-- End WPBM JavaScript -->\n";
1753
1754 $wpbm_queued_js = '';
1755 unset( $wpbm_queued_js );
1756 }
1757 }
1758
1759 // </editor-fold>
1760
1761 // from Toolbar
1762 // <editor-fold defaultstate="collapsed" desc=" JS & CSS - Tooltips & Popover" >
1763 ////////////////////////////////////////////////////////////////////////////////
1764 // JS & CSS
1765 ////////////////////////////////////////////////////////////////////////////////
1766
1767 /** Load suport JavaScript for "Items" page*/
1768 function wpbm_js_for_items_page() {
1769
1770 $is_use_hints = get_wpbm_option( 'wpbm_is_use_hints_at_admin_panel' );
1771 if ( $is_use_hints == 'On' )
1772 wpbm_bs_javascript_tooltips(); // JS Tooltips
1773
1774 wpbm_bs_javascript_popover(); // JS Popover
1775
1776 //wpbm_datepicker_js(); // JS Datepicker
1777 wpbm_datepicker_css(); // CSS DatePicker
1778 }
1779
1780
1781 /** Datepicker activation JavaScript */
1782 function wpbm_datepicker_js() {
1783
1784 ?><script type="text/javascript">
1785 jQuery(document).ready( function(){
1786
1787 function applyCSStoDays( date ){
1788 return [true, 'date_available'];
1789 }
1790 jQuery('input.wpbm-filters-section-calendar').datepick(
1791 { beforeShowDay: applyCSStoDays,
1792 showOn: 'focus',
1793 multiSelect: 0,
1794 numberOfMonths: 1,
1795 stepMonths: 1,
1796 prevText: '&laquo;',
1797 nextText: '&raquo;',
1798 dateFormat: 'yy-mm-dd',
1799 changeMonth: false,
1800 changeYear: false,
1801 minDate: null,
1802 maxDate: null, //'1Y',
1803 showStatus: false,
1804 multiSeparator: ', ',
1805 closeAtTop: false,
1806 // firstDay:<?php //echo get_wpbm_option( 'wpbm_start_day_weeek' ); ?>,
1807 gotoCurrent: false,
1808 hideIfNoPrevNext:true,
1809 useThemeRoller :false,
1810 mandatory: true
1811 }
1812 );
1813 });
1814 </script><?php
1815 }
1816
1817
1818 /** Support CSS - datepick, etc... */
1819 function wpbm_datepicker_css(){
1820 ?>
1821 <style type="text/css">
1822 #datepick-div .datepick-header {
1823 width: 172px !important;
1824 }
1825 #datepick-div {
1826 -border-radius: 3px;
1827 -box-shadow: 0 0 2px #888888;
1828 -webkit-border-radius: 3px;
1829 -webkit-box-shadow: 0 0 2px #888888;
1830 -moz-border-radius: 3px;
1831 -moz-box-shadow: 0 0 2px #888888;
1832 width: 172px !important;
1833 }
1834 #datepick-div .datepick .datepick-days-cell a{
1835 font-size: 12px;
1836 }
1837 #datepick-div table.datepick tr td {
1838 border-top: 0 none !important;
1839 line-height: 24px;
1840 padding: 0 !important;
1841 width: 24px;
1842 }
1843 #datepick-div .datepick-control {
1844 font-size: 10px;
1845 text-align: center;
1846 }
1847 #datepick-div .datepick-one-month {
1848 height: auto;
1849 }
1850 </style>
1851 <?php
1852 }
1853
1854
1855 /** Sortable Table JavaScript */
1856 function wpbm_sortable_js() {
1857 ?>
1858 <script type="text/javascript">
1859 // Activate Sortable Functionality
1860 jQuery( document ).ready(function(){
1861
1862 jQuery('.wpbm_input_table tbody th').css('cursor','move');
1863
1864 jQuery('.wpbm_input_table tbody td.sort').css('cursor','move');
1865
1866 jQuery('.wpbm_input_table.sortable tbody').sortable({
1867 items:'tr',
1868 cursor:'move',
1869 axis:'y',
1870 scrollSensitivity:40,
1871 forcePlaceholderSize: true,
1872 helper: 'clone',
1873 opacity: 0.65,
1874 placeholder: '.wpbm_sortable_table .sort',
1875 start:function(event,ui){
1876 ui.item.css('background-color','#f6f6f6');
1877 },
1878 stop:function(event,ui){
1879 ui.item.removeAttr('style');
1880 }
1881 });
1882 });
1883 </script>
1884 <?php
1885
1886 }
1887 // </editor-fold>
1888
1889
1890 // <editor-fold defaultstate="collapsed" desc=" R e l o a d p a g e " >
1891 ////////////////////////////////////////////////////////////////////////////////
1892 // R e l o a d p a g e
1893 ////////////////////////////////////////////////////////////////////////////////
1894 /**
1895 * Reload page by using JavaScript
1896 *
1897 * @param string $url - URL of page to load
1898 */
1899 function wpbm_reload_page_by_js( $url ) {
1900
1901 $redir = html_entity_decode( esc_url( $url ) );
1902
1903 if ( ! empty( $redir ) ) {
1904 ?>
1905 <script type="text/javascript">
1906 window.location.href = '<?php echo $redir ?>';
1907 </script>
1908 <?php
1909 }
1910 }
1911
1912
1913 /** Redirect browser to a specific page
1914 *
1915 * @param string $url - URL of page to redirect
1916 */
1917 function wpbm_redirect( $url ) {
1918
1919 $url = wpbm_make_link_absolute( $url );
1920
1921 $url = html_entity_decode( esc_url( $url ) );
1922
1923 echo '<script type="text/javascript">';
1924 echo 'window.location.href="'.$url.'";';
1925 echo '</script>';
1926 echo '<noscript>';
1927 echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
1928 echo '</noscript>';
1929 }
1930 // </editor-fold>
1931
1932
1933 // <editor-fold defaultstate="collapsed" desc=" P a g i n a t i o n o f T a b l e L i s t i n g " >
1934 /** Show P a g i n a t i o n
1935 *
1936 * @param int $summ_number_of_items - total number of items
1937 * @param int $active_page_num - number of activated page
1938 * @param int $num_items_per_page - number of items per page
1939 * @param array $only_these_parameters - array of keys to exclude from links
1940 * @param string $url_sufix - usefule for anchor to HTML section with specific ID, Example: '#my_section'
1941 */
1942 function wpbm_show_pagination( $summ_number_of_items, $active_page_num, $num_items_per_page , $only_these_parameters = false, $url_sufix = '' ) {
1943
1944 if ( empty( $num_items_per_page ) ) {
1945 $num_items_per_page = '10';
1946 }
1947
1948 $pages_number = ceil( $summ_number_of_items / $num_items_per_page );
1949 if ( $pages_number < 2 )
1950 return;
1951
1952 //Fix: 5.1.4 - Just in case we are having tooo much resources, then we need to show all resources - and its empty string
1953 if ( ( isset($_REQUEST['wh_wpbm_type'] ) ) && ( strlen($_REQUEST['wh_wpbm_type']) > 1000 ) ) {
1954 $_REQUEST['wh_wpbm_type'] = '';
1955 }
1956
1957 // First parameter will overwriten by $_GET['page'] parameter
1958 $bk_admin_url = wpbm_get_params_in_url( wpbm_get_master_url( false ), array('page_num'), $only_these_parameters );
1959
1960
1961 ?>
1962 <span class="wpdevelop wpbm-pagination">
1963 <div class="container-fluid">
1964 <div class="row">
1965 <div class="col-sm-12 text-center control-group0">
1966 <nav class="btn-toolbar">
1967 <div class="btn-group wpbm-no-margin" style="float:none;">
1968
1969 <?php if ( $pages_number > 1 ) { ?>
1970 <a class="button button-secondary <?php echo ( $active_page_num == 1 ) ? ' disabled' : ''; ?>"
1971 href="<?php echo $bk_admin_url; ?>&page_num=<?php if ($active_page_num == 1) { echo $active_page_num; } else { echo ($active_page_num-1); } echo $url_sufix; ?>">
1972 <?php _e('Prev', 'booking-manager'); ?>
1973 </a>
1974 <?php }
1975
1976 /** Number visible pages (links) that linked to active page, other pages skipped by "..." */
1977 $num_closed_steps = 3;
1978
1979 for ( $pg_num = 1; $pg_num <= $pages_number; $pg_num++ ) {
1980
1981 if ( ! (
1982 ( $pages_number > ( $num_closed_steps * 4) )
1983 && ( $pg_num > $num_closed_steps )
1984 && ( ( $pages_number - $pg_num + 1 ) > $num_closed_steps )
1985 && ( abs( $active_page_num - $pg_num ) > $num_closed_steps )
1986 ) ) {
1987 ?> <a class="button button-secondary <?php if ($pg_num == $active_page_num ) echo ' active'; ?>"
1988 href="<?php echo $bk_admin_url; ?>&page_num=<?php echo $pg_num; echo $url_sufix; ?>">
1989 <?php echo $pg_num; ?>
1990 </a><?php
1991
1992 if ( ( $pages_number > ( $num_closed_steps * 4) )
1993 && ( ($pg_num+1) > $num_closed_steps )
1994 && ( ( $pages_number - ( $pg_num + 1 ) ) > $num_closed_steps )
1995 && ( abs($active_page_num - ( $pg_num + 1 ) ) > $num_closed_steps )
1996 ) {
1997 echo ' <a class="button button-secondary disabled" href="javascript:void(0);">...</a> ';
1998 }
1999 }
2000 }
2001
2002 if ( $pages_number > 1 ) { ?>
2003 <a class="button button-secondary <?php echo ( $active_page_num == $pages_number ) ? ' disabled' : ''; ?>"
2004 href="<?php echo $bk_admin_url; ?>&page_num=<?php if ($active_page_num == $pages_number) { echo $active_page_num; } else { echo ($active_page_num+1); } echo $url_sufix; ?>">
2005 <?php _e('Next', 'booking-manager'); ?>
2006 </a>
2007 <?php } ?>
2008
2009 </div>
2010 </nav>
2011 </div>
2012 </div>
2013 </div>
2014 </span>
2015 <?php
2016 }
2017 // </editor-fold>
2018
2019
2020 // <editor-fold defaultstate="collapsed" desc=" D a t e s " >
2021 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022 // Dates Format
2023 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2024
2025
2026 /** Get Formated Date & time
2027 *
2028 * @param string $date_sql - 2017-07-31 00:00:00 || 2017-07-31
2029 * @param string $date_format - Optional. - "m / d / Y, D H:i:s"
2030 * @param string $seperator - Optional. - " "
2031 * @return string - July 29, 2014 12:00 am
2032 */
2033 function wpbm_get_date_time_formatted( $date_sql, $date_format = false, $seperator = ' ', $skip_midnight_time = false ) {
2034
2035 $return_date = wpbm_get_date_formatted( $date_sql, $date_format );
2036
2037 $return_time = wpbm_get_time_formatted( $date_sql, $date_format, $skip_midnight_time );
2038 if ( ! empty( $return_time ) )
2039 $return_date .= $seperator . $return_time;
2040
2041 return $return_date;
2042 }
2043
2044
2045 /** Get Formated Date
2046 *
2047 * @param string $date_sql - 2017-07-31 00:00:00 || 2017-07-31
2048 * @param string $date_format - Optional. - "m / d / Y, D"
2049 * @param bool $skip_midnight_time - Default false - if 00:00:00 then return '';
2050 * @return string - July 29, 2014
2051 */
2052 function wpbm_get_date_formatted( $date_sql, $date_format = false ) {
2053
2054 if ( $date_format === false ) $date_format = get_wpbm_option( 'wpbm_date_format' );
2055 if ( empty( $date_format ) ) $date_format = "m / d / Y, D";
2056
2057 $formated_date = date_i18n( $date_format, strtotime( $date_sql ) );
2058
2059 return $formated_date;
2060 }
2061
2062
2063 /** Get Formated Date & time
2064 *
2065 * @param string $date_sql - 2017-07-31 00:00:00 || 2017-07-31
2066 * @param string $time_format - Optional. - "H:i:s"
2067 * @return string - 12:00 am
2068 */
2069 function wpbm_get_time_formatted( $date_sql, $time_format = false , $skip_midnight_time = false ) {
2070
2071 if ( ( $skip_midnight_time ) && ( '00:00:00' == substr( $date_sql, -8 ) ) )
2072 return '';
2073
2074 if ( $time_format === false ) $time_format = get_wpbm_option( 'wpbm_time_format' );
2075 if ( empty( $time_format ) ) $time_format = 'h:i a';
2076
2077 $formated_date = date_i18n( $time_format, strtotime( $date_sql ) );
2078
2079 return $formated_date;
2080 }
2081
2082
2083 /** Check if "current_day" is tomorrow from "next_day"
2084 *
2085 * @param string $current_day_sql_check : 2015-02-29 00:00:00
2086 * @param string $next_day_sql_check : 2015-02-30 00:00:00
2087 * @return boolean : true | false
2088 */
2089 function wpbm_is_next_day( $current_day_sql_check, $next_day_sql_check ) {
2090
2091 // Current day
2092 $current_day_unix = strtotime( $current_day_sql_check );
2093
2094 $current_day_midnight_sql = date_i18n( 'Y-m-d', $current_day_unix );
2095 $current_day_midnight_unix = strtotime( $current_day_midnight_sql );
2096
2097 $calc_next_day_unix = strtotime( '+1 day', $current_day_midnight_unix );
2098
2099 // Next day
2100 $next_day_unix = strtotime( $next_day_sql_check );
2101 $next_day_midnight_sql = date_i18n( 'Y-m-d', $next_day_unix );
2102 $next_day_midnight_unix = strtotime( $next_day_midnight_sql );
2103
2104
2105 if ( $calc_next_day_unix == $next_day_midnight_unix )
2106 return true;
2107 else
2108 return false;
2109 }
2110
2111 /** Check if "current_day" is same day of "other_day"
2112 *
2113 * @param string $current_day_sql_check : 2015-02-29 00:00:00
2114 * @param string $other_day_sql_check : 2015-02-30 00:00:00
2115 * @return boolean : true | false
2116 */
2117 function wpbm_is_this_same_day( $current_day_sql_check, $other_day_sql_check ) {
2118
2119 // Current day
2120 $current_day_unix = strtotime( $current_day_sql_check );
2121
2122 $current_day_midnight_sql = date_i18n( 'Y-m-d', $current_day_unix );
2123 $current_day_midnight_unix = strtotime( $current_day_midnight_sql );
2124
2125 // Other day
2126 $other_day_unix = strtotime( $other_day_sql_check );
2127 $other_day_midnight_sql = date_i18n( 'Y-m-d', $other_day_unix );
2128 $other_day_midnight_unix = strtotime( $other_day_midnight_sql );
2129
2130
2131 if ( $current_day_midnight_unix == $other_day_midnight_unix )
2132 return true;
2133 else
2134 return false;
2135 }
2136
2137
2138 /** Get days in short format view
2139 *
2140 * @param string $days Dates: 15.05.2015, 16.05.2015, 17.05.2015
2141 * @return string Dates in format: 15.05.2015 - 17.05.2015
2142 */
2143 function wpbm_get_dates_short_format( $dates_sql_csv ) { // $days - string with comma seperated dates
2144
2145 if ( empty( $dates_sql_csv ) )
2146 return '';
2147
2148 $days = explode( ',', $dates_sql_csv );
2149
2150 $previosday = false;
2151 $result_string = '';
2152 $last_show_day = '';
2153
2154 foreach ( $days as $day ) {
2155
2156 $is_fin_at_end = false;
2157
2158 if ( $previosday === false ) { // First Day
2159
2160 $result_string = wpbm_get_date_time_formatted( $day, false, ' ', true ); // echo format for first day
2161 $last_show_day = $day;
2162 $previosday = $day; // Set previos day for next loop
2163
2164 } else { // Not first day
2165
2166 if (
2167 wpbm_is_next_day( $previosday, $day )
2168 || wpbm_is_this_same_day( $previosday, $day )
2169 ) { // Check if $day next day from previous
2170
2171 $previosday = $day; // Set previos day for next loop
2172 $is_fin_at_end = true;
2173 } else {
2174 if ( $last_show_day !== $previosday ) { // check if previos day was show or no
2175 $result_string .= ' - ' . wpbm_get_date_time_formatted( $previosday, false, ' ', true ); // assign in needed format this day
2176 }
2177 $result_string .= ', ' . wpbm_get_date_time_formatted( $day, false, ' ', true ); // assign in needed format this day
2178 $previosday = $day; // Set previos day for next loop
2179 $last_show_day = $day;
2180 }
2181 }
2182
2183 }
2184
2185 if ( $is_fin_at_end ) {
2186 $result_string .= ' - ' . wpbm_get_date_time_formatted( $day, false, ' ', true );
2187 }
2188
2189 return $result_string;
2190 }
2191
2192 // </editor-fold>