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:

1. Create a file macros/google_search_form.php by cutting and pasting the text below.
2. Include the file in your parse/macros.php by adding the following:
require('macros/google_search_form.php');
3. Add the macro to your $ViewMacroEngine array in lib/defaults.php:
// $ViewMacroEngine determines what macro names will be processed when
// displaying a page. For each name, a function must be provided.
// See parse/macros.php
$ViewMacroEngine = array(
'!' => 'view_macro_category',
'Anchor' => 'view_macro_anchor',
....
'GoogleSearchForm' => 'view_google_search_form'
);

Enjoy!

--John-Mason P. Shackelford


<?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;
}
?>