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 | null, |
---|
42 | __('External search engine form')); |
---|
43 | |
---|
44 | $w->externalSearchWidget->setting('title',__('Title (optional)').' :',__('Search')); |
---|
45 | |
---|
46 | $w->externalSearchWidget->setting('engine',__('Search engine:'), |
---|
47 | null,'combo',array( |
---|
48 | 'Bing' => 'bing', |
---|
49 | 'Google' => 'google', |
---|
50 | 'Yahoo!' => 'yahoo', |
---|
51 | ) |
---|
52 | ); |
---|
53 | $w->externalSearchWidget->setting('homeonly',__('Display on:'),0,'combo', |
---|
54 | array( |
---|
55 | __('All pages') => 0, |
---|
56 | __('Home page only') => 1, |
---|
57 | __('Except on home page') => 2 |
---|
58 | ) |
---|
59 | ); |
---|
60 | $w->externalSearchWidget->setting('content_only',__('Content only'),0,'check'); |
---|
61 | $w->externalSearchWidget->setting('class',__('CSS class:'),''); |
---|
62 | $w->externalSearchWidget->setting('offline',__('Offline'),0,'check'); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | show widget |
---|
67 | @param w <b>object</b> Widget |
---|
68 | @return <b>string</b> XHTML |
---|
69 | */ |
---|
70 | public static function show($w) |
---|
71 | { |
---|
72 | global $core; |
---|
73 | |
---|
74 | if ($w->offline) |
---|
75 | return; |
---|
76 | |
---|
77 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
78 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
79 | return; |
---|
80 | } |
---|
81 | |
---|
82 | $url = preg_replace('/^(http([s]*)\:\/\/)/i','', |
---|
83 | $core->blog->url); |
---|
84 | |
---|
85 | switch($w->engine) |
---|
86 | { |
---|
87 | case 'bing' : |
---|
88 | # add site:http://example.com/ to bing search |
---|
89 | $form = |
---|
90 | '<form method="post" action="'.$core->blog->url. |
---|
91 | $core->url->getBase('externalSearch').'">'. |
---|
92 | '<p><input type="text" size="10" maxlength="255" name="q" />'. |
---|
93 | form::hidden(array('engine'),$w->engine). |
---|
94 | ' <input class="submit" type="submit" value="ok" /></p>'. |
---|
95 | '</form>'; |
---|
96 | break; |
---|
97 | case 'google' : |
---|
98 | $form = |
---|
99 | '<form method="get" action="https://www.google.com/search">'. |
---|
100 | '<p><input type="text" size="10" maxlength="255" '. |
---|
101 | 'name="q" />'. |
---|
102 | form::hidden(array('domains'),$url). |
---|
103 | form::hidden(array('sitesearch'),$url). |
---|
104 | ' <input class="submit" type="submit" value="ok" /></p>'. |
---|
105 | '</form>'; |
---|
106 | break; |
---|
107 | case 'yahoo' : |
---|
108 | $form = |
---|
109 | '<form method="get" action="http://search.yahoo.com/search">'. |
---|
110 | '<p><input type="text" size="10" maxlength="255" '. |
---|
111 | 'name="p" />'. |
---|
112 | form::hidden(array('vs'),$url). |
---|
113 | ' <input class="submit" type="submit" value="ok" /></p>'. |
---|
114 | '</form>'; |
---|
115 | break; |
---|
116 | |
---|
117 | default : |
---|
118 | throw new Exception(__('invalid search engine')); |
---|
119 | break; |
---|
120 | } |
---|
121 | |
---|
122 | $res = |
---|
123 | ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : ''). |
---|
124 | $form; |
---|
125 | |
---|
126 | return $w->renderDiv($w->content_only,'externalSearch '.$w->class,'',$res); |
---|
127 | } |
---|
128 | } |
---|