1 # Copyright (C) 2007 Alex Schroeder <alex@gnu.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use vars
qw($GoogleCustomSearchEngine);
21 $GoogleCustomSearchEngine = 'http://www.google.com/cse?cx=004774160799092323420:6-ff2s0o6yi&q=';
23 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/google-custom-search.pl">google-custom-search.pl</a></p>';
28 # No more searching of titles
29 *OldGoogleCustomGetSearchLink = *GetSearchLink;
30 *GetSearchLink = *NewGoogleCustomGetSearchLink;
32 sub NewGoogleCustomGetSearchLink {
33 my ($text, $class, $name, $title) = @_;
34 $text = NormalToFree($text);
35 # It would be complicated to use ScriptLink here because of quoting
36 # issues: ScriptUrl expects a quoted URL, which it then proceeds to
37 # unquote again, etc. It's safer to just copy the necessary code
40 $params{'-rel'} = 'nofollow';
41 $params{-href} = $GoogleCustomSearchEngine . UrlEncode(qq("$text"));
42 $params{'-class'} = $class if $class;
43 $params{'-name'} = UrlEncode($name) if $name;
44 $params{'-title'} = $title if $title;
45 return $q->a(\%params, $text);
48 *OldGoogleCustomGetHeader = *GetHeader;
49 *GetHeader = *NewGoogleCustomGetHeader;
51 sub NewGoogleCustomGetHeader {
52 my $html = OldGoogleCustomGetHeader(@_);
54 <!-- Google CSE Search Box Begins -->
55 <form class="tiny" action="http://www.google.com/cse" id="searchbox_004774160799092323420:6-ff2s0o6yi"><p>
56 <input type="hidden" name="cx" value="004774160799092323420:6-ff2s0o6yi" />
57 <input type="text" name="q" size="25" />
58 <input type="submit" name="sa" value="Search" />
60 <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_004774160799092323420%3A6-ff2s0o6yi"></script>
61 <!-- Google CSE Search Box Ends -->
63 $html =~ s{</span>}{</span>$form};