Commit 8da1a3fc authored by Kevin Ditscheid's avatar Kevin Ditscheid

[TASK] Refactor code for TYPO3 9LTS

parent 82d53295
......@@ -43,6 +43,7 @@ abstract class AbstractBackendController extends AbstractController {
* Initializes any action
*
* @return void
* @throws \SGalinski\Lfeditor\Exceptions\DirectoryAccessRightsException
*/
public function initializeAction() {
parent::initializeAction();
......@@ -54,17 +55,17 @@ abstract class AbstractBackendController extends AbstractController {
$editingMode = $this->session->getDataByKey('editingMode');
$availableEditingModes = $this->configurationService->getAvailableEditingModes();
if ($this->backendUser->isAdmin()) {
if (!array_key_exists($editingMode, $availableEditingModes)) {
$firstAvailableEditMode = key($availableEditingModes);
if (!\array_key_exists($editingMode, $availableEditingModes)) {
$firstAvailableEditMode = \key($availableEditingModes);
$this->session->setDataByKey('editingMode', $firstAvailableEditMode);
}
$canChangeEditingModes = count($availableEditingModes) > 0;
$canChangeEditingModes = \count($availableEditingModes) > 0;
} else {
$canChangeEditingModes = count($availableEditingModes) > 0
$canChangeEditingModes = \count($availableEditingModes) > 0
&& $this->backendUser->user['lfeditor_change_editing_modes'] !== 0;
if (!$canChangeEditingModes || !array_key_exists($editingMode, $availableEditingModes)) {
end($availableEditingModes);
$lastAvailableEditMode = key($availableEditingModes);
if (!$canChangeEditingModes || !\array_key_exists($editingMode, $availableEditingModes)) {
\end($availableEditingModes);
$lastAvailableEditMode = \key($availableEditingModes);
$this->session->setDataByKey('editingMode', $lastAvailableEditMode);
}
}
......@@ -130,7 +131,7 @@ abstract class AbstractBackendController extends AbstractController {
$extensionKey = $this->request->getControllerExtensionKey();
$state = $this->backendUser->uc[$extensionKey . 'State']['LastActionControllerPair'];
return (!is_array($state) ? array() : $state);
return (!\is_array($state) ? [] : $state);
}
/**
......@@ -145,7 +146,7 @@ abstract class AbstractBackendController extends AbstractController {
$extensionKey = $this->request->getControllerExtensionKey();
$state = $this->backendUser->uc[$extensionKey . 'State']['LastActionControllerPairForRedirect'];
return (!is_array($state) ? array() : $state);
return (!\is_array($state) ? [] : $state);
}
/**
......@@ -153,10 +154,11 @@ abstract class AbstractBackendController extends AbstractController {
* backend user session
*
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
*/
protected function redirectToLastCalledControllerActionPair() {
$state = $this->getLastCalledControllerActionPairForRedirect();
if (count($state) && trim($state['action']) !== '' && trim($state['controller']) !== '') {
if (\count($state) && \trim($state['action']) !== '' && \trim($state['controller']) !== '') {
$currentAction = $this->request->getControllerActionName();
$currentController = $this->request->getControllerName();
if (!($currentController === $state['controller'] && $currentAction === $state['action'])) {
......@@ -166,7 +168,9 @@ abstract class AbstractBackendController extends AbstractController {
$availableControllers = $extensionConfig['modules'][$moduleSignature]['controllers'];
$controllerExists = isset($availableControllers[$state['controller']]);
if ($controllerExists) {
$actionExists = in_array($state['action'], $availableControllers[$state['controller']]['actions']);
$actionExists = \in_array(
$state['action'], $availableControllers[$state['controller']]['actions'], TRUE
);
if ($actionExists) {
$this->forward($state['action'], $state['controller']);
}
......
......@@ -27,12 +27,11 @@ namespace SGalinski\Lfeditor\Controller;
***************************************************************/
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Service\BackupService;
use SGalinski\Lfeditor\Service\ConfigurationService;
use SGalinski\Lfeditor\Session\PhpSession;
use SGalinski\Tinymce\Loader;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
......@@ -46,23 +45,42 @@ abstract class AbstractController extends ActionController {
protected $session;
/**
* @inject
* @var \SGalinski\Lfeditor\Service\ConfigurationService
*
* @var ConfigurationService
*/
protected $configurationService;
/**
* @inject
* @var \SGalinski\Lfeditor\Service\BackupService
* Inject the ConfigurationService
*
* @param ConfigurationService $configurationService
*/
public function injectConfigurationService(ConfigurationService $configurationService) {
$this->configurationService = $configurationService;
}
/**
*
* @var BackupService
*/
protected $backupService;
/**
* Inject the BackupService
*
* @param BackupService $backupService
*/
public function injectBackupService(BackupService $backupService) {
$this->backupService = $backupService;
}
/**
* Initializes the actions.
* - Initializes the session object.
* - Fetches configuration.
*
* @return void
* @throws \SGalinski\Lfeditor\Exceptions\DirectoryAccessRightsException
*/
public function initializeAction() {
parent::initializeAction();
......@@ -146,12 +164,12 @@ abstract class AbstractController extends ActionController {
*/
protected function checkMenuSelection($menuName, array $options) {
$selection = $this->session->getDataByKey($menuName . 'Selection');
if (!array_key_exists($selection, $options)) {
if (!\array_key_exists($selection, $options)) {
$selection = NULL;
}
if ($selection === NULL && !empty($options)) {
reset($options);
$selection = key($options);
\reset($options);
$selection = \key($options);
$this->session->setDataByKey($menuName . 'Selection', $selection);
return $selection;
}
......@@ -165,14 +183,14 @@ abstract class AbstractController extends ActionController {
* @return void
*/
public function addLFEFlashMessage(LFException $lFException) {
if ($lFException->getCode() == 0) {
if ($lFException->getCode() === 0) {
$this->addFlashMessage(
$lFException->getMessage(),
$messageTitle = LocalizationUtility::translate('failure.failure', 'lfeditor'),
$severity = AbstractMessage::ERROR,
$storeInSession = TRUE
);
} elseif ($lFException->getCode() == 1) {
} elseif ($lFException->getCode() === 1) {
$this->addFlashMessage(
$lFException->getMessage(),
$messageTitle = '',
......@@ -186,6 +204,7 @@ abstract class AbstractController extends ActionController {
* Prepares language file select options for each extension and sets combined data in view.
*
* @throws LFException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @return void
*/
protected function prepareExtensionAndLangFileOptions() {
......@@ -197,7 +216,7 @@ abstract class AbstractController extends ActionController {
$extensionGroupCount = 0;
foreach ($extensionOptions as $extAddress => $extLabel) {
$extension['extLabel'] = $extLabel;
$extension['languageFileOptions'] = array();
$extension['languageFileOptions'] = [];
$isExtensionGroupStart = $extAddress === '###extensionGroup###' . $extLabel;
try {
if (!$isExtensionGroupStart) {
......@@ -206,10 +225,10 @@ abstract class AbstractController extends ActionController {
continue;
}
} elseif (++$extensionGroupCount > 1) {
$extensions[$extAddress . 'EmptySpaceBefore'] = array(
$extensions[$extAddress . 'EmptySpaceBefore'] = [
'extLabel' => '',
'languageFileOptions' => array(),
);
'languageFileOptions' => [],
];
}
} catch (LFException $e) {
continue;
......@@ -217,10 +236,10 @@ abstract class AbstractController extends ActionController {
$extensions[$extAddress] = $extension;
if ($isExtensionGroupStart) {
$extensions[$extAddress . 'DelimiterAfter'] = array(
$extensions[$extAddress . 'DelimiterAfter'] = [
'extLabel' => '======',
'languageFileOptions' => array(),
);
'languageFileOptions' => [],
];
}
}
$cacheManager->getCache('lfeditor_select_options_cache')->set('extensionAndLangFileOptions', $extensions);
......@@ -252,8 +271,8 @@ abstract class AbstractController extends ActionController {
if (empty($extension['languageFileOptions'])) {
continue;
}
reset($extension['languageFileOptions']);
$languageFileSelection = key($extension['languageFileOptions']);
\reset($extension['languageFileOptions']);
$languageFileSelection = \key($extension['languageFileOptions']);
$this->session->setDataByKey('languageFileSelection', $languageFileSelection);
$this->session->setDataByKey('extensionSelection', $extAddress);
break;
......@@ -261,33 +280,6 @@ abstract class AbstractController extends ActionController {
}
}
/**
* Prepares TinyMCE for use if it's selected as insertion method.
*
* @return void
*/
protected function prepareTinyMCEIfSelected() {
$tinyMCELoaded = ExtensionManagementUtility::isLoaded('tinymce');
$this->view->assign('tinyMCELoaded', $tinyMCELoaded);
if (!$tinyMCELoaded) {
return;
}
$tinyMCESelected = $this->session->getDataByKey('tinyMCESelected');
$this->view->assign('tinyMCESelected', $tinyMCESelected);
if (!$tinyMCESelected) {
return;
}
$pathTinyMCEConfig = PATH_site . ExtensionManagementUtility::siteRelPath('lfeditor')
. 'Resources/Public/Scripts/TinyMCEConfig.js';
$tinyMCE = $this->objectManager->get('SGalinski\Tinymce\Loader');
$tinyMCE->loadConfiguration($pathTinyMCEConfig);
/** @var PageRenderer $pageRenderer */
$pageRenderer = $this->objectManager->get('TYPO3\CMS\Core\Page\PageRenderer');
$tinyMCE->loadJsViaPageRenderer($pageRenderer);
}
/**
* Clears cache used for storing select options.
* If $identifier is set, it clears only that entry in cache,
......
......@@ -29,6 +29,7 @@ namespace SGalinski\Lfeditor\Service;
use Exception;
use SGalinski\Lfeditor\Exceptions\DirectoryAccessRightsException;
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Utility\ExtensionUtility;
use SGalinski\Lfeditor\Utility\Functions;
use SGalinski\Lfeditor\Utility\SgLib;
use SGalinski\Lfeditor\Utility\Typo3Lib;
......@@ -39,6 +40,7 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use SGalinski\Lfeditor\Service\FileOverrideService;
/**
* Class ConfigurationService
......@@ -89,7 +91,7 @@ class ConfigurationService extends AbstractService {
if (!empty($this->extConfig)) {
return $this->extConfig;
}
$this->extConfig = \unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['lfeditor'], []);
$this->extConfig = ExtensionUtility::getExtensionConfiguration();
// regular expressions
if (!\preg_match('/^\/.*\/.*$/', $this->extConfig['searchRegex'])) {
......@@ -127,8 +129,6 @@ class ConfigurationService extends AbstractService {
// files
$this->extConfig['pathCSS'] = 'Resources/Public/StyleSheets/Lfeditor.css';
$this->extConfig['pathTinyMCEConfig'] = PATH_site .
ExtensionManagementUtility::siteRelPath('lfeditor') . 'Resources/Public/Scripts/TinyMCEConfig.js';
// languages (default is forbidden)
if (!empty($this->extConfig['viewLanguages'])) {
......@@ -340,7 +340,7 @@ class ConfigurationService extends AbstractService {
continue;
}
$languageLabel = $language;
if ($language == 'default') {
if ($language === 'default') {
$languageLabel = 'en';
}
$languageList[$language] = $languageLabel . ' (' . $constCount . ' ' .
......@@ -409,7 +409,7 @@ class ConfigurationService extends AbstractService {
try {
if ($this->session->getDataByKey('editingMode') === 'override') {
/** @var FileOverrideService $overrideFileObj */
$overrideFileObj = $this->objectManager->get('SGalinski\Lfeditor\Service\FileOverrideService');
$overrideFileObj = $this->objectManager->get(FileOverrideService::class);
$overrideFileObj->init($originalFileObject, '', '');
$this->fileObj = $overrideFileObj;
} else {
......@@ -444,7 +444,7 @@ class ConfigurationService extends AbstractService {
}
$fileObject = $this->getFileObj();
if ($fileObject == NULL) {
if ($fileObject === NULL) {
$this->initFileObject(
$this->session->getDataByKey('languageFileSelection'),
$this->session->getDataByKey('extensionSelection')
......@@ -454,7 +454,7 @@ class ConfigurationService extends AbstractService {
// execute backup
$extConfig = $this->getExtConfig();
if ($extConfig['execBackup'] && $this->session->getDataByKey('editingMode') == 'extension') {
if ($extConfig['execBackup'] && $this->session->getDataByKey('editingMode') === 'extension') {
/** @var BackupService $backupService */
$backupService = $this->objectManager->get('SGalinski\Lfeditor\Service\BackupService');
$backupService->execBackup();
......@@ -485,7 +485,7 @@ class ConfigurationService extends AbstractService {
$originLang = $fileObject->getOriginLangData();
$emptyFiles = [];
foreach ($originLang as $lang => $origin) {
if ($origin == $absFile || !\is_file($origin)) {
if ($origin === $absFile || !\is_file($origin)) {
continue;
}
......@@ -505,7 +505,7 @@ class ConfigurationService extends AbstractService {
}
/** @var CacheManager $cacheManager */
$cacheManager = $this->objectManager->get('TYPO3\CMS\Core\Cache\CacheManager');
$cacheManager = $this->objectManager->get(CacheManager::class);
$cacheManager->getCache('l10n')->flush();
}
......@@ -526,7 +526,7 @@ class ConfigurationService extends AbstractService {
// rewrite originLang array
$delLangFiles = [];
foreach ($langModes as $langKey => $mode) {
if ($langKey == 'default') {
if ($langKey === 'default') {
continue;
}
......@@ -536,7 +536,7 @@ class ConfigurationService extends AbstractService {
// split or merge
if ($mode === 1) {
// nothing to do if the file is already a normal splitted file
if (Typo3Lib::checkFileLocation($origin) != 'l10n') {
if (Typo3Lib::checkFileLocation($origin) !== 'l10n') {
if ($this->fileObj->checkLocalizedFile(\basename($origin), $langKey)) {
continue;
}
......@@ -600,7 +600,7 @@ class ConfigurationService extends AbstractService {
foreach ($origins as $langKey => $file) {
// localized or merged language origin
$newFile = SgLib::setFileExtension($type, $file);
if ($this->convObj->getVar('workspace') == 'base') {
if ($this->convObj->getVar('workspace') === 'base') {
if ($this->convObj->checkLocalizedFile(\basename($file), $langKey)) {
$newFile = \dirname($file) . '/' . $this->fileObj->nameLocalizedFile($langKey);
}
......@@ -724,10 +724,10 @@ class ConfigurationService extends AbstractService {
$languages = Functions::buildLangArray($this->extConfig['viewLanguages']);
$languages = $this->narrowToUserLanguages($languages, $backendUser);
if (!\in_array('default', $languages)) {
if (!\in_array('default', $languages, TRUE)) {
$languages = \array_merge(['default'], $languages);
}
if (!\in_array($this->extConfig['defaultLanguage'], $languages)) {
if (!\in_array($this->extConfig['defaultLanguage'], $languages, TRUE)) {
$languages = \array_merge([$this->extConfig['defaultLanguage']], $languages);
}
$this->langArray = $languages;
......
......@@ -28,9 +28,11 @@ namespace SGalinski\Lfeditor\Service;
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Utility\SgLib;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
/**
* base workspace class
......@@ -102,7 +104,7 @@ abstract class FileBaseService extends FileService {
$originLang = [];
foreach ($languages as $lang) {
$originLang[$lang] = $this->absFile;
if ($lang === 'default' || (\is_array($localLang[$lang]) && \count($localLang[$lang])) ) {
if ($lang === 'default' || (\is_array($localLang[$lang]) && \count($localLang[$lang]))) {
if (\is_array($localLang[$lang]) && \count($localLang[$lang])) {
\ksort($localLang[$lang]);
}
......@@ -140,4 +142,53 @@ abstract class FileBaseService extends FileService {
$this->localLang = $localLang;
$this->originLang = $originLang;
}
/**
* Checks if a localized file is found in labels pack (e.g. a language pack was downloaded in the backend)
* or if $sameLocation is set, then checks for a file located in "{language}.locallang.xlf" at the same directory
*
* @param string $fileRef Absolute file reference to locallang file
* @param string $language Language key
* @param bool $sameLocation If TRUE, then locallang localization file name will be returned with same directory as $fileRef
* @return string|null Absolute path to the language file, or null if error occurred
*/
protected function getLocalizedFileName($fileRef, $language, $sameLocation = FALSE) {
// If $fileRef is already prefixed with "[language key]" then we should return it as is
$fileName = PathUtility::basename($fileRef);
if (GeneralUtility::isFirstPartOfStr($fileName, $language . '.')) {
return GeneralUtility::getFileAbsFileName($fileRef);
}
if ($sameLocation) {
return GeneralUtility::getFileAbsFileName(str_replace($fileName, $language . '.' . $fileName, $fileRef));
}
// Analyze file reference
if (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getFrameworkBasePath() . '/')) {
// Is system
$validatedPrefix = Environment::getFrameworkBasePath() . '/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getBackendPath() . '/ext/')) {
// Is global
$validatedPrefix = Environment::getBackendPath() . '/ext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getExtensionsPath() . '/')) {
// Is local
$validatedPrefix = Environment::getExtensionsPath() . '/';
} else {
$validatedPrefix = '';
}
if ($validatedPrefix) {
// Divide file reference into extension key, directory (if any) and base name:
list($extensionKey, $file_extPath) = explode('/', substr($fileRef, strlen($validatedPrefix)), 2);
$temp = GeneralUtility::revExplode('/', $file_extPath, 2);
if (count($temp) === 1) {
array_unshift($temp, '');
}
// Add empty first-entry if not there.
list($file_extPath, $file_fileName) = $temp;
// The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it.
return Environment::getLabelsPath(
) . '/' . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName;
}
return NULL;
}
}
......@@ -27,6 +27,7 @@ namespace SGalinski\Lfeditor\Service;
***************************************************************/
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Utility\ExtensionUtility;
use SGalinski\Lfeditor\Utility\SgLib;
use SGalinski\Lfeditor\Utility\Typo3Lib;
use TYPO3\CMS\Core\Utility\ArrayUtility;
......@@ -41,7 +42,9 @@ class FileBaseXLFService extends FileBaseService {
*
* @param string $file name of the file (can be a path, if you need this (no check))
* @param string $path path to the file
* @param $metaFile
* @return void
* @throws LFException
*/
public function init($file, $path, $metaFile) {
$this->setFileType('xlf');
......@@ -73,7 +76,7 @@ class FileBaseXLFService extends FileBaseService {
* @return array language content
*/
protected function readLLFile($file, $langKey) {
if (!is_file($file)) {
if (!\is_file($file)) {
throw new LFException('failure.select.noLangfile');
}
......@@ -81,14 +84,14 @@ class FileBaseXLFService extends FileBaseService {
// htmlentities in CDATA are not modified,
// and those - normaly encoded if XML is valid - outside CDATA will be decoded.
$xmlContent = simplexml_load_file($file,'SimpleXMLElement', LIBXML_NOCDATA);
$xmlContent = \simplexml_load_string(\file_get_contents($file), 'SimpleXMLElement', LIBXML_NOCDATA);
// Cast XML to associative array with json_decode/encode.
// This way, value is XML are casted to string.
$xmlContent = json_decode(json_encode($xmlContent), TRUE);
$xmlContent = \json_decode(\json_encode($xmlContent), TRUE);
// check data
if (!is_array($xmlContent['file']['body'])) {
if (!\is_array($xmlContent['file']['body'])) {
throw new LFException('failure.search.noFileContent', 0, '(' . $file . ')');
}
......@@ -152,11 +155,11 @@ class FileBaseXLFService extends FileBaseService {
// get localized file
$lFile = $this->getLocalizedFile($localLang[$lang], $lang);
if ($this->checkLocalizedFile(basename($lFile), $lang)) {
if ($this->checkLocalizedFile(\basename($lFile), $lang)) {
$originLang[$lang] = $lFile;
$localLang[$lang] = array();
if (!is_file($lFile)) {
if (!\is_file($lFile)) {
continue;
}
......@@ -185,10 +188,10 @@ class FileBaseXLFService extends FileBaseService {
protected function getLocalizedFile($content, $langKey) {
$file = '';
if ($this->session->getDataByKey('editingMode') !== 'extension') {
$file = PATH_site . GeneralUtility::llXmlAutoFileName($this->absFile, $langKey);
$file = PATH_site . $this->getLocalizedFileName($this->absFile, $langKey);
}
if (!is_file($file)) {
$file = dirname($this->absFile) . '/' . $this->nameLocalizedFile($langKey);
if (!\is_file($file)) {
$file = \dirname($this->absFile) . '/' . $this->nameLocalizedFile($langKey);
}
return Typo3Lib::fixFilePath($file);
}
......@@ -201,7 +204,7 @@ class FileBaseXLFService extends FileBaseService {
* @return boolean true(localized) or false
*/
public function checkLocalizedFile($filename, $langKey) {
if (!preg_match('/^(' . $langKey . ')\..*\.xlf$/', $filename)) {
if (!\preg_match('/^(' . $langKey . ')\..*\.xlf$/', $filename)) {
return FALSE;
}
......@@ -215,7 +218,7 @@ class FileBaseXLFService extends FileBaseService {
* @return string localized file (only filename)
*/
public function nameLocalizedFile($langKey) {
return $langKey . '.' . basename($this->relFile);
return $langKey . '.' . \basename($this->relFile);
}
/**
......@@ -237,11 +240,11 @@ class FileBaseXLFService extends FileBaseService {
* @return string xml content
*/
private function array2xml($phpArray, $targetLanguage, $enLanguage) {
$targetLanguage = htmlspecialchars($targetLanguage);
$targetLanguage = \htmlspecialchars($targetLanguage);
$targetLanguageAttribute = ($targetLanguage !== 'default' ? ' target-language="' . $targetLanguage . '"' : '');
$lfeditorExtConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['lfeditor']);
$date = ($lfeditorExtConf['changeXlfDate'] ? gmdate('Y-m-d\TH:i:s\Z') : $this->meta['@attributes']['date']);
$lfeditorExtConf = ExtensionUtility::getExtensionConfiguration();
$date = ($lfeditorExtConf['changeXlfDate'] ? \gmdate('Y-m-d\TH:i:s\Z') : $this->meta['@attributes']['date']);
$xmlString = $this->getXMLHeader() . '<xliff version="1.0">
<file source-language="en"' . $targetLanguageAttribute . ' datatype="plaintext" original="messages" date="' . $date . '">
......@@ -251,18 +254,20 @@ class FileBaseXLFService extends FileBaseService {
</xliff>';
$header = '<header/>';
if (is_array($phpArray['header']) && count($phpArray['header'])) {
if (\is_array($phpArray['header']) && \count($phpArray['header'])) {
$header = '<header>' . "\n";
foreach ($phpArray['header'] as $tagName => $tagValue) {
$tagName = htmlspecialchars($tagName);
$header .= "\t\t\t" . '<' . $tagName . '>' . htmlspecialchars($tagValue) . '</' . $tagName . '>' . "\n";
$tagName = \htmlspecialchars($tagName);
$header .= "\t\t\t" . '<' . $tagName . '>' . \htmlspecialchars(
$tagValue
) . '</' . $tagName . '>' . "\n";
}
$header .= "\t\t" . '</header>';
}
$xmlString = str_replace('###HEADER###', $header, $xmlString);
$xmlString = \str_replace('###HEADER###', $header, $xmlString);
$body = '<body/>';
if (is_array($phpArray['data']) && count($phpArray['data'])) {
if (\is_array($phpArray['data']) && \count($phpArray['data'])) {
$body = '<body>' . "\n";
$startCDATA = "<![CDATA[";
$endCDATA = "]]>";
......@@ -278,7 +283,7 @@ class FileBaseXLFService extends FileBaseService {
$value = $startCDATA.$value.$endCDATA;
$enValue = $startCDATA.$enValue.$endCDATA;
$body .= "\t\t\t" . '<trans-unit id="' . htmlspecialchars(
$body .= "\t\t\t" . '<trans-unit id="' . \htmlspecialchars(
$constant
) . '"' . $approved . $this->addPreserveSpaceAttribute(
$value, $enValue, $targetLanguage
......@@ -294,7 +299,7 @@ class FileBaseXLFService extends FileBaseService {
}
$body .= "\t\t" . '</body>';
}
$xmlString = str_replace('###BODY###', $body, $xmlString);
$xmlString = \str_replace('###BODY###', $body, $xmlString);
return $xmlString;
}
......@@ -307,13 +312,13 @@ class FileBaseXLFService extends FileBaseService {
*/
private function getLangContent($localLang) {
$content = array();
if (!is_array($localLang) || !count($localLang)) {
if (!\is_array($localLang) || !\count($localLang)) {
return $content;
}
ksort($localLang);
\ksort($localLang);
foreach ($localLang as $const => $value) {
$content[$const] = str_replace("\r", '', $value);
$content[$const] = \str_replace("\r", '', $value);
}
return $content;
......@@ -325,9 +330,9 @@ class FileBaseXLFService extends FileBaseService {
* @return array meta content
*/
private function prepareMeta() {
if (is_array($this->meta) && count($this->meta)) {
if (\is_array($this->meta) && \count($this->meta)) {
foreach ($this->meta as $label => $value) {
$this->meta[$label] = str_replace("\r", '', $value);
$this->meta[$label] = \str_replace("\r", '', $value);
}
}
$this->addGeneratorString();
......@@ -356,12 +361,12 @@ class FileBaseXLFService extends FileBaseService {
}
// If default language content and $lang language content are not edited, skip this file.
if ($editedLanguages !== NULL &&
!in_array('default', $editedLanguages) && !in_array($lang, $editedLanguages)
!\in_array('default', $editedLanguages, TRUE) && !\in_array($lang, $editedLanguages, TRUE)
) {
continue;
}
if (is_array($this->localLang[$lang]) && count($this->localLang[$lang])) {
if (\is_array($this->localLang[$lang]) && \count($this->localLang[$lang])) {
$file = $this->originLang[$lang];
$data = array(
'header' => $metaData,
......@@ -372,10 +377,10 @@ class FileBaseXLFService extends FileBaseService {
}
// only a localized file?
if ($this->checkLocalizedFile(basename($this->absFile), implode('|', SgLib::getSystemLanguages()))) {
if ($this->checkLocalizedFile(\basename($this->absFile), \implode('|', SgLib::getSystemLanguages()))) {
return $languageFiles;
}
if ($editedLanguages !== NULL && !in_array('default', $editedLanguages)) {
if ($editedLanguages !== NULL && !\in_array('default', $editedLanguages, TRUE)) {
return $languageFiles;
}
......@@ -399,10 +404,10 @@ class FileBaseXLFService extends FileBaseService {
* @return string
*/
protected function addPreserveSpaceAttribute($value, $enValue, $targetLanguage) {
$valueContainsSpacesOrLF = strpos($value, ' ') !== FALSE || strpos($value, "\n") !== FALSE;
$valueContainsSpacesOrLF = \strpos($value, ' ') !== FALSE || \strpos($value, "\n") !== FALSE;
$enValueContainsSpacesOrLF = FALSE;
if ($targetLanguage !== 'default') {
$enValueContainsSpacesOrLF = strpos($enValue, ' ') !== FALSE || strpos($enValue, "\n") !== FALSE;
$enValueContainsSpacesOrLF = \strpos($enValue, ' ') !== FALSE || \strpos($enValue, "\n") !== FALSE;
}
return ($valueContainsSpacesOrLF || $enValueContainsSpacesOrLF ? ' xml:space="preserve"' : '');
}
......
......@@ -44,6 +44,7 @@ class FileBaseXMLService extends FileBaseService {
* @param string $file name of the file (can be a path, if you need this (no check))
* @param string $path path to the file
*
* @param $metaFile
* @return void
* @throws LFException
*/
......@@ -61,20 +62,20 @@ class FileBaseXMLService extends FileBaseService {
* @return array language content
*/
protected function readLLFile($file, $langKey) {
if (!is_file($file)) {
if (!\is_file($file)) {
throw new LFException('failure.select.noLangfile');
}
// read xml into array
$xmlContent = GeneralUtility::xml2array(file_get_contents($file));
$xmlContent = GeneralUtility::xml2array(\file_get_contents($file));
// check data
if (!is_array($xmlContent['data'])) {
if (!\is_array($xmlContent['data'])) {
throw new LFException('failure.search.noFileContent', 0, '(' . $file . ')');
}
// set header data
if ($langKey == 'default') {
if ($langKey === 'default') {
$this->meta = $xmlContent['meta'];
}
......@@ -91,8 +92,8 @@ class FileBaseXMLService extends FileBaseService {
*/
protected function getLocalizedFile($content, $langKey) {
if ($this->session->getDataByKey('editingMode') === 'l10n') {
$file = GeneralUtility::llXmlAutoFileName($this->absFile, $langKey);
if (is_file(PATH_site . $file)) {
$file = $this->getLocalizedFileName($this->absFile, $langKey);
if (\is_file(PATH_site . $file)) {
return Typo3Lib::fixFilePath(PATH_site . $file);
}
}
......@@ -100,11 +101,11 @@ class FileBaseXMLService extends FileBaseService {
try {
$file = Typo3Lib::transTypo3File($content, TRUE);