/** * Generate Download Code * * Create code to allow a YouTube video to be downloaded * * @package YouTube-Embed * @since 2.0 * * @uses vye_extract_id Extract an ID from a string * @uses vye_validate_id Confirm the type of video * @uses vye_error Display an error * * @param string $id YouTube video ID * @return string Download HTML */ function vye_generate_download_code($id) { if ($id == '') { return vye_error(__('No YouTube ID was found.', 'youtube-embed')); } // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); if ($embed_type != 'v') { if (strlen($embed_type) > 1) { return vye_error($embed_type); } else { return vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id)); } } // Create the link return 'http://www.videodownloadx.com/?video=' . $id; }
/** * Generate video short URL * * Create a short URL to a YouTube video * * @package YouTube-Embed * @since 2.0 * * @uses vye_extract_id Extract an ID from a string * @uses vye_validate_id Confirm the type of video * @uses vye_error Display an error * * @param string $id YouTube video ID * @return string $youtube_code Code */ function vye_generate_shorturl_code($id) { // Check that an ID has been specified if ($id == '') { return vye_error(__('No video ID has been supplied', 'youtube-embed')); } else { // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); if ($embed_type != 'v') { if (strlen($embed_type) > 1) { return vye_error($embed_type); } else { return vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id)); } } return 'http://youtu.be/' . $id; } }
/** * Generate Thumbnail Code * * Generate XHTML compatible YouTube video thumbnail * * @package YouTube-Embed * @since 2.0 * * @uses vye_extract_id Extract an ID from a string * @uses vye_validate_id Confirm the type of video * @uses vye_error Display an error * * @param string $id YouTube video ID * @param string $style Link STYLE * @param string $class Link CLASS * @param string $rel Link REL * @param string $target Link target * @param string $width Width * @param string $height Height * @param string $alt ALT text * @param string $version Thumbnail version * @param string $nolink True or False, whether no link should be added * @return string $youtube_code Code */ function vye_generate_thumbnail_code($id, $style, $class, $rel, $target, $width, $height, $alt, $version, $nolink = false) { // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); if ($embed_type != 'v') { if (strlen($embed_type) > 1) { return vye_error($embed_type); } else { return vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id)); } } $version = strtolower($version); if ($version != 'default' && $version != 'hq' && $version != 'start' && $version != 'middle' && $version != 'end') { $version = 'default'; } if ($version == 'hq') { $version = 'hqdefault'; } if ($version == 'start') { $version = 1; } if ($version == 'middle') { $version = 2; } if ($version == 'end') { $version = 3; } // Now create the required code if ($alt == '') { $alt = sprintf(__('YouTube Video %s'), $id); } if (!$nolink) { $youtube_code = '<a href="http://www.youtube.com/watch?v=' . $id . '"'; if ($style != '') { $youtube_code .= ' style="' . $style . '"'; } if ($class != '') { $youtube_code .= ' class="' . $class . '"'; } if ($rel != '') { $youtube_code .= ' rel="' . $rel . '"'; } if ($target != '') { $youtube_code .= ' target="' . $target . '"'; } $youtube_code .= '>'; } $youtube_code .= '<img src="http://img.youtube.com/vi/' . $id . '/' . $version . '.jpg"'; if ($width != '') { $youtube_code .= ' width="' . $width . '"'; } if ($height != '') { $youtube_code .= ' height="' . $height . '"'; } $youtube_code .= ' alt="' . $alt . '"/>'; if (!$nolink) { $youtube_code .= '</a>'; } return $youtube_code; }
/** * Get Video Name * * Function to return the name of a YouTube video * * @since 2.0 * * @uses vye_extract_id Extract the video ID * @uses vye_validate_id Get the name and video type * @uses vye_error Return an error * * @param string $id Video ID * @return string Video name */ function get_youtube_name($id) { // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $return = vye_validate_id($id, true); $embed_type = $return['type']; if (strlen($embed_type) > 1) { echo vye_error($embed_type); } else { echo vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id)); } // Return the video title return $return['title']; }
/** * Download shortcode * * Generate a short URL for a YouTube video * * @since 2.0 * * @uses vye_generate_download_code Generate the download code * * @param string $paras Shortcode parameters * @param string $content Shortcode content * @return string YouTube download link */ function vye_video_download($paras = '', $content = '') { extract(shortcode_atts(array('id' => ''), $paras)); if ($id == '') { return do_shortcode(vye_error(__('No YouTube ID was found.', 'youtube-embed'))); } // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); if ($embed_type != 'v') { if (strlen($embed_type) > 1) { return do_shortcode(vye_error($embed_type)); } else { return do_shortcode(vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id))); } } // Get the download code $link = vye_generate_download_code($id); // Now return the HTML return do_shortcode($link); }
/** * Search content for alternative embed methods * * Look through post/page content for various alternative methods of embedding - replace with * embed code. * * @since 2.0 * * @uses vye_convert_content Convert a URL to the embed code * @uses vye_generate_youtube_code Generate the YouTube embed code * @uses vye_set_general_defaults Get general defaults * @uses vye_validate_id Validate the video ID * * @param string $content Post/page content * @return string Resulting post/page content */ function vye_content_search($content) { $options = vye_set_general_defaults(); // The following are URL modifications if ($options['alt'] == 1) { $changed = true; while ($changed) { $changed = false; // Search for httpv URL $identifier = 'httpv://www.youtube.com/watch?v='; $search = strpos($content, $identifier); if ($search !== false) { $content = vye_convert_content($content, $identifier, substr($content, $search + strlen($identifier), 11), '', '', $options['other_profile']); $changed = true; } // Search for httpa URL $identifier = 'httpa://www.youtube.com/watch?v='; $search = strpos($content, $identifier); if ($search !== false) { $content = vye_convert_content($content, $identifier, substr($content, $search + strlen($identifier), 11), 1, '', $options['other_profile']); $changed = true; } // Search for httpvh URL $identifier = 'httpvh://www.youtube.com/watch?v='; $search = strpos($content, $identifier); if ($search !== false) { $content = vye_convert_content($content, $identifier, substr($content, $search + strlen($identifier), 11), '', '', $options['other_profile']); $changed = true; } // Search for httpvp playlist URL $identifier = 'httpvp://www.youtube.com/watch?p='; $search = strpos($content, $identifier); if ($search !== false) { $content = vye_convert_content($content, $identifier, substr($content, $search + strlen($identifier), 16), '', '', $options['other_profile']); $changed = true; } // Search for youtube:: URL $identifier = 'youtube::'; $search = strpos($content, $identifier); if ($search !== false) { $suffix = substr($content, $search + strlen($identifier) + 11, 2); if ($suffix == '::') { $content = vye_convert_content($content, $identifier, substr($content, $search + strlen($identifier), 11), '', '::', $options['other_profile']); $changed = true; } } } } // The following are embedding URLs that are within brackets but are not shortcodes if ($options['bracket'] == 1) { // Loop around content, looking for brackets - possible YouTube URL within! $current_pos = 0; $bracket_found = true; while ($bracket_found) { $open_bracket = strpos($content, '[', $current_pos); if ($open_bracket !== false) { $close_bracket = strpos($content, ']', $open_bracket); if ($close_bracket !== false) { $code = substr($content, $open_bracket + 1, $close_bracket - $open_bracket - 1); $code_found = false; $id = $code; // Maybe a video ID - validate first if (strlen($code) == 11 && !strpos($code, ' ')) { $type = vye_validate_id($code); if ($type == 'v') { $code_found = true; } } // Video URL if (strpos($code, 'youtube.com/watch?v=') !== false && !$code_found) { $code_found = true; } // Other URLs if (substr($code, 0, 8) == 'watch?v=' && !$code_found) { $id = substr($code, 8); $code_found = true; } if (substr($code, 0, 2) == 'v=' && !$code_found) { $id = substr($code, 2); $code_found = true; } // If an ID was found, update the code if ($code_found) { $ye_code = vye_generate_youtube_code($id, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', $options['other_profile'], '', ''); $content = str_replace('[' . $code . ']', $ye_code, $content); } } $current_pos = $close_bracket; } else { $bracket_found = false; } } } return $content; }
/** * Get YouTube Transcript * * Generate re-encoded YouTube transcript * * @since 2.0 * * @uses vye_extract_id Extract the ID * @uses vye_get_file Get a file * @uses vye_set_general_defaults Set default options * @uses vye_validate_id Validate the ID * * @param string $id Video ID * @param string $language Language * @return string $output Transcript output */ function vye_generate_transcript($id, $language = 'en') { // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); if ($embed_type != 'v') { if (strlen($embed_type) > 1) { return vye_error($embed_type); } else { return vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id)); } } // Get general options $general = vye_set_general_defaults(); // Check to see if cache is available if ($general['transcript_cache'] != 0) { $cache_key = 'vye_transcript_' . $id; $output = get_transient($cache_key); if ($output !== false) { return $output; } } // Get transcript file $return = vye_get_file('http://video.google.com/timedtext?lang=' . strtolower($language) . '&v=' . $id); $xml = $return['file']; $output = ''; // If transcript file exists, strip and output if ($return['rc'] == 0) { $output = "<!-- YouTube Embed v" . youtube_embed_version . " -->\n"; $pos = 0; $eof = false; while (!$eof) { $text_start = strpos($xml, '<text ', $pos); if ($text_start !== false) { // Extract the start time $start_start = strpos($xml, 'start="', $text_start) + 7; $start_end = strpos($xml, '"', $start_start) - 1; $start = substr($xml, $start_start, $start_end - $start_start + 1); // Convert time format $start = str_pad(floor($start), 3, '0', STR_PAD_LEFT); $start = substr($start, 0, -2) . ':' . substr($start, -2, 2); // Now extract the text $text_start = strpos($xml, '>', $text_start) + 1; $text_end = strpos($xml, '</text>', $text_start) - 1; $text = substr($xml, $text_start, $text_end - $text_start + 1); // Now return the output $output .= "<div class=\"Transcript\"><span class=\"TranscriptTime\">" . $start . "</span> <span class=\"TranscriptText\">" . htmlspecialchars_decode($text) . "</span></div>\n"; $pos = $text_end + 7; } else { $eof = true; } } $output .= "<!-- End of YouTube Embed code -->\n"; } // Save the cache if ($general['transcript_cache'] != 0) { set_transient($cache_key, $output, 3600 * $general['transcript_cache']); } return $output; }
/** * Get YouTube comments * * Generate output of video comments * * @since 3.2 * * @uses vye_extract_id Extract the ID * @uses vye_get_file Get a file * @uses vye_set_general_defaults Set default options * @uses vye_validate_id Validate the ID * * @param string $id Video ID * @param string $language Language * @return string $output Transcript output */ function vye_generate_comments($paras) { extract($paras); if ($id == '') { return vye_error(__('No YouTube ID was specified.', 'youtube-embed')); } // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); if ($embed_type != 'v') { if (strlen($embed_type) > 1) { return vye_error($embed_type); } else { return vye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id)); } } // Get general options $general = vye_set_general_defaults(); // Get cache time if ($cache == '') { $cache = $general['comments_cache']; } // Check to see if cache is available if ($cache != 0) { $cache_key = 'vye_comments_' . $id; $output = get_transient($cache_key); $output = false; if ($output !== false) { return $output; } } // Get transcript file $return = vye_get_file('https://gdata.youtube.com/feeds/api/videos/' . $id . '/comments?orderby=published'); $xml = $return['file']; $output = ''; // If comments file exists process the XML and build the output if ($return['rc'] == 0) { // Set default values $output = "<!-- YouTube Embed v" . youtube_embed_version . " -->\n" . '<div id="comments">' . "\n"; $pos = 0; $eof = false; $number = 1; if (!is_numeric($avatar)) { $avatar = 32; } if (!is_numeric($limit)) { $limit = 10; } $tab = "\t"; while (!$eof) { $entry = vye_extract_xml($xml, 'entry'); if ($entry != '') { // Extract field data from XML $published = human_time_diff(strtotime(vye_extract_xml($entry, 'published'))); $comment = vye_extract_xml($entry, 'content'); $user = vye_extract_xml($entry, 'name'); $profile_url = 'http://www.youtube.com/user/' . $user; $user_xml_url = vye_extract_xml($entry, 'uri'); // Get user image URL from a seperate XML file $image_url = ''; $user_xml = wp_remote_get($user_xml_url); $start_pos = strpos($user_xml['body'], '<media:thumbnail url='); if ($start_pos !== false) { $start_pos = $start_pos + 22; $end_pos = strpos($user_xml['body'], '/>', $start_pos); if ($end_pos !== false) { $end_pos = $end_pos - 2; $image_url = substr($user_xml['body'], $start_pos, $end_pos - $start_pos + 1); } } // Using the information fetched above built the comment output $output .= '<div id="comment-' . $number . '">' . "\n"; $output .= $tag . '<div class="comment-author">' . "\n"; if (is_numeric($avatar)) { $output .= $tab . $tab . '<img alt="" src="' . $image_url . '" class="avatar avatar-' . $avatar . '" height="' . $avatar . 'px" width="' . $avatar . 'px" />' . "\n"; } $output .= $tab . $tab . '<cite class="fn"><a href="' . $profile_url . '" rel="external nofollow" class="url">' . $user . '</a></cite>' . "\n"; $output .= $tab . '</div>' . "\n"; $output .= $tab . '<div class="comment-meta commentmetadata">' . $published . ' ' . __('ago', 'youtube-embed') . '</div>' . "\n"; $output .= $tab . '<div class="comment-body"><p>' . $comment . '</p></div>' . "\n"; $output .= '</div>' . "\n"; $number++; if ($number > $limit) { $eof = true; } } else { $eof = true; } // Remove current record from the XML file $next_record = strpos($xml, '</entry>'); if ($next_record !== false) { $xml = substr($xml, $next_record + 8); } } $output .= "</div>\n<!-- End of YouTube Embed code -->\n"; } // Save the cache if ($cache != 0) { set_transient($cache_key, $output, 60 * $cache); } return $output; }
/** * Generate embed code * * Generate XHTML compatible YouTube embed code * * @since 2.0 * * @uses vye_add_links Add links under video * @uses vye_error Display an error * @uses vye_extract_id Get the video ID * @uses vye_validate_list Get the requested listr * @uses vye_validate_id Validate the video ID * @uses vye_validate_profile Get the requested profile * @uses vye_set_general_defaults Get general options * @uses vye_set_profile_defaults Set default profile options * * @param string $id Video ID * @param string $width Video width * @param string $height Video height * @param string $fullscreen Fullscreen button * @param string $related Show related info. * @param string $autoplay Start video automatically * @param string $loop Loop video to start * @param string $start Start in seconds * @param string $info Show video info. * @param string $annotation Annotations * @param string $cc Closed captions * @param string $style Stylesheet information * @param string $stop Stop in seconds * @param string $disablekb Disable keyboard controls * @param string $ratio Video size ratio * @param string $autohide Autohide controls * @param string $controls Display controls * @param string $profile Which profile to use * @param string $list_style How to use a list, if used * @param string $template Display template * @param string $color Progress bar color * @param string $theme Use dark or light theme * @param string $https Use HTTPS for links * @param string $dynamic Show dynamic output * @param string $search Perform a search * @param string $user Look up user videos * @param string $modest Modest browsing * @param string $playsinline Playsinline on iOS * @param string $html5 Force HTML5 * @return string Code output */ function vye_generate_youtube_code($id = '', $width = '', $height = '', $fullscreen = '', $related = '', $autoplay = '', $loop = '', $start = '', $info = '', $annotation = '', $cc = '', $style = '', $stop = '', $disablekb = '', $ratio = '', $autohide = '', $controls = '', $profile = '', $list_style = '', $template = '', $color = '', $theme = '', $https = '', $dynamic = '', $search = '', $user = '', $modest = '', $playsinline = '', $html5 = '') { $start_time = microtime(true); // Ensure an ID is passed if ($id == '') { return vye_error(__('No video/playlist ID has been supplied', 'youtube-embed')); } $newline = "\n"; $tab = "\t"; // Get general options $general = vye_set_general_defaults(); // Find the profile, if one is specified $profile = vye_validate_profile($profile, $general['profile_no']); // Get default values if no values are supplied $options = vye_set_profile_defaults($profile); // If a user look-up or search has been requested, miss out looking up list details and // simple assign it as an IFRAME video $playlist_ids = ''; $embed_type = ''; if ($user == 0 && $search == 0) { // Check it's not a list $list = vye_validate_list($id, $general['list_no']); if (!is_array($list)) { // Check if certain parameters are included in the URL $width = vye_get_url_para($id, 'w', $width); $height = vye_get_url_para($id, 'h', $height); // Extract the ID if a full URL has been specified $id = vye_extract_id($id); // Check what type of video it is and whether it's valid $embed_type = vye_validate_id($id); // If the video is invalid, output an error if ($embed_type == '' or strlen($embed_type) != 1) { $result = $newline . '<!-- YouTube Embed v' . youtube_embed_version . ' -->' . $newline; $result .= sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id) . $newline . '<!-- End of YouTube Embed code -->' . $newline; return $result; } } else { $return = ''; $embed_type = 'v'; // Randomize the video if ($list_style == 'random') { shuffle($list); } // Extract one video randomly if ($list_style == 'single') { $id = $list[array_rand($list, 1)]; // Build the playlist } else { $id = $list[0]; // Build the playlist if (count($list) > 1) { $loop = 1; while ($loop < count($list)) { if ($playlist_ids != '') { $playlist_ids .= ','; } $list_id = vye_extract_id($list[$loop]); $playlist_ids .= $list_id; $loop++; } } } } } $metadata = $general['metadata']; // Correct the ID if a playlist if (strtolower(substr($id, 0, 2)) == 'pl') { $id = substr($id, 2); } // Work out correct protocol to use - HTTP or HTTPS if ($https == '') { $https = $options['https']; } if ($https == 1) { $https = 's'; } else { $https = ''; } // If this is a feed then display a thumbnail and/or text link to the original video if (is_feed()) { $result = ''; if ($playlist_ids != '') { $result .= '<p>' . __('A video list cannot be viewed within this feed - please view the original content', 'youtube-embed') . '.</p>' . $newline; } else { $youtube_url = 'http' . $https . '://www.youtube.com/watch?' . $embed_type . '=' . $id; if ($embed_type == 'v' && $general['feed'] != 't') { $result .= '<p><a href="' . $youtube_url . '"><img src="http://img.youtube.com/vi/' . $id . '/' . $general['thumbnail'] . '.jpg"></a></p>' . $newline; } if ($general['feed'] != 'v' or $embed_type != 'v') { $result .= '<p><a href="' . $youtube_url . '">' . __('Click here to view the video on YouTube', 'youtube-embed') . '</a>.</p>' . $newline; } } return $result; } // If a dynamic size has been requested, check whether the width should be fixed $fixed = 0; if ($dynamic == '') { $dynamic = $options['dynamic']; $fixed = $options['fixed']; } else { if ($width != '') { $fixed = 1; } } // Only set width and height from defaults if both are missing if ($width == '' && $height == '') { $width = $options['width']; $height = $options['height']; } // If controls parameter is not numeric then convert to 0 or 1 // This is to maintain backwards compatibility after version 2.6 if (!is_numeric($controls) && $controls != '') { $controls = vye_convert($controls); } // If values have not been pressed, use the default values if ($fullscreen == '') { $fullscreen = $options['fullscreen']; } if ($related == '') { $related = $options['related']; } if ($autoplay == '') { $autoplay = $options['autoplay']; } if ($loop == '') { $loop = $options['loop']; } if ($info == '') { $info = $options['info']; } if ($annotation == '') { $annotation = $options['annotation']; } if ($cc == '') { $cc = $options['cc']; } if ($disablekb == '') { $disablekb = $options['disablekb']; } if ($autohide == '') { $autohide = $options['autohide']; } if ($controls == '') { $controls = $options['controls']; } if ($style == '') { $style = $options['style']; } if ($color == '') { $color = $options['color']; } if ($theme == '') { $theme = $options['theme']; } if ($modest == '') { $modest = $options['modest']; } if ($playsinline == '') { $playsinline = $options['playsinline']; } if ($html5 == '') { $html5 = $options['html5']; } $language = $general['language']; $debug = $general['debug']; $wmode = $options['wmode']; if ($theme == '') { $theme = $options['theme']; } // Build the required template if ($template == '') { $template = $options['template']; } else { $template = vye_decode($template); } if (strpos($template, '%video%') === false) { $template = '%video%'; } // If looping and no playlist has been generated, add the current ID // This is a workaround for the AS3 player which won't otherwise loop if ($loop == 1 && $embed_type != 'p' && $playlist_ids == '') { $playlist_ids = $id; } // Set parameters without default values if ($start == '') { $start = '0'; } if ($stop == '') { $stop = '0'; } // If height or width is missing, calculate missing parameter using ratio if (($width == '' or $height == '') && ($width != '' or $height != '')) { $ratio_to_use = ''; if ($ratio != '') { // Extract the ratio from the provided string $pos = strpos($ratio, ':', 0); if ($pos !== false) { $ratio_l = substr($ratio, 0, $pos); $ratio_r = substr($ratio, $pos + 1); if (is_numeric($ratio_l) && is_numeric($ratio_r)) { $ratio_to_use = $ratio_l / $ratio_r; } } } // If no, or invalid, ratio supplied, calculate from the default video dimensions if ($ratio_to_use == '') { $ratio_to_use = $options['width'] / $options['height']; } // Complete the missing width or height using the ratio if ($width == '') { $width = round($height * $ratio_to_use, 0); } if ($height == '') { $height = round($width / $ratio_to_use, 0); } } // Set Frameborder output $frameborder = ''; $amp = '&'; if (isset($general['frameborder'])) { if ($general['frameborder'] != 1) { $frameborder = 'frameborder="0" '; } else { $amp = '&'; } } // Set up embed types $class = 'youtube-player'; $paras = ''; // Generate parameters to add to URL if ($modest == 1) { $paras .= $amp . 'modestbranding=1'; } if ($fullscreen != 1) { $paras .= $amp . 'fs=0'; } if ($related != 1) { $paras .= $amp . 'rel=0'; } if ($autoplay == 1) { $paras .= $amp . 'autoplay=1'; } if ($loop == 1) { $paras .= $amp . 'loop=1'; } if ($info != 1) { $paras .= $amp . 'showinfo=0'; } if ($annotation != 1) { $paras .= $amp . 'iv_load_policy=3'; } if ($cc != '') { $paras .= $amp . 'cc_load_policy=' . $cc; } if ($disablekb == 1) { $paras .= $amp . 'disablekb=1'; } if ($autohide != 2) { $paras .= $amp . 'autohide=' . $autohide; } if ($controls != 1) { $paras .= $amp . 'controls=' . $controls; } if (strtolower($color) != 'red') { $paras .= $amp . 'color=' . strtolower($color); } if (strtolower($theme) != 'dark') { $paras .= $amp . 'theme=' . strtolower($theme); } if ($wmode != 'window') { $paras .= $amp . 'wmode=' . $wmode; } if ($playsinline == 1) { $paras .= $amp . 'playsinline=1'; } if ($html5 == 1) { $paras .= $amp . 'html5=1'; } if ($language != '') { $paras .= $amp . 'hl=' . $language; } // If not a playlist, add the playlist parameter if ($playlist_ids != '' && $playlist_ids != $id) { $paras .= $amp . 'playlist=' . $playlist_ids; } // Add start & stop parameters if ($start != 0) { $paras .= $amp . 'start=' . $start; } if ($stop != 0) { $paras .= $amp . 'end=' . $stop; } // Generate DIVs to wrap around video $ttab = $tab; $result = '<div class="youtube-embed'; if ($dynamic == 1) { $result .= ' ye-container'; } $result .= '"'; if ($metadata != 0) { $result .= ' itemprop="video" itemscope itemtype="http://schema.org/VideoObject"'; } $result .= '>' . $newline; if ($dynamic == 1 && $fixed == 1) { $result = '<div style="width: ' . $width . 'px; max-width: 100%">' . $newline . $tab . $result; $ttab .= $tab; } // Add Metadata if ($metadata != 0) { $title = get_the_title(); $result .= $ttab . '<meta itemprop="url" content="http' . $https . '://www.youtube.com/' . $embed_type . '/' . $id . '" />' . $newline; $result .= $ttab . '<meta itemprop="name" content="' . $title . '" />' . $newline; $result .= $ttab . '<meta itemprop="description" content="' . $title . '" />' . $newline; $result .= $ttab . '<meta itemprop="uploadDate" content="' . get_the_date('c') . '" />' . $newline; $result .= $ttab . '<meta itemprop="thumbnailUrl" content="http://i.ytimg.com/vi/' . $id . '/hqdefault.jpg" />' . $newline; $result .= $ttab . '<meta itemprop="embedUrl" content="http' . $https . '://www.youtube.com/embed/' . $id . '" />' . $newline; $result .= $ttab . '<meta itemprop="height" content="' . $height . '" />' . $newline; $result .= $ttab . '<meta itemprop="width" content="' . $width . '" />' . $newline; } // Work out, depending on privacy settings, the main address to use $privacy = $general['privacy']; if ($privacy == 2) { $do_not_track = vye_do_not_track(); if ($do_not_track) { $privacy = 1; } else { $privacy = 0; } } if ($privacy == 1) { $url_privacy = 'youtube-nocookie.com'; } else { $url_privacy = 'youtube.com'; } // Generate the first part of the embed URL along with the ID section $embed_url = 'http' . $https . '://www.' . $url_privacy . '/embed'; $id_paras = '/' . $id; // If a playlist, user or download build the ID appropriately if ($embed_type == 'p' or $user != 0 or $search != 0) { $list_type = ''; if ($embed_type == 'p') { $list_type = 'playlist'; } if ($user != 0) { $list_type = 'user_uploads'; } if ($search != 0) { $list_type = 'search'; $id = urlencode($id); } $id_paras = '?listType=' . $list_type . '&list='; if ($embed_type == 'p' && strtolower(substr($id, 0, 2)) != 'pl') { $id_paras .= 'PL'; } $id_paras .= $id; } // Combine URL parts together $embed_url .= $id_paras; if (!strpos($embed_url, '?') && $paras != '') { $paras = '?' . substr($paras, 1); } $embed_url .= $paras; // Check length of URL to ensure it doesn't exceed 2000 characters if (strlen($embed_url) > 2000) { return vye_error(__('The maximum URL length has been exceeded. Please reduce your parameter and/or playlist.', 'youtube-embed')); } // Add IFRAME embed code if ($embed_type == "p") { $playlist_para = "p/"; } else { $playlist_para = ''; } $result .= $ttab . '<iframe ' . $frameborder . 'style="border: 0;' . $style . '" class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . $embed_url . '"'; if ($fullscreen == 1) { $result .= ' allowfullscreen'; } $result .= ' ></iframe>' . $newline; // Now apply the template to the result $end_tag = ''; if ($dynamic == 1 && $fixed == 1) { $end_tag .= $tab . '</div>' . $newline . '</div>' . $newline; } else { $end_tag .= '</div>' . $newline; } $result = str_replace('%video%', $result . $end_tag, $template); // Add the download link, if required if ($options['download'] == 1 && $embed_type == 'v') { $result .= '<div style="' . $options['download_style'] . '" class="aye_download">' . $newline . $tab . '<a href="' . vye_generate_download_code($id) . "\">" . $options['download_text'] . '</a>' . $newline . '</div>' . $newline; } // Now add a commented header and trailer if ($debug == 1) { $result = '<!-- YouTube Embed v' . youtube_embed_version . ' -->' . $newline . $result; $runtime = round(microtime(true) - $start_time, 5); $result .= '<!-- End of YouTube Embed code. Generated in ' . $runtime . ' seconds -->' . $newline; } return $newline . $result; }
"/></p> </form> <?php // If video IDs exist display them on screen along with their status' if ($options['list'] != '') { $id_array = explode("\n", $options['list']); echo "<table class=\"widefat\">\n<thead>\n\t<tr>\n\t\t<th>" . __('Video ID', 'youtube-embed') . "</th>\n\t\t<th>" . __('Video Title', 'youtube-embed') . "</th>\n\t\t<th>" . __('Status', 'youtube-embed') . "</th>\n\t</tr>\n</thead>\n<tbody>\n"; $loop = 0; while ($loop < count($id_array)) { // Extract the ID from the provided data $id = trim(vye_extract_id($id_array[$loop])); if ($id != '') { // Validate the video type $type = vye_validate_id($id); if ($type == 'p') { $text = __('This is a playlist', 'youtube-embed'); $status = '-1'; } else { if ($type == '') { $text = __('Invalid video ID', 'youtube-embed'); $status = '-2'; } else { if (strlen($type) != 1) { $text = __('YouTube API error', 'youtube-embed'); $status = '-3'; } else { $text = __('Valid video', 'youtube-embed'); $status = '0'; }