Files
Hi-School-Slide-Manager/templates/page-slide-confirmation.php
T

124 lines
6.2 KiB
PHP

<?php
/**
* Template Name: Slide Live Confirmation
*
* Page for ITC team to confirm a slide is live
*
* @package Hi_School_Slide_Manager
* @since 1.0.0
*/
// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct access forbidden.' );
}
get_header();
$slide_id = isset( $_REQUEST['slide_id'] ) ? absint( $_REQUEST['slide_id'] ) : 0;
$token = isset( $_REQUEST['hssm_token'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['hssm_token'] ) ) : '';
$slide = $slide_id ? get_post( $slide_id ) : null;
$is_valid_slide = ( $slide && 'hssm_slide' === $slide->post_type );
$has_valid_token = $is_valid_slide && class_exists( 'HSSM_Notifications' ) && HSSM_Notifications::is_valid_confirm_token( $slide_id, $token );
$already_confirmed = $is_valid_slide && (bool) get_post_meta( $slide_id, '_hssm_live_confirmed', true );
$confirmed = $already_confirmed;
$error_message = '';
if ( $is_valid_slide && ! $has_valid_token ) {
$error_message = 'This confirmation link is invalid or expired.';
}
if ( $has_valid_token && ! $already_confirmed && isset( $_POST['confirm_live_action'] ) && 'confirm' === $_POST['confirm_live_action'] ) {
if ( isset( $_POST['hssm_live_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['hssm_live_nonce'] ) ), 'hssm_confirm_live_action' ) ) {
$notifications = new HSSM_Notifications();
$notifications->notify_all_confirmed_live( $slide_id );
$confirmed = (bool) get_post_meta( $slide_id, '_hssm_live_confirmed', true );
if ( ! $confirmed ) {
$error_message = 'Could not send the confirmation email. Please try again.';
}
} else {
$error_message = 'Security check failed. Please refresh and try again.';
}
}
$thumbnail = $is_valid_slide ? get_the_post_thumbnail_url( $slide_id, 'medium' ) : '';
?>
<div id="main-content">
<div class="container-fluid">
<div id="content-area" class="clearfix full-width">
<div class="hssm-confirmation-container" style="max-width: 600px; margin: 50px auto; padding: 30px; background: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); text-align: center;">
<?php if ( ! $is_valid_slide ) : ?>
<div class="hssm-error">
<h2>Invalid Slide</h2>
<p>The slide you are trying to confirm could not be found.</p>
<a href="<?php echo esc_url( home_url() ); ?>" class="button">Return Home</a>
</div>
<?php elseif ( ! $has_valid_token ) : ?>
<div class="hssm-error">
<h2>Invalid Confirmation Link</h2>
<p><?php echo esc_html( $error_message ); ?></p>
<a href="<?php echo esc_url( home_url() ); ?>" class="button">Return Home</a>
</div>
<?php elseif ( $confirmed ) : ?>
<div class="hssm-success">
<h2 style="color: #46b450;"><?php echo $already_confirmed && empty( $_POST['confirm_live_action'] ) ? 'Already Confirmed' : 'Confirmation Sent!'; ?></h2>
<p class="dashicons dashicons-yes-alt" style="font-size: 64px; width: 64px; height: 64px; color: #46b450;"></p>
<p><strong>Thank you!</strong></p>
<p>Notifications have been sent to the Editor and Creator confirming that "<?php echo esc_html( $slide->post_title ); ?>" is Live.</p>
<a href="<?php echo esc_url( home_url() ); ?>" class="button">Return Home</a>
</div>
<?php else : ?>
<div class="hssm-confirm-form">
<h2>Confirm Slide is Live</h2>
<?php if ( $error_message ) : ?>
<div style="background: #f8d7da; color: #721c24; padding: 10px; margin-bottom: 20px; border-radius: 4px;">
<?php echo esc_html( $error_message ); ?>
</div>
<?php endif; ?>
<div style="margin: 30px 0; padding: 20px; background: #f9f9f9; border: 1px solid #eee; border-radius: 4px;">
<h3 style="margin-top: 0;"><?php echo esc_html( $slide->post_title ); ?></h3>
<?php
$target_sites = wp_get_post_terms( $slide_id, 'hssm_site', array( 'fields' => 'names' ) );
if ( ! empty( $target_sites ) && ! is_wp_error( $target_sites ) ) {
echo '<p><strong>Target Sites:</strong> ' . esc_html( implode( ', ', $target_sites ) ) . '</p>';
}
if ( $thumbnail ) :
?>
<div style="margin-top: 15px;">
<img src="<?php echo esc_url( $thumbnail ); ?>" alt="" style="max-width: 100%; height: auto; border-radius: 4px;">
</div>
<?php endif; ?>
</div>
<p>I confirm that the slide <strong>"<?php echo esc_html( $slide->post_title ); ?>"</strong> is Live and displaying correctly on the target sites.</p>
<form method="post">
<input type="hidden" name="confirm_live_action" value="confirm">
<input type="hidden" name="slide_id" value="<?php echo esc_attr( $slide_id ); ?>">
<input type="hidden" name="hssm_token" value="<?php echo esc_attr( $token ); ?>">
<?php wp_nonce_field( 'hssm_confirm_live_action', 'hssm_live_nonce' ); ?>
<button type="submit" class="button" style="background-color: #46b450; color: #fff; border: none; padding: 15px 30px; font-size: 18px; cursor: pointer; border-radius: 4px;">
<span class="dashicons dashicons-yes"></span> Confirm Slide is Live
</button>
</form>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>