';
}
?>
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();
}
?>