]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/servererroraction.php
change Controlez-Vous to Control Yourself
[quix0rs-gnu-social.git] / lib / servererroraction.php
1 <?php
2
3 /**
4  * Server 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 server errors
40  *
41  * Note: The older util.php class simply printed a string, but the spec
42  * says that 500 errors should be treated similarly to 400 errors, and
43  * it's easier to give an HTML response.  Maybe we can customize these
44  * to display some funny animal cartoons.  If not, we can probably role
45  * these classes up into a single class.
46  *
47  * See: http://tools.ietf.org/html/rfc2616#section-10
48  *
49  * @category Action
50  * @package  Laconica
51  * @author   Zach Copley <zach@controlyourself.ca>
52  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
53  * @link     http://laconi.ca/
54  */
55 class ServerErrorAction extends ErrorAction
56 {
57     function __construct($message='Error', $code=500)
58     {
59         parent::__construct($message, $code);
60
61         $this->status  = array(500 => 'Internal Server Error',
62                                501 => 'Not Implemented',
63                                502 => 'Bad Gateway',
64                                503 => 'Service Unavailable',
65                                504 => 'Gateway Timeout',
66                                505 => 'HTTP Version Not Supported');
67
68         $this->default = 500;
69     }
70
71     // XXX: Should these error actions even be invokable via URI?
72
73     function handle($args)
74     {
75         parent::handle($args);
76
77         $this->code = $this->trimmed('code');
78
79         if (!$this->code || $code < 500 || $code > 599) {
80             $this->code = $this->default;
81         }
82
83         $this->message = $this->trimmed('message');
84
85         if (!$this->message) {
86             $this->message = "Server Error $this->code";
87         }
88
89         $this->showPage();
90     }
91
92     function title()
93     {
94         return $this->status[$this->code];
95     }
96 }