TinyPortal

Development => Block Codes => Topic started by: extacy on February 27, 2006, 11:32:35 AM

Title: forum/google search block
Post by: extacy on February 27, 2006, 11:32:35 AM
May need to be moved, sorry....

I have been trying to come up with a search block that does exactly what the one on smf home page does. 1, sends you to a google site search and 2 sends you to a forum search. This is the best I can do with my limited knowledge of html/php etc. You just add this to a script box and change the 2 mysites.com to your own and you should be in business...

***You may need to change the "/forum" so it matches your forums location...***

<table border="0" cellspacing="1" style="border-collapse: collapse" width="13%" id="table1" height="105">
<tr>
<td align="left"><tbody><tr><th class="right" align="left">
<p style="margin-top: 0; margin-bottom: 0"><b><font color="#FF0000">Site Search</font></b></th></tr>
<tr>
<td class="right" align="left" valign="top" height="95">
<form style="margin-top: 4px; margin-bottom: 4px;" method="get" name="searchform" action="http://www.google.com/search" target="_top">
<input name="sitesearch" value="www.mysite.com" type="hidden">
<p style="margin-top: 0; margin-bottom: 0">
<input alt="search" style="width: 65px;height:22" name="as_q" size="20" type="text"> <input style="width: 41; font-weight: bold; height:26" value="GO" type="submit">
</p>
</form>

<p style="margin-top: 0; margin-bottom: 0"><b><font color="#FF0000">Forum Search</font></b></p>

<form action="http://www.mysite.com/forum/index.php?action=search2" method="post" target="_top" style="margin-top: 4px; margin-bottom: 4px;" method="get" name="searchform">
<p style="margin-top: 0; margin-bottom: 0">
<input name="search" style="width: 65px;height:22" name="as_q" size="20" type="text"> <input style="width: 42; font-weight: bold; height:26" value="GO" type="submit">
</p>
</form></td>
</tr>
</table>




I'm told it can be done easier with php, but me's don't know how.....

Anyone care to take a stab at it.....


Thanks
X




Title: Re: forum/google search block
Post by: Mitch on March 15, 2006, 01:05:17 AM
Just out of curiousity what is the difference of this and the actual search function?

Besides you can go to google.
Title: Re: forum/google search block
Post by: extacy on March 20, 2006, 09:27:28 AM
Well it searches your forum normally or a google site search.
As the 2 turn out way different results.

The real stupid thing about it is if you go to google adsence and get the code for adding a google site search and your site has not been indexed a whole lot by google,you will be lucky if you get 1 page of results. However if you do it the way laid out here you will get about 10 pages of results and you get credit with google adwords ($) for them doing the search.

The whole thing started out as we were tiring to get the same search as www.simplemachines.com w/ the pull down box and asked around on several forums for help with it. with not much help.... So we came up with our own jerry-rigged version of it..... Because everytime someone searches smf and forgets to pull down the tab to "community" they (smf) get paid from google..... and that's what we are really trying to do with this thing....... However they may be some problems with the way it interacts with adsence.... 


A subject that really should be looked into by the coding gurus as it can help all smf forum owners offset cost.....

I'm told smf does theirs with php...?. :uglystupid2:

thanks
X

Title: Re: forum/google search block
Post by: eldacar on March 20, 2006, 09:42:49 AM
Here's mine:
Put this in a file called search.php
<?php

// Search redirector

if ($_REQUEST['where'] == 'entire') {
header('Location: http://www.google.com/search?domains=somedomain.com&sitesearch=somedomain.com&q=' $_REQUEST['q']);
} else {
header('Location: http://somedomain.com/index.php?action=search2;search=' $_REQUEST['q']);
}

