//////////////////////////////////////////////////////////////////////////////// // V e r s i o n s //////////////////////////////////////////////////////////////////////////////// /** Get version * * @return string */ function get_wpbm_version(){ $version = 'free'; return $version; } /** Check if user accidentially update Booking Manager Paid version to Free * * @return bool */ function wpbm_is_updated_paid_to_free() { if ( ( wpbm_is_table_exists('wpbm_log') ) && ( ! class_exists('wpbm_personal') ) ) return true; else return false; } function wpbm_get_ver_sufix() { if ( strpos( strtolower( WPBM_VERSION ), 'multisite' ) !== false ) { $v_type = '-multi'; } else if ( strpos( strtolower( WPBM_VERSION ), 'develop' ) !== false ) { $v_type = '-dev'; } else { $v_type = ''; } $v = ''; if ( class_exists( 'wpbm_personal' ) ) $v = 'ps' . $v_type; if ( class_exists( 'wpbm_pro' ) ) $v = ''; return $v; } function wpbm_up_link() { if ( ! wpbm_is_this_demo() ) $v = wpbm_get_ver_sufix(); else $v = ''; return 'https://oplugins.com/plugins/booking-manager/' . ( ( empty($v) ) ? '' : 'upgrade-' . $v . '/' ) ; } /** Check if this demo website * * @return bool */ function wpbm_is_this_demo() { //return ! true; //TODO: comment it. 2016-09-27 // Replaced! if ( ( ( isset( $_SERVER['SCRIPT_FILENAME'] ) ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'oplugins.com' ) !== false ) ) || ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( strpos( $_SERVER['HTTP_HOST'], 'oplugins.com' ) !== false ) ) ) return true; else return false; } /** Get Warning Text for Demo websites */ function wpbm_get_warning_text_in_demo_mode() { return '
Warning! Demo test version does not allow changes to these items.
'; } /** Show System Info (status) at item > Settings General page * Link: http://server.com/wp-admin/admin.php?page=wpbm-settings&system_info=show#wpbm_general_settings_system_info_metabox */ function wpbm_system_info() { if ( wpbm_is_this_demo() ) return; if ( current_user_can( 'activate_plugins' ) ) { // Only for Administrator or Super admin. More here: https://codex.wordpress.org/Roles_and_Capabilities global $wpdb, $wp_version; $all_plugins = get_plugins(); $active_plugins = get_option( 'active_plugins' ); $mysql_info = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" ); if ( is_array( $mysql_info ) ) $sql_mode = $mysql_info[0]->Value; if ( empty( $sql_mode ) ) $sql_mode = 'Not set'; $safe_mode = ( ini_get( 'safe_mode' ) ) ? 'On' : 'Off'; $allow_url_fopen = ( ini_get( 'allow_url_fopen' ) ) ? 'On' : 'Off'; $upload_max_filesize = ( ini_get( 'upload_max_filesize' ) ) ? ini_get( 'upload_max_filesize' ) : 'N/A'; $post_max_size = ( ini_get( 'post_max_size' ) ) ? ini_get( 'post_max_size' ) : 'N/A'; $max_execution_time = ( ini_get( 'max_execution_time' ) ) ? ini_get( 'max_execution_time' ) : 'N/A'; $memory_limit = ( ini_get( 'memory_limit' ) ) ? ini_get( 'memory_limit' ) : 'N/A'; $memory_usage = ( function_exists( 'memory_get_usage' ) ) ? round( memory_get_usage() / 1024 / 1024, 2 ) . ' Mb' : 'N/A'; $exif_read_data = ( is_callable( 'exif_read_data' ) ) ? 'Yes' . " ( V" . substr( phpversion( 'exif' ), 0, 4 ) . ")" : 'No'; $iptcparse = ( is_callable( 'iptcparse' ) ) ? 'Yes' : 'No'; $xml_parser_create = ( is_callable( 'xml_parser_create' ) ) ? 'Yes' : 'No'; $theme = ( function_exists( 'wp_get_theme' ) ) ? wp_get_theme() : get_theme( get_current_theme() ); if ( function_exists( 'is_multisite' ) ) { if ( is_multisite() ) $multisite = 'Yes'; else $multisite = 'No'; } else { $multisite = 'N/A'; } $system_info = array( 'system_info' => '', 'php_info' => '', 'active_plugins' => array(), //FixIn: 2.0.25.1 'inactive_plugins' => array() //FixIn: 2.0.25.1 ); $ver_small_name = get_wpbm_version(); if ( class_exists( 'wpbm_multiuser' ) ) $ver_small_name = 'multiuser'; $system_info['system_info'] = array( 'Plugin Update' => ( defined( 'WPBM_VERSION' ) ) ? WPBM_VERSION : 'N/A', 'Plugin Version' => ucwords( $ver_small_name ), 'Plugin Update Date' => date( "Y-m-d", filemtime( WPBM_FILE ) ), 'WP Version' => $wp_version, 'WP DEBUG' => ( ( defined('WP_DEBUG') ) && ( WP_DEBUG ) ) ? 'On' : 'Off', 'WP DB Version' => get_option( 'db_version' ), 'Operating System' => PHP_OS, 'Server' => $_SERVER["SERVER_SOFTWARE"], 'PHP Version' => PHP_VERSION, 'PHP Safe Mode' => $safe_mode, 'MYSQL Version' => $wpdb->get_var( "SELECT VERSION() AS version" ), 'SQL Mode' => $sql_mode, 'Memory usage' => $memory_usage, 'Site URL' => get_option( 'siteurl' ), 'Home URL' => home_url(), 'SERVER[HTTP_HOST]' => $_SERVER['HTTP_HOST'], 'SERVER[SERVER_NAME]' => $_SERVER['SERVER_NAME'], 'Multisite' => $multisite, 'Active Theme' => $theme['Name'] . ' ' . $theme['Version'] ); $system_info['php_info'] = array( 'PHP Version' => PHP_VERSION, 'PHP Safe Mode' => $safe_mode, 'PHP Memory Limit' => '' . $memory_limit . '', 'PHP Max Script Execute Time' => '' . $max_execution_time . '', 'PHP Max Post Size' => '' . $post_max_size . '', 'PHP MAX Input Vars' => '' . ( ( ini_get( 'max_input_vars' ) ) ? ini_get( 'max_input_vars' ) : 'N/A' ) . '', //How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately). 'PHP Max Upload Size' => $upload_max_filesize, 'PHP Allow URL fopen' => $allow_url_fopen, 'PHP Exif support' => $exif_read_data, 'PHP IPTC support' => $iptcparse, 'PHP XML support' => $xml_parser_create ); $system_info['php_info']['PHP cURL'] = ( function_exists('curl_init') ) ? 'On' : 'Off'; $system_info['php_info']['Max Nesting Level'] = ( ( ini_get( 'max_input_nesting_level' ) ) ? ini_get( 'max_input_nesting_level' ) : 'N/A' ); $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 $system_info['php_info']['Log'] = ( ( ini_get( 'error_log' ) ) ? ini_get( 'error_log' ) : 'N/A' ); if ( ini_get( "suhosin.get.max_value_length" ) ) { $system_info['suhosin_info'] = array(); $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' ); $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' ); $system_info['suhosin_info']['POST max_totalname_length'] = ( ( ini_get( 'suhosin.post.max_totalname_length' ) ) ? ini_get( 'suhosin.post.max_totalname_length' ) : 'N/A' ); $system_info['suhosin_info']['REQUEST max_totalname_length'] = ( ( ini_get( 'suhosin.request.max_totalname_length' ) ) ? ini_get( 'suhosin.request.max_totalname_length' ) : 'N/A' ); $system_info['suhosin_info']['POST max_vars'] = ( ( ini_get( 'suhosin.post.max_vars' ) ) ? ini_get( 'suhosin.post.max_vars' ) : 'N/A' ); $system_info['suhosin_info']['REQUEST max_vars'] = ( ( ini_get( 'suhosin.request.max_vars' ) ) ? ini_get( 'suhosin.request.max_vars' ) : 'N/A' ); $system_info['suhosin_info']['POST max_value_length'] = ( ( ini_get( 'suhosin.post.max_value_length' ) ) ? ini_get( 'suhosin.post.max_value_length' ) : 'N/A' ); $system_info['suhosin_info']['REQUEST max_value_length'] = ( ( ini_get( 'suhosin.request.max_value_length' ) ) ? ini_get( 'suhosin.request.max_value_length' ) : 'N/A' ); $system_info['suhosin_info']['POST max_name_length'] = ( ( ini_get( 'suhosin.post.max_name_length' ) ) ? ini_get( 'suhosin.post.max_name_length' ) : 'N/A' ); $system_info['suhosin_info']['REQUEST max_varname_length'] = ( ( ini_get( 'suhosin.request.max_varname_length' ) ) ? ini_get( 'suhosin.request.max_varname_length' ) : 'N/A' ); $system_info['suhosin_info']['POST max_array_depth'] = ( ( ini_get( 'suhosin.post.max_array_depth' ) ) ? ini_get( 'suhosin.post.max_array_depth' ) : 'N/A' ); $system_info['suhosin_info']['REQUEST max_array_depth'] = ( ( ini_get( 'suhosin.request.max_array_depth' ) ) ? ini_get( 'suhosin.request.max_array_depth' ) : 'N/A' ); } if ( function_exists('gd_info') ) { $gd_info = gd_info(); if ( isset( $gd_info['GD Version'] ) ) $gd_info = $gd_info['GD Version']; else $gd_info = json_encode( $gd_info ); } else { $gd_info = 'Off'; } $system_info['php_info']['PHP GD'] = $gd_info; // More here https://docs.woocommerce.com/document/problems-with-large-amounts-of-data-not-saving-variations-rates-etc/ foreach ( $all_plugins as $path => $plugin ) { if ( is_plugin_active( $path ) ) { $system_info['active_plugins'][ $plugin['Name'] ] = $plugin['Version']; } else { $system_info['inactive_plugins'][ $plugin['Name'] ] = $plugin['Version']; } } // Showing foreach ( $system_info as $section_name => $section_values ) { ?> $value ) { ?>

