__construct(); } function __construct() { $this->local_version = '3.8.9'; // TODO: Change this number??? $this->custom_colors = array( 'blank' => array('d6d6d6', 'f0f0f0'), 'storm' => array('3a3a3a', '999999'), 'iceberg' => array('2b405b', '6b8ab6'), 'acid' => array('006699', '54abd6'), 'green' => array('21.2.0', '4e9e00'), 'orange' => array('e1600f', 'febd01'), 'pink' => array('cc2550', 'e87a9f'), 'purple' => array('402061', '9461ca'), 'rubyred' => array('5d1719', 'cd311b'), ); $this->plugin_url = defined('WP_PLUGIN_URL') ? trailingslashit(WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__))) : trailingslashit(get_bloginfo('wpurl')) . PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)); $this->key = 'add_youtube'; $this->options=$this->get_options(); $this->add_filters_and_hooks(); } function add_filters_and_hooks() { if ($this->options['posts'] == 'on') { add_filter('the_content', array($this, 'check'), 100); add_filter('the_excerpt', array($this, 'check'), 100); } if ($this->options['comments'] == 'on') { add_filter('comment_text', array($this, 'check'), 100); } add_action( 'plugins_loaded', array($this, 'install')); add_action( 'after_plugin_row', array($this, 'check_plugin_version')); add_action('admin_menu', array($this, 'add_menu_items')); register_activation_hook(__FILE__, array($this, 'install')); } function add_menu_items() { add_options_page('Add YouTube options', 'Add YouTube', 8, __FILE__, array($this, 'options_page')); } function options_page() { /* $status = $this->get_info(); $the_version = $status[1]; $the_message = $status[3]; if ((version_compare(strval($the_version), strval($this->local_version), '>') == 1)) { $msg = 'Latest version available '.' '.$the_version.'
'.$the_message; _e('

' . $msg . '

'); } */ // If form was submitted if (isset($_POST['submitted'])) { check_admin_referer('add-youtube'); #---------------------------------------------------------------------# $this->options['img'] = !isset($_POST['disp_img']) ? 'off' : 'on'; $this->options['link'] = !isset($_POST['disp_link']) ? 'off' : 'on'; $this->options['valid'] = !isset($_POST['valid']) ? 'off' : 'on'; $this->options['search'] = !isset($_POST['disp_search']) ? 'off' : 'on'; $this->options['ann'] = !isset($_POST['disp_ann']) ? 'off' : 'on'; $this->options['info'] = !isset($_POST['disp_info']) ? 'off' : 'on'; $this->options['width'] = !isset($_POST['disp_width']) ? 425 : intval($_POST['disp_width']); $this->options['height'] = !isset($_POST['disp_height']) ? 344 : intval($_POST['disp_height']); $this->options['widthhq'] = !isset($_POST['disp_widthhq']) ? 480 : intval($_POST['disp_widthhq']); $this->options['heighthq'] = !isset($_POST['disp_heighthq']) ? 295 : intval($_POST['disp_heighthq']); $this->options['widthside'] = !isset($_POST['disp_widthside']) ? 150 : intval($_POST['disp_widthside']); $this->options['heightside'] = !isset($_POST['disp_heightside']) ? 125 : intval($_POST['disp_heightside']); $this->options['rel'] = !isset($_POST['embedRel']) ? 1 : $_POST['embedRel']; $this->options['border'] = !isset($_POST['embedBorder']) ? 0 : 1; $this->options['color'] = !isset($_POST['embedColor']) ? 'blank' : $_POST['embedColor']; $this->options['autoplay'] = !isset($_POST['autoplay']) ? 0 : 1; $this->options['loop'] = !isset($_POST['loop']) ? 0 : 1; $this->options['privacy'] = !isset($_POST['disp_privacy']) ? 0 : 1; $this->options['posts'] = !isset($_POST['disp_posts']) ? 'off' : 'on'; $this->options['comments'] = !isset($_POST['disp_comments']) ? 'off' : 'on'; $this->options['iframe'] = !isset($_POST['iframe']) ? 'off' : 'on'; $this->options['template'] = !isset($_POST['disp_template']) ? '{video}' : stripslashes(htmlspecialchars($_POST['disp_template']));; $this->options['tag'] = !isset($_POST['tag']) ? '' : $_POST['tag']; $this->options['dark_player'] = ! isset( $_POST['dark_player'] ) ? 'off' : 'on'; $this->options['logoless'] = ! isset( $_POST['logoless'] ) ? 'off' : 'on'; update_option($this->key, $this->options); $msg_status = 'Add YouTube options saved.'; // Show message _e('

' . $msg_status . '

'); } $disp_img = $this->options['img'] == 'on' ? 'checked="checked"' : ''; $disp_link = $this->options['link'] == 'on' ? 'checked="checked"' : ''; $disp_search = $this->options['search'] == 'on' ? 'checked="checked"' : ''; $disp_ann = $this->options['ann'] == 'on' ? 'checked="checked"' : ''; $disp_info = $this->options['info'] == 'on' ? 'checked="checked"' : ''; $valid = $this->options['valid'] == 'on' ? 'checked="checked"' : ''; $disp_width = $this->options['width']; $disp_height = $this->options['height']; $disp_widthhq = $this->options['widthhq']; $disp_heighthq = $this->options['heighthq']; $disp_widthside = $this->options['widthside']; $disp_heightside = $this->options['heightside']; $disp_autoplay = $this->options['autoplay'] ? 'checked="checked"' : ''; $disp_loop = $this->options['loop'] ? 'checked="checked"' : ''; $disp_rel = $this->options['rel'] ? 'checked="checked"' : ''; $disp_rel2 = $this->options['rel'] ? '' : 'checked="checked"'; $disp_border = $this->options['border'] ? 'checked="checked"' : ''; $disp_color = $this->options['color']; $disp_posts = $this->options['posts'] == 'on' ? 'checked="checked"' : '' ; $disp_comments = $this->options['comments'] == 'on' ? 'checked="checked"' : ''; $disp_privacy = $this->options['privacy'] ? 'checked="checked"' : ''; $iframe = $this->options['iframe'] =='on' ? 'checked="checked"' : ''; $disp_template = wp_specialchars($this->options['template']); $tag = $this->options['tag']; $dark_player = $this->options['dark_player'] == 'on' ? 'checked="checked"' : ''; $logoless = $this->options['logoless'] == 'on' ? 'checked="checked"' : ''; if (!$disp_width) { $disp_width = 425; } if (!$disp_height) { $disp_height = 344; } global $wp_version; $embed_img = $this->plugin_url . '/img/embed_selection-vfl29294.png'; echo ' '; $imgpath = $this->plugin_url.'/i'; $actionurl = $_SERVER['REQUEST_URI']; $nonce = wp_create_nonce( 'add-youtube'); $example = htmlentities('
{video}
'); // Configuration Page echo <<

Add YouTube

Usage [view instructions]

Options

You can adjust the way your embeded youtube videos behave in the options below.

Video settings


Video Appearence

Video template. Default is just {video}.
You can try $example if you want the text to wrap around video.

Video width and height in normal mode (httpv://). Default is 425x344.

x

Video width and height in high quality mode (httpvh://). Default is 480x295.

x

Video width and height in sidebar mode (regardless of quality). Default is 150x125.

x












Custom code compatibility

Use this option if you have used another youtube plugin and switched over to Add YouTube.

For example if you used [yt]qYWWBwf2wHE[/yt] type of code, you would type yt in the box below.

xHTML validation

Enabling the option below will change default YouTube code to be xHTML valid. (videos may not work for Iphone users)

RSS feed options

Some RSS feed readers like Bloglines will show embeded YouTube videos. Some will not and Add YouTube allows you to display a video link and a video screenshot instead.

Add YouTube will always embed the video but it can not know if the reader supports embeded video or not. So use these additional options at your own likening.


Another fine WordPress plugin by EscalateSEO
END; } /** * Looks for Add YouTube URL(s) in the post content * and replace them with proper HTML tags * * @param mixed $the_content * @param mixed $side * @return mixed */ function check($the_content, $side = 0) { if (strpos($the_content, "httpv") !== false ) { $char_codes = array('×', '–'); $replacements = array("x", "--"); $the_content = str_replace($char_codes, $replacements, $the_content); preg_match_all("/http(v|vh|vhd):\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $the_content, $matches['youtube.com'], PREG_SET_ORDER); preg_match_all("/http(v|vh|vhd):\/\/([a-zA-Z0-9\-\_]+\.|)youtu\.be\/([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $the_content, $matches['youtu.be'], PREG_SET_ORDER); if (isset($matches['youtube.com'])) foreach ($matches['youtube.com'] as $match) { $the_content = preg_replace("/http".$match[1].":\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^\s<]*)/", $this->tag($match[4], $match[1], $match[5], $side), $the_content, 1); } if (isset($matches['youtu.be'])) { foreach ($matches['youtu.be'] as $match) { $the_content = preg_replace("/http".$match[1].":\/\/([a-zA-Z0-9\-\_]+\.|)youtu\.be\/([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $this->tag($match[3], $match[1], $match[4], $side), $the_content, 1); } } preg_match_all("/http(vp|vhp):\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/view_play_list(\?p\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{16})([^<\s]*)/", $the_content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $the_content = preg_replace("/http".$match[1].":\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/view_play_list(\?p\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{16})([^\s<]*)/", $this->tag($match[4], $match[1], $match[5], $side), $the_content, 1); } } // to work with migrated blogs from Wordpress.com replacing [youtube=youtubeadresss] if (strpos($the_content, "[youtube") !== false ) { preg_match_all("/\[youtube\=http:\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^<\s]*)\]/", $the_content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $the_content = preg_replace("/\[youtube\=http:\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^\s<]*)\]/", $this->tag($match[3], '', $match[4], $side), $the_content, 1); } } $tag=$this->options['tag']; if ($tag!='' && strpos($the_content, "[".$tag."]") !== false ) { preg_match_all("/\[$tag\]([a-zA-Z0-9\-\_]{11})([^<\s]*)\[\/$tag\]/", $the_content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { //print_r($matches); $the_content = preg_replace("/\[$tag\]([a-zA-Z0-9\-\_]{11})([^<\s]*)\[\/$tag\]/", $this->tag($match[1], '', '', $side), $the_content, 1); } } return $the_content; } function tag($file, $high = 'v', $time = '', $side = 0) { $playlist = 0; $disp_rel = $this->options['rel']; $disp_border = $this->options['border']; $disp_color = $this->options['color']; $autoplay = $this->options['autoplay']; $loop = $this->options['loop']; $disp_search = $this->options['search'] == 'on' ? 1 : 0; $disp_info = $this->options['info'] == 'on' ? '&showinfo=0' : ''; $disp_ann = $this->options['ann'] == 'on' ? '&iv_load_policy=3' : ''; $template = trim($this->options['template']) == '' ? '{video}' : $this->options['template']; $valid = $this->options['valid']; $dark_player = ( $this->options['dark_player'] == 'on' ) ? '&theme=dark' : ''; $logoless = $this->options['logoless']; switch ($high) { case 'v': $high = ''; break; case 'vh': $high = '&hd=1'; break; case 'vhd': $high = '&hd=1'; break; case 'vp': $high = ''; $playlist = 1; break; case 'vhp': $high = '&hd=1'; $playlist = 1; break; default: $high = ''; break; } $width = $side ? $this->options['widthside'] : ($high ? $this->options['widthhq'] : $this->options['width']); $height = $side ? $this->options['heightside'] : ($high ? $this->options['heighthq'] : $this->options['height']); if (!$width) { $width = !$high ? 480 : 425 ; } if (!$height) { $height = !$high ? 360 : 344; } if ($disp_border) { $height += 18; } if ( $logoless = 'on' ) { $ll = '&modestbranding=1'; } else { $ll = ''; } if ($autoplay) $ap='&autoplay=1'; $root_url = $this->options['privacy'] ? 'http://www.youtube-nocookie.com' : 'http://www.youtube.com'; if ($this->options['iframe']=='on') $video_url = htmlspecialchars("$root_url/embed/$file?color1={$this->custom_colors[$disp_color][0]}&color2={$this->custom_colors[$disp_color][1]}&border=$disp_border&fs=1&hl=en$ap$ll&loop=$loop{$disp_info}$disp_ann&showsearch=$disp_search&rel=$disp_rel$dark_player", ENT_QUOTES) . $high . $time; else $video_url = htmlspecialchars("$root_url/v/$file?color1={$this->custom_colors[$disp_color][0]}&color2={$this->custom_colors[$disp_color][1]}&border=$disp_border&fs=1&hl=en$ap$ll&loop=$loop{$disp_info}$disp_ann&showsearch=$disp_search&rel=$disp_rel$dark_player", ENT_QUOTES) . $high . $time; if ($playlist) { $video_url = htmlspecialchars("$root_url/p/$file?color1={$this->custom_colors[$disp_color][0]}&color2={$this->custom_colors[$disp_color][1]}&border=$disp_border&fs=1&hl=en$ap$ll&loop={$disp_info}$disp_ann&showsearch=$disp_search&rel=$disp_rel$dark_player", ENT_QUOTES) . $high . $time; if ($this->options['iframe']=='on') $yte_tag = << EOT; else $yte_tag = << EOT; } elseif ($valid == 'off' || strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')===TRUE || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod')===TRUE || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')===TRUE) { if ($this->options['iframe']=='on') $yte_tag = << EOT; else $yte_tag = << EOT; } else { if ($this->options['iframe']=='on') $yte_tag = << EOT; else $yte_tag = << EOT; } if (is_feed()) { if ($high) { $high = '&fmt=18'; } if ($playlist) $url='http://www.youtube.com/view_play_list?p='; else $url='http://www.youtube.com/watch?v='; if ($this->options['img'] == 'on') { $yte_tag .= '

'; } if ($this->options['link'] == 'on') { $yte_tag.='

www.youtube.com/watch?v=' . $file . '

'; } // if ($this->options['link'] == 'off' && $this->options['img'] == 'off') // $yte_tag='http://www.youtube.com/watch?v='.$file; } return str_replace('{video}', $yte_tag, html_entity_decode($template)); } function wp_footer() { echo '
seo seo consulting escalateseo seo basics seo tools seo tips seo tutorial seo services google seo seo software seo forum
'; } function install() { // register widget if (function_exists('register_sidebar_widget')) { register_sidebar_widget('Add YouTube', array($this, 'widget')); } if (function_exists('register_widget_control')) { register_widget_control('Add YouTube', array($this, 'widget_control')); } if (get_option($this->key)) { $this->options=$this->get_options(); } /* // upgrade the options format (as all-in-one, not single entries) $this->options = array( 'posts' => 'on', 'comments' => 'off', 'img' => 'off', 'width' => 425, 'height' => 344, 'widthhq' => 480, 'heighthq' => 295, 'widthside' => 150, 'heightside' => 125, 'rel' => 1, 'color' => 'blank', 'border' => 0, 'link' => 'on', 'valid' => 'off', 'search' => 'off', 'info' => 'on', 'ann' => 'on', 'template' => '{video}', 'autoplay' => 0, 'privacy' => 0, 'wtext' => '', 'wtitle' => '', 'tag' => '', 'iframe' => 'on' ); // migrate the old-fashion options foreach ($this->options as $key => $value) { if (false !== $old_option = get_option("add_yt_$key")) { $this->options[$key] = $old_option; } delete_option("add_yt_$key"); } add_option($this->key, $this->options);*/ } // Handle our options function get_options() { $options = array( 'posts' => 'on', 'comments' => 'off', 'img' => 'off', 'width' => 425, 'height' => 344, 'widthhq' => 480, 'heighthq' => 295, 'widthside' => 150, 'heightside' => 125, 'rel' => 1, 'color' => 'blank', 'border' => 0, 'link' => 'on', 'valid' => 'off', 'search' => 'off', 'info' => 'on', 'ann' => 'on', 'template' => '{video}', 'autoplay' => 0, 'privacy' => 0, 'wtext' => '', 'wtitle' => '', 'tag' => '', 'iframe' => 'on', 'dark_player' => '', 'logoless' => 'on' ); $saved = get_option($this->key); if (!empty($saved)) { foreach ($saved as $key => $option) $options[$key] = $option; } if ($saved != $options) update_option($this->key, $options); return $options; } function widget($args = array()) { extract ($args); $text = apply_filters( 'widget_text', $this->check($this->options['wtext'], 1)); $title = apply_filters( 'widget_title', $this->options['wtitle']); echo $before_widget, $before_title, $title, $after_title, $text, $after_widget; } function widget_control() { if ($_REQUEST['submit']) { $this->options['wtext'] = stripslashes($_REQUEST['yte_text']); $this->options['wtitle'] = stripslashes($_REQUEST['yte_title']); } update_option($this->key, $this->options); $text = wp_specialchars($this->options['wtext']); $title = wp_specialchars($this->options['wtitle']); echo <<
Insert HTML code below. In addition to normal text you may use httpv, httpvh and httpvhd links just like in your posts.
EOT; } /** * Checks the plugin version * @param $plugin * @return unknown_type */ function check_plugin_version($plugin) { global $plugindir; if (strpos($plugin, 'addyoutube.php') === false) return; $status = $this->get_info(); $the_version = $status[1]; $the_message = $status[3]; if ((version_compare(strval($the_version), strval($this->local_version), '>') != 1)) return; $msg = "Latest version available: $the_version
.$the_message"; echo << Latest version available: $the_version
$the_message EOT; } /** * Gets plugin info from WordPress Codex repo * @return mixed */ function get_info() { $checkfile = 'http://www.wordpress.org'; $status = array(); return $status; //??? $vcheck = wp_remote_fopen($checkfile); if ($vcheck) { $version = $$this->local_version; $status = explode('@', $vcheck); return $status; } } }