?>
And change your TPortalBlocks.template.php search function to:// TPortal searchblock
function TPortal_searchbox()
{
    global $context, $settings, $options, $txt , $scripturl;

echo '<form action="http://somedomain.com/search.php" method="post" style="text-align: center; margin: 0; margin-bottom: 3px;">
<input type="text" name="q" value="" style="width: 85%;" /><br />
<select id="where" name="where" style="width: 42%; margin-top: 2px;" >
<option value="entire">Entire Site</option>
<option value="forum" selected="selected">Forum</option>
</select>
<button type="submit" style="width: 42%; font-size: 85%;">', $txt[182], '</button>
</form>';

}
You can also add other places, I added an option to search my site's wiki.
Title: Re: forum/google search block
Post by: extacy on March 20, 2006, 10:11:20 AM
Hey thanks, I will look at it as soon as I awake... ;)
Title: Re: forum/google search block
Post by: TwinsX2Dad on March 20, 2006, 10:28:23 AM
Quote from: eldacar on March 20, 2006, 09:42:49 AM
Here's mine:
Put this in a file called search.php........

Now that is good - cleaner than the one I created. Now I have an extra something else to do.   ;D
Title: Re: forum/google search block
Post by: ontap on March 20, 2006, 05:07:19 PM
i wont ever be using a search box by google! nooooooo way  :tickedoff:
Title: Re: forum/google search block
Post by: Crip on March 20, 2006, 05:42:39 PM
OnTap!
you just plain don't like Google do ya.. hehehe :)
Title: Re: forum/google search block
Post by: TwinsX2Dad on March 20, 2006, 06:03:53 PM
Quote from: OnTap! on March 20, 2006, 05:07:19 PM
i wont ever be using a search box by google! nooooooo way  :tickedoff:

But Google is your friend........ Google is your friend........ Google is your friend........ Google is your friend........ Google is your friend........

Do you hear the utopian tone in that?

I now am seeing Logan's Run flashbacks.......   :coolsmiley:
Title: Re: forum/google search block
Post by: extacy on March 21, 2006, 04:20:03 AM
QuoteHere's mine:
Put this in a file called search.php

<?php

// Search redirector

if ($_REQUEST['where'] == 'entire') {
header('Location: http://www.google.com/search?domains=somedomain.com&sitesearch=somedomain.com&q=' $_REQUEST['q']);
} else {
header('Location: http://somedomain.com/index.php?action=search2;search=' $_REQUEST['q']);
}

?>



Hey,
This really looks great except 1 tiny problem.. No matter where i put this in my search.php it crashes when you do the forum search...

I replaced all the somedomain.com with ours etc...

The google part seems to work fine... I thought perhaps you might want us to make a new search.php with only this in it and i got the same results...   (crash)  Is there somehwere specific we need to put this code in our search.php or is there something else I'm missing?..  :uglystupid2:

This is exactly what I was looking for!!! THX ;)








Title: Re: forum/google search block
Post by: eldacar on March 21, 2006, 05:50:54 AM
That has to go in a new file called search.php (or anything else). Did you put it in the Search.php SMF source file? Haha, i should have been more clear..
Title: Re: forum/google search block
Post by: G6Cad on March 21, 2006, 07:33:09 AM
I allready have a search.php file in my source directory folder of SMF.

It contains a lot more code then the one i made from this code. Is it just to overwrite the old one, or is there an other way to do this?
Title: Re: forum/google search block
Post by: extacy on March 21, 2006, 08:08:09 AM
Ok, Mines all sorted out....

First cheers!!!!!!

Second,
Mine was giving me problems until I changed...

method="post"
to
method="get"
in
<form action="http://somedomain.com/search.php"method="post" style="text-align: center; margin: 0; margin-bottom: 3px;">

Don't ask me how or why, it works in that's good enough for me.... ;)

QuoteI allready have a search.php file in my source directory folder of SMF.


Thats the same problem I was making...

What I figured out is, he said we could make a file called anything (thingy.php) and put it just about anywhere in your directory w_w.mysite.com/lingerie/thingy.php

and as long as this matches the TPortal searchblock script he gave us, then you should be working. Provided you don't have the same issue I did....


// TPortal searchblock
function TPortal_searchbox()
{
    global $context, $settings, $options, $txt , $scripturl;

echo '<form action="http://w_w.mysite.com/lingerie/thingy.php" method="post" style="text-align: center; margin: 0; margin-bottom: 3px;">
<input type="text" name="q" value="" style="width: 85%;" />

<select id="where" name="where" style="width: 42%; margin-top: 2px;" >
<option value="entire">Entire Site</option>
<option value="forum" selected="selected">Forum</option>
</select>
<button type="submit" style="width: 42%; font-size: 85%;">', $txt[182], '</button>
</form>';

}


