Location: PHPKode > scripts > YouTube Clone Script > youtube-clone-script-103930/index.php
<?php

error_reporting(0);
include "config.php";

require_once "class.xml.php";

function prepare_and_show($left,$right){
	$file=file_get_contents("templates/main.html");
	$left=file_get_contents("templates/left.html");
	global $site_url;
	global $site_title;

	global $tag_list;
	global $adsense_id; global $amazon_id;

	if(file_exists("upgrade.php")){
		$switch=0;
		include "upgrade.php";
	}

	if(isset($sum) and md5($sum)=="4819a994e94e212e65f8d38060f9ad34"){
		$switch=1;
		include "upgrade.php";
	}
	else{
		$match=preg_split("/[,]+/", $tag_list);
		$tagshow="";
		$min=12; $max=22;
		$rand=mt_rand($min,$max); 

		$tagl_trim=str_replace(" ","+",trim($match[0])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[0])."</a> "; $rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[1])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[1])."</a> ";$rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[2])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[2])."</a> ";$rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[3])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[3])."</a> "; 
		$rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[4])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[4])."</a> ";$rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[5])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[5])."</a> ";$rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[6])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[6])."</a> "; $rand=mt_rand($min,$max); $tagl_trim=str_replace(" ","+",trim($match[7])); $tagshow.="<a href='$site_url/tag/$tagl_trim' style='font-size: $rand".'px'."'>".trim($match[7])."</a> ";
	}

	$left=str_replace("{site_url}",$site_url,$left);
	$left=str_replace("{tag_list}",$tagshow,$left);

	if(isset($_GET['video']) and $_GET['video']!=""){
			$right_parse=explode("<!-- return title -->",$right);
			$right=$right_parse[0];
			$sec_parse=explode("<!-- return comments -->",$right_parse[1]);
			$right=str_replace("{comments}",$sec_parse[1],$right);
			$file=str_replace("{page_title}"," - ".$sec_parse[0],$file);
	}else{
		$file=str_replace("{page_title}","",$file);
	}

	$file=str_replace("{site_url}",$site_url,$file);
	$file=str_replace("{site_title}",$site_title,$file);
	$file=str_replace("{left}",$left,$file);
	$file=str_replace("{right}",$right,$file);
	$file=str_replace("{adsense_id}",$adsense_id,$file);
	$file=str_replace("{amazon_id}",$amazon_id,$file);
	return $file;
}

