'wordpress', 'utm_medium' => $medium, ), untrailingslashit( VIGI_VIDEO_APP_URL ) . $path ); } /** * Messages after an action. */ private static function notices() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. $notice = isset( $_GET['vigi_notice'] ) ? sanitize_key( wp_unslash( $_GET['vigi_notice'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. $detail = isset( $_GET['vigi_detail'] ) ? sanitize_text_field( wp_unslash( $_GET['vigi_detail'] ) ) : ''; $messages = array( 'connected' => array( 'success', __( 'Connected to ViGi. Your videos are below.', 'videopronto' ) ), 'disconnected' => array( 'info', __( 'Disconnected. Videos already on your pages keep playing.', 'videopronto' ) ), 'cancelled' => array( 'warning', __( 'Connection cancelled.', 'videopronto' ) ), 'expired' => array( 'error', __( 'That connection link expired. Please click Connect again.', 'videopronto' ) ), 'failed' => array( 'error', __( "We couldn't finish connecting to ViGi. Please try again.", 'videopronto' ) ), 'placed' => array( 'success', __( 'Video added to the page.', 'videopronto' ) ), 'place_error' => array( 'error', $detail ), 'refreshed' => array( 'success', __( 'Videos refreshed from ViGi.', 'videopronto' ) ), ); $quick = Vigi_Video_Quick_Create::notice_message(); if ( $quick ) { printf( '

%2$s

', esc_attr( $quick[0] ), wp_kses( $quick[1], array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ) ) ) ); return; } if ( isset( $messages[ $notice ] ) && '' !== $messages[ $notice ][1] ) { printf( '

%2$s

', esc_attr( $messages[ $notice ][0] ), esc_html( $messages[ $notice ][1] ) ); } } /** * The screen. */ public static function render_page() { if ( ! current_user_can( 'edit_pages' ) ) { return; } echo '
'; echo '

' . esc_html__( 'VideoPronto', 'videopronto' ) . '

'; self::notices(); if ( ! Vigi_Video_Api::is_connected() ) { self::render_connect(); } else { self::render_connected(); } echo '
'; } /** * Not connected yet. */ private static function render_connect() { ?>

' . esc_html( ! empty( $account['email'] ) ? $account['email'] : __( 'your account', 'videopronto' ) ) . '' ); ?>

' . esc_html( $error->get_error_message() ) . '

'; if ( 'vigi_unauthorized' === $error->get_error_code() && current_user_can( 'manage_options' ) ) { self::render_connect(); } return; } Vigi_Video_Review::render(); self::render_essentials( $essentials, $pages ); self::render_quick_create( $videos ); self::render_other_videos( $videos, $essentials ); } /** * The 9 essentials. * * @param array $essentials Linked videos by key. * @param WP_Post[] $pages Pages. */ private static function render_essentials( $essentials, $pages ) { $defs = Vigi_Video_Essentials::all(); $done = 0; $placed = 0; foreach ( $defs as $key => $def ) { $video = isset( $essentials[ $key ]['video'] ) ? $essentials[ $key ]['video'] : null; if ( $video ) { ++$done; if ( Vigi_Video_Placement::placed_page( $key, $video['id'] ) ) { ++$placed; } } } ?>

$def ) { ++$n; $video = isset( $essentials[ $key ]['video'] ) ? $essentials[ $key ]['video'] : null; echo ''; echo ''; echo ''; echo ''; } ?>
#
' . (int) $n . '' . esc_html( $def['name'] ) . '
' . esc_html( $def['why'] ) . '
'; self::render_video_cell( $video ); echo ''; self::render_place_cell( $key, $def, $video, $pages ); echo '
' . esc_html__( 'Not made yet.', 'videopronto' ) . ' '; echo '' . esc_html__( 'Make it in ViGi', 'videopronto' ) . ''; return; } echo '
'; if ( $video['thumbnail_url'] ) { echo ''; } echo '' . esc_html( $video['title'] ); if ( ! $video['ready'] ) { echo '
' . esc_html__( 'Not published yet. Publish it in ViGi, then click Refresh.', 'videopronto' ) . ''; } echo '
'; } /** * Where it is, or a page picker + Add button. * * @param string $key Essential key. * @param array $def Definition. * @param array|null $video Video. * @param WP_Post[] $pages Pages. */ private static function render_place_cell( $key, $def, $video, $pages ) { if ( ! $video || ! $video['ready'] ) { echo '' . esc_html( $def['where'] ) . ''; return; } $placed = Vigi_Video_Placement::placed_page( $key, $video['id'] ); if ( $placed ) { printf( '✓ %1$s %3$s · %5$s', esc_html( get_the_title( $placed ) ), esc_url( get_permalink( $placed ) ), esc_html__( 'View', 'videopronto' ), esc_url( (string) get_edit_post_link( $placed ) ), esc_html__( 'Edit page', 'videopronto' ) ); if ( Vigi_Video_Placement::content_hidden_by_theme( $placed ) ) { echo '
' . esc_html__( "Your theme's homepage layout may not show page content. If the video doesn't appear, add the VideoPronto block in Appearance > Editor.", 'videopronto' ) . ''; } return; } if ( empty( $pages ) ) { echo '' . esc_html__( 'Create a page first, then come back.', 'videopronto' ) . ''; return; } $suggested = Vigi_Video_Essentials::suggest_page( $key, $pages ); ?>

' . esc_html__( 'Your other videos', 'videopronto' ) . ''; if ( empty( $others ) ) { echo '

' . esc_html__( 'None yet.', 'videopronto' ) . '

'; } else { echo '

' . esc_html__( 'Add any video to a post or page with the "VideoPronto" block, or paste its shortcode (works in page builders like Elementor and Divi too).', 'videopronto' ) . '

'; echo ''; foreach ( $others as $video ) { echo ''; } echo '
'; self::render_video_cell( $video ); echo ''; if ( $video['ready'] ) { echo ''; } echo '
'; } if ( $drafts > 0 ) { echo '

'; echo esc_html( sprintf( /* translators: %d: number of unfinished videos */ _n( '%d unfinished video is hidden here.', '%d unfinished videos are hidden here.', $drafts, 'videopronto' ), $drafts ) ); echo ' ' . esc_html__( 'Finish them in ViGi', 'videopronto' ) . '

'; } echo ''; } /** * Quick create: a video for any page or post, newest first. * * @param array $videos All of the account's videos. */ private static function render_quick_create( $videos ) { $by_id = array(); foreach ( $videos as $video ) { $by_id[ $video['id'] ] = $video; } $posts = get_posts( array( 'post_type' => Vigi_Video_Quick_Create::post_types(), 'post_status' => array( 'publish', 'draft', 'pending', 'future', 'private' ), 'posts_per_page' => 10, 'orderby' => 'modified', 'order' => 'DESC', ) ); $stages = array( 'making' => __( 'Being made in ViGi', 'videopronto' ), 'review' => __( 'Ready for your review', 'videopronto' ), 'publishing' => __( 'Publishing', 'videopronto' ), 'ready' => __( 'Live on the page', 'videopronto' ), 'error' => __( "Couldn't be made", 'videopronto' ), ); echo '

' . esc_html__( 'Quick create: a video for any page or post', 'videopronto' ) . '

'; echo '

' . esc_html__( 'Wrote a new blog post or service page? ViGi turns what the page says into a video and adds it to the top of the page. It goes live as soon as you review and publish it in ViGi. You can also click "Make a ViGi video" under any post in your Posts or Pages list, or use the VideoPronto block in the editor.', 'videopronto' ) . '

'; if ( empty( $posts ) ) { echo '

' . esc_html__( 'No pages or posts yet.', 'videopronto' ) . '

'; return; } echo ''; foreach ( $posts as $post ) { if ( ! current_user_can( 'edit_post', $post->ID ) ) { continue; } $type = get_post_type_object( $post->post_type ); $quick = Vigi_Video_Quick_Create::for_post( $post->ID ); echo ''; } echo '
' . esc_html( $post->post_title ? $post->post_title : __( '(no title)', 'videopronto' ) ) . '
'; echo esc_html( ( $type ? $type->labels->singular_name : $post->post_type ) . ' · ' . get_post_status_object( $post->post_status )->label ); echo '
'; if ( $quick && Vigi_Video_Placement::page_has_video( $post, $quick['video_id'] ) ) { $video = isset( $by_id[ $quick['video_id'] ] ) ? $by_id[ $quick['video_id'] ] : null; // The page may have seen it go live more recently than the list. $cached = Vigi_Video_Api::cached( $quick['video_id'] ); if ( $cached && ! empty( $cached['ready'] ) && ( ! $video || empty( $video['ready'] ) ) ) { $video = $cached; } $stage = $video ? Vigi_Video_Api::stage( $video ) : 'making'; echo '' . esc_html( $stages[ $stage ] ) . ' '; if ( 'ready' !== $stage ) { $link = $video && ! empty( $video['edit_url'] ) ? $video['edit_url'] : untrailingslashit( VIGI_VIDEO_APP_URL ) . '/videos/' . rawurlencode( $quick['video_id'] ); $label = 'review' === $stage ? __( 'Review & publish in ViGi', 'videopronto' ) : __( 'Open in ViGi', 'videopronto' ); echo '' . esc_html( $label ) . ''; } if ( 'error' === $stage ) { echo ' · ' . esc_html__( 'Try again', 'videopronto' ) . ''; } } elseif ( Vigi_Video_Placement::page_has_any_video( $post ) ) { echo '' . esc_html__( 'Has a ViGi video', 'videopronto' ) . ''; } elseif ( '' !== Vigi_Video_Placement::page_builder( $post ) ) { echo '' . esc_html__( 'Built with a page builder: add a video with the shortcode', 'videopronto' ) . ''; } else { echo '' . esc_html__( 'Make a video', 'videopronto' ) . ''; } echo '
'; } /** * Add to page. */ public static function handle_place() { if ( ! current_user_can( 'edit_pages' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'videopronto' ), 403 ); } // phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce checked right below, per essential. $key = isset( $_POST['essential'] ) ? sanitize_key( wp_unslash( $_POST['essential'] ) ) : ''; check_admin_referer( 'vigi_video_place_' . $key ); $video_id = isset( $_POST['video_id'] ) ? sanitize_text_field( wp_unslash( $_POST['video_id'] ) ) : ''; $page_id = isset( $_POST['page_id'] ) ? absint( $_POST['page_id'] ) : 0; // phpcs:enable $back = admin_url( 'admin.php?page=vigi-video' ); if ( ! Vigi_Video_Essentials::exists( $key ) ) { wp_safe_redirect( add_query_arg( 'vigi_notice', 'failed', $back ) ); exit; } $result = Vigi_Video_Placement::place( $key, $video_id, $page_id ); if ( is_wp_error( $result ) ) { wp_safe_redirect( add_query_arg( array( 'vigi_notice' => 'place_error', 'vigi_detail' => rawurlencode( $result->get_error_message() ), ), $back ) ); exit; } wp_safe_redirect( add_query_arg( 'vigi_notice', 'placed', $back ) ); exit; } /** * Refresh from ViGi. */ public static function handle_refresh() { if ( ! current_user_can( 'edit_pages' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'videopronto' ), 403 ); } check_admin_referer( 'vigi_video_refresh' ); Vigi_Video_Api::flush(); wp_safe_redirect( add_query_arg( 'vigi_notice', 'refreshed', admin_url( 'admin.php?page=vigi-video' ) ) ); exit; } }