Sådan benyttes komponenten Imagerotator klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Imagerotator.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Imagerotator::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Imagerotator($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Imagerotator klassen
Den fulde PHP kildekode for Imagerotator klassen
<?php/** * @package component * @filesource * @see HTML_COMPONENT_PAGE_PATH.'/Imagerotator.php' * @copyright (c) http://Finn-Rasmussen.com * @license http://Finn-Rasmussen.com/license/ myPHP License conditions * @author http://Finn-Rasmussen.com * @version 1.11 * @since 27-nov-2009 *//** * The required files */require_once(HTML_BASE_COMMON_PATH.'/Html.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: * $path = "/w200"; * $image = ""; // NOT USED if empty * $start = "10"; // Start with image no. 10 * $end = "20"; // End with image no. 20 * $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 String $path The Path to the images to use */ protected $path = ''; /** * @var String $image NOT USED, The Image to use */ protected $image = ''; /** * @var String $start The start name of picture to rotate */ protected $start = ''; /** * @var String $end The end name of picture to rotate */ protected $end = ''; /** * 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 __construct($path='', $image='', $start='', $end='') { parent::__construct(); $this->path = $path !== '' ? $path : IMAGE_ROTATOR_PATH; $this->image = $image !== '' ? $image : IMAGE_ROTATOR_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 = $this->image; if ($name == "") { $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 .= "require_once(HTML_COMPONENT_PAGE_PATH.'/Imagerotator.php');"; $html .= '<'.'?Imagerotator::display();?'.'>'; } else { $name = $this->getName(); $text = ''; $title = IMAGE_ROTATOR_LINK.' ('.$name.')'; $link = new Link($text, IMAGE_ROTATOR_LINK,CSS_LINK_COLOR, $title,LINK_LAYOUT_BR); $image = new Image($this->path.'/'.$name.'.'.IMAGE_SUFFIX_JPG,'','', $title,CSS_LINK_COLOR); $link->add($image); $html .= $link->getHtml(); } } else { if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $html .= "<!-- No Image Rotator object -->\r\n"; } } return $html; } /** * Display html * <code> * Usage: * $path = "/w200"; * $image = ""; // NOT USED if empty * $start = "10"; // Start with image no. 10 * $end = "20"; // End with image no. 20 * 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 */ public static function display($path='', $image='', $start='', $end='') { $html = new Imagerotator($path, $image, $start, $end); $html->addHtml(); }}?>
Den fulde HTML kildekode for Imagerotator klassen
<? <!-- DEBUG: Imagerotator --> <!-- DEBUG: Link --> <a class="baseLinkColor" href="http://www.hvepseeksperten.dk" title="http://www.hvepseeksperten.dk (56)"><!-- DEBUG: Image --> <img src="http://skadedyr.info/images/w200/56.jpg" alt="http://www.hvepseeksperten.dk (56)" class="baseLinkColor" /> </a><br /> ?>
Her er 'klasse metoderne' for Imagerotator klassen:
Her er 'objekt variable' for Imagerotator klassen: