Help with saving and loading youtube thumbs

I would like to include this feature into my script. Im not really sure how though. Can anyone help me?

[php]//
// 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 and still exists as a file
if ( ( ( $thumbnail_meta = get_post_meta( $post_id, '_video_thumbnail', true ) ) != '' ) && wp_remote_retrieve_response_code( wp_remote_head( $thumbnail_meta ) ) === '200' ) {
	return $thumbnail_meta;
}
// If the thumbnail isn't stored in custom meta, fetch a thumbnail
else {

	// Gets the post's content
	$post_array = get_post( $post_id );
	$markup = $post_array->post_content;
	$markup = apply_filters( 'the_content', $markup );
	$new_thumbnail = null;

	// 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( '#<object[^>]+>.+?https?://www\.youtube\.com/[ve]/([A-Za-z0-9\-_]+).+?</object>#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\.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\.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\.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( '#<div class="lyte" id="([A-Za-z0-9\-_]+)"#', $markup, $matches );
	}

	// If we've found a YouTube video ID, create the thumbnail URL
	if ( isset( $matches[1] ) ) {
		$youtube_thumbnail = 'http://img.youtube.com/vi/' . $matches[1] . '/0.jpg';

		// Check to make sure it's an actual thumbnail
		if ( ! function_exists( 'curl_init' ) ) {
			$new_thumbnail = $youtube_thumbnail;
		} else {
			$ch = curl_init( $youtube_thumbnail );
			curl_setopt( $ch, CURLOPT_NOBODY, true );
			curl_exec( $ch );
			$retcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
			// $retcode > 400 -> not found, $retcode = 200, found.
			curl_close( $ch );
			if ( $retcode == 200 ) {
				$new_thumbnail = $youtube_thumbnail;
			}
		}
	}[/php]

Here is my script

[php]<?php

global $templateimagepath,$isAdmin ;
$progressImage = $templateimagepath.‘progress.gif’ ;
$playpath = ‘’ ;
$termsLink = “<a href=’”.( S_PATH ).‘terms’."’>terms of service" ;
$videos_allowed = ( VEED_OK );
$music_allowed = ( MUSIC_OK );
$images_allowed = ( IMAGE_OK );
$games_allowed = ( GAMES_OK );
$embed_ok = ( EMBED_OK );
$noembed = ( NO_EMBED );

