]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/clienterroraction.php
change Controlez-Vous to Control Yourself
[quix0rs-gnu-social.git] / lib / clienterroraction.php
1 <?php
2
3 /**
4  * Client error action.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  Laconica
10  * @author   Evan Prodromou <evan@controlyourself.ca>
11  * @author   Zach Copley <zach@controlyourself.ca>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://laconi.ca/
14  *
15  * Laconica - a distributed open-source microblogging tool
16  * Copyright (C) 2008, Control Yourself, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('LACONICA')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/error.php';
37
38 /**
39  * Class for displaying HTTP client errors
40  *
41  * @category Action
42  * @package  Laconica
43  * @author   Zach Copley <zach@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://laconi.ca/
46  */
47 class ClientErrorAction extends ErrorAction
48 {
49     function __construct($message='Error', $code=400)
50     {
51         parent::__construct($message, $code);
52
53         $this->status  = array(400 => 'Bad Request',
54                                401 => 'Unauthorized',
55                                402 => 'Payment Required',
56                                403 => 'Forbidden',
57                                404 => 'Not Found',
58                                405 => 'Method Not Allowed',
59                                406 => 'Not Acceptable',
60                                407 => 'Proxy Authentication Required',
61                                408 => 'Request Timeout',
62                                409 => 'Conflict',
63                                410 => 'Gone',
64                                411 => 'Length Required',
65                                412 => 'Precondition Failed',
66                                413 => 'Request Entity Too Large',
67                                414 => 'Request-URI Too Long',
68                                415 => 'Unsupported Media Type',
69                                416 => 'Requested Range Not Satisfiable',
70                                417 => 'Expectation Failed');
71         $this->default = 400;
72     }
73
74     // XXX: Should these error actions even be invokable via URI?
75
76     function handle($args)
77     {
78         parent::handle($args);
79
80         $this->code = $this->trimmed('code');
81
82         if (!$this->code || $code < 400 || $code > 499) {
83             $this->code = $this->default;
84         }
85
86         $this->message = $this->trimmed('message');
87
88         if (!$this->message) {
89             $this->message = "Client Error $this->code";
90         }
91
92         $this->showPage();
93     }
94
95     function title()
96     {
97         return $this->status[$this->code];
98     }
99 }