]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/clienterroraction.php
common_fake_local_fancy_url to remove index.php/ from a local URL
[quix0rs-gnu-social.git] / lib / clienterroraction.php
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
31 if (!defined('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Class for displaying HTTP client 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 ClientErrorAction extends ErrorAction
43 {
44     static $status = array(400 => 'Bad Request',
45                            401 => 'Unauthorized',
46                            402 => 'Payment Required',
47                            403 => 'Forbidden',
48                            404 => 'Not Found',
49                            405 => 'Method Not Allowed',
50                            406 => 'Not Acceptable',
51                            407 => 'Proxy Authentication Required',
52                            408 => 'Request Timeout',
53                            409 => 'Conflict',
54                            410 => 'Gone',
55                            411 => 'Length Required',
56                            412 => 'Precondition Failed',
57                            413 => 'Request Entity Too Large',
58                            414 => 'Request-URI Too Long',
59                            415 => 'Unsupported Media Type',
60                            416 => 'Requested Range Not Satisfiable',
61                            417 => 'Expectation Failed');
62
63     function __construct($message='Error', $code=400)
64     {
65         parent::__construct($message, $code);
66         $this->default = 400;
67
68         if (!$this->code || $this->code < 400 || $this->code > 499) {
69             $this->code = $this->default;
70         }
71         if (!$this->message) {
72             $this->message = "Client Error $this->code";
73         }
74     }
75
76     /**
77      *  To specify additional HTTP headers for the action
78      *
79      *  @return void
80      */
81     function extraHeaders()
82     {
83         $status_string = @self::$status[$this->code];
84         header('HTTP/1.1 '.$this->code.' '.$status_string);
85     }
86
87     /**
88      * Page title.
89      *
90      * @return page title
91      */
92
93     function title()
94     {
95         return @self::$status[$this->code];
96     }
97 }