Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Template Modifications
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Replace search with Google Custom Search Details »»
Replace search with Google Custom Search
Version: 1.00, by Dave-ahfb Dave-ahfb is offline
Developer Last Online: Dec 2018 Show Printable Version Email this Page

Category: Integration with vBulletin - Version: 4.0.0 Beta 4 Rating:
Released: 11-30-2009 Last Update: Never Installs: 152
Template Edits
Re-useable Code  
No support by the author.

This mod assumes you have an adsense account and are using Google Custom Search.

You want to make sure your results page is named something other than the vb default search.php, this leaves the vb option open to those who click "advanced search"

Open your template navbar


find
PHP Code:
<form action="search.php?do=process" method="post" id="navbar_search"

replace with the form line of the google supplied code
example:
PHP Code:
<form action="http://www.ahfb2000.com/google.php" id="cse-search-box"


find
PHP Code:
<input type="hidden" name="s" value="{vb:raw session.sessionurl}" />
<
input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<
input type="hidden" name="do" value="process" /> 

replace with the first 3 hidden input types in your google code
example:
PHP Code:
    <input type="hidden" name="cx" value="partner-pub-xxxxxxxxxxxxxxxxxxxxxxx" />
    <
input type="hidden" name="cof" value="FORID:10" />
    <
input type="hidden" name="ie" value="ISO-8859-1" /> 


find
PHP Code:
<input type="text" value="" name="query" class="textbox" /> 

replace with
PHP Code:
<input type="text" value="" name="q" class="textbox" /> 


find
PHP Code:
<input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search.png" name="submit" onclick="document.getElementById('navbar_search').submit;" /> 

replace with
PHP Code:
<input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search.png" name="sa" onclick="document.getElementById('navbar_search').submit;" /> 


find
PHP Code:
</form

add this after
PHP Code:
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script

Screenshots

File Type: jpg Image1.jpg (107.9 KB, 0 views)

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #32  
Old 12-30-2009, 12:14 AM
Verionia Verionia is offline
 
Join Date: Jul 2009
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

- What do I replace with value="FORID:10"?
- Also how can I create a vbulletin page for the results to show?
Reply With Quote
  #33  
Old 12-31-2009, 08:28 PM
SemperFideles's Avatar
SemperFideles SemperFideles is offline
 
Join Date: Oct 2006
Location: Northern VA
Posts: 223
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm stuck. I've followed all the instructions and created a site search page from my Adsense account. I get a blank page from my search results.

My google.php looks like this:
PHP Code:
<div id="cse-search-results"></div>
<
script type="text/javascript">
  var 
googleSearchIframeName "cse-search-results";
  var 
googleSearchFormName "cse-search-box";
  var 
googleSearchFrameWidth 800;
  var 
googleSearchDomain "www.google.com";
  var 
googleSearchPath "/cse";
</
script>
<
script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script
Should I have anything else in the file?
Reply With Quote
  #34  
Old 12-31-2009, 08:31 PM
SemperFideles's Avatar
SemperFideles SemperFideles is offline
 
Join Date: Oct 2006
Location: Northern VA
Posts: 223
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I guess what I'm asking is if the google.php should have any other code within it? Should I just create a new file called google.php, paste the above code to it and then upload it or should there be some other code before and after it so it will display inline?
Reply With Quote
  #35  
Old 01-01-2010, 02:49 PM
bpr bpr is offline
 
Join Date: Dec 2009
Location: London
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by SemperFideles View Post
I'm stuck. I've followed all the instructions and created a site search page from my Adsense account. I get a blank page from my search results.

My google.php looks like this:
PHP Code:
<div id="cse-search-results"></div>
<
script type="text/javascript">
  var 
googleSearchIframeName "cse-search-results";
  var 
googleSearchFormName "cse-search-box";
  var 
googleSearchFrameWidth 800;
  var 
googleSearchDomain "www.google.com";
  var 
googleSearchPath "/cse";
</
script>
<
script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script
Should I have anything else in the file?
Dito guys, and I can not find the mistake
Reply With Quote
  #36  
Old 01-01-2010, 03:17 PM
Dave-ahfb Dave-ahfb is offline
 
Join Date: Mar 2002
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The code for your search results page looks fine. I have to ask if it may have been a case of "give google 10 minutes to update"? If not, make certain your form is calling the proper file. If the form call is correct paste the important part of your form here and I will check it out.
Reply With Quote
  #37  
Old 01-01-2010, 06:03 PM
SemperFideles's Avatar
SemperFideles SemperFideles is offline
 
