Sådan benyttes komponenten Google klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Google.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Google::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Google($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Google klassen
Fra denne side kan du søge efter mere information.
Den fulde PHP kildekode for Google klassen
<?php/** * @package component * @see HTML_COMPONENT_PAGE_PATH.'/Google.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.'/TableHeader.php');require_once(HTML_TABLE_COMPONENT_PATH.'/Table.php');require_once(HTML_FORM_COMPONENT_PATH.'/Form.php');require_once(HTML_BASE_UTIL_PATH.'/Link.php');require_once(HTML_COMPONENT_PAGE_PATH.'/Googlebox.php');if (defined('HTML_LANGUAGE_UTIL_PATH')) { require_once(HTML_LANGUAGE_UTIL_PATH.'/Translate.php');}/** * Generates a Google search box * <code> * Usage: * $datareader = null; * $text = "Text header"; * $width = "100%"; * $class = "theTable"; * $border = "1"; * $cellpadding = "5" * $cellspacing = "0"; * $summary = ""; * $caption = ""; * $id = ""; * * $google = new Google($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * print $google->getStart(); * print $google->getHtml(); * print $google->getEnd(); * Or * Google::start($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * // Do something * Google::end(); * Or * Google::display(); * </code> * @package menu */class Google extends Table { /** * 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 for the table * @param String $class The CSS Class name to use * @param String $border The Border * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $id The element ID */ function __construct($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $id='') { $theText = $text != '' ? $text : GOOGLE_TEXT_HEADER; $theWidth = $width != '' ? $width : GOOGLE_VIEW_WIDTH; $theClass = $class != '' ? $class : GOOGLE_VIEW_CLASS; $theBorder = $border != '' ? $border : GOOGLE_VIEW_BORDER; $theCellpadding = $cellpadding != '' ? $cellpadding : GOOGLE_VIEW_CELLPADDING; $theCellspacing = $cellspacing != '' ? $cellspacing : GOOGLE_VIEW_CELLSPACING; $theId = $id !== '' ? $id : $this->getClassName()."Id"; parent::__construct($datareader, $text, $theWidth, $theClass, $theBorder, $theCellpadding, $theCellspacing, $summary, $caption, $theId); } /** * Builds the start html for a Google search box, and return it * @return String The start of the form as html */ function getFormStart() { $html = ''; if (defined('COMPONENT_SHOW') && COMPONENT_SHOW & COMPONENT_SHOW_GOOGLE || defined('LINK_SHOW') && LINK_SHOW & LINK_SHOW_GOOGLE_TOP) { $form = new Form(); $html .= $form->getStart(@GOOGLE_COM_CUSTOM_URL); } return $html; } /** * Builds the end html for a Google search box, and return it * @return String The end if the form as html */ function getFormEnd() { $html = ''; if (defined('COMPONENT_SHOW') && COMPONENT_SHOW & COMPONENT_SHOW_GOOGLE || defined('LINK_SHOW') && LINK_SHOW & LINK_SHOW_GOOGLE_TOP) { $form = new Form(); $html .= $form->getEnd(); } return $html; } /** * Return the header text for the Google search box as html * @return String The header text as an html */ function getHeader() { $object = new Raw(); $link = new Link("http:/"."/google.com","http:/"."/google.com"); $object->add(new Raw("<h1>".@GOOGLE_TEXT_HEADER.$link->getHtml()."</h1>\r\n")); $object->add(new Raw("<p>".@GOOGLE_TEXT_PARAGRAPH."</p>\r\n")); return $object->getHtml(); } /** * Builds the html for a Google search box, and return it * This function assumes that you already have a table like: * <code> * <table ...><tr><td>...</td> ... <google> ... <td>...</td></tr></table> * </code> * @return String The google seach box as html */ function getHtml() { $html = $this->html; if (defined('COMPONENT_SHOW') && COMPONENT_SHOW & COMPONENT_SHOW_GOOGLE || defined('LINK_SHOW') && LINK_SHOW & LINK_SHOW_GOOGLE_TOP) { if (CACHE_MENU && $this->getCacheFileName(CACHE_MENU_PATH) != '' && file_exists($this->getCacheFileName(CACHE_MENU_PATH))) { $html .= $this->content($this->getCacheFileName(CACHE_MENU_PATH)); } else { $tr = new Tr(); $tr->add($this->newData()); $this->add($tr); // Render it $html .= $this->getHeader(); $html .= $this->getFormStart(); if ($this->text != '') { $html .= $this->getTableHeader(); } $html .= $this->getStart(); $html .= $this->getEnd(); $html .= $this->getFormEnd(); if (CACHE_MENU) { $this->save($html, CACHE_COMPONENT_PATH); } } } else { $html .= "<!-- ".$this->getClassName()." disabled -->\r\n"; } return $html; } /** * Builds the html for a Google search box, and return it * This function assumes that you already have a table like: * <code> * <table><tr> * <td>...</td> ... <google> ... <td>...</td> // The googlebox * </tr></table> * </code> * @return Googlebox The googlebox as an object */ function newData() { return new Googlebox($this->text, CSS_BODY); } /** * Display start html * <code> * Usage: * Google::formstart($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * </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 for the table * @param String $class The CSS Class name to use * @param String $border The Border * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption */ public static function start($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $id='') { $html = new Google($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); $html->addHtml($html->getStart()); } /** * Display end html * <code> * Usage: * Google::end(); * </code> * @static */ public static function end() { $html = new Google(); $html->addHtml($html->getEnd()); } /** * Display html * <code> * Usage: * Google::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * </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 for the table * @param String $class The CSS Class name to use * @param String $border The Border * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $id The element ID */ public static function display($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $id='') { $html = new Google($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); $html->addHtml(); }}?>
Den fulde HTML kildekode for Google klassen
<? <!-- DEBUG: Google --> <h1>Søgning i <!-- DEBUG: Link --> <!-- http://google.com --><a class="baseLinkColor" href="http://google.com" title="http://google.com">http://google.com</a></h1> <p>Fra denne side kan du søge efter mere information.</p> <form action="/source-code/component/Google/index.php" method="get" name="Form1" id="Form1"> <table id="GoogleId" width="300" class="baseBorder baseBody" border="0" cellpadding="0" cellspacing="0"> <tr> <!-- DEBUG: Googlebox --> <td valign="top" class="baseBody"><!-- DEBUG: Images --> <img src="http://kakerlakker.info/images/blank.gif" width="1" height="10" alt="blank.gif" /></td> <td valign="top" class="baseBody"><!-- DEBUG: Images --> <img src="http://kakerlakker.info/images/triangle.gif" width="10" height="10" alt="triangle.gif" class="baseBody" /></td> <td valign="middle" class="baseBody"><!-- DEBUG: Link --> <a class="baseBody" href="http://www.google.com/search" title="Powered by Google"><span class="menuBlue">G</span><span class="menuRed">o</span><span class="menuYellow">o</span><span class="menuBlue">g</span><span class="menuGreen">l</span><span class="menuRed">e</span></a></td> <td class="baseBody" valign="middle"><!-- DEBUG: Label --> <!-- Label->getHtml() Text for the label is empty --> <!-- DEBUG: Text --> <input type="text" name="q" id="Label2" class="formXSmall baseBorder" maxlength="255" value="Google" title="Skriv dine søgeord" tabindex="1" /><br /> <!-- DEBUG: Hidden --> <input type="hidden" name="client" value="pub-3894654089466394" /> <!-- DEBUG: Hidden --> <input type="hidden" name="forid" value="1" /> <!-- DEBUG: Hidden --> <input type="hidden" name="ie" value="ISO-8859-1" /> <!-- DEBUG: Hidden --> <input type="hidden" name="oe" value="ISO-8859-1" /> <!-- DEBUG: Hidden --> <input type="hidden" name="cof" value="GALT:#000000;GL:1;DIV:#ff0000;VLC:ff0000;AH:left;BGC:ffffff;LBGC:ffffff;ALC:ff0000;LC:0000ff;T:000000;GFNT:000066;GIMP:ff0000;FORID:11;" /> <!-- DEBUG: Hidden --> <input type="hidden" name="hl" value="da" /> <!-- DEBUG: Hiddens --> </td> <td class="baseBody" valign="middle"><!-- DEBUG: SubmitButton --> <input type="submit" class="formSearchSubmit baseBorder" value=" - Go" title="Powered by Google Search" tabindex="2" accesskey="G" /> </td> </tr> </table> </form> ?>
Her er 'klasse metoderne' for Google klassen:
Her er 'objekt variable' for Google klassen: