YouTube and Google Video as well as videos you host yourself, into WordPress. Credits: Owen Winkler for ButtonSnap and An-archos for help with WP 2.1+ button code. Author: Viper007Bond Author URI: http://www.viper007bond.com/ */ # Nothing to see here! Please use the plugin's options page. You can configure everything there. class VipersVideoQuicktags { var $version = '5.4.0'; var $folder = '/wp-content/plugins/vipers-video-quicktags'; // You shouldn't need to change this ;) var $fullfolderurl; var $settings = array(); var $defaultsettings = array(); var $wpversion; var $jsoutput; var $searchpatterns = array(); // Don't start this plugin until all other plugins have started up function VipersVideoQuicktags() { add_action('plugins_loaded', array(&$this, 'Initalization')); } // Initialization stuff function Initalization() { $this->fullfolderurl = get_bloginfo('wpurl') . $this->folder . '/'; $this->defaultsettings = array( 'youtube' => array( 'button' => 'on', 'width' => '425', 'height' => '355', ), 'googlevideo' => array( 'button' => 'on', 'width' => '400', 'height' => '326', ), 'ifilm' => array( 'button' => NULL, 'width' => '448', 'height' => '365', ), 'metacafe' => array( 'button' => NULL, 'width' => '400', 'height' => '345', ), 'myspace' => array( 'button' => NULL, 'width' => '430', 'height' => '346', ), 'vimeo' => array( 'button' => NULL, 'width' => '400', 'height' => '300', ), 'quicktime' => array( 'button' => NULL, 'width' => '400', 'height' => '300', ), 'videofile' => array( 'button' => NULL, 'width' => '400', 'height' => '300', ), 'flv' => array( 'button' => NULL, 'width' => '400', 'height' => '300', ), 'tinymce_linenumber' => 1, 'usewmp' => 'on', 'alignment' => 'center', 'promptforwh' => NULL, ); $this->settings = get_option('vvq_options'); if ( !is_array($this->settings['youtube']) ) { $this->settings = $this->defaultsettings; } // Set required options added in later versions for people upgrading if ( empty($this->settings['alignment']) ) $this->settings['alignment'] = $this->defaultsettings['alignment']; if ( empty($this->settings['promptforwh']) ) $this->settings['promptforwh'] = $this->defaultsettings['promptforwh']; if ( empty($this->settings['vimeo']['button']) ) $this->settings['vimeo']['button'] = $this->defaultsettings['vimeo']['button']; if ( empty($this->settings['vimeo']['width']) ) $this->settings['vimeo']['width'] = $this->defaultsettings['vimeo']['width']; if ( empty($this->settings['vimeo']['height']) ) $this->settings['vimeo']['height'] = $this->defaultsettings['vimeo']['height']; if ( empty($this->settings['quicktime']['width']) ) $this->settings['quicktime']['width'] = $this->defaultsettings['quicktime']['width']; if ( empty($this->settings['quicktime']['height']) ) $this->settings['quicktime']['height'] = $this->defaultsettings['quicktime']['height']; if ( empty($this->settings['videofile']['width']) ) $this->settings['videofile']['width'] = $this->defaultsettings['videofile']['width']; if ( empty($this->settings['videofile']['height']) ) $this->settings['videofile']['height'] = $this->defaultsettings['videofile']['height']; if ( empty($this->settings['flv']['width']) ) $this->settings['flv']['width'] = $this->defaultsettings['flv']['width']; if ( empty($this->settings['flv']['height']) ) $this->settings['flv']['height'] = $this->defaultsettings['flv']['height']; // Load up the localization file if we're using WordPress in a different language // Place it in the "localization" folder and name it "vvq-[value in wp-config].mo" // A link to some localization files is location at the homepage of this plugin load_plugin_textdomain('vvq', $this->folder . '/localization'); // No sense in running the addbuttons() function if no buttons are to be displayed if ( TRUE === $this->anybuttons() ) add_action('init', array(&$this, 'addbuttons')); // Figure out the WordPress version global $wp_db_version; if ( $wp_db_version > 6124 ) // add_meta_box() isn't defined at this point, so db_version works well here $this->wpversion = 2.5; elseif ( class_exists('WP_Scripts') ) $this->wpversion = 2.1; else $this->wpversion = 2.0; // Loads the needed Javascript file if ( $this->wpversion >= 2.1 ) wp_enqueue_script('vvq', $this->folder . '/vipers-video-quicktags.js', FALSE, $this->version); # Register our hooks and filter add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_head', array(&$this, 'admin_head')); add_action('edit_form_advanced', array(&$this, 'edit_form')); add_action('edit_page_form', array(&$this, 'edit_form')); add_action('wp_head', array(&$this, 'wp_head')); add_filter('the_content', array(&$this, 'replacebbcode'), 1); add_filter('get_the_excerpt', array(&$this, 'replacebbcode'), 1); add_filter('the_content', array(&$this, 'addinlinejs'), 11); add_filter('get_the_excerpt', array(&$this, 'addinlinejs'), 11); // Add support for the text widget add_filter('widget_text', array(&$this, 'replacebbcode'), 1); add_filter('widget_text', array(&$this, 'addinlinejs'), 11); // This is the regex we use to search and then what order the data will come out in // Format is: 'match regex' => array('type' => 'videotype', results => array( ... )) // The type is used internally and the results array is the order in which the data will be returned (width, height, url, + anything else you want) $this->searchpatterns = array ( '#\[youtube\]http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=)([\w-]+)(.*?)\[/youtube\]#i' => array('type' => 'youtube', 'results' => array('', '', 'videoid')), '#\[youtube\]([\w-]+)\[/youtube\]#i' => array('type' => 'youtube', 'results' => array('videoid')), '#\[youtube width="(\d+)" height="(\d+)"]http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=)([\w-]+)(.*?)\[\/youtube]#i' => array('type' => 'youtube', 'results' => array('width', 'height', '', '', 'videoid')), '#\[youtube width="(\d+)" height="(\d+)"]([\w-]+)\[\/youtube]#i' => array('type' => 'youtube', 'results' => array('width', 'height', 'videoid')), '#\[googlevideo]http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)\[\/googlevideo]#i' => array('type' => 'googlevideo', 'results' => array('', 'videoid')), '#\[googlevideo]([\d-]+)\[\/googlevideo]#i' => array('type' => 'googlevideo', 'results' => array('videoid')), '#\[googlevideo width="(\d+)" height="(\d+)"]http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)\[\/googlevideo]#i' => array('type' => 'googlevideo', 'results' => array('width', 'height', '', 'videoid')), '#\[googlevideo width="(\d+)" height="(\d+)"]([\d-]+)\[\/googlevideo]#i' => array('type' => 'googlevideo', 'results' => array('width', 'height', 'videoid')), '#\[stage6]http://(www.stage6.com|stage6.com|stage6.divx.com)/(.*?)/video/([0-9]+)(.*?)\[\/stage6]#i' => array('type' => 'stage6', 'results' => array('', '', 'videoid')), '#\[stage6 width="(\d+)" height="(\d+)"]http://(www.stage6.com|stage6.com|stage6.divx.com)/(.*?)/video/([0-9]+)(.*?)\[\/stage6]#i' => array('type' => 'stage6', 'results' => array('width', 'height', '', '', 'videoid')), '#\[ifilm]http://(www.ifilm|ifilm)\.com/video/([\d-]+)(.*?)\[\/ifilm]#i' => array('type' => 'ifilm', 'results' => array('', 'videoid')), '#\[ifilm]([\d-]+)\[\/ifilm]#i' => array('type' => 'ifilm', 'results' => array('videoid')), '#\[ifilm width="(\d+)" height="(\d+)"]http://(www.ifilm|ifilm)\.com/video/([\d-]+)(.*?)\[\/ifilm]#i' => array('type' => 'ifilm', 'results' => array('width', 'height', '', 'videoid')), '#\[ifilm width="(\d+)" height="(\d+)"]([\d-]+)\[\/ifilm]#i' => array('type' => 'ifilm', 'results' => array('width', 'height', 'videoid')), '#\[metacafe]http://(www.metacafe|metacafe)\.com/watch/([\d-]+)/(.*?)/\[\/metacafe]#i' => array('type' => 'metacafe', 'results' => array('', 'videoid', 'videoname')), '#\[metacafe width="(\d+)" height="(\d+)"]http://(www.metacafe|metacafe)\.com/watch/([\d-]+)/([\d-]+)/\[\/metacafe]#i' => array('type' => 'metacafe', 'results' => array('width', 'height', '', 'videoid', 'videoname')), '#\[myspace]http://vids\.myspace\.com/index\.cfm\?fuseaction=vids\.individual(&|&)videoid=(\d+)\[\/myspace]#i' => array('type' => 'myspace', 'results' => array('', 'videoid')), '#\[myspace width="(\d+)" height="(\d+)"]http://vids\.myspace\.com/index\.cfm\?fuseaction=vids\.individual(&|&)videoid=(\d+)\[\/myspace]#i' => array('type' => 'ifilm', 'results' => array('width', 'height', '', 'videoid')), '#\[vimeo]http://(www.vimeo|vimeo)\.com(/|/clip:)([\d-]+)(.*?)\[\/vimeo]#i' => array('type' => 'vimeo', 'results' => array('', '', 'videoid')), '#\[vimeo]([\d-]+)\[\/vimeo]#i' => array('type' => 'vimeo', 'results' => array('videoid')), '#\[vimeo width="(\d+)" height="(\d+)"]http://(www.vimeo|vimeo)\.com(/|/clip:)([\d-]+)(.*?)\[\/vimeo]#i' => array('type' => 'vimeo', 'results' => array('width', 'height', '', '', 'videoid')), '#\[vimeo width="(\d+)" height="(\d+)"]([\d-]+)\[\/vimeo]#i' => array('type' => 'vimeo', 'results' => array('width', 'height', 'videoid')), '#\[flv](.*?)\[\/flv]#i' => array('type' => 'flv', 'results' => array('videoid')), '#\[flv width="(\d+)" height="(\d+)"](.*?)\[\/flv]#i' => array('type' => 'flv', 'results' => array('width', 'height', 'videoid')), // VERY old (v2.x) placeholder handling '#\#i' => array('type' => 'youtube', 'results' => array('videoid')), '#\#i' => array('type' => 'googlevideo', 'results' => array('videoid')), ); $this->searchpatterns = apply_filters( 'vvq_searchpatterns', $this->searchpatterns ); } // Checks to see if any buttons at all are to be displayed function anybuttons() { if ('on' == $this->settings['youtube']['button'] || 'on' == $this->settings['googlevideo']['button'] || 'on' == $this->settings['ifilm']['button'] || 'on' == $this->settings['metacafe']['button'] || 'on' == $this->settings['myspace']['button'] || 'on' == $this->settings['vimeo']['button'] || 'on' == $this->settings['quicktime']['button'] || 'on' == $this->settings['videofile']['button'] || 'on' == $this->settings['flv']['button'] ) return TRUE; else return FALSE; } // Make our buttons on the write screens function addbuttons() { // Don't bother doing this stuff if the current user lacks permissions as they'll never see the pages if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) return; // Create the buttons based on the WP version number if ( 'true' == get_user_option('rich_editing') && $this->wpversion >= 2.1 ) { // WordPress 2.5+ (TinyMCE 3.x) if ( $this->wpversion >= 2.5 ) { add_filter( 'mce_external_plugins', array(&$this, 'mce_external_plugins') ); add_filter( 'mce_buttons_3', array(&$this, 'mce_buttons') ); add_action( 'admin_head', array(&$this, 'buttonhider') ); } // WordPress 2.1+ (TinyMCE 2.x) else { add_filter('mce_plugins', array(&$this, 'mce_plugins')); if ( 1 != $this->settings['tinymce_linenumber'] ) { add_filter('mce_buttons_' . $this->settings['tinymce_linenumber'], array(&$this, 'mce_buttons')); } else { add_filter('mce_buttons', array(&$this, 'mce_buttons')); } add_action('tinymce_before_init', array(&$this, 'tinymce_before_init')); add_action('admin_head', array(&$this, 'buttonhider')); } } else { buttonsnap_separator(); if ( 'on' == $this->settings['youtube']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/youtube.png', __('YouTube', 'vvq'), 'VVQInsertVideoSite("' . __('YouTube', 'vvq') . '", "http://www.youtube.com/watch?v=JzqumbhfxRo", "youtube");'); if ( 'on' == $this->settings['googlevideo']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/googlevideo.png', __('GVideo', 'vvq'), 'VVQInsertVideoSite("' . __('Google Video', 'vvq') . '", "http://video.google.com/videoplay?docid=3688185030664621355", "googlevideo");'); if ( 'on' == $this->settings['ifilm']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/ifilm.png', __('IFILM', 'vvq'), 'VVQInsertVideoSite("' . __('IFILM', 'vvq') . '", "http://www.ifilm.com/video/2710582", "ifilm");'); if ( 'on' == $this->settings['metacafe']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/metacafe.png', __('Metacafe', 'vvq'), 'VVQInsertVideoSite("' . __('Metacafe', 'vvq') . '", "http://www.metacafe.com/watch/299980/italian_police_lamborghini/", "metacafe");'); if ( 'on' == $this->settings['myspace']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/myspace.png', __('MySpace', 'vvq'), 'VVQInsertVideoSite("' . __('MySpace', 'vvq') . '", "http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=1387215221", "myspace");'); if ( 'on' == $this->settings['vimeo']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/vimeo.png', __('Vimeo', 'vvq'), 'VVQInsertVideoSite("' . __('Vimeo', 'vvq') . '", "http://www.vimeo.com/27810", "vimeo");'); if ( 'on' == $this->settings['quicktime']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/quicktime.png', __('QT', 'vvq'), 'VVQInsertVideoFile("' . __('Quicktime', 'vvq') . '", "mov", "quicktime");'); if ( 'on' == $this->settings['videofile']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/videofile.png', __('Video File', 'vvq'), 'VVQInsertVideoFile("", "avi", "video");'); if ( 'on' == $this->settings['flv']['button'] ) buttonsnap_jsbutton($this->fullfolderurl . 'images/flv.png', __('FLV', 'vvq'), 'VVQInsertVideoFile("' . __('FLV', 'vvq') . '", "flv", "flv");'); } } // TinyMCE integration hooks function mce_external_plugins( $plugins ) { // WordPress 2.5 $plugins['vipersvideoquicktags'] = get_bloginfo('wpurl') . $this->folder . '/resources/tinymce3/editor_plugin.js'; return $plugins; } function mce_plugins($plugins) { // WordPress 2.1 array_push($plugins, 'vipersvideoquicktags'); return $plugins; } function mce_buttons($buttons) { if ( $this->wpversion < 2.5 ) { if ( 1 == $this->settings['tinymce_linenumber'] ) array_push($buttons, 'separator'); array_push( $buttons, 'vipersvideoquicktags' ); } else { array_push( $buttons, 'vvqYouTube', 'vvqGoogleVideo', 'vvqIFILM', 'vvqMetaCafe', 'vvqMySpace', 'vvqVimeo', /*'vvqQuicktime', 'vvqVideoFile',*/ 'vvqFLV' ); } return $buttons; } function tinymce_before_init() { // WordPress 2.1 echo 'tinyMCE.loadPlugin("vipersvideoquicktags", "' . $this->fullfolderurl . 'resources/tinymce2/");'; } // Hide TinnyMCE buttons the user doesn't want to see in WP v2.1+ function buttonhider() { echo "\n"; } function admin_menu() { add_options_page(__("Viper's Video Quicktags Configuration", 'vvq'), __('Video Quicktags', 'vvq'), 'manage_options', basename(__FILE__), array(&$this, 'optionspage')); } // Handle form submit and add the Javascript file function admin_head() { // Handle options page submits if ( $_POST && basename(__FILE__) == $_GET['page'] ) { if ( $_POST['defaults'] ) { $this->settings = $this->defaultsettings; } else { $this->settings = array( 'youtube' => array( 'button' => $_POST['youtube']['button'], 'width' => (int) $_POST['youtube']['width'], 'height' => (int) $_POST['youtube']['height'], ), 'googlevideo' => array( 'button' => $_POST['googlevideo']['button'], 'width' => (int) $_POST['googlevideo']['width'], 'height' => (int) $_POST['googlevideo']['height'], ), 'ifilm' => array( 'button' => $_POST['ifilm']['button'], 'width' => (int) $_POST['ifilm']['width'], 'height' => (int) $_POST['ifilm']['height'], ), 'metacafe' => array( 'button' => $_POST['metacafe']['button'], 'width' => (int) $_POST['metacafe']['width'], 'height' => (int) $_POST['metacafe']['height'], ), 'myspace' => array( 'button' => $_POST['myspace']['button'], 'width' => (int) $_POST['myspace']['width'], 'height' => (int) $_POST['myspace']['height'], ), 'vimeo' => array( 'button' => $_POST['vimeo']['button'], 'width' => (int) $_POST['vimeo']['width'], 'height' => (int) $_POST['vimeo']['height'], ), 'quicktime' => array( 'button' => $_POST['quicktime']['button'], 'width' => (int) $_POST['quicktime']['width'], 'height' => (int) $_POST['quicktime']['height'], ), 'videofile' => array( 'button' => $_POST['videofile']['button'], 'width' => (int) $_POST['videofile']['width'], 'height' => (int) $_POST['videofile']['height'], ), 'flv' => array( 'button' => $_POST['flv']['button'], 'width' => (int) $_POST['flv']['width'], 'height' => (int) $_POST['flv']['height'], ), 'tinymce_linenumber' => (int) $_POST['tinymce_linenumber'], 'usewmp' => $_POST['usewmp'], 'alignment' => $_POST['alignment'], 'promptforwh' => $_POST['promptforwh'], ); } update_option('vvq_options', $this->settings); } } // Outputs the needed Javascript (not in a .js file as it's dynamic and just easier this way) function edit_form() { ?>
' . __('Settings reset to defaults.', 'vvq') . '
' . "\n"; elseif ( !empty($_POST) ) echo "\n" . '' . __('Settings saved.') . '