/**
* 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:
* $google = new Google($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
* print $google->getStart();
* print $google->getHtml();
* print $google->getEnd();
* Or
* Google::start($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
* // Do something
* Google::end();
* Or
* Google::display();
* </code>
* @package menu
*/
class Google extends Table {
/**
* Constructor
* @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
*/
function Google($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
$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;
$this->Table($text,$theWidth,$theClass,$theBorder,$theCellpadding,$theCellspacing,$summary,$caption);
}
/**
* 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) {
$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($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
* </code>
* @static
* @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
*/
function start($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
$html = new Google($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
$html->addHtml($html->getStart());
}
/**
* Display end html
* <code>
* Usage:
* Google::end();
* </code>
* @static
*/
function end() {
$html = new Google();
$html->addHtml($html->getEnd());
}
/**
* Display html
* <code>
* Usage:
* Google::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
* </code>
* @static
* @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
*/
function display($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
$html = new Google($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
$html->addHtml();
}
}
?>
HTML source code
Den fulde HTML kildekode for Google klassen
<?
<h1>Søgning i <!-- 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="Form10" id="Form10">