Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Template Modifications

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
  #182  
Old 05-28-2013, 02:08 PM
slcousin slcousin is offline
 
Join Date: Sep 2006
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Confirmed working on 4.2 as per SemperFideles instructions:

http://www.supermotoforum.co.uk/

Thanks for the help!
Reply With Quote
  #183  
Old 06-01-2013, 06:38 AM
Lpspider Lpspider is offline
 
Join Date: Oct 2005
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Managed to get this working with two issues:

- it breaks my header style - logo not showing up, forumhome sidebar shows on the bottom of the page, and it shows a large blank space below the results.
Reply With Quote
  #184  
Old 06-23-2013, 06:58 PM
fxdigi-cash fxdigi-cash is offline
 
Join Date: Jul 2012
Posts: 674
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks first for the great effort and trying to share the good stuff...

I believe there is something missing here, which is google.php connection to the search box. I tested your way, but not really working as I expected. It opens new page on google search while actually we want the search to be taking place in the forum itself using the google.php...

what I did is the following:

1- created google.php "or whatever you like to call it"
2- created a template for google search as mentioned earlier.
3- placed google script in headeinclude template from my google custom search similar to this one:
Code:
<script>
  (function() {
    var cx = '00000000000000:aaaaaaaaaaa'; ///////////////CHANGE THIS TO YOUR OWN ID //// 
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
4- in the navtab, I edited the source in
Code:
<form action 
.... vb code for search box + button
</form>
to this:
Code:
<form method="get" action="http://www.YOUR VB LINK.com/google.php" target="_blank" class="navbar_search">
            <input type="hidden" name="sitesearch" value="YOUR VB LINK.com"  id="pn"/>
            <span class="textboxcontainer"><span><input type="text" value="" name="q" class="textbox" tabindex="99"/></span></span>
            <span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search.png" name="submit" style="border:0; margin-left:5px;" onclick="document.getElementById('navbar_search').submit;" tabindex="100"/></span></span>
        <input type="hidden" name="domains" value="YOUR VB LINK.com"/>
</form>
replace the red tag with your forum url.

5- Last step, I added <gcse:search></gcse:search> in my google.php custom page...

Save the whole work and check it out...

I tested it and works perfect.

Thanks, and good luck.

Quote:
Originally Posted by svensonsan View Post
There is an update for this with the latest (v2) version of google custom search. I really like the google cse in vbulletin. It's much faster and with some styling in the css even the Google cse v2 will work in vbulletin 4.2

This short instruction will help if you use a two-page CSE as shown in the documentation at Multiple search boxes and results sections.

Already mentioned here:

1. Create the google.php file as mentioned on page 3 in this thread.
2. Create the GOOGLE template as mentioned on page 3 in this thread.

Now the new stuff.

1. headinclude template
copy the script-snippet at the bottom of your headinclude template.

Code:
<!-- google cse -->
<script>
  (function() {
    var cx = '00000000000000:aaaaaaaaaaa'; ///////////////CHANGE THIS TO YOUR OWN ID //// 
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<!-- / google cse -->
This will "enable" the searchform and searchresults in general in your forum.


2. navbar template
Display the search form in the navigation

Search for <form action="search.php ....
comment the normal search form
Code:
<vb:comment><form action 
.... a few lines 
</form></vb:comment>
Enter the new google search form under the global search div.

Code:
<div id="globalsearch" class="globalsearch">
<gcse:searchbox-only></gcse:searchbox-only>
Now you have the search form in your forum and yes, styling will follow.

but first edit the

3. GOOGLE Template

Should look like this:

Code:
<div class="blockrow">

<gcse:search></gcse:search>

      </div>
Not the long and old version mentioned in this thread. Only the <gcse:search></gcse:search> is used to display the search results and the search bar.
If you only want to show the search results you can use <gcse:searchresults-only></gcse:searchresults-only>

4. additional.css template
The search form will look broken at first.
You should modify at least the following styles:


Code:
input.gsc-input {
font-size:11px !important;
}

#globalsearch .gsc-input-box { 
border:none !important; 
height:22px !important; 
}

#globalsearch input.gsc-search-button-v2 {
padding:4px 20px !important;
margin-top:1px !important;
}
Reply With Quote
  #185  
Old 07-28-2013, 11:03 AM
SimonB SimonB is offline
 
Join Date: Jun 2012
Posts: 52
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by fxdigi-cash View Post
Thanks first for the great effort and trying to share the good stuff...

I believe there is something missing here, which is google.php connection to the search box. I tested your way, but not really working as I expected. It opens new page on google search while actually we want the search to be taking place in the forum itself using the google.php...

what I did is the following:
Thanks for posting this update.

It works fine for my site although i had to make a couple of style mods.

My one question is: I have linked my CSE to my Adsense Account, but the ads are not displaying in the search results page, although adsense is working perfectly on my actual site. Is this an adsense problem, or is there something I still need to do?
Reply With Quote
  #186  
Old 07-28-2013, 12:04 PM
fxdigi-cash fxdigi-cash is offline
 
Join Date: Jul 2012
Posts: 674
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have no idea how that should work, sorry about that, mate
Reply With Quote
  #187  
Old 09-27-2013, 05:43 AM
amogh amogh is offline
 
Join Date: Mar 2011
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The mod is working great on VB 4.2

However I have an issue. It is working ONLY on the custom theme and not on the default theme.

Any idea how do I fix this?

Thanks
Reply With Quote
  #188  
Old 04-12-2014, 09:09 AM
Charis Charis is offline
 
Join Date: Oct 2009
Location: Thessaloniki, Greece
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I followed the instructions but doesn't work (eMesitis.gr vB4.2.2).
Unfortunately I get a blank page.
I would appreciate any help.

1) I created a new Template called "GOOGLE":
PHP Code:
<div class="blockrow">
    <
gcse:search></gcse:search>
</
div
2) I created a "google.php" page. (I added <gcse:search></gcse:search> as you can see)
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 #####
<script>
$pagetitle 'Google Custom Search';
<
gcse:search></gcse: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());

