]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/searchaction.php
isReadOnly() now takes arguments
[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  Laconica
9  * @author   Evan Prodromou <evan@controlyourself.ca>
10  * @author   Robin Millette <millette@controlyourself.ca>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://laconi.ca/
13  *
14  * Laconica - a distributed open-source microblogging tool
15  * Copyright (C) 2008, Controlez-Vous, 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('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  Laconica
42  * @author   Evan Prodromou <evan@controlyourself.ca>
43  * @author   Robin Millette <millette@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://laconi.ca/
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
74     function showLocalNav()
75     {
76         $nav = new SearchGroupNav($this, $this->trimmed('q'));
77         $nav->show();
78     }
79
80     function showTop($arr=null)
81     {
82         $error = null;
83         if ($arr) {
84             $error = $arr[1];
85         }
86         if (!empty($error)) {
87             $this->element('p', 'error', $error);
88         } else {
89             $instr = $this->getInstructions();
90             $output = common_markup_to_html($instr);
91             $this->elementStart('div', 'instructions');
92             $this->raw($output);
93             $this->elementEnd('div');
94         }
95     }
96
97     function title()
98     {
99         return null;
100     }
101
102     function showNoticeForm() {
103         // remote post notice form
104     }
105
106     function showContent() {
107         $this->showTop();
108         $this->showForm();
109     }
110
111     function showForm($error=null)
112     {
113         $q = $this->trimmed('q');
114         $page = $this->trimmed('page', 1);
115         $this->elementStart('form', array('method' => 'get',
116                                            'id' => 'form_search',
117                                            'class' => 'form_settings',
118                                            'action' => common_local_url($this->trimmed('action'))));
119         $this->elementStart('fieldset');
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         $this->input('q', 'Keyword(s)', $q);
127         $this->submit('search', 'Search');
128         $this->elementEnd('li');
129         $this->elementEnd('ul');
130         $this->elementEnd('fieldset');
131         $this->elementEnd('form');
132         if ($q) {
133             $this->showResults($q, $page);
134         }
135     }
136
137     function searchSuggestions($q) {
138         $qe = urlencode($q);
139         $message = sprintf(_(<<<E_O_T
140 * Make sure all words are spelled correctly.
141 * Try different keywords.
142 * Try more general keywords.
143 * Try fewer keywords.
144
145 You can also try your search on other engines:
146
147 * [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=identi.ca)
148 * [Tweet scan](http://www.tweetscan.com/indexi.php?s=%s)
149 * [Google](http://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s)
150 * [Yahoo](http://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s)
151
152
153 E_O_T
154 ), $qe, $qe, $qe, $qe);
155         $this->elementStart('dl', array('id' => 'help_search', 'class' => 'help'));
156         $this->element('dt', null, _('Search help'));
157         $this->elementStart('dd', 'instructions');
158         $this->raw(common_markup_to_html($message));
159         $this->elementEnd('dd');
160         $this->elementEnd('div');
161     }
162 }
163