Press75.com. Version: 2.2 Author: James Lao Author URI: http://jameslao.com/ */ /** * Gets the embed code for a video. * * @param $postID The post ID of the video * @return The embed code */ function p75GetVideo($postID) { global $wp_embed; // legacy support... 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); if ( !($videoWidth = get_post_meta($postID, '_videowidth', true)) ) $videoWidth = get_option('p75_default_player_width'); if ( !($videoHeight = get_post_meta($postID, '_videoheight', true)) ) $videoHeight = get_option('p75_default_player_height'); return $wp_embed->shortcode( array('width' => $videoWidth, 'height' => $videoHeight), $videoURL ); } /** * Returns true if post has a video. * * @param $postID The post ID * @return True if post has a video, false otherwise */ function p75HasVideo($postID) { return (bool) ( get_post_meta($postID, '_videoembed', true) || get_post_meta($postID, '_videoembed_manual', true) || get_post_meta($postID, 'videoembed', true) ); } // Register the custom JW Media Player embed handler. function p75_jw_player_handler( $matches, $attr, $url, $rawattr ) { static $counter = 1; if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) { $width = (int) $rawattr['width']; $height = (int) $rawattr['height']; } else { list( $width, $height ) = wp_expand_dimensions( get_option('p75_default_player_width'), get_option('p75_default_player_height'), $attr['width'], $attr['height'] ); } $flashvars = get_option('p75_jw_flashvars'); if ( !empty($flashvars) && substr($flashvars, 0, 1)!='&' ) parse_str( $flashvars, $vars ); $file_loc = get_option('p75_jw_files'); if ( substr($file_loc, -1)!='/' ) $file_loc = $file_loc . '/'; $res = "
This text will be replaced
\n"; return $res; } wp_embed_register_handler( 'p75_jw_player', '#http://.*\.(flv|mp4)#i', 'p75_jw_player_handler' ); // RSS feed filter to include videos function p75_feed_video_filter($content, $feed) { global $post; if ( p75HasVideo($post->ID) ) return p75GetVideo($post->ID) . $content; return $content; } add_filter('the_content_feed', 'p75_feed_video_filter', 10, 2); /** * Plugin activation. Set default player width * and height if not present. */ register_activation_hook(__FILE__, 'p75_sveActivate'); function p75_sveActivate() { global $wpdb; // Set default player width and height if not present. add_option('p75_default_player_width', '400'); add_option('p75_default_player_height', '300'); update_option('p75_sve_version', '2.0'); } /** * Post admin hooks */ add_action('admin_menu', "p75_videoAdminInit"); add_action('save_post', 'p75_saveVideo'); /** * Add video posting widget and options page. */ function p75_videoAdminInit() { if( function_exists("add_meta_box") ) { add_meta_box("p75-video-posting", "Post Video Options", "p75_videoPosting", "post", "advanced"); } add_options_page('Simple Video Embedder Options', 'Video Options', 8, 'videooptions', 'p75_videoOptionsAdmin'); } /** * Code for the meta box. */ function p75_videoPosting() { global $post_ID, $wp_embed; $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") . ')
'; echo p75GetVideo($post_ID); echo '
'; } else if ( $videoEmbed ) { echo '
' . __("Video Preview") . ': (' . __("Actual Size") . ')
'; echo stripslashes($videoEmbed); echo '
'; } ?>

" accesskey="p" tabindex="5" name="save"/>

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. if ( is_numeric($_POST['p75-video-width']) ) { if( !update_post_meta($postID, '_videowidth', $_POST['p75-video-width']) ) add_post_meta($postID, '_videowidth', $_POST['p75-video-width']); } else if ( empty($_POST['p75-video-width']) ) delete_post_meta($postID, '_videowidth'); if ( is_numeric($_POST['p75-video-height']) ) { if( !update_post_meta($postID, '_videoheight', $_POST['p75-video-height']) ) add_post_meta($postID, '_videoheight', $_POST['p75-video-height']); } else if ( empty($_POST['p75-video-height']) ) delete_post_meta($postID, '_videoheight'); } } /** * The shortcode for embedding videos in your posts wherever. * * The shortcode accepts four parameters: * id: some post ID, defaults the current post * url: a URL to a video, defaults to null * width: the player width, only works when specifying the URL * height: the player height, only works when specifying the URL * * If you specify the post ID, it will use the video, width, and height * associated with the post. * * If you specify the video URL, it will use that URL to create the embedded player. * If width and height are specified as well, they will be used, otherwise the * defaults will be used as set in the options page. */ function p75_video_short_code($atts, $content=null) { global $post, $wp_embed; extract(shortcode_atts(array( 'id' => $post->ID, 'url' => null, 'width' => -1, 'height' => -1 ), $atts)); // If a URL is passed in, use that. if ( null != $url ) { $width = (-1 != $width) ? $width : get_option('p75_default_player_width'); $height = (-1 != $height) ? $height : get_option('p75_default_player_height'); return $wp_embed->shortcode( array('width' => $width, 'height' => $height), $url ); } // No URL was passed in. return p75GetVideo($id); } add_shortcode('simple_video', 'p75_video_short_code'); function p75_videoOptionsAdmin() { ?>

Simple Video Embedder Options

The default width of the video player if not set.
The default height of the video player if not set.
: The location of the JW player files relative to your WordPress installation.
" target="_blank">: Extra parameters for JW player. For experienced users.

__( 'Press75 Simple Video Plugin 1.2' ), 'readonly' => true, 'option' => 'simple_video_embedder' ); return $blogopts; } add_filter('xmlrpc_blog_options', 'ident_simple_video_plugin'); ?>