init() 공개 메소드

public init ( )
예제 #1
0
 public static function init($debug = false)
 {
     define('FATAL', E_USER_ERROR);
     define('ERROR', E_USER_WARNING);
     define('WARNING', E_USER_NOTICE);
     try {
         include "framework" . DS . "bootstrap.php";
         $error = new ErrorHandler();
         $config = Config::getInstance();
         $baseURL = $config->getbaseurl();
         if (!defined("BASE_URL")) {
             define("BASE_URL", $baseURL);
         }
         $filter = BaseFilter::getInstance();
         new Request();
         $i18n = i18n::init();
         Router::getInstance();
         new Dispatcher();
     } catch (Exception $ex) {
         trigger_error("CORE | There has been an exception at the core of the Framework {$ex->getMessage()} ", E_USER_ERROR);
     }
 }
예제 #2
0
 /**
  * Initialize db connections, cache and session
  */
 public static function init($options = [])
 {
     // initialize mbstring
     mb_internal_encoding('UTF-8');
     mb_regex_encoding('UTF-8');
     // get flags & dependencies
     $flags = application::get('flag');
     $backend = application::get('numbers.backend', ['backend_exists' => true]);
     // processing wildcard first
     $wildcard = application::get('wildcard');
     $wildcard_keys = null;
     if (!empty($wildcard['enabled']) && !empty($wildcard['model'])) {
         $wildcard_keys = call_user_func($wildcard['model']);
         application::set(['wildcard', 'keys'], $wildcard_keys);
     }
     // initialize cryptography
     $crypt = application::get('crypt');
     if (!empty($crypt) && $backend) {
         foreach ($crypt as $crypt_link => $crypt_settings) {
             if (!empty($crypt_settings['submodule']) && !empty($crypt_settings['autoconnect'])) {
                 $crypt_object = new crypt($crypt_link, $crypt_settings['submodule'], $crypt_settings);
             }
         }
     }
     // create database connections
     $db = application::get('db');
     if (!empty($db) && $backend) {
         foreach ($db as $db_link => $db_settings) {
             if (empty($db_settings['autoconnect']) || empty($db_settings['servers']) || empty($db_settings['submodule'])) {
                 continue;
             }
             $connected = false;
             foreach ($db_settings['servers'] as $server_key => $server_values) {
                 $db_object = new db($db_link, $db_settings['submodule']);
                 // wildcards replaces
                 if (isset($wildcard_keys[$db_link])) {
                     $server_values['dbname'] = $wildcard_keys[$db_link]['dbname'];
                 }
                 // connecting
                 $server_values = array_merge2($server_values, $db_settings);
                 $db_status = $db_object->connect($server_values);
                 if ($db_status['success'] && $db_status['status']) {
                     $connected = true;
                     break;
                 }
             }
             // checking if not connected
             if (!$connected) {
                 throw new Exception('Unable to open database connection!');
             }
         }
     }
     // initialize cache
     $cache = application::get('cache');
     if (!empty($cache) && $backend) {
         foreach ($cache as $cache_link => $cache_settings) {
             if (empty($cache_settings['submodule']) || empty($cache_settings['autoconnect'])) {
                 continue;
             }
             $connected = false;
             foreach ($cache_settings['servers'] as $cache_server) {
                 $cache_object = new cache($cache_link, $cache_settings['submodule']);
                 $cache_status = $cache_object->connect($cache_server);
                 if ($cache_status['success']) {
                     $connected = true;
                     break;
                 }
             }
             // checking if not connected
             if (!$connected) {
                 throw new Exception('Unable to open cache connection!');
             }
         }
     }
     // if we are from command line we exit here
     if (!empty($options['__run_only_bootstrap'])) {
         return;
     }
     // initialize session
     $session = application::get('flag.global.session');
     if (!empty($session['start']) && $backend && !application::get('flag.global.__skip_session')) {
         session::start(isset($session['options']) ? $session['options'] : []);
     }
     // we need to get overrides from session and put them back to flag array
     $flags = array_merge_hard($flags, session::get('numbers.flag'));
     application::set('flag', $flags);
     // initialize i18n
     if ($backend) {
         $temp_result = i18n::init();
         if (!$temp_result['success']) {
             throw new Exception('Could not initialize i18n.');
         }
     }
     // format
     format::init();
     // including libraries that we need to auto include
     if (!empty($flags['global']['library'])) {
         foreach ($flags['global']['library'] as $k => $v) {
             // we need to skip certain keys
             if ($k == 'submodule' || $k == 'options') {
                 continue;
             }
             // we only include if autoconnect is on
             if (!empty($v['autoconnect'])) {
                 factory::submodule('flag.global.library.' . $k . '.submodule')->add();
             }
         }
     }
     // check if we need to include system files from frontend
     if (application::get('dep.submodule.numbers.frontend.system')) {
         numbers_frontend_system_model_base::start();
     }
 }