Thx Again eldacar
Great stuff!!!

Title: Re: forum/google search block
Post by: eldacar on March 21, 2006, 08:21:15 AM
Yes sorry, I should have explained more clearly. The code needs to go in a new file, which can be called anything, and can be located anywhere. Just change the url extacy coloured red in the last post and it should be fine ;)
And you don't have to use Google, it should work with any search engine.
Title: Re: forum/google search block
Post by: G6Cad on March 21, 2006, 10:47:41 AM
Now even I got this to work :)
Thanks for the extra help  :-*
Title: Re: forum/google search block
Post by: extacy on March 24, 2006, 06:25:23 AM
Ok, that worked great, now let's take it to the next level and have it "carry over" our google id/info so we get credit for the site searches that may occur. Somehow our google info needs to get incorporated in there.



<input type="hidden" name="client" value="pub-xxxxxxxxxxxxxxxxx"></input>
<input type="hidden" name="forid" value="1"></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:#009900;GL:1;DIV:#FFFFFF;VLC:660099;AH:center;BGC:FFFFFF;LBGC:303030;ALC:3300FF;LC:3300FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input>
<input type="hidden" name="hl" value="en"></input>


thanks!!!
Title: Re: forum/google search block
Post by: eldacar on March 24, 2006, 11:03:18 AM
What is that for?
Title: Re: forum/google search block
Post by: TwinsX2Dad on March 24, 2006, 06:53:12 PM
Quote from: extacy on March 24, 2006, 06:25:23 AM
Ok, that worked great, now let's take it to the next level and have it "carry over" our google id/info so we get credit for the site searches that may occur. Somehow our google info needs to get incorporated in there.

Perfect - you took a great idea and made it better. Nice job.
Title: Re: forum/google search block
Post by: nite0859 on March 31, 2006, 01:28:25 AM
Quote from: eldacar on March 24, 2006, 11:03:18 AM
What is that for?
Quote from: extacy on March 24, 2006, 06:25:23 AM
Ok, that worked great, now let's take it to the next level and have it "carry over" our google id/info so we get credit for the site searches that may occur. Somehow our google info needs to get incorporated in there.



<input type="hidden" name="client" value="pub-xxxxxxxxxxxxxxxxx"></input>
<input type="hidden" name="forid" value="1"></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:#009900;GL:1;DIV:#FFFFFF;VLC:660099;AH:center;BGC:FFFFFF;LBGC:303030;ALC:3300FF;LC:3300FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input>
<input type="hidden" name="hl" value="en"></input>


thanks!!!

The problem is that Google will punish you if you modify their code in any way whatsoever. Also, I don't know if Google will consider having their search executing at the same time as another kind of search as violating TOS.
Title: Re: forum/google search block
Post by: eldacar on April 01, 2006, 01:51:36 AM
Modifying google's code? another search at the same time? I still don't understand :S
Title: Re: forum/google search block
Post by: nite0859 on April 02, 2006, 05:14:54 AM
https://www.google.com/adsense/localized-terms?hl=en_US

Implementation and Operation of Ads, Search Results, and Referrals. You agree to comply with the specifications provided by Google from time to time to enable proper delivery, display, tracking, and reporting of Ads, Links, Search Results, Referral Buttons, and Google Brand Features (as defined in Section 12 below) in connection with Your Site(s), including without limitation by not modifying the JavaScript or other programming provided to You by Google in any way, unless expressly authorized in writing by Google (including by electronic mail).

AdSense for Search. If You have elected to receive Search Results, You will display on Your Site(s) a Google search box (a "Search Box") in accordance with the specifications provided by Google. Each Web page(s) that contains a Search Box must also contain other content related to Your Site. Except for related Google queries, all search queries (including queries entered into an Ad search box) must originate from individual human end users inputting data directly into a Search Box (or Ad search box, as applicable) on Your Site(s). You will send any and all queries (without editing, modifying, or filtering such queries individually or in the aggregate) to Google and Google will use commercially reasonable efforts to provide You with corresponding Search Results and/or Ads, as applicable and as available. Search Results and any accompanying Ads will be displayed on Web pages hosted by Google (each, a "Search Results Page"), the format, look and feel of which may be modified by Google from time to time.

