__( '1 min', AINSYS_CONNECTOR_TEXTDOMAIN ), '900' => __( '15 min', AINSYS_CONNECTOR_TEXTDOMAIN ), '1800' => __( '30 min', AINSYS_CONNECTOR_TEXTDOMAIN ), '3600' => __( '1 hour', AINSYS_CONNECTOR_TEXTDOMAIN ), '10800' => __( '3 hours', AINSYS_CONNECTOR_TEXTDOMAIN ), '21600' => __( '6 hours', AINSYS_CONNECTOR_TEXTDOMAIN ), '43200' => __( '12 hours', AINSYS_CONNECTOR_TEXTDOMAIN ), '86400' => __( '24 hours', AINSYS_CONNECTOR_TEXTDOMAIN ), '-1' => __( 'Unlimited', AINSYS_CONNECTOR_TEXTDOMAIN ), ] ); } /** * Regenerates log HTML (for ajax). * */ public function reload_log_html(): void { if ( ! isset( $_POST['action'] ) ) { wp_die( __( 'Action is missing', AINSYS_CONNECTOR_TEXTDOMAIN ) ); } echo self::generate_log_html(); wp_die(); } /** * Clears log DB table (for ajax). * */ public function clear_log(): void { if ( ! isset( $_POST['action'] ) ) { wp_die( __( 'Action is missing', AINSYS_CONNECTOR_TEXTDOMAIN ) ); } Settings::truncate_tables( 'ainsys_log' ); echo self::generate_log_html(); wp_die(); } /** * Toggles logging on/off. Set up time till log is saved (for ajax). * */ public function toggle_logging(): void { if ( ! isset( $_POST['command'] ) ) { wp_die( __( 'Command is missing', AINSYS_CONNECTOR_TEXTDOMAIN ) ); } $command = sanitize_text_field( $_POST['command'] ); $time = sanitize_text_field( $_POST['time'] ); $start_at = sanitize_text_field( $_POST['startat'] ); $logging_time = 0; if ( isset( $time ) ) { $current_time = time(); $time = (float) ( $time ?? 0 ); $end_time = $time; if ( $time > 0 ) { $end_time = $current_time + $time; } Settings::set_option( 'log_until_certain_time', $end_time ); Settings::set_option( 'log_select_value', $time ); $logging_time = $end_time; } $logging_since = ''; if ( 'start_loging' === $command ) { Settings::set_option( 'do_log_transactions', 1 ); Settings::set_option( 'log_transactions_since', $start_at ); $logging_since = Settings::get_option( 'log_transactions_since' ); } else { Settings::set_option( 'do_log_transactions', 0 ); Settings::set_option( 'log_transactions_since', '' ); Settings::set_option( 'log_select_value', $time ); } wp_send_json( [ 'logging_time' => $logging_time, 'logging_since' => $logging_since, ] ); } /** * Generate server data transactions HTML. * * @param string $where * * @return string */ public static function generate_log_html( string $where = '' ): string { $log_html = '
| %s | ', $name, strtoupper( str_replace( '_', ' ', $name ) ) ) : ''; $log_html_body .= sprintf( '', $name );
if ( $name === 'request_data' || $name === 'server_response' ) {
$value = maybe_unserialize( $value );
if ( empty( $value ) ) {
$log_html_body .= __( 'EMPTY', AINSYS_CONNECTOR_TEXTDOMAIN );
} else {
$log_html_body .= sprintf( ' %s... ', mb_substr( Logger::convert_response( $value ), 0, 40 ) );
$log_html_body .= sprintf( '%s | ';
}
$log_html_body .= '
|---|---|