/**
* Generate Download Code
*
* Create code to allow a YouTube video to be downloaded
*
* @package	Artiss-YouTube-Embed
* @since	2.0
*
* @uses		aye_extract_id				Extract an ID from a string
* @uses		aye_validate_id				Confirm the type of video
* @uses		aye_error					Display an error
*
* @param    string	$id					YouTube video ID
* @param 	string	$target				Link target
* @param 	string	$nofollow			Use rel="nofollow" ?
* @param 	string	$text				Text to add link to
* @return	string						URL
*/
function aye_generate_download_code($id)
{
    if ($id == '') {
        return aye_error(__('No YouTube ID was found.', 'youtube-embed'));
    }
    // Extract the ID if a full URL has been specified
    $id = aye_extract_id($id);
    // Check what type of video it is and whether it's valid
    $embed_type = aye_validate_id($id);
    if ($embed_type != 'v') {
        if (strlen($embed_type) > 1) {
            return aye_error($embed_type);
        } else {
            return aye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id));
        }
    }
    // Create the link
    return 'http://deturl.com/www.youtube.com/watch?' . $embed_type . '=' . $id;
}
/**
* Generate video short URL
*
* Create a short URL to a YouTube video
*
* @package	Artiss-YouTube-Embed
* @since	2.0
*
* @uses		aye_extract_id				Extract an ID from a string
* @uses		aye_validate_id				Confirm the type of video
* @uses		aye_error					Display an error
*
* @param    string	$id					YouTube video ID
* @return	string	$youtube_code		Code
*/
function aye_generate_shorturl_code($id)
{
    // Check that an ID has been specified
    if ($id == '') {
        return aye_error(__('No video ID has been supplied', 'youtube-embed'));
    } else {
        // Extract the ID if a full URL has been specified
        $id = aye_extract_id($id);
        // Check what type of video it is and whether it's valid
        $embed_type = aye_validate_id($id);
        if ($embed_type != 'v') {
            if (strlen($embed_type) > 1) {
                return aye_error($embed_type);
            } else {
                return aye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id));
            }
        }
        return 'http://youtu.be/' . $id;
    }
}
示例#3
0
/**
* Get playlist download link
*
* Return YouTube playlist download URL
* No longer found to work, so simply reports an error now
*
* @deprecated	2.0		Use youtube_short_url() instead.
* @since		2.0
*
* @uses		ye_error			Display an error
*
* @param    string  $id		    Video ID
*/
function get_playlist_download($id = '')
{
    echo aye_error(__('This function does not support playlists', 'youtube-embed'));
    return;
}
/**
* Generate Thumbnail Code
*
* Generate XHTML compatible YouTube video thumbnail
*
* @package	Artiss-YouTube-Embed
* @since	2.0
*
* @uses		aye_extract_id				Extract an ID from a string
* @uses		aye_validate_id				Confirm the type of video
* @uses		aye_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 aye_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 = aye_extract_id($id);
    // Check what type of video it is and whether it's valid
    $embed_type = aye_validate_id($id);
    if ($embed_type != 'v') {
        if (strlen($embed_type) > 1) {
            return aye_error($embed_type);
        } else {
            return aye_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 . 'px"';
    }
    if ($height != '') {
        $youtube_code .= ' height="' . $height . 'px"';
    }
    $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		aye_extract_id				Extract the video ID
* @uses		aye_validate_id				Get the name and video type
* @uses		aye_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 = aye_extract_id($id);
    // Check what type of video it is and whether it's valid
    $return = aye_validate_id($id, true);
    $embed_type = $return['type'];
    if (strlen($embed_type) > 1) {
        echo aye_error($embed_type);
    } else {
        echo aye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id));
    }
    // Return the video title
    return $return['title'];
}
/**
* Get YouTube Transcript
*
* Generate re-encoded YouTube transcript
*
* @since	2.0
*
* @uses     aye_extract_id              Extract the ID
* @uses		aye_get_file			    Get a file
* @uses     aye_set_general_defaults    Set default options
* @uses     aye_validate_id             Validate the ID
*
* @param	string	$id			        Video ID
* @return	string	$output		        Transcript output
*/
function aye_generate_transcript($id)
{
    // Extract the ID if a full URL has been specified
    $id = aye_extract_id($id);
    // Check what type of video it is and whether it's valid
    $embed_type = aye_validate_id($id);
    if ($embed_type != 'v') {
        if (strlen($embed_type) > 1) {
            return aye_error($embed_type);
        } else {
            return aye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id));
        }
    }
    // Get general options
    $general = aye_set_general_defaults();
    // Check to see if cache is available
    if ($general['transcript_cache'] != 0) {
        $cache_key = 'aye_transcript_' . $id;
        $output = get_transient($cache_key);
        if ($output !== false) {
            return $output;
        }
    }
    // Get transcript file
    $return = aye_get_file('http://video.google.com/timedtext?lang=en&v=' . $id);
    $xml = $return['file'];
    $output = '';
    // If transcript file exists, strip and output
    if ($return['rc'] == 0) {
        $output = "<!-- YouTube Embed v" . youtube_embed_version . " | http://www.artiss.co.uk/youtube-embed -->\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;
}
/**
* Generate embed code
*
* Generate XHTML compatible YouTube embed code
*
* @since	2.0
*
* @uses		aye_error				    Display an error
* @uses		aye_extract_id			    Get the video ID
* @uses		aye_validate_list		    Get the requested listr
* @uses		aye_validate_id			    Validate the video ID
* @uses		aye_validate_profile		Get the requested profile
* @uses		aye_set_general_defaults	Get general options
* @uses		aye_set_profile_defaults	Set default profile options
*
* @param	string		$id				Video ID
* @param	string		$type			Embed type
* @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		$link			Link back to YouTube
* @param	string		$react			Show EmbedPlus reactions
* @param	string		$stop			Stop in seconds
* @param	string		$sweetspot		Show EmbedPlus sweetspots
* @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		$audio			Only show controls, for audio playback
* @param	string		$template		Display template
* @param	string		$hd				Use HD, if available
* @param	string		$color		 	Progress bar colour
* @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
* @return	string						Code output
*/
function aye_generate_youtube_code($id = '', $type = '', $width = '', $height = '', $fullscreen = '', $related = '', $autoplay = '', $loop = '', $start = '', $info = '', $annotation = '', $cc = '', $style = '', $link = '', $react = '', $stop = '', $sweetspot = '', $disablekb = '', $ratio = '', $autohide = '', $controls = '', $profile = '', $list_style = '', $audio = '', $template = '', $hd = '', $color = '', $theme = '', $https = '', $dynamic = '', $search = '', $user = '')
{
    // Ensure an ID is passed
    if ($id == '') {
        return aye_error(__('No video/playlist ID has been supplied', 'youtube-embed'));
    }
    // Get general options
    $general = aye_set_general_defaults();
    // Find the profile, if one is specified
    $profile = aye_validate_profile($profile, $general['profile_no']);
    // Get default values if no values are supplied
    $options = aye_set_profile_defaults($profile);
    // If a user look-up or search has been requested, mis-out looking up list details and
    // simple assign it as an IFRAME video
    if ($user == 0 && $search == 0) {
        // Check it's not a list
        $playlist_ids = '';
        $list = aye_validate_list($id, $general['list_no']);
        if (!is_array($list)) {
            // Check if certain parameters are included in the URL
            $width = aye_get_url_para($id, 'w', $width);
            $height = aye_get_url_para($id, 'h', $height);
            // Extract the ID if a full URL has been specified
            $id = aye_extract_id($id);
            // Is it being previewed? In which case remove any cache
            if (preg_match('/p=([0-9]*)&preview=true/', $_SERVER['QUERY_STRING']) == 1 && $general['preview'] == 1) {
                delete_transient('aye_type_' . $id);
                delete_transient('aye_title_' . $id);
            }
            // Check what type of video it is and whether it's valid
            $return = aye_validate_id($id, true);
            $embed_type = $return['type'];
            // If the video is invalid, output an appropriate error
            if ($embed_type == '' or strlen($embed_type) != 1) {
                if ($embed_type == '') {
                    $error = sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id);
                } else {
                    $error = $embed_type;
                }
                $result = "\n<!-- YouTube Embed v" . youtube_embed_version . " | http://www.artiss.co.uk/youtube-embed -->\n";
                $result .= "<!-- " . $error . " -->\n" . aye_decode($general['error_message']) . "\n<!-- End of YouTube Embed code -->\n";
                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 = aye_extract_id($list[$loop]);
                        $playlist_ids .= $list_id;
                        $loop++;
                    }
                }
            }
        }
    }
    // Generate a cache key for the above passed parameters
    $cache_key = 'aye_video_' . md5($id . $type . $width . $height . $fullscreen . $related . $autoplay . $loop . $start . $info . $annotation . $cc . $style . $link . $react . $stop . $sweetspot . $disablekb . $ratio . $autohide . $controls . $profile . $list_style . $audio . $template . $hd . $color . $theme . $https . $dynamic . $search . $user . serialize($general) . serialize($options) . serialize($list) . serialize($return));
    // Try and get the output from cache. If it exists, return the code
    if ($general['embed_cache'] != 0 && !is_feed() && $list_style != 'random') {
        $result = get_transient($cache_key);
        if ($result !== false) {
            return $result;
        }
    }
    $metadata = $general['metadata'];
    // 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>\n";
        } 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>\n";
            }
            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>\n";
            }
        }
        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 = aye_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 ($link == '') {
        $link = $options['link'];
    }
    if ($react == '') {
        $react = $options['react'];
    }
    if ($sweetspot == '') {
        $sweetspot = $options['sweetspot'];
    }
    if ($disablekb == '') {
        $disablekb = $options['disablekb'];
    }
    if ($autohide == '') {
        $autohide = $options['autohide'];
    }
    if ($controls == '') {
        $controls = $options['controls'];
    }
    if ($audio == '') {
        $audio = $options['audio'];
    }
    if ($hd == '') {
        $hd = $options['hd'];
    }
    if ($style == '') {
        $style = $options['style'];
    }
    if ($color == '') {
        $color = $options['color'];
    }
    if ($theme == '') {
        $theme = $options['theme'];
    }
    $wmode = $options['wmode'];
    if ($theme == '') {
        $theme = $options['theme'];
    }
    // Build the required template
    if ($template == '') {
        $template = $options['template'];
    } else {
        $template = aye_decode($template);
    }
    if (strpos($template, '%video%') === false) {
        $template = '%video%';
    }
    // If a multi-play list has been specified and EmbedPlus selected, use fallback embedding method instead
    if ($playlist_ids != '' && $type == 'm' && $list_style != 'single') {
        $type = $options['fallback'];
    }
    // 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;
    }
    // If no type was specified, depending on whether this is a video or playlist, set the specific default
    if ($type == '') {
        if ($embed_type == 'v') {
            $type = $options['type'];
        } else {
            $type = $options['playlist'];
        }
    }
    // If a playlist, user or search was specified and this is is Chromeless, switch back to IFRAME to allow
    if (($embed_type == 'p' or $user != 0 or $search != 0) && $type == 'c') {
        $type = 'v';
    }
    // 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 = '';
    if (isset($general['frameborder'])) {
        if ($general['frameborder'] == 1) {
            $frameborder = 'frameborder="0" ';
        }
    }
    // If audio playback option is set, restrict the height to just show the player toolbar
    if ($audio == '1') {
        $height = 27;
    }
    // Set up embed types
    $tab = '';
    $class = 'youtube-player';
    $paras = '';
    $embedplus = false;
    $swf = false;
    $iframe = false;
    $chromeless = false;
    if ($type == 'm' && ($user != 0 or $search != 0)) {
        $type = $options['fallback'];
    }
    if ($type != 'v') {
        if ($type == 'm') {
            $embedplus = true;
            $tab = "\t";
            $embedheight = $height + 32;
            $class = 'cantembedplus';
            $fallback = $options['fallback'];
        } else {
            if ($type == "c") {
                $chromeless = true;
            } else {
                $swf = true;
            }
        }
        $paras .= '&amp;version=3';
    } else {
        $iframe = true;
    }
    // Generate parameters to add to URL
    if ($options['modest'] == 1) {
        $paras .= '&amp;modestbranding=1';
    }
    if ($fullscreen == 1) {
        $paras .= '&amp;fs=1';
    } else {
        $paras .= '&amp;fs=0';
    }
    if ($related != 1) {
        $paras .= '&amp;rel=0';
    }
    if ($autoplay == 1) {
        $paras .= '&amp;autoplay=1';
        $paras_ep .= '&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 == 1) {
        $paras .= '&amp;cc_load_policy=1';
    }
    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 not a playlist, add the playlist parameter
    if ($playlist_ids != '') {
        $paras .= '&amp;playlist=' . $playlist_ids;
    }
    // Generate EmbedPlus parameters
    $paras_ep = '&amp;width=' . $width . '&amp;height=' . $height;
    if ($react != 1) {
        $paras_ep .= '&amp;react=0';
    }
    if ($sweetspot != 1) {
        $paras_ep .= '&amp;sweetspot=0';
    }
    if ($hd == 1) {
        $paras_ep .= '&amp;hd=1';
    }
    // Add start & stop parameters
    if ($start != 0) {
        $paras .= '&amp;start=' . $start;
        $paras_ep .= '&amp;start=' . $start;
    }
    if ($stop != 0) {
        $paras_ep .= '&amp;stop=' . $stop;
        $paras .= '&amp;end=' . $stop;
    }
    // Generate DIVs to wrap around video
    if ($dynamic == 1) {
        $result = "<div class=\"ye-container\">\n";
        if ($fixed == 1) {
            $result = '<div style="width: ' . $width . 'px; max-width: 100%">' . "\n" . $result;
        }
    }
    // Add EmbedPlus code
    if ($embedplus) {
        $result .= "<object type=\"application/x-shockwave-flash\" width=\"" . $width . "\" height=\"" . $embedheight . "\" data=\"http://getembedplus.com/embedplus.swf\" style=\"" . $style . "\" id=\"" . uniqid('ep_', true) . "\" >\n";
        $result .= "\t<param value=\"http://getembedplus.com/embedplus.swf\" name=\"movie\" />\n";
        $result .= "\t<param value=\"high\" name=\"quality\" />\n";
        $result .= "\t<param value=\"" . $wmode . "\" name=\"wmode\" />\n";
        $result .= "\t<param value=\"always\" name=\"allowscriptaccess\" />\n";
        if ($fullscreen == 1) {
            $result .= "\t<param name=\"allowFullScreen\" value=\"true\" />\n";
        }
        $result .= "\t<param name=\"flashvars\" value=\"ytid=" . $id . $paras_ep . "\" />\n";
    }
    // Work out, depending on privacy settings, the main address to use
    $privacy = $general['privacy'];
    if ($privacy == 2) {
        $do_not_track = aye_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
    if ($chromeless) {
        $embed_url = 'http' . $https . '://www.youtube.com/apiplayer';
        $id_paras = '?video_id=' . $id;
    } else {
        $embed_url = 'http' . $https . '://www.' . $url_privacy . '/';
        if ($type == 'v') {
            $embed_url .= 'embed';
        } else {
            $embed_url .= 'v/';
        }
        $id_paras = $id;
        if ($type == 'v') {
            $id_paras = '/' . $id_paras;
        }
    }
    // 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 = '';
        if ($type == 'p') {
            $id_paras .= 'videoseries';
        }
        $id_paras .= '?listType=' . $list_type . '&amp;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, '?') && substr($paras, 0, 5) == '&amp;') {
        $paras = '?' . substr($paras, 5);
    }
    $embed_url .= $paras;
    // Add AS3 YouTube embed code
    if ($swf or $chromeless or $embedplus && ($fallback == 'o' or $fallback == 'p')) {
        $result .= $tab . "<object class=\"" . $class . "\" type=\"application/x-shockwave-flash\" data=\"" . $embed_url . "\" width=\"" . $width . "\" height=\"" . $height . "\" style=\"" . $style . "\"";
        if ($metadata != 0) {
            $result .= " rel=\"media:video\" resource=\"http" . $https . "://www.youtube.com/" . $embed_type . "/" . $id . "\" xmlns:media=\"http://search.yahoo.com/searchmonkey/media/\"";
        }
        $result .= " >\n";
        if ($metadata != 0) {
            $result .= $tab . "\t<a rel=\"media:thumbnail\" href=\"http://img.youtube.com/vi/" . $id . "/default.jpg\" /></a>\n";
        }
        $result .= $tab . "\t<param name=\"movie\" value=\"" . $embed_url . "\" />\n";
        $result .= $tab . "\t<param name=\"wmode\" value=\"" . $wmode . "\" />\n";
        if ($fullscreen == 1) {
            $result .= $tab . "\t<param name=\"allowFullScreen\" value=\"true\" />\n";
        }
        if ($link != 1 && $link != '') {
            $result .= $tab . "\t<param name=\"allowNetworking\" value=\"internal\" />\n";
        }
        if ($metadata != 0 && $return['title'] != '') {
            $result .= $tab . "\t<span property=\"media:title\" content=\"" . htmlentities($return['title']) . "\" />\n";
        }
        $result .= $tab . "</object>\n";
    }
    // Add IFRAME embed code
    if ($iframe or $embedplus && $fallback == "v") {
        if ($embed_type == "p") {
            $playlist_para = "p/";
        } else {
            $playlist_para = '';
        }
        $result .= $tab . '<iframe ' . $frameborder . 'style="border: 0;' . $style . '" class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . $embed_url . '&amp;wmode=' . $wmode . '"';
        if ($fullscreen == 1) {
            $result .= ' allowfullscreen="allowfullscreen"';
        }
        $result .= " ></iframe>\n";
    }
    // If using EmbedPlus, add the OBJECT closure tag
    if ($embedplus) {
        $result .= "</object>\n<!--[if lte IE 6]> <style type=\"text/css\">.cantembedplus{display:none;}</style><![endif]-->\n";
    }
    // Now apply the template to the result
    $end_tag = '';
    if ($dynamic == 1) {
        $end_tag .= "</div>\n";
        if ($fixed == 1) {
            $end_tag .= "</div>\n";
        }
    }
    $result = str_replace('%video%', $result . $end_tag, $template);
    // Now add a commented header and trailer
    $result = "\n<!-- YouTube Embed v" . youtube_embed_version . " | http://www.artiss.co.uk/youtube-embed -->\n" . $result;
    $result .= "<!-- End of YouTube Embed code -->\n";
    // Cache the output
    if ($general['embed_cache'] != 0) {
        set_transient($cache_key, $result, 3600 * $general['embed_cache']);
    }
    return $result;
}
示例#8
0
/**
* Video Name Shortcode
*
* Shortcode to return the name of a YouTube video
*
* @since	2.0
*
* @uses		aye_extract_id				Extract the video ID
* @uses		aye_validate_id				Get the name and video type
* @uses		aye_error					Return an error
*
* @param    string		$paras			Shortcode parameters
* @param	string		$content		Shortcode content
* @return   string						Video name
*/
function aye_video_name_shortcode($paras = '', $content = '')
{
    // Extract the ID if a full URL has been specified
    $id = aye_extract_id($content);
    // Check what type of video it is and whether it's valid
    $return = aye_validate_id($id, true);
    if (!$return['type']) {
        return aye_error(sprintf(__('The YouTube ID of %s is invalid.', 'youtube-embed'), $id));
    }
    if (strlen($return['type']) != 1) {
        return aye_error($return['type']);
    }
    // Return the video title
    return do_shortcode($return['title']);
}