__( 'Queued', '85pl-android-sms-api' ), 'sending' => __( 'Sending', '85pl-android-sms-api' ), 'waiting_phone' => __( 'Waiting for the phone', '85pl-android-sms-api' ), 'sent' => __( 'Sent, waiting for the report', '85pl-android-sms-api' ), 'delivered' => __( 'Delivered', '85pl-android-sms-api' ), 'failed' => __( 'Failed', '85pl-android-sms-api' ), 'expired' => __( 'Expired', '85pl-android-sms-api' ), 'blocked_stop' => __( 'Blocked (STOP)', '85pl-android-sms-api' ), 'limit' => __( 'Plan limit', '85pl-android-sms-api' ), 'rate_limited' => __( 'Stopped by the safety limit', '85pl-android-sms-api' ), ); return $labels[ $status ] ?? $status; } /** * Readable label of a connection log type. * * @param string $type Type from ConnectionLog::TYPES. * @return string */ public static function log_type_label( string $type ): string { $labels = array( 'connected' => __( 'Connected', '85pl-android-sms-api' ), 'disconnected' => __( 'Disconnected', '85pl-android-sms-api' ), 'auth_error' => __( 'Authorization error', '85pl-android-sms-api' ), 'webhook_rejected' => __( 'Notification rejected', '85pl-android-sms-api' ), 'send_error' => __( 'Sending error', '85pl-android-sms-api' ), 'rate_limited' => __( 'Safety limit', '85pl-android-sms-api' ), ); return $labels[ $type ] ?? $type; } /** * Event of a message, with the order or booking number when there is one. * * @param array $row Messages row. * @return string */ public static function event_text( array $row ): string { $label = '' !== (string) $row['event_label'] ? (string) $row['event_label'] : __( 'SMS from code', '85pl-android-sms-api' ); if ( in_array( (string) $row['object_type'], self::NUMBERED_OBJECTS, true ) && '' !== (string) $row['object_id'] ) { $label .= ' #' . $row['object_id']; } return $label; } /** * Local date and time of a UTC MySQL datetime. * * @param string|null $utc "Y-m-d H:i:s" in UTC. * @return string */ public static function local_time( ?string $utc ): string { $time = strtotime( (string) $utc . ' UTC' ); if ( false === $time ) { return ''; } return (string) wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time ); } /** * Page links under a list. * * @param int $current Current page. * @param int $total Number of pages. * @return void */ public static function pagination( int $current, int $total ): void { if ( $total < 2 ) { return; } $links = paginate_links( array( 'base' => add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => $current, 'total' => $total, ) ); if ( is_string( $links ) ) { echo '
' . wp_kses_post( $links ) . '
'; } } /** * Block form handler (admin-post). * * @return void */ public static function handle_block(): void { if ( ! current_user_can( Menu::CAPABILITY ) ) { Guard::deny(); } check_admin_referer( self::BLOCK_ACTION ); self::process_block( wp_unslash( $_POST ) ); Guard::redirect( Menu::tab_url( 'blocked' ) ); } /** * Unblock form handler (admin-post). * * @return void */ public static function handle_unblock(): void { if ( ! current_user_can( Menu::CAPABILITY ) ) { Guard::deny(); } check_admin_referer( self::UNBLOCK_ACTION ); self::process_unblock( wp_unslash( $_POST ) ); Guard::redirect( Menu::tab_url( 'blocked' ) ); } /** * Block the posted number. * * @param array $post Unslashed form fields. * @return void */ public static function process_block( array $post ): void { $phone = isset( $post['phone'] ) && is_string( $post['phone'] ) ? sanitize_text_field( $post['phone'] ) : ''; if ( Blocklist::add( $phone, 'manual' ) ) { Notice::add( 'success', __( 'The number is blocked: this site will not send it SMS.', '85pl-android-sms-api' ) ); return; } Notice::add( 'error', __( 'This is not a valid phone number.', '85pl-android-sms-api' ) ); } /** * Unblock the number behind the posted token. * * @param array $post Unslashed form fields. * @return void */ public static function process_unblock( array $post ): void { $token = isset( $post['token'] ) && is_string( $post['token'] ) ? sanitize_text_field( $post['token'] ) : ''; if ( '' !== $token && Blocklist::remove_by_token( $token ) ) { Notice::add( 'success', __( 'The number is unblocked.', '85pl-android-sms-api' ) ); return; } Notice::add( 'error', __( 'This number is not on the list any more.', '85pl-android-sms-api' ) ); } /** * Requested list page (1-based). * * @return int */ private static function current_page(): int { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only paging. $page = isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : 1; return max( 1, $page ); } }