2 rcs_id('$Id: GooglePlugin.php,v 1.5 2004-06-13 14:30:26 rurban Exp $');
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 getVersion() {
51 return preg_replace("/[Revision: $]/", '',
55 function getDefaultArguments() {
56 return array('q' => '',
57 'mode' => 'search', // or 'cache' or 'spell'
59 'maxResults' => 10, // fixed to 10 for now by google
62 //'license_key' => false,
66 function run($dbi, $argstr, &$request, $basepage) {
67 $args = $this->getArgs($argstr, $request);
68 // if (empty($args['s']))
73 if ($q and $request->isPost()) {
74 require_once("lib/Google.php");
75 $google = new Google();
76 if (!$google) return '';
78 case 'search': $result = $google->doGoogleSearch($q); break;
79 case 'cache': $result = $google->doGetCachedPage($q); break;
80 case 'spell': $result = $google->doSpellingSuggestion($q); break;
82 trigger_error("Invalid mode");
84 if (isa($result,'HTML'))
85 $html->pushContent($result);
86 if (isa($result,'GoogleSearchResults')) {
87 //TODO: result template
88 if (!empty($result->resultElements)) {
90 foreach ($result->resultElements as $res) {
91 $li = HTML::li(LinkURL($res['URL'],$res['directoryTitle']),HTML::br(),
92 $res['directoryTitle'] ? HTML(HTML::raw(' '),HTML::em($res['summary']),' -- ',LinkURL($res['URL'])) : '');
93 $list->pushContent($li);
95 $html->pushContent($list);
98 return _("Nothing found");
100 if (is_string($result)) {
101 // cache content also?
102 $html->pushContent(HTML::blockquote(HTML::raw($result)));
105 if ($formsize < 1) $formsize = 30;
107 $form = HTML::form(array('action' => $request->getPostURL(),
109 //'class' => 'class', //fixme
110 'accept-charset' => $GLOBALS['charset']),
111 HiddenInputs(array('pagename' => $basepage,
113 $form->pushContent(HTML::input(array('type' => 'text',
116 'size' => $formsize)));
117 $form->pushContent(HTML::input(array('type' => 'submit',
119 'value' => gettext($mode)
121 return HTML($html,$form);
125 // $Log: not supported by cvs2svn $
126 // Revision 1.4 2004/06/13 14:15:28 rurban
127 // GooglePlugin now actually works (templated result missing)
129 // Revision 1.3 2004/06/13 13:54:25 rurban
130 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
131 // FoafViewer: Check against external requirements, instead of fatal.
132 // Change output for xhtmldumps: using file:// urls to the local fs.
133 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
134 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
136 // Revision 1.2 2004/04/18 01:11:52 rurban
137 // more numeric pagename fixes.
138 // fixed action=upload with merge conflict warnings.
139 // charset changed from constant to global (dynamic utf-8 switching)
141 // Revision 1.1 2004/02/29 01:37:59 rurban
142 // New experimental feature: use the Google API directly
143 // Needs a free license key and the soap library nosoap,
144 // Todo: templates for search and results, some proxy debugging
146 // Revision 1.7 2004/02/22 23:20:33 rurban
147 // fixed DumpHtmlToDir,
148 // enhanced sortby handling in PageList
149 // new button_heading th style (enabled),
150 // added sortby and limit support to the db backends and plugins
151 // for paging support (<<prev, next>> links on long lists)
153 // Revision 1.6 2004/02/19 22:06:53 rurban
154 // use new class, to be able to get rid of lib/interwiki.php
156 // Revision 1.5 2003/02/26 01:56:52 dairiki
157 // Tuning/fixing of POST action URLs and hidden inputs.
159 // Revision 1.4 2003/01/30 02:46:46 carstenklapp
160 // Bugfix: Plugin was redirecting to nonexistant local wiki page named
161 // "ExternalSearch" instead of the invoked url. Reported by Arthur Chereau.
163 // Revision 1.3 2003/01/18 21:41:01 carstenklapp
165 // Reformatting & tabs to spaces;
166 // Added copyleft, getVersion, getDescription, rcs_id.
173 // c-hanging-comment-ender-p: nil
174 // indent-tabs-mode: nil