1
|
|
|
<?php namespace EvolutionCMS\Legacy; |
2
|
|
|
|
3
|
|
|
// this is the old error handler. Here for legacy, until i replace all the old errors. |
4
|
|
|
class ErrorHandler |
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @var int |
9
|
|
|
*/ |
10
|
|
|
public $errorcode; |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
public $errors = array(); |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public $errormessage; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* errorHandler constructor. |
22
|
|
|
*/ |
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
$_lang = $this->includeLang('errormsg'); |
27
|
|
|
|
28
|
|
|
$this->errors = array( |
29
|
|
|
0 => $_lang["No errors occured."], |
30
|
|
|
1 => $_lang["An error occured!"], |
31
|
|
|
2 => $_lang["Document's ID not passed in request!"], |
32
|
|
|
3 => $_lang["You don't have enough privileges for this action!"], |
33
|
|
|
4 => $_lang["ID passed in request is NaN!"], |
34
|
|
|
5 => $_lang["The document is locked!"], |
35
|
|
|
6 => $_lang["Too many results returned from database!"], |
36
|
|
|
7 => $_lang["Not enough/ no results returned from database!"], |
37
|
|
|
8 => $_lang["Couldn't find parent document's name!"], |
38
|
|
|
9 => $_lang["Logging error!"], |
39
|
|
|
10 => $_lang["Table to optimise not found in request!"], |
40
|
|
|
11 => $_lang["No settings found in request!"], |
41
|
|
|
12 => $_lang["The document must have a title!"], |
42
|
|
|
13 => $_lang["No user selected as recipient of this message!"], |
43
|
|
|
14 => $_lang["No group selected as recipient of this message!"], |
44
|
|
|
15 => $_lang["The document was not found!"], |
45
|
|
|
|
46
|
|
|
100 => $_lang["Double action (GET & POST) posted!"], |
47
|
|
|
600 => $_lang["Document cannot be it's own parent!"], |
48
|
|
|
601 => $_lang["Document's ID not passed in request!"], |
49
|
|
|
602 => $_lang["New parent not set in request!"], |
50
|
|
|
900 => $_lang["don't know the user!"], // don't know the user! |
51
|
|
|
901 => $_lang["wrong password!"], // wrong password! |
52
|
|
|
902 => $_lang["Due to too many failed logins, you have been blocked!"], |
53
|
|
|
903 => $_lang["You are blocked and cannot log in!"], |
54
|
|
|
904 => $_lang["You are blocked and cannot log in! Please try again later."], |
55
|
|
|
905 => $_lang["The security code you entered didn't validate! Please try to login again!"] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $context |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function includeLang($context = 'common') |
64
|
|
|
{ |
65
|
|
|
$modx = evolutionCMS(); |
66
|
|
|
$_lang = array(); |
67
|
|
|
|
68
|
|
|
$context = trim($context, '/'); |
69
|
|
|
if (strpos($context, '..') !== false) { |
70
|
|
|
return $_lang; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($context === 'common') { |
74
|
|
|
$lang_path = MODX_MANAGER_PATH . 'includes/lang/'; |
75
|
|
|
} else { |
76
|
|
|
$lang_path = MODX_MANAGER_PATH . "includes/lang/{$context}/"; |
77
|
|
|
} |
78
|
|
|
include_once($lang_path . 'english.inc.php'); |
79
|
|
|
$manager_language = $modx->config['manager_language']; |
80
|
|
|
if (is_file("{$lang_path}{$manager_language}.inc.php")) { |
81
|
|
|
include_once("{$lang_path}{$manager_language}.inc.php"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return is_array($_lang) ? $_lang : array(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param int $errorcode |
89
|
|
|
* @param string $custommessage |
90
|
|
|
*/ |
91
|
|
|
public function setError($errorcode, $custommessage = "") |
92
|
|
|
{ |
93
|
|
|
$this->errorcode = $errorcode; |
94
|
|
|
$this->errormessage = $this->errors[$errorcode]; |
95
|
|
|
if ($custommessage != "") { |
96
|
|
|
$this->errormessage = $custommessage; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
|
|
public function getError() |
104
|
|
|
{ |
105
|
|
|
return $this->errorcode; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
public function dumpError() |
112
|
|
|
{ |
113
|
|
|
?> |
114
|
|
|
<html> |
115
|
|
|
<head> |
116
|
|
|
<title>MODX :: Error</title> |
117
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $modx_manager_charset; ?>"> |
118
|
|
|
<script> |
119
|
|
|
function showError() { |
120
|
|
|
alert("<?php echo $this->errormessage; ?>"); |
121
|
|
|
history.back(-1); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
setTimeout("showError()", 10); |
125
|
|
|
</script> |
126
|
|
|
</head> |
127
|
|
|
<body> |
128
|
|
|
</body> |
129
|
|
|
</html> |
130
|
|
|
<?php |
131
|
|
|
exit; |
|
|
|
|
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.