Witam. Proszę o sprawdzenie skryptu, który udało mi się zmontować, nie zrobiłem jej sam, gdyż z internetu posiadam funkcję checkYoutubeId i warunek z wyrażeniem regularnym (czyli prawie cały skrypt xd). Chodzi mi o to, abyście ocenili czy do strony internetowej ten kod się nadaje, czy da się to prościej napisać, optymalniej. Z góry dziękuję.
<!DOCTYPE html>
<html>
<head>
<title>Strona Glowna</title>
</head>
<body>
<a href="wideo.php">Strona Glowna</a> <br /><br />
Dodaj film:
<form action="wideo.php" method="GET">
<input type="text" name="yt_link" default="" style="width:300px" />
<input type="hidden" name="yt_send" value="1" />
<input type="submit" value="Wyslij" />
</form>
<br />
<iframe width="400" height="225" src="http://www.youtube.com/embed/2jXUNO-y3HA?rel=0" frameborder="0" allowfullscreen></iframe>
<?php
if($_GET['yt_send'] == '1')
{
echo '<br />';
$adres = $_GET['yt_link'];
if(!preg_match('/http:\/\/(.*?)youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)/', $adres, $nr))
{
echo 'Link jest niepoprawny';
exit;
}
$kurde = $nr[2];
function checkYoutubeId($id) {
// sprawdza czy istnieje w youtube film o podanym id
if (!$data = @file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$id)) return false;
if ($data == 'Video not found') return false;
return true;
}
if(!checkYoutubeId($kurde))
{
echo 'Link do tego filmu jest niepoprawny lub jest on niedostepny';
exit;
}
$kurde = str_replace("watch?v=", "embed/", $adres);
echo '<iframe width="400" height="225" src="'.$kurde.'?rel=0" frameborder="0" allowfullscreen></iframe>';
}
?>
</body>
</html>