]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/searchaction.php
XSS vulnerability when remote-subscribing
[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     function showTop($arr=null)
66     {
67         $error = null;
68         if ($arr) {
69             $error = $arr[1];
70         }
71         if (!empty($error)) {
72             $this->element('p', 'error', $error);
73         } else {
74             $instr = $this->getInstructions();
75             $output = common_markup_to_html($instr);
76             $this->elementStart('div', 'instructions');
77             $this->raw($output);
78             $this->elementEnd('div');
79         }
80     }
81
82     function title()
83     {
84         return null;
85     }
86
87     function showContent() {
88         $this->showTop();
89         $this->showForm();
90     }
91
92     function showForm($error=null)
93     {
94         $q = $this->trimmed('q');
95         $page = $this->trimmed('page', 1);
96         $this->elementStart('form', array('method' => 'get',
97                                            'id' => 'form_search',
98                                            'class' => 'form_settings',
99                                            'action' => common_local_url($this->trimmed('action'))));
100         $this->elementStart('fieldset');
101         // TRANS: Fieldset legend for the search form.
102         $this->element('legend', null, _('Search site'));
103         $this->elementStart('ul', 'form_data');
104         $this->elementStart('li');
105         if (!common_config('site', 'fancy')) {
106             $this->hidden('action', $this->trimmed('action'));
107         }
108         // TRANS: Used as a field label for the field where one or more keywords
109         // TRANS: for searching can be entered.
110         $this->input('q', _('Keyword(s)'), $q);
111         // TRANS: Button text for searching site.
112         $this->element('input', array('type'=>'submit', 'class'=>'submit', 'value'=>_m('BUTTON','Search')));
113         $this->elementEnd('li');
114         $this->elementEnd('ul');
115         $this->elementEnd('fieldset');
116         $this->elementEnd('form');
117         if ($q) {
118             $this->showResults($q, $page);
119         }
120     }
121
122     function searchSuggestions($q) {
123         // Don't change these long strings to HEREDOC; xgettext won't pick them up.
124         // TRANS: Standard search suggestions shown when a search does not give any results.
125         $message = _("* Make sure all words are spelled correctly.
126 * Try different keywords.
127 * Try more general keywords.
128 * Try fewer keywords.");
129             $message .= "\n";
130
131         if (!common_config('site', 'private')) {
132             $qe = urlencode($q);
133             $message .= "\n";
134             // Don't change these long strings to HEREDOC; xgettext won't pick them up.
135             // TRANS: Standard search suggestions shown when a search does not give any results.
136             $message .= sprintf(_("You can also try your search on other engines:
137
138 * [DuckDuckGo](https://duckduckgo.com/?q=site%%3A%%%%site.server%%%%+%s)
139 * [Ixquick](https://ixquick.com/do/search?query=site%%3A%%%%site.server%%%%+%s)
140 * [Google](https://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s)
141 * [Yahoo!](https://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s)
142 "), $qe, $qe, $qe, $qe);
143             $message .= "\n";
144         }
145         $this->elementStart('div', 'help instructions');
146         $this->raw(common_markup_to_html($message));
147         $this->elementEnd('div');
148     }
149 }