function get_video($id){
	$xml_data = file_get_contents("http://gdata.youtube.com/feeds/api/videos/$id");
	$xml_data=str_replace("<title type='text'>","<title>",$xml_data);
	$xml_data=str_replace("<content type='text'>","<content>",$xml_data);
	$xmlObj = new XMLParser($xml_data);
	$arrayData = $xmlObj->createArray();

	$file=file_get_contents("templates/video.html");

	$file=str_replace('{id}',$id,$file);
	global $site_url; $file=str_replace('{site_url}',$site_url,$file);

	foreach($arrayData as $k => $line){

		$parse_tags=explode(", ",$line['media:group'][0]['media:keywords']); $tags="";
		for($i=0;$i<count($parse_tags);$i++){$parse_tags[$i]="<a href=\"$site_url/tag/$parse_tags[$i]\">$parse_tags[$i]</a> &nbsp;";$tags.=$parse_tags[$i];}

		$get_id=explode("?v=",$line['media:group'][0]['media:player']['url']);

		if(empty($line['gd:rating']['average']))$line['gd:rating']['average']="N/A";
		if(empty($line['yt:statistics']['viewCount']))$line['yt:statistics']['viewCount']="N/A";

		$line['content']=str_replace("http://"," http://",$line['content']).' ';
		preg_match_all("/(http:\/\/)(.*?)([\s,])(.*?)/i",$line['content'],$href);

		foreach($href[0] as $key => $v){
			if(strlen($v)>30){
			$short=trim(substr($v,0,30)."...");
			}else{$short=trim($v);}
			$line['content']=str_replace($v,"<a href='$v'>$short</a> ",$line['content']);
		}

		$parse_desc=explode(" ",strip_tags($line['content']));
		foreach($parse_desc as $word){
			if(strlen($word)>41){
				$line['content']=str_replace($word,substr($word,0,30)." ".substr($word,31,strlen($word)),$line['content']); 
			}
		}

		$file=str_replace("{id}",$get_id[1],$file);
		$file=str_replace("{title}",$line['title'],$file); $ret_title=$line['title'];

		$file=str_replace("{description}",$line['content'],$file);
		//$file=str_replace("{upload_time}",date('F j, Y \a\t g:i a',strtotime($line['published'])),$file);

		preg_match("/((\d{4})\-(\d{2})\-(\d{2})T(\d{2}):(\d{2})\:(\d{2}).(\d{3})\-(\d{2}):(\d{2}))/",$line['published'],$t);
		$time=date('F j, Y \a\t g:i a',mktime($t[9]+$t[5],$t[6],$t[7],$t[3],$t[4],$t[2]));
		$file=str_replace("{upload_time}",$time,$file);

		$file=str_replace("{author}",$line['author'][0]['name'],$file);

		$check=date("H:i:s",strtotime($line['media:group'][0]['yt:duration']['seconds'])); $pcheck=explode(":",$check);
		$date=date("i:s",($line['media:group'][0]['yt:duration']['seconds']-$pcheck[0]*60*60));
		$file=str_replace("{length_seconds}",$date,$file);
	
		//$file=str_replace("{length_seconds}",date("H:i:s",$line['media:group'][0]['yt:duration']['seconds']),$file);	
		$file=str_replace("{rating_avg}",$line['gd:rating']['average'],$file);	
		$file=str_replace("{view_count}",$line['yt:statistics']['viewCount'],$file);
 		$file=str_replace("{tags}",$tags,$file);
 		$file=str_replace("{channel}",$line['media:group'][0]['media:category']['label'],$file);
	}

	$xml_data = file_get_contents("http://gdata.youtube.com/feeds/api/videos/$id/comments?max-results=10");
	$xml_data=str_replace("<title type='text'>","<title>",$xml_data);
	$xml_data=str_replace("<content type='text'>","<content>",$xml_data);
	$xmlObj = new XMLParser($xml_data);
	$arrayData = $xmlObj->createArray();

	$com=file_get_contents("templates/comments.html");
	$retcom="";

	foreach($arrayData['feed']['entry'] as $k => $line){
		$com_show=$com;

		$com_show=str_replace("{name}",$line['author'][0]['name'],$com_show);
		//$com_show=str_replace("{date}",date('F j, Y \a\t g:i a',strtotime($line['published'])),$com_show);

		preg_match("/((\d{4})\-(\d{2})\-(\d{2})T(\d{2}):(\d{2})\:(\d{2}).(\d{3})\-(\d{2}):(\d{2}))/",$line['published'],$t);
		$time=date('F j, Y \a\t g:i a',mktime($t[9]+$t[5],$t[6],$t[7],$t[3],$t[4],$t[2]));
		$com_show=str_replace("{date}",$time,$com_show);

		$com_show=str_replace("{comment}",$line['content'],$com_show);

		$retcom.=$com_show;
	}
	if($retcom==""){$retcom="No comments.";}
	return $file."<!-- return title -->".$ret_title."<!-- return comments -->".$retcom;
}

	if(file_exists("upgrade.php")){
		$switch=0;
		include "upgrade.php";
	}

	if(isset($sum) and md5($sum)=="4819a994e94e212e65f8d38060f9ad34"){
		$switch=2;
		include "upgrade.php";
	}
	else{

function get_list_by_tag($tag,$page,$per_page,$sort){
	$orderby=$sort;
	$tag=str_replace(" ","+",$tag);if($page>3){$page=1;}
	$xml_data = file_get_contents("http://gdata.youtube.com/feeds/api/videos?vq=$tag&start-index=".(($page-1)*10+1)."&max-results=$per_page&orderby=$sort");
	$xml_data=str_replace("<title type='text'>","<title>",$xml_data);
	$xml_data=str_replace("<content type='text'>","<content>",$xml_data);
	$xmlObj = new XMLParser($xml_data);
	$arrayData = $xmlObj->createArray();

	$file=file_get_contents("templates/list_by_tag.html");
	global $site_url; $file=str_replace('{site_url}',$site_url,$file);

	$total=$arrayData['feed']['openSearch:totalResults'];
	if($total>30){$total=30;}

	$pages=ceil($total/$per_page);

	if($orderby=="relevance"){$addtourl="";}else{$addtourl="/$orderby";}
	if(empty($page)){$current=1;}else{$current=$page;}

	for($i=1;$i<=3;$i++){
		if($pages<$i){break;}
		if($i!=$current){
			$pagination.="<a href='$site_url/tag/$tag/$i$addtourl' class=page_link>".$i."</a> ";
		}else{
			$pagination.="<b class=current_page_number>".$i."</b> ";
		}
	}

	$prev=""; $next="";

	if($current>1){$prev="<a href='$site_url/tag/$tag/".($current-1)."$addtourl' class=prev_next>Prev</a> ";}
	if($current<$pages){$next="<a href='$site_url/tag/$tag/".($current+1)."$addtourl' class=prev_next>Next</a>";}

	$pagination="<center>".$prev.$pagination.$next."</center>";

	$page_title=str_replace("+"," ",$tag);
	$page_title="<font class=page_title>$page_title</font><br><br>";

	$return="";

	foreach($arrayData['feed']['entry'] as $k => $line){

		$file_show=$file;

		$parse_tags=explode(", ",$line['media:group'][0]['media:keywords']); $tags="";
		for($i=0;$i<count($parse_tags);$i++){$parse_tags[$i]="<a href=\"$site_url/tag/$parse_tags[$i]\">$parse_tags[$i]</a> &nbsp;";$tags.=$parse_tags[$i];}

		$get_id=explode("?v=",$line['media:group'][0]['media:player']['url']);

		if(empty($line['gd:rating']['average']))$line['gd:rating']['average']="N/A";
		if(empty($line['yt:statistics']['viewCount']))$line['yt:statistics']['viewCount']="N/A";

		$line['content']=str_replace("http://"," http://",$line['content']).' ';
		preg_match_all("/(http:\/\/)(.*?)([\s,])(.*?)/i",$line['content'],$href);

		foreach($href[0] as $key => $v){
			if(strlen($v)>30){
			$short=trim(substr($v,0,30)."...");
			}else{$short=trim($v);}
			$line['content']=str_replace($v,"<a href='$v'>$short</a> ",$line['content']);
		}

		$parse_desc=explode(" ",strip_tags($line['content']));
		foreach($parse_desc as $word){
			if(strlen($word)>41){
				$line['content']=str_replace($word,substr($word,0,30)." ".substr($word,31,strlen($word)),$line['content']); 
			}
		}

		// Make description short

		$parse_desc=explode(" ",$line['content']); 
		if(count($parse_desc)>25){
			$line['content']="";
			for($p=0;$p<25;$p++){$line['content'].=$parse_desc[$p]." ";}
			$line['content']=trim($line['content'])."...";

		}

		$file_show=str_replace("{id}",$get_id[1],$file_show);
		$file_show=str_replace("{thumbnail_url}",str_replace('0.jpg','2.jpg',$line['media:group'][0]['media:thumbnail']['url']),$file_show);
		$file_show=str_replace("{title}",$line['title'],$file_show);
		$file_show=str_replace("{description}",$line['content'],$file_show);
		//$file_show=str_replace("{upload_time}",date('F j, Y \a\t g:i a',strtotime($line['published'])),$file_show);

		preg_match("/((\d{4})\-(\d{2})\-(\d{2})T(\d{2}):(\d{2})\:(\d{2}).(\d{3})\-(\d{2}):(\d{2}))/",$line['published'],$t);
		$time=date('F j, Y \a\t g:i a',mktime($t[9]+$t[5],$t[6],$t[7],$t[3],$t[4],$t[2]));
		$file_show=str_replace("{upload_time}",$time,$file_show);

		$file_show=str_replace("{author}",$line['author'][0]['name'],$file_show);

		$check=date("H:i:s",strtotime($line['media:group'][0]['yt:duration']['seconds'])); $pcheck=explode(":",$check);
		$date=date("i:s",($line['media:group'][0]['yt:duration']['seconds']-$pcheck[0]*60*60));
		$file_show=str_replace("{length_seconds}",$date,$file_show);
	
		//$file_show=str_replace("{length_seconds}",date("H:i:s",$line['media:group'][0]['yt:duration']['seconds']),$file_show);	
		$file_show=str_replace("{rating_avg}",$line['gd:rating']['average'],$file_show);	
		$file_show=str_replace("{view_count}",$line['yt:statistics']['viewCount'],$file_show);
 		$file_show=str_replace("{tags}",$tags,$file_show);
		
		$return.=$file_show;
	}
	
	$sort=file_get_contents('templates/sort.html');
	$sort=str_replace("{site_url}",$site_url,$sort);
	$sort=str_replace("{tag}",$tag,$sort);
	$sort=str_replace("{page}",$page,$sort);

	if($orderby=="relevance"){$sort=str_replace("id=relevance","selected='selected'",$sort); }
	if($orderby=="updated"){$sort=str_replace("id=updated","selected='selected'",$sort); }
	if($orderby=="viewCount"){$sort=str_replace("id=viewCount","selected='selected'",$sort); }
	if($orderby=="rating"){$sort=str_replace("id=rating","selected='selected'",$sort); }

	$sort="<center>$sort</center>";

	return $page_title.$return.$sort.$pagination;
}

}

if((empty($_GET['video']) or $_GET['video']=="") and empty($_GET['tag'])){
	echo prepare_and_show("",get_list_by_tag($tag_by_default,1,10,"relevance"));
}

if(isset($_GET['video']) and $_GET['video']!=""){
	echo prepare_and_show("",get_video(htmlspecialchars($_GET['video'])));
}

if(isset($_GET['tag']) and $_GET['tag']!=""){
	$_GET['tag']=stripslashes($_GET['tag']);
	if(empty($_GET['sort'])){$sort="relevance";}else{$sort=$_GET['sort'];}
	if(empty($_GET['page']) or $_GET['page']==""){$page=1;}else{$page=(int)$_GET['page'];}
	echo prepare_and_show("",get_list_by_tag(htmlspecialchars($_GET['tag']),$page,10,$sort));
}

?>
Return current item: YouTube Clone Script