Ejemplo n.º 1
0
 /**
  * Initialize the system and load config options
  * @return boolean
  */
 public static function init()
 {
     $config =& self::$config;
     $file = self::$configFile ? self::$configFile : $config['base.path'] . 'gateway.config.php';
     // load config file if available.
     $rt = is_file($file) ? include_once $file : false;
     // setup defaults
     $base = $config['base.path'];
     if (empty($config['site.host'])) {
         $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '';
         $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
         if ($host) {
             $host = explode(':', $host);
             $host = trim($host[0]);
             $schema = isset($_SERVER['HTTP_HOST']) && strtolower($_SERVER['HTTP_HOST']) == 'on' || $port == 443 ? 'https://' : 'http://';
             $config['site.host'] = $schema . $host . ($port == 80 || $port == 443 ? '' : ':' . $port);
         }
     }
     if (empty($config['site.path']) || empty($config['site.url'])) {
         // auto detect site path & url
         $sn = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : '';
         $sf = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';
         $ps = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
         if ($sn && $ps != $sn) {
             $su = $sn;
         } else {
             $su = $ps;
         }
         $su = str_replace('\\', '/', dirname($su));
         // fix issue #10 - bug with "\" path on windows PCs
         $sf = str_replace('\\', '/', dirname($sf));
         $config['site.url'] = $su != '/' ? $su . '/' : './';
         $config['site.path'] = $sf != '/' ? $sf . '/' : './';
     }
     if (empty($config['raxan.path']) || empty($config['raxan.url'])) {
         // auto detect raxan path & url
         $pth = implode('/', array_slice(explode('/', $base), 0, -2));
         $config['raxan.path'] = $pth . '/';
         $url = Raxan::mapSitePathToUrl($pth);
         $config['raxan.url'] = $url ? $url . '/' : './raxan/';
     }
     if (empty($config['cache.path'])) {
         $config['cache.path'] = $config['raxan.path'] . 'cache/';
     }
     if (empty($config['locale.path'])) {
         $config['locale.path'] = $base . 'shared/locale/';
     }
     if (empty($config['views.path'])) {
         $config['views.path'] = $config['site.path'] . 'views/';
     }
     if (empty($config['plugins.path'])) {
         $config['plugins.path'] = $config['raxan.path'] . 'plugins/';
     }
     if (empty($config['widgets.path'])) {
         $config['widgets.path'] = $config['raxan.path'] . 'ui/widgets/';
     }
     self::$isDebug = $config['debug'];
     self::$isLogging = $config['log.enable'];
     // setup post back token
     if (isset($_COOKIE['_ptok'])) {
         self::$postBackToken = $_COOKIE['_ptok'];
     } else {
         // generate random token
         $tok = substr(str_shuffle('$*!:;'), -2) . rand(1000000, 999999999);
         for ($i = 0; $i < 7; $i++) {
             $tok .= chr($i % 2 ? rand(64, 90) : rand(97, 122));
         }
         self::$postBackToken = str_shuffle($tok);
         if (!defined('STDIN')) {
             setcookie('_ptok', self::$postBackToken);
         }
         // send cookie if not in CLI mode
     }
     // set timezone
     if ($config['site.timezone']) {
         date_default_timezone_set($config['site.timezone']);
     }
     self::$isInit = true;
     // preload widgets from $config
     if ($config['preload.widgets']) {
         $ui = explode(',', $config['preload.widgets']);
         foreach ($ui as $f) {
             $f = trim($f);
             // fix issue #9
             $extrn = substr($f, -4) == '.php';
             self::loadWidget($f, $extrn);
         }
     }
     // preload plugins from $config
     if ($config['preload.plugins']) {
         $pl = explode(',', $config['preload.plugins']);
         foreach ($pl as $f) {
             $f = trim($f);
             // fix issue #9
             $extrn = substr($f, -4) == '.php';
             self::loadPlugin($f, $extrn);
         }
     }
     // trigger system_init
     self::triggerSysEvent('system_init');
     return $rt;
 }