Skip to content

Commit ae3a8a0

Browse files
author
vogelor
committed
Improved app errorhandling
1 parent f3dab79 commit ae3a8a0

File tree

2 files changed

+40
-56
lines changed

2 files changed

+40
-56
lines changed

interface/lib/app.inc.php

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,39 @@ class app {
4141
private $_loaded_classes = array();
4242
private $_conf;
4343

44-
public function __construct()
45-
{
44+
public function __construct() {
4645
global $conf;
47-
46+
4847
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']) || isset($_REQUEST['s']) || isset($_REQUEST['s_old']) || isset($_REQUEST['conf'])) {
4948
die('Internal Error: var override attempt detected');
5049
}
51-
50+
5251
$this->_conf = $conf;
5352
if($this->_conf['start_db'] == true) {
5453
$this->load('db_'.$this->_conf['db_type']);
5554
$this->db = new db;
5655
}
57-
56+
5857
//* Start the session
5958
if($this->_conf['start_session'] == true) {
6059
session_start();
61-
60+
6261
//* Initialize session variables
6362
if(!isset($_SESSION['s']['id']) ) $_SESSION['s']['id'] = session_id();
6463
if(empty($_SESSION['s']['theme'])) $_SESSION['s']['theme'] = $conf['theme'];
6564
if(empty($_SESSION['s']['language'])) $_SESSION['s']['language'] = $conf['language'];
6665
}
67-
66+
6867
$this->uses('auth,plugin');
6968
}
7069

71-
public function uses($classes)
72-
{
73-
$cl = explode(',', $classes);
70+
public function uses($classes) {
71+
$cl = explode(',', $classes);
7472
if(is_array($cl)) {
75-
foreach($cl as $classname){
73+
foreach($cl as $classname) {
7674
$classname = trim($classname);
77-
//* Class is not loaded so load it
78-
if(!array_key_exists($classname, $this->_loaded_classes)){
75+
//* Class is not loaded so load it
76+
if(!array_key_exists($classname, $this->_loaded_classes)) {
7977
include_once(ISPC_CLASS_PATH."/$classname.inc.php");
8078
$this->$classname = new $classname();
8179
$this->_loaded_classes[$classname] = true;
@@ -84,20 +82,18 @@ public function uses($classes)
8482
}
8583
}
8684

87-
public function load($files)
88-
{
85+
public function load($files) {
8986
$fl = explode(',', $files);
9087
if(is_array($fl)) {
91-
foreach($fl as $file){
88+
foreach($fl as $file) {
9289
$file = trim($file);
9390
include_once(ISPC_CLASS_PATH."/$file.inc.php");
9491
}
9592
}
9693
}
9794

9895
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
99-
public function log($msg, $priority = 0)
100-
{
96+
public function log($msg, $priority = 0) {
10197
global $conf;
10298
if($priority >= $this->_conf['log_priority']) {
10399
// $server_id = $conf["server_id"];
@@ -119,46 +115,27 @@ public function log($msg, $priority = 0)
119115
$this->error('Unable to write to logfile.');
120116
}
121117
*/
122-
}
123-
}
118+
}
119+
}
124120

125-
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
126-
public function error($msg, $next_link = '', $stop = true, $priority = 1)
127-
{
121+
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
122+
public function error($msg, $next_link = '', $stop = true, $priority = 1) {
128123
//$this->uses("error");
129124
//$this->error->message($msg, $priority);
130-
if($stop == true){
131-
$msg = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
132-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
133-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
134-
<head>
135-
<title>Error</title>
136-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
137-
<link href="../themes/default/css/central.css" rel="stylesheet" type="text/css" />
138-
</head>
139-
<body>
140-
<div class="uniForm">
141-
<div id="errorMsg">
142-
<h3>Error</h3>
143-
<ol>
144-
<li>'.$msg;
125+
if($stop == true) {
126+
$content = file_get_contents(dirname(__FILE__) .
127+
'/../web/themes/' . $_SESSION['s']['theme'] . '/templates/error.tpl.htm');
145128
if($next_link != '') $msg .= '<a href="'.$next_link.'">Next</a>';
146-
$msg .= '</li>
147-
</ol>
148-
</div>
149-
</div>
150-
</body>
151-
</html>';
152-
die($msg);
129+
$content = str_replace('###ERRORMSG###', $msg, $content);
130+
die($content);
153131
} else {
154132
echo $msg;
155133
if($next_link != '') echo "<a href='$next_link'>Next</a>";
156134
}
157135
}
158136

159-
/** Translates strings in current language */
160-
public function lng($text)
161-
{
137+
/** Translates strings in current language */
138+
public function lng($text) {
162139
if($this->_language_inc != 1) {
163140
//* loading global Wordbook
164141
$this->load_language_file('/lib/lang/'.$_SESSION['s']['language'].'.lng');
@@ -169,7 +146,7 @@ public function lng($text)
169146
$this->load_language_file($lng_file);
170147
}
171148
$this->_language_inc = 1;
172-
}
149+
}
173150
if(!empty($this->_wb[$text])) {
174151
$text = $this->_wb[$text];
175152
} else {
@@ -179,7 +156,7 @@ public function lng($text)
179156
}
180157
return $text;
181158
}
182-
159+
183160
//** Helper function to load the language files.
184161
public function load_language_file($filename) {
185162
$filename = ISPC_ROOT_PATH.'/'.$filename;
@@ -196,16 +173,15 @@ public function load_language_file($filename) {
196173
}
197174
}
198175

199-
public function tpl_defaults()
200-
{
176+
public function tpl_defaults() {
201177
$this->tpl->setVar('app_title', $this->_conf['app_title']);
202178
if(isset($_SESSION['s']['user'])) {
203179
$this->tpl->setVar('app_version', $this->_conf['app_version']);
204180
} else {
205181
$this->tpl->setVar('app_version', '');
206182
}
207183
$this->tpl->setVar('app_link', $this->_conf['app_link']);
208-
if(isset($this->_conf['app_logo']) && $this->_conf['app_logo'] != '' && @is_file($this->_conf['app_logo'])){
184+
if(isset($this->_conf['app_logo']) && $this->_conf['app_logo'] != '' && @is_file($this->_conf['app_logo'])) {
209185
$this->tpl->setVar('app_logo', '<img src="'.$this->_conf['app_logo'].'">');
210186
} else {
211187
$this->tpl->setVar('app_logo', '&nbsp;');
@@ -217,7 +193,7 @@ public function tpl_defaults()
217193
$this->tpl->setVar('html_content_encoding', $this->_conf['html_content_encoding']);
218194

219195
$this->tpl->setVar('delete_confirmation', $this->lng('delete_confirmation'));
220-
//print_r($_SESSION);
196+
//print_r($_SESSION);
221197
if(isset($_SESSION['s']['module']['name'])) {
222198
$this->tpl->setVar('app_module', $_SESSION['s']['module']['name']);
223199
}
@@ -227,8 +203,8 @@ public function tpl_defaults()
227203
if(isset($_SESSION['s']['user']) && $this->auth->has_clients($_SESSION['s']['user']['userid'])) {
228204
$this->tpl->setVar('is_reseller', 1);
229205
}
230-
}
231-
206+
}
207+
232208
} // end class
233209

234210
//** Initialize application (app) object
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="uniForm">
2+
<div id="errorMsg">
3+
<h3>Error</h3>
4+
<ol>
5+
<li>###ERRORMSG###</li>
6+
</ol>
7+
</div>
8+
</div>

0 commit comments

Comments
 (0)