| 1 | 1488 | DarkViper | <?php
 | 
      
        | 2 |  |  | /**
 | 
      
        | 3 |  |  |  * @category        WebsiteBaker
 | 
      
        | 4 |  |  |  * @package         WebsiteBaker_core
 | 
      
        | 5 |  |  |  * @author          Werner v.d.Decken
 | 
      
        | 6 |  |  |  * @copyright       WebsiteBaker.org e.V.
 | 
      
        | 7 |  |  |  * @link            http://websitebaker2.org
 | 
      
        | 8 |  |  |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
      
        | 9 |  |  |  * @version         $Id: class.order.php 1487 2011-08-10 13:20:15Z DarkViper $
 | 
      
        | 10 |  |  |  * @filesource		$HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/framework/class.order.php $
 | 
      
        | 11 |  |  |  *
 | 
      
        | 12 |  |  |  * Global exception-handler
 | 
      
        | 13 |  |  |  * This module will activate a global exception handler to catch all thrown exceptions
 | 
      
        | 14 |  |  |  *
 | 
      
        | 15 |  |  |  */
 | 
      
        | 16 |  |  | /**
 | 
      
        | 17 |  |  |  * define several default exceptions directly to prevent from extra loading requests
 | 
      
        | 18 |  |  |  */
 | 
      
        | 19 |  |  | 
 | 
      
        | 20 |  |  | /**
 | 
      
        | 21 |  |  |  * define Exception to show error after accessing a forbidden file
 | 
      
        | 22 |  |  |  */
 | 
      
        | 23 |  |  | 	class IllegalFileException extends LogicException {
 | 
      
        | 24 |  |  | 		public function __toString() {
 | 
      
        | 25 | 1489 | DarkViper | 			$file = str_replace(dirname(dirname(__FILE__)), '', $this->getFile());
 | 
      
        | 26 | 1499 | DarkViper | 			$out  = '<div style="color: #ff0000; text-align: center;"><br />';
 | 
      
        | 27 |  |  | 			$out .= '<br /><br /><h1>Illegale file access</h1>';
 | 
      
        | 28 | 1488 | DarkViper | 			$out .= '<h2>'.$file.'</h2></div>';
 | 
      
        | 29 |  |  | 			return $out;
 | 
      
        | 30 |  |  | 		}
 | 
      
        | 31 |  |  | 	} // end of class
 | 
      
        | 32 |  |  | 
 | 
      
        | 33 |  |  | /**
 | 
      
        | 34 |  |  |  *
 | 
      
        | 35 |  |  |  * @param Exception $e
 | 
      
        | 36 |  |  |  */
 | 
      
        | 37 |  |  | 	function globalExceptionHandler($e) {
 | 
      
        | 38 |  |  | 		// hide server internals from filename where the exception was thrown
 | 
      
        | 39 |  |  | 		$file = str_replace(dirname(dirname(__FILE__)), '', $e->getFile());
 | 
      
        | 40 |  |  | 		// select some exceptions for special handling
 | 
      
        | 41 |  |  | 		if ($e instanceof IllegalFileException) {
 | 
      
        | 42 |  |  | 			$sResponse  = $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden';
 | 
      
        | 43 |  |  | 			header($sResponse);
 | 
      
        | 44 |  |  | 			echo $e;
 | 
      
        | 45 |  |  | 		}else {
 | 
      
        | 46 |  |  | 		// default exception handling
 | 
      
        | 47 |  |  | 			$out  = 'There was an unknown exception:'."\n";
 | 
      
        | 48 |  |  | 			$out .= $e->getMessage()."\n";
 | 
      
        | 49 |  |  | 			$out .= 'in line ('.$e->getLine().') of ('.$file.')'."\n";
 | 
      
        | 50 |  |  | 			echo $out;
 | 
      
        | 51 |  |  | 		}
 | 
      
        | 52 |  |  | 	}
 | 
      
        | 53 |  |  | /**
 | 
      
        | 54 |  |  |  * now activate the new defined handler
 | 
      
        | 55 |  |  |  */
 | 
      
        | 56 |  |  | 	set_exception_handler('globalExceptionHandler');
 |