<?php
/*
YouTube API hek up.
Version: 1.0
Author: Sam Napolitano
URL: http://www.napolitopia.com/youtube_videos.php
Last Mod Date: 9/22/06
Notes: I am relatively new to php so you will have to excuse me if it seems that this is a little redundant or undercoded.
This is also the first class I have ever created from scratch, so the concept is still new to me.
This is under a GNU just leave my name in the credits and use/hek/destroy as needed.
*/
class youTube {
function get_feed($feed){
//Open and return Feed with cURL for parsing
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $feed);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$xml = curl_exec($ch);
curl_close($ch);
return $xml;
}
function yt_results($xml, $howmany){
//Match appropriate tags and throw them in an array. I know I don't need to escape the carrots but I was recieving some strange results without it.
preg_match_all("/\<url\>(.+?)\<\/url\>/smi",$xml, $url);
preg_match_all("/\<description\>(.+?)\<\/description\>/smi",$xml, $description);
preg_match_all("/\<video\>(.+?)\<\/video\>/smi",$xml, $video);
preg_match_all("/\<thumbnail_url\>(.+?)\<\/thumbnail_url\>/smi",$xml, $thumb_nail);
//shift return arrays to negate 0 level
array_shift($url);
array_shift($thumb_nail);
array_shift($description);
array_shift($video);
// Replace html characters. More can be added but this seems to work for me across the board.
for($i=0;$i<count($description[0]);$i++){
$description[0][$i] = preg_replace("/</","<",$description[0][$i]);
$description[0][$i] = html_entity_decode($description[0][$i],ENT_QUOTES);
}
// find out how many videos are returned
$total_videos = count($video[0]);
//error checking for how many videos to display
//if more videos are asked for then exist only return how many acutally exist
if($howmany > $total_videos){
$howmany = $total_videos;
}
//if none are asked for default to all
if(!$howmany || $howmany == 0){
$howmany = $total_videos;
}
//video display options
for($i = 0; $i<$howmany; $i++){
// print "<p>".$url[0][$i]."---".$thumb_nail[0][$i]."---</a>".$description[0][$i]."</p>";
$dbhost = 'localhost';
$dbuser = 'ssss';
$dbpass = 'ssss';
$s = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db('sss');
//Burda Veri Tabanına Bağlanıyoruz Kurulumda Yazılan Kullanıcı Ve Şifredir
if( empty($url[0][$i] ) || empty($thumb_nail[0][$i] ) || empty($description[0][$i] ) || empty($description[0][$i] ) || empty($description[0][$i] ) ) {
echo "Form alanını eksik doldurdunuz.";
//Burda Gelen Bilgilerin Eksik Olup Olmadığını Kontrol Ediyoruz.
}
else {
$veriler[1] = $url[0][$i] ;
$veriler[2] = $thumb_nail[0][$i] ;
$veriler[3] = $description[0][$i] ;
$veriler[4] = $description[0][$i] ;
$veriler[5] = $description[0][$i] ;
$veriler[6] = 1 ;
$veriler[7] = 550 ;
$veriler[8] = 500 ;
$veriler[9] = 0 ;
$veriler[10] = 2007-03-10 ;
//Burda Gelen Verilerin MySQL e yazılıcağını belirtiyoruz.
$s = mysql_query("SELECT * FROM files WHERE file='$file'" );
if ( mysql_num_rows($s ) >= 1 ) {
echo "<b>$ad</b> Sen Yazdınız Lütfen Birdaha Yazmayın : )";
exit( );
}
//Burda kullanıcının yazıp yazmadığını kontrol ediyoruz
$tablo = "INSERT INTO files VALUES ('$veriler[6]', '$veriler[1]', '$veriler[2]', '$veriler[6]', '$veriler[6]', '$veriler[3]', '$veriler[4]', '$veriler[4]', '$veriler[7]', '$veriler[8]', '$veriler[6]', '$veriler[9]', '$veriler[6]', '$veriler[6]', '$veriler[10]', '$veriler[9]', '$veriler[9]', '$veriler[9]')";
if ( mysql_query($tablo ) ) {
echo "Kaydınız gerçekleştirildi";
} else {
echo "Bir sorun çıktı.Kaydınız gerçekleşmedi.";
}
}
//not serkancakmak yazan kısım tablo adımızdır
}
}
function yt_featured($dev_id, $howmany){
//youTube api feed
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_id=$dev_id";
//get the feed as a string data source
$xml = $this->get_feed($feed);
//get results
$this->yt_results($xml, $howmany);
}
function yt_user($dev_id, $user, $howmany){
//youTube api feed
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_user&dev_id=$dev_id&user=$user";
//get the feed as a string data source
$xml = $this->get_feed($feed);
//get results
$this->yt_results($xml, $howmany);
}
function yt_tag($dev_id, $tag, $howmany){
//youTube api feed
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=$dev_id&tag=$tag";
//get the feed as a string data source
$xml = $this->get_feed($feed);
//get results
$this->yt_results($xml, $howmany);
}
}
?>