'' ), $atts, 'vigi_video' ); wp_enqueue_style( 'vigi-video-video-style' ); return self::render( $atts['id'], array( 'class' => 'videopronto' ) ); } /** * HTML for one video. * * @param string $video_id ViGi video id. * @param array $args class: wrapper classes; wrapper_attributes: pre-escaped attributes from the block. * @return string */ public static function render( $video_id, $args = array() ) { $video = Vigi_Video_Api::get_video( $video_id ); if ( ! $video || empty( $video['video_url'] ) || empty( $video['ready'] ) ) { // Only editors see why nothing shows; visitors see nothing at all. if ( current_user_can( 'edit_posts' ) ) { return self::editor_notice( $video, $video_id ); } return ''; } $wrapper = ! empty( $args['wrapper_attributes'] ) ? $args['wrapper_attributes'] : 'class="' . esc_attr( isset( $args['class'] ) ? $args['class'] : 'videopronto' ) . '"'; $width = $video['width'] > 0 ? $video['width'] : 1920; $height = $video['height'] > 0 ? $video['height'] : 1080; $html = '
'; $html .= sprintf( ''; $html .= self::structured_data( $video ); $html .= '
'; return $html; } /** * What editors see in place of a video that isn't live yet. * * @param array|null $video Normalised video, if ViGi knows it. * @param string $video_id Video id. * @return string */ private static function editor_notice( $video, $video_id ) { $stage = $video ? Vigi_Video_Api::stage( $video ) : 'unknown'; $texts = array( 'making' => __( 'ViGi video: ViGi is making this video. It shows here once you review and publish it in ViGi.', 'videopronto' ), 'review' => __( 'ViGi video: ready for your review. Publish it in ViGi and it appears here automatically.', 'videopronto' ), 'publishing' => __( 'ViGi video: publishing now. It appears here in a few minutes.', 'videopronto' ), 'error' => $video && ! empty( $video['error_message'] ) ? __( 'ViGi video: this video could not be made.', 'videopronto' ) . ' ' . $video['error_message'] : __( 'ViGi video: this video could not be made.', 'videopronto' ), 'unknown' => __( 'ViGi video: this video is not ready yet. Publish it in ViGi, then refresh this page.', 'videopronto' ), ); $text = isset( $texts[ $stage ] ) ? $texts[ $stage ] : $texts['unknown']; $link = $video && ! empty( $video['edit_url'] ) ? $video['edit_url'] : untrailingslashit( VIGI_VIDEO_APP_URL ) . '/videos/' . rawurlencode( Vigi_Video_Api::clean_id( $video_id ) ); $html = '

' . esc_html( $text ); $html .= ' ' . esc_html__( 'Open in ViGi', 'videopronto' ) . ''; $html .= ' ' . esc_html__( '(Only you see this note; visitors see nothing until the video is live.)', 'videopronto' ) . '

'; return $html; } /** * schema.org VideoObject, so Google can show the video in search. * * @param array $video Normalised video. * @return string */ public static function structured_data( $video ) { if ( ! apply_filters( 'vigi_video_structured_data', true, $video ) ) { return ''; } $data = array( '@context' => 'https://schema.org', '@type' => 'VideoObject', 'name' => $video['title'], 'description' => $video['description'] ? $video['description'] : sprintf( /* translators: 1: video title, 2: site name */ __( '%1$s from %2$s', 'videopronto' ), $video['title'], get_bloginfo( 'name' ) ), 'contentUrl' => $video['video_url'], ); if ( $video['thumbnail_url'] ) { $data['thumbnailUrl'] = $video['thumbnail_url']; } if ( $video['created'] ) { $data['uploadDate'] = $video['created']; } if ( $video['duration'] > 0 ) { $seconds = (int) round( $video['duration'] ); $data['duration'] = sprintf( 'PT%dM%dS', floor( $seconds / 60 ), $seconds % 60 ); } return ''; } }