Пример #1
0
 public function updateConfig()
 {
     ipRequest()->mustBePost();
     $configModel = ConfigModel::instance();
     $form = $configModel->getThemeConfigForm(ipConfig()->theme());
     $post = ipRequest()->getPost();
     $errors = $form->validate($post);
     if ($errors) {
         return JsonRpc::error('Invalid form');
     }
     $configModel = ConfigModel::instance();
     $model = Model::instance();
     $theme = $model->getTheme(ipConfig()->theme());
     if (!$theme) {
         throw new \Ip\Exception("Theme doesn't exist");
     }
     $options = $theme->getOptionsAsArray();
     $valuesToStore = array();
     foreach ($options as $option) {
         if (empty($option['name'])) {
             continue;
         }
         $field = $form->getField($option['name']);
         if (!$field) {
             continue;
         }
         switch ($option['type']) {
             case 'checkbox':
                 /**
                  * @var \Ip\Form\Field\Checkbox $field
                  */
                 $value = $field->isChecked($post, $option['name']);
                 break;
             case 'RepositoryFile':
                 $value = '';
                 if (!empty($post[$option['name']][0])) {
                     $value = $post[$option['name']][0];
                 }
                 break;
             default:
                 $value = $field->getValueAsString($post, $option['name']);
         }
         $valuesToStore[$option['name']] = $value;
     }
     $valuesToStore = ipFilter('ipDesignOptionsSave', $valuesToStore);
     foreach ($valuesToStore as $key => $value) {
         $configModel->setConfigValue(ipConfig()->theme(), $key, $value);
     }
     $lessCompiler = LessCompiler::instance();
     $lessCompiler->rebuild(ipConfig()->theme());
     \Ip\Internal\Core\Service::invalidateAssetCache();
     ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml());
     return JsonRpc::result(true);
 }
Пример #2
0
 protected function parseThemeJson($file)
 {
     if (!file_exists($file) || !is_file($file)) {
         return array();
     }
     $configJson = file_get_contents($file);
     $config = Helper::instance()->json_clean_decode($configJson, true);
     if ($config) {
         return $config;
     } else {
         return array();
     }
 }