url = $url; } /** * Sets the width of the video to use instead of the default. */ function setWidth($width) { $this->width = $width; } function setHeight($height) { $this->height = $height; } function setDefaultWidth($width) { $this->defaultWidth = $width; } /** * Generates the proper embed code. */ function getEmbedCode() { // Watch out for flv and mp4's if( preg_match("/(\.flv|\.mp4)$/i", $this->url) ) { return $this->getJWPlayer(); } switch( $this->getDomain() ) { case "youtube": return $this->getYouTube(); case 'vimeo': return $this->getVimeo(); case 'metacafe': return $this->getMetacafe(); case 'seesmic': return $this->getSeesmic(); case 'video.google': return $this->getGoogleVideo(); case 'revver': return $this->getRevver(); default: return false; } } /** * Determine the domain name of the video. */ function getDomain() { $matches; preg_match("#^http://(?:www\.)?([\.a-z0-9]+)\.(?:com|tv|net)#i", $this->url, $matches); return $matches[1]; } function calcWH($playerW, $playerH) { if( $this->width && $this->height ) return array($this->width, $this->height); else if( $this->width ) return array($this->width, ($playerH/$playerW)*$this->width); else if( $this->height ) return array(($playerW/$playerH)*$this->height, $this->height); else return array($this->defaultWidth, ($playerH/$playerW)*$this->defaultWidth); } function getJWPlayer() { list($width, $height) = $this->calcWH(500, 400); return '
Get the Flash Player to see this player.
'; } function getYouTube() { $matches = array(); // example: http://www.youtube.com/watch?v=R7yfISlGLNU preg_match("#http://(?:www\.)?youtube\.com/watch\?v=([_\-a-z0-9]+)#i", $this->url, $matches); if( strstr($this->url, "&fmt=22") ) // Check for HD { list($width, $height) = $this->calcWH(850, 500); return ''; } else { list($width, $height) = $this->calcWH(425, 344); return ''; } } function getVimeo() { $matches = array(); // example: http://vimeo.com/127768 preg_match("#http://(?:www\.)?vimeo\.com/([0-9]+)#i", $this->url, $matches); list($width, $height) = $this->calcWH(400, 300); return ''; } function getMetacafe() { $matches = array(); // example: http://www.metacafe.com/watch/2467303/hair_washing_toffee/ preg_match("#http://(?:www\.)?metacafe\.com/watch/([0-9]+)/([_a-z0-9]+)#i", $this->url, $matches); list($width, $height) = $this->calcWH(400, 345); return ' '; } function getRevver() { $matches = array(); // example: http://revver.com/video/1373455/animator-vs-animation-ii-original/ preg_match("#http://(?:www\.)?revver\.com/video/([0-9]+)#i", $this->url, $matches); list($width, $height) = $this->calcWH(480, 392); return ''; } function getGoogleVideo() { $matches = array(); // example: http://video.google.com/videoplay?docid=-8111235669135653751 preg_match("#http://(?:www\.)?video\.google\.com/videoplay\?docid=(\-[0-9]+)#i", $this->url, $matches); list($width, $height) = $this->calcWH(400, 362); return ' '; } /* Viddler doesn't use video IDs so there's no apparent way to create embed code... function getViddler() { $matches = array(); // example: http://www.viddler.com/explore/Powermat/videos/5/ preg_match("#http://(?:www\.)?revver\.com/video/([0-9]+)/#i", $this->url, $matches); return ''; } */ function getSeesmic() { $matches = array(); // example: http://seesmic.com/threads/veyy9lwnnm preg_match("#http://(?:www\.)?seesmic\.com/threads/([a-z0-9]+)#i", $this->url, $matches); list($width, $height) = $this->calcWH(435, 355); return ""; } } add_action('admin_menu', "p75_videoAdminInit"); add_action('save_post', 'p75_saveVideo'); function p75_videoAdminInit() { if( function_exists("add_meta_box") ) { add_meta_box("p75-video-posting", "Video Options", "p75_videoPosting", "post", "advanced"); } } /** * Code for the meta box. */ function p75_videoPosting() { global $post_ID; $videoURL = get_post_meta($post_ID, '_videoembed', true); $videoHeight = get_post_meta($post_ID, '_videoheight', true); $videoWidth = get_post_meta($post_ID, '_videowidth', true); $videoEmbed = get_post_meta($post_ID, '_videoembed_manual', true); ?>




Video Preview: (Actual Size)
'; $videoEmbedder = new p75VideoEmbedder($videoURL); $videoEmbedder->setDefaultWidth(P75_VIDEO_W); $videoEmbedder->setHeight($videoHeight); $videoEmbedder->setWidth($videoWidth); echo $videoEmbedder->getEmbedCode(); echo '
'; } else if ( $videoEmbed ) { echo '
Video Preview: (Actual Size)
'; echo stripslashes($videoEmbed); echo '
'; } ?>

Preview Video'; } /** * Saves the thumbnail image as a meta field associated * with the current post. Runs when a post is saved. */ function p75_saveVideo( $postID ) { global $wpdb; // Get the correct post ID if revision. if ( $wpdb->get_var("SELECT post_type FROM $wpdb->posts WHERE ID=$postID")=='revision') $postID = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=$postID"); // Trim white space just in case. $_POST['p75-video-embed'] = trim($_POST['p75-video-embed']); $_POST['p75-video-url'] = trim($_POST['p75-video-url']); $_POST['p75-video-width'] = trim($_POST['p75-video-width']); $_POST['p75-video-height'] = trim($_POST['p75-video-height']); if ( $_POST['p75-remove-video'] ) { // Remove video delete_post_meta($postID, '_videoembed'); delete_post_meta($postID, '_videowidth'); delete_post_meta($postID, '_videoheight'); delete_post_meta($postID, '_videoembed_manual'); } elseif ( $_POST['p75-video-embed'] ) { // Save video embed code. if( !update_post_meta($postID, '_videoembed_manual', $_POST['p75-video-embed'] ) ) add_post_meta($postID, '_videoembed_manual', $_POST['p75-video-embed'] ); delete_post_meta($postID, '_videoembed'); delete_post_meta($postID, '_videowidth'); delete_post_meta($postID, '_videoheight'); } elseif ( $_POST['p75-video-url'] ) { // Save video URL. if( !update_post_meta($postID, '_videoembed', $_POST['p75-video-url'] ) ) add_post_meta($postID, '_videoembed', $_POST['p75-video-url'] ); delete_post_meta($postID, '_videoembed_manual'); // Save width and height. $videoWidth = is_numeric($_POST['p75-video-width']) ? $_POST['p75-video-width'] : ""; if( !update_post_meta($postID, '_videowidth', $videoWidth) ) add_post_meta($postID, '_videowidth', $videoWidth); $videoHeight = is_numeric($_POST['p75-video-height']) ? $_POST['p75-video-height'] : ""; if( !update_post_meta($postID, '_videoheight', $videoHeight) ) add_post_meta($postID, '_videoheight', $videoHeight); } } /** * Gets the embed code for a video. * * @param $postID The post ID of the video * @return The embed code */ function GetVideo($postID) { if ( $videoURL = get_post_meta($postID, 'videoembed', true) ) return $videoURL; if ( $videoEmbed = get_post_meta($postID, '_videoembed_manual', true ) ) return $videoEmbed; $videoURL = get_post_meta($postID, '_videoembed', true); $videoWidth = get_post_meta($postID, '_videowidth', true); $videoHeight = get_post_meta($postID, '_videoheight', true); $videoEmbedder = new p75VideoEmbedder($videoURL); $videoEmbedder->setDefaultWidth(P75_VIDEO_W); $videoEmbedder->setWidth($videoWidth); $videoEmbedder->setHeight($videoHeight); return $videoEmbedder->getEmbedCode(); } ?>