/**
  * generates a general information array
  *
  * @param string reference language
  * @param array language key array
  * @param object file object
  * @return array general information array
  * @see outputGeneral()
  */
 public static function genGeneralInfoArray($refLang, $languages, $fileObj)
 {
     // reference language data informations
     $localRefLangData = $fileObj->getLocalLangData($refLang);
     // generate needed data
     foreach ($languages as $langKey) {
         // get origin data and meta informations
         $origin = $fileObj->getOriginLangData($langKey);
         $infos['default']['meta'] = $fileObj->getMetaData();
         // language data
         $localLangData = $fileObj->getLocalLangData($langKey);
         // detailed constants informations
         $infos[$langKey]['numUntranslated'] = count(array_diff_key($localRefLangData, $localLangData));
         $infos[$langKey]['numUnknown'] = count(array_diff_key($localLangData, $localRefLangData));
         $infos[$langKey]['numTranslated'] = count(array_intersect_key($localLangData, $localRefLangData));
         // get location type
         if ($fileObj->getVar('workspace') != 'xll') {
             $locType = typo3Lib::checkFileLocation($origin);
             if ($locType == 'local') {
                 $infos[$langKey]['type'] = $GLOBALS['LANG']->getLL('ext.local');
             } elseif ($locType == 'global') {
                 $infos[$langKey]['type'] = $GLOBALS['LANG']->getLL('ext.global');
             } elseif ($locType == 'system') {
                 $infos[$langKey]['type'] = $GLOBALS['LANG']->getLL('ext.system');
             } elseif ($locType == 'l10n') {
                 $infos[$langKey]['type'] = $GLOBALS['LANG']->getLL('lang.file.l10n');
                 $infos[$langKey]['type2'] = 'l10n';
             } else {
                 $infos[$langKey]['type'] = $GLOBALS['LANG']->getLL('ext.unknown');
             }
             if ($infos[$langKey]['type2'] != 'l10n') {
                 if ($fileObj->checkLocalizedFile(basename($origin), $langKey)) {
                     $infos[$langKey]['type2'] = 'splitted';
                 } else {
                     $infos[$langKey]['type2'] = 'merged';
                 }
             }
         } else {
             $infos[$langKey]['type'] = 'xll';
             $infos[$langKey]['type2'] = 'merged';
         }
         // set origin
         try {
             $infos[$langKey]['origin'] = '[-]';
             if (!empty($origin)) {
                 $infos[$langKey]['origin'] = typo3Lib::transTypo3File($origin, false);
             }
         } catch (Exception $e) {
             $infos[$langKey]['origin'] = sgLib::trimPath(PATH_site, $origin);
         }
     }
     return $infos;
 }
 /**
  * removes the meta information entry and the backup file
  *
  * @throws LFException raised if the backup or meta file cant be written
  * @param string file name
  * @param string extension Name (default = $this->extName)
  * @param string language file (default = $this->langFile)
  * @return void
  */
 public function deleteSpecFile($filename, $extName = '', $langFile = '')
 {
     // get needed meta informations
     $extName = empty($extName) ? $this->extName : $extName;
     $langFile = empty($langFile) ? $this->langFile : $langFile;
     $metaArray = $this->getMetaInfos(3, $extName, '', $langFile);
     // check backup file
     if (!isset($metaArray[$filename])) {
         throw new LFException('failure.backup.notDeleted');
     }
     // get file
     $backupPath = $metaArray[$filename]['pathBackup'];
     $file = t3lib_div::fixWindowsFilePath(PATH_site . '/' . $backupPath . '/' . $filename);
     // build new meta information file
     unset($metaArray[$filename]);
     if (!count($metaArray)) {
         unset($metaArray);
     }
     $this->setMetaInfos($metaArray, 3, $extName, '', $langFile);
     $extMetaArray = $this->getMetaInfos(2, $extName);
     if (!count($extMetaArray)) {
         unset($extMetaArray);
     }
     $this->setMetaInfos($extMetaArray, 2, $extName);
     // write meta information
     try {
         $this->writeMetaFile();
     } catch (LFException $e) {
         throw $e;
     }
     // delete backup file
     try {
         sgLib::deleteFiles(array($file));
     } catch (Exception $e) {
         throw new LFException('failure.backup.notDeleted', 0, '(' . $e->getMessage(), ')');
     }
 }
