PageRenderTime 127ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/www/assets/tiny_mce/plugins/imagemanager/classes/Utils/Error.php

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