git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

searchaction.php 4.88 KB
Newer Older
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7
/**
 * Base search action class.
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
11
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
13
 *
14
 * StatusNet - the distributed open-source microblogging tool
15
 * Copyright (C) 2008, 2009, StatusNet, Inc.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
Robin Millette's avatar
Robin Millette committed
32 33 34 35
    exit(1);
}

require_once INSTALLDIR.'/lib/searchgroupnav.php';
36

Robin Millette's avatar
Robin Millette committed
37 38 39 40
/**
 * Base search action class.
 *
 * @category Action
41
 * @package  StatusNet
42 43
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
44
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
46
 */
47 48
class SearchAction extends Action
{
Robin Millette's avatar
Robin Millette committed
49 50 51 52 53
    /**
     * Return true if read only.
     *
     * @return boolean true
     */
54
    function isReadOnly($args)
55
    {
56 57
        return true;
    }
58

59 60
    function handle($args)
    {
61
        parent::handle($args);
Robin Millette's avatar
Robin Millette committed
62
        $this->showPage();
63
    }
64

Robin Millette's avatar
Robin Millette committed
65
    function showTop($arr=null)
66
    {
67
        $error = null;
68 69 70
        if ($arr) {
            $error = $arr[1];
        }
71
        if (!empty($error)) {
Robin Millette's avatar
Robin Millette committed
72
            $this->element('p', 'error', $error);
73
        } else {
Robin Millette's avatar
Robin Millette committed
74
            $instr = $this->getInstructions();
75
            $output = common_markup_to_html($instr);
Robin Millette's avatar
Robin Millette committed
76 77 78
            $this->elementStart('div', 'instructions');
            $this->raw($output);
            $this->elementEnd('div');
79 80
        }
    }
81

Robin Millette's avatar
Robin Millette committed
82
    function title()
83
    {
Evan Prodromou's avatar
Evan Prodromou committed
84
        return null;
85
    }
86

Robin Millette's avatar
Robin Millette committed
87 88 89 90 91 92
    function showContent() {
        $this->showTop();
        $this->showForm();
    }

    function showForm($error=null)
93
    {
94 95
        $q = $this->trimmed('q');
        $page = $this->trimmed('page', 1);
Robin Millette's avatar
Robin Millette committed
96
        $this->elementStart('form', array('method' => 'get',
sarven's avatar
sarven committed
97 98
                                           'id' => 'form_search',
                                           'class' => 'form_settings',
99
                                           'action' => common_local_url($this->trimmed('action'))));
sarven's avatar
sarven committed
100
        $this->elementStart('fieldset');
101
        // TRANS: Fieldset legend for the search form.
sarven's avatar
sarven committed
102 103 104
        $this->element('legend', null, _('Search site'));
        $this->elementStart('ul', 'form_data');
        $this->elementStart('li');
105
        if (!common_config('site', 'fancy')) {
Robin Millette's avatar
Robin Millette committed
106
            $this->hidden('action', $this->trimmed('action'));
107
        }
108 109
        // TRANS: Used as a field label for the field where one or more keywords
        // 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')));
sarven's avatar
sarven committed
113 114 115
        $this->elementEnd('li');
        $this->elementEnd('ul');
        $this->elementEnd('fieldset');
Robin Millette's avatar
Robin Millette committed
116
        $this->elementEnd('form');
117
        if ($q) {
Robin Millette's avatar
Robin Millette committed
118
            $this->showResults($q, $page);
119 120
        }
    }
121 122

    function searchSuggestions($q) {
123 124 125
        // Don't change these long strings to HEREDOC; xgettext won't pick them up.
        // TRANS: Standard search suggestions shown when a search does not give any results.
        $message = _("* Make sure all words are spelled correctly.
126 127
* Try different keywords.
* Try more general keywords.
128 129 130
* Try fewer keywords.");
            $message .= "\n";

131 132
        if (!common_config('site', 'private')) {
            $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)
Bob Mottram's avatar
Bob Mottram committed
140
* [Searx](https://searx.laquadrature.net/?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
}