Пример #1
0
 private static function prepare()
 {
     define('WM', '');
     session_set_cookie_params(0);
     session_name('Watermelon');
     session_start();
     session_regenerate_id();
     ob_start();
     header('Content-Type: text/html; charset=UTF-8');
     define('WM_StartTime', microtime());
     define('WM_StartMemory', memory_get_usage());
     set_include_path('.');
     mb_internal_encoding('UTF-8');
     // fixing "magic" quotes
     if (get_magic_quotes_gpc()) {
         function stripslashes_deep($value)
         {
             $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
             return $value;
         }
         $_POST = array_map('stripslashes_deep', $_POST);
         $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
         $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
     }
     // paths
     $basePath = str_replace('\\', '/', realpath(dirname(__FILE__) . '/../')) . '/';
     define('SystemPath', $basePath);
     define('CorePath', SystemPath . 'core/');
     define('BundlesPath', SystemPath . 'bundles/');
     define('CachePath', SystemPath . 'cache/');
     // loading config file
     include $basePath . 'config.php';
     // checking if installer
     if (!isset($dbHost)) {
         self::$appType = self::Installer;
         $installer = true;
         error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
         define('WM_Debug', '');
     } else {
         // setting proper error reporting mode and debug constant
         switch ($debugLevel) {
             case 0:
             default:
                 error_reporting(0);
                 break;
             case 1:
                 error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
                 define('WM_Debug', '');
                 break;
             case 2:
                 error_reporting(E_ALL);
                 define('WM_Debug', '');
                 break;
         }
     }
     // creating messages array in session
     if (!is_array($_SESSION['wmelon.messages'])) {
         $_SESSION['wmelon.messages'] = array();
     }
     // URL-s
     $requestURL = self::getRequestURL();
     list($segments, $format, $params) = self::parseRequestURL($requestURL);
     if (self::$appType != self::Installer) {
         if ($segments[0] == 'admin') {
             self::$appType = self::Admin;
             array_shift($segments);
         } else {
             self::$appType = self::Site;
         }
     }
     self::$requestURL = $requestURL;
     self::$segments = $segments;
     self::$format = $format;
     self::$params = $params;
     // including libraries
     $libs = array('helpers/helpers.php', 'DB/DB.php', 'Loader.php', 'Config.php', 'Exception.php', 'headers/Controller.php', 'headers/Skin.php', 'headers/View.php', 'headers/Model.php', 'headers/Extension.php');
     foreach ($libs as $file) {
         include CorePath . $file;
     }
     // and that's it for the installer
     if ($installer) {
         return;
     }
     // MySQL connection
     DB::connect($dbHost, $dbName, $dbUser, $dbPass, $dbPrefix);
     // getting main configuration array from Config
     $w = Config::get('wmelon.wmelon');
     self::$config =& $w;
     // setting constants
     define('SiteURL', $w->siteURL);
     define('AdminURL', $w->siteURL . 'admin/');
     define('SystemURL', $w->systemURL);
     define('BundlesURL', SystemURL . 'bundles/');
     define('CacheURL', SystemURL . 'cache/');
     if (self::$appType == self::Admin) {
         define('SkinPath', SystemPath . 'core/ACPSkin/');
         define('SkinURL', SystemURL . 'core/ACPSkin/');
         define('CurrURL', AdminURL);
     } else {
         define('SkinPath', BundlesPath . $w->skin . '_skin/');
         define('SkinURL', BundlesURL . $w->skin . '_skin/');
         define('CurrURL', SiteURL);
     }
 }