erroraction.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Error action.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @author Zach Copley <zach@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. * Base class for displaying HTTP errors
  35. *
  36. * @category Action
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  40. * @link http://status.net/
  41. */
  42. class ErrorAction extends InfoAction
  43. {
  44. static $status = [];
  45. var $code = null;
  46. var $message = null;
  47. var $default = null;
  48. function __construct($message, $code, $output='php://output', $indent=null)
  49. {
  50. parent::__construct(null, $message, $output, $indent);
  51. $this->code = $code;
  52. $this->message = $message;
  53. $this->minimal = GNUsocial::isApi();
  54. // XXX: hack alert: usually we aren't going to
  55. // call this page directly, but because it's
  56. // an action it needs an args array anyway
  57. $this->prepare($_REQUEST);
  58. }
  59. function showPage()
  60. {
  61. if (GNUsocial::isAjax()) {
  62. $this->extraHeaders();
  63. $this->ajaxErrorMsg();
  64. exit();
  65. } if ($this->minimal) {
  66. // Even more minimal -- we're in a machine API
  67. // and don't want to flood the output.
  68. $this->extraHeaders();
  69. $this->showContent();
  70. } else {
  71. parent::showPage();
  72. }
  73. // We don't want to have any more output after this
  74. exit();
  75. }
  76. /**
  77. * Display content.
  78. *
  79. * @return void
  80. */
  81. function showContent()
  82. {
  83. $this->element('div', ['class' => 'error'], $this->message);
  84. }
  85. function showNoticeForm()
  86. {
  87. }
  88. /**
  89. * Show an Ajax-y error message
  90. *
  91. * Goes back to the browser, where it's shown in a popup.
  92. *
  93. * @return void
  94. * @throws ClientException
  95. */
  96. function ajaxErrorMsg()
  97. {
  98. $this->startHTML('text/xml;charset=utf-8');
  99. $this->elementStart('head');
  100. // TRANS: Page title after an AJAX error occurs on the send notice page.
  101. $this->element('title', null, _('Ajax Error'));
  102. $this->elementEnd('head');
  103. $this->elementStart('body');
  104. $this->element('p', ['id' => 'error'], $this->message);
  105. $this->elementEnd('body');
  106. $this->endHTML();
  107. }
  108. }