/** * Set up TinyMCE button * * Add filters (assuming user is editing) for TinyMCE * * @uses vye_set_general_defaults Set default options * * @since 2.0 */ function youtube_embed_button() { // Ensure user is in rich editor and button option is switched on if (get_user_option('rich_editing') == 'true') { $options = vye_set_general_defaults(); if ($options['editor_button'] != '') { // Ensure shortcode cookie is set $editor_sc = vye_set_editor_sc(); // Add filters add_filter('mce_external_plugins', 'add_youtube_embed_mce_plugin'); add_filter('mce_buttons', 'register_youtube_embed_button'); } } }
/** * Add option to Admin Bar * * Add link to YouTube Embed profile options to Admin Bar. * With help from http://technerdia.com/1140_wordpress-admin-bar.html * * @uses vye_set_general_default Set default options * * @since 2.5 */ function vye_admin_bar_render($meta = TRUE) { $options = vye_set_general_defaults(); if ($options['admin_bar'] != '') { global $wp_admin_bar; if (!is_user_logged_in()) { return; } if (!is_admin_bar_showing()) { return; } if (!current_user_can($options['menu_access'])) { return; } $wp_admin_bar->add_menu(array('id' => 'aye-menu', 'title' => __('YouTube Embed', 'youtube-embed'))); $wp_admin_bar->add_menu(array('parent' => 'aye-menu', 'id' => 'aye-options', 'title' => __('Options', 'youtube-embed'), 'href' => admin_url('admin.php?page=general-options'), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'aye-menu', 'id' => 'aye-profile', 'title' => __('Profiles', 'youtube-embed'), 'href' => admin_url('admin.php?page=profile-options'), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'aye-menu', 'id' => 'aye-lists', 'title' => __('Lists', 'youtube-embed'), 'href' => admin_url('admin.php?page=list-options'), 'meta' => array('target' => '_blank'))); } }
/** * Show Admin Messages * * Display messages on the administration screen * * @since 4.1 * */ function youtube_embed_admin_messages() { $shortcode_site = get_option('youtube_embed_shortcode_site'); $shortcode_admin = get_option('youtube_embed_shortcode_admin'); if ($shortcode_admin != 0 or $shortcode_site != 0) { $options = vye_set_general_defaults(); if ($options['prompt'] == 1) { if ($shortcode_site == 3) { $message = __('For some reason the shortcode <strong>[youtube]</strong> is not working on the main site'); } $alternative = __('An alternative plugin is using the <strong>[youtube]</strong> shortcode'); if ($shortcode_admin == 1 or $shortcode_site == 1) { $message = $alternative; } if ($shortcode_admin == 2 or $shortcode_site == 2) { $message = __($alternative . ', possibly the <a href="admin.php?page=jetpack_modules&activated=true">Shortcode Embeds module</a> in Jetpack'); } echo '<div class="error notice"><p>YouTube Embed: ' . $message . '.</p></div>'; } } }
<?php // Set default options $default = array('titles' => 'YouTube', 'id' => '', 'profile' => '', 'type' => '', 'template' => '', 'style' => '', 'start' => '', 'autoplay' => '', 'width' => '', 'height' => '', 'dynamic' => '', 'list' => '', 'loop' => '', 'stop' => '', 'id_type' => 'v'); $instance = wp_parse_args((array) $instance, $default); $general = vye_set_general_defaults(); // Widget Title field $field_id = $this->get_field_id('titles'); $field_name = $this->get_field_name('titles'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Widget Title', 'youtube-embed') . ': </label><input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . attribute_escape($instance['titles']) . '" /></p>'; // Video ID field $field_id = $this->get_field_id('id'); $field_name = $this->get_field_name('id'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Video ID', 'youtube-embed') . ': </label><input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . attribute_escape($instance['id']) . '" /></p>'; echo "<table>\n"; // ID Type $field_id = $this->get_field_id('id_type'); $field_name = $this->get_field_name('id_type'); echo "\r\n" . '<tr><td width="100%">' . __('ID Type', 'youtube-embed') . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value="v"'; if (attribute_escape($instance['id_type']) == 'v') { echo " selected='selected'"; } echo '>' . __('Video or Playlist', 'youtube-embed') . '</option><option value="s"'; if (attribute_escape($instance['id_type']) == 's') { echo " selected='selected'"; } echo '>' . __('Search', 'youtube-embed') . '</option><option value="u"'; if (attribute_escape($instance['id_type']) == 'u') { echo " selected='selected'"; } echo '>' . __('User', 'youtube-embed') . '</option></select></td></tr>';
/** * Widget Admin control form * * Define admin file * * @since 2.0 * * @param string $instance Instance */ function form($instance) { // Set default options $default = array('titles' => 'YouTube', 'id' => '', 'profile' => '', 'start' => '', 'list' => '', 'stop' => '', 'id_type' => 'v'); $instance = wp_parse_args((array) $instance, $default); $general = vye_set_general_defaults(); // Widget Title field $field_id = $this->get_field_id('titles'); $field_name = $this->get_field_name('titles'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Widget Title', 'youtube-embed') . ': </label><input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . attribute_escape($instance['titles']) . '" /></p>'; // Video ID field $field_id = $this->get_field_id('id'); $field_name = $this->get_field_name('id'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Video ID', 'youtube-embed') . ': </label><input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . attribute_escape($instance['id']) . '" /></p>'; // ID Type echo "<table>\n"; $field_id = $this->get_field_id('id_type'); $field_name = $this->get_field_name('id_type'); echo "\r\n" . '<tr><td width="100%">' . __('ID Type', 'youtube-embed') . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value="v"'; if (attribute_escape($instance['id_type']) == 'v') { echo " selected='selected'"; } echo '>' . __('Video or Playlist', 'youtube-embed') . '</option><option value="s"'; if (attribute_escape($instance['id_type']) == 's') { echo " selected='selected'"; } echo '>' . __('Search', 'youtube-embed') . '</option><option value="u"'; if (attribute_escape($instance['id_type']) == 'u') { echo " selected='selected'"; } echo '>' . __('User', 'youtube-embed') . '</option></select></td></tr>'; echo "</table>\n"; // Profile field $field_id = $this->get_field_id('profile'); $field_name = $this->get_field_name('profile'); echo "\r\n" . '<p><label for="' . $field_id . '">' . __('Profile', 'youtube-embed') . ': </label><select name="' . $field_name . '" class="widefat" id="' . $field_id . '">'; vye_generate_profile_list(attribute_escape($instance['profile']), $general['profile_no']); echo '</select></p>'; echo "<table>\n"; // Start field $field_id = $this->get_field_id('start'); $field_name = $this->get_field_name('start'); echo "\r\n" . '<tr><td width="100%">' . __('Start (seconds)', 'youtube-embed') . '</td><td><input type="text" size="3" maxlength="3" id="' . $field_id . '" name="' . $field_name . '" value="' . attribute_escape($instance['start']) . '" /></td></tr>'; // Stop field $field_id = $this->get_field_id('stop'); $field_name = $this->get_field_name('stop'); echo "\r\n" . '<tr><td width="100%">' . __('Stop (seconds)', 'youtube-embed') . '</td><td><input type="text" size="3" maxlength="3" id="' . $field_id . '" name="' . $field_name . '" value="' . attribute_escape($instance['stop']) . '" /></td></tr>'; echo "</table><table>\n"; // List field $field_id = $this->get_field_id('list'); $field_name = $this->get_field_name('list'); echo "\r\n" . '<tr><td width="100%">' . __('List Playback', 'youtube-embed') . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value=""'; if (attribute_escape($instance['list']) == '') { echo " selected='selected'"; } echo '>' . __('Profile default', 'youtube-embed') . '</option><option value="order"'; if (attribute_escape($instance['list']) == 'order') { echo " selected='selected'"; } echo '>' . __('Play each video in order', 'youtube-embed') . '</option><option value="random"'; if (attribute_escape($instance['list']) == 'random') { echo " selected='selected'"; } echo '>' . __('Play videos randomly', 'youtube-embed') . '</option><option value="single"'; if (attribute_escape($instance['list']) == 'single') { echo " selected='selected'"; } echo '>' . __('Play one random video', 'youtube-embed') . '</option></select></td></tr>'; echo "</table>\n"; }
/** * Video shortcode * * Use shortcode parameters to embed a YouTube video or playlist * * @since 2.0 * * @uses vye_get_embed_type Get the embed type * @uses vye_set_autohide Get the autohide parameter * @uses vye_set_general_defaults Set default options * @uses vye_generate_youtube_code Generate the embed code * * @param string $paras Shortcode parameters * @param string $content Shortcode content * @param string $alt_shortcode The number of the alternative shortcode used * @return string YouTube embed code */ function vye_video_shortcode($paras = '', $content = '', $callback = '', $alt_shortcode = false) { extract(shortcode_atts(array('width' => '', 'height' => '', 'fullscreen' => '', 'related' => '', 'autoplay' => '', 'loop' => '', 'start' => '', 'info' => '', 'annotation' => '', 'cc' => '', 'style' => '', 'stop' => '', 'disablekb' => '', 'ratio' => '', 'autohide' => '', 'controls' => '', 'profile' => '', 'id' => '', 'url' => '', 'rel' => '', 'fs' => '', 'cc_load_policy' => '', 'iv_load_policy' => '', 'showinfo' => '', 'youtubeurl' => '', 'template' => '', 'list' => '', 'color' => '', 'theme' => '', 'ssl' => '', 'height' => '', 'width' => '', 'dynamic' => '', 'h' => '', 'w' => '', 'search' => '', 'user' => '', 'modest' => '', 'playsinline' => '', 'html5' => ''), $paras)); // If no profile specified and an alternative shortcode used, get that shortcodes default profile if ($profile == '' && $alt_shortcode) { // Get general options $options = vye_set_general_defaults(); $profile = $options['alt_profile']; } // If an alternative field is set, use it if ($id != '' && $content == '') { $content = $id; } if ($url != '' && $content == '') { $content = $url; } if ($youtubeurl != '' && $content == '') { $content = $youtubeurl; } if ($h != '' && $height == '') { $height = $h; } if ($w != '' && $width == '') { $width = $w; } if ($rel != '' && $related == '') { $related = $rel; } if ($fs != '' && $fullscreen == '') { $fullscreen = $fs; } if ($cc_load_policy != '' && $cc == '') { $cc = $cc_load_policy; } if ($iv_load_policy != '' && $annotation == '') { $annotation = $iv_load_policy; } if ($showinfo != '' && $info == '') { $info = $showinfo; } // If ID was not passed in the content and the first parameter is set, assume that to be the ID if ($content == '' && $paras[0] != '') { $content = $paras[0]; if (substr($content, 0, 1) == ":" or substr($content, 0, 1) == "=") { $content = substr($content, 1); } if (array_key_exists(1, $paras)) { if ($paras[1] != '') { $width = $paras[1]; } } if (array_key_exists(2, $paras)) { if ($paras[2] != '') { $height = $paras[2]; } } } // Set up Autohide parameter $autohide = vye_set_autohide($autohide); // Create YouTube code $youtube_code = vye_generate_youtube_code($content, $width, $height, vye_convert($fullscreen), vye_convert($related), vye_convert($autoplay), vye_convert($loop), $start, vye_convert($info), vye_convert_3($annotation), vye_convert($cc), $style, $stop, vye_convert($disablekb), $ratio, $autohide, $controls, $profile, $list, $template, $color, $theme, vye_convert($ssl), vye_convert($dynamic), vye_convert($search), vye_convert($user), vye_convert($modest), vye_convert($playsinline), vye_convert($html5)); return apply_filters('a3_lazy_load_html', do_shortcode($youtube_code)); }
/** * Add to site header * * Perform main site head processing * * @uses youtube_embed_head_checks Perform the actual checks * * @since 4.1 */ function youtube_embed_add_to_head() { youtube_embed_shortcode_checks('site'); $options = vye_set_general_defaults(); if ($options['script'] == 'f') { $tab = "\t"; $newline = "\n"; echo '<script type="text/javascript" src="' . plugins_url() . '/youtube-embed/js/jquery.fitvids.js"></script>' . $newline; echo '<script>' . $newline; echo $tab . '$(".youtube-embed").fitVids();' . $newline; echo '</script>' . $newline; } if ($options['script'] == 'i') { wp_enqueue_script('youtube-embed-iframe-resizer', plugins_url() . '/youtube-embed/js/iframeResizer.min.js'); } }
/** * Filter comments * * Filter comments and add YouTube embeds * * @since 2.0 * * @uses vye_set_general_defaults Get the general defaults * @uses vye_generate_youtube_code Generate the YouTube embed code * * @param string $content The comments content * @return string Content to return */ function vye_filter_comments($content) { $options = vye_set_general_defaults(); if ($options['comments'] == 1) { $identifier = 'http://www.youtube.com/watch?v='; $search_pos = 0; $search = strpos($content, $identifier, $search_pos); while ($search !== false) { $prefix = substr($content, $search - 1, 1); if ($prefix != ']' && $prefix != '"' && $prefix != "'") { // Check if link around video. If so, work out how much more needs stripping out $anchor_start = 0; $anchor_end = 0; if ($prefix == ">") { $anchor_pos = strrpos(substr($content, 0, $search), '<a'); if ($anchor_pos !== false) { $anchor_start = $search - $anchor_pos; $anchor_end = strpos(substr($content, $search), '</a>') - strlen($identifier) - 11; } } // Work out video ID and generate code $id = substr($content, $search + strlen($identifier), 11); $code = vye_generate_youtube_code($id, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', $options['comments_profile'], '', ''); // Now replace the URL with the resultant code $first_section = $search - 1 - $anchor_start; if ($first_section < 1) { $content = $code . substr($content, $search + strlen($identifier) + 11 + $anchor_end); } else { $content = substr($content, 0, $first_section) . $code . substr($content, $search + strlen($identifier) + 11 + $anchor_end); } $search_pos = $search + strlen($code) - $anchor_start; } else { $search_pos = $search + strlen($identifier) + 11; } $search = strpos($content, $identifier, $search_pos - 1); } } 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; }
update_option('youtube_embed_general', $options); $update_message = __('Settings Saved.', 'youtube-embed'); // Update the alternative shortcodes $shortcode = $_POST['youtube_embed_shortcode']; $shortcode = trim($shortcode, '[]'); update_option('youtube_embed_shortcode', $shortcode); // If the option to clear the cache has been ticked run an SQL to clear them down if (!empty($_POST['youtube_embed_clear_cache'])) { global $wpdb; $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%ye_video_%' OR option_name LIKE '_transient_%ye_type_%' OR option_name LIKE '_transient_%ye_title_%' OR option_name LIKE '_transient_%vye_comments_%'"); $update_message .= ' ' . __('Cache cleared.', 'youtube-embed'); } echo '<div class="updated fade"><p><strong>' . $update_message . "</strong></p></div>\n"; } // Get options $options = vye_set_general_defaults(); $shortcode = vye_set_shortcode_option(); ?> <p><?php _e('These are the general settings for YouTube Embed. Please select <a href="admin.php?page=ye-profile-options">Profiles</a> for default embedding settings.', 'youtube-embed'); ?> </p> <form method="post" action="<?php echo get_bloginfo('wpurl') . '/wp-admin/admin.php?page=ye-general-options'; ?> "> <h3 class="title"><?php _e('Embedding', 'youtube-embed');