Пример #1
0
 public function saveParameters($moduleGroup = null, $moduleName = null, $allowCreateLanguage = true)
 {
     global $parametersMod;
     $this->languageId = Db::getLanguageId($this->cachedLanguage['code']);
     if ($this->languageId === false) {
         if ($allowCreateLanguage) {
             $this->languageId = Db::insertLanguage($this->cachedLanguage);
             \Modules\standard\languages\Db::createEmptyTranslations($this->languageId, 'par_lang');
         } else {
             $siteLanguages = \Modules\standard\languages\Db::getLanguages();
             $this->languageId = $siteLanguages[0]['id'];
         }
     }
     foreach ($this->parameterGroups as $groupKey => $group) {
         if ($moduleGroup == null || $moduleName == null || $moduleGroup == $group->moduleGroupName && $moduleName == $group->moduleName) {
             if ($parametersMod->getValue('standard', 'configuration', 'advanced_options', 'administrator_interface_language') == $this->languageCode) {
                 //set module group translation
                 $tmpGroup = Db::getGroup($group->moduleGroupName);
                 if ($tmpGroup && $group->moduleGroupTranslation) {
                     Db::updateModuleGroupTranslation($tmpGroup['id'], $group->moduleGroupTranslation);
                 }
                 //set module translation
                 $tmpModule = \Db::getModule(null, $group->moduleGroupName, $group->moduleName);
                 if ($tmpModule && $group->moduleTranslation) {
                     Db::updateModuleTranslation($tmpModule['id'], $group->moduleTranslation);
                 }
             }
             $group->saveToDb($this->languageId);
         }
     }
 }
