4 * Copyright 2004 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 require_once("lib/Google.php");
26 * This module is a wrapper for the Google Web APIs. It allows you to do Google searches,
27 * retrieve pages from the Google cache, and ask Google for spelling suggestions.
29 * Note: You must first obtain a license key at http://www.google.com/apis/
30 * Max 1000 queries per day.
32 * Other possible sample usages:
33 * Auto-monitor the web for new information on a subject
34 * Glean market research insights and trends over time
35 * Invent a catchy online game
36 * Create a novel UI for searching
37 * Add Google's spell-checking to an application
39 class WikiPlugin_GooglePlugin
43 return _("GooglePlugin");
46 function getDescription () {
47 return _("Make use of the Google API");
50 function getDefaultArguments() {
51 return array('q' => '',
52 'mode' => 'search', // or 'cache' or 'spell'
54 'maxResults' => 10, // fixed to 10 for now by google
57 //'license_key' => false,
61 function run($dbi, $argstr, &$request, $basepage) {
62 $args = $this->getArgs($argstr, $request);
63 // if (empty($args['s']))
68 if ($q and $request->isPost()) {
69 require_once("lib/Google.php");
70 $google = new Google();
71 if (!$google) return '';
73 case 'search': $result = $google->doGoogleSearch($q); break;
74 case 'cache': $result = $google->doGetCachedPage($q); break;
75 case 'spell': $result = $google->doSpellingSuggestion($q); break;
77 trigger_error("Invalid mode");
79 if (isa($result,'HTML'))
80 $html->pushContent($result);
81 if (isa($result,'GoogleSearchResults')) {
82 //TODO: result template
83 if (!empty($result->resultElements)) {
85 foreach ($result->resultElements as $res) {
86 $li = HTML::li(LinkURL($res['URL'],$res['directoryTitle']),HTML::br(),
87 $res['directoryTitle'] ? HTML(HTML::raw(' '),HTML::em($res['summary']),' -- ',LinkURL($res['URL'])) : '');
88 $list->pushContent($li);
90 $html->pushContent($list);
93 return _("Nothing found");
95 if (is_string($result)) {
96 // cache content also?
97 $html->pushContent(HTML::blockquote(HTML::raw($result)));
100 if ($formsize < 1) $formsize = 30;
102 $form = HTML::form(array('action' => $request->getPostURL(),
104 //'class' => 'class', //fixme
105 'accept-charset' => $GLOBALS['charset']),
106 HiddenInputs(array('pagename' => $basepage,
108 $form->pushContent(HTML::input(array('type' => 'text',
111 'size' => $formsize)));
112 $form->pushContent(HTML::input(array('type' => 'submit',
114 'value' => gettext($mode)
116 return HTML($html,$form);
124 // c-hanging-comment-ender-p: nil
125 // indent-tabs-mode: nil