Google Powered Search

Google
 
LinuxWebLog.com Web

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Integrate Google Search on Drupal sites and generate revenue

Below is what I have done to integrate the adsense google search with the Drupal CMS.

  1. Add the rewrite rule to ".htaccess" file so the search query gets directed to the search page:
      RewriteCond %{QUERY_STRING} ^domains=linuxweblog.com&q=([^&]+)&.*$
      RewriteRule ^.*$ index.php?q=search&keys=%1 [L]

    This should come before any other rules, so put it just after the "RewriteEngine on" line. Don't forget to replace linuxweblog.com with your own.

  2. Add a "google_search()" function in the "search.module" file to return the Search box and the results. The code can be generated from your adsense account. Here is what I have -- note the query text is pre-filled into the search box:
    function google_search() {
    
            $keys = isset($_GET['keys']) ? $_GET['keys'] : $_POST['keys'];
            return t("
                    <p><hr /></p>
                    <h2>Google Powered Search Results</h2>
                    <p>%google_search</p>
                    ", array('%google_search' => '
                    <div align="center">
                    <!-- SiteSearch Google -->
                    <form method="get" action="http://linuxweblog.com/search-results" target="_top">
                    <table border="0" bgcolor="#ffffff">
                    <tr><td nowrap="nowrap" valign="top" align="left" height="32">
                    <a href="http://www.google.com/">
                    <img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" 
    align="middle"></img></a>
                    </td>
                    <td nowrap="nowrap">
                    <input type="hidden" name="domains" value="linuxweblog.com"></input>
                    <input type="text" name="q" size="31" maxlength="255" value="' . $keys . '"></input>
                    <input type="submit" name="sa" value="Search"></input>
                    </td></tr>
                    <tr>
                    <td> </td>
                    <td nowrap="nowrap">
                    <table>
                    <tr>
                    <td>
                    <input type="radio" name="sitesearch" value="linuxweblog.com" checked="checked"></input>
                    <font size="-1" color="#000000">LinuxWebLog.com</font>
                    </td>
                    <td>
                    <input type="radio" name="sitesearch" value=""></input>
                    <font size="-1" color="#000000">Web</font>
                    </td>
                    </tr>
                    </table>
                    <input type="hidden" name="client" value="pub-3520033732422687"></input>
                    <input type="hidden" name="forid" value="1"></input>
                    <input type="hidden" name="channel" value="9732135083"></input>
                    <input type="hidden" name="ie" value="ISO-8859-1"></input>
                    <input type="hidden" name="oe" value="ISO-8859-1"></input>
                    <input type="hidden" name="cof" 
    value="GALT:#0066CC;GL:1;DIV:#999999;VLC:336633;AH:center;
    BGC:FFFFFF;LBGC:FF9900;ALC:0066CC;LC:0066CC;T:000000;GFNT:666666;
    GIMP:666666;FORID:11"></input>
                    <input type="hidden" name="hl" value="en"></input>
                    </td></tr></table>
                    </form>
                    <!-- SiteSearch Google -->
    
                    <!-- Google Search Result Snippet Begins -->
                    <div id="googleSearchUnitIframe"></div>
                    <script type="text/javascript">
                    var googleSearchIframeName = "googleSearchUnitIframe";
                    var googleSearchFrameWidth = 600;
                    var googleSearchFrameborder = 0 ;
                    var googleSearchDomain = "www.google.com";
                    </script>
                    <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js">
                    </script>
                    <!-- Google Search Result Snippet Ends -->
                    </div>
                    '));
    }
    
  3. Now in the "search_view()" function concatenate the search results just before printing the page:
        $output .= google_search();
        print theme('page', $output, t('Search'));
    

That's it. Test it out and see how it works!!

Comment