Пример #2
0
 public static function saveParameters($file, $ignoreLanguage = false)
 {
     require_once MODULE_DIR . 'standard/languages/db.php';
     //require_once(MODULE_DIR."standard/seo/db.php");
     global $parametersMod;
     global $site;
     require $file;
     $answer = '';
     //get languageId
     $languageId = null;
     if ($ignoreLanguage || !isset($languageCode)) {
         $languageId = $site->currentLanguage['id'];
     } else {
         $languages = \Modules\standard\languages\db::getLanguages();
         foreach ($languages as $key => $language) {
             if ($language['code'] == $languageCode) {
                 $languageId = $language['id'];
             }
         }
         if ($languageId === null) {
             if (!isset($languageShort)) {
                 $languageShort = $languageCode;
             }
             if (!isset($languageLong)) {
                 $languageLong = $languageCode;
             }
             if (!isset($languageUrl)) {
                 $languageUrl = $languageCode;
             }
             $parameter = array();
             $rowNumber = -1.0E+17;
             $languages = \Modules\standard\languages\Db::getLanguages();
             foreach ($languages as $language) {
                 if ($language['row_number'] >= $rowNumber) {
                     $rowNumber = $language['row_number'] + 1;
                 }
             }
             $languageId = Db::insertLanguage($languageCode, $languageShort, $languageLong, $languageUrl, 0, $rowNumber);
             \Modules\standard\languages\Db::createRootZoneElement($languageId);
             \Modules\standard\languages\Db::createEmptyTranslations($languageId, 'par_lang');
         }
     }
     if (isset($parameterGroupTitle)) {
         foreach ($parameterGroupTitle as $groupName => $group) {
             foreach ($group as $moduleName => $module) {
                 foreach ($module as $parameterGroupName => $value) {
                     $tmpModule = \Db::getModule(null, $groupName, $moduleName);
                     if ($tmpModule) {
                         $tmpParameterGroup = Db::getParameterGroup($tmpModule['id'], $parameterGroupName);
                         if ($tmpParameterGroup) {
                             Db::setParameterGroupTitle($tmpParameterGroup['id'], $value);
                         } else {
                             if (isset($parameterGroupAdmin[$groupName][$moduleName][$parameterGroupName])) {
                                 $admin = $parameterGroupAdmin[$groupName][$moduleName][$parameterGroupName];
                             } else {
                                 $admin = 1;
                             }
                             $tmpParameterGroup = Db::createParameterGroup($tmpModule['id'], $parameterGroupName, $value, $admin);
                         }
                     }
                 }
             }
         }
     }
     if (isset($parameterValue)) {
         foreach ($parameterValue as $groupName => $moduleGroup) {
             foreach ($moduleGroup as $moduleName => $module) {
                 $tmpModule = \Db::getModule(null, $groupName, $moduleName);
                 if ($tmpModule) {
                     foreach ($module as $parameterGroupName => $parameterGroup) {
                         $tmpParameterGroup = Db::getParameterGroup($tmpModule['id'], $parameterGroupName);
                         if (!$tmpParameterGroup) {
                             if (isset($parameterGroupAdmin[$groupName][$moduleName][$parameterGroupName])) {
                                 $admin = $parameterGroupAdmin[$groupName][$moduleName][$parameterGroupName];
                             } else {
                                 $admin = 1;
                             }
                             $tmpParameterGroup['id'] = Db::createParameterGroup($tmpModule['id'], $parameterGroupName, $parameterGroupName, $admin);
                         }
                         foreach ($parameterGroup as $parameterName => $value) {
                             if (!$parametersMod->exist($groupName, $moduleName, $parameterGroupName, $parameterName)) {
                                 $parameter = array();
                                 $parameter['name'] = $parameterName;
                                 if (isset($parameterAdmin[$groupName][$moduleName][$parameterGroupName][$parameterName])) {
                                     $parameter['admin'] = $parameterAdmin[$groupName][$moduleName][$parameterGroupName][$parameterName];
                                 } else {
                                     $parameter['admin'] = 1;
                                 }
                                 if (isset($parameterTitle[$groupName][$moduleName][$parameterGroupName][$parameterName])) {
                                     $parameter['translation'] = $parameterTitle[$groupName][$moduleName][$parameterGroupName][$parameterName];
                                 } else {
                                     $parameter['translation'] = $parameterName;
                                 }
                                 if (isset($parameterType[$groupName][$moduleName][$parameterGroupName][$parameterName])) {
                                     $parameter['type'] = $parameterType[$groupName][$moduleName][$parameterGroupName][$parameterName];
                                 } else {
                                     $parameter['type'] = 'string';
                                 }
                                 $parameter['value'] = str_replace("\r\n", "\n", $value);
                                 //user can edit parameters file and change line endings. So, we convert them back
                                 $parameter['value'] = str_replace("\r", "\n", $parameter['value']);
                                 Db::insertParameter($tmpParameterGroup['id'], $parameter);
                             } else {
                                 $value = str_replace("\r\n", "\n", $value);
                                 //user can edit parameters file and change line endings. So, we convert them back
                                 $value = str_replace("\r", "\n", $value);
                                 $parametersMod->setValue($groupName, $moduleName, $parameterGroupName, $parameterName, $value, $languageId);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($parameterTitle)) {
         foreach ($parameterTitle as $moduleGroupName => $moduleGroup) {
             foreach ($moduleGroup as $moduleName => $module) {
                 foreach ($module as $parameterGroupName => $parameterGroup) {
                     foreach ($parameterGroup as $parameterName => $title) {
                         Db::setParameterTitle($moduleGroupName, $moduleName, $parameterGroupName, $parameterName, $title);
                     }
                 }
             }
         }
     }
     if (isset($moduleGroupTitle)) {
         foreach ($moduleGroupTitle as $groupName => $value) {
             Db::setModuleGroupTitle($groupName, $value);
         }
     }
     if (isset($moduleTitle)) {
         foreach ($moduleTitle as $groupName => $group) {
             foreach ($group as $moduleName => $value) {
                 Db::setModuleTitle($groupName, $moduleName, $value);
             }
         }
     }
     return $answer;
 }