예제 #3
0
    die("Keine SCRIPT_NAME vom Apache erhalten!");
}
$_SERVER["REQUEST_URI2"] = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]) - 10);
$p = strpos($_SERVER["REQUEST_URI2"], "?");
if (!$p) {
    $_SERVER["REQUEST_URIpure"] = $_SERVER["REQUEST_URI2"];
} else {
    $_SERVER["REQUEST_URIpure"] = substr($_SERVER["REQUEST_URI2"], 0, $p);
}
include_once $_ENV["basepath"] . "/app/code/classes/class.i18n.php";
include_once $_ENV["basepath"] . "/app/code/classes/class.fcache.php";
@session_start();
if (isset($_GET["_lang"])) {
    $_SESSION["language"] = $_GET["_lang"];
}
i18n::init(isset($_SESSION["language"]) ? $_SESSION["language"] : "de_DE", "install");
switch ($_SERVER["REQUEST_URIpure"]) {
    case "/":
    case "/index.php":
        include $_ENV["basepath"] . "/app/design/default/install/index.php";
        exit(1);
    case "/license":
        include $_ENV["basepath"] . "/app/design/default/install/license.php";
        exit(1);
    case "/install":
        if (isset($_POST["action"]) && $_POST["action"] == "write_config") {
            include $_ENV["basepath"] . "/app/design/default/install/install_page5.php";
            exit(1);
        }
        if (isset($_POST["status"]) && $_POST["status"] == "database_ok") {
            include $_ENV["basepath"] . "/app/design/default/install/install_page4.php";
예제 #4
0
        if (file_exists($file)) {
            require $file;
            return true;
        }
    }
    if (isset($_GET["debug"])) {
        throw new Exception("Klasse " . $class_name . " kann nicht gefunden werden!");
    }
    return false;
});
srand();
SiteConfig::load(0);
Session::init();
$config = SiteConfig::get(0);
if (!isset($_ENV["baseurl"])) {
    $_ENV["baseurl"] = $config["baseurl"];
}
if (!isset($_ENV["baseurlpath"])) {
    $_ENV["baseurlpath"] = $config["baseurlpath"];
}
//Bugvermeidung
$_REQUEST = array_merge($_GET, $_POST);
i18n::init(isset($_GET["_lang"]) ? $_GET["_lang"] : (isset($config["language"]) ? $config["language"] : "de_DE"));
function get_path($file)
{
    return str_replace("//", "/", $_ENV["baseurlpath"] . $file);
}
function html($txt)
{
    return htmlentities($txt, 3, "UTF-8");
}
예제 #5
0
<?php

// include i18n class and initialize it
require_once 'i18n.class.php';
$i18n = new i18n('lang/lang_{LANGUAGE}.yml', 'langcache/', 'en');
// Parameters: language file path, cache dir, default language (all optional)
// init object: load language files, parse them if not cached, and so on.
$i18n->init();
?>

<!-- get applied language -->
<p>Applied Language: <?php 
echo $i18n->getAppliedLang();
?>
 </p>

<!-- get the cache path -->
<p>Cache path: <?php 
echo $i18n->getCachePath();
?>
</p>

