1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # |
---|
4 | # This file is part of External Search, a plugin for Dotclear 2 |
---|
5 | # Copyright (C) 2009 Moe (http://gniark.net/) |
---|
6 | # |
---|
7 | # External Search is free software; you can redistribute it and/or |
---|
8 | # modify it under the terms of the GNU General Public License v2.0 |
---|
9 | # as published by the Free Software Foundation. |
---|
10 | # |
---|
11 | # External Search is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with this program; if not, write to the Free Software Foundation, |
---|
18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
19 | # |
---|
20 | # ***** END LICENSE BLOCK ***** |
---|
21 | |
---|
22 | if (!defined('DC_RC_PATH')) {return;} |
---|
23 | |
---|
24 | $core->addBehavior('initWidgets',array('externalSearchWidget', |
---|
25 | 'initWidgets')); |
---|
26 | |
---|
27 | /** |
---|
28 | @ingroup External Search |
---|
29 | @brief Widget |
---|
30 | */ |
---|
31 | class externalSearchWidget |
---|
32 | { |
---|
33 | /** |
---|
34 | widget |
---|
35 | @param w <b>object</b> Widget |
---|
36 | */ |
---|
37 | public static function initWidgets(&$w) |
---|
38 | { |
---|
39 | $w->create('externalSearchWidget',__('External search engine'), |
---|
40 | array('externalSearchWidget','show')); |
---|
41 | |
---|
42 | $w->externalSearchWidget->setting('title', |
---|
43 | __('Title:').' ('.__('optional').')', |
---|
44 | __('Search'),'text'); |
---|
45 | |
---|
46 | $w->externalSearchWidget->setting('engine',__('Search engine:'), |
---|
47 | null,'combo',array( |
---|
48 | 'Bing' => 'bing', |
---|
49 | 'Google' => 'google', |
---|
50 | 'Yahoo!' => 'yahoo', |
---|
51 | ) |
---|
52 | ); |
---|
53 | |
---|
54 | $w->externalSearchWidget->setting('homeonly',__('Home page only'), |
---|
55 | false,'check'); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | show widget |
---|
60 | @param w <b>object</b> Widget |
---|
61 | @return <b>string</b> XHTML |
---|
62 | */ |
---|
63 | public static function show(&$w) |
---|
64 | { |
---|
65 | global $core; |
---|
66 | |
---|
67 | if ($w->homeonly && $core->url->type != 'default') { |
---|
68 | return; |
---|
69 | } |
---|
70 | |
---|
71 | $url = preg_replace('/^(http([s]*)\:\/\/)/i','', |
---|
72 | $core->blog->url); |
---|
73 | |
---|
74 | # output |
---|
75 | $header = (strlen($w->title) > 0) |
---|
76 | ? '<h2>'.html::escapeHTML($w->title).'</h2>' : null; |
---|
77 | |
---|
78 | switch($w->engine) |
---|
79 | { |
---|
80 | case 'bing' : |
---|
81 | # add site:http://example.com/ to bing search |
---|
82 | $form = |
---|
83 | '<form method="post" action="'.$core->blog->url. |
---|
84 | $core->url->getBase('externalSearch').'">'. |
---|
85 | '<p><input type="text" size="10" maxlength="255" name="q" />'. |
---|
86 | form::hidden(array('engine'),$w->engine). |
---|
87 | ' <input class="submit" type="submit" value="ok" /></p>'. |
---|
88 | '</form>'; |
---|
89 | break; |
---|
90 | case 'google' : |
---|
91 | $form = |
---|
92 | '<form method="get" action="http://www.google.com/search">'. |
---|
93 | '<p><input type="text" size="10" maxlength="255" '. |
---|
94 | 'name="q" />'. |
---|
95 | form::hidden(array('domains'),$url). |
---|
96 | form::hidden(array('sitesearch'),$url). |
---|
97 | ' <input class="submit" type="submit" value="ok" /></p>'. |
---|
98 | '</form>'; |
---|
99 | break; |
---|
100 | case 'yahoo' : |
---|
101 | $form = |
---|
102 | '<form method="get" action="http://search.yahoo.com/search">'. |
---|
103 | '<p><input type="text" size="10" maxlength="255" '. |
---|
104 | 'name="p" />'. |
---|
105 | form::hidden(array('vs'),$url). |
---|
106 | ' <input class="submit" type="submit" value="ok" /></p>'. |
---|
107 | '</form>'; |
---|
108 | break; |
---|
109 | |
---|
110 | default : |
---|
111 | throw new Exception(__('invalid search engine')); |
---|
112 | break; |
---|
113 | } |
---|
114 | |
---|
115 | return '<div class="externalSearch">'.$header.$form.'</div>'; |
---|
116 | } |
---|
117 | } |
---|
118 | ?> |
---|