示例#1
0
 static function getSettings()
 {
     global $enabled_modules;
     $settings = false;
     // if already fetched, return it straight
     if (isset(self::$settings)) {
         return self::$settings;
     }
     // if table not exist, return null
     if (in_array('database', $enabled_modules)) {
         self::createTableIfNotExist();
         global $mysqli;
         // if not cached in db or in dev, load it
         $settings = self::findByName('system');
     }
     if (!$settings || ENV == 'dev') {
         require_once MODULESROOT . DS . 'core' . DS . 'includes' . DS . 'libraries' . DS . 'spyc' . DS . 'spyc.php';
         $settings = array();
         // load core module settings first
         $module_dir = MODULESROOT . DS . 'core';
         $settings = array_merge_recursive(Spyc::YAMLLoad($module_dir . DS . 'settings.yml'), $settings);
         $settings = array_merge_recursive(Spyc::YAMLLoad($module_dir . DS . 'routing.yml'), $settings);
         $settings = array_merge_recursive(Spyc::YAMLLoad($module_dir . DS . 'role.yml'), $settings);
         // loop through modules and merge all settings
         if ($handle = opendir(MODULESROOT)) {
             while (false !== ($entry = readdir($handle))) {
                 // skip any file starting with "."
                 if (preg_match('/^\\./', $entry)) {
                     continue;
                 }
                 // loop over the module folder
                 $module_dir = MODULESROOT . DS . $entry;
                 if (is_dir($module_dir) && in_array($entry, $enabled_modules) && $entry != 'core') {
                     if (is_file($module_dir . DS . 'settings.yml')) {
                         $settings = array_merge_recursive(Spyc::YAMLLoad($module_dir . DS . 'settings.yml'), $settings);
                     }
                     if (is_file($module_dir . DS . 'routing.yml')) {
                         $settings = array_merge_recursive(Spyc::YAMLLoad($module_dir . DS . 'routing.yml'), $settings);
                     }
                     if (is_file($module_dir . DS . 'role.yml')) {
                         $settings = array_merge_recursive(Spyc::YAMLLoad($module_dir . DS . 'role.yml'), $settings);
                     }
                 }
             }
         }
         // store in db
         if (in_array('database', $enabled_modules) && ENV != 'dev') {
             $var = new Vars();
             $var->setName('system');
             $var->setValue(serialize($settings));
             $var->save();
             self::$settings = $settings;
         }
         return $settings;
     } else {
         self::$settings = unserialize($settings->getValue());
         return self::$settings;
     }
 }
示例#2
0
<?php

$maintenance = Vars::findByName('maintenance');
$maintenance = $maintenance ? $maintenance->getValue() : 0;
// handle form submission
if (isset($_POST['submit'])) {
    $switch = isset($_POST['switch']) && $_POST['switch'] == 1 ? 1 : 0;
    $var = new Vars();
    $var->setName('maintenance');
    $var->setValue($switch);
    $var->save();
    Message::register(new Message(Message::SUCCESS, i18n(array('en' => 'Maintenance mode updated', 'zh' => '系统维护模式已更新'))));
    HTML::forward('admin/maintenance');
    exit;
}
// presentation
$html = new HTML();
$html->renderOut('core/backend/html_header', array('title' => i18n(array('en' => 'Maintenance mode', 'zh' => '系统维护设置'))), true);
$html->output('<div id="wrapper">');
$html->renderOut('core/backend/header');
$html->renderOut('core/backend/maintenance', array('maintenance' => $maintenance));
$html->output('</div>');
$html->renderOut('core/backend/html_footer');
exit;