/** * Returns the featured video html, ready to echo. * * @since 1.0.0 * * @param int $post_id * @param string|array $size */ public function get_the_post_video($post_id = null, $size = null) { $post_id = null === $post_id ? get_the_ID() : $post_id; if (!has_post_video($post_id)) { return ''; } $meta = get_post_meta($post_id, '_fvp_video', true); $options = get_option('fvp-settings'); // Extract default and default->general options for easy access. $defaults = !empty($options['default_args']) ? $options['default_args'] : array(); $general = !empty($defaults['general']) ? $defaults['general'] : array(); // Autoplay option. Suppressed when viewing admin. $general['autoplay'] = (defined('DOING_AJAX') && DOING_AJAX || !is_admin()) && !empty($general['autoplay']) && $general['autoplay'] ? '1' : null; // Responsive scaling option. Not used when viewing the admin screen. $responsive = !empty($options['sizing']['responsive']) && $options['sizing']['responsive'] && (defined('DOING_AJAX') && DOING_AJAX || !is_admin()); // Alignment option $align = !empty($options['alignment']) ? $options['alignment'] : 'center'; $args = array('id' => !empty($meta['id']) ? $meta['id'] : null, 'provider' => !empty($meta['provider']) ? $meta['provider'] : null); $provider = $args['provider']; switch ($provider) { case 'local': $img_meta = wp_get_attachment_metadata($meta['id']); $size = $this->get_size($size, array('width' => !empty($img_meta['width']) ? $img_meta['width'] : null, 'height' => !empty($img_meta['height']) ? $img_meta['height'] : null)); $atts = array('src' => wp_get_attachment_url($meta['id']), 'autoplay' => $general['autoplay'] ? 'on' : null, 'loop' => !empty($general['loop']) ? 'on' : null, 'width' => $responsive ? $size['width'] * 8 : $size['width'], 'height' => $responsive ? $size['height'] * 8 : $size['height']); $args = array_merge($args, $atts); $embed = wp_video_shortcode($atts); $embed = apply_filters('fvp-local', $embed, $args); break; case 'raw': $embed = $meta['full']; break; default: $atts = array_merge($general, $this->get_size($size), !empty($defaults[$provider]) ? $defaults[$provider] : array(), isset($meta['parameters']) ? $meta['parameters'] : array()); $args = array_merge($args, $atts); $embed = $this->oembed->get_html($meta['full'], $atts, $provider); $embed = apply_filters('fvp-oembed', $embed, $args); break; } if (empty($embed)) { return ''; } $classnames = array('featured-video-plus' => true, 'post-thumbnail' => true, 'fvp-responsive' => $responsive); $classnames['fvp-' . $provider] = !empty($provider); $classnames['fvp-' . $align] = !empty($align); $embed = sprintf("<!-- Featured Video Plus v%s -->\n<div%s>%s</div>\n\n", FVP_VERSION, FVP_HTML::class_names($classnames, true, true), $embed); return $embed; }
/** * Add a notice about the requirement of a featured image to the * featured image meta box. * * @param {string} $content * @param {int} $post_id * @return {string} */ public function featured_image_box($content, $post_id) { if (!has_post_video($post_id)) { // Has no featured video so the plugin does not interfere. return $content; } if (has_post_thumbnail($post_id)) { // Has featured video and featured image. return $content . sprintf('<p class="hidden"><a href="#" class="fvp-remove-image">%s</a></p>', esc_html__('Remove featured image')); } // Has featured video but not featured image. return sprintf('<p class="fvp-notice">%s <a href="#" class="fvp-set-image hide-if-no-js">%s</a></p>', esc_html__('Featured Videos require a Featured Image for automatic replacement.', 'featured-video-plus'), esc_html__('Auto set', 'featured-video-plus')) . $content; }
/** * * @since 1.7 */ public function ajax_get_embed() { header("Content-Type: application/json"); if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'featured-video-plus-nonce')) { echo json_encode(array('success' => false, 'html' => 'invalid nonce')); exit; } if (has_post_video($_POST['id'])) { $meta = get_post_meta($_POST['id'], '_fvp_video', true); $video = get_the_post_video($_POST['id']); echo json_encode(array('success' => 'true', 'html' => $video, 'id' => $meta['id'])); } else { $image = get_the_post_thumbnail($_POST['id']); echo json_encode(array('success' => 'false', 'html' => $image)); } exit; }
/** * Shortcode for usage in post or page entries. Echos the post's featured video. * * @since 1.0 * * @param array $atts can contain the width and/or height how the featured video should be displayed in px, optional */ function shortcode($atts) { $w = isset($atts['width']) ? $atts['width'] : ''; $h = isset($atts['height']) ? $atts['height'] : ''; if (has_post_video()) { return get_the_post_video(null, array($w, $h)); } }
/** * Returns the featured video html, ready to echo. * * @since 1.0 * * @param int $post_id * @param string|array $size * @param bool $allowfullscreen * @param bool $container */ public function get_the_post_video($post_id = null, $size = null) { $post_id = null === $post_id ? get_the_ID() : $post_id; if (!has_post_video($post_id)) { return false; } $meta = get_post_meta($post_id, '_fvp_video', true); $options = get_option('fvp-settings'); $size = $this->get_size($size); $size = array('width' => $size[0], 'height' => $size[1]); if (!is_admin()) { switch ($options['autoplay']) { case 'yes': $autoplay = '1'; break; case 'auto': if (is_single() || defined('DOING_AJAX') && DOING_AJAX && ($options['usage'] == 'dynamic' || $options['usage'] == 'overlay')) { $autoplay = '1'; } case 'no': default: $autoplay = '0'; break; } } else { $autoplay = '0'; } $valid = $meta['valid']; switch ($meta['prov']) { case 'local': // mediaelement.js is only available in WordPress 3.6 and higher. if (get_bloginfo('version') < 3.6) { break; } $videourl = wp_get_attachment_url($meta['id']); $ext = pathinfo($videourl, PATHINFO_EXTENSION); if ($ext != 'mp4' && $ext != 'ogv' && $ext != 'webm' && $ext != 'ogg') { break; } $videometa = wp_get_attachment_metadata($meta['id']); $atts = array('src' => $videourl, 'poster' => !empty($options['local']['poster']) && $options['local']['poster'] && has_post_thumbnail($post_id) ? wp_get_attachment_url(get_post_thumbnail_id($post_id)) : '', 'loop' => !empty($options['local']['loop']) && $options['local']['loop'] ? 'on' : 'off', 'autoplay' => $autoplay == '1' ? 'on' : null, 'preload' => null, 'height' => $options['sizing']['hmode'] == 'auto' && !is_admin() ? $options['sizing']['wmode'] == 'auto' ? $videometa['height'] * 8 : $videometa['height'] / $videometa['width'] * $videometa['height'] : $size['height'], 'width' => $options['sizing']['wmode'] == 'auto' && !is_admin() ? $videometa['width'] * 8 : $size['width']); $embed = wp_video_shortcode($atts); break; case 'vimeo': $option = $options['vimeo']; $params = array('badge' => 0, 'portrait' => $option['portrait'], 'title' => $option['title'], 'byline' => $option['byline'], 'color' => $option['color'], 'autoplay' => $autoplay); $src = '//player.vimeo.com/video/' . $meta['id'] . '?' . http_build_query($params); $embed = "\n\t" . '<iframe src="' . $src . '" width="' . $size['width'] . '" height="' . $size['height'] . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>' . "\n"; break; case 'youtube': $option = $options['youtube']; $params = array('origin' => esc_attr(home_url()), 'theme' => isset($option['theme']) ? $option['theme'] : 'dark', 'color' => isset($option['color']) ? $option['color'] : 'red', 'enablejsapi' => isset($option['jsapi']) ? $option['jsapi'] : null, 'showinfo' => isset($option['info']) ? $option['info'] : 1, 'modestbranding' => isset($option['logo']) ? $option['logo'] : 1, 'rel' => isset($option['rel']) ? $option['rel'] : 1, 'fs' => isset($option['fs']) ? $option['fs'] : 1, 'start' => isset($meta['time']) ? $meta['time'] : null, 'end' => isset($meta['end_time']) ? $meta['end_time'] : null, 'autoplay' => $autoplay, 'wmode' => isset($option['wmode']) && $option['wmode'] != 'auto' ? $option['wmode'] : null, 'playerapiid' => isset($option['jsapi']) && $option['jsapi'] == 1 ? 'fvpyt' . $post_id : null); $src = '//www.youtube.com/embed/' . $meta['id'] . '?' . http_build_query($params); $embed = "\n\t" . '<iframe width="' . $size['width'] . '" height="' . $size['height'] . '" src="' . $src . '" type="text/html" frameborder="0" id="fvpyt' . $post_id . '"></iframe>' . "\n"; break; case 'dailymotion': $option = $options['dailymotion']; $params = array('foreground' => isset($option['foreground']) ? $option['foreground'] : null, 'highlight' => isset($option['highlight']) ? $option['highlight'] : null, 'background' => isset($option['background']) ? $option['background'] : null, 'logo' => isset($option['logo']) ? $option['logo'] : 1, 'hideInfos' => isset($option['info']) ? 1 - $option['info'] : 0, 'syndication' => empty($option['syndication']) ? null : $option['syndication'], 'start' => $meta['time']); $src = '//www.dailymotion.com/embed/video/' . $meta['id'] . '?' . http_build_query($params); $embed = "\n" . '<iframe width="' . $size['width'] . '" height="' . $size['height'] . '" src="' . $src . '" frameborder="0"></iframe>' . "\n"; break; case 'liveleak': $embed = "\n" . '<iframe width="' . $size['width'] . '" height="' . $size['height'] . '" src="//www.liveleak.com/ll_embed?f=' . $meta['id'] . '" frameborder="0" allowfullscreen></iframe>'; break; case 'prochan': $embed = "\n" . '<iframe width="' . $size['width'] . '" height="' . $size['height'] . '" src="//www.prochan.com/embed?f=' . $meta['id'] . '" frameborder="0" allowfullscreen></iframe>'; break; default: $embed = wp_oembed_get($meta['full'], $size); break; } if (!$embed) { return ''; } $class = $options['sizing']['wmode'] == 'auto' ? ' responsive' : ''; $containerstyle = isset($options['sizing']['align']) ? ' style="text-align: ' . $options['sizing']['align'] . '"' : ''; $embed = "<div class=\"featured_video_plus{$class}\"{$containerstyle}>{$embed}</div>\n\n"; $embed = "\n\n<!-- Featured Video Plus v" . FVP_VERSION . "-->\n" . $embed; return $embed; }
sharing_display('', true); } if (class_exists('Jetpack_Likes')) { $custom_likes = new Jetpack_Likes(); echo $custom_likes->post_likes(''); } ?> </div> <!-- featured images & videos --> <div class="container-fluid"> <?php // display featured video //echo has_post_video($post->ID); if (has_post_video($post->ID)) { echo get_the_post_video($post->ID, 'large'); } else { //display featured image if (has_post_thumbnail($post->ID)) { $thumb_id = get_post_thumbnail_id(); $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true); $thumb_url = $thumb_url_array[0]; //echo $thumb_url; //echo '<img src="'.$thumb_url.'" alt="featured image">'; echo '<div class="bg-image" style="background-image:url(' . $thumb_url . ')"></div>'; } } ?> </div> </section>
<!-- DISPLAY POST IN HOME PAGE AND CATEGORIES, TAG, SEARCH PAGE --> <?php $post_id = get_the_ID(); $post_link = get_permalink($post_id); ?> <div class="row story-wrapper"> <div id="story-image-<?php echo $post_id; ?> "class="col-md-6 story-image" > <?php if (has_post_video($post_id)) { ?> <a href="<?php echo $post_link; ?> "><?php echo get_the_post_video_image($post_id); ?> </a> <script type="text/javascript"> $("#story-image-<?php echo $post_id; ?> ").append("<span class='fa fa-play-circle video-play-button'></span>"); </script> <?php } else { ?> <a href="<?php echo $post_link;
}).next("div").css({ position: "absolute", top: 0, width: "100%" }); } }(jQuery); jQuery(document).ready(getFeaturedBlogPost); </script> <div class="featured-video"> <?php $video_args = array('numberposts' => 1, 'category_name' => 'featured-video', 'orderby' => 'date'); $weekly_video = get_posts($video_args); foreach ($weekly_video as $post) { setup_postdata($post); if (has_post_video()) { the_post_video(); } else { the_post_thumbnail(); } } wp_reset_postdata(); ?> </div> </section> <section class="weekly-tip col-full"> <img src="/wp-content/themes/storefront-child/images/weekly-tip.png" alt="your weekly disc golf tip" /> <div class="weekly-tip-content"> <?php $wt_args = array('numberposts' => 1, 'category_name' => 'weekly-tip', 'orderby' => 'date');