]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/searchaction.php
Merge branch '0.9.x' into twitstream
[quix0rs-gnu-social.git] / lib / searchaction.php
1 <?php
2 /**
3  * Base search action class.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/searchgroupnav.php';
36
37 /**
38  * Base search action class.
39  *
40  * @category Action
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Robin Millette <millette@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://status.net/
46  */
47 class SearchAction extends Action
48 {
49     /**
50      * Return true if read only.
51      *
52      * @return boolean true
53      */
54     function isReadOnly($args)
55     {
56         return true;
57     }
58
59     function handle($args)
60     {
61         parent::handle($args);
62         $this->showPage();
63     }
64
65     /**
66      * Show tabset for this page
67      *
68      * Uses the SearchGroupNav widget
69      *
70      * @return void
71      * @see SearchGroupNav
72      */
73     function showLocalNav()
74     {
75         $nav = new SearchGroupNav($this, $this->trimmed('q'));
76         $nav->show();
77     }
78
79     function showTop($arr=null)
80     {
81         $error = null;
82         if ($arr) {
83             $error = $arr[1];
84         }
85         if (!empty($error)) {
86             $this->element('p', 'error', $error);
87         } else {
88             $instr = $this->getInstructions();
89             $output = common_markup_to_html($instr);
90             $this->elementStart('div', 'instructions');
91             $this->raw($output);
92             $this->elementEnd('div');
93         }
94     }
95
96     function title()
97     {
98         return null;
99     }
100
101     function showNoticeForm() {
102         // remote post notice form
103     }
104
105     function showContent() {
106         $this->showTop();
107         $this->showForm();
108     }
109
110     function showForm($error=null)
111     {
112         $q = $this->trimmed('q');
113         $page = $this->trimmed('page', 1);
114         $this->elementStart('form', array('method' => 'get',
115                                            'id' => 'form_search',
116                                            'class' => 'form_settings',
117                                            'action' => common_local_url($this->trimmed('action'))));
118         $this->elementStart('fieldset');
119         // TRANS: Fieldset legend for the search form.
120         $this->element('legend', null, _('Search site'));
121         $this->elementStart('ul', 'form_data');
122         $this->elementStart('li');
123         if (!common_config('site', 'fancy')) {
124             $this->hidden('action', $this->trimmed('action'));
125         }
126         // TRANS: Used as a field label for the field where one or more keywords
127         // TRANS: for searching can be entered.
128         $this->input('q', _('Keyword(s)'), $q);
129         // TRANS: Button text for searching site.
130         $this->submit('search', _m('BUTTON','Search'));
131         $this->elementEnd('li');
132         $this->elementEnd('ul');
133         $this->elementEnd('fieldset');
134         $this->elementEnd('form');
135         if ($q) {
136             $this->showResults($q, $page);
137         }
138     }
139
140     function searchSuggestions($q) {
141         // @todo FIXME: i18n issue: This formatting does not make this string get picked up by gettext.
142             // TRANS: Standard search suggestions shown when a search does not give any results.
143         $message = _(<<<E_O_T
144 * Make sure all words are spelled correctly.
145 * Try different keywords.
146 * Try more general keywords.
147 * Try fewer keywords.
148
149 E_O_T
150 );
151         if (!common_config('site', 'private')) {
152             $qe = urlencode($q);
153             // @todo FIXME: i18n issue: This formatting does not make this string get picked up by gettext.
154             // TRANS: Standard search suggestions shown when a search does not give any results.
155             $message .= sprintf(_(<<<E_O_T
156
157 You can also try your search on other engines:
158
159 * [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=%%%%site.server%%%%)
160 * [Tweet scan](http://www.tweetscan.com/indexi.php?s=%s)
161 * [Google](http://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s)
162 * [Yahoo](http://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s)
163 * [Collecta](http://collecta.com/#q=%s)
164
165 E_O_T
166 ), $qe, $qe, $qe, $qe, $qe);
167         }
168         $this->elementStart('dl', array('id' => 'help_search', 'class' => 'help'));
169         // TRANS: Definition list item with instructions on how to get (better) search results.
170         $this->element('dt', null, _('Search help'));
171         $this->elementStart('dd', 'instructions');
172         $this->raw(common_markup_to_html($message));
173         $this->elementEnd('dd');
174         $this->elementEnd('div');
175     }
176 }