= 400
$output = unserialize( curl_exec( $ch ) );
$output = $output[0][$info];
if ( curl_error( $ch ) != null ) {
$output = new WP_Error( 'vimeo_info_retrieval', __( 'Error retrieving video information from the URL ' . $videoinfo_url . '.
Libcurl error ' . curl_errno( $ch ) . ': ' . curl_error( $ch ) . '. If opening that URL in your web browser returns anything else than an error page, the problem may be related to your web server and might be something your host administrator can solve.' ) );
}
curl_close( $ch );
return $output;
}
};
// Blip.tv Functions
function getBliptvInfo( $id ) {
$videoinfo_url = "http://blip.tv/players/episode/$id?skin=rss";
$xml = simplexml_load_file( $videoinfo_url );
if ( $xml == false ) {
return new WP_Error( 'bliptv_info_retrieval', __( 'Error retrieving video information from the URL ' . $videoinfo_url . '. If opening that URL in your web browser returns anything else than an error page, the problem may be related to your web server and might be something your host administrator can solve.' ) );
} else {
$result = $xml->xpath( "/rss/channel/item/media:thumbnail/@url" );
$thumbnail = (string) $result[0]['url'];
return $thumbnail;
}
}
// Justin.tv Functions
function getJustintvInfo( $id ) {
$xml = simplexml_load_file( "http://api.justin.tv/api/clip/show/$id.xml" );
return (string) $xml->clip->image_url_large;
}
// Get DailyMotion Thumbnail
function getDailyMotionThumbnail( $id ) {
if ( ! function_exists( 'curl_init' ) ) {
return null;
} else {
$ch = curl_init();
$videoinfo_url = "https://api.dailymotion.com/video/$id?fields=thumbnail_url";
curl_setopt( $ch, CURLOPT_URL, $videoinfo_url );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_FAILONERROR, true ); // Return an error for curl_error() processing if HTTP response code >= 400
$output = curl_exec( $ch );
$output = json_decode( $output );
$output = $output->thumbnail_url;
if ( curl_error( $ch ) != null ) {
$output = new WP_Error( 'dailymotion_info_retrieval', __( 'Error retrieving video information from the URL ' . $videoinfo_url . '.
Libcurl error ' . curl_errno( $ch ) . ': ' . curl_error( $ch ) . '. If opening that URL in your web browser returns anything else than an error page, the problem may be related to your web server and might be something your host administrator can solve.' ) );
}
curl_close( $ch ); // Moved here to allow curl_error() operation above. Was previously below curl_exec() call.
return $output;
}
};
// Metacafe
function getMetacafeThumbnail( $id ) {
$videoinfo_url = "http://www.metacafe.com/api/item/$id/";
$xml = simplexml_load_file( $videoinfo_url );
if ( $xml == false ) {
return new WP_Error( 'metacafe_info_retrieval', __( 'Error retrieving video information from the URL ' . $videoinfo_url . '.
Libcurl error ' . curl_errno( $ch ) . ': ' . curl_error( $ch ) . '. If opening that URL in your web browser returns anything else than an error page, the problem may be related to your web server and might be something your host administrator can solve.' ) );
} else {
$result = $xml->xpath( "/rss/channel/item/media:thumbnail/@url" );
$thumbnail = (string) $result[0]['url'];
return $thumbnail;
}
};
//
// The Main Event
//
function get_video_thumbnail( $post_id = null ) {
// Get the post ID if none is provided
if ( $post_id == null OR $post_id == '' ) $post_id = get_the_ID();
// Check to see if thumbnail has already been found
if( ( $thumbnail_meta = get_post_meta( $post_id, '_video_thumbnail', true ) ) != '' ) {
return $thumbnail_meta;
}
// If the thumbnail isn't stored in custom meta, fetch a thumbnail
else {
echo "
";
var_dump(get_post_custom($post_id));
echo "";
// Get the post or custom field to search
if ( $video_key = get_option( 'video_thumbnails_custom_field' ) ) {
$markup = get_post_meta( $post_id, $video_key, true );
} else {
$post_array = get_post( $post_id );
$markup = $post_array->post_content;
$markup = apply_filters( 'the_content', $markup );
}
$new_thumbnail = null;
/*echo "video_key = " . $video_key . ""; echo "
markeup = " . $markup . "";*/ // Simple Video Embedder Compatibility if ( function_exists( 'p75HasVideo' ) ) { if ( p75HasVideo( $post_id ) ) { $markup = p75GetVideo( $post_id ); } } // Checks for the old standard YouTube embed preg_match( '##s', $markup, $matches ); // More comprehensive search for YouTube embed, redundant but necessary until more testing is completed if ( !isset( $matches[1] ) ) { preg_match( '#https?://www\.youtube(?:\-nocookie)?\.com/[ve]/([A-Za-z0-9\-_]+)#', $markup, $matches ); } // Checks for YouTube iframe, the new standard since at least 2011 if ( !isset( $matches[1] ) ) { preg_match( '#https?://www\.youtube(?:\-nocookie)?\.com/embed/([A-Za-z0-9\-_]+)#', $markup, $matches ); } // Checks for any YouTube URL. After http(s) support a or v for Youtube Lyte and v or vh for Smart Youtube plugin if ( !isset( $matches[1] ) ) { preg_match( '#(?:https?(?:a|vh?)?://)?(?:www\.)?youtube(?:\-nocookie)?\.com/watch\?.*v=([A-Za-z0-9\-_]+)#', $markup, $matches ); } // Checks for any shortened youtu.be URL. After http(s) a or v for Youtube Lyte and v or vh for Smart Youtube plugin if ( !isset( $matches[1] ) ) { preg_match( '#(?:https?(?:a|vh?)?://)?youtu\.be/([A-Za-z0-9\-_]+)#', $markup, $matches ); } // Checks for YouTube Lyte if ( !isset( $matches[1] ) && function_exists( 'lyte_parse' ) ) { preg_match( '#
' . curl_error( $ch ) . '';
}
$error = new WP_Error( 'thumbnail_retrieval', __( 'Error retrieving a thumbnail from the URL ' . $new_thumbnail . '' . $curl_error . '. If opening that URL in your web browser shows an image, the problem may be related to your web server and might be something your server administrator can solve.' ) );
}
curl_close( $ch );
if ( $error != null ) {
return $error;
} else {
$upload = wp_upload_bits( basename( $new_thumbnail ), null, $image_contents );
$new_thumbnail = $upload['url'];
$filename = $upload['file'];
$wp_filetype = wp_check_filetype( basename( $filename ), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => get_the_title($post_id),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
// you must first include the image.php file
// for the function wp_generate_attachment_metadata() to work
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
}
// Add hidden custom field with thumbnail URL
if ( !update_post_meta( $post_id, '_video_thumbnail', $new_thumbnail ) ) add_post_meta( $post_id, '_video_thumbnail', $new_thumbnail, true );
// Set attachment as featured image if enabled
if ( get_option( 'video_thumbnails_set_featured' ) == 1 && get_option( 'video_thumbnails_save_media' ) == 1 && get_post_meta( $post_id, '_thumbnail_id', true ) == '' ) {
if ( !update_post_meta( $post_id, '_thumbnail_id', $attach_id ) ) add_post_meta( $post_id, '_thumbnail_id', $attach_id, true );
}
}
return $new_thumbnail;
}
};
// Echo thumbnail
function video_thumbnail( $post_id = null ) {
if ( ( $video_thumbnail = get_video_thumbnail( $post_id ) ) == null ) { echo plugins_url() . '/video-thumbnails/default.jpg'; }
else { echo $video_thumbnail; }
};
// Create Meta Fields on Edit Page
add_action( 'admin_init', 'video_thumbnail_admin_init' );
function video_thumbnail_admin_init() {
$video_thumbnails_post_types = get_option( 'video_thumbnails_post_types' );
if ( is_array( $video_thumbnails_post_types ) ) {
foreach ( $video_thumbnails_post_types as $type ) {
add_meta_box( 'video_thumbnail', 'Video Thumbnail', 'video_thumbnail_admin', $type, 'side', 'low' );
}
}
}
function video_thumbnail_admin() {
global $post;
$custom = get_post_custom( $post->ID );
$video_thumbnail = $custom["_video_thumbnail"][0];
if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) {
echo 'We didn\'t find a video thumbnail for this post.
'; echo ''; } } else { if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) { echo ''; } else { echo 'A video thumbnail will be found for this post when it is published.
'; } } } // AJAX Searching if ( in_array( basename( $_SERVER['PHP_SELF'] ), apply_filters( 'video_thumbnails_editor_pages', array( 'post-new.php', 'page-new.php', 'post.php', 'page.php' ) ) ) ) { add_action( 'admin_head', 'video_thumbnails_ajax' ); } function video_thumbnails_ajax() { ?> get_error_message(); } else if ( $video_thumbnail != null ) { echo 'Say thanks by donating, any amount is appreciated!
Scan all of your past posts for video thumbnails. Be sure to save any settings before running the scan.