si la quieren probar van a necesitar de estas clases tambien:
"links.class.php"
Código PHP:
<? // link class .php
class Img { // clase img
private $url;
private $alt;
private $border;
function __construct($url){
$this->url=$url;
$this->setborder(0);
}
function addAlt($alt){
$this->alt="alt='$alt'";
}
function setBorder($border){
$this->border="border='$border'";
}
function getImg(){
return $this->url; // aca habia un error (!)
}
function getAlt(){
return $this->alt;
}
function show (){
return "<img src='$this->url' $this->alt $this->border />";
}
function __toString (){
return ($this->show());
}
}
class link { // super-clase, antes abstracta (abstract class link)
public $url; // antes protected
public $diana;
public $title; // antes protected
public $target; // antes protected - relacionado con newPage()
function __construct($url){
$this->url=$url;
}
function addTitle($title){
$this->title="title='$title'";
}
function newPage(){
$this->target="target ='_blank'";
}
function getTarget(){
return $this->target;
}
function getUrl(){
return $this->url;
}
function setDiana($diana){
$this->diana=$diana;
}
function getDiana(){
return $this->diana;
}
}
class Link2text extends link{ // clase Link a texto
private $anchor;
function __construct($url,$anchor){
parent::__construct($url);
$this->anchor = $anchor;
}
function setAnchor($anchor){
parent::setDiana($anchor);
}
function getAnchor(){
return (parent::getDiana());
}
function __toString() { // 'metodo magico' que genera una salida (me evito ponerle nombre a la funcion porque se ejecuta sola al hacer echo o print)
if (isset($this->title)){
$title=' '.$this->title;
}else{
$title=$this->title;
}
return "<a href='$this->url'".$title."$this->target>$this->anchor</a>";
}
}
class Link2graph extends link{ // clase Link a Grafico
function __construct($url,$img_url){ // quizas podria acetar un objeto tipo imagen
parent::__construct($url);
$imagen = new img($img_url);
parent::setDiana($imagen);
}
function addAlt($alt){
$this->imagen->addAlt($alt); // uso el metodo add_alt de la clase IMG
}
function __toString (){
$img = parent::getDiana();
$title=$this->title;
return "<a href='$this->url' $this->title $this->target >$img</a>";
}
}
?>
"video.class.php"
Código PHP:
<?
class video { # clase video
private $source; // url
private $width;
private $height;
private $color;
private $brand; // {IMBD: youtube, metacafe, ....}
private $id;
private $center;
function setDefault(){
$this->setWidth(400);
$this->setHeight(345);
$this->color[1]='b1b1b1'; // anteponer 0x al imprimir
$this->color[2]='cfcfcf';
$this->center=FALSE;
}
function setSource($source){
$this->source=$source;
}
function getSource(){
return $this->source;
}
function __construct($source){
$this->setSource($source);
$this->setDefault();
if (strstr($source,'youtube')){
$this->brand='youtube';
}else{
if (strstr($source,'metacafe')){
$this->brand='metacafe';
}else{
echo 'FORMATO DE VIDEO NO RECONOCIDO';
break;
}
}
}
function setWidth($width){
$this->width =$width;
}
function setHeight($height){
$this->height = $height;
}
function setColor1($color){
$this->color[1] = $color;
}
function setColor2($color){
$this->color[2] = $color;
}
function setBrand($brand){
$this->brand=$brand;
}
function getBrand(){
return $this->brand;
}
function getID() {
return $this->id; // el ID deberia extraerse de SOURCE (!)
}
function __toString (){
switch($this->brand){
case 'youtube':
return "<object width=\"{$this->width}\" height=\"{$this->height}\"><param name=\"movie\" value=\"{$this->source}&color1=0x{$this->color[1]}&color2=0x{$this->color[1]}&feature=player_embedded&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param>
<embed src=\"{$this->source}&color1=0x{$this->color[1]}&color2=0x{$this->color[2]}&feature=player_embedded&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"{$this->width}\" height=\"{$this->height}\"></embed></object>";
break;
case 'metacafe':
return "<embed pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"{$this->source}\" width=\"{$this->width}\" height=\"{$this->height}\" type=\"application/x-shockwave-flash\" flashvars=\"altServerURL=http://www.metacafe.com&playerVars=videoTitle=Technology CookingshowStats=yesautoPlay=noblogName=mas tecnoblogURL=http://mastecno.com\" wmode=\"transparent\"></embed>";
break;
}
}
} #fin de clase video
class youtube extends video { #clase hija: youtube
function __construct($source=""){
parent::setSource($source);
parent::setDefault();
parent::setBrand('youtube');
//$this->brand='youtube'; /// por q no funciona en la clase padre ????
}
function setID ($id){ // forma alternativa de indicar de que video se trata
$this->id=$id;
parent::setSource("http://www.youtube.com/v/$id");
}
function __toString (){
return (parent::__toString());
}
} # fin de clase
?>