<?php
/*
* AdRotator : Simple adrotator class
* vedanta dot barooah at gmail dot com
*/
# version 1.2
class AdRotator{
var $iMax="";
var $imageIndex="";
var $imageNames="";
var $linkNames="";
function AdRotator($images,$links=NULL){
if(!is_array($images)) die("error: cant find image array");
else{
$this->iMax=count($images);
$this->imageNames=$images;
$this->linkNames=$links;
}
}
function rotate($num){
if($num > $this->iMax) die("error: not enough images to randomize");
$image_index=array();
while(count($image_index)<$num){
$pin=rand(0,$this->iMax-1);
if(!in_array("$pin",$image_index))array_push($image_index,$pin);
}
$this->imageIndex=$image_index;
}
function getImages(){
$tmp=array();
for($idx=0;$idx<count($this->imageIndex);$idx++) array_push($tmp,$this->imageNames[$this->imageIndex[$idx]]);
return $tmp;
}
function showAds($orientation=NULL /* say VERTICAL if you need vertical orientation */,$link_style=NULL,$target="_blank" /* target to open pages in */,$image_style=NULL /* this is the css class that can be used */){
if(!$link_style){$link_style="text-decoration:none;";}
if(!$image_style){$image_style="background:#f0f0f0;";}
$html='';
for($idx=0;$idx<count($this->imageIndex);$idx++){
$html.="<a target='".$target."' style='".$link_style."' href='".$this->linkNames[$this->imageIndex[$idx]]."'><img border=0 src='".$this->imageNames[$this->imageIndex[$idx]]."' style='".$image_style."'></a>\n";
if($orientation=="VERTICAL")$html.="<br>\n";
}
return $html;
}
}
?>