<!-- Get some greetings -->
<p>A greeting: <?php 
echo L::greeting;
?>
</p>
<p>Something other: <?php 
echo L::category_somethingother;
?>
</p><!-- normally sections in the ini are seperated with an underscore like here. -->
예제 #6
0
 /**
  * Main server procedure. index.php in the system's root calls this method by default.
  */
 public function run()
 {
     $db = Config::main()->getDbo();
     // Prepare necessities.
     $this->user = new ModelUser($db);
     if ($this->user->isLoggedIn()) {
         $this->user->restoreSession()->refreshSession();
     }
     Cache::init($db);
     Profiler::startSection('DiamondMVC');
     Profiler::startSection('Initiating i18n');
     logMsg('DiamondMVC: using compressed language file: ' . (Config::main()->get('DEBUG_MODE') ? 'yes' : 'no'), 1, false);
     i18n::init(Config::main()->get('DEBUG_MODE'));
     Profiler::endSection();
     // Load plugins
     Profiler::startSection('Load plugins');
     $this->plugins = Plugin::getPlugins();
     Profiler::endSection();
     Profiler::startSection('Load permissions');
     Permissions::init($db);
     Profiler::endSection();
     // Register field classes
     Profiler::startSection('Register fields');
     FormBuilder::registerFields();
     Profiler::endSection();
     $evt = new SystemBeforeRouteEvent();
     $this->trigger($evt);
     if (!$evt->isDefaultPrevented()) {
         Profiler::startSection('Routing');
         // Route requested controller
         if (isset($_REQUEST['control']) and !empty($_REQUEST['control'])) {
             $control = 'Controller' . str_replace('-', '_', $_REQUEST['control']);
             if (!class_exists($control)) {
                 $control = Config::main()->get('DEFAULT_CONTROLLER');
             }
         } else {
             $control = Config::main()->get('DEFAULT_CONTROLLER');
         }
         logMsg("DiamondMVC: routed controller to " . $control, 1, false);
         // Detect requested action, by default "main"
         if (isset($_REQUEST['action'])) {
             $action = $_REQUEST['action'];
         } else {
             $action = 'main';
         }
         $action = preg_replace('/[^A-z_]+/', '_', $action);
         logMsg("DiamondMVC: action is " . $action, 1, false);
         // Detect type of action. Currently possible: HTML, AJAX, JSON
         if (isset($_REQUEST['type'])) {
             $type = strToLower($_REQUEST['type']);
         } else {
             $type = 'html';
         }
         logMsg("DiamondMVC: request type is " . $type, 1, false);
         // Detect requested template. Ignored in JSON requests
         if (isset($_REQUEST['tpl'])) {
             $_REQUEST['tpl'] = trim($_REQUEST['tpl']);
             if (!empty($_REQUEST['tpl'])) {
                 $tpl = $_REQUEST['tpl'];
             } else {
                 $tpl = 'default';
             }
         } else {
             $tpl = 'default';
         }
         if (!file_exists(jailpath(DIAMONDMVC_ROOT . '/templates', $tpl))) {
             $tpl = 'default';
         }
         logMsg("DiamondMVC: jailed template is " . $tpl, 1, false);
         // Detect requested view
         if (isset($_REQUEST['view'])) {
             $view = $_REQUEST['view'];
         } else {
             $view = '';
         }
         logMsg("DiamondMVC: view is " . $view, 1, false);
         // The controller is the heart of the MVC system.
         logMsg("DiamondMVC: constructing controller", 1, false);
         $controller = new $control();
         // Before actually performing the action, we'll give plugins the chance to change the controller, action, view and template.
         logMsg("DiamondMVC: triggering pre-action event", 1, false);
         $this->controller = $controller;
         $this->action = $action;
         $this->view = $view;
         $this->tpl = $tpl;
         $evt = new SystemActionEvent($controller, $action, $view, $tpl);
         $this->trigger($evt);
         $contrller = $this->controller = $evt->controller;
         $action = $this->action = $evt->action;
         $view = $this->view = $evt->view;
         $tpl = $this->tpl = $evt->template;
         Profiler::endSection();
         logMsg("DiamondMVC: new controller is: Controller" . $controller->getName() . '; new action is: ' . $action . '; new view is: ' . $view . '; new type is: ' . $type, 1, false);
         Profiler::startSection('Perform action');
         $controller->action($action);
         Profiler::endSection();
         Profiler::startSection('Output');
         switch ($type) {
             // Not specially treated view type
             default:
                 // Does the view type exist in the controller?
                 if ($controller->hasView($view, $type)) {
                     logMsg("DiamondMVC: typed view {$view} ({$type}) found", 1, false);
                     $controller->getView($view, $type)->render();
                     break;
                 } else {
                     logMsg("DiamondMVC: no specific typed view found, defaulting to HTML view", 1, false);
                 }
                 // The entire website is built and sent to the client.
             // The entire website is built and sent to the client.
             case 'html':
                 logMsg("DiamondMVC: rendering HTML view", 1, false);
                 (new Template($controller, $tpl))->title(Config::main()->get('WEBSITE_TITLE'))->render($view);
                 break;
                 // TODO: AJAX request differ from JSON requests in that they make use of the client side engine to update particular parts of the web page (content, header, etc.) and request missing css and js.
             // TODO: AJAX request differ from JSON requests in that they make use of the client side engine to update particular parts of the web page (content, header, etc.) and request missing css and js.
             case 'ajax':
                 logMsg("DiamondMVC: AJAX view still needs implementation!", 1, false);
                 break;
                 // Send JSON formatted raw data. By default the result of the controller is simply encoded, but a specialized JSON view can manipulate and format data before sending it out. This is
                 // useful to remove circular references and PHP objects.
             // Send JSON formatted raw data. By default the result of the controller is simply encoded, but a specialized JSON view can manipulate and format data before sending it out. This is
             // useful to remove circular references and PHP objects.
             case 'json':
                 logMsg('DiamondMVC: hasView - ' . ($controller->hasView($view, 'json') ? 'yes' : 'no') . ' | hasTemplate - ' . ($controller->hasTemplate($view, 'json') ? 'yes' : 'no'), 1, false);
                 if ($controller->hasView($view, 'json') or $controller->hasTemplate($view, 'json')) {
                     logMsg("DiamondMVC: JSON view for " . (empty($view) ? 'default' : $view) . " found", 1, false);
                     $controller->getView($view, 'json')->read()->render();
                 } else {
                     logMsg("DiamondMVC: using generic JSON stringification on controller result", 1, false);
                     echo json_encode($controller->getResult());
                 }
                 break;
         }
         Profiler::endSection();
     } else {
         logMsg('DiamondMVC: Skipping routing', 1, false);
     }
     Profiler::endSection();
 }