?>
I added the following code to the end of "headinclude" template:
PHP Code:
<!-- google CSE -->
<
script>
  (function() {
    var 
cx '<script>
  (function() {
    var cx = '
partner-pub-6928381629786967:3340711439';
    var gcse = document.createElement('
script');
    gcse.type = '
text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == '
https:' ? 'https:' : 'http:') +
        '
//www.google.com/cse/cse.js?cx=' + cx;
    
var document.getElementsByTagName('script')[0];
    
s.parentNode.insertBefore(gcses);
  })();
</
script>
<!-- 
google CSE  --> 
I replaced the
PHP Code:
<form action .... (vb code for search box button) ... </form
in "navbar" template with the following code:
PHP Code:
<form method="get" action="http://www.emesitis.gr/google.php" target="_blank" class="navbar_search">
            <
input type="hidden" name="sitesearch" value="emesitis.gr"  id="pn"/>
            <
span class="textboxcontainer"><span><input type="text" value="" name="q" class="textbox" tabindex="99"/></span></span>
            <
span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search.png" name="submit" style="border:0; margin-left:5px;" onclick="document.getElementById('navbar_search').submit;" tabindex="100"/></span></span>
        <
input type="hidden" name="domains" value="emesitis.gr"/>
</
form
Finally, I added the following code into "additional.css" template:
PHP Code:
input.gsc-input {
font-size:11px !important;
}

#globalsearch .gsc-input-box { 
border:none !important
height:22px !important
}

#globalsearch input.gsc-search-button-v2 {
padding:4px 20px !important;
margin-top:1px !important;

Reply With Quote
  #189  
Old 04-12-2014, 05:01 PM
ramesh_umk3 ramesh_umk3 is offline
 
Join Date: Jul 2010
Location: Earth
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

See mostly is happens when your running site on folder of root server..

In Google.php file uncomment below line
Quote:
// chdir ('/path/to/your/forums'); (And mention your site path)
Regards,
Reply With Quote
Благодарность от:
Charis
  #190  
Old 04-14-2014, 05:40 AM
Charis Charis is offline
 
Join Date: Oct 2009
Location: Thessaloniki, Greece
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks mate but it didn't work.
I found my forum path using the following php:
PHP Code:
 <?php
echo getcwd();
So my forum path is: /home3/emesitis/public_html

After that I followed your instructions and uncomment the path line in google.php:
PHP Code:
chdir ('/home3/emesitis/public_html'); 
I still have a complete blank page.

In google.php there are three lines:
PHP Code:
define('THIS_SCRIPT''test');
define('CSRF_PROTECTION'true);  
// change this depending on your filename 
Which filename?
Should I change the 'test' on the first line?
Reply With Quote
  #191  
Old 04-14-2014, 12:38 PM
ramesh_umk3 ramesh_umk3 is offline
 
Join Date: Jul 2010
Location: Earth
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

try to create only test.php there were some tutorials here see you have blank page on that too . If you have same problem on test.php then tell your host to fix permissions on your account
cause the problem you would be getting is 500 internal server error which would be either permission or path error
Reply With Quote
Reply

Thread Tools

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 04:54 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.12270 seconds
  • Memory Usage 2,411KB
  • Queries Executed 28 (?)
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
  • (8)bbcode_code
  • (19)bbcode_php
  • (3)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
  • (3)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (1)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • 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
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete