PageRenderTime 21ms CodeModel.GetById 9ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/site/www/_js/libs/tiny_mce/plugins/imagemanager/classes/Utils/Error.php

https://bitbucket.org/thiscode/thiscode-shop
PHP | 286 lines | 164 code | 57 blank | 65 comment | 28 complexity | f8247921cfc2aa72bc64967d148ce4eb MD5 | raw file
  1<?php
  2/**
  3 * $Id: Error.php 624 2008-12-02 17:44:39Z spocke $
  4 *
  5 * @package MCManager.utils
  6 * @author Moxiecode
  7 * @copyright Copyright Š 2005, Moxiecode Systems AB, All rights reserved.
  8 */
  9
 10// Define it on PHP4
 11if (!defined('E_STRICT'))
 12	define('E_STRICT', 2048);
 13
 14// Define error levels
 15define('FATAL', E_USER_ERROR);
 16define('ERROR', E_USER_WARNING);
 17define('WARNING', E_USER_NOTICE);
 18
 19/**
 20 * This class handles Error messages.
 21 *
 22 * @package MCManager.utils
 23 */
 24class Moxiecode_Error {
 25	var $id;
 26
 27	function Moxiecode_Error() {
 28	}
 29
 30	function setId($id) {
 31		$this->id = $id;
 32	}
 33
 34	function handleError($errno, $errstr, $errfile, $errline, $errcontext) {
 35		global $man;
 36
 37		$error = array();
 38		$log = false;
 39
 40		$error['title'] = "";
 41		$error['break'] = false;
 42		$error['errstr'] = $errstr;
 43		//$error['errcontext'] = $errcontext;
 44		$error['errcontext'] = "";
 45		$error['errfile'] = "";
 46		$error['errline'] = "";
 47
 48		// Add file and line only in debug mode
 49		if (isset($man)) {
 50			$mcConfig = $man->getConfig();
 51			$log = $man->getLogger();
 52
 53			if (checkBool($mcConfig['general.debug'])) {
 54				$error['errfile'] = $errfile;
 55				$error['errline'] = $errline;
 56			}
 57		}
 58
 59		switch ($errno) {
 60			case E_USER_ERROR:
 61				$error['title'] = "Fatal Error";
 62				$error['break'] = true;
 63			break;
 64
 65			case E_USER_NOTICE:
 66				$error['title'] = "Notice";
 67				$error['break'] = false;
 68			break;
 69
 70			case E_USER_WARNING:
 71				$error['title'] = "Warning";
 72				$error['break'] = true;
 73			break;
 74
 75			case E_PARSE:
 76				$error['title'] = "PHP Parse Error";
 77				$error['break'] = true;
 78
 79				if ($log)
 80					$log->fatal($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
 81			break;
 82
 83			case E_ERROR:
 84				$error['title'] = "PHP Error";
 85				$error['break'] = true;
 86
 87				if ($log)
 88					$log->error($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
 89			break;
 90
 91			case E_WARNING:
 92				$error['title'] = "PHP Warning";
 93				$error['break'] = false;
 94
 95				if ($log)
 96					$log->warn($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
 97			break;
 98
 99			case E_CORE_ERROR:
100				$error['title'] = "PHP Error : Core Error";
101				$error['break'] = true;
102
103				if ($log)
104					$log->error($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
105			break;
106
107			case E_CORE_WARNING:
108				$error['title'] = "PHP Error : Core Warning";
109				$error['break'] = true;
110
111				if ($log)
112					$log->warn($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
113			break;
114
115			case E_COMPILE_ERROR:
116				$error['title'] = "PHP Error : Compile Error";
117				$error['break'] = true;
118
119				if ($log)
120					$log->error($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
121			break;
122
123			case E_COMPILE_WARNING:
124				$error['title'] = "PHP Error : Compile Warning";
125				$error['break'] = true;
126
127				if ($log)
128					$log->warn($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
129			break;
130
131			case E_NOTICE:
132				$error['title'] = "PHP Notice";
133				$error['break'] = false;
134
135				if ($log)
136					$log->info($error['title'] . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
137			break;
138
139			case E_STRICT:
140				$error['title'] = "PHP Strict";
141				$error['break'] = false;
142
143				if ($log)
144					$log->info($error['title'] . " (" . $errno . ")" . ", Msg: " . $error['errstr'] . " in " . $error['errfile'] . "(" . $error['errline'] . ")");
145			break;
146		}
147
148		// Add error number
149		$error['title'] = $error['title'] . " (". $errno .")";
150
151		return $error;
152	}
153}
154
155/**
156 * Calls the MCError class, returns true.
157 *
158 * @param Int $errno Number of the error.
159 * @param String $errstr Error message.
160 * @param String $errfile The file the error occured in.
161 * @param String $errline The line in the file where error occured.
162 * @param Array $errcontext Error context array, contains all variables.
163 * @return Bool Just return true for now.
164 */
165function JSONErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
166	global $MCErrorHandler;
167
168	// Ignore these
169	if ($errno == E_STRICT)
170		return true;
171
172	// Just pass it through	to the class.
173	$data = $MCErrorHandler->handleError($errno, $errstr, $errfile, $errline, $errcontext);
174
175	if ($data['break']) {
176		unset($data['break']);
177		unset($data['title']);
178
179		$data['level'] = "FATAL";
180
181		$json = new Moxiecode_JSON();
182		$result = new stdClass();
183		$result->result = null;
184		$result->id = 'err';
185		$result->error = $data;
186
187		echo $json->encode($result);
188		die();
189	}
190}
191
192/**
193 * Calls the MCError class, returns true.
194 *
195 * @param Int $errno Number of the error.
196 * @param String $errstr Error message.
197 * @param String $errfile The file the error occured in.
198 * @param String $errline The line in the file where error occured.
199 * @param Array $errcontext Error context array, contains all variables.
200 * @return Bool Just return true for now.
201 */
202function JSErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
203	global $MCErrorHandler;
204
205	// Ignore these
206	if ($errno == E_STRICT)
207		return true;
208
209	// Just pass it through	to the class.
210	$data = $MCErrorHandler->handleError($errno, $errstr, $errfile, $errline, $errcontext);
211
212	if ($data['break']) {
213		echo 'alert(\'' . addslashes($data['errstr']) . '\');';
214		die();
215	}
216}
217
218/**
219 * Calls the MCError class, returns true.
220 *
221 * @param Int $errno Number of the error.
222 * @param String $errstr Error message.
223 * @param String $errfile The file the error occured in.
224 * @param String $errline The line in the file where error occured.
225 * @param Array $errcontext Error context array, contains all variables.
226 * @return Bool Just return true for now.
227 */
228function StreamErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
229	global $MCErrorHandler;
230
231	// Ignore these
232	if ($errno == E_STRICT)
233		return true;
234
235	// Just pass it through	to the class.
236	$data = $MCErrorHandler->handleError($errno, $errstr, $errfile, $errline, $errcontext);
237
238	if ($data['break']) {
239		if ($_SERVER["REQUEST_METHOD"] == "GET") {
240			header("HTTP/1.1 500 Internal server error");
241			die($errstr);
242		} else {
243			unset($data['break']);
244			unset($data['title']);
245
246			$data['level'] = "FATAL";
247
248			$json = new Moxiecode_JSON();
249			$result = new stdClass();
250			$result->result = null;
251			$result->id = 'err';
252			$result->error = $data;
253
254			echo '<html><body><script type="text/javascript">parent.handleJSON(' . $json->encode($result) . ');</script></body></html>';
255			die();
256		}
257	}
258}
259
260/**
261 * Calls the MCError class, returns true.
262 *
263 * @param Int $errno Number of the error.
264 * @param String $errstr Error message.
265 * @param String $errfile The file the error occured in.
266 * @param String $errline The line in the file where error occured.
267 * @param Array $errcontext Error context array, contains all variables.
268 * @return Bool Just return true for now.
269 */
270function HTMLErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
271	global $MCErrorHandler;
272
273	// Ignore these
274	if ($errno == E_STRICT)
275		return true;
276
277	// Just pass it through	to the class.
278	$data = $MCErrorHandler->handleError($errno, $errstr, $errfile, $errline, $errcontext);
279
280	if ($data['break']) {
281		die($errstr);
282	}
283}
284
285
286?>