Prohibited Uses. You shall not, and shall not authorize or encourage any third party to: (i) directly or indirectly generate queries, Referral Events, or impressions of or clicks on any Ad, Link, Search Result, or Referral Button through any automated, deceptive, fraudulent or other invalid means, including but not limited to through repeated manual clicks, the use of robots or other automated query tools and/or computer generated search requests, and/or the unauthorized use of other search engine optimization services and/or software; (ii) edit, modify, filter or change the order of the information contained in any Ad, Link, Ad Unit, Search Result, or Referral Button, or remove, obscure or minimize any Ad, Link, Ad Unit, Search Result, or Referral Button in any way; (iii) frame, minimize, remove or otherwise inhibit the full and complete display of any Web page accessed by an end user after clicking on any part of an Ad ("Advertiser Page"), any Search Results Page, or any Referral Page; (iv) redirect an end user away from any Advertiser Page, Search Results Page, or Referral Page; provide a version of the Advertiser Page, Search Results Page, or Referral Page that is different from the page an end user would access by going directly to the Advertiser Page, Search Results Page, or Referral Page; intersperse any content between the Ad and the Advertiser Page, between the page containing the Search Box and the Search Results Page, or between the Referral Button and the Referral Page; or otherwise provide anything other than a direct link from an Ad to an Advertiser Page, from the page containing the Search Box to the Search Results Page, or from the Referral Button to the Referral Page; (v) display any Ad(s), Link(s), or Referral Button(s) on any error page, on any registration or "thank you" page (e.g., a page that thanks a user after he/she has registered with the applicable Web site), on any chat page, in any email, or on any Web page or any Web site that contains any pornographic, hate-related, violent, or illegal content; (vi) directly or indirectly access, launch, and/or activate Ads, Links, Search Results, or Referral Buttons through or from, or otherwise incorporate the Ads, Links, Search Results, or Referral Buttons in, any software application, Web site, or other means other than Your Site(s), and then only to the extent expressly permitted by this Agreement (e.g., while Search Results may be indirectly accessed from Your Site(s), they may only be displayed on the appropriate Google-hosted Web page); (vii) "crawl", "spider", index or in any non-transitory manner store or cache information obtained from any Ads, Links, Search Results, or Referral Events, or any part, copy, or derivative thereto; (viii) act in any way that violates any Program Policies posted on the Google Web Site, as may be revised from time to time, or any other agreement between You and Google (including without limitation the Google AdWords program terms), or engage in any action or practice that reflects poorly on Google or otherwise disparages or devalues Google’s reputation or goodwill. You acknowledge that any attempted participation or violation of any of the foregoing is a material breach of this Agreement and that we may pursue any and all applicable legal and equitable remedies against You, including an immediate suspension of Your account or termination of this Agreement, and the pursuit of all available civil or criminal remedies.

Title: Re: forum/google search block
Post by: eldacar on April 02, 2006, 05:33:17 AM
Hmmm. But this isn't using 'AdSense for Search'.
Title: Re: forum/google search block
Post by: nite0859 on April 02, 2006, 05:46:29 AM
Well, the fact of the matter is that I could be mis-interpreting Google's TOS. For all I know, it is acceptable to integrate Google's search function along inside the general searching features already built into SMF. Earlier, some one mentioned that it would be useful to put in one's own Google ID so that one could get credit for performing a Google search. I wasn't quite sure if doing such a thing would violate Google's TOS, though.

Title: Re: forum/google search block
Post by: eldacar on April 02, 2006, 06:08:58 AM
All I was doing was simply making a search box that links to a google url. There are no ads, no skewing results, no being naughty. I don't see any problems with my code. It is possible that it violates one of the 20 ToS Google has, but if so that ToS is probably unfair and deserving to be broken.
Title: Re: forum/google search block
Post by: nite0859 on April 02, 2006, 06:15:59 AM
Well, the ToS only applied if you're attempting to make money from Google, I would imagine. So, following the letter of the ToS is more important for those who are attempting to make some money. If you're not using Google to generate revenue, then I suppose it really doesn't matter. That's my opinion anyhow.
Title: Re: forum/google search block
Post by: RoarinRow on July 25, 2006, 12:31:08 AM
I found this code that combines a Google Search and a site search in one in a script/html block

