]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/error.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[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 require_once INSTALLDIR . '/lib/info.php';
37
38 /**
39  * Base class for displaying HTTP errors
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Zach Copley <zach@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://status.net/
46  */
47 class ErrorAction extends InfoAction
48 {
49     static $status = array();
50
51     var $code    = null;
52     var $message = null;
53     var $default = null;
54
55     function __construct($message, $code, $output='php://output', $indent=null)
56     {
57         parent::__construct(null, $message, $output, $indent);
58
59         $this->code = $code;
60         $this->message = $message;
61         $this->minimal = StatusNet::isApi();
62
63         // XXX: hack alert: usually we aren't going to
64         // call this page directly, but because it's
65         // an action it needs an args array anyway
66         $this->prepare($_REQUEST);
67     }
68
69     function showPage()
70     {
71         if (StatusNet::isAjax()) {
72             $this->extraHeaders();
73             $this->ajaxErrorMsg();
74             exit();
75         } if ($this->minimal) {
76             // Even more minimal -- we're in a machine API
77             // and don't want to flood the output.
78             $this->extraHeaders();
79             $this->showContent();
80         } else {
81             parent::showPage();
82         }
83
84         // We don't want to have any more output after this
85         exit();
86     }
87
88     /**
89      * Display content.
90      *
91      * @return nothing
92      */
93     function showContent()
94     {
95         $this->element('div', array('class' => 'error'), $this->message);
96     }
97
98     function showNoticeForm()
99     {
100     }
101
102     /**
103      * Show an Ajax-y error message
104      *
105      * Goes back to the browser, where it's shown in a popup.
106      *
107      * @param string $msg Message to show
108      *
109      * @return void
110      */
111
112     function ajaxErrorMsg()
113     {
114         $this->startHTML('text/xml;charset=utf-8', true);
115         $this->elementStart('head');
116         // TRANS: Page title after an AJAX error occurs on the send notice page.
117         $this->element('title', null, _('Ajax Error'));
118         $this->elementEnd('head');
119         $this->elementStart('body');
120         $this->element('p', array('id' => 'error'), $this->message);
121         $this->elementEnd('body');
122         $this->elementEnd('html');
123     }
124 }