示例#1
0
 /**
  * init backup object
  *
  * @throws LFException raised if directories cant be created or backup class instantiated
  * @param string workspace
  * @param boolean set to true if you want use informations from the file object
  * @return void
  */
 private function initBackupObject($mode, $infos = null)
 {
     // create backup and meta directory
     $backupPath = $this->extConfig['pathBackup'];
     $metaFile = $this->extConfig['metaFile'];
     try {
         sgLib::createDir($backupPath, PATH_site);
         sgLib::createDir(dirname($metaFile), PATH_site);
     } catch (Exception $e) {
         throw new LFException('failure.failure', 0, '(' . $e->getMessage() . ')');
     }
     // get informations
     if (!is_array($infos)) {
         // build language file and extension path
         if ($mode == 'xll') {
             try {
                 $typo3RelFile = $this->fileObj->getVar('typo3RelFile');
                 $typo3AbsFile = typo3Lib::transTypo3File($typo3RelFile, true);
             } catch (Exception $e) {
                 throw new LFException('failure.failure', 0, '(' . $e->getMessage() . ')');
             }
             $langFile = sgLib::trimPath('EXT:', $typo3RelFile);
             $langFile = substr($langFile, strpos($langFile, '/') + 1);
             $extPath = sgLib::trimPath($langFile, sgLib::trimPath(PATH_site, $typo3AbsFile), '/');
         } else {
             $extPath = sgLib::trimPath(PATH_site, $this->fileObj->getVar('absPath'), '/');
             $langFile = $this->fileObj->getVar('relFile');
         }
         // set data informations
         $informations['localLang'] = $this->fileObj->getLocalLangData();
         $informations['originLang'] = $this->fileObj->getOriginLangData();
         $informations['meta'] = $this->fileObj->getMetaData();
     }
     // set informations
     $informations['workspace'] = $mode;
     $informations['extPath'] = is_array($infos) ? $infos['extPath'] : $extPath;
     $informations['langFile'] = is_array($infos) ? $infos['langFile'] : $langFile;
     // create and initialize the backup object
     try {
         $this->backupObj = t3lib_div::makeInstance('tx_lfeditor_mod1_file_backup');
         $this->backupObj->init('', $backupPath, $metaFile);
         $this->backupObj->setVar($informations);
     } catch (LFException $e) {
         throw $e;
     }
 }
 /**
  * extends writing of language files for xll
  *
  * @throws LFException raised if parent method fails or the xll file cant be created
  * @return boolean always true
  */
 public function writeFile()
 {
     // create xll directory
     try {
         sgLib::createDir($this->absPath, PATH_site);
     } catch (Exception $e) {
         throw new LFException('failure.failure', 0, '(' . $e->getMessage() . ')');
     }
     // write xll file
     try {
         parent::writeFile();
     } catch (LFException $e) {
         throw $e;
     }
     // set only new values in localconf if something changed
     $relXLLFile = sgLib::trimPath(PATH_site, $this->absFile);
     if ($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$this->typo3RelFile] == $relXLLFile) {
         return true;
     }
     try {
         $fileRef = substr($this->typo3RelFile, 0, strrpos($this->typo3RelFile, '.'));
         $addLine = '$TYPO3_CONF_VARS[\'BE\'][\'XLLfile\'][\'' . $fileRef . '.xml\']';
         typo3Lib::writeLocalconf($addLine, $relXLLFile);
         $GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef . '.xml'] = $relXLLFile;
         // create alternative
         $addLine = '$TYPO3_CONF_VARS[\'BE\'][\'XLLfile\'][\'' . $fileRef . '.php\']';
         typo3Lib::writeLocalconf($addLine, $relXLLFile);
         $GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef . '.php'] = $relXLLFile;
     } catch (Exception $e) {
         throw new LFException('failure.failure', 0, '(' . $e->getMessage() . ')');
     }
     return true;
 }