1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333:
<?php
defined( 'ABSPATH' ) || exit;
use VSP\Modules\Logger;
use VSP\Modules\Logger\File_Handler;
if ( ! function_exists( 'vsp_current_screen' ) ) {
function vsp_current_screen( $only_id = true ) {
$screen = get_current_screen();
if ( false === $only_id ) {
return $screen;
}
return isset( $screen->id ) ? $screen->id : false;
}
}
if ( ! function_exists( 'vsp_is_screen' ) ) {
function vsp_is_screen( $check_screen = '', $current_screen = '' ) {
if ( ! empty( $check_screen ) ) {
$current_screen = ( empty( $current_screen ) ) ? vsp_current_screen( true ) : $current_screen;
if ( is_array( $check_screen ) ) {
return in_array( $current_screen, $check_screen, true );
}
return ( $check_screen === $current_screen );
}
return false;
}
}
if ( ! function_exists( 'vsp_get_time_in_seconds' ) ) {
function vsp_get_time_in_seconds( $time ) {
$times = explode( '_', $time );
if ( ! is_array( $times ) ) {
return $time;
}
$time_limit = $times[0];
$type = $times[1];
$time_limit = intval( $time_limit );
switch ( $type ) {
case 'seconds':
case 'second':
case 'sec':
$time = $time_limit;
break;
case 'minute':
case 'minutes':
case 'min':
$time = $time_limit * MINUTE_IN_SECONDS;
break;
case 'hour':
case 'hours':
case 'hrs':
$time = $time_limit * HOUR_IN_SECONDS;
break;
case 'days':
case 'day':
$time = $time_limit * DAY_IN_SECONDS;
break;
case 'weeks':
case 'week':
$time = $time_limit * WEEK_IN_SECONDS;
break;
case 'month':
case 'months':
$time = $time_limit * MONTH_IN_SECONDS;
break;
case 'year':
case 'years':
$time = $time_limit * YEAR_IN_SECONDS;
break;
}
return intval( $time );
}
}
if ( ! function_exists( 'vsp_placeholder_img' ) ) {
function vsp_placeholder_img() {
return apply_filters( 'vsp/placeholder_img', vsp_url( 'assets/img/noimage.png' ) );
}
}
if ( ! function_exists( 'vsp_set_time_limit' ) ) {
function vsp_set_time_limit( $limit = 0 ) {
if ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
@set_time_limit( $limit );
}
}
}
if ( ! function_exists( 'vsp_doing_it_wrong' ) ) {
function vsp_doing_it_wrong( $function, $message, $version ) {
$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
if ( is_ajax() ) {
do_action( 'doing_it_wrong_run', $function, $message, $version );
vsp_log_msg( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
} else {
_doing_it_wrong( $function, $message, $version );
}
}
}
if ( ! function_exists( 'vsp_get_logger' ) ) {
function vsp_get_logger( $subpath = false, $file_name = null, $filesize = false ) {
$class = apply_filters( 'vsp/log/class', '\VSP\Modules\Logger' );
$implements = class_implements( $class );
if ( is_array( $implements ) && in_array( 'VSP\Core\Interfaces\Logger', $implements, true ) ) {
$logger = ( is_object( $class ) ) ? $class : new $class( array( new File_Handler( $subpath, $file_name, $filesize ) ) );
} else {
$smgs = sprintf( esc_html__( 'The class %1$s provided by %2$s filter must implement %3$s.', 'vsp-framework' ), '<code>' . esc_html( is_object( $class ) ? get_class( $class ) : $class ) . '</code>', '<code>vsp_logging_class</code>', '<code>\VSP\Core\Interfaces\Logger</code>' );
vsp_doing_it_wrong( __FUNCTION__, $smgs, '3.0' );
$logger = new Logger( array( new File_Handler( $subpath, $file_name, $filesize ) ) );
}
return $logger;
}
}
if ( ! function_exists( 'vsp_logger' ) ) {
function vsp_logger() {
static $logger = null;
if ( null === $logger ) {
$logger = vsp_get_logger( false, null, false );
}
return $logger;
}
}
if ( ! function_exists( 'vsp_log_msg' ) ) {
function vsp_log_msg( $messages = '', $type = 'critical', $handler = false, $context = array() ) {
$types = array( 'critical', 'emergency', 'alert', 'error', 'warning', 'notice', 'info', 'debug' );
if ( ! in_array( $type, $types, true ) ) {
return false;
}
if ( is_array( $messages ) ) {
$messages = implode( PHP_EOL, $messages );
}
$messages .= PHP_EOL;
if ( false === $handler ) {
$handler = vsp_logger();
}
if ( $handler instanceof Logger && method_exists( $handler, $type ) ) {
$handler->$type( $messages, $context );
return true;
} elseif ( vsp_logger() instanceof Logger && method_exists( vsp_logger(), $type ) ) {
$msg = array_merge( array( esc_html__( 'Tried To Log A Message But Failed Got unknown Handler', 'vsp-framework' ) ), wp_debug_backtrace_summary( null, 0, false ) );
$content = <<<TEXT
//////////////////////// = VSP Critical = /////////////////////////////////
${msg}
${messages}
/////////////////////////////////////////////////////////////////
TEXT;
vsp_log_msg( $content, 'notice', vsp_logger() );
}
return false;
}
}
if ( ! function_exists( 'vsp_date_format' ) ) {
function vsp_date_format() {
return apply_filters( 'vsp/date/format', get_option( 'date_format' ) );
}
}
if ( ! function_exists( 'vsp_time_format' ) ) {
function vsp_time_format() {
return apply_filters( 'vsp/time/format', get_option( 'time_format' ) );
}
}
if ( ! function_exists( 'vsp_json_last_error' ) ) {
function vsp_json_last_error() {
switch ( function_exists( 'json_last_error' ) ? json_last_error() : -1 ) {
case JSON_ERROR_NONE:
return null;
break;
case JSON_ERROR_DEPTH:
return esc_html__( 'Maximum stack depth exceeded', 'vsp-framework' );
break;
case JSON_ERROR_STATE_MISMATCH:
return esc_html__( 'Underflow or the modes mismatch', 'vsp-framework' );
break;
case JSON_ERROR_CTRL_CHAR:
return esc_html__( 'Unexpected control character found', 'vsp-framework' );
break;
case JSON_ERROR_SYNTAX:
return esc_html__( 'Syntax error, malformed JSON', 'vsp-framework' );
break;
case JSON_ERROR_UTF8:
return esc_html__( 'Malformed UTF-8 characters, possibly incorrectly encoded', 'vsp-framework' );
break;
default:
return esc_html__( 'Unknown error', 'vsp-framework' );
break;
}
}
}
if ( ! function_exists( 'vsp_is_json' ) ) {
function vsp_is_json( $string = '' ) {
if ( is_string( $string ) ) {
json_decode( $string );
return ( json_last_error() === JSON_ERROR_NONE );
}
return false;
}
}
if ( ! function_exists( 'vsp_is_error' ) ) {
function vsp_is_error( $thing ) {
return ( $thing instanceof \VSP\Error );
}
}