/** * Convert a Vimeo shortcode into an embed code. * * @param array $atts An array of shortcode attributes. * @return string The embed code for the Vimeo video. */ function vimeo_shortcode($atts) { global $content_width; extract(array_map('intval', shortcode_atts(array('id' => 0, 'width' => 400, 'height' => 300, 'autoplay' => 0, 'loop' => 0), $atts, 'vimeo'))); if (isset($atts[0])) { $id = jetpack_shortcode_get_vimeo_id($atts); } if (!$id) { return "<!-- vimeo error: not a vimeo video -->"; } // [vimeo 141358 h=500&w=350] $params = shortcode_new_to_old_params($atts); // h=500&w=350 $params = str_replace(array('&', '&'), '&', $params); parse_str($params, $args); if (isset($args['w'])) { $width = (int) $args['w']; if (!isset($args['h'])) { // The case where w=300 is specified without h=200, otherwise $height // will always equal the default of 300, no matter what w was set to. $height = round($width / 640 * 360); } } if (isset($args['h'])) { $height = (int) $args['h']; if (!isset($args['w'])) { $width = round($height / 360 * 640); } } if (!$width) { $width = absint($content_width); } if (!$height) { $height = round($width / 640 * 360); } $url = esc_url(set_url_scheme("http://player.vimeo.com/video/{$id}")); // $args['autoplay'] is parsed from the embedded url. // $autoplay is parsed from shortcode arguments. // in_array( 'autoplay', $atts ) catches the argument passed without a value. if (!empty($args['autoplay']) || !empty($autoplay) || in_array('autoplay', $atts)) { $url = add_query_arg('autoplay', 1, $url); } if (!empty($args['loop']) || !empty($loop) || in_array('loop', $atts)) { $url = add_query_arg('loop', 1, $url); } $html = sprintf('<div class="embed-vimeo" style="text-align:center;"><iframe src="%1$s" width="%2$u" height="%3$u" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>', esc_url($url), $width, $height); $html = apply_filters('video_embed_html', $html); return $html; }
/** * Convert a Vimeo shortcode into an embed code. * * @param array $atts An array of shortcode attributes. * @return string The embed code for the Vimeo video. */ function vimeo_shortcode($atts) { global $content_width; extract(array_map('intval', shortcode_atts(array('id' => 0, 'width' => 400, 'height' => 300), $atts))); if (isset($atts[0])) { $id = jetpack_shortcode_get_vimeo_id($atts); } if (!$id) { return "<!-- vimeo error: not a vimeo video -->"; } // [vimeo 141358 h=500&w=350] $params = shortcode_new_to_old_params($atts); // h=500&w=350 $params = str_replace(array('&', '&'), '&', $params); parse_str($params, $args); if (isset($args['w'])) { $width = (int) $args['w']; if (!isset($args['h'])) { // The case where w=300 is specified without h=200, otherwise $height // will always equal the default of 300, no matter what w was set to. $height = round($width / 640 * 360); } } if (isset($args['h'])) { $height = (int) $args['h']; if (!isset($args['w'])) { $width = round($height / 360 * 640); } } if (!$width) { $width = absint($content_width); } if (!$height) { $height = round($width / 640 * 360); } $url = esc_url(set_url_scheme("http://player.vimeo.com/video/{$id}")); $html = "<div class='embed-vimeo' style='text-align:center;'><iframe src='{$url}' width='{$width}' height='{$height}' frameborder='0'></iframe></div>"; $html = apply_filters('video_embed_html', $html); return $html; }
/** * Convert a Vimeo shortcode into an embed code. * * @param array $atts An array of shortcode attributes. * * @return string The embed code for the Vimeo video. */ function vimeo_shortcode($atts) { global $content_width; $attr = array_map('intval', shortcode_atts(array('id' => 0, 'width' => 0, 'height' => 0, 'autoplay' => 0, 'loop' => 0), $atts)); if (isset($atts[0])) { $attr['id'] = jetpack_shortcode_get_vimeo_id($atts); } if (!$attr['id']) { return '<!-- vimeo error: not a vimeo video -->'; } // [vimeo 141358 h=500&w=350] $params = shortcode_new_to_old_params($atts); // h=500&w=350 $params = str_replace(array('&', '&'), '&', $params); parse_str($params, $args); $width = intval($attr['width']); $height = intval($attr['height']); // Support w and h argument as fallback. if (empty($width) && isset($args['w'])) { $width = intval($args['w']); if (empty($height) && !isset($args['h'])) { // The case where w=300 is specified without h=200, otherwise $height // will always equal the default of 300, no matter what w was set to. $height = round($width / 640 * 360); } } if (empty($height) && isset($args['h'])) { $height = (int) $args['h']; if (!isset($args['w'])) { $width = round($height / 360 * 640); } } if (!$width && !empty($content_width)) { $width = absint($content_width); } // If setting the width with content_width has failed, defaulting if (!$width) { $width = 640; } if (!$height) { $height = round($width / 640 * 360); } /** * Filter the Vimeo player width. * * @module shortcodes * * @since 3.4.0 * * @param int $width Width of the Vimeo player in pixels. */ $width = (int) apply_filters('vimeo_width', $width); /** * Filter the Vimeo player height. * * @module shortcodes * * @since 3.4.0 * * @param int $height Height of the Vimeo player in pixels. */ $height = (int) apply_filters('vimeo_height', $height); $url = esc_url('https://player.vimeo.com/video/' . $attr['id']); // Handle autoplay and loop arguments. if (isset($args['autoplay']) && '1' === $args['autoplay'] || $attr['autoplay'] || in_array('autoplay', $atts)) { $url = add_query_arg('autoplay', 1, $url); } if (isset($args['loop']) && '1' === $args['loop'] || $attr['loop'] || in_array('loop', $atts)) { $url = add_query_arg('loop', 1, $url); } $html = sprintf('<div class="embed-vimeo" style="text-align: center;"><iframe src="%1$s" width="%2$u" height="%3$u" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>', esc_url($url), esc_attr($width), esc_attr($height)); /** * Filter the Vimeo player HTML. * * @module shortcodes * * @since 1.2.3 * * @param string $html Embedded Vimeo player HTML. */ $html = apply_filters('video_embed_html', $html); return $html; }