Commit 96524f69 authored by Rémy DANIEL's avatar Rémy DANIEL

[BUGFIX] Fix compatibility with TYPO3 8.7

The Environment class exists only since TYPO3 9, so we must introduce some
boilerplate code while TYPO3 8.7 is supported

Also, this commit fixes some misusages of PATH_site where paths were
already absolutes.

Fixes: #30
parent c7448b14
......@@ -28,7 +28,7 @@ namespace SGalinski\Lfeditor\Service;
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Utility\SgLib;
use TYPO3\CMS\Core\Core\Environment;
use SGalinski\Lfeditor\Utility\Typo3Lib;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -164,18 +164,7 @@ abstract class FileBaseService extends FileService {
}
// 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 = '';
}
$validatedPrefix = Typo3Lib::getLocalizedFilePrefix($fileRef);
if ($validatedPrefix) {
// Divide file reference into extension key, directory (if any) and base name:
list($extensionKey, $file_extPath) = explode('/', substr($fileRef, strlen($validatedPrefix)), 2);
......@@ -185,9 +174,9 @@ abstract class FileBaseService extends FileService {
}
// 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 Typo3Lib::getLabelsPath() . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName;
}
return NULL;
}
......
......@@ -190,13 +190,7 @@ class FileBaseXLFService extends FileBaseService {
protected function getLocalizedFile($content, $langKey) {
$file = '';
if ($this->session->getDataByKey('editingMode') !== 'extension') {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pathSite = PATH_site;
} else {
$pathSite = Environment::getPublicPath() . '/';
}
$file = $pathSite . $this->getLocalizedFileName($this->absFile, $langKey);
$file = $this->getLocalizedFileName($this->absFile, $langKey);
}
if (!\is_file($file)) {
$file = \dirname($this->absFile) . '/' . $this->nameLocalizedFile($langKey);
......
......@@ -93,16 +93,10 @@ class FileBaseXMLService extends FileBaseService {
* @return string localized file (absolute)
*/
protected function getLocalizedFile($content, $langKey) {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pathSite = PATH_site;
} else {
$pathSite = Environment::getPublicPath() . '/';
}
if ($this->session->getDataByKey('editingMode') === 'l10n') {
$file = $this->getLocalizedFileName($this->absFile, $langKey);
if (\is_file($pathSite . $file)) {
return Typo3Lib::fixFilePath($pathSite . $file);
if (\is_file($file)) {
return Typo3Lib::fixFilePath($file);
}
}
......@@ -112,7 +106,6 @@ class FileBaseXMLService extends FileBaseService {
if (!$file = $this->getLocalizedFileName($this->absFile, $langKey, TRUE)) {
return $content;
}
$file = $pathSite . $file;
if (!\is_file($file)) {
return $content;
}
......
......@@ -101,6 +101,57 @@ class Typo3Lib {
return '';
}
/**
* @param string $fileRef Absolute path of the language file
* @return string Absolute prefix to the language file location
*/
public static function getLocalizedFilePrefix($fileRef) {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.5.0', '<')) {
// Analyze file reference
if (GeneralUtility::isFirstPartOfStr($fileRef, self::PATH_SYS_EXT)) {
// Is system
$validatedPrefix = PATH_site . self::PATH_SYS_EXT;
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, self::PATH_GLOBAL_EXT)) {
// Is global
$validatedPrefix = PATH_site . self::PATH_GLOBAL_EXT;
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, self::PATH_LOCAL_EXT)) {
// Is local
$validatedPrefix = PATH_site . self::PATH_LOCAL_EXT;
} else {
$validatedPrefix = '';
}
} else {
// 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 = '';
}
}
return $validatedPrefix;
}
/**
* @return string Absolute path to the l10n directory
*/
public static function getLabelsPath() {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.5.0', '<')) {
$pathL10N = PATH_site . self::PATH_L10N;
} else {
$pathL10N = Environment::getLabelsPath() . '/';
}
return $pathL10N;
}
/**
* converts an absolute or relative typo3 style (EXT:) file path
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment