Example #1
0
function shutdown_handler()
{
    try {
        if (NULL !== ($error = error_get_last())) {
            throw new CustomizableException($error['message'], $error['type'], $error['file'], $error['line']);
        }
    } catch (\Exception $e) {
        exception_handler($e);
    }
}
Example #2
0
function exception_handler($exception)
{
    global $request_method;
    // If the exception is a usernotloggedin, save the return URL and redirect them to the signin page
    if (get_class($exception) == "UserNotLoggedInException" && $request_method == Method::GET) {
        header('Location: /user/login/null/100?return=' . $_SERVER['REQUEST_URI']);
    } else {
        if (get_parent_class($exception) == "BaseException") {
            error_log($exception->printMe($request_method));
            echo $exception->printMe($request_method);
        } else {
            $e = new DatabaseException("Database error.", $exception);
            error_log($exception);
            // Kick it back up
            exception_handler($e);
        }
    }
}
Example #3
0
 public static function factory($className, $dir = '')
 {
     $_file = '';
     // Mod,Lib,Pub,Ctl类的自动调用
     $clsPath = array('Mod' => PATH_MOD, 'Ent' => PATH_ENT, 'Ser' => PATH_SER);
     $_classType = substr($className, 0, 3);
     if (isset($clsPath[$_classType])) {
         $_file = "{$clsPath[$_classType]}/{$dir}" . basename($className) . '.php';
     }
     if ($_file) {
         // auto中不能抛出错误
         if (!is_file($_file)) {
             exception_handler(new RuntimeException("Not Found", 404));
             exit;
         }
         require $_file;
         return new $className();
     }
     return false;
 }
function exception_handler($e, $sub = 0)
{
    if (PHP_SAPI == 'cli' || defined('DEBUG_OUTPUT') && DEBUG_OUTPUT == 'text') {
        ob_start();
        echo $e;
        $content = ob_get_contents();
        ob_end_clean();
        foreach (explode("\n", $content) as $line) {
            echo str_repeat(' ', $sub * 4) . $line . "\n";
        }
    } else {
        echo '<div style="margin: 0 0 10px ' . $sub * 30 . 'px">';
        echo '<code style="color: red"><b>' . get_class($e) . '</b>: ' . $e->getMessage() . '</code><br />';
        echo "<p style=\"font-family: monospace; background: #eee; padding: 5px;\">";
        echo "<span style=\"color: #555;\">";
        echo render_backtrace($e->getTrace());
        echo '</span></div>';
    }
    // Show reason
    if ($e instanceof Lib_Exception && $e->reason) {
        exception_handler($e->reason, $sub + 1);
    }
}
Example #5
0
/**
 * 自动加载魔术方法
 * 支持core系统下的Mod,Lib,Pub,Ctl及三种基础类的自动加载
 * @param 类名 $className
 * @return null
 */
function autoload($className)
{
    $_file = '';
    // controller model
    if ($className == 'Controller' || $className == 'Model' || $className == 'ExceptionHandler') {
        $_file = PATH_CORE . '/' . $className . '.php';
    } else {
        // Mod,Lib,Pub,Ctl类的自动调用
        $clsPath = array('Mod' => PATH_MOD, 'Lib' => PATH_LIB, 'Pub' => PATH_PUB, 'Ctl' => PATH_CTL, 'Ent' => PATH_ENT, 'Api' => PATH_API, 'Ser' => PATH_SER);
        $_classType = substr($className, 0, 3);
        if (isset($clsPath[$_classType])) {
            $_file = "{$clsPath[$_classType]}/" . basename($className) . '.php';
        }
    }
    if ($_file) {
        // auto中不能抛出错误
        if (!is_file($_file)) {
            exception_handler(new RuntimeException("Not Found", 404));
            exit;
        }
        require $_file;
        return true;
    }
    return false;
}
    } catch (Exception $e) {
        exception_handler($e);
    }
    if (!$request->containsUser($login)) {
        echo "<br />Erreur: l'utilisateur {$login} n'a pu &ecirc;tre ajout&eacute;. Login ou mot de passe incorrect";
    }
    $xmlResult_EpisodesToWatch = null;
    $xmlSeries = null;
    try {
        if ($login == constant('SERVER_ACCOUNT')) {
            $xmlResult_EpisodesToWatch = $request->userRequest($login, "members/episodes/vf.xml");
        } else {
            $xmlResult_EpisodesToWatch = $request->userRequest($login, "members/episodes/vf.xml", array("view" => "next"));
        }
    } catch (Exception $e) {
        exception_handler($e);
    }
    $oldUrl = '';
    //Pour chaque épisode de chaque utilisateur
    foreach ($xmlResult_EpisodesToWatch->episodes->episode as $episode) {
        //On évite d'avoir deux fois les même épisode dans le tableau que l'ont génère
        if (!array_key_exists($episode->url . " " . $episode->episode, $EpisodeArray)) {
            //on ajoute l'épisode au tableau avec l'utilisateur courrant
            $EpisodeArray[(string) $episode->url . " " . (string) $episode->episode] = array("episode" => $episode, "user" => $login);
        } else {
            //on ajoute l'utilisateur à l'épisode
            $EpisodeArray[(string) $episode->url . " " . (string) $episode->episode]["user"] .= " " . $login;
        }
    }
}
/*echo "<!--";
Example #7
0
require_once "config/translation/" . $__out['lang'] . ".php";
try {
    dispatcher::request();
    // handle request
} catch (PermissionDeniedException $ex) {
    if ($_SESSION['group_id'] == 0) {
        // visitor
        dispatcher::redirect(array("controller" => "user", "action" => "login"), "please_login_first");
    } else {
        dispatcher::redirect(array("controller" => "errors", "action" => "permission_denied"));
    }
} catch (PageNotFoundException $ex) {
    if (DEBUG) {
        exception_handler($ex);
    } else {
        dispatcher::redirect(array("controller" => "errors", "action" => "page_not_found"));
    }
} catch (Exception $ex) {
    exception_handler($ex);
}
$__out['user_id'] = $_SESSION['user_id'];
$__out['__errors'] = $__errors;
/**< Add the $__errors array to the array of output ($__out) to be shown on the template when displayed. */
$__out['__info'] = $__info;
/**< Add the $__info array to the array of output ($__out) to be shown on the template when displayed. */
//-------------------------------------------------------------
// view handling
require_once "lib/clssmarty.php";
$template = new clssmarty();
$template->display_index();
/**< assign the $__out variables to the template and display the main tpl of the current language and current theme and current group. */
Example #8
0
function exception_error_handler($code, $message, $file, $line)
{
    exception_handler(new moojon_exception($message, $code, 0, $file, $line));
}
 /**
  * The super-magical method that includes files & finalizes things using 
  * the given templating engine. 
  * NOTE: the local variable "$page" is made so that the included scripts 
  * can make calls to the templating engine, just like they used to.  It's 
  * AWESOME.
  */
 function finish()
 {
     //Avoid problems when REGISTER_GLOBALS is on...
     $badUrlVars = array('page', 'this');
     foreach ($badUrlVars as $badVarName) {
         unset($_GET[$badVarName], $_POST[$badVarName]);
     }
     unset($badUrlVars, $badVarName);
     if (is_array($this->injectVars) && count($this->injectVars)) {
         $definedVars = get_defined_vars();
         foreach ($this->injectVars as $myVarName => $myVarVal) {
             if (!isset($definedVars[$myVarName])) {
                 ${$myVarName} = $myVarVal;
             } else {
                 throw new exception(__METHOD__ . ": attempt to inject already defined var '" . $myVarName . "'");
             }
         }
     }
     unset($definedVars, $myVarName, $myVarVal);
     if (isset($this->session) && is_object($this->session)) {
         $this->templateObj->session = $this->session;
     }
     //if we loaded an index, but there is no "content", then move 'em around so we have content.
     if (isset($this->templateObj->templateFiles['index']) && !isset($this->templateObj->templateFiles['content'])) {
         $this->add_template('content', $this->templateObj->templateFiles['index']);
     }
     //make the "final section" available to scripts.
     $finalSection = $this->finalSection;
     $sectionArr = $this->sectionArr;
     if (count($sectionArr) && $sectionArr[count($sectionArr) - 1] == "") {
         array_pop($sectionArr);
     }
     $fullSectionArr = $this->fullSectionArr;
     array_unshift($sectionArr, $this->baseDir);
     $finalURL = ToolBox::string_from_array($sectionArr, NULL, '/');
     $this->templateObj->add_template_var('PHP_SELF', '/' . ToolBox::string_from_array($sectionArr, NULL, '/'));
     $page = $this->templateObj;
     //now include the includes scripts, if there are any.
     if (is_array($this->includesList) && count($this->includesList)) {
         try {
             foreach ($this->includesList as $myInternalIndex => $myInternalScriptName) {
                 $this->myLastInclude = $myInternalScriptName;
                 unset($myInternalScriptName, $myInternalIndex);
                 include_once $this->myLastInclude;
             }
             //now load the "after" includes.
             if (is_array($this->afterIncludesList)) {
                 foreach ($this->afterIncludesList as $myInternalIndex => $myInternalScriptName) {
                     $this->myLastInclude = $myInternalScriptName;
                     unset($myInternalScriptName, $myInternalIndex);
                     include_once $this->myLastInclude;
                 }
             }
         } catch (exception $e) {
             $myRoot = preg_replace('/\\//', '\\\\/', $this->incFs->root);
             $displayableInclude = preg_replace('/^' . $myRoot . '/', '', $this->myLastInclude);
             $page->set_message_wrapper(array('title' => "Fatal Error", 'message' => __METHOD__ . ": A fatal error occurred while processing <b>" . $displayableInclude . "</b>:<BR>\n<b>ERROR</b>: " . $e->getMessage(), 'type' => "fatal"));
             //try to pass the error on to the user's exception handler, if there is one.
             if (function_exists('exception_handler')) {
                 exception_handler($e);
             }
         }
         unset($myInternalIndex);
         unset($myInternalScriptName);
     }
     if (is_bool($page->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) {
         $this->isValid = $page->allow_invalid_urls();
     }
     if ($this->isValid === TRUE) {
         if ($page->printOnFinish === true) {
             $page->print_page();
         }
     } else {
         $this->die_gracefully($this->reason);
     }
 }
Example #10
0
/**
 * CMS's Error functionality, these will prettify, and give you detailed error reporting
 * when this file is included and functional
 */
function error_handler($errno, $errstr, $errfile, $errline)
{
    if (!(error_reporting() & $errno)) {
        return;
    }
    if ($errno == 8) {
        return;
    }
    $exception = new error_Exception($errstr, $errno, $errfile, $errline);
    exception_handler($exception);
}