. ************************************************************************** In short, this plugin is free to use by anyone and everyone. You are welcome to use it on a commercial site or whatever you want. However, I do very much appreciate donations for all of my time and effort, although they obviously aren't required for you to use this plugin. You can even just buy me a beer ( http://www.viper007bond.com/donate/ ). If you sell this code (i.e. are a web developer selling features provided via this plugin to clients), it would be very nice if you threw some of your profits my way. After all, you are profiting off my hard work. ;) Thanks and enjoy this plugin! ************************************************************************** If you're here looking for how to add support for both TinyMCE 2 and TinyMCE 3 buttons, then you'll need to check out the legacy version of this plugin. The version you are looking at only supports WordPress 2.6 and newer to keep the code of this plugin siginificantly simpler as well as encourage people to update. The legacy version can be found here: http://downloads.wordpress.org/plugin/vipers-video-quicktags.5.4.4.zip **************************************************************************/ class VipersVideoQuicktags { var $version = '6.1.3'; var $settings = array(); var $defaultsettings = array(); var $swfobjects = array(); var $standardcss; var $cssalignments; var $flvskins = array(); var $wpheadrun = FALSE; var $adminwarned = FALSE; // Class initialization function VipersVideoQuicktags() { global $wp_db_version, $wpmu_version; // This version of VVQ requires WordPress 2.6+ if ( !function_exists('plugins_url') ) { load_plugin_textdomain( 'vipers-video-quicktags', '/wp-content/plugins/vipers-video-quicktags/localization' ); // Old format if ( isset( $_GET['activate'] ) ) { wp_redirect( 'plugins.php?deactivate=true' ); exit(); } else { // Replicate deactivate_plugins() $current = get_option('active_plugins'); $plugins = array( 'vipers-video-quicktags/vipers-video-quicktags.php', 'vipers-video-quicktags.php' ); foreach ( $plugins as $plugin ) { if( !in_array( $plugin, $current ) ) continue; array_splice( $current, array_search( $plugin, $current ), 1 ); // Fixed Array-fu! } update_option('active_plugins', $current); add_action( 'admin_notices', array(&$this, 'WPVersionTooOld') ); return; } } // Redirect the old settings page to the new one for any old links if ( is_admin() && 'vipers-video-quicktags.php' == $_GET['page'] ) { wp_redirect( admin_url( 'options-general.php?page=vipers-video-quicktags' ) ); exit(); } // For debugging (this is limited to localhost installs since it's not nonced) if ( !empty($_GET['resetalloptions']) && 'localhost' == $_SERVER['HTTP_HOST'] && is_admin() && 'vipers-video-quicktags' == $_GET['page'] ) { update_option( 'vvq_options', array() ); wp_redirect( admin_url( 'options-general.php?page=vipers-video-quicktags&defaults=true' ) ); exit(); } // Load up the localization file if we're using WordPress in a different language // Place it in this plugin's "localization" folder and name it "vipers-video-quicktags-[value in wp-config].mo" load_plugin_textdomain( 'vipers-video-quicktags', FALSE, '/vipers-video-quicktags/localization' ); // Create default settings array $this->defaultsettings = apply_filters( 'vvq_defaultsettings', array( 'youtube' => array( 'button' => 1, 'width' => 425, 'height' => 344, 'color1' => '#666666', 'color2' => '#EFEFEF', 'border' => 0, 'rel' => 1, 'fs' => 1, 'autoplay' => 0, 'loop' => 0, 'quality' => 18, 'previewurl' => 'http://www.youtube.com/watch?v=stdJd598Dtg', 'aspectratio' => 1, ), 'googlevideo' => array( 'button' => 1, 'width' => 400, 'height' => 326, 'autoplay' => 0, 'previewurl' => 'http://video.google.com/videoplay?docid=-6006084025483872237', 'aspectratio' => 1, ), 'dailymotion' => array( 'button' => 1, 'width' => 420, 'height' => 336, 'backgroundcolor' => '#DEDEDE', 'glowcolor' => '#FFFFFF', 'foregroundcolor' => '#333333', 'seekbarcolor' => '#FFC300', 'autoplay' => 0, 'related' => 0, 'previewurl' => 'http://www.dailymotion.com/video/x347lz_bugatti-veyron-407-kmh-la-plus-rapi_shortfilms', 'aspectratio' => 1, ), 'vimeo' => array( 'button' => 1, 'width' => 400, 'height' => 300, 'color' => '#00ADEF', 'portrait' => 0, 'title' => 1, 'byline' => 1, 'fullscreen' => 1, 'previewurl' => 'http://www.vimeo.com/240975', 'aspectratio' => 1, ), 'veoh' => array( 'button' => 1, 'width' => 540, 'height' => 438, 'aspectratio' => 1, ), 'viddler' => array( 'button' => 1, ), 'metacafe' => array( 'button' => 1, 'width' => 400, 'height' => 345, 'aspectratio' => 1, ), 'bliptv' => array( 'button' => 1, 'width' => 400, 'height' => 330, 'aspectratio' => 1, ), 'flickrvideo' => array( 'button' => 1, 'width' => 400, 'height' => 300, 'aspectratio' => 1, ), 'spike' => array( 'button' => 1, 'width' => 448, 'height' => 365, 'aspectratio' => 1, ), 'myspace' => array( 'button' => 1, 'width' => 425, 'height' => 360, 'aspectratio' => 1, ), 'flv' => array( 'button' => 0, // Agree to license 'width' => 400, 'height' => 320, 'skin' => '', 'customcolors' => 0, 'backcolor' => '#FFFFFF', 'frontcolor' => '#000000', 'lightcolor' => '#000000', 'screencolor' => '#000000', 'flashvars' => '', 'previewurl' => 'http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured', ), 'quicktime' => array( 'button' => 0, // Marginal support, plugin focus is Flash 'width' => 400, 'height' => 300, 'dynamicload' => 1, ), 'videofile' => array( 'button' => 0, // Shit support 'width' => 400, 'height' => 300, 'usewmp' => 1, ), 'flash' => array( 'width' => 400, 'height' => 300, ), 'alignment' => 'center', 'tinymceline' => 3, 'customcss' => '', 'customfeedtext' => '', ) ); // Setup the settings by using the default as a base and then adding in any changed values // This allows settings arrays from old versions to be used even though they are missing values $usersettings = (array) get_option('vvq_options'); $this->settings = $this->defaultsettings; if ( $usersettings !== $this->defaultsettings ) { foreach ( (array) $usersettings as $key1 => $value1 ) { if ( is_array($value1) ) { foreach ( $value1 as $key2 => $value2 ) { $this->settings[$key1][$key2] = $value2; } } else { $this->settings[$key1] = $value1; } } } // Upgrade settings if ( empty($this->settings['version']) || -1 == version_compare($this->settings['version'], '6.0.0') ) { $usersettings = (array) get_option('vvq_options'); foreach ( $this->defaultsettings as $type => $setting ) { if ( !is_array($this->defaultsettings[$type]) ) continue; if ( isset($usersettings[$type]['button']) ) unset($usersettings[$type]['button']); // Reset buttons } $usersettings['version'] = $this->version; update_option( 'vvq_options', $usersettings ); } if ( -1 == version_compare($this->settings['version'], '6.1.0') ) { $usersettings = (array) get_option('vvq_options'); // Convert quality toggle to new format if ( isset($this->settings['highqual']) ) { unset($usersettings['highqual']); if ( 0 == $this->settings['highqual'] ) $usersettings['quality'] = 0; // If the user wanted low quality videos } // Custom FLV colors $colors = array( 'backcolor', 'frontcolor', 'lightcolor', 'screencolor' ); foreach ( $colors as $color ) { if ( $usersettings['flv'][$color] != $this->defaultsettings['flv'][$color] ) $usersettings['flv']['customcolors'] = 1; } $usersettings['version'] = $this->version; update_option( 'vvq_options', $usersettings ); } // Register general hooks add_action( 'admin_menu', array(&$this, 'RegisterSettingsPage') ); add_filter( 'plugin_action_links', array(&$this, 'AddPluginActionLink'), 10, 2 ); add_action( 'admin_post_vvqsettings', array(&$this, 'POSTHandler') ); add_action( 'wp_head', array(&$this, 'Head') ); add_action( 'admin_head', array(&$this, 'Head') ); add_action( 'the_content', array(&$this, 'SWFObjectCalls'), 15 ); add_filter( 'widget_text', 'do_shortcode', 11 ); // Videos in the text widget add_action( 'widget_text', array(&$this, 'SWFObjectCalls'), 15 ); if ( $wp_db_version < 8990 && 'update.php' == basename( $_SERVER['PHP_SELF'] ) && 'upgrade-plugin' == $_GET['action'] && FALSE !== strstr( $_GET['plugin'], 'vipers-video-quicktags' ) ) add_action( 'admin_notices', array(&$this, 'AutomaticUpgradeNotice') ); // Register editor button hooks add_filter( 'tiny_mce_version', array(&$this, 'tiny_mce_version') ); add_filter( 'mce_external_plugins', array(&$this, 'mce_external_plugins') ); add_action( 'edit_form_advanced', array(&$this, 'AddQuicktagsAndFunctions') ); add_action( 'edit_page_form', array(&$this, 'AddQuicktagsAndFunctions') ); if ( 1 == $this->settings['tinymceline'] ) add_filter( 'mce_buttons', array(&$this, 'mce_buttons') ); else add_filter( 'mce_buttons_' . $this->settings['tinymceline'], array(&$this, 'mce_buttons') ); // Hide the donate button on WPMU installs as admins probably don't want it there if ( !empty($wpmu_version) ) add_filter( 'vvq_donatebutton', array(&$this, 'ReturnFalse'), 5 ); // Register shortcodes add_shortcode( 'youtube', array(&$this, 'shortcode_youtube') ); add_shortcode( 'googlevideo', array(&$this, 'shortcode_googlevideo') ); add_shortcode( 'gvideo', array(&$this, 'shortcode_googlevideo') ); // Not the preferred format add_shortcode( 'dailymotion', array(&$this, 'shortcode_dailymotion') ); add_shortcode( 'vimeo', array(&$this, 'shortcode_vimeo') ); add_shortcode( 'veoh', array(&$this, 'shortcode_veoh') ); add_shortcode( 'viddler', array(&$this, 'shortcode_viddler') ); add_shortcode( 'metacafe', array(&$this, 'shortcode_metacafe') ); add_shortcode( 'blip.tv', array(&$this, 'shortcode_bliptv') ); add_shortcode( 'bliptv', array(&$this, 'shortcode_bliptv') ); // Not the preferred format add_shortcode( 'flickr video', array(&$this, 'shortcode_flickrvideo') ); // WordPress.com add_shortcode( 'flickrvideo', array(&$this, 'shortcode_flickrvideo') ); // Normal format add_shortcode( 'ifilm', array(&$this, 'shortcode_ifilm') ); add_shortcode( 'spike', array(&$this, 'shortcode_ifilm') ); add_shortcode( 'myspace', array(&$this, 'shortcode_myspace') ); add_shortcode( 'stage6', array(&$this, 'shortcode_stage6') ); // Stage6 = dead, but we still need to handle it add_shortcode( 'flv', array(&$this, 'shortcode_flv') ); add_shortcode( 'quicktime', array(&$this, 'shortcode_quicktime') ); add_shortcode( 'flash', array(&$this, 'shortcode_flash') ); add_shortcode( 'kml_flashembed', array(&$this, 'shortcode_flash') ); // Anarchy Media Plugin support add_shortcode( 'videofile', array(&$this, 'shortcode_videofile') ); add_shortcode( 'video', array(&$this, 'shortcode_videofile') ); // Legacy add_shortcode( 'avi', array(&$this, 'shortcode_videofile') ); // Legacy add_shortcode( 'mpeg', array(&$this, 'shortcode_videofile') ); // Legacy add_shortcode( 'wmv', array(&$this, 'shortcode_videofile') ); // Legacy // Register scripts and styles wp_enqueue_script( 'swfobject', plugins_url('/vipers-video-quicktags/resources/swfobject.js'), array(), '2.1' ); wp_register_script( 'qtobject', plugins_url('/vipers-video-quicktags/resources/qtobject.js'), array(), '1.0.2' ); if ( is_admin() ) { // Settings page only if ( 'vipers-video-quicktags' == $_GET['page'] ) { add_action( 'admin_head', array(&$this, 'StyleTweaks' ) ); wp_enqueue_script( 'farbtastic', plugins_url('/vipers-video-quicktags/resources/farbtastic/farbtastic.js'), array('jquery'), '1.2' ); wp_enqueue_style( 'farbtastic', plugins_url('/vipers-video-quicktags/resources/farbtastic/farbtastic.css'), array(), '1.2', 'screen' ); } // Editor pages only if ( in_array( basename($_SERVER['PHP_SELF']), apply_filters( 'vvq_editor_pages', array('post-new.php', 'page-new.php', 'post.php', 'page.php') ) ) ) { add_action( 'admin_head', array(&$this, 'EditorCSS') ); add_action( 'admin_footer', array(&$this, 'OutputjQueryDialogDiv') ); // If old version of jQuery UI, then replace it to fix a bug with the UI core if ( $wp_db_version < 8601 ) { wp_deregister_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-core', plugins_url('/vipers-video-quicktags/resources/jquery-ui/ui.core.js'), array('jquery'), '1.5.2' ); } wp_enqueue_script( 'jquery-ui-draggable', plugins_url('/vipers-video-quicktags/resources/jquery-ui/ui.draggable.js'), array('jquery-ui-core'), '1.5.2' ); wp_enqueue_script( 'jquery-ui-resizable', plugins_url('/vipers-video-quicktags/resources/jquery-ui/ui.resizable.js'), array('jquery-ui-core'), '1.5.2' ); wp_enqueue_script( 'jquery-ui-dialog', plugins_url('/vipers-video-quicktags/resources/jquery-ui/ui.dialog.js'), array('jquery-ui-core'), '1.5.2' ); wp_enqueue_style( 'vvq-jquery-ui', plugins_url('/vipers-video-quicktags/resources/jquery-ui/vvq-jquery-ui.css'), array(), $this->version, 'screen' ); } } if ( 1 == $this->settings['quicktime']['dynamicload'] ) add_action( 'wp_head', array(&$this, 'MaybeEnqueueQuicktimeJavascript'), 1 ); else wp_enqueue_script( 'qtobject' ); // Set up the CSS $this->cssalignments = array( 'left' => 'margin: 10px auto 10px 0;', 'center' => 'margin: 10px auto;', 'right' => 'margin: 10px 0 10px auto;', 'floatleft' => 'float: left;\n margin: 10px 10px 10px 0;', 'floatright' => 'float: right;\n margin: 10px 0 10px 10px;', ); $this->standardcss = '.vvqbox { display: block; max-width: 100%; visibility: visible !important; /* alignment CSS placeholder */ } .vvqbox img { max-width: 100%; height: 100%; } .vvqbox object { max-width: 100%; }'; $this->flvskins = apply_filters( 'vvq_flvskins', array( '' => __('Default', 'vipers-video-quicktags'), '3dpixelstyle' => __('3D Pixel Style', 'vipers-video-quicktags'), 'atomicred' => __('Atomic Red', 'vipers-video-quicktags'), 'comet' => __('Comet', 'vipers-video-quicktags'), 'controlpanel' => __('Control Panel', 'vipers-video-quicktags'), 'dangdang' => __('Dang Dang', 'vipers-video-quicktags'), 'fashion' => __('Fashion', 'vipers-video-quicktags'), 'festival' => __('Festival', 'vipers-video-quicktags'), 'icecreamsneaka' => __('Ice Cream Sneaka', 'vipers-video-quicktags'), 'kleur' => __('Kleur', 'vipers-video-quicktags'), 'magma' => __('Magma', 'vipers-video-quicktags'), 'metarby10' => __('Metarby 10', 'vipers-video-quicktags'), 'nacht' => __('Nacht', 'vipers-video-quicktags'), 'neon' => __('Neon', 'vipers-video-quicktags'), 'pearlized' => __('Pearlized', 'vipers-video-quicktags'), 'pixelize' => __('Pixelize', 'vipers-video-quicktags'), 'playcasso' => __('Play Casso', 'vipers-video-quicktags'), 'schoon' => __('Schoon', 'vipers-video-quicktags'), 'silverywhite' => __('Silvery White', 'vipers-video-quicktags'), 'snel' => __('Snel', 'vipers-video-quicktags'), 'stijl' => __('Stijl', 'vipers-video-quicktags'), 'traganja' => __('Traganja', 'vipers-video-quicktags'), ) ); } // This function gets called when the minimum WordPress version isn't met function WPVersionTooOld() { echo '
' . sprintf( __( 'This version of Viper\'s Video Quicktags requires WordPress 2.6 or newer. Please upgrade or use the legacy version of this plugin.', 'vipers-video-quicktags' ), 'http://codex.wordpress.org/Upgrading_WordPress', 'http://downloads.wordpress.org/plugin/vipers-video-quicktags.5.4.4.zip' ) . "
' . sprintf( __( "WARNING: If you use the FLV embed feature of Viper's Video Quicktags, there is a bug in WordPress with the FTP method of upgrading plugins. It will not upload the .swf files properly. If you do embed FLV files, please manually download the plugin and upload the files to your server. If you don't embed FLV files (and only embed YouTube, etc. videos), you can safely ignore this message and upgrade automatically.", 'vipers-video-quicktags' ), 'http://downloads.wordpress.org/plugin/vipers-video-quicktags.zip' ) . "
';
}
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$embedpath = 'v/' . $content;
$fallbacklink = 'http://www.youtube.com/watch?v=' . $content;
$fallbackcontent = '
';
}
// Setup the parameters
$color1 = $color2 = $border = $quality = $autoplay = $loop = '';
if ( '' != $atts['color1'] && $this->defaultsettings['youtube']['color1'] != $atts['color1'] ) $color1 = '&color1=0x' . str_replace( '#', '', $atts['color1'] );
if ( '' != $atts['color2'] && $this->defaultsettings['youtube']['color2'] != $atts['color2'] ) $color2 = '&color2=0x' . str_replace( '#', '', $atts['color2'] );
if ( $atts['border'] ) $border = '&border=1';
$rel = ( 1 == $atts['rel'] ) ? '1' : '0';
$fs = ( 1 == $atts['fs'] ) ? '1' : '0';
if ( !empty($atts['quality']) && 0 != $atts['quality'] ) $quality = '&ap=%2526fmt%3D' . $atts['quality'];
if ( $atts['autoplay'] ) $autoplay = '&autoplay=1';
if ( $atts['loop'] ) $loop = '&loop=1';
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.youtube.com/' . $embedpath . $color1 . $color2 . $border . '&rel=' . $rel . '&fs=' . $fs . $autoplay . $loop . $quality );
return '' . $fallbackcontent . '';
}
// Handle Google Video shortcodes
function shortcode_googlevideo( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
// Handle WordPress.com shortcode format
if ( isset($atts[0]) ) {
$atts = $this->attributefix( $atts );
$content = $atts[0];
unset($atts[0]);
}
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('Google Video') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['googlevideo']['width'],
'height' => $this->settings['googlevideo']['height'],
'autoplay' => $this->settings['googlevideo']['autoplay'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'googlevideo' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', $content, $matches );
if ( empty($matches) || empty($matches[2]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('Google Video') ) );
$videoid = $matches[2];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
// Setup the parameters
$autoplay = '';
if ( 1 == $atts['autoplay'] ) $autoplay = '&autoplay=1';
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://video.google.com/googleplayer.swf?docid=' . $videoid . $autoplay );
return 'http://video.google.com/videoplay?docid=' . $videoid . '';
}
// Handle DailyMotion shortcodes
function shortcode_dailymotion( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('YouTube') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['dailymotion']['width'],
'height' => $this->settings['dailymotion']['height'],
'backgroundcolor' => $this->settings['dailymotion']['backgroundcolor'],
'glowcolor' => $this->settings['dailymotion']['glowcolor'],
'foregroundcolor' => $this->settings['dailymotion']['foregroundcolor'],
'seekbarcolor' => $this->settings['dailymotion']['seekbarcolor'],
'autoplay' => $this->settings['dailymotion']['autoplay'],
'related' => $this->settings['dailymotion']['related'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'dailymotion' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
//http://www.dailymotion.com/visited/search/top%2Bgear/video/x347lz_bugatti-veyron-407-kmh-la-plus-rapi_shortfilms
preg_match( '#http://(www.dailymotion|dailymotion)\.com/(.+)/([0-9a-zA-Z]+)\_(.*?)#i', $content, $matches );
if ( empty($matches) || empty($matches[3]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('DailyMotion') ) );
$videoid = $matches[3];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
// Setup the parameters
$backgroundcolor = $glowcolor = $foregroundcolor = $seekbarcolor = '';
if ( '' != $atts['backgroundcolor'] && $this->defaultsettings['dailymotion']['backgroundcolor'] != $atts['backgroundcolor'] ) $backgroundcolor = 'background:' . str_replace( '#', '', $atts['backgroundcolor'] ) . ';';
if ( '' != $atts['glowcolor'] && $this->defaultsettings['dailymotion']['glowcolor'] != $atts['glowcolor'] ) $glowcolor = 'glow:' . str_replace( '#', '', $atts['glowcolor'] ) . ';';
if ( '' != $atts['foregroundcolor'] && $this->defaultsettings['dailymotion']['foregroundcolor'] != $atts['foregroundcolor'] ) $foregroundcolor = 'foreground:' . str_replace( '#', '', $atts['foregroundcolor'] ) . ';';
if ( '' != $atts['seekbarcolor'] && $this->defaultsettings['dailymotion']['seekbarcolor'] != $atts['seekbarcolor'] ) $seekbarcolor = 'special:' . str_replace( '#', '', $atts['seekbarcolor'] ) . ';';
$autoplay = ( 1 == $atts['autoplay'] ) ? '1' : '0';
$related = ( 1 == $atts['related'] ) ? '1' : '0';
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.dailymotion.com/swf/' . $videoid . '&colors=' . $backgroundcolor . $glowcolor . $foregroundcolor . $seekbarcolor . '&autoPlay=' . $autoplay . '&related=' . $related );
return 'http://www.dailymotion.com/video' . $videoid . '';
}
// Handle Vimeo shortcodes
function shortcode_vimeo( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
// Handle malformed WordPress.com shortcode format
if ( isset($atts[0]) ) {
$atts = $this->attributefix( $atts );
$content = $atts[0];
unset($atts[0]);
}
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('Vimeo') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['vimeo']['width'],
'height' => $this->settings['vimeo']['height'],
'color' => $this->settings['vimeo']['color'],
'portrait' => $this->settings['vimeo']['portrait'],
'title' => $this->settings['vimeo']['title'],
'byline' => $this->settings['vimeo']['byline'],
'fullscreen' => $this->settings['vimeo']['fullscreen'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'vimeo' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://(www.vimeo|vimeo)\.com(/|/clip:)(\d+)(.*?)#i', $content, $matches );
if ( empty($matches) || empty($matches[3]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('Vimeo') ) );
$videoid = $matches[3];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
// Setup the parameters
$portrait = ( 1 == $atts['portrait'] ) ? '1' : '0';
$title = ( 1 == $atts['title'] ) ? '1' : '0';
$byline = ( 1 == $atts['byline'] ) ? '1' : '0';
$fullscreen = ( 1 == $atts['fullscreen'] ) ? '1' : '0';
$objectid = uniqid('vvq');
// Gotta pass these via flashvars rather than the URL to keep for valid XHTML (Vimeo doesn't like &'s)
$flashvars = array(
'server' => 'www.vimeo.com',
'clip_id' => $videoid,
'show_portrait' => $portrait,
'show_title' => $title,
'show_byline' => $byline,
'fullscreen' => $fullscreen,
);
if ( '' != $atts['color'] && $this->defaultsettings['vimeo']['color'] != $atts['color'] )
$flashvars['color'] = str_replace( '#', '', $atts['color'] );
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.vimeo.com/moogaloop.swf', 'flashvars' => $flashvars );
return 'http://www.vimeo.com/' . $videoid . '';
}
// Handle Veoh shortcodes
function shortcode_veoh( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('Veoh') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['veoh']['width'],
'height' => $this->settings['veoh']['height'],
'autoplay' => 0,
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'veoh' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://(www.veoh|veoh)\.com/videos/([0-9a-zA-Z]+)(.*?)#i', $content, $matches );
if ( empty($matches) || empty($matches[2]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('Veoh') ) );
$videoid = $matches[2];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.veoh.com/veohplayer.swf?permalinkId=' . $videoid . '&id=anonymous&player=videodetailsembedded&affiliateId=&videoAutoPlay=' . $atts['autoplay'] );
return 'http://www.veoh.com/videos/' . $videoid . '';
}
// Handle Viddler shortcodes
function shortcode_viddler( $atts, $content = '' ) {
if ( empty($atts['id']) ) return $this->error( __('Sorry, but the only format that is supported for Viddler is the WordPress.com-style format rather than the URL. You can find it in the "Embed This" window.', 'vipers-video-quicktags') );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'id' => '',
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'viddler' );
// Parse WordPress.com shortcode format
preg_match( '#(.*?)(&|&\#038;|&)w=(\d+)(&|&\#038;|&)h=(\d+)#i', $atts['id'], $matches );
$videoid = $matches[1];
$width = $matches[3];
$height = $matches[5];
if ( empty($videoid) || empty($width) || empty($height) ) return $this->error( sprintf( __('An invalid %s shortcode format was used. Please check your code.', 'vipers-video-quicktags'), __('Viddler', 'vipers-video-quicktags') ) );
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $width, 'height' => $height, 'url' => 'http://www.viddler.com/player/' . $videoid . '/' );
return '' . sprintf( __('Please enable Javascript and Flash to view this %3$s video.', 'vipers-video-quicktags'), 'http://www.google.com/support/bin/answer.py?answer=23852', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', __('Viddler') ) . '';
}
// Handle Metacafe shortcodes
function shortcode_metacafe( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('Metacafe') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['metacafe']['width'],
'height' => $this->settings['metacafe']['height'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'metacafe' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://(www.metacafe|metacafe)\.com/watch/(\d+)/(.*?)#i', $content, $matches );
if ( empty($matches) || empty($matches[2]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('Metacafe') ) );
$videoid = $matches[2];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.metacafe.com/fplayer/' . $videoid . '/vipers_video_quicktags.swf' );
return '';
}
// Handle Blip.tv shortcodes
function shortcode_bliptv( $atts ) {
if ( empty($atts[0]) ) return $this->error( __('Sorry, but the only format that is supported for Blip.tv is the WordPress.com-style format. You can find it at Share -> Embed -> WordPress.com.', 'vipers-video-quicktags') );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
0 => '',
'width' => $this->settings['bliptv']['width'],
'height' => $this->settings['bliptv']['height'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'bliptv' );
// Parse WordPress.com shortcode format
parse_str( $atts[0], $params );
if ( empty($params['?posts_id']) ) return $this->error( sprintf( __('An invalid %s shortcode format was used. Please check your code.', 'vipers-video-quicktags'), __('Blip.tv', 'vipers-video-quicktags') ) );
$videoid = $params['?posts_id'];
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://blip.tv/scripts/flash/showplayer.swf?file=http://blip.tv/rss/flash/' . $videoid );
return '' . sprintf( __('Please enable Javascript and Flash to view this %3$s video.', 'vipers-video-quicktags'), 'http://www.google.com/support/bin/answer.py?answer=23852', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', __('Blip.tv') ) . '';
}
// Handle Flickr videos
function shortcode_flickrvideo( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
// Handle WordPress.com shortcode format
if ( isset($atts[0]) ) {
$atts = $this->attributefix( $atts );
$content = $atts[0];
unset($atts[0]);
}
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('Flickr Video') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['flickrvideo']['width'],
'height' => $this->settings['flickrvideo']['height'],
'showinfobox' => 1,
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'flickrvideo' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://(www.flickr|flickr)\.com/photos/(.+)/(\d+)(.*?)#i', $content, $matches );
if ( empty($matches) || empty($matches[3]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('Flickr Video') ) );
$videoid = $matches[3];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
// Setup the parameters
$showinfobox = ( 1 == $atts['showinfobox'] ) ? 'true' : 'false';
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.flickr.com/apps/video/stewart.swf?v=1.161', 'flashvars' => array( 'photo_id' => $videoid, 'flickr_show_info_box' => $showinfobox ) );
return '' . __('Flickr Video', 'vipers-video-quicktags') . '';
}
// Handle IFILM aka Spike shortcodes for backwards compatibility
function shortcode_ifilm( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('IFILM/Spike') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['spike']['width'],
'height' => $this->settings['spike']['height'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'spike' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://(www.ifilm|ifilm|www.spike|spike)\.com/(.+)/(\d+)#i', $content, $matches );
if ( empty($matches) || empty($matches[3]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('IFILM/Spike') ) );
$videoid = $matches[3];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://www.spike.com/efp', 'flashvars' => array( 'flvbaseclip' => $videoid ) );
return 'http://www.spike.com/video/' . $videoid . '';
}
// Handle MySpace videos
function shortcode_myspace( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL or video ID was passed to the %s BBCode', 'vipers-video-quicktags'), __('MySpace') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['myspace']['width'],
'height' => $this->settings['myspace']['height'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'myspace' );
// If a URL was passed
if ( 'http://' == substr( $content, 0, 7 ) ) {
preg_match( '#http://(vids.myspace|myspacetv)\.com/index\.cfm\?fuseaction=vids\.individual(.+)videoid=(\d+)#i', $content, $matches ); // Had issues with the "&"
if ( empty($matches) || empty($matches[3]) ) return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('MySpace') ) );
$videoid = $matches[3];
}
// If a URL wasn't passed, assume a video ID was passed instead
else {
$videoid = $content;
}
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => 'http://mediaservices.myspace.com/services/media/embed.aspx/m=' . $videoid );
return 'http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid=' . $videoid . '';
}
// Handle FLV videos
function shortcode_flv( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL was passed to the %s BBCode', 'vipers-video-quicktags'), __('FLV') ) );
if ( is_feed() ) return $this->postlink();
$origatts = $atts;
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['flv']['width'],
'height' => $this->settings['flv']['height'],
'image' => FALSE,
'customcolors' => $this->settings['flv']['customcolors'],
'backcolor' => $this->settings['flv']['backcolor'],
'frontcolor' => $this->settings['flv']['frontcolor'],
'lightcolor' => $this->settings['flv']['lightcolor'],
'screencolor' => $this->settings['flv']['screencolor'],
'volume' => 100,
'flashvars' => '',
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'flv' );
// Default image is the URL to the video but .jpg instead of .flv
if ( FALSE === $atts['image'] )
$atts['image'] = str_replace( '.flv', '.jpg', $content );
// Setup the flashvars using the parameters as well as the "flashvars" value
$flashvars = array(
'file' => $content,
'image' => $atts['image'],
'bufferlength' => 15,
'volume' => 100,
);
// Skin
if ( !empty($this->settings['flv']['skin']) && !empty($this->flvskins[$this->settings['flv']['skin']]) )
$flashvars['skin'] = plugins_url('/vipers-video-quicktags/resources/jw-flv-player/skins/' . $this->settings['flv']['skin'] . '.swf');
// Custom colors
if ( 1 == $atts['customcolors'] || !empty($origatts['backcolor']) )
$flashvars['backcolor'] = str_replace( '#', '', $atts['backcolor'] );
if ( 1 == $atts['customcolors'] || !empty($origatts['frontcolor']) )
$flashvars['frontcolor'] = str_replace( '#', '', $atts['frontcolor'] );
if ( 1 == $atts['customcolors'] || !empty($origatts['lightcolor']) )
$flashvars['lightcolor'] = str_replace( '#', '', $atts['lightcolor'] );
if ( 1 == $atts['customcolors'] || !empty($origatts['screencolor']) )
$flashvars['screencolor'] = str_replace( '#', '', $atts['screencolor'] );
// Copy in any user set default vars
if ( !empty($this->settings['flv']['flashvars']) ) {
parse_str( $this->settings['flv']['flashvars'], $params );
$flashvars = array_merge( $flashvars, $params );
}
// Copy in any one-off passed vars
if ( !empty($atts['flashvars']) ) {
$atts['flashvars'] = $this->wpuntexturize( $atts['flashvars'] );
parse_str( $atts['flashvars'], $params );
$flashvars = array_merge( $flashvars, $params );
}
$objectid = uniqid('vvq');
$swfurl = plugins_url('/vipers-video-quicktags/resources/jw-flv-player/player.swf');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => $swfurl, 'flashvars' => $flashvars );
return '' . htmlspecialchars( $content ) . '';
}
// Handle major pain in the ass Quicktime video files
function shortcode_quicktime( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL was passed to the %s BBCode', 'vipers-video-quicktags'), __('Quicktime') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['quicktime']['width'],
'height' => $this->settings['quicktime']['height'],
'autostart' => 0,
'useplaceholder' => 0,
'placeholder' => str_replace( '.mov', '.jpg', $content ),
'controller' => 1,
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'quicktime' );
if ( 1 == $atts['useplaceholder'] && !empty($atts['placeholder']) ) {
$mov = $atts['placeholder'];
$href = ' myQTObject.addParam("href", "' . $content . '"); myQTObject.addParam("target", "myself");';
} else {
$mov = $content;
$href = '';
}
$autostart = ( 1 == $atts['autostart'] ) ? 'true' : 'false';
$controller = ( 1 == $atts['controller'] ) ? 'true' : 'false';
return '';
}
// Handle super-duper pain in the ass regular video files
function shortcode_videofile( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( empty($content) ) return $this->error( sprintf( __('No URL was passed to the %s BBCode', 'vipers-video-quicktags'), __('generic video') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['videofile']['width'],
'height' => $this->settings['videofile']['height'],
'usewmp' => $this->settings['videofile']['usewmp'],
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'videofile' );
// This is semi-temporary. Embedding generic video files is a major pain in the ass, so this part of the plugin is kinda half-heartedly coded.
if ( 1 == $atts['usewmp'] && FALSE !== strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') ) {
$atts['height'] = $atts['height'] + 64; // Compensate for the player controls
return '';
} else {
// Determine the MIME type
$mimetypes = apply_filters( 'vvqvideomimes', array(
'asf' => 'video/x-ms-asf',
'asx' => 'video/x-ms-asf',
'avi' => 'video/avi',
'm1v' => 'video/mpeg',
'mp3' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'wmv' => 'video/x-ms-wmv',
) );
$mimetype = $mimetypes[array_pop(explode('.', $content))];
if ( empty($mimetype) ) $mimetype = 'video/mpeg'; // If we don't know the MIME type, just pick something (MPEG)
return '';
}
}
// Generic Flash embed allowing you to embed any type of Flash-based video
function shortcode_flash( $atts, $content = '' ) {
$content = $this->wpuntexturize( $content );
if ( !empty($atts['movie']) ) $content = $atts['movie'];
if ( empty($content) ) return $this->error( sprintf( __('No URL was passed to the %s BBCode', 'vipers-video-quicktags'), __('generic Flash embed') ) );
if ( is_feed() ) return $this->postlink();
// Set any missing $atts items to the defaults
$atts = shortcode_atts(array(
'width' => $this->settings['flash']['width'],
'height' => $this->settings['flash']['height'],
'flashvars' => '',
), $atts);
// Allow other plugins to modify these values (for example based on conditionals)
$atts = apply_filters( 'vvq_shortcodeatts', $atts, 'flash' );
// Create Flashvars
$flashvars = array();
if ( !empty($atts['flashvars']) ) {
$atts['flashvars'] = str_replace( array('#038;', '&'), '&', $atts['flashvars'] ); // Fix formatting applied by WordPress
parse_str( $atts['flashvars'], $params );
foreach ( $params as $key => $value )
$flashvars[$key] = $value;
}
$objectid = uniqid('vvq');
$this->swfobjects[$objectid] = array( 'width' => $atts['width'], 'height' => $atts['height'], 'url' => $content, 'flashvars' => $flashvars );
return '' . sprintf( __('Please enable Javascript and Flash to view this %3$s video.', 'vipers-video-quicktags'), 'http://www.google.com/support/bin/answer.py?answer=23852', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', __('Flash') ) . '';
}
// Output the SWFObject calls that replace all of the placeholders created by the shortcode handlers with the Flash videos (this is per post now)
function SWFObjectCalls( $content ) {
global $wpmu_version;
if ( is_feed() || empty($this->swfobjects) ) return $content;
// Abort if wp_head() is missing from the theme
//if ( FALSE == $this->wpheadrun ) return $content;
$content .= "\n\n";
// Clear outputted calls
$this->swfobjects = array();
return $content;
}
// WordPress' js_escape() won't allow <, >, or " -- instead it converts it to an HTML entity. This is a "fixed" function that's used when needed.
function js_escape($text) {
$safe_text = addslashes($text);
$safe_text = preg_replace('/(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text));
$safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text));
$safe_text = str_replace('\\\n', '\n', $safe_text);
return apply_filters('js_escape', $safe_text, $text);
}
// This function always return FALSE (who woulda guessed?)
function ReturnFalse() { return FALSE; }
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', 'VipersVideoQuicktags' ); function VipersVideoQuicktags() { global $VipersVideoQuicktags; $VipersVideoQuicktags = new VipersVideoQuicktags(); }
?>