Пример #3
0
 /**
  * searches defined files in a given path recursivly
  *
  * @throws Exception raised if the search directory cant be read
  * @param string search in this path
  * @param string optional: regular expression for files
  * @param integer optional: maximum search in this depth (0 is infinite)
  * @return void
  */
 public static function searchFiles($path, $searchRegex = '', $pathDepth = 0)
 {
     if (!($fhd = @opendir($path))) {
         throw new Exception('directory "' . $path . '" cant be read');
     }
     $fileArray = array();
     while ($file = readdir($fhd)) {
         $filePath = $path . '/' . $file;
         // ignore links and point directories
         if (preg_match('/^\\.{1,2}$/', $file) || is_link($filePath)) {
             continue;
         }
         // save path to file or continue
         if (is_file($filePath)) {
             if (empty($searchRegex)) {
                 $fileArray[] = $filePath;
             } elseif (preg_match($searchRegex, $file)) {
                 $fileArray[] = $filePath;
             }
             continue;
         }
         // breakpoint, if pathDepth is reached
         if ($pathDepth <= 1 && $pathDepth != 0) {
             continue;
         }
         // next dir
         if (is_dir($filePath)) {
             $fileArray = array_merge($fileArray, sgLib::searchFiles($filePath, $searchRegex, $pathDepth - 1));
         }
     }
     closedir($fhd);
     return $fileArray;
 }
