]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/error.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / lib / error.php
1 <?php
2
3 /**
4  * Error action.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @author   Zach Copley <zach@status.net>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://status.net/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET') && !defined('LACONICA')) {
33     exit(1);
34 }
35
36 /**
37  * Base class for displaying HTTP errors
38  *
39  * @category Action
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  */
45 class ErrorAction extends Action
46 {
47     static $status = array();
48
49     var $code    = null;
50     var $message = null;
51     var $default = null;
52
53     function __construct($message, $code, $output='php://output', $indent=null)
54     {
55         parent::__construct($output, $indent);
56
57         $this->code = $code;
58         $this->message = $message;
59         $this->minimal = StatusNet::isApi();
60
61         // XXX: hack alert: usually we aren't going to
62         // call this page directly, but because it's
63         // an action it needs an args array anyway
64         $this->prepare($_REQUEST);
65     }
66
67     /**
68      *  To specify additional HTTP headers for the action
69      *
70      *  @return void
71      */
72     function extraHeaders()
73     {
74         $status_string = @self::$status[$this->code];
75         header('HTTP/1.1 '.$this->code.' '.$status_string);
76     }
77
78     /**
79      * Display content.
80      *
81      * @return nothing
82      */
83     function showContent()
84     {
85         $this->element('div', array('class' => 'error'), $this->message);
86     }
87
88     /**
89      * Page title.
90      *
91      * @return page title
92      */
93
94     function title()
95     {
96         return @self::$status[$this->code];
97     }
98
99     function isReadOnly($args)
100     {
101         return true;
102     }
103
104     function showPage()
105     {
106         if ($this->minimal) {
107             // Even more minimal -- we're in a machine API
108             // and don't want to flood the output.
109             $this->extraHeaders();
110             $this->showContent();
111         } else {
112             parent::showPage();
113         }
114
115         // We don't want to have any more output after this
116         exit();
117     }
118
119     // Overload a bunch of stuff so the page isn't too bloated
120
121     function showBody()
122     {
123         $this->elementStart('body', array('id' => 'error'));
124         $this->elementStart('div', array('id' => 'wrap'));
125         $this->showHeader();
126         $this->showCore();
127         $this->showFooter();
128         $this->elementEnd('div');
129         $this->elementEnd('body');
130     }
131
132     function showCore()
133     {
134         $this->elementStart('div', array('id' => 'core'));
135         $this->showContentBlock();
136         $this->elementEnd('div');
137     }
138
139     function showHeader()
140     {
141         $this->elementStart('div', array('id' => 'header'));
142         $this->showLogo();
143         $this->showPrimaryNav();
144         $this->elementEnd('div');
145     }
146
147 }