searchaction.php 4.9 KB

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