The following Macro displays a Google search box on the page. You can see it in action at http://shackelford.org/wiki/PortalPage.html.
Installation:
Enjoy!
<?php
function view_google_search_form($args){
ob_start();
?>
<form name="GoogleSearchForm" method="get">
<script type="text/javascript">
var googleURL = 'http://google.com/';
function searchGoogle(searchType){
var f = document.GoogleSearchForm;
// if query field is filled, perform search
if(trim(f.q.value).length > 0){
f.action = googleURL + searchType;
f.submit();
return false;
} else { // otherwise go to the front page
if(searchType == 'search' && f.cat.value.length == 0){
this.location.href = "http://google.com";
} else if(searchType == 'images'){
this.location.href = "http://images.google.com";
} else if(searchType == 'groups'){
this.location.href = "http://groups.google.com";
} else if(searchType == 'search' && f.cat.value.length > 0){
this.location.href = "http://directory.google.com";
} else if(searchType == 'news'){
this.location.href = "http://news.google.com";
}
return false;
}
}
function addCat(){
document.GoogleSearchForm.cat.value = "gwd/Top";
}
function trim(s){
while(''+ s.charAt(s.length-1)==' '){
s=s.substring(0,s.length-1);
}
return s;
}
</script>
<input type="textbox" name="q" size="55" maxlength="255">
<input type="hidden" name="cat" value="">
<br>
Google
<a href="javascript:searchGoogle('search');">Search</a>
<a href="javascript:searchGoogle('images');">Images</a>
<a href="javascript:searchGoogle('groups');">Groups</a>
<a href="javascript:addCat();searchGoogle('search');">Directory</a>
<a href="javascript:searchGoogle('news');">News</a>
</form>
<?php
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
?>