예제 #1
0
 public static function get($key = null, $subkey = null)
 {
     $config = Config::getInstance()->config['database'];
     // If 'use_db_settings' = true, get settings from Database
     if ($config['use_db'] === true && $config['use_db_settings'] === true) {
         $db = new Database();
         $settings = $db->select("SELECT data FROM {$config['table_db_settings']} WHERE 1");
         // Add settings to the global config
         Config::getInstance()->combineSettings(array('settings' => json_decode($settings[0]['data'], true)));
     }
     foreach (Config::getInstance()->config['settings']['modules'] as $module) {
         if (is_file('App/' . $module . '/config/config.php')) {
             $config = (require 'App/' . $module . '/config/config.php');
             Config::getInstance()->combineSettings(array('settings' => $config));
         }
     }
     if ($key) {
         if (array_key_exists($key, Config::getInstance()->config)) {
             if ($subkey) {
                 if (array_key_exists($subkey, Config::getInstance()->config[$key])) {
                     return Config::getInstance()->config[$key][$subkey];
                 } else {
                     return false;
                 }
             } else {
                 return Config::getInstance()->config[$key];
             }
         } else {
             return null;
         }
     } else {
         return Config::getInstance()->config;
     }
 }
예제 #2
0
 public static function db_backup()
 {
     $config = Config::get();
     $destination = is_dir($config['backup']['path']) ? $config['backup']['path'] : die("Directory " . $config['backup']['path'] . " not exist");
     if ($config['database']['use_db']) {
         $db_config = (require 'app/config/database.php');
         if ($db_config['default'] == 'mysql') {
             $db = new Database();
             $file = $db->dump('db_backup');
         } elseif ($db_config['default'] == 'sqlite') {
             $file = $config['database']['sqlite_file'];
         }
         $zip = new Zip();
         $zip->setArchiveName($destination . '/' . 'db_backup_' . date('d.m.Y'));
         $path = pathinfo($file);
         $zip->setPath($path['dirname']);
         $zip->zip();
         if ($db_config['default'] == 'mysql') {
             unlink($file);
             rmdir('db_backup');
         }
     }
 }
예제 #3
0
 public static function readSessionFromDb($key = null)
 {
     $config = Config::get('session');
     if (!$key) {
         $key = $config['cookie_default_key'];
     }
     if ($config['session_use_db'] === true) {
         $session_key = !is_null(self::getSession($key)) ? self::getSession($key) : self::getCookie($key);
         if ($session_key) {
             $db = new Database();
             $result = $db->select("SELECT user_data FROM {$config['session_db_table']} WHERE session_key='{$session_key}'");
             if (!empty($result)) {
                 $user_data = unserialize($result[0]['user_data']);
                 return $user_data;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
     return null;
 }