<form method="get" action="http://www.google.com/search" target='_blank'>

<input type="text"   name="q" size="25"
maxlength="140" value="" />
<input type="submit" value="Google Search" />
<br />
<input type="radio"  name="sitesearch" value="" checked />
The Web
<input type="radio"  name="sitesearch"
value="avalanchestyle.com" /> AVS<br />

</form>


1.  Modified it so that my search results would open up in a new window
2.  Adjusted the setting to size = "25" so that the input field would not extend pass my block's theme.  Same goes with maxlength, I changed that to 140
3.  Changed where the radio button defaults to from my site to 'The Web'
4.  Change the value to your own site's domain without the 'www'
5.  Used my site's abbreviation to it would not take too much space

Source is from - here (http://www.askdavetaylor.com/how_can_i_add_a_google_search_box_to_my_web_site.html).

Note that it will only provide site search results based on what information Google has indexed from your site.  This is what makes it different from your own forum's search feature.

It also give you the regular Google search results screen instead of a customize results screen from the original code in this thread.
Title: Re: forum/google search block
Post by: yjobcreations on October 02, 2006, 01:56:59 AM
the only way you can violate the Google Search TOS is by applying for an account with Adsense for Search, however, if you just made a search code that takes you to google search page there is no adsense account involved in it so there is no such thing as TOS being tied up with your code.
Title: Re: forum/google search block
Post by: Shadow on February 15, 2007, 02:47:26 AM
I hope you don't mind of me edit this code some. 

It's show correct in FireFox but it won't show correct in IE, So i put a code on this topic for IE user's.

FireFox user's use this code!

Put this code in scriptbox

<form method="get" action="http://www.google.com/search" target='_blank'>

<input type="text"   name="q" size="23"
maxlength="140" value="" />
<center><input type="submit" value="Google Search" />
<br /></center>
</form>


This code is only Google Search

IE User's use this code!

Put this code in scriptbox. Now in IE it's will show correct. But it's won't show right in FireFox...


<form method="get" action="http://www.google.com/search" target='_blank'>

<input type="text"   name="q" size="28"
maxlength="140" value="" />
<input type="submit" value="Google Search" />
<br />
</form>

Title: Re: forum/google search block
Post by: catchpen on October 25, 2007, 02:45:06 AM
I took the small Google banner off the search snippet I got from my Goggle Adsense account to make it look more like part of my site, it does go to google.com for search results and shows ads to make Google happy. Does anyone know if that violates the TOS?

Thanks.
Title: Re: forum/google search block
Post by: Marook on November 09, 2007, 09:34:45 PM
I did it that way :

replace the first function TPortal_searchbox() in TPortalBlocks.template.php with the following one. Adjust the sitesearch url to your domain and place a file called google.gif in the images dir of your current theme.


// TPortal searchblock
function TPortal_searchbox()
{
global $context, $settings, $options, $txt , $scripturl;

echo '
<form  accept-charset="', $context['character_set'], '" action="', $scripturl, '?action=search2" method="post" style="padding: 0; text-align: center; margin: 0; margin-bottom: 5px;"><br />
    <input type="text" name="search" value="" style="width: 85%;" /><br />
<input type="submit" name="submit" value="', $txt[182], '" style="width: 90%; margin: 4px;" /><br /><span class="smalltext">
<a href="', $scripturl, '?action=search;advanced">', $txt['smf298'], '</a></span>
<input type="hidden" name="advanced" value="0" /></form>
    <hr><center><img src="'.$settings['images_url'].'/google.gif"<center /><br />
    <form method="GET" action="http://www.google.com/search" target="_blank" style="padding: 0; text-align: center; margin: 0; margin-bottom: 5px;">
    <input type="text" name="q" style="width: 85%;" value="" />
    <input type="submit" value="Google Search" style="width: 90%; margin: 4px;" /><br />
    <input type="radio"  name="sitesearch" value="" checked />The Web<br />
    <input type="radio"  name="sitesearch" value="yourdomain.com" /> marook-online<br /></form>
  ';
}


And your default search block will have now a new option to search with google.

Demo : here (http://www.marook-online.de)