2007-01-12 02:00:44 +00:00
|
|
|
# Copyright (C) 2007 Alex Schroeder <alex@emacswiki.org>
|
2007-01-02 20:16:35 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2007-01-02 20:16:35 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-01-02 20:16:35 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('google-search.pl', 'Use Google For Searches');
|
2007-01-02 20:16:35 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %Action, $ScriptName, @MyInitVariables);
|
|
|
|
|
our ($GoogleSearchDomain, $GoogleSearchExclusive);
|
2007-11-14 13:10:20 +00:00
|
|
|
|
|
|
|
|
$GoogleSearchDomain = undef;
|
|
|
|
|
$GoogleSearchExclusive = 1;
|
2007-01-02 20:16:35 +00:00
|
|
|
|
|
|
|
|
$Action{search} = \&DoGoogleSearch;
|
|
|
|
|
|
|
|
|
|
push(@MyInitVariables, \&GoogleSearchInit);
|
|
|
|
|
|
|
|
|
|
sub GoogleSearchInit {
|
|
|
|
|
# If $ScriptName does not contain a hostname, this extension will
|
|
|
|
|
# have no effect. Domain regexp based on RFC 2396 section 3.2.2.
|
2007-11-14 13:10:20 +00:00
|
|
|
if (!$GoogleSearchDomain) {
|
|
|
|
|
my $alpha = '[a-zA-Z]';
|
|
|
|
|
my $alphanum = '[a-zA-Z0-9]';
|
|
|
|
|
my $alphanumdash = '[-a-zA-Z0-9]';
|
|
|
|
|
my $domainlabel = "$alphanum($alphanumdash*$alphanum)?";
|
|
|
|
|
my $toplabel = "$alpha($alphanumdash*$alphanum)?";
|
|
|
|
|
if ($ScriptName =~ m!^(https?://)?([^/]+\.)?($domainlabel\.$toplabel)\.?(:|/|\z)!) {
|
|
|
|
|
$GoogleSearchDomain = $3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($GoogleSearchDomain
|
|
|
|
|
and GetParam('search', undef)
|
|
|
|
|
and not GetParam('action', undef)
|
|
|
|
|
and not GetParam('old', 0)) {
|
|
|
|
|
SetParam('action', 'search');
|
2007-01-02 20:16:35 +00:00
|
|
|
}
|
2015-04-12 22:50:50 +03:00
|
|
|
*SearchTitleAndBody = \&GoogleSearchDoNothing if $GoogleSearchExclusive;
|
2007-11-14 13:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# disable all other searches
|
|
|
|
|
sub GoogleSearchDoNothing {
|
|
|
|
|
undef;
|
2007-01-02 20:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub DoGoogleSearch {
|
|
|
|
|
my $search = GetParam('search', undef);
|
|
|
|
|
print $q->redirect({-uri=>"http://www.google.com/search?q=site%3A$GoogleSearchDomain+$search"});
|
|
|
|
|
}
|