opensearch.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Opensearch 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. /**
  34. * Opensearch action class.
  35. *
  36. * Formatting of RSS handled by Rss10Action
  37. *
  38. * @category Action
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @author Robin Millette <millette@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  43. * @link http://status.net/
  44. */
  45. class OpensearchAction extends Action
  46. {
  47. /**
  48. * Class handler.
  49. *
  50. * @param array $args query arguments
  51. *
  52. * @return boolean false if user doesn't exist
  53. */
  54. function handle($args)
  55. {
  56. parent::handle($args);
  57. $type = $this->trimmed('type');
  58. $short_name = '';
  59. if ($type == 'people') {
  60. $type = 'peoplesearch';
  61. // TRANS: ShortName in the OpenSearch interface when trying to find users.
  62. $short_name = _('People Search');
  63. } else {
  64. $type = 'noticesearch';
  65. // TRANS: ShortName in the OpenSearch interface when trying to find notices.
  66. $short_name = _('Notice Search');
  67. }
  68. header('Content-Type: application/opensearchdescription+xml');
  69. $this->startXML();
  70. $this->elementStart('OpenSearchDescription', array('xmlns' => 'http://a9.com/-/spec/opensearch/1.1/'));
  71. $short_name = common_config('site', 'name').' '.$short_name;
  72. $this->element('ShortName', null, $short_name);
  73. $this->element('Contact', null, common_config('site', 'email'));
  74. $this->element('Url', array('type' => 'text/html', 'method' => 'get',
  75. 'template' => str_replace('---', '{searchTerms}', common_local_url($type, array('q' => '---')))));
  76. $this->element('Image', array('height' => 16, 'width' => 16, 'type' => 'image/vnd.microsoft.icon'), common_path('favicon.ico'));
  77. $this->element('Image', array('height' => 50, 'width' => 50, 'type' => 'image/png'), Theme::path('logo.png'));
  78. $this->element('AdultContent', null, 'false');
  79. $this->element('Language', null, common_language());
  80. $this->element('OutputEncoding', null, 'UTF-8');
  81. $this->element('InputEncoding', null, 'UTF-8');
  82. $this->elementEnd('OpenSearchDescription');
  83. $this->endXML();
  84. }
  85. function isReadOnly($args)
  86. {
  87. return true;
  88. }
  89. }