" http-equiv=refresh> endet nicht beim ersten ">".
$html = (string) preg_replace( '/<(?:meta|base|link|script|iframe|frame|object|embed)\b(?:"[^"]*"|\'[^\']*\'|[^>"\'])*>?/i', '', $html );
return '
'
. ''
. ''
. ''
. '' . $html . '';
}
/** Adresse des Reiters (ab T11 mit dem Reiter-Parameter). */
public static function tab_url( array $args = array() ) {
return add_query_arg( array_merge( array( 'tab' => 'mails' ), $args ), Wp360_Staging_Guard_Admin_Page::page_url() );
}
/** Inhalt des Reiters. */
public static function render() {
if ( ! self::can_view() ) {
if ( current_user_can( self::CAPABILITY ) ) {
echo '' . esc_html__( 'On a multisite network only super admins can see caught emails.', '360-orbit-staging-guard' ) . '
';
}
return;
}
// Alter und Anzahl werden hier ebenfalls durchgesetzt, nicht nur beim Speichern.
Wp360_Staging_Guard_Mail_Store::prune();
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nur lesende Auswahl einer Mail.
$id = isset( $_GET['mail'] ) ? absint( wp_unslash( $_GET['mail'] ) ) : 0;
if ( $id > 0 ) {
self::render_detail( $id );
return;
}
self::render_list();
}
private static function render_list() {
$limit = Wp360_Staging_Guard_Mail_Store::limit();
$days = (int) Wp360_Staging_Guard_Settings::get()['mail_keep_days'];
$search = '';
$rows = Wp360_Staging_Guard_Mail_Store::recent( $limit, $search );
echo '';
echo '
' . esc_html(
sprintf(
/* translators: 1: maximum number of mails, 2: number of days */
__( 'Emails that were caught instead of sent. The latest %1$d are kept, for at most %2$d days. They may contain real customer data: delete them when you no longer need them.', '360-orbit-staging-guard' ),
$limit,
$days
)
) . '
';
if ( ! $rows ) {
echo '
' . esc_html__( 'No emails caught yet.', '360-orbit-staging-guard' ) . '
';
return;
}
echo '';
echo '| ' . esc_html__( 'Time', '360-orbit-staging-guard' ) . ' | ';
echo '' . esc_html__( 'Subject', '360-orbit-staging-guard' ) . ' | ';
echo '' . esc_html__( 'To', '360-orbit-staging-guard' ) . ' | ';
echo '' . esc_html__( 'From', '360-orbit-staging-guard' ) . ' | ';
echo ' |
';
foreach ( $rows as $row ) {
$to = array();
foreach ( $row['recipients'] as $recipient ) {
if ( is_array( $recipient ) && 'to' === ( $recipient['type'] ?? '' ) ) {
$to[] = (string) ( $recipient['email'] ?? '' );
}
}
echo '';
echo '| ' . esc_html( self::format_time( (string) $row['created_at'] ) ) . ' | ';
echo '' . esc_html( '' !== $row['subject'] ? $row['subject'] : __( '(no subject)', '360-orbit-staging-guard' ) ) . ' | ';
echo '' . esc_html( implode( ', ', $to ) ) . ' | ';
echo '' . esc_html( (string) $row['sender'] ) . ' | ';
echo '';
self::delete_form( 'wp360_sg_mail_delete', __( 'Delete', '360-orbit-staging-guard' ), array( 'mail' => $row['id'] ), 'link-delete' );
echo ' |
';
}
echo '
';
echo '';
self::delete_form( 'wp360_sg_mail_delete_all', __( 'Delete all', '360-orbit-staging-guard' ), array(), 'secondary' );
echo '
';
}
/**
* @param int $id Mail-ID.
*/
private static function render_detail( $id ) {
$mail = Wp360_Staging_Guard_Mail_Store::get( $id );
echo '';
return;
}
echo '' . esc_html( '' !== $mail['subject'] ? $mail['subject'] : __( '(no subject)', '360-orbit-staging-guard' ) ) . '
';
echo '';
echo '| ' . esc_html__( 'Time', '360-orbit-staging-guard' ) . ' | ' . esc_html( self::format_time( (string) $mail['created_at'] ) ) . ' |
';
echo '| ' . esc_html__( 'From', '360-orbit-staging-guard' ) . ' | ' . esc_html( (string) $mail['sender'] ) . ' |
';
$labels = array(
'to' => __( 'To', '360-orbit-staging-guard' ),
'cc' => __( 'Cc', '360-orbit-staging-guard' ),
'bcc' => __( 'Bcc', '360-orbit-staging-guard' ),
);
foreach ( $labels as $type => $label ) {
$list = array();
foreach ( $mail['recipients'] as $recipient ) {
if ( is_array( $recipient ) && ( $recipient['type'] ?? '' ) === $type ) {
$name = (string) ( $recipient['name'] ?? '' );
$email = (string) ( $recipient['email'] ?? '' );
$list[] = '' !== $name ? $name . ' <' . $email . '>' : $email;
}
}
if ( $list ) {
echo '| ' . esc_html( $label ) . ' | ' . esc_html( implode( ', ', $list ) ) . ' |
';
}
}
if ( $mail['attachments'] ) {
echo '| ' . esc_html__( 'Attachments', '360-orbit-staging-guard' ) . ' | ' . esc_html( implode( ', ', array_map( 'strval', $mail['attachments'] ) ) ) . ' (' . esc_html__( 'names only, files are never stored', '360-orbit-staging-guard' ) . ') |
';
}
echo '
';
echo '' . esc_html__( 'Message', '360-orbit-staging-guard' ) . '
';
if ( $mail['is_html'] ) {
echo '';
echo '' . esc_html__( 'Source', '360-orbit-staging-guard' ) . '
';
}
echo '' . esc_html( (string) $mail['body'] ) . '
';
if ( '' !== (string) $mail['headers'] ) {
echo '' . esc_html__( 'Headers', '360-orbit-staging-guard' ) . '
';
echo '' . esc_html( (string) $mail['headers'] ) . '
';
}
echo '';
self::delete_form( 'wp360_sg_mail_delete', __( 'Delete this email', '360-orbit-staging-guard' ), array( 'mail' => $mail['id'] ), 'secondary' );
echo '
';
echo '';
}
/**
* @param string $action Aktion (admin-post).
* @param string $label Beschriftung.
* @param array $fields Zusaetzliche versteckte Felder.
* @param string $style secondary oder link-delete.
*/
private static function delete_form( $action, $label, array $fields, $style ) {
echo '';
}
/**
* Wer aufgefangene Mails sehen darf: Administratoren, auf einem Netzwerk
* nur Super-Admins. Die Mails enthalten Passwort-Links und Codes; ein
* Site-Administrator koennte sonst das Konto eines Super-Admins uebernehmen.
*
* @return bool
*/
public static function can_view() {
if ( is_multisite() ) {
return is_super_admin();
}
return current_user_can( self::CAPABILITY );
}
private static function authorize() {
if ( ! self::can_view() ) {
wp_die( esc_html__( 'You do not have permission to do this.', '360-orbit-staging-guard' ), '', array( 'response' => 403 ) );
}
check_admin_referer( self::NONCE_ACTION );
}
private static function back() {
wp_safe_redirect( self::tab_url() );
exit;
}
public static function handle_delete() {
self::authorize();
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce in authorize() geprueft.
$id = isset( $_POST['mail'] ) ? absint( wp_unslash( $_POST['mail'] ) ) : 0;
if ( $id > 0 ) {
Wp360_Staging_Guard_Mail_Store::delete( $id );
}
self::back();
}
public static function handle_delete_all() {
self::authorize();
Wp360_Staging_Guard_Mail_Store::delete_all();
self::back();
}
/**
* @param string $gmt Zeitpunkt in GMT (MySQL-Format).
* @return string In der Zeitzone der Website.
*/
private static function format_time( $gmt ) {
$timestamp = strtotime( $gmt . ' UTC' );
return $timestamp ? wp_date( 'd.m.Y H:i:s', $timestamp ) : $gmt;
}
}