Beispiel #1
0
 public function importPrefixFromZip($path, $key, $refreshCache = true, $addLanuage = false)
 {
     $importDir = $this->getImportDirPath() . $key . DS;
     mkdir($importDir);
     chmod($importDir, 0777);
     $this->cleanImportDir($importDir);
     $zip = new ZipArchive();
     $zip->open($path);
     $zip->extractTo($importDir);
     $zip->close();
     $arr = glob("{$importDir}language_*");
     $langsToImport = array();
     $prefixesToImport = array();
     foreach ($arr as $index => $dir) {
         $dh = opendir($dir);
         $langXmlE = simplexml_load_file($dir . DS . 'language.xml');
         /* @var $xmlElement SimpleXMLElement */
         $l = array('label' => strval($langXmlE->attributes()->label), 'tag' => strval($langXmlE->attributes()->tag));
         if (!in_array($l, $langsToImport)) {
             $langsToImport[] = $l;
         }
         while (false !== ($file = readdir($dh))) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             if (is_dir("{$dir}/{$file}")) {
                 //printVar("$file/");
             } else {
                 if ($file == 'language.xml') {
                     continue;
                 }
                 $xmlElement = simplexml_load_file("{$dir}/{$file}");
                 /* @var $xmlElement SimpleXMLElement */
                 $arr = $xmlElement->xpath('/prefix/key');
                 $tmp = $xmlElement->xpath('/prefix');
                 $prefixElement = $tmp[0];
                 $p = array('label' => strval($prefixElement->attributes()->label), 'prefix' => strval($prefixElement->attributes()->name));
                 if (!in_array($p, $prefixesToImport)) {
                     $prefixesToImport[] = $p;
                 }
             }
         }
     }
     $languages = $this->getLanguages();
     $activateFirstLang = empty($languages);
     foreach ($langsToImport as $langToImport) {
         if (!$this->findByTag($langToImport['tag'])) {
             if ($addLanuage) {
                 $dto = new BOL_Language();
                 $dto->setLabel($langToImport['label'])->setTag($langToImport['tag'])->setStatus($activateFirstLang ? 'active' : 'inactive')->setOrder($this->findMaxOrder() + 1);
                 $this->save($dto);
                 $activateFirstLang = false;
             } else {
                 continue;
             }
         }
         foreach ($prefixesToImport as $prefixToImport) {
             $xml = simplexml_load_file($importDir . "language_{$langToImport['tag']}" . DS . "{$prefixToImport['prefix']}.xml");
             $this->importPrefix($xml, false);
         }
         if ($refreshCache) {
             $this->generateCacheForAllActiveLanguages();
         }
     }
     UTIL_File::removeDir($importDir);
 }
Beispiel #2
0
 /**
  * @param string $path
  * @param bool $refreshCache
  * @param bool $addLanguage
  * @param bool $updateValues
  */
 public function importPrefixFromDir($path, $refreshCache = true, $addLanguage = false, $updateValues = false)
 {
     $path = UTIL_File::removeLastDS($path) . DS;
     if (!UTIL_File::checkDir($path)) {
         throw new InvalidArgumentException("Directory not found : {$path}");
     }
     $arr = glob("{$path}*");
     $prefixesToImport = array();
     $langsToImport = array();
     foreach ($arr as $index => $dir) {
         $dh = opendir($dir);
         if (!file_exists($dir . DS . 'language.xml')) {
             continue;
         }
         $langXmlE = simplexml_load_file($dir . DS . 'language.xml');
         $l = array('label' => strval($langXmlE->attributes()->label), 'tag' => strval($langXmlE->attributes()->tag), 'path' => $dir . DS);
         if (!in_array($l, $langsToImport)) {
             $langsToImport[] = $l;
         }
         /* @var $xmlElement SimpleXMLElement */
         while (false !== ($file = readdir($dh))) {
             if ($file == '.' || $file == '..' || is_dir($dir . DS . $file) || $file == 'language.xml' || !file_exists($dir . DS . $file)) {
                 continue;
             }
             $xmlElement = simplexml_load_file($dir . DS . $file);
             $tmp = $xmlElement->xpath('/prefix');
             $prefixElement = $tmp[0];
             $prefixItem = array('label' => strval($prefixElement->attributes()->label), 'prefix' => strval($prefixElement->attributes()->name));
             if (!in_array($prefixItem, $prefixesToImport)) {
                 $prefixesToImport[] = $prefixItem;
             }
         }
     }
     $languages = $this->getLanguages();
     $activateFirstLang = empty($languages);
     foreach ($langsToImport as $langToImport) {
         if (!$this->findByTag($langToImport['tag'])) {
             if (!$addLanguage) {
                 continue;
             }
             $dto = new BOL_Language();
             $dto->setLabel($langToImport['label'])->setTag($langToImport['tag'])->setStatus($activateFirstLang ? 'active' : 'inactive')->setOrder($this->findMaxOrder() + 1);
             $this->save($dto);
             $activateFirstLang = false;
         }
         foreach ($prefixesToImport as $prefixToImport) {
             $filePath = $langToImport['path'] . "{$prefixToImport['prefix']}.xml";
             if (!file_exists($filePath)) {
                 continue;
             }
             $xml = simplexml_load_file($filePath);
             $this->importPrefix($xml, false, false, $updateValues);
         }
     }
     if ($refreshCache) {
         $this->generateCacheForAllActiveLanguages();
     }
 }
 public function cloneLanguage($id, $label, $tag)
 {
     $languageClone = new BOL_Language();
     $languageClone->setLabel($label)->setTag($tag)->setStatus('inactive')->setOrder($this->findMaxOrder() + 1);
     $this->save($languageClone);
     $prefixes = null == ($prefixes = $this->getPrefixList()) ? array() : $prefixes;
     foreach ($prefixes as $prefix) {
         $keys = null === ($keys = $this->findAllPrefixKeys($prefix->getId())) ? array() : $keys;
         foreach ($keys as $key) {
             $value = $this->findValue($id, $key->getId());
             /* @var $value BOL_LanguageValue */
             if ($value === null) {
                 continue;
             }
             $valueClone = new BOL_LanguageValue();
             $valueClone->setKeyId($value->getKeyId())->setLanguageId($languageClone->getId())->setValue($value->getValue());
             $this->saveValue($valueClone, false);
         }
     }
     $this->generateCache($languageClone->getId());
 }