/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Html.php');
require_once(HTML_BASIC_UTIL_PATH.'/Message.php');
require_once(HTML_BASE_UTIL_PATH.'/Image.php');
require_once(HTML_BASE_UTIL_PATH.'/Link.php');
/**
* Image Rotator. An image is shown in an round robin fasion in an interval
* Note: At the moment of writing, only numbers between 00,01,02,...,99 are supported
* <code>
* Usage:
* $imagerotator = new Imagerotator($path,$image,$start,$end);
* print $imagerotator->getHtml();
* Or
* Imagerotator::display($path,$image,$start,$end);
* </code>
* @package component
*/
class Imagerotator extends Html {
var $path = '';
var $image = '';
var $start = ''; // The start name of picture to rotate
var $end = ''; // The end name of picture to rotate
/**
* Constructor
* @param String $path The path to the images
* @param String $image The image to use for now
* @param String $start The start of the image name to use for now
* @param String $end The end of the image name to use for now
*/
function Imagerotator($path='',$image='',$start='',$end='') {
$this->Html();
$this->path = $path!=''?$path:IMAGE_ROTATOR_PATH;
$this->image = $image!=''?$image:'';
$this->start = $start!=''?$start:IMAGE_ROTATOR_START;
$this->end = $end!=''?$end:IMAGE_ROTATOR_END;
if ($this->end>IMAGE_ROTATOR_END) {
die($this->getClassName()."(), The max rotator end:".$this->end." is greater than ".IMAGE_ROTATOR_END."<br />\r\n");
}
}
/**
* Get the name of the image to rotate
* The name is prepended with zero if the name is smaller than 10
* so the images must be named i.e. 00,01,02,..99
* @return String The name
*/
function getName() {
$name = rand($this->start,$this->end);
$length = strlen($this->end - $this->start);
$start = strlen($name);
for ($i=$start;$i<$length;$i*=10) {
$name = '0'.$name;
}
return $name;
}
/**
* Builds the html, and return it for an Image Rotator object
* @return String The html
*/
function getHtml() {
$html = $this->html;
if (defined('COMPONENT_SHOW') && COMPONENT_SHOW & COMPONENT_SHOW_IMAGEROTATOR && HTTP_USER_AGENT!=HTTP_USER_AGENT_P900) {
if (defined('CREATE_RUNTIME_KERNEL') && CREATE_RUNTIME_KERNEL) {
$html .= '<?$imagerotator = new Imagerotator();print $imagerotator->getHtml();?>';
} else {
$name = $this->getName();
$text = '';
$title = IMAGE_ROTATOR_LINK.' ('.$name.')';
$link = new Link($text, IMAGE_ROTATOR_LINK,CSS_LINK_COLOR,$title,LINK_LAYOUT_BR);
//if (file_exists(PROJECT_PATH.$this->path.'/'.$name.'.jpg')) {
$image = new Image($this->path.'/'.$name.'.jpg','','',$title,CSS_LINK_COLOR);
$link->add($image);
//} else {
// $msg = $this->getClassName()."->getHtml(), Unable to find image=".PORTAL_PATH.$this->path.'/'.$name.".jpg<br />\r\n";
// Message::add($msg,__FILE__,__LINE__);
//}
$html .= $link->getHtml();
}
} else {
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$html .= "<!-- No Image Rotator object -->\r\n";
}
}
return $html;
}
/**
* Display html
* <code>
* Usage:
* Imagerotator::display($path,$image,$start,$end);
* </code>
* @static
* @param String $path The path to the images to rotate
* @param String $image The image to use for now
* @param String $start The start of the image name to use for now
* @param String $end The end of the image name to use for now
*/
function display($path='',$image='',$start='',$end='') {
$html = new Imagerotator($path,$image,$start,$end);
$html->addHtml();
}
}
?>