Пример #4
0
 /**
  * generates the module content
  *
  * @throws LFException raised if any output failure occured
  * @return void at failure
  */
 private function moduleContent()
 {
     // generate menus
     try {
         // generate extension and workspace list
         $name = 'select.extensionAndWorkspace';
         $name = tx_lfeditor_mod1_functions::prepareSectionName($name);
         $this->content .= $this->doc->section($name, '', 0, 1);
         $this->menuExtList();
         $extList = $this->getFuncMenu('extList');
         $this->menuWorkspaceList();
         $this->content .= $this->doc->funcMenu($extList, $this->getFuncMenu('wsList'));
         // generate language file list
         if ($this->MOD_SETTINGS['function'] != 'backupMgr') {
             $name = tx_lfeditor_mod1_functions::prepareSectionName('select.langfile');
             $this->content .= $this->doc->section($name, '', 0, 1);
             $this->menuLangFileList();
             $this->content .= $this->doc->funcMenu($this->getFuncMenu('langFileList'), '');
         }
     } catch (LFException $e) {
         throw $e;
     }
     // init language file object
     try {
         if ($this->MOD_SETTINGS['function'] != 'backupMgr') {
             $this->initFileObject($this->MOD_SETTINGS['langFileList'], $this->MOD_SETTINGS['extList'], $this->MOD_SETTINGS['wsList']);
         }
     } catch (LFException $e) {
         throw $e;
     }
     // init backup object
     try {
         if ($this->MOD_SETTINGS['function'] == 'backupMgr') {
             $informations = array('extPath' => sgLib::trimPath(PATH_site, $this->MOD_SETTINGS['extList']), 'langFile' => t3lib_div::_POST('langFile'));
             $this->initBackupObject($this->MOD_SETTINGS['wsList'], $informations);
         }
     } catch (LFException $e) {
         throw $e;
     }
     // generate general output
     switch ($this->MOD_SETTINGS['function']) {
         case 'general':
             // exec action specific part of function
             try {
                 $submit = t3lib_div::_POST('submitted');
                 $sendMail = t3lib_div::_POST('sendMail');
                 if ($submit) {
                     if ($this->actionFuncGeneral()) {
                         if (!$sendMail) {
                             $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('lang.file.write.success') . '</p>';
                         } else {
                             $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('function.general.mail.success') . '</p>';
                         }
                     }
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // draw the language reference list
             $this->menuLangList($langData, 'patternList');
             $refMenu = $this->doc->funcMenu($this->getFuncMenu('patternList'), '');
             $sectName = 'select.referenceLanguage';
             $name = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             $this->content .= $this->doc->section($name, $refMenu, 0, 1);
             // get main content
             $content = $this->outputFuncGeneral();
             $sectName = 'function.general.general';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'langfile.edit':
             // start session
             session_start();
             // exec action specific part of function
             try {
                 $submit = t3lib_div::_POST('submitted');
                 $session = t3lib_div::_POST('session');
                 if ($submit) {
                     $this->actionFuncLangfileEdit();
                     if (!$session) {
                         $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('lang.file.write.success') . '</p>';
                     }
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // draw the language- and patternlist
             $this->menuLangList($langData, 'langList');
             $langList = $this->getFuncMenu('langList');
             $this->menuLangList($langData, 'langfileEditPatternList', $GLOBALS['LANG']->getLL('select.nothing'));
             $patternList = $this->getFuncMenu('langfileEditPatternList');
             $languageMenu = $this->doc->funcMenu($langList, $patternList);
             $name = 'select.languageAndPattern';
             $name = tx_lfeditor_mod1_functions::prepareSectionName($name);
             $this->content .= $this->doc->section($name, $languageMenu, 0, 1);
             // draw type selector
             $this->menuConstantType();
             $typeList = $this->getFuncMenu('constTypeList');
             $typeMenu = $this->doc->funcMenu($typeList, '');
             $name = 'select.constantType';
             $name = tx_lfeditor_mod1_functions::prepareSectionName($name);
             $this->content .= $this->doc->section($name, $typeMenu, 0, 1);
             // get main content
             try {
                 $content = $this->outputFuncLangfileEdit($langData);
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.langfile.edit';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'const.edit':
             // exec action specific part of function
             try {
                 $submit = t3lib_div::_POST('submit');
                 if ($submit) {
                     $this->actionFuncConstEdit();
                     $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('lang.file.write.success') . '</p>';
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // draw the constant list menu
             $this->menuConstList($langData, $GLOBALS['LANG']->getLL('select.nothing'));
             $constList = $this->doc->funcMenu($this->getFuncMenu('constList'), '');
             $name = tx_lfeditor_mod1_functions::prepareSectionName('select.constant');
             $this->content .= $this->doc->section($name, $constList, 0, 1);
             // get main content
             try {
                 $content = $this->outputFuncConstEdit($langData);
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.const.edit.edit';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'const.add':
             $constant = t3lib_div::_POST('nameOfConst');
             $newLang = t3lib_div::_POST('newLang');
             $langData = $this->fileObj->getLocalLangData();
             // exec action specific part of function
             $submit = t3lib_div::_POST('submit');
             try {
                 if ($submit) {
                     $this->actionFuncConstAdd($langData, $newLang, $constant);
                     $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('lang.file.write.success') . '</p>';
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get main content
             try {
                 $content = $this->outputFuncConstAdd($constant, $newLang);
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.const.add.add';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'const.delete':
             // exec action specific part of function
             try {
                 $submit = t3lib_div::_POST('submit');
                 if ($submit) {
                     $this->actionFuncConstDelete();
                     $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('lang.file.write.success') . '</p>';
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // draw the constant list menu
             $this->menuConstList($langData, $GLOBALS['LANG']->getLL('select.nothing'));
             $constList = $this->doc->funcMenu($this->getFuncMenu('constList'), '');
             $name = tx_lfeditor_mod1_functions::prepareSectionName('select.constant');
             $this->content .= $this->doc->section($name, $constList, 0, 1);
             // get main content
             try {
                 $content = $this->outputFuncConstDelete();
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.const.delete.delete';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'const.rename':
             // exec action specific part of function
             try {
                 $submit = t3lib_div::_POST('submit');
                 if ($submit) {
                     $langData = $this->fileObj->getLocalLangData();
                     $this->actionFuncConstRename($langData);
                     $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('lang.file.write.success') . '</p>';
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // draw the constant list menu
             $this->menuConstList($langData, $GLOBALS['LANG']->getLL('select.nothing'));
             $constList = $this->doc->funcMenu($this->getFuncMenu('constList'), '');
             $name = tx_lfeditor_mod1_functions::prepareSectionName('select.constant');
             $this->content .= $this->doc->section($name, $constList, 0, 1);
             // get main content
             try {
                 $content = $this->outputFuncConstRename();
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.const.rename.rename';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'const.search':
             // exec action specific part of function
             $submit = t3lib_div::_POST('submitted');
             if ($submit) {
                 $this->actionFuncConstSearch();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // get main content
             try {
                 $content = $this->outputFuncConstSearch($langData);
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.const.search.search';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'const.treeview':
             $curToken = t3lib_div::_POST('usedToken');
             // exec action specific part of function
             $submit = t3lib_div::_POST('submitted');
             if ($submit) {
                 $this->actionFuncConstTreeview();
             }
             // get language data
             $langData = $this->fileObj->getLocalLangData();
             // draw the language and reference list
             $this->menuLangList($langData, 'langList');
             $langList = $this->getFuncMenu('langList');
             $this->menuLangList($langData, 'patternList');
             $refList = $this->getFuncMenu('patternList');
             $name = 'select.languageAndPattern';
             $name = tx_lfeditor_mod1_functions::prepareSectionName($name);
             $langMenu = $this->doc->funcMenu($langList, $refList);
             $this->content .= $this->doc->section($name, $langMenu, 0, 1);
             // draw explode token menu
             $curToken = tx_lfeditor_mod1_functions::getExplodeToken($curToken, $langData[$this->MOD_SETTINGS['patternList']]);
             $selToken = tx_lfeditor_mod1_template::fieldSetToken($curToken);
             $treeMenu = $this->doc->funcMenu($selToken, '');
             $name = 'select.explodeToken';
             $name = tx_lfeditor_mod1_functions::prepareSectionName($name);
             $this->content .= $this->doc->section($name, $treeMenu, 0, 1);
             // get main content
             try {
                 $content = $this->outputFuncConstTreeview($langData, $curToken);
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.const.treeview.treeview';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
         case 'backupMgr':
             // exec action specific part of function
             try {
                 $origDiff = t3lib_div::_POST('origDiff');
                 $submit = t3lib_div::_POST('submitted');
                 if ($submit) {
                     $this->actionFuncBackupMgr();
                     if (!$origDiff) {
                         $preContent = '<p class="tx-lfeditor-success">' . $GLOBALS['LANG']->getLL('function.backupMgr.success') . '</p>';
                     }
                 }
             } catch (LFException $e) {
                 $preContent = $e->getMessage();
             }
             // get main content
             try {
                 $content = $this->outputFuncBackupMgr();
             } catch (LFException $e) {
                 $content = $e->getMessage();
             }
             $sectName = 'function.backupMgr.backupMgr';
             $sectName = tx_lfeditor_mod1_functions::prepareSectionName($sectName);
             break;
     }
     // save generated content
     $this->content .= $this->doc->section($sectName, $preContent . $content, 0, 1);
 }
Пример #5
0
 /**
  * converts an absolute or relative typo3 style (EXT:) file path
  *
  * @throws Exception raised, if the conversion fails
  * @param string absolute file or an typo3 relative file (EXT:)
  * @param boolean generate to relative(false) or absolute file
  * @return string converted file path
  */
 public static function transTypo3File($file, $mode)
 {
     $extType['local'] = typo3Lib::pathLocalExt;
     $extType['global'] = typo3Lib::pathGlobalExt;
     $extType['system'] = typo3Lib::pathSysExt;
     // relative to absolute
     if ($mode) {
         if (strpos($file, 'EXT:') === false) {
             throw new Exception('no typo3 relative path "' . $file . '"');
         }
         $cleanFile = sgLib::trimPath('EXT:', $file);
         foreach ($extType as $type) {
             $path = typo3Lib::fixFilePath(PATH_site . '/' . $type . '/' . $cleanFile);
             if (is_dir(dirname($path))) {
                 return $path;
             }
         }
         throw new Exception('cant convert typo3 relative file "' . $file . '"');
     } else {
         foreach ($extType as $type) {
             if (strpos($file, $type) === false) {
                 continue;
             }
             return 'EXT:' . sgLib::trimPath($type, sgLib::trimPath(PATH_site, $file));
         }
         throw new Exception('cant convert absolute file "' . $file . '"');
     }
 }
 /**
  * writes language files
  *
  * @throws LFException raised if a file cant be written
  * @return void
  */
 public function writeFile()
 {
     // get prepared language files
     $languageFiles = $this->prepareFileContents();
     // check write permissions of all files
     foreach ($languageFiles as $file => $content) {
         if (!sgLib::checkWritePerms($file)) {
             throw new LFException('failure.file.badPermissions');
         }
     }
     // write files
     foreach ($languageFiles as $file => $content) {
         if (!t3lib_div::writeFile($file, $content)) {
             throw new LFException('failure.file.notWritten');
         }
     }
 }
 /**
  * get the name of a localized file
  *
  * @param string language shortcut
  * @return string localized file (only filename)
  */
 public function nameLocalizedFile($langKey)
 {
     return sgLib::setFileExtension($langKey . '.php', basename($this->relFile));
 }
 /**
  * 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;
 }