gnu-social/lib/searchaction.php

150 lines
4.9 KiB
PHP
Raw Normal View History

<?php
2009-01-23 10:00:57 +09:00
/**
* Base search action class.
*
* PHP version 5
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
2009-01-23 10:00:57 +09:00
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
2009-08-26 07:16:46 +09:00
* @link http://status.net/
2009-01-23 10:00:57 +09:00
*
2009-08-26 07:14:12 +09:00
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* 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/>.
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
2009-01-23 10:00:57 +09:00
exit(1);
}
require_once INSTALLDIR.'/lib/searchgroupnav.php';
2009-01-23 10:00:57 +09:00
/**
* Base search action class.
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
2009-01-23 10:00:57 +09:00
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
2009-08-26 07:16:46 +09:00
* @link http://status.net/
2009-01-23 10:00:57 +09:00
*/
class SearchAction extends Action
{
2009-01-23 10:00:57 +09:00
/**
* Return true if read only.
*
* @return boolean true
*/
function isReadOnly($args)
{
return true;
}
function handle($args)
{
parent::handle($args);
2009-01-23 10:00:57 +09:00
$this->showPage();
}
2009-01-23 10:00:57 +09:00
function showTop($arr=null)
{
2009-02-21 06:51:39 +09:00
$error = null;
if ($arr) {
$error = $arr[1];
}
2009-02-21 06:51:39 +09:00
if (!empty($error)) {
2009-01-23 10:00:57 +09:00
$this->element('p', 'error', $error);
} else {
2009-01-23 10:00:57 +09:00
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
2009-01-23 10:00:57 +09:00
$this->elementStart('div', 'instructions');
$this->raw($output);
$this->elementEnd('div');
}
}
2009-01-23 10:00:57 +09:00
function title()
{
return null;
}
2009-01-23 10:00:57 +09:00
function showContent() {
$this->showTop();
$this->showForm();
}
function showForm($error=null)
{
$q = $this->trimmed('q');
$page = $this->trimmed('page', 1);
2009-01-23 10:00:57 +09:00
$this->elementStart('form', array('method' => 'get',
2009-01-24 09:58:12 +09:00
'id' => 'form_search',
'class' => 'form_settings',
'action' => common_local_url($this->trimmed('action'))));
2009-01-24 09:58:12 +09:00
$this->elementStart('fieldset');
// TRANS: Fieldset legend for the search form.
2009-01-24 09:58:12 +09:00
$this->element('legend', null, _('Search site'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
if (!common_config('site', 'fancy')) {
2009-01-23 10:00:57 +09:00
$this->hidden('action', $this->trimmed('action'));
}
// TRANS: Used as a field label for the field where one or more keywords
// TRANS: for searching can be entered.
2009-11-21 23:59:54 +09:00
$this->input('q', _('Keyword(s)'), $q);
// TRANS: Button text for searching site.
$this->element('input', array('type'=>'submit', 'class'=>'submit', 'value'=>_m('BUTTON','Search')));
2009-01-24 09:58:12 +09:00
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementEnd('fieldset');
2009-01-23 10:00:57 +09:00
$this->elementEnd('form');
if ($q) {
2009-01-23 10:00:57 +09:00
$this->showResults($q, $page);
}
}
function searchSuggestions($q) {
// 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.
* Try different keywords.
* Try more general keywords.
* Try fewer keywords.");
$message .= "\n";
if (!common_config('site', 'private')) {
$qe = urlencode($q);
$message .= "\n";
// 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 .= sprintf(_("You can also try your search on other engines:
* [DuckDuckGo](https://duckduckgo.com/?q=site%%3A%%%%site.server%%%%+%s)
* [Ixquick](https://ixquick.com/do/search?query=site%%3A%%%%site.server%%%%+%s)
* [Google](https://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s)
* [Yahoo!](https://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s)
"), $qe, $qe, $qe, $qe);
$message .= "\n";
}
2011-01-15 05:36:06 +09:00
$this->elementStart('div', 'help instructions');
$this->raw(common_markup_to_html($message));
2011-01-15 05:36:06 +09:00
$this->elementEnd('div');
}
}