__construct();
}
function __construct() {
$this->local_version = '1.0'; // TODO: Change this number???
$this->plugin_url = trailingslashit(plugins_url(null,__FILE__));
$this->key = 'smart_youtube_pro';
$this->first_post_on_archive = false;
$script_path = $this->plugin_url . '/javascripts/jquery.colorbox-min.js';
wp_register_script( 'colorbox', $script_path );
$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' ), 5 );
add_filter( 'the_excerpt', array( $this, 'check_excerpt' ), 5 );
}
if ( $this->options['comments'] == 'on' ) {
add_filter( 'comment_text', array( $this, 'check' ), 100 );
}
add_action( 'plugins_loaded', array( $this, 'install' ) );
add_action( 'admin_menu', array( $this, 'add_menu_items' ) );
add_action( 'admin_head', array( $this, 'plugin_header' ) );
add_action( 'wp_head', array( $this, 'post_header' ) );
add_action( 'wp_print_scripts', array( $this, 'load_scripts' ) );
add_action( 'wp_print_styles', array( $this, 'load_styles' ) );
add_action( 'template_redirect', array( $this, 'mark_first_post_on_archive' ) );
register_activation_hook(__FILE__, array($this, 'install' ) );
}
function post_header() {
if ( is_singular() ) {
global $wp_query;
$the_content = $wp_query->post->post_content;
$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, PREG_SET_ORDER );
if ( isset( $matches[0][5] ) )
if ( $matches[0][5] != '' )
echo '';
if ( $this->options['colorbox'] == 'on' ) {
?>
options["colorbox"] == 'on' && is_singular() ) {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'colorbox' );
}
}
function load_styles() {
$style_path = $this->plugin_url . '/themes/theme' . $this->options['colorbox_theme'] . '/colorbox.css';
wp_register_style( 'colorbox', $style_path );
if ( $this->options["colorbox"] == 'on' && is_singular() ) {
wp_enqueue_style( 'colorbox' );
}
}
function plugin_header() {
if ( ! empty( $_REQUEST['page'] ) )
$page = $_REQUEST['page'];
else
$page = '';
?>
plugin_url . '/i/icon.png';
add_menu_page( __( 'Smart Youtube', 'smart-youtube' ), __( 'Smart Youtube', 'smart-youtube' ), 'manage_options', 'syt_settings', array(
&$this,
'options_page'
), $image);
$page_settings = add_submenu_page( 'syt_settings', __( 'Smart Youtube', 'smart-youtube' ) . __( ' Settings', 'smart-youtube' ), __( 'Settings', 'smart-youtube' ), 'manage_options', 'syt_settings', array(
&$this,
'options_page'
) );
$page_colorbox = add_submenu_page( 'syt_settings', __( 'Smart Youtube', 'smart-youtube' ) . __( ' Colorbox Options', 'smart-youtube' ), __( 'Colorbox Options', 'smart-youtube' ), 'manage_options', 'syt_colorbox_options', array(
&$this,
'handle_colorbox_options'
) );
$page_about = add_submenu_page( 'syt_settings', __( 'Smart Youtube', 'smart-youtube' ) . __( ' About', 'smart-youtube' ), __( 'About', 'smart-youtube' ), 'manage_options', 'syt_about', array(
&$this,
'handle_about'
) );
}
function options_page() {
// If form was submitted
if ( isset( $_POST['submitted'] ) ) {
check_admin_referer( 'smart-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['autoplay'] = ! isset( $_POST['autoplay'] ) ? 0 : 1;
$this->options['autoplay_first'] = ! isset( $_POST['autoplay_first'] ) ? 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['www'] = ! isset( $_POST['www'] ) ? 'off' : 'on';
$this->options['http'] = ! isset( $_POST['http'] ) ? '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['wiziapp'] = ! isset( $_POST['wiziapp'] ) ? 'off' : 'on';
$this->options['loop'] = ! isset( $_POST['loop'] ) ? 0 : 1;
$this->options['thumb'] = ! isset( $_POST['thumb'] ) ? 'off' : 'on';
$this->options['colorbox'] = ! isset( $_POST['colorbox'] ) ? 'off' : 'on';
$this->options['excerpt'] = ! isset( $_POST['excerpt'] ) ? '' : $_POST['excerpt'];
$this->options['excerpt_align'] = ! isset( $_POST['excerpt_align'] ) ? '' : $_POST['excerpt_align'];
$this->options['logoless'] = ! isset( $_POST['logoless'] ) ? 'off' : 'on';
$this->options['theme'] = ! isset( $_POST['theme'] ) ? '' : $_POST['theme'];
update_option( $this->key, $this->options );
// Show message
echo '
' . __( 'Smart Youtube options saved.', 'smart-youtube' ) . '
';
}
$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_autoplay_first = $this->options['autoplay_first'] ? 'checked="checked"' : '';
$disp_rel = $this->options['rel'] ? 'checked="checked"' : '';
$disp_rel2 = $this->options['rel'] ? '' : 'checked="checked"';
$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"' : '';
$www = $this->options['www'] =='on' ? 'checked="checked"' : '';
$http = $this->options['http'] =='on' ? 'checked="checked"' : '';
$disp_loop = $this->options['loop'] ? 'checked="checked"' : '';
$thumb = $this->options['thumb'] == 'on' ? 'checked="checked"' : '';
$colorbox = $this->options['colorbox'] == 'on' ? 'checked="checked"' : '';
$excerpt = isset( $this->options['excerpt'] ) ? $this->options['excerpt'] : 'not';
$excerpt_align = isset( $this->options['excerpt_align'] ) ? $this->options['excerpt_align'] : 'left';
$disp_template = esc_html( $this->options['template'] );
$tag = $this->options['tag'];
$wiziapp = $this->options['wiziapp'] == 'on' ? 'checked="checked"' : '';
$logoless = $this->options['logoless'] == 'on' ? 'checked="checked"' : '';
$theme = isset( $this->options['theme'] ) ? $this->options['theme'] : '';
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( 'smart-youtube' );
$example = htmlentities( '{video}
' );
// Configuration Page
?>
|
|
httpv:// (notice the \'v\').', 'smart-youtube' ); ?>
Important: The URL should just be copied into your post normally and the letter \'v\' added, do not create a clickable link!', 'smart-youtube' ); ?>
httpvh:// instead (Video High Defintion).', 'smart-youtube' ); ?>
Vladimir Prelovac', 'smart-youtube' ); ?>
options['colorbox_theme'] = ( ! isset( $_POST['colorbox_theme'] ) ? '1' : $_POST['colorbox_theme'] );
update_option( $this->key, $this->options );
$msg_status = __( 'SEO Friendly Images PRO colorbox options saved.', 'smart-youtube' );
// Show message
echo '';
}
$imgpath = $this->plugin_url . '/i';
$actionurl = $_SERVER['REQUEST_URI'];
$this->options = $this->get_options();
?>
Welcome to ' . __( 'Smart YouTube PRO', 'smart-youtube' ) . '.';
?>
first_post_on_archive = true;
}
}
/**
* Looks for Smart 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 ) {
$char_codes = array( '×', '–' );
$replacements = array( "x", "--" );
$the_content = str_replace( $char_codes, $replacements, $the_content );
$this->first = false;
$context = $side ? 'side' : 'post';
preg_match_all( "/((http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^<\s]*))|((http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?youtu\.be\/([a-zA-Z0-9\-\_]{11}))|((http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?metacafe\.com\/watch\/([a-zA-Z0-9\-\_]{7})\/([^<^\/\s]*)([\/])?)|((http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?vimeo\.com\/([a-zA-Z0-9\-\_]{8})([\/])?)|((http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?liveleak\.com\/view(\?i\=)([a-zA-Z0-9\-\_]*))|((http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?facebook\.com\/video\/video.php\?v\=([a-zA-Z0-9\-\_]*))|((http(vp|vhp)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?youtube\.com\/(view_play_list\?p\=|playlist\?list\=)([a-zA-Z0-9\-\_]{18})([^<\s]*))/", $the_content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if ( $match[1] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.youtube.com/watch?v={$match[6]}";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[2] == 'http://' && $this->options['http'] == 'on' ) || ( $match[2] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[1], $this->tag_youtube( $context, $match[6], 'v', $match[7] ), $the_content );
} else if ( $match[3] == 'v' || $match[3] == 'vh' || $match[3] == 'vhd' ) {
$the_content = str_replace( $match[1], $this->tag_youtube( $context, $match[6], $match[3], $match[7] ), $the_content );
}
} elseif ( $match[8] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.youtube.com/watch?v={$match[12]}";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[9] == 'http://' && $this->options['http'] == 'on' ) || ( $match[9] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[8], $this->tag_youtube( $context, $match[12], 'v' ), $the_content );
} else if ( $match[10] == 'v' || $match[10] == 'vh' || $match[10] == 'vhd' ) {
$the_content = str_replace( $match[8], $this->tag_youtube( $context, $match[12], $match[10] ), $the_content );
}
} elseif ( $match[13] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.metacafe.com/watch/{$match[17]}/{$match[18]}/";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[14] == 'http://' && $this->options['http'] == 'on' ) || ( $match[14] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[13], $this->tag_metacafe( $context, $match[17], 'v', $match[18] ), $the_content );
} else if ( $match[15] == 'v' || $match[15] == 'vh' || $match[15] == 'vhd' ) {
$the_content = str_replace( $match[13], $this->tag_metacafe( $context, $match[17], $match[15], $match[18] ), $the_content );
}
} elseif ( $match[20] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.vimeo.com/{$match[24]}";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[21] == 'http://' && $this->options['http'] == 'on' ) || ( $match[21] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[20], $this->tag_vimeo( $context, $match[24], 'v' ), $the_content );
} else if ( $match[22] == 'v' || $match[22] == 'vh' || $match[22] == 'vhd' ) {
$the_content = str_replace( $match[20], $this->tag_vimeo( $context, $match[24], $match[22] ), $the_content );
}
} elseif ( $match[26] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.liveleak.com/view?i={$match[31]}";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[27] == 'http://' && $this->options['http'] == 'on' ) || ( $match[27] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[26], $this->tag_liveleak( $context, $match[31], 'v' ), $the_content );
} else if ( $match[28] == 'v' || $match[28] == 'vh' || $match[28] == 'vhd' ) {
$the_content = str_replace( $match[26], $this->tag_liveleak( $context, $match[31], $match[28] ), $the_content );
}
} elseif ( $match[32] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.facebook.com/video/video.php?v={$match[36]}";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[33] == 'http://' && $this->options['http'] == 'on' ) || ( $match[33] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[32], $this->tag_facebook( $context, $match[36], 'v' ), $the_content );
} else if ( $match[34] == 'v' || $match[34] == 'vh' || $match[34] == 'vhd' ) {
$the_content = str_replace( $match[32], $this->tag_facebook( $context, $match[36], $match[34] ), $the_content );
}
} elseif ( $match[37] != '' ) {
if ( 'on' == $this->options['wiziapp'] ) {
$videos = array();
$video_info['src'] = "http://www.youtube.com/playlist?list={$match[42]}";
array_push( $videos, $video_info );
$replace_text = '';
$replace_text = apply_filters( 'wiziapp_3rd_party_plugin', $replace_text, 'video', $videos );
$the_content = str_replace( $match[1], $replace_text, $the_content );
} else if ( ( $match[38] == 'http://' && $this->options['http'] == 'on' ) || ( $match[38] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[37], $this->tag_youtube( $context, $match[42], 'vp', $match[43] ), $the_content );
} else if ( $match[39] == 'vp' || $match[39] == 'vhp' ) {
$the_content = str_replace( $match[37], $this->tag_youtube( $context, $match[42], $match[39], $match[43] ), $the_content );
}
}
}
/*preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?youtu\.be\/([a-zA-Z0-9\-\_]{11})/", $the_content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if (( $match[1] == 'http://' && $this->options['http'] == 'on' ) || ( $match[1] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[0], $this->tag_youtube( $context, $match[4], 'v' ), $the_content );
} else if ( $match[2] == 'v' || $match[2] == 'vh' || $match[2] == 'vhd' ) {
$the_content = str_replace( $match[0], $this->tag_youtube( $context, $match[4], $match[2] ), $the_content );
}
}
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?metacafe\.com\/watch\/([a-zA-Z0-9\-\_]{7})\/([^<^\/\s]*)([\/])?/", $the_content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if ( ( $match[1] == 'http://' && $this->options['http'] == 'on' ) || ( $match[1] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[0], $this->tag_metacafe( $context, $match[4], 'v', $match[5] ), $the_content );
} else if ( $match[2] == 'v' || $match[2] == 'vh' || $match[2] == 'vhd' ) {
$the_content = str_replace( $match[0], $this->tag_metacafe( $context, $match[4], $match[2], $match[5] ), $the_content );
}
}
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?vimeo\.com\/([a-zA-Z0-9\-\_]{8})([\/])?/", $the_content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if ( ( $match[1] == 'http://' && $this->options['http'] == 'on' ) || ( $match[1] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[0], $this->tag_vimeo( $context, $match[4], 'v' ), $the_content );
} else if ( $match[2] == 'v' || $match[2] == 'vh' || $match[2] == 'vhd' ) {
$the_content = str_replace( $match[0], $this->tag_vimeo( $context, $match[4], $match[2] ), $the_content );
}
}
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?liveleak\.com\/view(\?i\=)([a-zA-Z0-9\-\_]*)/", $the_content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if ( ( $match[1] == 'http://' && $this->options['http'] == 'on' ) || ( $match[1] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[0], $this->tag_liveleak( $context, $match[5], 'v' ), $the_content );
} else if ( $match[2] == 'v' || $match[2] == 'vh' || $match[2] == 'vhd' ) {
$the_content = str_replace( $match[0], $this->tag_liveleak( $context, $match[5], $match[2] ), $the_content );
}
}
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?facebook\.com\/video\/video.php\?v\=([a-zA-Z0-9\-\_]*)/", $the_content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if ( ( $match[1] == 'http://' && $this->options['http'] == 'on' ) || ( $match[1] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[0], $this->tag_facebook( $context, $match[4], 'v' ), $the_content );
} else if ( $match[2] == 'v' || $match[2] == 'vh' || $match[2] == 'vhd' ) {
$the_content = str_replace( $match[0], $this->tag_facebook( $context, $match[4], $match[2] ), $the_content );
}
}
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 ) {
if ( ( $match[1] == 'http://' && $this->options['http'] == 'on' ) || ( $match[1] == '' && $this->options['www'] == 'on' ) ) {
$the_content = str_replace( $match[0], $this->tag_youtube( $context, $match[5], 'vp', $match[6] ), $the_content );
} else if ( $match[2] == 'vp' || $match[2] == 'vhp' ) {
$the_content = str_replace( $match[0], $this->tag_youtube( $context, $match[5], $match[2], $match[6] ), $the_content );
}
}*/
// 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_youtube( $context, $match[3], '', $match[4] ), $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 ) {
$the_content = preg_replace( "/\[$tag\]([a-zA-Z0-9\-\_]{11})([^<\s]*)\[\/$tag\]/", $this->tag_youtube( $context, $match[1], '', '' ), $the_content, 1 );
}
}
if ( $this->first_post_on_archive ) {
$this->first_post_on_archive = false;
}
return $the_content;
}
function check_excerpt( $the_content ) {
$excerpt = $this->options['excerpt'];
$template = trim($this->options['template']) == '' ? '{video}' : $this->options['template'];
if ( $excerpt != 'not' ) {
global $post;
$content = $post->post_content;
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $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})/", $content, $matches['youtu.be'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?metacafe\.com\/watch\/([a-zA-Z0-9\-\_]{7})\/([^<^\/\s]*)([\/])?/", $content, $matches['metacafe.com'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?vimeo\.com\/([a-zA-Z0-9\-\_]{8})([\/])?/", $content, $matches['vimeo.com'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?liveleak\.com\/view(\?i\=)([a-zA-Z0-9\-\_]*)/", $content, $matches['liveleak.com'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?facebook\.com\/video\/video.php\?v\=([a-zA-Z0-9\-\_]*)/", $content, $matches['facebook.com'], PREG_SET_ORDER );
if ( isset( $matches['youtube.com'][0] ) ) {
if ( ( $matches['youtube.com'][0][1] == 'http://' && $this->options['http'] == 'on' ) || ( $matches['youtube.com'][0][1] == '' && $this->options['www'] == 'on' ) ) {
$matches['youtube.com'][0][0] = str_replace( $matches['youtube.com'][0][0], $this->tag_youtube( 'excerpt', $matches['youtube.com'][0][5], 'v', $matches['youtube.com'][0][6] ), $matches['youtube.com'][0][0] );
} else if ( $matches['youtube.com'][0][2] == 'v' || $matches['youtube.com'][0][2] == 'vh' || $matches['youtube.com'][0][2] == 'vhd' ) {
$matches['youtube.com'][0][0] = str_replace( $matches['youtube.com'][0][0], $this->tag_youtube( 'excerpt', $matches['youtube.com'][0][5], $matches['youtube.com'][0][2], $matches['youtube.com'][0][6] ), $matches['youtube.com'][0][0] );
}
$result = $matches['youtube.com'][0][0];
} else if ( isset( $matches['youtu.be'][0] ) ) {
if ( ( $matches['youtu.be'][0][1] == 'http://' && $this->options['http'] == 'on' ) || ( $matches['youtu.be'][0][1] == '' && $this->options['www'] == 'on' ) ) {
$matches['youtu.be'][0][0] = str_replace( $matches['youtu.be'][0][0], $this->tag_youtube( 'excerpt', $matches['youtu.be'][0][4], 'v' ), $matches['youtu.be'][0][0] );
} else if ( $matches['youtu.be'][0][2] == 'v' || $matches['youtu.be'][0][2] == 'vh' || $matches['youtu.be'][0][2] == 'vhd' ) {
$matches['youtu.be'][0][0] = str_replace( $matches['youtu.be'][0][0], $this->tag_youtube( 'excerpt', $matches['youtu.be'][0][4], $matches['youtu.be'][0][2]), $matches['youtu.be'][0][0] );
}
$result = $matches['youtu.be'][0][0];
} else if ( isset( $matches['metacafe.com'][0] ) ) {
if ( ( $matches['metacafe.com'][0][1] == 'http://' && $this->options['http'] == 'on' ) || ( $matches['metacafe.com'][0][1] == '' && $this->options['www'] == 'on' ) ) {
$matches['metacafe.com'][0][0] = str_replace( $matches['metacafe.com'][0][0], $this->tag_metacafe( 'excerpt', $matches['metacafe.com'][0][4], 'v', $matches['metacafe.com'][0][5] ), $matches['metacafe.com'][0][0] );
} else if ( $matches['metacafe.com'][0][2] == 'v' || $matches['metacafe.com'][0][2] == 'vh' || $matches['metacafe.com'][0][2] == 'vhd' ) {
$matches['metacafe.com'][0][0] = str_replace( $matches['metacafe.com'][0][0], $this->tag_metacafe( 'excerpt', $matches['metacafe.com'][0][4], $matches['metacafe.com'][0][2], $matches['metacafe.com'][0][5] ), $matches['metacafe.com'][0][0] );
}
$result = $matches['metacafe.com'][0][0];
} else if ( isset($matches['vimeo.com'][0] ) ) {
if ( ( $matches['vimeo.com'][0][1] == 'http://' && $this->options['http'] == 'on' ) || ( $matches['vimeo.com'][0][1] == '' && $this->options['www'] == 'on' ) ) {
$matches['vimeo.com'][0][0] = str_replace( $matches['vimeo.com'][0][0], $this->tag_vimeo( 'excerpt', $matches['vimeo.com'][0][4], 'v' ), $matches['vimeo.com'][0][0] );
}
else if ( $matches['vimeo.com'][0][2] == 'v' || $matches['vimeo.com'][0][2] == 'vh' || $matches['vimeo.com'][0][2] == 'vhd' ) {
$matches['vimeo.com'][0][0] = str_replace( $matches['vimeo.com'][0][0], $this->tag_vimeo( 'excerpt', $matches['vimeo.com'][0][4], $matches['vimeo.com'][0][2] ), $matches['vimeo.com'][0][0] );
}
$result = $matches['vimeo.com'][0][0];
} else if ( isset( $matches['liveleak.com'][0] ) ) {
if ( ( $matches['liveleak.com'][0][1] == 'http://' && $this->options['http'] == 'on' ) || ( $matches['liveleak.com'][0][1] == '' && $this->options['www'] == 'on' ) ) {
$matches['liveleak.com'][0][0] = str_replace( $matches['liveleak.com'][0][0], $this->tag_liveleak( 'excerpt', $matches['liveleak.com'][0][4], 'v' ), $matches['liveleak.com'][0][0] );
} else if ( $matches['liveleak.com'][0][2] == 'v' || $matches['liveleak.com'][0][2] == 'vh' || $matches['liveleak.com'][0][2] == 'vhd' ) {
$matches['liveleak.com'][0][0] = str_replace( $matches['liveleak.com'][0][0], $this->tag__liveleak( 'excerpt', $matches['liveleak.com'][0][4], $matches['liveleak.com'][0][2] ), $matches['liveleak.com'][0][0] );
}
$result = $matches['liveleak.com'][0][0];
} else if ( isset( $matches['facebook.com'][0] ) ) {
if ( ( $matches['facebook.com'][0][1] == 'http://' && $this->options['http'] == 'on' ) || ( $matches['facebook.com'][0][1] == '' && $this->options['www'] == 'on' ) ) {
$matches['facebook.com'][0][0] = str_replace( $matches['facebook.com'][0][0], $this->tag_facebook( 'excerpt', $matches['facebook.com'][0][4], 'v' ), $matches['facebook.com'][0][0] );
} else if ( $matches['facebook.com'][0][2] == 'v' || $matches['facebook.com'][0][2] == 'vh' || $matches['facebook.com'][0][2] == 'vhd' ) {
$matches['facebook.com'][0][0] = str_replace( $matches['facebook.com'][0][0], $this->tag_facebook( 'excerpt', $matches['facebook.com'][0][4], $matches['facebook.com'][0][2] ), $matches['facebook.com'][0][0] );
}
$result = $matches['facebook.com'][0][0];
} else {
/*$width = $this->options['widthside'];
$height = $this->options['heightside'];
$img_url = htmlspecialchars( $this->plugin_url . '/img/default.jpg' );
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
$result = str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );*/
return $the_content;
}
if ( isset( $result ) ) {
$the_content = 'options["excerpt_aign"] == 'left' ? 'right' : 'left' ) . ':10px;">' . $result . '
' . $the_content . '';
}
}
if ( $this->first_post_on_archive ) {
$this->first_post_on_archive = false;
}
return $the_content;
}
function tag_youtube( $context, $file, $high = 'v', $time = '' ) {
$playlist = 0;
$disp_rel = $this->options['rel'];
$autoplay = $this->options['autoplay'];
$autoplay_first = $this->options['autoplay_first'];
$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'];
if ($this->options['loop'])
$loop="&loop=1&playlist=$file";
else $loop='';
$thumb = $this->options['thumb'];
$colorbox = $this->options['colorbox'];
$logoless = $this->options['logoless'];
$theme = $this->options['theme'];
$excerpt = $this->options['excerpt'];
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 = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['widthside'] :
( $high ? $this->options['widthhq'] : $this->options['width'] );
$height = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['heightside'] :
( $high ? $this->options['heighthq'] : $this->options['height'] );
if ( ! $width ) {
$width = ! $high ? 480 : 425 ;
}
if ( ! $height ) {
$height = ! $high ? 360 : 344;
}
$ap = '';
if ( is_single() ) {
if ( $context == 'post' && $autoplay_first && ! $this->first ) {
$ap = '&autoplay=1';
$this->first = true;
} else if ( ( $context == 'post' && $autoplay && ! $autoplay_first ) || ( $context == 'excerpt' && $autoplay ) ) {
$ap = '&autoplay=1';
} else {
$ap = '';
}
} elseif ( $this->first_post_on_archive ) {
if ( $context == 'post' && $autoplay_first && ! $this->first ) {
$ap = '&autoplay=1';
$this->first = true;
} else if ( ( $context == 'post' && $autoplay && ! $autoplay_first ) || ( $context == 'excerpt' && $autoplay ) ) {
$ap = '&autoplay=1';
} else {
$ap = '';
}
}
if ( $logoless == 'on' ) {
$ll = '&modestbranding=1';
$disp_info = '';
} else {
$ll = '';
}
$root_url = $this->options['privacy'] ? 'http://www.youtube-nocookie.com' : 'http://www.youtube.com';
if ( $excerpt == 'thm' ) {
$img_url = htmlspecialchars( "http://img.youtube.com/vi/$file/0.jpg" );
global $post;
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
}
if ( ( ( is_home() || is_front_page() || is_archive() ) && $context == 'post' && $thumb == 'on' ) || ( $context == 'thumb' ) || ( $context == 'excerpt' && $excerpt == 'thm' ) ) {
$img_url = htmlspecialchars( "http://img.youtube.com/vi/$file/0.jpg" );
if ( $context == 'excerpt' && $excerpt == 'thm' ) {
global $post;
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
} else {
if ( $this->options['iframe'] == 'on' )
$video_url = htmlspecialchars( "$root_url/embed/$file?wmode=transparent&fs=1&hl=en$ap$ll$loop{$disp_info}$disp_ann&showsearch=$disp_search&rel=$disp_rel&theme=$theme", ENT_QUOTES ) . $high . $time;
else
$video_url = htmlspecialchars( "$root_url/v/$file?wmode=transparent&fs=1&hl=en&$ap$ll$loop{$disp_info}$disp_ann&showsearch=$disp_search&rel=$disp_rel&theme=$theme", ENT_QUOTES ) . $high . $time;
if ( $playlist ) {
$video_url = htmlspecialchars( "$root_url/embed/videoseries?list=$file&fs=1&hl=en$ap$ll$loop{$disp_info}$disp_ann&showsearch=$disp_search&rel=$disp_rel&theme=$theme", ENT_QUOTES ) . $high . $time;
$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 ( $context == 'post' && $colorbox == 'on' && is_singular() ) {
$img_url = htmlspecialchars( "http://img.youtube.com/vi/$file/0.jpg" );
$yte_tag = <<
EOT;
} else if ( $this->options['iframe'] == 'on' )
$yte_tag = <<
EOT;
else
$yte_tag = <<
EOT;
} else {
if ( $context == 'post' && $colorbox == 'on' && is_singular() ) {
$img_url = htmlspecialchars( "http://img.youtube.com/vi/$file/0.jpg" );
$yte_tag = <<
EOT;
} else if ( $this->options['iframe'] == 'on' ) {
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
}
}
if ( is_feed() && ( $context == 'post' || $context = 'excerpt' ) ) {
if ( $high ) {
$high = '&fmt=18';
}
if ( $playlist )
$url = 'http://www.youtube.com/playlist?list=';
else
$url = 'http://www.youtube.com/watch?v=';
$yte_tag = '';
if ( $this->options['link'] == 'on' ) {
$yte_tag .= ''.$url. $file . '
';
}
if ( $this->options['img'] == 'on' ) {
$yte_tag .= '
';
}
if ($this->options['link'] == 'off' && $this->options['img'] == 'off')
$yte_tag=$url.$file;
}
return str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );
}
function tag_metacafe( $context, $file, $high = 'v', $name = '' ) {
$width = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['widthside'] :
( $high ? $this->options['widthhq'] : $this->options['width'] );
$height = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['heightside'] :
( $high ? $this->options['heighthq'] : $this->options['height'] );
if ( ! $width ) {
$width = ! ( $high == 'v' ) ? 480 : 425 ;
}
if ( ! $height ) {
$height = ! ( $high == 'v' ) ? 360 : 344;
}
$template = trim( $this->options['template'] ) == '' ? '{video}' : $this->options['template'];
$excerpt = $this->options['excerpt'];
$thumb = $this->options['thumb'];
$colorbox = $this->options['colorbox'];
$autoplay = $this->options['autoplay'];
$autoplay_first = $this->options['autoplay_first'];
$ap = 'no';
if ( is_single() ) {
if ( $context == 'post' && $autoplay_first && ! $this->first ) {
$ap = 'yes';
$this->first = true;
} else if ( ( $context == 'post' && $autoplay && ! $autoplay_first ) || ( $context == 'excerpt' && $autoplay ) ) {
$ap = 'yes';
} else {
$ap = 'no';
}
} elseif ( $this->first_post_on_archive ) {
if ( $context == 'post' && $autoplay_first && ! $this->first ) {
$ap = 'yes';
$this->first = true;
} else if ( ( $context == 'post' && $autoplay && ! $autoplay_first ) || ( $context == 'excerpt' && $autoplay ) ) {
$ap = 'yes';
} else {
$ap = 'no';
}
}
$flash_vars = "playerVars=showStats=no|autoPlay=$ap|";
if ( ( ( is_home() || is_front_page() || is_archive() ) && $context == 'post' && $thumb == 'on' ) || ( $context == 'thumb' ) || ( $context == 'excerpt' && $excerpt == 'thm' ) ) {
$img_url = htmlspecialchars( "http://www.metacafe.com/thumb/$file.jpg" );
if ( $context == 'excerpt' && $excerpt == 'thm' ) {
global $post;
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
} else if ( $context == 'post' && $colorbox == 'on' && is_singular() ) {
$img_url = htmlspecialchars( "http://www.metacafe.com/thumb/$file.jpg" );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
return str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );
}
function tag_vimeo( $context, $file, $high = 'v', $side = 0 ) {
$width = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['widthside'] :
( $high ? $this->options['widthhq'] : $this->options['width'] );
$height = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['heightside'] :
( $high ? $this->options['heighthq'] : $this->options['height'] );
if ( ! $width ) {
$width = ! ( $high == 'v' ) ? 480 : 425 ;
}
if ( ! $height ) {
$height = ! ( $high == 'v' ) ? 360 : 344;
}
$template = trim( $this->options['template'] ) == '' ? '{video}' : $this->options['template'];
$excerpt = $this->options['excerpt'];
$thumb = $this->options['thumb'];
$colorbox = $this->options['colorbox'];
$autoplay = $this->options['autoplay'];
$autoplay_first = $this->options['autoplay_first'];
$loop = $this->options['loop'];
$video_url = "http://player.vimeo.com/video/$file";
if ( $context == 'post' && $autoplay_first && ! $this->first ) {
if ( is_single() ) {
$video_url .= "?autoplay=1";
} elseif ( $this->first_post_on_archive ) {
$video_url .= "?autoplay=1";
}
if ( $loop ) {
$video_url .= "&loop=1";
}
$this->first = true;
} else if ( ( $context == 'post' && $autoplay && ! $autoplay_first ) || ( $context == 'excerpt' && $autoplay ) ) {
if ( is_single() ) {
$video_url .= "?autoplay=1";
} elseif ( $this->first_post_on_archive ) {
$video_url .= "?autoplay=1";
}
if ( $loop ) {
$video_url .= "&loop=1";
}
} else {
if ( $loop ) {
$video_url .= "?loop=1";
}
}
if ( ( ( is_home() || is_front_page() || is_archive() ) && $context == 'post' && $thumb == 'on' ) || ( $context == 'thumb' ) || ( $context == 'excerpt' && $excerpt == 'thm' ) ) {
$thumbs = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$file.php"));
$img_url = htmlspecialchars($thumbs[0]['thumbnail_large']);
if ( $context == 'excerpt' && $excerpt == 'thm' ) {
global $post;
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
}
else if ( $context == 'post' && $colorbox == 'on' && is_singular() ) {
$thumbs = unserialize( file_get_contents( "http://vimeo.com/api/v2/video/$file.php" ) );
$img_url = htmlspecialchars( $thumbs[0]['thumbnail_large'] );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
return str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );
}
function tag_liveleak( $context, $file, $high = 'v', $side = 0 ) {
$width = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['widthside'] :
( $high ? $this->options['widthhq'] : $this->options['width'] );
$height = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['heightside'] :
( $high ? $this->options['heighthq'] : $this->options['height'] );
if ( ! $width ) {
$width = ! ( $high == 'v' ) ? 480 : 425 ;
}
if ( ! $height ) {
$height = ! ( $high == 'v' ) ? 360 : 344;
}
$template = trim($this->options['template']) == '' ? '{video}' : $this->options['template'];
$thumb = $this->options['thumb'];
$colorbox = $this->options['colorbox'];
$excerpt = $this->options['excerpt'];
if ( ( ( is_home() || is_front_page() || is_archive() ) && $context == 'post' && $thumb == 'on' ) || ( $context == 'thumb' ) || ( $context == 'excerpt' && $excerpt == 'thm' ) ) {
$img_url = htmlspecialchars( $this->plugin_url . '/img/default.jpg' );
if ( $context == 'excerpt' && $excerpt == 'thm' ) {
global $post;
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
} else if ( $context == 'post' && $colorbox == 'on' && is_singular() ) {
$img_url = htmlspecialchars( $this->plugin_url . '/img/default.jpg' );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
return str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );
}
function tag_facebook( $context, $file, $high = 'v', $side = 0 ) {
$width = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['widthside'] :
( $high ? $this->options['widthhq'] : $this->options['width'] );
$height = ( $context == 'excerpt' || $context == 'side' ) ?
$this->options['heightside'] :
( $high ? $this->options['heighthq'] : $this->options['height'] );
if ( ! $width ) {
$width = ! ( $high == 'v' ) ? 480 : 425 ;
}
if ( ! $height ) {
$height = ! ( $high == 'v' ) ? 360 : 344;
}
$template = trim($this->options['template']) == '' ? '{video}' : $this->options['template'];
$thumb = $this->options['thumb'];
$colorbox = $this->options['colorbox'];
$excerpt = $this->options['excerpt'];
if ( ( ( is_home() || is_front_page() || is_archive() ) && $context == 'post' && $thumb == 'on' ) || ( $context == 'thumb' ) || ( $context == 'excerpt' && $excerpt == 'thm' ) ) {
$img_url = htmlspecialchars( $this->plugin_url . '/img/default.jpg' );
if ( $context == 'excerpt' && $excerpt == 'thm' ) {
global $post;
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
} else if ( $context == 'post' && $colorbox == 'on' && is_singular() ) {
$img_url = htmlspecialchars( $this->plugin_url . '/img/default.jpg' );
$yte_tag = <<
EOT;
} else {
$yte_tag = <<
EOT;
}
return str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );
}
function install() {
add_action( 'widgets_init', array( $this, 'load_widgets' ) );
if ( get_option( $this->key ) ) {
$this->options = $this->get_options();
}
}
// Handle our options
function get_options() {
$options = array(
'posts' => 'on',
'comments' => 'off',
'img' => 'off',
'width' => 425,
'height' => 344,
'widthhq' => 480,
'heighthq' => 295,
'widthside' => 200,
'heightside' => 167,
'rel' => 1,
'link' => 'on',
'valid' => 'off',
'search' => 'off',
'info' => 'on',
'ann' => 'on',
'template' => '{video}',
'autoplay' => 0,
'autoplay_first' => 0,
'privacy' => 0,
'wtext' => '',
'wtitle' => '',
'tag' => '',
'iframe' => 'on',
'http' => 'off',
'www' => 'off',
'loop' => 0,
'thumb' => 'off',
'colorbox' => 'off',
'colorbox_theme' => 1,
'excerpt' => 'not',
'logoless' => 'on',
'wiziapp' => 'off',
'theme' => 'dark'
);
$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 load_widgets() {
register_widget( 'SmartYouTube_Widget' );
}
/**
* Gets plugin info from WordPress Codex repo
* @return mixed
*/
function get_info() {
$checkfile = 'http://svn.wp-plugins.org/smart-youtube/trunk/smartyoutube.chk';
$status = array();
return $status; //???
$vcheck = wp_remote_fopen( $checkfile );
if ( $vcheck ) {
$version = $this->local_version;
$status = explode( '@', $vcheck );
return $status;
}
}
}
class SmartYouTube_Widget extends WP_Widget {
function SmartYouTube_Widget() {
$widget_ops = array( 'classname' => 'smart-youtube', 'description' => 'A widget which dispalys some video from Youtube.' );
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'smart-youtube' );
$this->WP_Widget( 'smart-youtube', 'Smart Youtube', $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
extract( $args );
$text = smart_youtube_check( $instance['text'], 1 );
$title = $instance['title'];
echo
$before_widget,
$before_title, $title, $after_title,
$text,
$after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = strip_tags( $new_instance['text'] );
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
function form( $instance ) {
$defaults = array( 'title' => 'Smart Youtube Widget', 'text' => '' );
$instance = wp_parse_args( ( array )$instance, $defaults );
?>
check( $the_content, $side );
}
function syt_show_thumb( $post_id ) {
$p = get_post( $post_id );
$content = $p->post_content;
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $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})/", $content, $matches['youtu.be'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?metacafe\.com\/watch\/([a-zA-Z0-9\-\_]{7})\/([^<^\/\s]*)([\/])?/", $content, $matches['metacafe.com'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?vimeo\.com\/([a-zA-Z0-9\-\_]{8})([\/])?/", $content, $matches['vimeo.com'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?liveleak\.com\/view(\?i\=)([a-zA-Z0-9\-\_]*)/", $content, $matches['liveleak.com'], PREG_SET_ORDER );
preg_match_all( "/(http(v|vh|vhd)?:\/\/)?([a-zA-Z0-9\-\_]+\.|)?facebook\.com\/video\/video.php\?v\=([a-zA-Z0-9\-\_]*)/", $content, $matches['facebook.com'], PREG_SET_ORDER );
global $smart_youtube_pro;
if ( isset( $matches['youtube.com'][0] ) ) {
if ( ( $matches['youtube.com'][0][1] == 'http://' && $smart_youtube_pro->options['http'] == 'on' ) || ( $matches['youtube.com'][0][1] == '' && $smart_youtube_pro->options['www'] == 'on' ) ) {
$matches['youtube.com'][0][0] = str_replace( $matches['youtube.com'][0][0], $smart_youtube_pro->tag_youtube( 'excerpt', $matches['youtube.com'][0][5], 'v', $matches['youtube.com'][0][6] ), $matches['youtube.com'][0][0] );
} else if ( $matches['youtube.com'][0][2] == 'v' || $matches['youtube.com'][0][2] == 'vh' || $matches['youtube.com'][0][2] == 'vhd' ) {
$matches['youtube.com'][0][0] = str_replace( $matches['youtube.com'][0][0], $smart_youtube_pro->tag_youtube( 'excerpt', $matches['youtube.com'][0][5], $matches['youtube.com'][0][2], $matches['youtube.com'][0][6] ), $matches['youtube.com'][0][0] );
}
$result = $matches['youtube.com'][0][0];
} else if ( isset( $matches['youtu.be'][0] ) ) {
if ( ( $matches['youtu.be'][0][1] == 'http://' && $smart_youtube_pro->options['http'] == 'on' ) || ( $matches['youtu.be'][0][1] == '' && $smart_youtube_pro->options['www'] == 'on' ) ) {
$matches['youtu.be'][0][0] = str_replace( $matches['youtu.be'][0][0], $smart_youtube_pro->tag_youtube( 'excerpt', $matches['youtu.be'][0][4], 'v' ), $matches['youtu.be'][0][0] );
} else if ( $matches['youtu.be'][0][2] == 'v' || $matches['youtu.be'][0][2] == 'vh' || $matches['youtu.be'][0][2] == 'vhd' ) {
$matches['youtu.be'][0][0] = str_replace( $matches['youtu.be'][0][0], $smart_youtube_pro->tag_youtube( 'excerpt', $matches['youtu.be'][0][4], $matches['youtu.be'][0][2]), $matches['youtu.be'][0][0] );
}
$result = $matches['youtu.be'][0][0];
} else if ( isset( $matches['metacafe.com'][0] ) ) {
if ( ( $matches['metacafe.com'][0][1] == 'http://' && $smart_youtube_pro->options['http'] == 'on' ) || ( $matches['metacafe.com'][0][1] == '' && $smart_youtube_pro->options['www'] == 'on' ) ) {
$matches['metacafe.com'][0][0] = str_replace( $matches['metacafe.com'][0][0], $smart_youtube_pro->tag_metacafe( 'excerpt', $matches['metacafe.com'][0][4], 'v', $matches['metacafe.com'][0][5] ), $matches['metacafe.com'][0][0] );
} else if ( $matches['metacafe.com'][0][2] == 'v' || $matches['metacafe.com'][0][2] == 'vh' || $matches['metacafe.com'][0][2] == 'vhd' ) {
$matches['metacafe.com'][0][0] = str_replace( $matches['metacafe.com'][0][0], $smart_youtube_pro->tag_metacafe( 'excerpt', $matches['metacafe.com'][0][4], $matches['metacafe.com'][0][2], $matches['metacafe.com'][0][5] ), $matches['metacafe.com'][0][0] );
}
$result = $matches['metacafe.com'][0][0];
} else if ( isset($matches['vimeo.com'][0] ) ) {
if ( ( $matches['vimeo.com'][0][1] == 'http://' && $smart_youtube_pro->options['http'] == 'on' ) || ( $matches['vimeo.com'][0][1] == '' && $smart_youtube_pro->options['www'] == 'on' ) ) {
$matches['vimeo.com'][0][0] = str_replace( $matches['vimeo.com'][0][0], $smart_youtube_pro->tag_vimeo( 'excerpt', $matches['vimeo.com'][0][4], 'v' ), $matches['vimeo.com'][0][0] );
}
else if ( $matches['vimeo.com'][0][2] == 'v' || $matches['vimeo.com'][0][2] == 'vh' || $matches['vimeo.com'][0][2] == 'vhd' ) {
$matches['vimeo.com'][0][0] = str_replace( $matches['vimeo.com'][0][0], $smart_youtube_pro->tag_vimeo( 'excerpt', $matches['vimeo.com'][0][4], $matches['vimeo.com'][0][2] ), $matches['vimeo.com'][0][0] );
}
$result = $matches['vimeo.com'][0][0];
} else if ( isset( $matches['liveleak.com'][0] ) ) {
if ( ( $matches['liveleak.com'][0][1] == 'http://' && $smart_youtube_pro->options['http'] == 'on' ) || ( $matches['liveleak.com'][0][1] == '' && $smart_youtube_pro->options['www'] == 'on' ) ) {
$matches['liveleak.com'][0][0] = str_replace( $matches['liveleak.com'][0][0], $smart_youtube_pro->tag_liveleak( 'excerpt', $matches['liveleak.com'][0][4], 'v' ), $matches['liveleak.com'][0][0] );
} else if ( $matches['liveleak.com'][0][2] == 'v' || $matches['liveleak.com'][0][2] == 'vh' || $matches['liveleak.com'][0][2] == 'vhd' ) {
$matches['liveleak.com'][0][0] = str_replace( $matches['liveleak.com'][0][0], $smart_youtube_pro->tag__liveleak( 'excerpt', $matches['liveleak.com'][0][4], $matches['liveleak.com'][0][2] ), $matches['liveleak.com'][0][0] );
}
$result = $matches['liveleak.com'][0][0];
} else if ( isset( $matches['facebook.com'][0] ) ) {
if ( ( $matches['facebook.com'][0][1] == 'http://' && $smart_youtube_pro->options['http'] == 'on' ) || ( $matches['facebook.com'][0][1] == '' && $smart_youtube_pro->options['www'] == 'on' ) ) {
$matches['facebook.com'][0][0] = str_replace( $matches['facebook.com'][0][0], $smart_youtube_pro->tag_facebook( 'excerpt', $matches['facebook.com'][0][4], 'v' ), $matches['facebook.com'][0][0] );
} else if ( $matches['facebook.com'][0][2] == 'v' || $matches['facebook.com'][0][2] == 'vh' || $matches['facebook.com'][0][2] == 'vhd' ) {
$matches['facebook.com'][0][0] = str_replace( $matches['facebook.com'][0][0], $smart_youtube_pro->tag_facebook( 'excerpt', $matches['facebook.com'][0][4], $matches['facebook.com'][0][2] ), $matches['facebook.com'][0][0] );
}
$result = $matches['facebook.com'][0][0];
} else {
$width = $smart_youtube_pro->options['width'];
$height = $smart_youtube_pro->options['height'];
$img_url = htmlspecialchars( $smart_youtube_pro->plugin_url . '/img/default.jpg' );
$post_url = get_permalink( $post->ID );
$yte_tag = <<
EOT;
$result = str_replace( '{video}', $yte_tag, html_entity_decode( $template ) );
}
if ( isset( $result ) ) {
return $result;
}
}
?>