示例#1
0
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->order = 't.order';
     $criteria->with = array('config');
     $model = ConfigGroup::model()->opened()->findAll($criteria);
     // Save
     if (isset($_POST['Config'])) {
         if (isset($_POST['Config'][request()->csrfTokenName])) {
             unset($_POST['Config'][request()->csrfTokenName]);
         }
         foreach ($_POST['Config'] as $k => $v) {
             db()->createCommand()->update('{{config}}', array('value' => $v, 'updated_at' => date('Y-m-d H:i:s')), 'param = :param', array(':param' => $k));
         }
         if (request()->isAjaxRequest) {
             echo 'ok';
             app()->end();
         }
     }
     if (isset($_POST['Reset'])) {
         $configModel = Config::model()->find('param = :param', array(':param' => $_POST['Reset']['field']));
         if ($configModel !== NULL) {
             $configModel->setAttribute('value', $configModel->default);
             $configModel->save(FALSE);
             echo $configModel->default;
         } else {
             echo 'fail';
         }
         app()->end();
     }
     $this->render('//settings/index', array('model' => $model));
 }
示例#2
0
 public function safeUp()
 {
     Yii::import('application.components.ActiveRecord');
     Yii::import('application.models.ConfigGroup');
     $groupId = ConfigGroup::model()->find('name = "Капча"');
     $this->insert('{{config}}', array('param' => 'captcha.bg.color', 'value' => '#2D1A13', 'default' => '#FFFFFF', 'label' => 'Задний фон капчи', 'group_id' => $groupId->id, 'order' => 5, 'method' => '', 'field_type' => 'textField', 'created_at' => date('Y-m-d H:i:s')));
     $this->insert('{{config}}', array('param' => 'captcha.font.color', 'value' => '#FFFFFF', 'default' => '#000000', 'label' => 'Цвет текста', 'group_id' => $groupId->id, 'order' => 5, 'method' => '', 'field_type' => 'textField', 'created_at' => date('Y-m-d H:i:s')));
     $groupId = ConfigGroup::model()->find('name = "Регистрация"');
     $this->insert('{{config}}', array('param' => 'register.multiemail', 'value' => 0, 'default' => 0, 'label' => 'Разрешить регистрировать на один Email много аккаунтов', 'group_id' => $groupId->id, 'order' => 5, 'method' => '', 'field_type' => 'dropDownList', 'created_at' => date('Y-m-d H:i:s')));
 }
