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

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