| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.1 |
| 4 |
* @package Any |
| 5 |
* @category Dubug info showing |
| 6 |
* @author wpdevelop |
| 7 |
* |
| 8 |
* @web-site https://wpbookingcalendar.com/ |
| 9 |
* @email info@wpbookingcalendar.com |
| 10 |
* |
| 11 |
* @modified 09.09.2015 |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 19 |
// D e b u g f u n c t i o n s /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 21 |
|
| 22 |
/* |
| 23 |
* Show values of the arguments list |
| 24 |
*/ |
| 25 |
if (!function_exists ('debuge')) { |
| 26 |
function debuge() { |
| 27 |
$numargs = func_num_args(); |
| 28 |
$var = func_get_args(); |
| 29 |
$makeexit = is_bool( $var[count($var)-1] ) ? $var[ count($var) - 1 ]:false; |
| 30 |
echo "<div><pre class='prettyprint linenums'>"; //FixIn: 8.8.3.11 |
| 31 |
foreach ( $var as $ind => $item ) { |
| 32 |
|
| 33 |
echo "\n<strong> [$ind] " . gettype( $item ) . "</strong>\n"; |
| 34 |
|
| 35 |
if ( 'string' === gettype( $item ) ) { |
| 36 |
echo( htmlentities( $item ) ); |
| 37 |
} else { |
| 38 |
print_r( $item ); |
| 39 |
} |
| 40 |
} |
| 41 |
echo "</pre></div>"; |
| 42 |
echo '<script type="text/javascript"> jQuery(".ajax_respond_insert, .ajax_respond").show(); </script>'; |
| 43 |
if ( $makeexit ) { |
| 44 |
echo '<div style="font-size:18px;float:right;">' . get_num_queries(). '/' . timer_stop(0, 3) . 'qps</div>'; |
| 45 |
exit; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
/* |
| 53 |
* Show debug info for Visitors. This function used for showing debug info for visitors at the website. |
| 54 |
* if first parameter is 'clear', second parameter it's how many mesages (DIV elements) to show in exist view. Negative value, calculate DIV elements from bottom. |
| 55 |
* Example: show_debug( 'clear', -3 ); - show 3 last DIV elements. |
| 56 |
*/ |
| 57 |
if (!function_exists ('show_debug')) { |
| 58 |
//FixIn: 8.8.3.18 |
| 59 |
function show_debug() { |
| 60 |
//TODO: 2023-09-19 13:42 Need to remake it relative to new 'create_booking.php' functionality. We can not simply echo here !!!! |
| 61 |
if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) { |
| 62 |
}else { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
//$numargs = func_num_args(); |
| 67 |
$var = func_get_args(); |
| 68 |
|
| 69 |
if ( 'clear' === $var[0] ) { |
| 70 |
echo '<script type="text/javascript"> |
| 71 |
jQuery(".ajax_respond_insert div").hide(); |
| 72 |
jQuery(".ajax_respond_insert div").slice( '.$var[1].' ).show(); |
| 73 |
</script>'; |
| 74 |
} |
| 75 |
|
| 76 |
$milliseconds = round(microtime(true) * 1000); |
| 77 |
|
| 78 |
echo "<div class='wpbc_debug wpbc_debug_{$milliseconds}'><pre class='prettyprint linenums'>"; |
| 79 |
foreach ( $var as $ind => $item ) { |
| 80 |
echo "\n"; |
| 81 |
|
| 82 |
if ( 'string' === gettype( $item ) ) { |
| 83 |
echo( htmlentities( $item ) ); |
| 84 |
} else { |
| 85 |
print_r( $item ); |
| 86 |
} |
| 87 |
} |
| 88 |
echo "</pre></div>"; |
| 89 |
echo '<script type="text/javascript"> jQuery(".ajax_respond_insert, .ajax_respond").show(); </script>'; |
| 90 |
echo '<script type="text/javascript"> if ( jQuery(".ajax_respond_insert").length == 0 ) {jQuery(".wpbc_debug_'.$milliseconds.'").hide()}; </script>'; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
/* |
| 96 |
* Show Speed of the execution and number of queries. |
| 97 |
*/ |
| 98 |
if (!function_exists ('debuge_speed')) { |
| 99 |
function debuge_speed() { |
| 100 |
echo '<div style="font-size:18px;float:right;">' . get_num_queries(). '/' . timer_stop(0, 3) . 'qps</div>'; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Show error info |
| 106 |
*/ |
| 107 |
if (!function_exists ('debuge_error')) { |
| 108 |
function debuge_error( $msg , $file_name='', $line_num=''){ |
| 109 |
echo get_debuge_error( $msg , $file_name , $line_num ); |
| 110 |
} |
| 111 |
} |
| 112 |
if (!function_exists ('get_debuge_error')) { |
| 113 |
function get_debuge_error( $msg , $file_name='', $line_num=''){ |
| 114 |
|
| 115 |
return wpbc_get_debuge_error( $msg , $file_name, $line_num ); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
function wpbc_get_debuge_error( $msg , $file_name='', $line_num=''){ |
| 121 |
|
| 122 |
$ver_num = ( ! defined('WPDEV_BK_VERSION') ) ? '' : '|V:' . WPDEV_BK_VERSION ; |
| 123 |
|
| 124 |
$last_db_error = ''; |
| 125 |
global $EZSQL_ERROR; |
| 126 |
|
| 127 |
if ( |
| 128 |
( ! empty( $EZSQL_ERROR ) ) |
| 129 |
&& ( is_array( $EZSQL_ERROR ) ) |
| 130 |
&& ( isset( $EZSQL_ERROR[ ( count( $EZSQL_ERROR ) - 1 ) ] ) ) |
| 131 |
){ |
| 132 |
|
| 133 |
$last_db_error2 = $EZSQL_ERROR[ (count($EZSQL_ERROR)-1)]; |
| 134 |
|
| 135 |
if ( (isset($last_db_error2['query'])) && (isset($last_db_error2['error_str'])) ) { |
| 136 |
|
| 137 |
$str = str_replace( array( '"', "'" ), '', $last_db_error2['error_str'] ); |
| 138 |
$query = str_replace( array( '"', "'" ), '', $last_db_error2['query'] ); |
| 139 |
|
| 140 |
$str = htmlspecialchars( $str, ENT_QUOTES ); |
| 141 |
$query = htmlspecialchars( $query , ENT_QUOTES ); |
| 142 |
|
| 143 |
$last_db_error = $str ; |
| 144 |
$last_db_error .= '::<span style="color:#300;">'.$query.'</span>'; |
| 145 |
} |
| 146 |
} |
| 147 |
return $msg . '<br /><span style="font-size:11px;"> [' |
| 148 |
. 'F:' . str_replace( dirname( $file_name ) , '' , $file_name ) |
| 149 |
. '| L:' . $line_num |
| 150 |
. $ver_num |
| 151 |
. '| DB:' . $last_db_error |
| 152 |
. '] </span>' ; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
// Usage: if ( function_exists ('wpbc_check_post_key_max_number')) { wpbc_check_post_key_max_number(); } |
| 157 |
if ( ! function_exists ('wpbc_check_post_key_max_number')) { |
| 158 |
function wpbc_check_post_key_max_number() { |
| 159 |
|
| 160 |
/* |
| 161 |
$post_max_totalname_length = intval( ( ini_get( 'suhosin.post.max_totalname_length' ) ) ? ini_get( 'suhosin.post.max_totalname_length' ) : '9999999' ); |
| 162 |
$request_max_totalname_length = intval( ( ini_get( 'suhosin.request.max_totalname_length' ) ) ? ini_get( 'suhosin.request.max_totalname_length' ) : '9999999' ); |
| 163 |
$post_max_name_length = intval( ( ini_get( 'suhosin.post.max_name_length' ) ) ? ini_get( 'suhosin.post.max_name_length' ) : '9999999' ); |
| 164 |
$request_max_varname_length = intval( ( ini_get( 'suhosin.request.max_varname_length' ) ) ? ini_get( 'suhosin.request.max_varname_length' ) : '9999999' ); |
| 165 |
*/ |
| 166 |
$php_ini_vars = array( |
| 167 |
'suhosin.post.max_totalname_length' |
| 168 |
, 'suhosin.request.max_totalname_length' |
| 169 |
, 'suhosin.post.max_name_length' |
| 170 |
, 'suhosin.request.max_varname_length' |
| 171 |
); |
| 172 |
|
| 173 |
foreach ( $_POST as $key_name => $post_value ) { |
| 174 |
|
| 175 |
$key_length = strlen( $key_name ); |
| 176 |
|
| 177 |
foreach ( $php_ini_vars as $php_ini_var ) { |
| 178 |
|
| 179 |
$php_ini_var_length = intval( ( ini_get( $php_ini_var ) ) ? ini_get( $php_ini_var ) : '9999999' ); |
| 180 |
|
| 181 |
if ( $key_length > $php_ini_var_length ) { |
| 182 |
|
| 183 |
wpbc_show_message_in_settings( 'Your php.ini configuration limited to ' |
| 184 |
. '<strong> '. $php_ini_var . ' = ' . $php_ini_var_length . '</strong>.' |
| 185 |
. ' ' |
| 186 |
. 'Plugin require at least ' . ( intval( $key_length ) + 1 ). ', ' |
| 187 |
. 'for saving option: ' . '<strong>'. $key_name . '</strong>' |
| 188 |
, 'error' |
| 189 |
, __('Error' ,'booking') . '.' ); |
| 190 |
|
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
/** |
| 199 |
* Show System debug log for Beta features. |
| 200 |
* |
| 201 |
* @param mixed $show_debug_info |
| 202 |
* |
| 203 |
* Example of usage: |
| 204 |
* |
| 205 |
$is_show_debug_info = ( ( get_bk_option( 'booking_is_show_system_debug_log' ) == 'On' ) ? true : false ); |
| 206 |
if ( $is_show_debug_info ) |
| 207 |
add_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10, 1 ); |
| 208 |
... |
| 209 |
//- |
| 210 |
do_action( 'wpbc_show_debug', array( 'after import' , $ics_array) ); |
| 211 |
... |
| 212 |
if ( $is_show_debug_info ) |
| 213 |
remove_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10 ); |
| 214 |
*/ |
| 215 |
function wpbc_start_showing_debug( $show_debug_info ) { //FixIn: 7.2.1.15 |
| 216 |
|
| 217 |
// Make first item as header - bold |
| 218 |
if ( is_array( $show_debug_info ) ) |
| 219 |
$show_debug_info[0] = '<strong>' . $show_debug_info[0] . '</strong>'; |
| 220 |
|
| 221 |
// Get evrything in human redable view |
| 222 |
$show_debug_info = print_r ( $show_debug_info, true ); |
| 223 |
|
| 224 |
// Remove unnecesary new lines |
| 225 |
$show_debug_info = preg_replace( '/Array[\n\r\s]*\(/', 'array(', $show_debug_info ); |
| 226 |
$show_debug_info = preg_replace( '/\)\n/', ")", $show_debug_info ); |
| 227 |
|
| 228 |
// Show |
| 229 |
echo "<div><pre class='prettyprint linenums'>"; |
| 230 |
|
| 231 |
echo( $show_debug_info ); |
| 232 |
|
| 233 |
echo "</pre></div>"; |
| 234 |
|
| 235 |
echo '<hr/>'; |
| 236 |
|
| 237 |
// For system debug log in Ajax request show it |
| 238 |
?><script type="text/javascript"> jQuery( '.wpbc_system_info_log' ).show(); </script><?php |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
/** |
| 243 |
* Show Top Notice in Admin panel by writing in-line JS |
| 244 |
* |
| 245 |
* @param string $message |
| 246 |
* @param string $message_type - (default notice) notice | error | warning | info | success |
| 247 |
* @param int $seconds_to_show - (default 3000) - delay in microseconds |
| 248 |
* @param bool $is_append - (default true) - append notice instead of replacing |
| 249 |
*/ |
| 250 |
function wpbc_admin_show_top_notice( $message, $message_type = 'info', $seconds_to_show = 3000, $is_append = true ) { |
| 251 |
|
| 252 |
if ( ! is_admin() ) return; |
| 253 |
|
| 254 |
// Show Notice in Admin header |
| 255 |
?><script type="text/javascript"> |
| 256 |
wpbc_admin_show_message( '<?php echo html_entity_decode( esc_js( $message ), ENT_QUOTES ); ?>' |
| 257 |
, '<?php echo $message_type; ?>' |
| 258 |
, <?php echo intval( $seconds_to_show ); ?> |
| 259 |
, <?php echo ( $is_append ? 'true' : 'false' ); ?> |
| 260 |
); |
| 261 |
</script><?php |
| 262 |
} |
| 263 |
add_action( 'wpbc_admin_show_top_notice', 'wpbc_admin_show_top_notice', 10, 3 ); |
| 264 |
|