示例#3
0
文件: Kurogo.php 项目: nncsang/Kurogo
 private function initSite(&$path)
 {
     includePackage('Cache');
     includePackage('Config');
     $siteConfig = new ConfigGroup();
     $saveCache = true;
     // Load main configuration file
     $kurogoConfig = ConfigFile::factory('kurogo', 'project', ConfigFile::OPTION_IGNORE_MODE | ConfigFile::OPTION_IGNORE_LOCAL);
     $siteConfig->addConfig($kurogoConfig);
     define('CONFIG_MODE', $siteConfig->getVar('CONFIG_MODE', 'kurogo'));
     Kurogo::log(LOG_DEBUG, "Setting config mode to " . (CONFIG_MODE ? CONFIG_MODE : '<empty>'), 'config');
     define('CONFIG_IGNORE_LOCAL', $siteConfig->getVar('CONFIG_IGNORE_LOCAL', 'kurogo'));
     if ($cacheClass = $siteConfig->getOptionalVar('CACHE_CLASS', '', 'cache')) {
         $this->cacher = KurogoMemoryCache::factory($cacheClass, $siteConfig->getOptionalSection('cache'));
     }
     //multi site currently only works with a url base of root "/"
     if ($siteConfig->getOptionalVar('MULTI_SITE', false, 'kurogo')) {
         // in scripts you can pass the site name to Kurogo::initialize()
         if (PHP_SAPI == 'cli') {
             $site = strlen($path) > 0 ? $path : $siteConfig->getVar('DEFAULT_SITE');
             $siteDir = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
             if (!file_exists(realpath($siteDir))) {
                 die("FATAL ERROR: Site Directory {$siteDir} not found for site {$path}");
             }
         } else {
             $paths = explode("/", $path);
             // this is url
             $sites = array();
             $siteDir = '';
             if (count($paths) > 1) {
                 $site = $paths[1];
                 if ($sites = $siteConfig->getOptionalVar('ACTIVE_SITES', array(), 'kurogo')) {
                     //see if the site is in the list of available sites
                     if (in_array($site, $sites)) {
                         $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
                         if (($siteDir = realpath($testPath)) && file_exists($siteDir)) {
                             $urlBase = '/' . $site . '/';
                             // this is a url
                         }
                     }
                 } elseif (self::isValidSiteName($site)) {
                     $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
                     if (($siteDir = realpath($testPath)) && file_exists($siteDir)) {
                         $urlBase = '/' . $site . '/';
                         // this is a url
                     }
                 }
             }
             if (!$siteDir) {
                 $site = $siteConfig->getVar('DEFAULT_SITE');
                 array_splice($paths, 1, 1, array($site, $paths[1]));
                 $url = implode("/", $paths);
                 Kurogo::redirectToURL($url, Kurogo::REDIRECT_PERMANENT);
             }
         }
         define('SITE_NAME', $site);
     } else {
         //make sure active site is set
         if (!($site = $siteConfig->getVar('ACTIVE_SITE'))) {
             die("FATAL ERROR: ACTIVE_SITE not set");
         }
         // make sure site_dir is set and is a valid path
         // Do not call realpath_exists here because until SITE_DIR define is set
         // it will not allow files and directories outside ROOT_DIR
         if (!($siteDir = $siteConfig->getVar('SITE_DIR')) || !(($siteDir = realpath($siteDir)) && file_exists($siteDir))) {
             die("FATAL ERROR: Site Directory " . $siteConfig->getVar('SITE_DIR') . " not found for site " . $site);
         }
         define('SITE_NAME', $site);
         if (PHP_SAPI != 'cli') {
             //
             // Get URL base
             //
             if ($urlBase = $siteConfig->getOptionalVar('URL_BASE', '', 'kurogo')) {
                 $urlBase = rtrim($urlBase, '/') . '/';
             } elseif ($urlBase = Kurogo::getCache('URL_BASE')) {
                 //@TODO this won't work yet because the cache hasn't initialized
                 $urlBase = rtrim($urlBase, '/') . '/';
                 $saveCache = false;
             } else {
                 //extract the path parts from the url
                 $pathParts = array_values(array_filter(explode("/", $_SERVER['REQUEST_URI'])));
                 $testPath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR;
                 $urlBase = '/';
                 //once the path equals the WEBROOT_DIR we've found the base. This only works with symlinks
                 if (realpath($testPath) != WEBROOT_DIR) {
                     foreach ($pathParts as $dir) {
                         $test = $testPath . $dir . DIRECTORY_SEPARATOR;
                         if (file_exists(realpath($test))) {
                             $testPath = $test;
                             $urlBase .= $dir . '/';
                             if (realpath($test) == WEBROOT_DIR) {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (PHP_SAPI == 'cli') {
         define('URL_BASE', null);
     } else {
         if (!isset($urlBase)) {
             throw new KurogoConfigurationException("URL base not set. Please report the configuration to see why this happened");
         }
         define('URL_BASE', $urlBase);
         if ($saveCache) {
             Kurogo::setCache('URL_BASE', $urlBase);
         }
         Kurogo::log(LOG_DEBUG, "Setting site to {$site} with a base of {$urlBase}", 'kurogo');
         // Strips out the leading part of the url for sites where
         // the base is not located at the document root, ie.. /mobile or /m
         // Also strips off the leading slash (needed by device debug below)
         if (isset($path)) {
             // Strip the URL_BASE off the path
             $baseLen = strlen(URL_BASE);
             if ($baseLen && strpos($path, URL_BASE) === 0) {
                 $path = substr($path, $baseLen);
             }
         }
     }
     // Set up defines relative to SITE_DIR
     define('SITE_DIR', $siteDir);
     //already been realpath'd
     define('SITE_LIB_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'lib');
     define('SITE_APP_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app');
     define('SITE_MODULES_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'modules');
     define('DATA_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'data');
     define('CACHE_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'cache');
     define('LOG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'logs');
     define('SITE_CONFIG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config');
     define('SITE_DISABLED_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config_disabled');
     //load in the site config file (required);
     $config = ConfigFile::factory('site', 'site');
     $siteConfig->addConfig($config);
     // attempt to load site key
     $siteKey = $siteConfig->getOptionalVar('SITE_KEY', md5($siteDir));
     define('SITE_KEY', $siteKey);
     if ($siteConfig->getOptionalVar('SITE_DISABLED')) {
         die("FATAL ERROR: Site disabled");
     }
     // Set up theme define
     if (!($theme = $siteConfig->getVar('ACTIVE_THEME'))) {
         die("FATAL ERROR: ACTIVE_THEME not set");
     }
     Kurogo::log(LOG_DEBUG, "Setting theme to {$theme}", 'kurogo');
     define('THEME_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme);
     $this->siteConfig = $siteConfig;
 }