$nomediaallowed = (!$videos_allowed) && (!$music_allowed) && (!$images_allowed) && (!$games_allowed) && (!$embed_ok);
if ($isAdmin) {
$videos_allowed = true ;
$music_allowed = true ;
$images_allowed = true ;
$games_allowed = true ;
$nomediaallowed = false ;
$noembed = false ;
/////// smarty assign here //////////
}
if ($nomediaallowed) {
$mediaallowed = ‘’ ;
}
else {
$mediaallowed = 'Media Type allowed: ';
$mediaallowed .= ($videos_allowed) ? ‘videos ’ : ‘’;
$vi_deos = ($videos_allowed) ? ’ videos’ : ‘’;
$mediaallowed .= ($music_allowed) ? ‘music ’ : ‘’;
$mu_sic = ($music_allowed) ? ’ music’ : ‘’;
$mediaallowed .= ($images_allowed) ? ‘images ’ : ‘’;
$im_ages = ($images_allowed) ? ’ images’ : ‘’;
$mediaallowed .= ($games_allowed) ? ‘games ’ : ‘’;
$ga_mes = ($games_allowed) ? ’ games’ : ‘’;

	$mediaallowed .= '</b>';
	//$media_Allowed = array($vi_deos =>'Video',$mu_sic =>'Music',$im_ages =>'Images',$embed_ok =>'Embed');

}
$uploadsdisabled = ($nomediaallowed) && ($noembed) ;
$errorresult = ‘ok’ ;
$res = 0 ;
function postData() {
return “&name=”.stripslashes($_POST[‘name’])."&title=".stripslashes($_POST[‘title’])."&dis=".stripslashes($_POST[‘dis’])."&tags=".stripslashes($_POST[‘tags’])."&group=".stripslashes($_POST[‘group’])."&url=".stripslashes($_FILES[‘url’][‘name’])."&thumb=".stripslashes($_FILES[‘thumbnail’][‘name’])."&kat=".stripslashes($_POST[‘kat’])."&thumbnail=".stripslashes($_POST[‘thumbnail’]) ;
}
function sendAdminNotice($poster, $file, $title, $catid) {
global $db;
$fromAdd = “New Upload http://".$_SERVER[‘SERVER_NAME’]."” ;
$messageBody = getEmail(“email_upload”) ;
$messageBody = str_replace("[MANAGELINK]", “http://”.$_SERVER[‘SERVER_NAME’]."?id=103", $messageBody) ;
$messageBody = str_replace("[POSTER]", $poster, $messageBody) ;
/* Get Link /
$db->query(“SELECT name FROM category WHERE id = “.$catid) ;
$resKat = $db->fetch() ;
$kat = url_encode($resKat[‘name’]) ;
$title = url_encode(stripslashes(alphanum($title))) ;
$mediaLink = S_PATH.“play/”.$kat.”/”.$title ;
$messageBody = str_replace("[MEDIALINK]", $mediaLink, $messageBody) ;
$filelink = S_PATH.“uploads/$file” ;
$messageBody = str_replace("[FILELINK]", $filelink, $messageBody) ;
$headers = “From: $fromAdd” ;
$headers = “From: New Uploads <”.getSetting(‘contact_email’, $db).">>\r\n".“Reply-To: “.getSetting(‘contact_email’, $db).”\r\n”.“X-Mailer: PHP/”.phpversion() ;
mail(getSetting(“contact_email”, $db), ‘New media Uploaded’, $messageBody, $headers) ;
}
function chk_form($input) {
$input = preg_replace(’/[^a-zA-Z0-9 ]/s’, ’ ', $input);
$input = trim($input);
$input = stripslashes($input);
$input = htmlspecialchars($input);
return $input;
};
//$db = new mysql($db_host, $db_user, $db_password, $db_database) ;
//get encoding settings
$embedded = trim($_POST[‘embedcode’]) != ‘’ ? 1 : 0 ;
//thumbnail size
$sw = getSetting(“thumb_w2”, $db) ;
$lw = getSetting(“thumb_w1”, $db) ;
$sh = getSetting(“thumb_h2”, $db) ;
$lh = getSetting(“thumb_h1”, $db) ;
{ // form is submitted // 01
if (isset($_POST[‘title’]) && strlen($_POST[‘title’]) > 0) { //title is posted upon form submission 02
if (isset($_POST[‘kat’])) { // category is post upon form submission 03
if (isset($_POST[‘dis’]) && strlen($_POST[‘dis’]) > 0) { //discription posted 04
if (isset($_POST[‘name’])) { //this is the poster’s name //
//set default values for db insert
$title = chk_form($_POST[‘title’]);
$title = alphanum($title) ;
$title = quote_smart(apply_word_censor2($title)) ;
$title = str_replace("
", “x”, $title) ;
$cat = quote_smart($_POST[‘kat’]) ;
$group = quote_smart($_POST[‘groups’]) ;
$description = chk_form($_POST[‘dis’]);
$description = quote_smart($description) ;
$embedcode = quote_smart($_POST[‘embedcode’]) ;
$description = quote_smart(apply_word_censor2($description)) ;
$tags = chk_form($_POST[‘tags’]);
$tags = quote_smart($tags) ;
$tags = alphaNumComma($tags) ;
$mediaurl = “” ;
$thumb = “” ;
$poster = quote_smart($_POST[‘name’]) ;
$extern = “false” ;
$status = “false” ;
$useraw = “false” ;
$url = “” ;
//get thumbnail time
$thumbtime = isset($_POST[‘thumb’]) && $_POST[‘thumb’] != 0 ? $POST[‘thumb’] : getSetting(‘default_thumbtime’, $db) ;
$int = 0 ;
$db->query(“SELECT * FROM media WHERE title = '”.quote_smart($title)."’;") ;
//make title unique
while ($db->numrows() >= 1) {
$int++ ;
$title .= $int ;
$db->query(“SELECT * FROM media WHERE title = '”.quote_smart($title)."’;") ;
}
//$filename = md5(uniqid(rand())) . '
’ . url_clean($title);
//$filename = url_clean($title);
$url = url_encode($title) ;
$title = quote_smart($title) ;
//set the time
$added = time() ;
if ($isAdmin) {
if (isset($_POST[‘day’]) && isset($_POST[‘month’]) && isset($_POST[‘year’]) && isset($_POST[‘hour’]) && isset($_POST[‘minute’]) && isset($_POST[‘second’])) {
$added = mktime(intval($_POST[‘hour’]), intval($_POST[‘minute’]), intval($_POST[‘second’]), intval($_POST[‘month’]), intval($_POST[‘day’]), intval($_POST[‘year’])) ;
}
}
//set the status
if (getSetting(“admin_automod”, $db) == ‘1’ && $isAdmin) {
$status = “true” ;
}
else {
if (getSetting(“moderate_media”, $db) == ‘1’)
$status = “false” ;
else
$status = “true” ;
}
/*
******** UPLOAD FILE *************
*/
//EMBED is allowed ////////////
if (($embedded == 1) && (!$noembed)) {
$dbthumb = ‘’;
if (! empty($FILES[‘uploadthumb’][‘tmp_name’])) {
$thumbfilename = str_replace(" ", "
", $FILES[‘uploadthumb’][‘name’]) ;
$thumbfilename = md5(uniqid(rand())).’
’.$thumbfilename ;
$maxsize = 10000 ;
if ($FILES[‘uploadthumb’][‘size’] < $maxsize * 1024) {
$thumbfilename = str_replace(" ", "
", $FILES[‘uploadthumb’][‘name’]) ;
$thumbfilename = md5(uniqid(rand())).’
’.$thumbfilename ;
//upload the thumbnail if one was specified
$maxsize = 10000 ;
if ($_FILES[‘uploadthumb’][‘size’] < $maxsize * 1024) {
$filename = $_FILES[‘uploadthumb’][‘name’] ;
$filename_without_ext = $filename ;
$ext_pos = strrchr($filename, ‘.’) ;
if ($ext_pos !== false) {
$filename_without_ext = substr($filename, 0, -strlen($ext_pos)) ;
}
$ext = strtolower(substr($filename, strrpos($filename, ‘.’) + 1)) ;
$img_exts = array(‘jpg’, ‘gif’, ‘bmp’, ‘png’) ;
if (array_search($ext, $img_exts) !== FALSE) {
if (move_uploaded_file($_FILES[‘uploadthumb’][‘tmp_name’], ‘uploads/thumbs/’.$thumbfilename)) {
$thumb_name = str_replace("’","",$title);
createThumb($thumbfilename, ( ST_H ), ( ST_W ), ‘uploads/thumbs/’, ‘uploads/thumbs/’, $title.".large.jpg") ;
createThumb($thumbfilename, ( ST_H ), ( ST_W ), ‘uploads/thumbs/’, ‘uploads/thumbs/’, $title.".small.jpg") ;
$dbthumb = $thumb_name ;
}
}
else {
$errorresult = “th” ;
////////////////////////// samrty here ////////////////////////
}
}
}
}
else if (trim($_POST[‘remotethumb’]) != ‘’) {
createThumb($_POST[‘remotethumb’], ( ST_H ), ( ST_W ), ‘’, ‘uploads/thumbs/’, $title.".small.jpg") ;
createThumb($_POST[‘remotethumb’], ( ST_H ), ( ST_W ), ‘’, ‘uploads/thumbs/’, $title.".large.jpg") ;
$dbthumb = $title ;
}
$sql = “INSERT INTO media (title, category, description, tags, embed, mediaurl, thumb, poster, added, status, url,mediatype,groupid) VALUES (’”.$title."’, ‘".$cat."’, ‘".$description."’, ‘".$tags."’, ‘".$embedcode."’, ‘".$title."’,’".$dbthumb."’,
‘".$poster."’, ‘".$added."’, ‘".$status."’, ‘".$url."’,‘embed’,".$group."
)" ;
$db->query($sql) ;
if ($status == “true”) {
$catpath = getCategoryPath($cat) ;
$playpath = ( S_PATH ).‘play’.$catpath.’/’.$title ;
}
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service