Sådan benyttes komponenten Picture klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Picture.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Picture::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Picture($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Picture klassen
Den fulde PHP kildekode for Picture klassen
<?php/** * @package base * @see HTML_BASE_UTIL_PATH/Picture.php * @copyright 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.'/Link.php');require_once(HTML_BASE_UTIL_PATH.'/Image.php');/** * Create the link and image for one of the pictures in the path /images/w200/ * The picture names are from "00" to "60" with the extension of ".jpg" * <code> * Usage: * $name = "21"; // Assume ".jpg" extension * $pictures = array( * : * 21=>array('text'=>'', 'href'=>, 'title'=>'', 'src'=>'', 'width'=>'', 'height'=>'', 'alt'=>'', 'class'=>'', ), * : * ); * $path = "/images/w200"; * $start = ''; * $end = ''; * $view = new Picture($name, $pictures, $path, $start, $end); * print $view->getHtml(); * Or * Picture::display($name, $pictures, $path, $start, $end); * </code> * @see HTML_BASE_RESOURCE_PATH/ConfigurationPictures.php * @package base */class Picture extends Html { /** * @var String $name The name of the picture to show */ protected $name = ''; /** * @var array $pictures The rows of the pictures to show */ protected $pictures = ''; /** * @var String $path The path to the the picture to show */ protected $path = ''; /** * @var String $start The start name of picture to show */ protected $start = ''; /** * @var String $end The end name of picture to show */ protected $end = ''; /** * Constructor * @param integer $name The picture to display * @param array $pictures The rows of pictures to display * @param String $path The path to the picture to display * @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($name='', $pictures='', $path='', $start='', $end='') { parent::__construct(); $picture = array_key_exists(DEFINE_PICTURES, $GLOBALS) ? $GLOBALS[DEFINE_PICTURES] : array("PictureIsMissing"); $this->name = $name != '' ? $name : ''; $this->pictures = $pictures !== '' ? $pictures : $picture; $this->path = $path != '' ? $path : IMAGE_PATH; $this->start = $start != '' ? $start : '0'; // TODO PICTURE_START $this->end = $end != '' ? $end : '70'; // TODO PICTURE_END } /** * 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->name; 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; } /** * Return the Picture for the Image and the Link to use as an object * @param String $name The name of the picture * @param array $picture The array data for the picture * @return Object The html as an Link and/or Image object */ function newObject($name, $picture='') { $text = ''; $href = LINK_HREF_URL.'/'; $title = BRANDING_TEXT."\r\n".MOBILE_PHONE."\r\n".LINK_TITLE_FREE_ADVICE." ($name)"; $src = ''; $width = ''; $height = ''; $alt = ''; $class = CSS_BODY; if ($picture != '' && is_array($picture)) { foreach($picture as $key=>$value) { if ($value != '') { $$key = $value; } } } $object = new Raw(); if ($href != '') { $object = new Link($text, $href, $class, $title); } if ($src == '') { $name = (strlen($name)==1?'0' : '').$name; $src = $this->path.'/'.$name.'.'.IMAGE_SUFFIX_JPG; } if ($class == CSS_BODY) { $class .= ' '.CSS_FLOAT_RIGHT; } if ($src != '') { $object->add(new Image($src, $width, $height, $alt, $class)); } return $object; } /** * Return the content for the Image and the Link to use as an object * @return Object The picture object */ function newContent() { $object = new Raw(); $name = $this->getName(); if (is_array($this->pictures) && array_key_exists($name, $this->pictures)) { $object = $this->newObject($name, $this->pictures[$name]); } else { $object = $this->newObject($name); if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $object = new Raw($this->getClassName().'->newContent(), Unknown picture found, name='.$name."<br />\r\n"); } } return $object; } /** * Return the html for the Image and the Link to use * @return String The html */ function getHtml() { $html = ''; $content = $this->newContent(); $html .= $content->getHtml(); return $html; } /** * Display html * <code> * Usage: * $name = "21"; // Assume 'jpg' extension * $pictures = array("20", "21", "22", "23",); * $path = "/images/w200"; * $start = ''; * $end = ''; * Picture::display($name, $pictures, $path, $start, $end); * </code> * @static * @param integer $name The image to display * @param array $pictures The rows of pictures to display * @param String $path The path to the picture to display * @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($name='', $pictures='', $path='', $start='', $end='') { $html = new Picture($name, $pictures, $path, $start, $end); $html->addHtml(); }}?>
Den fulde HTML kildekode for Picture klassen
<? <!-- DEBUG: Link --> <a class="baseBody" href="http://www.hvepseeksperten.dk/" title="HvepseEksperten.dk ApS
(+45) 40 50 60 69
Ring for Gratis rådgivning ... (30)"><!-- DEBUG: Image --> <img src="http://borebiller.info/images/w200/30.jpg" alt="30.jpg" class="baseBody baseFloatRight" /> </a> ?>
Her er 'klasse metoderne' for Picture klassen:
Her er 'objekt variable' for Picture klassen: