<?php
/*
Funções basicas para trabalhar com o link do youtube
*/
class YouTube{
//Get the ID of a video from any youtube link
//Pega o ID do video de qualquer link do youtube
function getID( $url ){
if( !strpos($url, "#!v=") === false ){ //Em caso de ser um link de quando clica nos related
//In case of be a link from related
$url = str_replace('#!v=','?v=',$url);
}
parse_str( parse_url( $url, PHP_URL_QUERY ) );
if( isset( $v ) ){
return $v;
} else { //Se não achou, é por que é o link de um video de canal ex: http://www.youtube.com/user/laryssap#p/a/u/1/SAXVMaLL94g
//If not found, is because is a link from a user channel ex: http://www.youtube.com/user/laryssap#p/a/u/1/SAXVMaLL94g
return substr( $url, strrpos( $url,'/') + 1, 11);
}
}
//Generate a youtube link from a video ID
//Gera um link para o youtube a partir de um ID de video
function generateLink( $id ){
return 'http://www.youtube.com/watch?v=' . trim($id);
}
//Generate a simple embedded code from a video ID
//Gera um code de embedded simples, a partir de um ID de video
function generateEmbedded( $id, $width = 320, $height = 240 ){
return '<object width="' . $width . '" height="' . $height . '">
<param name="movie" value="http://www.youtube.com/v/' . $id . '?fs=1&hl=pt_BR&rel=0"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/' . $id . '?fs=1&hl=pt_BR&rel=0"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="' . $width . '"
height="' . $height . '">
</embed>
</object>';
}
}
?>