示例#1
0
 public static function readConfigFile($path)
 {
     require_once $path;
     return Options::filter(get_defined_vars());
 }
示例#2
0
 public static function init()
 {
     // Displays all errors
     if (DEBUG) {
         ini_set('display_errors', 'On');
         ini_set('display_startup_errors', 'On');
         ini_set('error_reporting', -1);
     }
     // Vendor libs by some great guys
     require_once PATH . '/app/Vendor/phpass.php';
     require_once PATH . '/app/Vendor/idiorm.php';
     require_once PATH . '/app/Vendor/Identicon/autoload.php';
     // Connection to mysql database
     require_once PATH . '/app/Core/config.php';
     // Configuration file
     $cfg['dsn'] = "mysql:dbname={$cfg['database']};host={$cfg['hostname']}";
     ORM::configure($cfg['dsn']);
     ORM::configure('username', $cfg['username']);
     ORM::configure('password', $cfg['password']);
     ORM::configure('return_result_sets', true);
     if (DEBUG) {
         ORM::configure('logging', true);
     }
     ORM::configure('caching', true);
     ORM::configure('caching_auto_clear', true);
     ORM::configure('id_column_overrides', array('session' => 'sid'));
     // Configuration data
     self::$g = Options::filter('pairs');
     self::$g['logged'] = User::filter('byLogged');
     define('LOGGED', self::$g['logged'] ? self::$g['logged']->id : 0);
     define('ADMIN', LOGGED && '1' === self::$g['logged']->admin);
     define('UPLOAD_PATH', PATH . '/uploads/');
     // View library init
     View::init();
     // Selects parameter from query
     $param = !empty($_GET['p']) ? $_GET['p'] : '';
     $param = explode('/', $param, 3);
     // Splits parameter
     // Checks parameters for inadequate behaviour
     foreach ($param as &$v) {
         if (!Validate::slug($v)) {
             $v = '';
         }
     }
     // Checks the existence of controller
     $controller = 'home';
     if (!empty($param[0])) {
         if (ctype_lower($param[0]) && file_exists(PATH . '/app/Controller/' . $param[0] . '.php')) {
             $controller = $param[0];
         } elseif ($param[0] === 'u') {
             $controller = 'profile';
         } elseif (ctype_digit($param[0])) {
             $controller = 'playlist';
         }
     }
     // Sets the rest of parameters for global use
     define('FIRST_PARAMETER', isset($param[0]) ? $param[0] : '');
     define('SECOND_PARAMETER', isset($param[1]) ? $param[1] : '');
     define('THIRD_PARAMETER', isset($param[2]) ? $param[2] : '');
     // Initializes the controller
     require_once PATH . '/app/Controller/' . $controller . '.php';
     $controller = new Controller();
 }