clienterroraction.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Client 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-2010 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/error.php';
  34. /**
  35. * Class for displaying HTTP client errors
  36. *
  37. * @category Action
  38. * @package StatusNet
  39. * @author Zach Copley <zach@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  41. * @link http://status.net/
  42. */
  43. class ClientErrorAction extends ErrorAction
  44. {
  45. static $status = array(400 => 'Bad Request',
  46. 401 => 'Unauthorized',
  47. 402 => 'Payment Required',
  48. 403 => 'Forbidden',
  49. 404 => 'Not Found',
  50. 405 => 'Method Not Allowed',
  51. 406 => 'Not Acceptable',
  52. 407 => 'Proxy Authentication Required',
  53. 408 => 'Request Timeout',
  54. 409 => 'Conflict',
  55. 410 => 'Gone',
  56. 411 => 'Length Required',
  57. 412 => 'Precondition Failed',
  58. 413 => 'Request Entity Too Large',
  59. 414 => 'Request-URI Too Long',
  60. 415 => 'Unsupported Media Type',
  61. 416 => 'Requested Range Not Satisfiable',
  62. 417 => 'Expectation Failed');
  63. function __construct($message='Error', $code=400)
  64. {
  65. parent::__construct($message, $code);
  66. $this->default = 400;
  67. }
  68. // XXX: Should these error actions even be invokable via URI?
  69. function handle($args)
  70. {
  71. parent::handle($args);
  72. $this->code = $this->trimmed('code');
  73. if (!$this->code || $code < 400 || $code > 499) {
  74. $this->code = $this->default;
  75. }
  76. $this->message = $this->trimmed('message');
  77. if (!$this->message) {
  78. $this->message = "Client Error $this->code";
  79. }
  80. $this->showPage();
  81. }
  82. /**
  83. * To specify additional HTTP headers for the action
  84. *
  85. * @return void
  86. */
  87. function extraHeaders()
  88. {
  89. $status_string = @self::$status[$this->code];
  90. header('HTTP/1.1 '.$this->code.' '.$status_string);
  91. }
  92. /**
  93. * Page title.
  94. *
  95. * @return page title
  96. */
  97. function title()
  98. {
  99. return @self::$status[$this->code];
  100. }
  101. }