예제 #1
0
 /**
  * Installs the selected languages.
  */
 protected function installLanguage()
 {
     $this->initDB();
     foreach (self::$selectedLanguages as $language) {
         // get language.xml file name
         $filename = TMP_DIR . TMP_FILE_PREFIX . $language . '.xml';
         // check the file
         if (!file_exists($filename)) {
             throw new SystemException("unable to find language file '" . $filename . "'", 11002);
         }
         // open the file
         $xml = new XML($filename);
         // import xml
         LanguageEditor::importFromXML($xml, 0);
     }
     // set default language
     $language = LanguageEditor::getLanguageByCode(in_array(self::$selectedLanguageCode, self::$selectedLanguages) ? self::$selectedLanguageCode : self::$selectedLanguages[0]);
     $language->makeDefault();
     // assign all languages to package id 0
     $sql = "INSERT INTO\twcf" . WCF_N . "_language_to_packages\n\t\t\t\t\t(languageID, packageID)\n\t\t\tSELECT \t\tlanguageID, 0\n\t\t\tFROM\t\twcf" . WCF_N . "_language";
     WCF::getDB()->sendQuery($sql);
     // rebuild language cache
     WCF::getCache()->clearResource('languages');
     // go to next step
     $this->gotoNextStep('createUser');
 }
 /**
  * Creates permissions for this source
  */
 public function createPermissions()
 {
     // determine position for next group option
     $sql = "SELECT\tIFNULL(MAX(showOrder), 0) + 1 AS showOrder\n\t\t\tFROM\twcf" . WCF_N . "_group_option\n\t\t\tWHERE\tcategoryName = 'user.source.dynamic'\n\t\t\tAND\tpackageID = " . PACKAGE_ID;
     $row = WCF::getDB()->getFirstRow($sql);
     $showOrder = $row['showOrder'];
     // create group option
     $sql = "INSERT INTO\twcf" . WCF_N . "_group_option\n\t\t\t\t\t(packageID, optionName, categoryName, optionType, defaultValue, showOrder, validationPattern, enableOptions, permissions, options, additionalData)\n\t\t\tVALUES\t\t(" . PACKAGE_ID . ",\n\t\t\t\t\t'user.source.dynamic.canUseSource" . $this->sourceID . "',\n\t\t\t\t\t'user.source.dynamic',\n\t\t\t\t\t'boolean',\n\t\t\t\t\t0,\n\t\t\t\t\t" . intval($showOrder) . ",\n\t\t\t\t\t'',\n\t\t\t\t\t'',\n\t\t\t\t\t'',\n\t\t\t\t\t'',\n\t\t\t\t\t'" . serialize(array()) . "')";
     WCF::getDB()->sendQuery($sql);
     $optionID = WCF::getDB()->getInsertID();
     // insert new option and default value to each group
     // get all groupIDs
     // don't change values of existing options
     $sql = "SELECT\tgroupID\n\t\t\tFROM\twcf" . WCF_N . "_group";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_group_option_value\n\t\t\t\t\t\t\t(groupID, optionID, optionValue)\n\t\t\t\tVALUES\t\t\t(" . $row['groupID'] . ",\n\t\t\t\t\t\t\t " . $optionID . ",\n\t\t\t\t\t\t\t'0')";
         WCF::getDB()->sendQuery($sql);
     }
     WCF::getCache()->clear(WCF_DIR . 'cache/', 'cache.group-option-*.php');
     // get available languages
     $languageCodes = Language::getLanguageCodes();
     // create language variables
     $sql = "SELECT\tlanguageID, languageItem, languageItemValue\n\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\tWHERE\tlanguageItem IN\n\t\t\t\t(\n\t\t\t\t\t'wcf.acp.group.option.user.source.dynamic.default',\n\t\t\t\t\t'wcf.acp.group.option.user.source.dynamic.default.description'\n\t\t\t\t)\n\t\t\tAND\tpackageID = " . PACKAGE_ID;
     $result = WCF::getDB()->sendQuery($sql);
     $languageData = array();
     // create language variables for each language
     while ($row = WCF::getDB()->fetchArray($result)) {
         $key = 'option.user.source.dynamic.canUseSource' . $this->sourceID;
         if ($row['languageItem'] == 'wcf.acp.group.option.user.source.dynamic.default.description') {
             $key .= '.description';
         }
         $value = str_replace('#sourceName#', $this->name, $row['languageItemValue']);
         $languageCode = $languageCodes[$row['languageID']];
         $languageData[$languageCode]['wcf.acp.group'][$key] = $value;
     }
     // import language variables
     foreach ($languageData as $languageCode => $data) {
         //create XML string
         $xml = LanguagesXMLPIP::create(array($languageCode => $data), true);
         // parse xml
         $xmlObj = new XML();
         $xmlObj->loadString($xml);
         // import language xml
         LanguageEditor::importFromXML($xmlObj, PACKAGE_ID);
     }
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if ($this->mode == 'copy') {
         // language code
         if (empty($this->languageCode)) {
             throw new UserInputException('languageCode');
         }
         //
         if (LanguageEditor::getLanguageByCode($this->languageCode)) {
             throw new UserInputException('languageCode', 'notUnique');
         }
         // source language id
         if (empty($this->sourceLanguageID)) {
             throw new UserInputException('sourceLanguageID');
         }
         // get language
         $this->sourceLanguage = new LanguageEditor($this->sourceLanguageID);
         if (!$this->sourceLanguage->getLanguageID()) {
             throw new UserInputException('sourceLanguageID');
         }
     } else {
         // check file
         if (!file_exists($this->filename)) {
             throw new UserInputException('languageFile');
         }
         // try to import
         try {
             // open xml document
             $xml = new XML($this->filename);
             // import xml document
             $this->language = LanguageEditor::importFromXML($xml, PACKAGE_ID);
         } catch (SystemException $e) {
             throw new UserInputException($this->importField, $e->getMessage());
         }
     }
 }