Join Date: Oct 2006
Location: Northern VA
Posts: 223
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is the process I used to create a custom search results page. You can see the search in operation at http://www.puritanboard.com

1. In your Adsense Setup page for your Custom Search
  • Select Only sites I select
  • Type your URL (without http:/)
  • Select Use Safe Search (to avoid explicit content)
  • Under Open Search Results Page select Open results within my own site
  • In the block type http://www.yourforum.com/google.php
  • The rest of the settings you can figure out

2. Create a file called google.php to upload to your forum root. Here are my contents
PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''test');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('GOOGLE',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => 'Google Site Search'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'Google Custom Search';

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('GOOGLE');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('pagetitle'$pagetitle);
print_output($templater->render());

?>
3. Go to your AdminCP
  • Go to Styles & Templates -> Style Manager
  • Within your Style pulldown select Create New Templat
  • Name the Template GOOGLE
  • Paste the following code within:

PHP Code:
{vb:stylevar htmldoctype}
<
html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <
head>
    <
title>{vb:raw vboptions.bbtitle}</title>
    {
vb:raw headinclude}
  </
head>
  <
body>
    
    {
vb:raw header}
    
    {
vb:raw navbar}
    
    <
div id="pagetitle">
      <
h1>{vb:raw pagetitle}</h1>
    </
div>
    
    <
h2 class="blockhead">Google Custom Search</h2>
    <
div class="blockbody">
      <
div class="blockrow">

<
div id="cse-search-results"></div>
<
script type="text/javascript">
  var 
googleSearchIframeName "cse-search-results";
  var 
googleSearchFormName "cse-search-box";
  var 
googleSearchFrameWidth 800;
  var 
googleSearchDomain "www.google.com";
  var 
googleSearchPath "/cse";
</
script>
<
script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
      </
div>
    </
div>
    
    {
vb:raw footer}
  </
body>
</
html
4. Make the modifications to navbar as described herein. Here is my entire form within Navbar so you can see how mine was implemented (Google Adsense code modified):

PHP Code:
<form action="http://www.puritanboard.com/google.php" id="cse-search-box">
    <
input type="hidden" name="cx" value="partner-pub-xxxxxxxxxxx:xxxxxx-xxxx" />
    <
input type="hidden" name="cof" value="FORID:9" />
    <
input type="hidden" name="ie" value="ISO-8859-1" />
            <
span class="textboxcontainer"><span><input type="text" value="" name="q" class="textbox" /></span></span>
            <
span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search.png" name="sa" onclick="document.getElementById('navbar_search').submit;" />  </span></span>
        </
form>
<
script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script
Reply With Quote
  #38  
Old 01-02-2010, 04:16 AM
vivamexico55 vivamexico55 is offline
 
Join Date: Apr 2005
Posts: 66
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Semper, thanks! When you comment "// ###### YOUR CUSTOM CODE GOES HERE #####"
Are you referring to the Search Results Code? And where exactly do we paste it?

Or do we just paste everything into google.php without modifying anything? If I do that, I get a blank page.

thanks!
Reply With Quote
  #39  
Old 01-02-2010, 12:56 PM
SemperFideles's Avatar
SemperFideles SemperFideles is offline
 
Join Date: Oct 2006
Location: Northern VA
Posts: 223
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, you do not need to make any modifications to google.php. You can copy, paste, and save exactly as above. The only customization you need to make above is to Step 4. You can customize Step 3 by making the frame width for search higher but that's minor.

Regarding Step 4, when you go to Google Adsense in Step 1 to create your Custom Search (be sure to save that Custom Search), then you will be able to get the code you need from Google so your particular code is inserted where the XX's are in my example.

If you're getting a blank page then either you have not created the Template (Step 3) or you have not modified the navbar template correctly (Step 4). You should be able to test google.php out just by visiting the page. You'll see that the page works even if there are no search results. Also, make sure to set the file permissions to 755 for google.php
Reply With Quote
  #40  
Old 01-02-2010, 06:02 PM
vivamexico55 vivamexico55 is offline
 
Join Date: Apr 2005
Posts: 66
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you SO MUCH Semper! It is indeed working now, with the default google.php you supplied, my mistake was trying to add the code in there. Again, thanks =)
Reply With Quote
  #41  
Old 01-06-2010, 01:48 AM
volarium volarium is offline
 
Join Date: Mar 2005
Posts: 92
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by SemperFideles View Post
Here is the process I used to create a custom search results page.
Thanks for posting this, it made it very easy to implement.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:05 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.13894 seconds
  • Memory Usage 2,403KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (15)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete