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 = "
' . __("Video Preview") . ': (' . __("Actual Size") . ')
" 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() { ?>