check_compatibility(); $this->define_constants(); // Alle default libs inladen $this->load_default_libs(); //Registry inladen $registry = Registry::getInstance(); //versie defineren include_once(Loader::get_location("default/config/version.php")); $this->set_paths(); $this->set_settings(); $this->start_session(); //Router inladen $registry->router = new Router(); // Debug engine $registry->debug = new Debug(); // Database engine inladen include_once(Loader::get_location("default/config/database.php")); $registry->database = new Database(DATABASE_ADDRESS,DATABASE_DATABASE,DATABASE_USERNAME,DATABASE_PASSWORD); // Rights $registry->rights = new Rights(); // Language $registry->language = new Language(); // User inladen $registry->user = new User(); if($registry->user->id_user) { $registry->user_settings = new UserSettings($registry->user->id_user); } // Event inladen $this->load_plugins(); // Set alvast de datetimezone vast (voorkomt warnings by gebruik van timestamps) date_default_timezone_set(TIMEZONE); $this->start_error_handling(); // Registreer welke gebruiker dit is $this->login(); } /** * Kijkt in custom en system dir op zoek naar default libraries * Alle gevonden default libraries worden ingeladen * */ private final function load_default_libs() { $custom_lib_dir = SITE_PATH."custom".DIRSEP."default".DIRSEP."lib".DIRSEP; $default_lib_dir = SITE_PATH."system".DIRSEP."default".DIRSEP."lib".DIRSEP; $default_libs = array(); // Loader moet altijd eerst ingeladen worden! if(file_exists($custom_lib_dir."loader.php")) { require_once($custom_lib_dir."loader.php"); }else { require_once($default_lib_dir."loader.php"); } if (is_dir($custom_lib_dir)) { if ($dh = opendir($custom_lib_dir)) { while(($file = readdir($dh)) !== false) { if(basename($file)!="." && basename($file)!=".." && !is_dir($custom_lib_dir.$file) ) { $default_libs[basename($file)] = $custom_lib_dir.$file; } } closedir($dh); } } if (is_dir($default_lib_dir)) { if ($dh = opendir($default_lib_dir)) { while(($file = readdir($dh)) !== false) { if($file!="." && $file!=".." && !is_dir($default_lib_dir.$file)) { if(!in_array($file,$default_libs)) { $default_libs[basename($file)] = $default_lib_dir.$file; } } } closedir($dh); } } foreach($default_libs as $file=>$filelocation) { include_once($filelocation); } } /** * Start sessie indien nodig en stelt $_ARGS in als het een systeem user betreft * */ private function start_session() { // Start sessie etc. if(!$this->is_cli_access() ) { session_name(md5($_SERVER["PHP_SELF"])); ini_set("session.gc_maxlifetime","14400"); //$sessdir = ini_get('session.save_path')."/"."my_sessions"; //if(!is_dir($sessdir)) {mkdir($sessdir, 0777);} //ini_set('session.save_path', $sessdir); if($_GET[session_name()]) { session_id($_GET[session_name()]); } session_start(); if($_GET['id_language']) { $_SESSION['language_id'] = (int) $_GET['id_language']; } $registry->cli_access = false; }else { // Directe benadering via commandline $registry->cli_access = true; // Argumenten van de cli worden in $_ARG geplaatst $this->_args = array(); foreach($_SERVER['argv'] as $arg) { if(ereg('--([^=]+)=(.*)',$arg,$reg)) { $this->_args[$reg[1]] = $reg[2]; }elseif(ereg('-([a-zA-Z0-9])',$arg,$reg)) { $this->_args[$reg[1]] = 'true'; } } $registry->_args = $this->_args; } } /** * Geeft aan of de user via de commandline binnenkomt * * @return boolean */ final public function is_cli_access() { if(!$_SERVER['SHELL'] && php_sapi_name()!="cli") { return false; }else { return true; } } /** * Als er geen commandline request is dan wordt login procedure opgestart * */ final function login() { $registry = Registry::getInstance(); if(!$this->is_cli_access()) { // Inloggen? if($_GET['hash'] && $_GET['id']) { $registry->user->login_hash($_GET['hash'],$_GET['id']); }else if($_POST['login']) { $registry->user->login($_POST['username'],$_POST['password']); if($registry->user->is_loggedin()) { Loader::load("default/models/notifications.php"); $notification_lib = new Notifications; $notification_lib->delete_all(); $me = $registry->user->me(); if(!$registry->rights->check_role("superuser")) { $message = $registry->language->get_text("login_notification"); $message = str_replace("%username%",$me['realname'],$message); $notification_lib->add($message,10,"login","*",array($me['id_user'])); } } } header( 'Content-type: text/html; charset=UTF-8' ); } } /** * Start OptiManage * */ final function run() { Timer::getInstance()->time("core->run()","start"); $registry = Registry::getInstance(); if(!$this->is_cli_access()) { $registry->router->delegate(); }else { $registry->router->is_cli_access = true; $registry->router->delegate($this->_args['route']); } Timer::getInstance()->time("core->run()","eind"); if($this->is_cli_access()) { // Commandline interface na 1 command uitloggen $registry->user->logout(); } if(is_arrix() && $registry->rights->accredit("debug")) { //Timer::getInstance()->render(); } // Afsluiten applicatie $registry->database->close_connention(); if($this->compressor) { $this->compressor->finish(); } } /** * Load plugins */ private function load_plugins() { $registry = Registry::getInstance(); $registry->event = new Event(); } /** * Controleer of optimanage kan draaien * Controleer b.v. of php versie 5.1 of hoger is * */ function check_compatibility() { // Controleer versie PHP if (version_compare(phpversion(), '5.1.0', '<') == true) { die ('PHP5.1 Only'); } } /** * Stel systeem constanten in * */ function define_constants() { define('DIRSEP', DIRECTORY_SEPARATOR); define('NULL_ARG', 'DUMMY_ARGUMENT'); define('SITE_PATH', $this->get_root_path()); } final function get_root_path() { $root_path = dirname($_SERVER['SCRIPT_FILENAME']).DIRSEP; return $root_path; } static function path_back($path, $steps) { $path = trim($path, DIRSEP); $path_parts = explode(DIRSEP,$path); $return = ""; for ($i=0;$i<$steps;$i++) { array_pop($path_parts); } foreach ($path_parts as $part) { $return .= $part.DIRSEP; } $return = trim($return , DIRSEP); $return = str_replace(DIRSEP.DIRSEP,DIRSEP,$return); $return = DIRSEP.$return.DIRSEP; return $return; } static function url_back($url, $steps) { $url = str_ireplace("http://","",$url); $url_parts = explode("/",$url); $return = ""; for($i=0;$i<$steps+1;$i++) { array_pop($url_parts); } foreach($url_parts as $part) { $return .= $part."/"; } $return = trim($return , "/"); $return = str_replace("//","/",$return); $return = "http://".$return."/"; return $return; } final function set_paths() { $registry = Registry::getInstance(); $registry->root_path = $this->get_root_path(); $registry->root_url = "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/"; $registry->template_url = $registry->root_url."templates/"; $registry->template_path = $registry->root_path."templates"; $registry->frontend_url = $registry->root_url; $registry->frontend_files_path = $registry->root_path."files".DIRSEP; $registry->frontend_files_url = $registry->frontend_url."files/"; include_once(Loader::get_location("default/config/paths.php")); } final function set_settings() { include_once(Loader::get_location("default/config/settings.php")); $registry = Registry::getInstance(); $registry->settings = $settings; } function start_compressor() { return false; // Meer info op http://aciddrop.com/php-speedy/ PHP Speedy Loader::load("default/lib/compressor/compressor.php"); Loader::load("default/lib/compressor/view.php"); include_once(Loader::get_location("default/config/compressor.php")); //Con. the view library $view = new compressor_view(); //Con. the js min library if(substr(phpversion(),0,1) == 5) { Loader::load("default/lib/compressor/jsmin.php"); $jsmin = new JSMin(null); } //Con. the compression controller $this->compressor = new compressor(array( 'view'=>$view, 'options'=>$compress_options, 'jsmin'=>$jsmin )); } /** * Error handler initialiseren */ function start_error_handling() { error_reporting(E_ALL); include_once(Loader::get_location("default/lib/error_handler.php")); set_error_handler("error_handler"); } static final function fast_load_file($file) { return file_get_contents($file); } } ?>