| 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' ) ) { |
| 15 |
exit; // Exit if accessed directly . |
| 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() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 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> [" . esc_html( $ind ) . '] ' . esc_html( gettype( $item ) ) . "</strong>\n"; |
| 34 |
|
| 35 |
if ( 'string' === gettype( $item ) ) { |
| 36 |
echo( htmlentities( $item ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 37 |
} else { |
| 38 |
print_r( $item ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 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;">' . esc_html( get_num_queries() ) . '/' . esc_html( timer_stop( 0, 3 ) ) . 'qps</div>'; |
| 45 |
exit; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
/* |
| 52 |
* Show debug info for Visitors. This function used for showing debug info for visitors at the website. |
| 53 |
* 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. |
| 54 |
* Example: show_debug( 'clear', -3 ); - show 3 last DIV elements. |
| 55 |
*/ |
| 56 |
if ( ! function_exists( 'show_debug' ) ) { |
| 57 |
// FixIn: 8.8.3.18. |
| 58 |
function show_debug() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 59 |
//TODO: 2023-09-19 13:42 Need to remake it relative to new 'create_booking.php' functionality. We can not simply echo here !!!! |
| 60 |
if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) { |
| 61 |
} else { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
$var = func_get_args(); |
| 66 |
|
| 67 |
if ( 'clear' === $var[0] ) { |
| 68 |
echo '<script type="text/javascript"> |
| 69 |
jQuery(".ajax_respond_insert div").hide(); |
| 70 |
jQuery(".ajax_respond_insert div").slice( ' . esc_js( $var[1] ) . ' ).show(); |
| 71 |
</script>'; |
| 72 |
} |
| 73 |
|
| 74 |
$milliseconds = round( microtime( true ) * 1000 ); |
| 75 |
|
| 76 |
echo "<div class='wpbc_debug wpbc_debug_" . esc_attr( $milliseconds ) . "'><pre class='prettyprint linenums'>"; |
| 77 |
foreach ( $var as $ind => $item ) { |
| 78 |
echo "\n"; |
| 79 |
|
| 80 |
if ( 'string' === gettype( $item ) ) { |
| 81 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 82 |
echo( htmlentities( $item ) ); |
| 83 |
} else { |
| 84 |
print_r( $item ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 85 |
} |
| 86 |
} |
| 87 |
echo "</pre></div>"; |
| 88 |
echo '<script type="text/javascript"> jQuery(".ajax_respond_insert, .ajax_respond").show(); </script>'; |
| 89 |
echo '<script type="text/javascript"> if ( jQuery(".ajax_respond_insert").length == 0 ) {jQuery(".wpbc_debug_' . esc_js( $milliseconds ) . '").hide()}; </script>'; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/* |
| 95 |
* Show Speed of the execution and number of queries. |
| 96 |
*/ |
| 97 |
if ( ! function_exists( 'debuge_speed' ) ) { |
| 98 |
function debuge_speed() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 99 |
echo '<div style="font-size:18px;float:right;">' . esc_html( get_num_queries() ) . '/' . esc_html( timer_stop( 0, 3 ) ) . 'qps</div>'; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Show error info |
| 105 |
*/ |
| 106 |
if ( ! function_exists( 'debuge_error' ) ) { |
| 107 |
function debuge_error( $msg, $file_name = '', $line_num = '' ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 108 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 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 = '' ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 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 ) ) && ( is_array( $EZSQL_ERROR ) ) && ( isset( $EZSQL_ERROR[ ( count( $EZSQL_ERROR ) - 1 ) ] ) ) ) { |
| 129 |
|
| 130 |
$last_db_error2 = $EZSQL_ERROR[ ( count( $EZSQL_ERROR ) - 1 ) ]; |
| 131 |
|
| 132 |
if ( ( isset( $last_db_error2['query'] ) ) && ( isset( $last_db_error2['error_str'] ) ) ) { |
| 133 |
|
| 134 |
$str = str_replace( array( '"', "'" ), '', $last_db_error2['error_str'] ); |
| 135 |
$query = str_replace( array( '"', "'" ), '', $last_db_error2['query'] ); |
| 136 |
|
| 137 |
$str = htmlspecialchars( $str, ENT_QUOTES ); |
| 138 |
$query = htmlspecialchars( $query, ENT_QUOTES ); |
| 139 |
|
| 140 |
$last_db_error = $str; |
| 141 |
$last_db_error .= '::<span style="color:#300;">' . $query . '</span>'; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
return $msg . '<br /><span style="font-size:11px;"> [F:' . str_replace( dirname( $file_name ), '', $file_name ) . '| L:' . $line_num . $ver_num . '| DB:' . $last_db_error . '] </span>'; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
// Usage: if ( function_exists ('wpbc_check_post_key_max_number')) { wpbc_check_post_key_max_number(); } |
| 150 |
if ( ! function_exists( 'wpbc_check_post_key_max_number' ) ) { |
| 151 |
function wpbc_check_post_key_max_number() { |
| 152 |
|
| 153 |
/* |
| 154 |
$post_max_totalname_length = intval( ( ini_get( 'suhosin.post.max_totalname_length' ) ) ? ini_get( 'suhosin.post.max_totalname_length' ) : '9999999' ); |
| 155 |
$request_max_totalname_length = intval( ( ini_get( 'suhosin.request.max_totalname_length' ) ) ? ini_get( 'suhosin.request.max_totalname_length' ) : '9999999' ); |
| 156 |
$post_max_name_length = intval( ( ini_get( 'suhosin.post.max_name_length' ) ) ? ini_get( 'suhosin.post.max_name_length' ) : '9999999' ); |
| 157 |
$request_max_varname_length = intval( ( ini_get( 'suhosin.request.max_varname_length' ) ) ? ini_get( 'suhosin.request.max_varname_length' ) : '9999999' ); |
| 158 |
*/ |
| 159 |
$php_ini_vars = array( |
| 160 |
'suhosin.post.max_totalname_length', 'suhosin.request.max_totalname_length', 'suhosin.post.max_name_length', |
| 161 |
'suhosin.request.max_varname_length', |
| 162 |
); |
| 163 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 164 |
foreach ( $_POST as $key_name => $post_value ) { |
| 165 |
|
| 166 |
$key_length = strlen( $key_name ); |
| 167 |
|
| 168 |
foreach ( $php_ini_vars as $php_ini_var ) { |
| 169 |
|
| 170 |
$php_ini_var_length = intval( ( ini_get( $php_ini_var ) ) ? ini_get( $php_ini_var ) : '9999999' ); |
| 171 |
|
| 172 |
if ( $key_length > $php_ini_var_length ) { |
| 173 |
|
| 174 |
wpbc_show_message_in_settings( 'Your php.ini configuration limited to <strong> ' . $php_ini_var . ' = ' . $php_ini_var_length . '</strong>. ' . |
| 175 |
'Plugin require at least ' . ( intval( $key_length ) + 1 ) . ', ' . |
| 176 |
'for saving option: <strong>' . $key_name . '</strong>', |
| 177 |
'error', __( 'Error', 'booking' ) . '.' ); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
/** |
| 186 |
* Show System debug log for Beta features. |
| 187 |
* |
| 188 |
* @param mixed $show_debug_info |
| 189 |
* |
| 190 |
* Example of usage: |
| 191 |
* |
| 192 |
* $is_show_debug_info = ( ( get_bk_option( 'booking_is_show_system_debug_log' ) == 'On' ) ? true : false ); |
| 193 |
* if ( $is_show_debug_info ) |
| 194 |
* add_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10, 1 ); |
| 195 |
* ... |
| 196 |
* //- |
| 197 |
* do_action( 'wpbc_show_debug', array( 'after import' , $ics_array) ); |
| 198 |
* ... |
| 199 |
* if ( $is_show_debug_info ) |
| 200 |
* remove_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10 ); |
| 201 |
*/ |
| 202 |
function wpbc_start_showing_debug( $show_debug_info ) { |
| 203 |
|
| 204 |
// FixIn: 7.2.1.15. |
| 205 |
|
| 206 |
// Make first item as header - bold. |
| 207 |
if ( is_array( $show_debug_info ) ) { |
| 208 |
$show_debug_info[0] = '<strong>' . $show_debug_info[0] . '</strong>'; |
| 209 |
} |
| 210 |
|
| 211 |
// Get evrything in human redable view. |
| 212 |
$show_debug_info = print_r( $show_debug_info, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 213 |
|
| 214 |
// Remove unnecesary new lines. |
| 215 |
$show_debug_info = preg_replace( '/Array[\n\r\s]*\(/', 'array(', $show_debug_info ); |
| 216 |
$show_debug_info = preg_replace( '/\)\n/', ")", $show_debug_info ); |
| 217 |
|
| 218 |
// Show. |
| 219 |
echo "<div><pre class='prettyprint linenums'>"; |
| 220 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 221 |
echo( $show_debug_info ); |
| 222 |
|
| 223 |
echo '</pre></div>'; |
| 224 |
|
| 225 |
echo '<hr/>'; |
| 226 |
|
| 227 |
// For system debug log in Ajax request show it. |
| 228 |
?> |
| 229 |
<script type="text/javascript"> jQuery('.wpbc_system_info_log').show(); </script> |
| 230 |
<?php |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
/** |
| 235 |
* Show Top Notice in Admin panel by writing in-line JS |
| 236 |
* |
| 237 |
* @param string $message |
| 238 |
* @param string $message_type - (default notice) notice | error | warning | info | success |
| 239 |
* @param int $seconds_to_show - (default 3000) - delay in microseconds |
| 240 |
* @param bool $is_append - (default true) - append notice instead of replacing |
| 241 |
*/ |
| 242 |
function wpbc_admin_show_top_notice( $message, $message_type = 'info', $seconds_to_show = 3000, $is_append = true ) { |
| 243 |
|
| 244 |
if ( ! is_admin() ) { |
| 245 |
return; |
| 246 |
} |
| 247 |
|
| 248 |
// Show Notice in Admin header. |
| 249 |
?> |
| 250 |
<script type="text/javascript"> |
| 251 |
wpbc_admin_show_message('<?php |
| 252 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 253 |
echo html_entity_decode( esc_js( $message ), ENT_QUOTES ); ?>' |
| 254 |
, '<?php echo esc_attr( $message_type ); ?>' |
| 255 |
, <?php echo intval( $seconds_to_show ); ?> |
| 256 |
, <?php echo( $is_append ? 'true' : 'false' ); ?> |
| 257 |
); |
| 258 |
</script> |
| 259 |
<?php |
| 260 |
} |
| 261 |
add_action( 'wpbc_admin_show_top_notice', 'wpbc_admin_show_top_notice', 10, 3 ); |
| 262 |
|