<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?PHP
@include("wp-load.php");
?>
<?PHP
function aramam($q) { 
$q = str_replace("`","",$q); 
$q = str_replace("&","",$q); 
$q = str_replace("%","",$q);  
$q = str_replace("'","",$q); 
$q = str_replace(")","",$q);
$q = str_replace("(","",$q);  
$q = str_replace("<","",$q);  
$q = str_replace(">","",$q);  
$q = str_replace(" ","+",$q); 
$q=trim($q); 
$q = htmlspecialchars(strip_tags(mysql_real_escape_string($q)));
return $q; 
}
function suresi($secs) 
	{
		if ($secs<0) return false;
		$m = (int)($secs / 60); 
		$s = $secs % 60;
		$h = (int)($m / 60); 
		$m = $m % 60;
		$text = "";
		if ($h > 0)
			$text = $h.":";
		if (strlen($s)==1)
		   	$s = "0".$s;
		return $text.$m.":".$s;
	}
function temizet($de){
	$de=str_replace("'",'',$de);
	$de=str_replace('"','',$de);
	$de=str_replace('amp;','',$de);
	$de=str_replace(',','',$de);
	$de=str_replace('*','',$de);
	$de= eregi_replace("\\\\","",$de);  
	return $de;

}
?>
<?PHP $siteadres=get_bloginfo("url"); ?>
<div align="center"><h1>YouTube Alakalı Videolar</h1><br /> <br />
<form action="" method="post">
<tr><td width="90%">Resimler Sunucuya Çekilsin Mi?:
Evet <input type="radio" name="ans" value="ans1" />
Hayır <input type="radio" name="ans" value="ans2"  />
</tr></td>
<br> 
Aranacak Kelime:<input type="text" name="x" /><br />
Kaç Sayfa?:<input type="text" name="sayfa" /><br />
Kaç Video Çekilsin?:<input type="text" name="kactane" /><br />
<input type="submit" value="ARA"/>
</form>
</div>

<?PHP
$arama=aramam($_POST["x"]);
$sayfa=$_POST["sayfa"];
$kactane=$_POST["kactane"];
if(empty($arama)){}else {
function baglan($feed,$coo=null,$ref=null){

        $ch = curl_init();
        $timeout = 0;
        curl_setopt ($ch, CURLOPT_URL, $feed);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
        if(!empty($coo))
        {
            curl_setopt($ch, CURLOPT_COOKIEFILE, $coo);
            curl_setopt($ch, CURLOPT_COOKIEJAR, $coo);
        }
        if(empty($ref))
        {
            curl_setopt($ch, CURLOPT_REFERER,$feed);
        }
        else
        {
            curl_setopt($ch, CURLOPT_REFERER,$ref);
        }
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $veri= curl_exec($ch);
        curl_close($ch);
        return $veri;
}

$site=baglan("http://gdata.youtube.com/feeds/api/videos?max-results=$kactane&start-index=$sayfa&q=".urlencode($arama)."");

preg_match_all("#<entry>(.*?)</entry>#si",$site,$icerikler);

$iceriksayisi=count($icerikler[1])-1;

$i=0;
while($i<=$iceriksayisi){
$link_x=explode('<id>',$icerikler[1][$i]);
$link_x=explode('</id>',$link_x[1]);
$link_k=explode('/',$link_x[0]);
$video_link=$link_k[6];
$video_link=str_replace($video_link,''.$video_link.'',$video_link);

$baslik_x=explode("<title type='text'>",$icerikler[1][$i]);
$baslik_x=explode('</title>',$baslik_x[1]);
$video_baslik = temizet(trim($baslik_x[0]));

$sure_x=explode("<yt:duration seconds='",$icerikler[1][$i]);
$sure_x=explode("'/>",$sure_x[1]);
$video_sure=suresi($sure_x[0]);


$resim_x=explode("<media:thumbnail url='",$icerikler[1][$i]);
$resim_x=explode("'",$resim_x[1]);
$video_resim=$resim_x[0];

$video_etiket=str_replace("{baslik}",$video_baslik,$kod);
?>

<script type="text/javascript" src="<?PHP echo $siteadres; ?>/jquery.js"></script>
<?php
$answer = $_POST['ans'];  
if ($answer == "ans1") {          
?><script type="text/javascript">
function tybot<?PHP echo $i; ?>(){
$('#sonuc<?PHP echo $i; ?>').slideDown('slow');
$("#sonuc<?PHP echo $i; ?>").html('<div id=resim><center><img src="ajax.gif"></center></div>');
$.ajax({
type:'POST',
url:'<?PHP echo $siteadres; ?>/kaydetyouin.php',
data:$('#form<?PHP echo $i; ?>').serialize(),
success:function(cevap){
    
    $("#sonuc<?PHP echo $i; ?>").html(cevap)

}

})

}
</script>
<?php } else { ?>	
<script type="text/javascript">
function tybot<?PHP echo $i; ?>(){
$('#sonuc<?PHP echo $i; ?>').slideDown('slow');
$("#sonuc<?PHP echo $i; ?>").html('<div id=resim><center><img src="ajax.gif"></center></div>');
$.ajax({
type:'POST',
url:'<?PHP echo $siteadres; ?>/kaydetyou.php',
data:$('#form<?PHP echo $i; ?>').serialize(),
success:function(cevap){
    
    $("#sonuc<?PHP echo $i; ?>").html(cevap)

}

})

}
</script><?php } ?>
<hr>
<div style="width:900px;"><form id="form<?PHP echo $i; ?>" action="" method="post"><div id='div'>           <div style="float:right"><img src="<?PHP echo $video_resim;?>" width="200" height="200"/></div>
        <div id="sonuc<?PHP echo $i; ?>"></div>
		<input type="button" value="Ekle" onclick="tybot<?PHP echo $i; ?>();" >  <br/> 
        Başlık: <input type="text" name="baslik" value="<?PHP echo $video_baslik;?>" size="60">  <br/> 
        Etiketler: <input type="text" name="etiket" value="<?PHP echo $video_etiket;?>" size="60">  <br/>
        Resim : <input type="text" name="resimlink" value="<?PHP echo $video_resim; ?>" size="60"> <br/> 
        Süre : <input type="text" name="sure" value="<?PHP echo $video_sure; ?>" size="60"> <br/>

        Katego: <select name="kategori">
<?PHP $sql=mysql_query("SELECT * FROM `wp_term_taxonomy` WHERE taxonomy='category'"); while($katid=mysql_fetch_array($sql)){
$sql2=mysql_fetch_array(mysql_query("SELECT * FROM `wp_terms` WHERE term_id='$katid[term_id]'"));
echo '<option value="'.$sql2['term_id'].'">'.$sql2['name'].'</option>';

 } ?></select>
		</select>           <br/> 
		Konu : <textarea name="konu" rows="1" cols="50"><iframe width="560" height="400" src="http://www.youtube.com/embed/<?PHP echo $video_link; ?>" frameborder="0" allowfullscreen></iframe></textarea> 
       
         <br/>
</form>
<br /><br />

<?PHP
$i++;
}
}
?>
<br /><br />