Commonly required configuration vars in php.ini file:

General section:

memory_limit = 256M
max_execution_time = 120
post_max_size = 8M
upload_max_filesize = 8M
max_input_vars = 20480
post_max_size = 64M

Suhosin section (if installed):

suhosin.post.max_array_index_length = 1024
suhosin.post.max_totalname_length = 65535
suhosin.post.max_vars = 2048
suhosin.post.max_value_length = 1000000
suhosin.post.max_name_length = 256
suhosin.post.max_array_depth = 1000
suhosin.request.max_array_index_length = 1024
suhosin.request.max_totalname_length = 65535
suhosin.request.max_vars = 2048
suhosin.request.max_value_length = 1000000
suhosin.request.max_varname_length = 256
suhosin.request.max_array_depth = 1000
= 0 ) { return true; } else { return false; } } // // //////////////////////////////////////////////////////////////////////////////// // F o r m a t t i n g //////////////////////////////////////////////////////////////////////////////// /** * Sanitize term to Slug format (no spaces, lowercase). * urldecode - reverse munging of UTF8 characters. * * @param mixed $value * @return string */ function wpbm_get_slug_format( $value ) { return urldecode( sanitize_title( $value ) ); } /** * Get Slug Format Option Value for saving to the options table. * Replacing - to _ and restrict length to 64 characters. * * @param string $value * @return string */ function wpbm_get_slug_format_4_option_name( $value ) { $value = wpbm_get_slug_format( $value ); $value = str_replace('-', '_', $value); $value = substr($value, 0, 64); return $value; } /** Insert New Line symbols after
tags. Usefull for the settings pages to show in redable view * * @param type $param * @return type */ function wpbm_nl_after_br($param) { $value = preg_replace( "@(<|<)br\s*/?(>|>)(\r\n)?@", "
", $param ); return $value; } /** * Replace ** to and * to * * @param String $text * @return string */ if ( ! function_exists( 'wpbm_recheck_strong_symbols' ) ) { function wpbm_recheck_strong_symbols( $text ){ $patterns = '/(\*\*)(\s*[^\*\*]*)(\*\*)/'; $replacement = '${2}'; $value_return = preg_replace($patterns, $replacement, $text); $patterns = '/(\*)(\s*[^\*]*)(\*)/'; $replacement = '${2}'; $value_return = preg_replace($patterns, $replacement, $value_return); return $value_return; } } /** Esacpe and replace any HTML entities * * @param type $string * @return string */ function wpbm_esc_to_plain_text( $string ) { // //Replace Link to Link( http://server.com ) // $pattern = "/]*>(.*)<\/a>/" ; //"/(?<=href=(\"|'))[^\"']+(?=(\"|'))/i"; // $newurl = "$4 ($2)"; // $string = preg_replace($pattern,$newurl,$string); // 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 $plain_search_array = array( "/\r/", // Non-legal carriage return '/&(nbsp|#160);/i', // Non-breaking space '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148|#34|#034);/i', // Double quotes //FixIn: 2.0.1.6 '/&(apos|rsquo|lsquo|#8216|#8217|#39|#039);/i', // Single quotes //FixIn: 2.0.1.6 '/>/i', // Greater-than '/</i', // Less-than '/&/i', // Ampersand '/&/i', // Ampersand '/&/i', // Ampersand '/&(copy|#169);/i', // Copyright '/&(trade|#8482|#153);/i', // Trademark '/&(reg|#174);/i', // Registered '/&(mdash|#151|#8212);/i', // mdash '/&(ndash|minus|#8211|#8722);/i', // ndash '/&(bull|#149|#8226);/i', // Bullet '/&(pound|#163);/i', // Pound sign '/&(euro|#8364);/i', // Euro sign '/$/', // Dollar sign '/&[^&;]+;/i', // Unknown/unhandled entities '/[ ]{2,}/' // Runs of spaces, post-handling ); // List of symbols for Replace $get_plain_replace_array = array( '', // Non-legal carriage return ' ', // Non-breaking space '"', // Double quotes "'", // Single quotes '>', // Greater-than '<', // Less-than '&', // Ampersand '&', // Ampersand '&', // Ampersand '(c)', // Copyright '(tm)', // Trademark '(R)', // Registered '--', // mdash '-', // ndash '*', // Bullet '£', // Pound sign 'EUR', // Euro sign. € ? '$', // Dollar sign '', // Unknown/unhandled entities ' ' // Runs of spaces, post-handling ); $newstring = preg_replace( $plain_search_array, $get_plain_replace_array, strip_tags( $string ) ); return $newstring; } //
// //////////////////////////////////////////////////////////////////////////////// // S u p p o r t Functions //////////////////////////////////////////////////////////////////////////////// /** Replace shortcodes in string * * @param string $subject - string to manipulate * @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, .... ) * @param mixed $replace_unknown_shortcodes - replace unknown params, if false, then no replace unknown params * @return string */ function wpbm_replace_shortcodes( $subject, $replace_array , $replace_unknown_shortcodes = ' ' ) { $defaults = array( 'ip' => apply_wpbm_filter( 'wpbm_get_user_ip' ) , 'blogname' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) , 'siteurl' => get_site_url() ); $replace = wp_parse_args( $replace_array, $defaults ); foreach ( $replace as $replace_shortcode => $replace_value ) { $subject = str_replace( array( '[' . $replace_shortcode . ']' , '{' . $replace_shortcode . '}' ) , $replace_value , $subject ); } // Remove all shortcodes, which is not replaced early. if ( $replace_unknown_shortcodes !== false ) $subject = preg_replace( '/[\s]{0,}[\[\{]{1}[a-zA-Z][0-9a-zA-Z:._-]{0,}[\]\}]{1}[\s]{0,}/', $replace_unknown_shortcodes, $subject ); return $subject; } /** Simple hack to make array strings lowercase * * @param type $array * @return type */ function wpbm_arraytolower( $array ){ return unserialize( strtolower( serialize( $array ) ) ); } /** Support 'hash_equals' this function at older servers than PHP 5.6.0 */ if ( !function_exists( 'hash_equals' ) ) { function hash_equals( $known_string, $user_string ) { $ret = 0; if ( strlen( $known_string ) !== strlen( $user_string ) ) { $user_string = $known_string; $ret = 1; } $res = $known_string ^ $user_string; for ( $i = strlen( $res ) - 1; $i >= 0; --$i ) { $ret |= ord( $res[$i] ); } return !$ret; } } /** Check if this valid timestamp * * @param string|int $timestamp * @return bool */ function wpbm_is_valid_timestamp( $timestamp ) { return ( ( (string) (int) $timestamp === $timestamp) && ($timestamp <= PHP_INT_MAX) && ($timestamp >= ~PHP_INT_MAX) ); } // // //////////////////////////////////////////////////////////////////////////////// // F i l e s && U R L s //////////////////////////////////////////////////////////////////////////////// /** Get absolute URL to relative plugin path. * Depend from the WPBM_MIN contant can be load minified version of file, if its exist * @param string $path - path * @return string */ function wpbm_plugin_url( $path ) { if ( ( defined( 'WPBM_MIN' ) ) && ( WPBM_MIN ) ){ $path_min = $path; if ( substr( $path_min , -3 ) === '.js' ) { $path_min = substr( $path_min , 0, -3 ) . '.min.js'; } if ( substr( $path_min , -4 ) === '.css' ) { $path_min = substr( $path_min , 0, -4 ) . '.min.css'; } if ( file_exists( trailingslashit( WPBM_PLUGIN_DIR ) . ltrim( $path_min, '/\\' ) ) ) // check if this file exist return trailingslashit( WPBM_PLUGIN_URL ) . ltrim( $path_min, '/\\' ); } return trailingslashit( WPBM_PLUGIN_URL ) . ltrim( $path, '/\\' ); } /** Check if such file exist or not. * * @param string $path - relative path to file (relative to plugin folder). * @return boolean true | false */ function wpbm_is_file_exist( $path ) { if ( file_exists( trailingslashit( WPBM_PLUGIN_DIR ) . ltrim( $path, '/\\' ) ) ) // check if this file exist return true; else return false; } /** Set URL from absolute to relative (starting from /) * * @param type $url * @return type */ function wpbm_set_relative_url( $url ){ $url = esc_url_raw($url); $url_path = parse_url($url, PHP_URL_PATH); $url_path = ( empty($url_path) ? $url : $url_path ); $url = trim($url_path, '/'); return '/' . $url; } /** Get Correct Relative URL * * @param type $link * @return string */ function wpbm_make_link_relative( $link ){ if ( $link == get_option('siteurl') ) $link = '/'; $link = '/' . trim( wp_make_link_relative( $link ), '/' ); return $link; } /** Get Correct Absolute URL * * @param string $link * @return type */ function wpbm_make_link_absolute( $link ){ if ( ( $link != get_option('siteurl') ) && ( strpos($link, 'http') !== 0 ) ) $link = get_option('siteurl') . '/' . trim( wp_make_link_relative( $link ), '/' ); return esc_js( $link ) ; } if (!function_exists ('get_file_data_wpdev')) { /** Get header info from this file, just for compatibility with WordPress 2.8 and older versions * * @param type $file * @param type $default_headers * @param type $context * @return type */ function get_file_data_wpdev( $file, $default_headers, $context = '' ) { // We don't need to write to the file, so just open for reading. $fp = fopen( $file, 'r' ); // Pull only the first 8kiB of the file in. $file_data = fread( $fp, 8192 ); // PHP will close file handle, but we are good citizens. fclose( $fp ); if( $context != '' ) { $extra_headers = array(); //apply_filters( "extra_$context".'_headers', array() ); $extra_headers = array_flip( $extra_headers ); foreach( $extra_headers as $key=>$value ) { $extra_headers[$key] = $key; } $all_headers = array_merge($extra_headers, $default_headers); } else { $all_headers = $default_headers; } foreach ( $all_headers as $field => $regex ) { preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field}); if ( !empty( ${$field} ) ) ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] )); else ${$field} = ''; } $file_data = compact( array_keys( $all_headers ) ); return $file_data; } } /** Get content from specific URL * * @param string $url * @return string|boolean (false on error) */ function wpbm_get_ssl_page_content( $url ) { $request = new WP_Http(); $result = $request->request( $url , array( // Default Parameters 'reject_unsafe_urls' => true, //FixIn: 2.0.29.1 '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 // 'method' => 'GET', // 'timeout' => 5, // timeout value for an HTTP request. // 'redirection' => 5, // number of redirects allowed during an HTTP request. // 'httpversion' => '1.0', // 'user-agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), // 'reject_unsafe_urls' => false, // 'blocking' => true, // 'headers' => array(), // 'cookies' => array(), // 'body' => null, // 'compress' => false, // 'decompress' => true, // 'sslverify' => true, // 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', // 'stream' => false, // 'filename' => null, // 'limit_response_size' => null ) ); if ( ( ! is_wp_error( $result ) ) && ( $result[ 'response' ][ 'code' ] == '200' ) ) { return $result[ 'body' ]; } else { //FixIn: 2.0.2.2 if ( is_wp_error( $result ) ) { $error_message = $result->get_error_message(); } else { $error_message = __( 'Unknown error during downloading feed', 'booking-manager' ); // Show more detail info of not ability to download .ics feeds. //FixIn: 2.0.10.5 $error_message .= $result[ 'body' ]; //do_action( 'wpbc_admin_show_top_notice', $error_message, 'error', 5000 ); //die; } do_action( 'wpbc_admin_show_top_notice', $error_message, 'error', 5000 ); // N_O_T_I_C_E in H_E_A_D_E_R // debuge($error_message); //FixIn: 2.0.1.3 //FixIn: 2.0.8.2 return false; } } /** Count the number of bytes of a given string. * Input string is expected to be ASCII or UTF-8 encoded. * Warning: the function doesn't return the number of chars * in the string, but the number of bytes. * See http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 * for information on UTF-8. * * @param string $str The string to compute number of bytes * * @return The length in bytes of the given string. */ function wpbm_get_bytes_from_str( $str ) { // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT // Number of characters in string $strlen_var = strlen( $str ); $d = 0; // string bytes counter // Iterate over every character in the string, escaping with a slash or encoding to UTF-8 where necessary for ( $c = 0; $c < $strlen_var; ++ $c ) { $ord_var_c = ord( $str[$c] ); //FixIn: 2.0.17.1 switch ( true ) { case(($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): // characters U-00000000 - U-0000007F (same as ASCII) $d ++; break; case(($ord_var_c & 0xE0) == 0xC0): // characters U-00000080 - U-000007FF, mask 110XXXXX $d += 2; break; case(($ord_var_c & 0xF0) == 0xE0): // characters U-00000800 - U-0000FFFF, mask 1110XXXX $d += 3; break; case(($ord_var_c & 0xF8) == 0xF0): // characters U-00010000 - U-001FFFFF, mask 11110XXX $d += 4; break; case(($ord_var_c & 0xFC) == 0xF8): // characters U-00200000 - U-03FFFFFF, mask 111110XX $d += 5; break; case(($ord_var_c & 0xFE) == 0xFC): // characters U-04000000 - U-7FFFFFFF, mask 1111110X $d += 6; break; default: $d ++; } } return $d; } // // //////////////////////////////////////////////////////////////////////////// // A d m i n M e n u L i n k s //////////////////////////////////////////////////////////////////////////// /** Get URL to specific Admin Menu page * * @param string $menu_type - { item | add | resources | settings } * @param boolean $is_absolute_url - Absolute or relative url { default: true } * @return string - URL to menu */ function wpbm_get_menu_url( $menu_type, $is_absolute_url = true ) { switch ( $menu_type) { case 'master': // Master $link = 'oplugins&tab=wpbm'; break; case 'add': // Add New case 'new': // Add New $link = 'oplugins&wpbm-new'; break; case 'settings': // Settings case 'options': $link = 'oplugins&tab=wpbm-settings'; break; default: // Master $link = 'oplugins'; break; } if ( $is_absolute_url ) { $link = admin_url( 'admin.php' ) . '?page=' . $link ; } return $link; } // // // // // // // // // // // // // // // // // // // // // // // // // / /** Get URL of item Listing or Calendar Overview page * * @param boolean $is_absolute_url - Absolute or relative url { default: true } * @param boolean $is_old - { default: true } * @return string - URL to menu */ function wpbm_get_master_url( $is_absolute_url = true ) { return wpbm_get_menu_url( 'master', $is_absolute_url ); } /** Get URL of item > Add item page * * @param boolean $is_absolute_url - Absolute or relative url { default: true } * @param boolean $is_old - { default: true } * @return string - URL to menu */ function wpbm_get_new_wpbm_url( $is_absolute_url = true ) { return wpbm_get_menu_url( 'add', $is_absolute_url ); } /** Get URL of item > Settings page * * @param boolean $is_absolute_url - Absolute or relative url { default: true } * @param boolean $is_old - { default: true } * @return string - URL to menu */ function wpbm_get_settings_url( $is_absolute_url = true ) { return wpbm_get_menu_url( 'settings', $is_absolute_url ); } // // // // // // // // // // // // // // // // // // // // // // // // // / /** Check if this item Listing or Calendar Overview page * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' * @return boolean true | false */ function wpbm_is_master_page( $server_param = 'REQUEST_URI' ) { if ( ( is_admin() ) && ( strpos($_SERVER[ $server_param ],'page=oplugins') !== false ) && ( strpos($_SERVER[ $server_param ],'tab=wpbm-') === false ) && // not the settings ( ( strpos($_SERVER[ $server_param ],'tab=wpbm') !== false ) // tab specified || ( strpos($_SERVER[ $server_param ],'tab=') === false ) ) // or tab not specified at all ) { return true; } return false; } /** Check if this item > Add item page * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' * @return boolean true | false */ function wpbm_is_new_wpbm_page( $server_param = 'REQUEST_URI' ) { if ( ( is_admin() ) && ( strpos($_SERVER[ $server_param ],'page=oplugins') !== false ) && ( strpos($_SERVER[ $server_param ],'tab=wpbm-new') !== false ) ) { return true; } return false; } /** Check if this item > Settings page * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' * @return boolean true | false */ function wpbm_is_settings_page( $server_param = 'REQUEST_URI' ) { if ( ( is_admin() ) && ( strpos($_SERVER[ $server_param ],'page=oplugins') !== false ) && ( strpos($_SERVER[ $server_param ],'tab=wpbm-settings') !== false ) ) { return true; } return false; } // // //////////////////////////////////////////////////////////////////////////// // A d m i n U I E l e m e n t s //////////////////////////////////////////////////////////////////////////// /** Get Number of new items * * @return int */ function wpbm_get_number_new_items(){ return 0; } /** Show Admin B A R . * * @global type $wp_admin_bar * @return type */ function wp_admin_bar_items_menu(){ global $wp_admin_bar; $current_user = wp_get_current_user(); $curr_user_role = get_wpbm_option( 'wpbm_user_role_master' ); $level = 10; if ($curr_user_role == 'administrator') $level = 10; else if ($curr_user_role == 'editor') $level = 7; else if ($curr_user_role == 'author') $level = 2; else if ($curr_user_role == 'contributor') $level = 1; else if ($curr_user_role == 'subscriber') $level = 0; if ( ( $current_user->user_level < $level ) || ! is_admin_bar_showing() ) return; $update_count = wpbm_get_number_new_items(); // 0 $title = 'Booking Manager'; $update_title = $title; if ( $update_count > 0 ) { $update_count_title = " " . number_format_i18n($update_count) . "" ; //id='wpbm-count' $update_title .= $update_count_title; } $link_items = wpbm_get_master_url(); $link_settings = wpbm_get_settings_url(); $wp_admin_bar->add_menu( array( 'id' => 'bar_wpbm', 'title' => $update_title , 'href' => wpbm_get_master_url() ) ); $curr_user_role_settings = get_wpbm_option( 'wpbm_user_role_settings' ); $level = 10; if ($curr_user_role_settings == 'administrator') $level = 10; else if ($curr_user_role_settings == 'editor') $level = 7; else if ($curr_user_role_settings == 'author') $level = 2; else if ($curr_user_role_settings == 'contributor') $level = 1; else if ($curr_user_role_settings == 'subscriber') $level = 0; if ( ( ($current_user->user_level < $level) ) || !is_admin_bar_showing() ) return; $wp_admin_bar->add_menu( array( 'id' => 'bar_wpbm_new', 'title' => __( 'Add New', 'booking-manager'), 'href' => wpbm_get_new_wpbm_url(), 'parent' => 'bar_wpbm', ) ); $wp_admin_bar->add_menu( array( 'id' => 'bar_wpbm_settings', 'title' => __( 'Settings', 'booking-manager'), 'href' => wpbm_get_settings_url(), 'parent' => 'bar_wpbm', ) ); $wp_admin_bar->add_menu( array( 'id' => 'bar_wpbm_settings_email', 'title' => __( 'Emails', 'booking-manager'), 'href' => $link_settings . '&tab=email', 'parent' => 'bar_wpbm_settings' ) ); } // add_action( 'admin_bar_menu', 'wp_admin_bar_items_menu', 70 ); // Add Admin Bar /** Show Rating link at footer */ function wpbm_show_wpbm_footer(){ if ( ! wpbm_is_this_demo() ) { $message = sprintf( __( 'If you like %s please leave us a %s rating. A huge thank you in advance!', 'booking-manager') , 'Booking Manager' . ' ' . WPBM_VERSION_NUM , '' . '★★★★★' . '' ); echo ''; ?> // //////////////////////////////////////////////////////////////////////////// // DB - cheking if table, field or index exists //////////////////////////////////////////////////////////////////////////// /** * Check if table exist * * @global type $wpdb * @param string $tablename * @return 0|1 */ function wpbm_is_table_exists( $tablename ) { global $wpdb; if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) ) $tablename = $wpdb->prefix . $tablename ; $sql_check_table = $wpdb->prepare("SHOW TABLES LIKE %s" , $tablename ); //FixIn 5.4.3 $res = $wpdb->get_results( $sql_check_table ); return count($res); //FixIn 5.4.3 /* $sql_check_table = $wpdb->prepare(" SELECT COUNT(*) AS count FROM information_schema.tables WHERE table_schema = '". DB_NAME ."' AND table_name = %s " , $tablename ); $res = $wpdb->get_results( $sql_check_table ); return $res[0]->count;*/ } /** * Check if table exist * * @global type $wpdb * @param string $tablename * @param type $fieldname * @return 0|1 */ function wpbm_is_field_in_table_exists( $tablename , $fieldname) { global $wpdb; if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) ) $tablename = $wpdb->prefix . $tablename ; $sql_check_table = "SHOW COLUMNS FROM {$tablename}" ; $res = $wpdb->get_results( $sql_check_table ); foreach ($res as $fld) { if ($fld->Field == $fieldname) return 1; } return 0; } /** * Check if index exist * * @global type $wpdb * @param string $tablename * @param type $fieldindex * @return 0|1 */ function wpbm_is_index_in_table_exists( $tablename , $fieldindex) { global $wpdb; if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) ) $tablename = $wpdb->prefix . $tablename ; $sql_check_table = $wpdb->prepare("SHOW INDEX FROM {$tablename} WHERE Key_name = %s", $fieldindex ); $res = $wpdb->get_results( $sql_check_table ); if (count($res)>0) return 1; else return 0; } // // //////////////////////////////////////////////////////////////////////////// // E s c a p i n g //////////////////////////////////////////////////////////////////////////// /** Transform the REQESTS parameters (GET and POST) into URL * * @param type $page_param * @param array $exclude_params * @param type $only_these_parameters * @return type */ function wpbm_get_params_in_url( $page_param , $exclude_params = array(), $only_these_parameters = false, $is_escape_url = false, $only_get = false ){ $exclude_params[] = 'page'; if ( isset( $_GET['page'] ) ) $page_param = $_GET['page']; $get_paramaters = array( 'page' => $page_param ); if ( $only_get ) $check_params = $_GET; else $check_params = $_REQUEST; //debuge($check_params); foreach ( $check_params as $prm_key => $prm_value ) { // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 ) if ( ( is_string( $prm_value ) ) || ( is_numeric( $prm_value ) ) ) { if ( strlen( $prm_value ) > 1000 ) { // Check about TOOO long parameters, if it exist then reset it. $prm_value = ''; } if ( ! in_array( $prm_key, $exclude_params ) ) if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) ) $get_paramaters[ $prm_key ] = $prm_value; } } //debuge($check_params, $get_paramaters, $exclude_params ); $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) ); if ( $is_escape_url ) $url = esc_url( $url ); return $url; /* // Old variant: if ( isset( $_GET['page'] ) ) $page_param = $_GET['page']; $url_start = 'admin.php?page=' . $page_param . '&'; $exclude_params[] = 'page'; foreach ( $_REQUEST as $prm_key => $prm_value ) { if ( !in_array( $prm_key, $exclude_params ) ) if ( ($only_these_parameters === false) || ( in_array( $prm_key, $only_these_parameters ) ) ) $url_start .= $prm_key . '=' . $prm_value . '&'; } $url_start = substr( $url_start, 0, -1 ); return $url_start; */ } /** Clean Request Parameters * */ function wpbm_check_request_paramters() { $clean_params = array(); $clean_params[ 'wh_wpbm_id' ] = 'digit_or_csd'; // '0' | '1' | '' $clean_params[ 'wh_wpbm_date' ] = 'digit_or_date'; // number | date 2016-07-20 $clean_params[ 'wh_wpbm_datenext' ] = 'd'; // '1' | '2' .... $clean_params[ 'wh_pay_statuscustom' ] = 's'; //string !!! LIKE !!! $clean_params[ 'wh_pay_status' ] = array( 'all', 'group_ok', 'group_unknown', 'group_pending', 'group_failed' ); foreach ( $clean_params as $request_key => $clean_type ) { // elements only listed in array:: if ( is_array( $clean_type ) ) { // check only values from the list in this array if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( ! in_array( $_REQUEST[ $request_key ], $clean_type ) ) ) $clean_type = 's'; else $clean_type = 'checked_skip_it'; } switch ( $clean_type ) { case 'checked_skip_it': break; case 'digit_or_date': // digit or comma separated digit if ( isset( $_REQUEST[ $request_key ] ) ) $_REQUEST[ $request_key ] = wpbm_clean_digit_or_date( $_REQUEST[ $request_key ] ); // nums break; case 'digit_or_csd': // digit or comma separated digit if ( isset( $_REQUEST[ $request_key ] ) ) $_REQUEST[ $request_key ] = wpbm_clean_digit_or_csd( $_REQUEST[ $request_key ] ); // nums break; case 's': // string if ( isset( $_REQUEST[ $request_key ] ) ) $_REQUEST[ $request_key ] = wpbm_clean_like_string_for_db( $_REQUEST[ $request_key ] ); break; case 'd': // digit if ( isset( $_REQUEST[ $request_key ] ) ) if ( $_REQUEST[ $request_key ] !== '' ) $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] ); break; default: if ( isset( $_REQUEST[ $request_key ] ) ) { $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] ); } break; } } } /** Check paramter if it number or comma separated list of numbers * * @global type $wpdb * @param string $value * @return string * * Exmaple: wpbm_clean_digit_or_csd( '12,a,45,9' ) => '12,0,45,9' * or wpbm_clean_digit_or_csd( '10a' ) => '10 * or wpbm_clean_digit_or_csd( array( '12,a,45,9', '10a' ) ) => array ( '12,0,45,9', '10' ) */ function wpbm_clean_digit_or_csd( $value ) { //FixIn:6.2.1.4 if ( $value === '' ) return $value; if ( is_array( $value ) ) { foreach ( $value as $key => $check_value ) { $value[ $key ] = wpbm_clean_digit_or_csd( $check_value ); } return $value; } global $wpdb; $value = str_replace( ';', ',', $value ); $array_of_nums = explode(',', $value); $result = array(); foreach ($array_of_nums as $check_element) { $result[] = $wpdb->prepare( "%d", $check_element ); } $result = implode(',', $result ); return $result; } /** Cehck about Valid date, like 2016-07-20 or digit * * @param string $value * @return string or int */ function wpbm_clean_digit_or_date( $value ) { //FixIn:6.2.1.4 if ( $value === '' ) return $value; if ( preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $value ) ) { return $value; // Date is valid in format: 2016-07-20 } else { return intval( $value ); } } /** Check $value for injection here * * @param type $value * @return type */ function wpbm_clean_parameter( $value ) { $value = preg_replace( '/<[^>]*>/', '', $value ); // clean any tags $value = str_replace( '<', ' ', $value ); $value = str_replace( '>', ' ', $value ); $value = strip_tags( $value ); // Clean SQL injection $value = esc_sql( $value ); return $value; } function wpbm_esc_like( $value_trimmed ) { global $wpdb; if ( method_exists( $wpdb ,'esc_like' ) ) return $wpdb->esc_like( $value_trimmed ); // Its require minimum WP 4.0.0 else return addcslashes( $value_trimmed, '_%\\' ); // Direct implementation from $wpdb->esc_like( } /** Clean user string for using in SQL LIKE statement - append to LIKE sql * * @param string $value - to clean * @return string - escaped * Exmaple: * $search_escaped_like_title = wpbm_clean_like_string_for_append_in_sql_for_db( $input_var ); * * $where_sql = " WHERE title LIKE ". $search_escaped_like_title ." "; */ function wpbm_clean_like_string_for_append_in_sql_for_db( $value ) { global $wpdb; $value_trimmed = trim( stripslashes( $value ) ); $wild = '%'; $like = $wild . wpbm_esc_like( $value_trimmed ) . $wild; $sql = $wpdb->prepare( "'%s'", $like ); return $sql; /* Help: * First half of escaping for LIKE special characters % and _ before preparing for MySQL. * Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security. * * Example Prepared Statement: * * $wild = '%'; * $find = 'only 43% of planets'; * $like = $wild . wpbm_esc_like( $find ) . $wild; * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like ); * * Example Escape Chain: * * $sql = esc_sql( wpbm_esc_like( $input ) ); */ } /** Clean string for using in SQL LIKE requests inside single quotes: WHERE title LIKE '%". $escaped_search_title ."%' * Replaced _ to \_ % to \% \ to \\ * @param string $value - to clean * @return string - escaped * Exmaple: * $search_escaped_like_title = wpbm_clean_like_string_for_db( $input_var ); * * $where_sql = " WHERE title LIKE '%". $search_escaped_like_title ."%' "; * * Important! Use SINGLE quotes after in SQL query: LIKE '%".$data."%' */ function wpbm_clean_like_string_for_db( $value ){ global $wpdb; $value_trimmed = trim( stripslashes( $value ) ); $value_trimmed = wpbm_esc_like( $value_trimmed ); $value = trim( $wpdb->prepare( "'%s'", $value_trimmed ) , "'" ); return $value; /* Help: * First half of escaping for LIKE special characters % and _ before preparing for MySQL. * Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security. * * Example Prepared Statement: * * $wild = '%'; * $find = 'only 43% of planets'; * $like = $wild . wpbm_esc_like( $find ) . $wild; * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like ); * * Example Escape Chain: * * $sql = esc_sql( wpbm_esc_like( $input ) ); */ } /** Escape string from SQL for the HTML form field * * @param string $value * @return string * * Used: esc_sql function. * * https://codex.wordpress.org/Function_Reference/esc_sql * Note: Be careful to use this function correctly. It will only escape values to be used in strings in the query. * That is, it only provides escaping for values that will be within quotes in the SQL (as in field = '{$escaped_value}'). * If your value is not going to be within quotes, your code will still be vulnerable to SQL injection. * For example, this is vulnerable, because the escaped value is not surrounded by quotes in the SQL query: * ORDER BY {$escaped_value}. As such, this function does not escape unquoted numeric values, field names, or SQL keywords. * */ function wpbm_clean_string_for_form( $value ){ global $wpdb; $value_trimmed = trim( stripslashes( $value ) ); $esc_sql_value = esc_sql( $value_trimmed ); //$value = trim( $wpdb->prepare( "'%s'", $esc_sql_value ) , "'" ); $esc_sql_value = trim( stripslashes( $esc_sql_value ) ); return $esc_sql_value; } // // //////////////////////////////////////////////////////////////////////////////// // U s e r s //////////////////////////////////////////////////////////////////////////////// /** Get ID of active user * * @return type */ function get_wpbm_current_user_id() { $user = wp_get_current_user(); return ( isset( $user->ID ) ? (int) $user->ID : 0 ); } /** Check if Current User have specific Role * * @return bool Whether the current user has the given capability. */ function wpbm_is_current_user_have_this_role( $user_role ) { if ( $user_role == 'administrator' ) $user_role = 'activate_plugins'; if ( $user_role == 'editor' ) $user_role = 'publish_pages'; if ( $user_role == 'author' ) $user_role = 'publish_posts'; if ( $user_role == 'contributor' ) $user_role = 'edit_posts'; if ( $user_role == 'subscriber') $user_role = 'read'; return current_user_can( $user_role ); } function wpbm_get_user_ip() { //return '84.243.195.114' ; // Test //90.36.89.174 if (isset($_SERVER['HTTP_CLIENT_IP'])) { $userIP = $_SERVER['HTTP_CLIENT_IP'] ; } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $userIP = $_SERVER['HTTP_X_FORWARDED_FOR'] ; } elseif (isset($_SERVER['HTTP_X_FORWARDED'])) { $userIP = $_SERVER['HTTP_X_FORWARDED'] ; } elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) { $userIP = $_SERVER['HTTP_FORWARDED_FOR'] ; } elseif (isset($_SERVER['HTTP_FORWARDED'])) { $userIP = $_SERVER['HTTP_FORWARDED'] ; } elseif (isset($_SERVER['REMOTE_ADDR'])) { $userIP = $_SERVER['REMOTE_ADDR'] ; } else { $userIP = "" ; } $userIP = explode( ',', $userIP ); $userIP = array_map( 'trim', $userIP ); return $userIP[0] ; } add_wpbm_filter( 'wpbm_get_user_ip', 'wpbm_get_user_ip' ); // // //////////////////////////////////////////////////////////////////////////////// // Mesages for Admin panel //////////////////////////////////////////////////////////////////////////////// function wpbm_show_fixed_message( $message, $time_to_show , $message_type = 'updated' , $notice_id = 0, $is_dismissible = false ) { // Generate unique HTML ID for the message if ( $notice_id == 0 ) $notice_id = intval( time() * rand(10, 100) ); $notice_id = 'wpbm_system_notice_' . $notice_id; $is_dismissible = false; if ( ( ( $is_dismissible ) && ( ! wpbm_section_is_dismissed( $notice_id ) ) ) || ( ! $is_dismissible ) // || true ){ ?>
0 ) { ?> ×'; if (! empty( $inner_message_id )) $inner_message_id = 'id="wpbm_inner_message_'. $inner_message_id .'"'; $notice = '
' . $notice . '
'; return $notice; } /** Show system info in settings page * * @param string $message ... * @param string $message_type 'info' | 'warning' | 'error' * @param string $title __('Important!' , 'booking-manager') | __('Note' , 'booking-manager') * * Exmaple: wpbm_show_message_in_settings( __( 'Nothing Found', 'booking-manager'), 'warning', __('Important!' , 'booking-manager') ); */ function wpbm_show_message_in_settings( $message, $message_type = 'info', $title = '' , $is_echo = true ) { $message_content = ''; $message_content .= '
'; $message_content .= '
'; if ( ! empty( $title ) ) $message_content .= '' . esc_js( $title ) . ' '; $message_content .= html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ; $message_content .= '
'; $message_content .= '
'; if ( $is_echo ) echo $message_content; else return $message_content; } //
// //////////////////////////////////////////////////////////////////////////////// // Settings Meta Boxes //////////////////////////////////////////////////////////////////////////////// function wpbm_open_meta_box_section( $metabox_id, $title ) { $my_close_open_win_id = $metabox_id . '_metabox'; //FixIn: 2.0.16.1 ?>


// from Toolbar // //////////////////////////////////////////////////////////////////////////////// // M o d a l s //////////////////////////////////////////////////////////////////////////////// /** Start Loyouts - Modal Window structure */ function wpbm_write_content_for_modals_start_here() { ?> // //////////////////////////////////////////////////////////////////////////////// // Inline J a v a S c r i p t to Footer page //////////////////////////////////////////////////////////////////////////////// /** * Queue JavaScript for later output at footer * * @param string $code */ function wpbm_enqueue_js( $code ) { global $wpbm_queued_js; if ( empty( $wpbm_queued_js ) ) { $wpbm_queued_js = ''; } $wpbm_queued_js .= "\n" . $code . "\n"; } /** * Output any queued javascript code in the footer. */ function wpbm_print_js() { global $wpbm_queued_js; if ( ! empty( $wpbm_queued_js ) ) { echo "\n\n\n"; $wpbm_queued_js = ''; unset( $wpbm_queued_js ); } } // // from Toolbar // //////////////////////////////////////////////////////////////////////////////// // JS & CSS //////////////////////////////////////////////////////////////////////////////// /** Load suport JavaScript for "Items" page*/ function wpbm_js_for_items_page() { $is_use_hints = get_wpbm_option( 'wpbm_is_use_hints_at_admin_panel' ); if ( $is_use_hints == 'On' ) wpbm_bs_javascript_tooltips(); // JS Tooltips wpbm_bs_javascript_popover(); // JS Popover //wpbm_datepicker_js(); // JS Datepicker wpbm_datepicker_css(); // CSS DatePicker } /** Datepicker activation JavaScript */ function wpbm_datepicker_js() { ?> // //////////////////////////////////////////////////////////////////////////////// // R e l o a d p a g e //////////////////////////////////////////////////////////////////////////////// /** * Reload page by using JavaScript * * @param string $url - URL of page to load */ function wpbm_reload_page_by_js( $url ) { $redir = html_entity_decode( esc_url( $url ) ); if ( ! empty( $redir ) ) { ?> '; echo 'window.location.href="'.$url.'";'; echo ''; echo ''; } // // /** Show P a g i n a t i o n * * @param int $summ_number_of_items - total number of items * @param int $active_page_num - number of activated page * @param int $num_items_per_page - number of items per page * @param array $only_these_parameters - array of keys to exclude from links * @param string $url_sufix - usefule for anchor to HTML section with specific ID, Example: '#my_section' */ function wpbm_show_pagination( $summ_number_of_items, $active_page_num, $num_items_per_page , $only_these_parameters = false, $url_sufix = '' ) { if ( empty( $num_items_per_page ) ) { $num_items_per_page = '10'; } $pages_number = ceil( $summ_number_of_items / $num_items_per_page ); if ( $pages_number < 2 ) return; //Fix: 5.1.4 - Just in case we are having tooo much resources, then we need to show all resources - and its empty string if ( ( isset($_REQUEST['wh_wpbm_type'] ) ) && ( strlen($_REQUEST['wh_wpbm_type']) > 1000 ) ) { $_REQUEST['wh_wpbm_type'] = ''; } // First parameter will overwriten by $_GET['page'] parameter $bk_admin_url = wpbm_get_params_in_url( wpbm_get_master_url( false ), array('page_num'), $only_these_parameters ); ?>
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Dates Format //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** Get Formated Date & time * * @param string $date_sql - 2017-07-31 00:00:00 || 2017-07-31 * @param string $date_format - Optional. - "m / d / Y, D H:i:s" * @param string $seperator - Optional. - " " * @return string - July 29, 2014 12:00 am */ function wpbm_get_date_time_formatted( $date_sql, $date_format = false, $seperator = ' ', $skip_midnight_time = false ) { $return_date = wpbm_get_date_formatted( $date_sql, $date_format ); $return_time = wpbm_get_time_formatted( $date_sql, $date_format, $skip_midnight_time ); if ( ! empty( $return_time ) ) $return_date .= $seperator . $return_time; return $return_date; } /** Get Formated Date * * @param string $date_sql - 2017-07-31 00:00:00 || 2017-07-31 * @param string $date_format - Optional. - "m / d / Y, D" * @param bool $skip_midnight_time - Default false - if 00:00:00 then return ''; * @return string - July 29, 2014 */ function wpbm_get_date_formatted( $date_sql, $date_format = false ) { if ( $date_format === false ) $date_format = get_wpbm_option( 'wpbm_date_format' ); if ( empty( $date_format ) ) $date_format = "m / d / Y, D"; $formated_date = date_i18n( $date_format, strtotime( $date_sql ) ); return $formated_date; } /** Get Formated Date & time * * @param string $date_sql - 2017-07-31 00:00:00 || 2017-07-31 * @param string $time_format - Optional. - "H:i:s" * @return string - 12:00 am */ function wpbm_get_time_formatted( $date_sql, $time_format = false , $skip_midnight_time = false ) { if ( ( $skip_midnight_time ) && ( '00:00:00' == substr( $date_sql, -8 ) ) ) return ''; if ( $time_format === false ) $time_format = get_wpbm_option( 'wpbm_time_format' ); if ( empty( $time_format ) ) $time_format = 'h:i a'; $formated_date = date_i18n( $time_format, strtotime( $date_sql ) ); return $formated_date; } /** Check if "current_day" is tomorrow from "next_day" * * @param string $current_day_sql_check : 2015-02-29 00:00:00 * @param string $next_day_sql_check : 2015-02-30 00:00:00 * @return boolean : true | false */ function wpbm_is_next_day( $current_day_sql_check, $next_day_sql_check ) { // Current day $current_day_unix = strtotime( $current_day_sql_check ); $current_day_midnight_sql = date_i18n( 'Y-m-d', $current_day_unix ); $current_day_midnight_unix = strtotime( $current_day_midnight_sql ); $calc_next_day_unix = strtotime( '+1 day', $current_day_midnight_unix ); // Next day $next_day_unix = strtotime( $next_day_sql_check ); $next_day_midnight_sql = date_i18n( 'Y-m-d', $next_day_unix ); $next_day_midnight_unix = strtotime( $next_day_midnight_sql ); if ( $calc_next_day_unix == $next_day_midnight_unix ) return true; else return false; } /** Check if "current_day" is same day of "other_day" * * @param string $current_day_sql_check : 2015-02-29 00:00:00 * @param string $other_day_sql_check : 2015-02-30 00:00:00 * @return boolean : true | false */ function wpbm_is_this_same_day( $current_day_sql_check, $other_day_sql_check ) { // Current day $current_day_unix = strtotime( $current_day_sql_check ); $current_day_midnight_sql = date_i18n( 'Y-m-d', $current_day_unix ); $current_day_midnight_unix = strtotime( $current_day_midnight_sql ); // Other day $other_day_unix = strtotime( $other_day_sql_check ); $other_day_midnight_sql = date_i18n( 'Y-m-d', $other_day_unix ); $other_day_midnight_unix = strtotime( $other_day_midnight_sql ); if ( $current_day_midnight_unix == $other_day_midnight_unix ) return true; else return false; } /** Get days in short format view * * @param string $days Dates: 15.05.2015, 16.05.2015, 17.05.2015 * @return string Dates in format: 15.05.2015 - 17.05.2015 */ function wpbm_get_dates_short_format( $dates_sql_csv ) { // $days - string with comma seperated dates if ( empty( $dates_sql_csv ) ) return ''; $days = explode( ',', $dates_sql_csv ); $previosday = false; $result_string = ''; $last_show_day = ''; foreach ( $days as $day ) { $is_fin_at_end = false; if ( $previosday === false ) { // First Day $result_string = wpbm_get_date_time_formatted( $day, false, ' ', true ); // echo format for first day $last_show_day = $day; $previosday = $day; // Set previos day for next loop } else { // Not first day if ( wpbm_is_next_day( $previosday, $day ) || wpbm_is_this_same_day( $previosday, $day ) ) { // Check if $day next day from previous $previosday = $day; // Set previos day for next loop $is_fin_at_end = true; } else { if ( $last_show_day !== $previosday ) { // check if previos day was show or no $result_string .= ' - ' . wpbm_get_date_time_formatted( $previosday, false, ' ', true ); // assign in needed format this day } $result_string .= ', ' . wpbm_get_date_time_formatted( $day, false, ' ', true ); // assign in needed format this day $previosday = $day; // Set previos day for next loop $last_show_day = $day; } } } if ( $is_fin_at_end ) { $result_string .= ' - ' . wpbm_get_date_time_formatted( $day, false, ' ', true ); } return $result_string; } //