Sådan benyttes komponenten Locator klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Locator.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Locator::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Locator($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Locator klassen
Den fulde PHP kildekode for Locator klassen
<?php/** * @package layout * @see HTML_LAYOUT_PAGE_PATH.'/Locator.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_TABLE_COMPONENT_PATH.'/TableDataReader.php');if (defined('HTML_BASE_UTIL_PATH')) { require_once(HTML_BASE_UTIL_PATH.'/Div.php');}if (defined('HTML_LANGUAGE_UTIL_PATH')) { require_once(HTML_LANGUAGE_UTIL_PATH.'/Translate.php');}/** * Display the navigation path * <code> * Usage: * $rows = array( * array( * KEY_LINK=>LINK_COPYRIGHT, * KEY_POWERED=>LINK_POWERED_BY, * KEY_VERSION=>CURRENT_VERSION, * ), * ); * $header = ''; // The header meta data * $default = ''; // The default meta data array * $limit = ''; // The limit to use for the array * $sort = true; * $datareader = DataReaderFactory::newDataReader($rows, $header, $default, $limit, $sort); * $locator = new Locator($datareader, $text, $width, $class, $border, * $cellpadding, $cellspacing, $summary, $caption, $layout); * print $locator->getHtml(); * Or * Locator::display($datareader, $text, $width, $class, $border, * $cellpadding, $cellspacing, $summary, $caption, $layout); * </code> * @package layout */class Locator extends TableDataReader { /** * Constructor * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text The text header for the table * @param String $width The width of the table, default 100% * @param String $class The css class to use * @param String $border The table border * @param String $cellpadding The Cell Padding * @param String $cellspacing The Cell Spacing * @param String $summary The Summary * @param String $caption The Caption * @param String $layout The layout to use */ function __construct($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $theText = $text != '' ? $text : ''; $theWidth = $width != '' ? $width : LOCATOR_VIEW_WIDTH; $theClass = $class != '' ? $class : LOCATOR_VIEW_CLASS; $theBorder = $border != '' ? $border : LOCATOR_VIEW_BORDER; $theCellPadding = $cellpadding != '' ? $cellpadding : LOCATOR_VIEW_CELLPADDING; $theCellSpacing = $cellspacing != '' ? $cellspacing : LOCATOR_VIEW_CELLSPACING; $theLayout = $layout != '' ? $layout : LOCATOR_VIEW_LAYOUT; $theDatareader = $datareader; if ($theDatareader == '') { $theDatareader = $this->getDirs(); } parent::__construct($theDatareader, $theText, $theWidth, $theClass, $theBorder, $theCellPadding, $theCellSpacing, $summary, $caption, $theLayout); } /** * Get a dirview of the Disk * <code> * The path info looks like i.e. /dir1/dir2/dir3/file.php * $url[0] is empty, * $url[1]..$url[3] is the dir path * $url[4] is the filename * </code> * @return array The array of dir links */ function getDirs() { $dirs = array(); $url = explode('/', LINK_TEXT_HOME.$_SERVER['PHP_SELF']); $count = count($url)-1; // Skip filename $root = ''; for ($i = 0; $i < $count; $i++) { if ($i==0) { $dash = TEXT_LOCATOR.": / "; } else { $root .= '/'.$url[$i]; // Next dir $dash = " / "; // » OR » } if (defined('HTML_LANGUAGE_UTIL_PATH')) { $text = ucfirst(Translate::get($url[$i])); } else { $text = ucfirst($url[$i]); } //$text = str_replace('-',"»", $text); // In order to avoid line breaks $dash = str_replace(' '," ", $dash); // In order to avoid line breaks $href = $root.'/'; $title = LINK_TITLE_VISIT_US.$text; $dirs[] = array(KEY_PLAIN=>$dash,'class'=>CSS_LOCATOR); $dirs[] = array('text'=>$text,'href'=>$href,'class'=>CSS_LOCATOR,'title'=>$title); } $dirs[] = array(KEY_PLAIN=>' ','class'=>CSS_LOCATOR.' '.CSS_FILL_OUT); $dirs[] = $this->getLoginImage(); $dirs[] = array(KEY_PLAIN=>' ','class'=>CSS_LOCATOR); $dirs[] = $this->getLoginLink(); return $dirs; } /** * Get the Login Image if supplied * @return String The login name */ function getLoginImage() { $dirs = array(); if (defined('LOGIN_REQUIRED') && LOGIN_REQUIRED) { // Login/Logoff required if (defined('LOGIN_USERNAME')) { $text = ""; $href = ""; $name = IMAGE_LOGIN; $image = new Images($name, '', '', '', CSS_LOCATOR); $link = new Links (LINK_LOGIN, $text, $href, CSS_LOCATOR); if (defined('LOGIN_USERNAME') && LOGIN_USERNAME !== @DEFAULT_LOGIN_USERNAME) { $name = IMAGE_LOGOFF; $image = new Images($name, '', '', '', CSS_LOCATOR); $link = new Links(LINK_LOGOFF, $text, $href, CSS_LOCATOR); } else { // Not logged in } $src = ''; $dirs = array('href'=>$link->get('href'),'class'=>$link->get('class'),'title'=>$link->get('title'), 'src'=>$image->getSrc($src, $name),'width'=>$image->get('width'),'height'=>$image->get('height'),'alt'=>$image->get('alt')); } } else { // Login not required } return $dirs; } /** * Get the Login Link if supplied * @return String The login name */ function getLoginLink() { $dirs = array(); if (defined('LOGIN_REQUIRED') && LOGIN_REQUIRED) { // Login/Logoff required if (defined('LOGIN_USERNAME')) { $text = ""; $href = ""; $link = new Links(LINK_LOGIN, $text, $href, CSS_LOCATOR); if (defined('LOGIN_USERNAME') && LOGIN_USERNAME !== @DEFAULT_LOGIN_USERNAME) { $link = new Links(LINK_LOGOFF, $text, $href, CSS_LOCATOR); } else { // Not logged in } $dirs = array('text'=>$link->get('text'),'href'=>$link->get('href'),'class'=>$link->get('class'),'title'=>$link->get('title')); } } else { // Login not required } return $dirs; } /** * Get the CSS class Name for this component * @return String The CSS class name */ function getCssClass() { return CSS_LOCATOR; } /** * Toogle the request parameters which will minimize or maximize this component * @return array The array of key=>value pair */ function getMinimize() { return $this->getToogle(REQUEST_LAYOUT_SHOW, LAYOUT_SHOW, LAYOUT_SHOW_LOCATOR); } /** * Get the html, and return it for a location * @return String The html */ function getHtml() { $html = $this->html; if (LAYOUT_SHOW & LAYOUT_SHOW_LOCATOR && HTTP_USER_AGENT!=HTTP_USER_AGENT_P900) { if (defined('CREATE_RUNTIME_KERNEL') && CREATE_RUNTIME_KERNEL) { $html .= '<?php'.ucfirst($this->getClassName()).'::display()?>'; } else { if (defined('LOGIN_USERNAME') && LOGIN_USERNAME === '' && CACHE_LAYOUT && $this->getCacheFileName(CACHE_LAYOUT_PATH) != '' && file_exists($this->getCacheFileName(CACHE_LAYOUT_PATH))) { $html .= $this->content($this->getCacheFileName(CACHE_LAYOUT_PATH)); } else { $html .= $this->getColumns(); if (CACHE_LAYOUT && defined('LOGIN_USERNAME') && LOGIN_USERNAME === '') { $this->save($html, CACHE_LAYOUT_PATH); } } } } else { $html .= $this->getMaximize(); } return $html; } /** * Display html * <code> * Usage: * Locator::display($datareader, $text, $width, $class, $border, * $cellpadding, $cellspacing, $summary, $caption, $layout); * </code> * @static * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text The text header for the table * @param String $width The width of the table, default 100% * @param String $class The css class to use * @param String $border The table border * @param String $cellpadding The Cell Padding * @param String $cellspacing The Cell Spacing * @param String $summary The Summary * @param String $caption The Caption * @param String $layout The layout to use */ public static function display($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $html = new Locator($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); $html->addHtml(); }}?>
Den fulde HTML kildekode for Locator klassen
<? <!-- DEBUG: Locator --> <table id="LocatorId" width="100%" class="tableBorderLeft tableBorderRight basePrinter" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="layoutLocator baseOnepc" valign="top"><!-- DEBUG: Link --> <a class="layoutLocator" href="?layoutLAYOUT_SHOW=641" title="Klik her for at Minimere ... Locator"><!-- DEBUG: Images --> <img src="http://myrer.info/images/triangle.gif" width="10" height="10" alt="triangle.gif" class="layoutLocator" /> </a> </td> <td class="layoutLocator" valign="top">Du er her: / </td> <td class="layoutLocator" valign="top"><!-- DEBUG: Link --> <!-- Forsiden --><a class="layoutLocator" href="/" title="Besøg vores hjemmeside: Forsiden">Forsiden</a> </td> <td class="layoutLocator" valign="top"> / </td> <td class="layoutLocator" valign="top"><!-- DEBUG: Link --> <!-- Kildekoden --><a class="layoutLocator" href="/source-code/" title="Besøg vores hjemmeside: Kildekoden">Kildekoden</a> </td> <td class="layoutLocator" valign="top"> / </td> <td class="layoutLocator" valign="top"><!-- DEBUG: Link --> <!-- Layout --><a class="layoutLocator" href="/source-code/layout/" title="Besøg vores hjemmeside: Layout">Layout</a> </td> <td class="layoutLocator" valign="top"> / </td> <td class="layoutLocator" valign="top"><!-- DEBUG: Link --> <!-- Locator --><a class="layoutLocator" href="/source-code/layout/Locator/" title="Besøg vores hjemmeside: Locator">Locator</a> </td> <td class="layoutLocator baseFillOut" valign="top"> </td> <td class="layoutLocator" valign="top"><!-- DEBUG: Link --> <a class="layoutLocator" href="?baseCOMMAND=3658c8b6000fa4bb49f881e093187d3c" title="Logoff nu"><!-- DEBUG: Image --> <img src="http://myrer.info/images/logoff.gif" width="13" height="13" alt="Logoff nu" class="layoutLocator" /> </a> </td> <td class="layoutLocator" valign="top"> </td> <td class="layoutLocator" valign="top"><!-- DEBUG: Link --> <!-- Logoff : xxx --><a class="layoutLocator" href="?baseCOMMAND=3658c8b6000fa4bb49f881e093187d3c" title="Logoff nu">Logoff : xxx</a> </td> </tr> </table> ?>
Her er 'klasse metoderne' for Locator klassen:
Her er 'objekt variable' for Locator klassen: