| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\SEO\render\Thing\CreativeWork\MediaObject\VideoObject; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | |
| | | // Build video tag |
| | | $classes = trim("video-cover {$fade_class} {$css_class}"); |
| | | |
| | | $html = '<section class="'.esc_attr($classes).'"> |
| | | <script type="application/ld+json"> |
| | | { |
| | | "@context": "https://schema.org/", |
| | | "@type": "VideoObject", |
| | | "name": "'.$title.'", |
| | | "thumbnailUrl": "'.$poster_url.'", |
| | | "contentUrl": "'.$video_sources[0]['url'].'", |
| | | "description": "'.$description.'", |
| | | "uploadDate": "'.$date.'" |
| | | } |
| | | </script> |
| | | <div class="wrap abs edges"> |
| | | <div class="video-container">'; |
| | | $html .= '<video'; |
| | | $html .= ' muted loop playsinline autoplay'; |
| | | $video = new VideoObject(); |
| | | $video->setName($title); |
| | | $video->setThumbnailUrl($poster_url); |
| | | $video->setContentUrl($video_sources[0]['url']); |
| | | $video->setDescription($description); |
| | | $video->setUploadDate($date); |
| | | |
| | | if ($poster_url) { |
| | | $html .= ' poster="' . esc_url($poster_url) . '"'; |
| | | } |
| | | $html = sprintf( |
| | | '<section class="%s"> |
| | | <script type="application/ld+json">%s</script> |
| | | <div class="wrap abs edges"> |
| | | <div class="video-container">', |
| | | esc_attr($classes), |
| | | json_encode($video->outputSchema()) |
| | | ); |
| | | |
| | | $poster = $poster_url ? sprintf( |
| | | ' poster="%s"', |
| | | esc_url($poster_url) |
| | | ) : ''; |
| | | |
| | | $html .= sprintf( |
| | | '<video muted loop playsinline autoplay%s fetch-priority="high">', |
| | | $poster |
| | | ); |
| | | |
| | | |
| | | $html .= ' fetch-priority="high">'; |
| | | |
| | | foreach ($video_sources as $source) { |
| | | if (!empty($source['url']) && !empty($source['mime'])) { |
| | | $html .= '<source'; |
| | | $html .= ' data-src="' . esc_url($source['url']) . '"'; |
| | | $html .= ' type="' . esc_attr($source['mime']) . '"'; |
| | | $html .= '>'; |
| | | $html .= sprintf( |
| | | '<source data-src="%s" type="%s">', |
| | | esc_url($source['url']), |
| | | esc_attr($source['mime']) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | $html .= '</video>'; |
| | | |
| | | $inner_content = $this->extractInnerContent($content); |
| | | $html .= '</div></div><div class="inner-wrap">'.$inner_content.'</div></section>'; |
| | | $html .= sprintf( |
| | | '</div></div><div class="inner-wrap">%s</div></section>', |
| | | $inner_content |
| | | ); |
| | | |
| | | return $html; |
| | | } |