searchaction.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR . '/lib/search/searchgroupnav.php';
  34. /**
  35. * Base search action class.
  36. *
  37. * @category Action
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @author Robin Millette <millette@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  42. * @link http://status.net/
  43. */
  44. class SearchAction extends Action
  45. {
  46. public $widgetOpts;
  47. public $scoped;
  48. /**
  49. * Return true if read only.
  50. *
  51. * @return boolean true
  52. */
  53. function isReadOnly($args)
  54. {
  55. return true;
  56. }
  57. function handle()
  58. {
  59. parent::handle();
  60. $this->showPage();
  61. }
  62. function showTop($arr=null)
  63. {
  64. $error = null;
  65. if ($arr) {
  66. $error = $arr[1];
  67. }
  68. if (!empty($error)) {
  69. $this->element('p', 'error', $error);
  70. } else {
  71. $instr = $this->getInstructions();
  72. $output = common_markup_to_html($instr);
  73. $this->elementStart('div', 'instructions');
  74. $this->raw($output);
  75. $this->elementEnd('div');
  76. }
  77. }
  78. function title()
  79. {
  80. return null;
  81. }
  82. function showContent() {
  83. $this->showTop();
  84. $this->showForm();
  85. }
  86. function showForm($error=null)
  87. {
  88. $q = $this->trimmed('q');
  89. $page = $this->trimmed('page', 1);
  90. $this->elementStart('form', array('method' => 'get',
  91. 'id' => 'form_search',
  92. 'class' => 'form_settings',
  93. 'action' => common_local_url($this->trimmed('action'))));
  94. $this->elementStart('fieldset');
  95. // TRANS: Fieldset legend for the search form.
  96. $this->element('legend', null, _('Search site'));
  97. $this->elementStart('ul', 'form_data');
  98. $this->elementStart('li');
  99. if (!common_config('site', 'fancy')) {
  100. $this->hidden('action', $this->trimmed('action'));
  101. }
  102. // TRANS: Used as a field label for the field where one or more keywords
  103. // TRANS: for searching can be entered.
  104. $this->input('q', _('Keyword(s)'), $q);
  105. // TRANS: Button text for searching site.
  106. $this->element('input', array('type'=>'submit', 'class'=>'submit', 'value'=>_m('BUTTON','Search')));
  107. $this->elementEnd('li');
  108. $this->elementEnd('ul');
  109. $this->elementEnd('fieldset');
  110. $this->elementEnd('form');
  111. if ($q) {
  112. $this->showResults($q, $page);
  113. }
  114. }
  115. function searchSuggestions($q) {
  116. // Don't change these long strings to HEREDOC; xgettext won't pick them up.
  117. // TRANS: Standard search suggestions shown when a search does not give any results.
  118. $message = _("* Make sure all words are spelled correctly.
  119. * Try different keywords.
  120. * Try more general keywords.
  121. * Try fewer keywords.");
  122. $message .= "\n";
  123. if (!common_config('site', 'private')) {
  124. $qe = urlencode($q);
  125. $message .= "\n";
  126. // Don't change these long strings to HEREDOC; xgettext won't pick them up.
  127. // TRANS: Standard search suggestions shown when a search does not give any results.
  128. $message .= sprintf(_("You can also try your search on other engines:
  129. * [DuckDuckGo](https://duckduckgo.com/?q=site%%3A%%%%site.server%%%%+%s)
  130. * [Ixquick](https://ixquick.com/do/search?query=site%%3A%%%%site.server%%%%+%s)
  131. * [Searx](https://searx.laquadrature.net/?q=site%%3A%%%%site.server%%%%+%s)
  132. * [Yahoo!](https://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s)
  133. "), $qe, $qe, $qe, $qe);
  134. $message .= "\n";
  135. }
  136. $this->elementStart('div', 'help instructions');
  137. $this->raw(common_markup_to_html($message));
  138. $this->elementEnd('div');
  139. }
  140. }