Commit 311cfe21 authored by Christian Kuhn's avatar Christian Kuhn Committed by Jan Helke
Browse files

[TASK] Use Environment API instead of PATH_site in core

First batch taking care of "easy" places.

Resolves: #85283
Releases: master
Change-Id: I68fa5a0559aae6191858aba7690ba72918bdf507
Reviewed-on: https://review.typo3.org/57240

Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Jan Helke's avatarJan Helke <typo3@helke.de>
Tested-by: Jan Helke's avatarJan Helke <typo3@helke.de>
parent f66e9156
......@@ -37,7 +37,7 @@ class YamlFileLoader
/**
* Loads and parses a YAML file, and returns an array with the found data
*
* @param string $fileName either relative to PATH_site or prefixed with EXT:...
* @param string $fileName either relative to TYPO3's base project folder or prefixed with EXT:...
* @return array the configuration as array
* @throws \RuntimeException when the file is empty or is of invalid format
*/
......@@ -61,7 +61,7 @@ class YamlFileLoader
/**
* Put into a separate method to ease the pains with unit tests
*
* @param string $fileName either relative to PATH_site or prefixed with EXT:...
* @param string $fileName either relative to TYPO3's base project folder or prefixed with EXT:...
*
* @return string the contents of the file
* @throws \RuntimeException when the file was not accessible
......
......@@ -840,7 +840,7 @@ class Bootstrap
public static function initializeBackendRouter()
{
// See if the Routes.php from all active packages have been built together already
$cacheIdentifier = 'BackendRoutesFromPackages_' . sha1(TYPO3_version . PATH_site . 'BackendRoutesFromPackages');
$cacheIdentifier = 'BackendRoutesFromPackages_' . sha1(TYPO3_version . Environment::getProjectPath() . 'BackendRoutesFromPackages');
/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface */
$codeCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
......
......@@ -64,7 +64,7 @@ class ClassLoadingInformationGenerator
* Returns class loading information for a single package
*
* @param PackageInterface $package The package to generate the class loading info for
* @param bool $useRelativePaths If set to TRUE, make the path relative to the current TYPO3 instance (PATH_site)
* @param bool $useRelativePaths If set to TRUE, make the path relative to the current TYPO3 public web path
* @return array
*/
public function buildClassLoadingInformationForPackage(PackageInterface $package, $useRelativePaths = false)
......
......@@ -288,7 +288,7 @@ class NormalizedParams
* @param ServerRequestInterface $serverRequest Used to access $_SERVER
* @param array $typo3ConfVars $GLOBALS['TYPO3_CONF_VARS']
* @param string $pathThisScript Absolute server entry script path, usually found within Environment::getCurrentScript()
* @param string $pathSite Absolute server path to document root, constant PATH_site
* @param string $pathSite Absolute server path to document root, Environment::getPublicPath()
*/
public function __construct(ServerRequestInterface $serverRequest, array $typo3ConfVars, string $pathThisScript, string $pathSite)
{
......@@ -307,7 +307,7 @@ class NormalizedParams
$this->remoteAddress = self::determineRemoteAddress($serverParams, $typo3ConfVars, $isBehindReverseProxy);
$scriptFilename = $this->scriptFilename = $pathThisScript;
$this->documentRoot = self::determineDocumentRoot($scriptName, $scriptFilename);
$siteUrl = $this->siteUrl = self::determineSiteUrl($requestDir, $pathThisScript, $pathSite);
$siteUrl = $this->siteUrl = self::determineSiteUrl($requestDir, $pathThisScript, $pathSite . '/');
$this->sitePath = self::determineSitePath($requestHost, $siteUrl);
$this->siteScript = self::determineSiteScript($requestUrl, $siteUrl);
......
......@@ -2131,9 +2131,9 @@ class GraphicalFunctions
$theOutputName = $this->imageMagickConvert_forceFileNameBody;
$this->imageMagickConvert_forceFileNameBody = '';
}
// Making the temporary filename:
GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
$output = PATH_site . 'typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
// Making the temporary filename
GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/typo3temp/assets/images/');
$output = Environment::getPublicPath() . '/typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
if ($this->dontCheckForExistingTempFile || !file_exists($output)) {
$this->imageMagickExec($imagefile, $output, $command, $frame);
}
......@@ -2210,7 +2210,7 @@ class GraphicalFunctions
/**
* Fetches the cached image dimensions from the cache. Does not check if the image file exists.
*
* @param string $filePath Image file path, relative to PATH_site
* @param string $filePath Image file path, relative to public web path
*
* @return array|bool an array where [0]/[1] is w/h, [2] is extension and [3] is the file name,
* or FALSE for a cache miss
......@@ -2248,7 +2248,7 @@ class GraphicalFunctions
*
* This method does not check if the image file actually exists.
*
* @param string $filePath Image file path, relative to PATH_site
* @param string $filePath Image file path, relative to public web path
*
* @return string the hash key (an SHA1 hash), will not be empty
*/
......@@ -2260,7 +2260,7 @@ class GraphicalFunctions
/**
* Creates the status hash to check whether a file has been changed.
*
* @param string $filePath Image file path, relative to PATH_site
* @param string $filePath Image file path, relative to public web path
*
* @return string the status hash (an SHA1 hash)
*/
......@@ -2401,7 +2401,7 @@ class GraphicalFunctions
/**
* Call the identify command
*
* @param string $imagefile The relative (to PATH_site) image filepath
* @param string $imagefile The relative to public web path image filepath
* @return array|null Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
*/
public function imageMagickIdentify($imagefile)
......@@ -2441,8 +2441,8 @@ class GraphicalFunctions
* Executes an ImageMagick "convert" on two filenames, $input and $output using $params before them.
* Can be used for many things, mostly scaling and effects.
*
* @param string $input The relative (to PATH_site) image filepath, input file (read from)
* @param string $output The relative (to PATH_site) image filepath, output filename (written to)
* @param string $input The relative to public web path image filepath, input file (read from)
* @param string $output The relative to public web path image filepath, output filename (written to)
* @param string $params ImageMagick parameters
* @param int $frame Optional, refers to which frame-number to select in the image. '' or 0
* @return string The result of a call to PHP function "exec()
......@@ -2467,10 +2467,10 @@ class GraphicalFunctions
* Executes an ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to)
* Can be used for many things, mostly scaling and effects.
*
* @param string $input The relative (to PATH_site) image filepath, bottom file
* @param string $overlay The relative (to PATH_site) image filepath, overlay file (top)
* @param string $mask The relative (to PATH_site) image filepath, the mask file (grayscale)
* @param string $output The relative (to PATH_site) image filepath, output filename (written to)
* @param string $input The relative to public web path image filepath, bottom file
* @param string $overlay The relative to public web path image filepath, overlay file (top)
* @param string $mask The relative to public web path image filepath, the mask file (grayscale)
* @param string $output The relative to public web path image filepath, output filename (written to)
* @return string
*/
public function combineExec($input, $overlay, $mask, $output)
......@@ -2570,10 +2570,10 @@ class GraphicalFunctions
return $theFile;
}
if (!@is_dir(PATH_site . 'typo3temp/assets/images/')) {
GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
if (!@is_dir(Environment::getPublicPath() . '/typo3temp/assets/images/')) {
GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/typo3temp/assets/images/');
}
$newFile = PATH_site . 'typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
$newFile = Environment::getPublicPath() . '/typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
$cmd = CommandUtility::imageMagickCommand(
'convert',
'"' . $theFile . '" "' . $newFile . '"',
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Localization\Parser;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException;
use TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -105,16 +106,16 @@ abstract class AbstractXmlParser implements LocalizationParserInterface
return GeneralUtility::getFileAbsFileName(str_replace($fileName, $language . '.' . $fileName, $fileRef));
}
// Analyse file reference:
// Is system:
if (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) {
$validatedPrefix = PATH_typo3 . 'sysext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3 . 'ext/')) {
// Is global:
$validatedPrefix = PATH_typo3 . 'ext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) {
// Is local:
$validatedPrefix = PATH_typo3conf . 'ext/';
// Analyse file reference
if (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getPublicPath() . '/typo3/sysext/')) {
// Is system
$validatedPrefix = Environment::getPublicPath() . '/typo3/sysext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getPublicPath() . '/typo3/ext/')) {
// Is global
$validatedPrefix = Environment::getPublicPath() . '/typo3/ext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getPublicPath() . '/typo3conf/ext/')) {
// Is local
$validatedPrefix = Environment::getPublicPath() . '/typo3conf/ext/';
} else {
$validatedPrefix = '';
}
......@@ -128,7 +129,7 @@ abstract class AbstractXmlParser implements LocalizationParserInterface
// 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 PATH_site . 'typo3conf/l10n/' . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName;
return Environment::getPublicPath() . '/typo3conf/l10n/' . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName;
}
return null;
}
......
......@@ -28,7 +28,7 @@ use TYPO3\CMS\Core\Utility\PathUtility;
class FileWriter extends AbstractWriter
{
/**
* Log file path, relative to PATH_site
* Log file path, relative to TYPO3's base project folder
*
* @var string
*/
......@@ -93,7 +93,7 @@ class FileWriter extends AbstractWriter
/**
* Sets the path to the log file.
*
* @param string $relativeLogFile path to the log file, relative to PATH_site
* @param string $relativeLogFile path to the log file, relative to public web dir
* @return WriterInterface
* @throws InvalidLogWriterConfigurationException
*/
......@@ -212,7 +212,7 @@ class FileWriter extends AbstractWriter
if (!@is_dir($logFileDirectory)) {
GeneralUtility::mkdir_deep($logFileDirectory);
// create .htaccess file if log file is within the site path
if (PathUtility::getCommonPrefix([PATH_site, $logFileDirectory]) === PATH_site) {
if (PathUtility::getCommonPrefix([Environment::getPublicPath() . '/', $logFileDirectory]) === (Environment::getPublicPath() . '/')) {
// only create .htaccess, if we created the directory on our own
$this->createHtaccessFile($logFileDirectory . '/.htaccess');
}
......
......@@ -40,7 +40,15 @@ class NormalizedParamsAttribute implements MiddlewareInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$request = $request->withAttribute('normalizedParams', new NormalizedParams($request, $GLOBALS['TYPO3_CONF_VARS'], Environment::getCurrentScript(), PATH_site));
$request = $request->withAttribute(
'normalizedParams',
new NormalizedParams(
$request,
$GLOBALS['TYPO3_CONF_VARS'],
Environment::getCurrentScript(),
Environment::getPublicPath()
)
);
// Set $request as global variable. This is needed in a transition phase until core code has been
// refactored to have ServerRequest object available where it is needed. This global will be
......
......@@ -22,6 +22,7 @@ use TYPO3\CMS\Core\Core\ClassLoadingInformation;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
......@@ -30,7 +31,7 @@ use TYPO3\CMS\Core\Utility\StringUtility;
/**
* The default TYPO3 Package Manager
*/
class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
class PackageManager implements SingletonInterface
{
/**
* @var DependencyOrderingService
......@@ -66,7 +67,7 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
* Absolute path leading to the various package directories
* @var string
*/
protected $packagesBasePath = PATH_site;
protected $packagesBasePath;
/**
* Array of available packages, indexed by package key
......@@ -107,7 +108,8 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
*/
public function __construct(DependencyOrderingService $dependencyOrderingService = null)
{
$this->packageStatesPathAndFilename = PATH_typo3conf . 'PackageStates.php';
$this->packagesBasePath = Environment::getPublicPath() . '/';
$this->packageStatesPathAndFilename = Environment::getPublicPath() . '/typo3conf/PackageStates.php';
if ($dependencyOrderingService === null) {
trigger_error(self::class . ' without constructor based dependency injection has been deprecated in v9.2 and will not work in TYPO3 v10.', E_USER_DEPRECATED);
$dependencyOrderingService = GeneralUtility::makeInstance(DependencyOrderingService::class);
......@@ -1058,13 +1060,13 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
{
if (count($this->packagesBasePaths) < 3) {
// Check if the directory even exists and if it is not empty
if (is_dir(PATH_typo3conf . 'ext') && $this->hasSubDirectories(PATH_typo3conf . 'ext')) {
$this->packagesBasePaths['local'] = PATH_typo3conf . 'ext/*/';
if (is_dir(Environment::getPublicPath() . '/typo3conf/ext') && $this->hasSubDirectories(Environment::getPublicPath() . '/typo3conf/ext')) {
$this->packagesBasePaths['local'] = Environment::getPublicPath() . '/typo3conf/ext/*/';
}
if (is_dir(PATH_typo3 . 'ext') && $this->hasSubDirectories(PATH_typo3 . 'ext')) {
$this->packagesBasePaths['global'] = PATH_typo3 . 'ext/*/';
if (is_dir(Environment::getPublicPath() . '/typo3/ext') && $this->hasSubDirectories(Environment::getPublicPath() . '/typo3/ext')) {
$this->packagesBasePaths['global'] = Environment::getPublicPath() . '/typo3/ext/*/';
}
$this->packagesBasePaths['system'] = PATH_typo3 . 'sysext/*/';
$this->packagesBasePaths['system'] = Environment::getPublicPath() . '/typo3/sysext/*/';
}
return $this->packagesBasePaths;
}
......
......@@ -119,7 +119,7 @@ interface DriverInterface
/**
* Returns the public URL to a file.
* Either fully qualified URL or relative to PATH_site (rawurlencoded).
* Either fully qualified URL or relative to public web path (rawurlencoded).
*
* @param string $identifier
* @return string|null NULL if file is missing or deleted, the generated url otherwise
......@@ -185,7 +185,7 @@ interface DriverInterface
* further check is done here! After a successful the original file must
* not exist anymore.
*
* @param string $localFilePath (within PATH_site)
* @param string $localFilePath within public web path
* @param string $targetFolderIdentifier
* @param string $newFileName optional, if not given original name is used
* @param bool $removeOriginal if set the original file will be removed
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Resource\Driver;
*/
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Resource\Exception;
use TYPO3\CMS\Core\Resource\FolderInterface;
use TYPO3\CMS\Core\Resource\ResourceStorage;
......@@ -117,7 +118,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
{
// only calculate baseURI if the storage does not enforce jumpUrl Script
if ($this->hasCapability(ResourceStorage::CAPABILITY_PUBLIC)) {
if (GeneralUtility::isFirstPartOfStr($this->absoluteBasePath, PATH_site)) {
if (GeneralUtility::isFirstPartOfStr($this->absoluteBasePath, Environment::getPublicPath())) {
// use site-relative URLs
$temporaryBaseUri = rtrim(PathUtility::stripPathSitePrefix($this->absoluteBasePath), '/');
if ($temporaryBaseUri !== '') {
......@@ -150,7 +151,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
if (!empty($configuration['pathType']) && $configuration['pathType'] === 'relative') {
$relativeBasePath = $configuration['basePath'];
$absoluteBasePath = PATH_site . $relativeBasePath;
$absoluteBasePath = Environment::getPublicPath() . '/' . $relativeBasePath;
} else {
$absoluteBasePath = $configuration['basePath'];
}
......@@ -167,7 +168,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
/**
* Returns the public URL to a file.
* For the local driver, this will always return a path relative to PATH_site.
* For the local driver, this will always return a path relative to public web path.
*
* @param string $identifier
* @return string|null NULL if file is missing or deleted, the generated url otherwise
......@@ -750,7 +751,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
* This assumes that the local file exists, so no further check is done here!
* After a successful the original file must not exist anymore.
*
* @param string $localFilePath (within PATH_site)
* @param string $localFilePath within public web path
* @param string $targetFolderIdentifier
* @param string $newFileName optional, if not given original name is used
* @param bool $removeOriginal if set the original file will be removed after successful operation
......@@ -761,7 +762,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true)
{
$localFilePath = $this->canonicalizeAndCheckFilePath($localFilePath);
// as for the "virtual storage" for backwards-compatibility, this check always fails, as the file probably lies under PATH_site
// as for the "virtual storage" for backwards-compatibility, this check always fails, as the file probably lies under public web path
// thus, it is not checked here
// @todo is check in storage
if (GeneralUtility::isFirstPartOfStr($localFilePath, $this->absoluteBasePath) && $this->storageUid > 0) {
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource\Processing;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Resource;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
......@@ -138,7 +139,7 @@ class LocalCropScaleMaskHelper
}
} else {
$targetFileName = $this->getFilenameForImageCropScaleMask($task);
$temporaryFileName = PATH_site . 'typo3temp/' . $targetFileName;
$temporaryFileName = Environment::getPublicPath() . '/typo3temp/' . $targetFileName;
$maskImage = $configuration['maskImages']['maskImage'];
$maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
if ($maskImage instanceof Resource\FileInterface && $maskBackgroundImage instanceof Resource\FileInterface) {
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
......@@ -63,13 +64,13 @@ class ResourceCompressor
public function __construct()
{
// we check for existence of our targetDirectory
if (!is_dir(PATH_site . $this->targetDirectory)) {
GeneralUtility::mkdir_deep(PATH_site . $this->targetDirectory);
if (!is_dir(Environment::getPublicPath() . '/' . $this->targetDirectory)) {
GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/' . $this->targetDirectory);
}
// if enabled, we check whether we should auto-create the .htaccess file
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess']) {
// check whether .htaccess exists
$htaccessPath = PATH_site . $this->targetDirectory . '.htaccess';
$htaccessPath = Environment::getPublicPath() . '/' . $this->targetDirectory . '.htaccess';
if (!file_exists($htaccessPath)) {
GeneralUtility::writeFile($htaccessPath, $this->htaccessTemplate);
}
......@@ -84,7 +85,7 @@ class ResourceCompressor
$this->gzipCompressionLevel = (int)$compressionLevel;
}
}
$this->setRootPath(TYPO3_MODE === 'BE' ? PATH_typo3 : PATH_site);
$this->setRootPath(TYPO3_MODE === 'BE' ? Environment::getPublicPath() . '/typo3/' : Environment::getPublicPath() . '/');
}
/**
......@@ -286,7 +287,7 @@ class ResourceCompressor
}
$targetFile = $this->targetDirectory . 'merged-' . md5($unique) . '.' . $type;
// if the file doesn't already exist, we create it
if (!file_exists(PATH_site . $targetFile)) {
if (!file_exists(Environment::getPublicPath() . '/' . $targetFile)) {
$concatenated = '';
// concatenate all the files together
foreach ($filesToInclude as $filename) {
......@@ -307,7 +308,7 @@ class ResourceCompressor
if ($type === 'css') {
$concatenated = $this->cssFixStatements($concatenated);
}
GeneralUtility::writeFile(PATH_site . $targetFile, $concatenated);
GeneralUtility::writeFile(Environment::getPublicPath() . '/' . $targetFile, $concatenated);
}
return $targetFile;
}
......@@ -363,7 +364,7 @@ class ResourceCompressor
$pathinfo = PathUtility::pathinfo($filenameAbsolute);
$targetFile = $this->targetDirectory . $pathinfo['filename'] . '-' . md5($unique) . '.css';
// only create it, if it doesn't exist, yet
if (!file_exists(PATH_site . $targetFile) || $this->createGzipped && !file_exists(PATH_site . $targetFile . '.gzip')) {
if (!file_exists(Environment::getPublicPath() . '/' . $targetFile) || $this->createGzipped && !file_exists(Environment::getPublicPath() . '/' . $targetFile . '.gzip')) {
$contents = $this->compressCssString(file_get_contents($filenameAbsolute));
if (strpos($filename, $this->targetDirectory) === false) {
$contents = $this->cssFixRelativeUrlPaths($contents, PathUtility::dirname($filename) . '/');
......@@ -415,7 +416,7 @@ class ResourceCompressor
$pathinfo = PathUtility::pathinfo($filename);
$targetFile = $this->targetDirectory . $pathinfo['filename'] . '-' . md5($unique) . '.js';
// only create it, if it doesn't exist, yet
if (!file_exists(PATH_site . $targetFile) || $this->createGzipped && !file_exists(PATH_site . $targetFile . '.gzip')) {
if (!file_exists(Environment::getPublicPath() . '/' . $targetFile) || $this->createGzipped && !file_exists(Environment::getPublicPath() . '/' . $targetFile . '.gzip')) {
$contents = file_get_contents($filenameAbsolute);
$this->writeFileAndCompressed($targetFile, $contents);
}
......@@ -433,12 +434,12 @@ class ResourceCompressor
/*
* The various paths may have those values (e.g. if TYPO3 is installed in a subdir)
* - docRoot = /var/www/html/
* - PATH_site = /var/www/html/sites/site1/
* - Environment::getPublicPath() = /var/www/html/sites/site1/
* - $this->rootPath = /var/www/html/sites/site1/typo3
*
* The file names passed into this function may be either:
* - relative to $this->rootPath
* - relative to PATH_site
* - relative to Environment::getPublicPath()
* - relative to docRoot
*/
$docRoot = GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT');
......@@ -454,29 +455,28 @@ class ResourceCompressor
}
// the path is not within the root path, strip off the site path, the remaining logic below
// takes care about adjusting the path correctly.
$filename = substr($absolutePath, strlen(PATH_site));
$filename = substr($absolutePath, strlen(Environment::getPublicPath() . '/'));
}
// if the file exists in the root path, just return the $filename
if (is_file($this->rootPath . $fileNameWithoutSlash)) {
return $fileNameWithoutSlash;
}
// if the file is from a special TYPO3 internal directory, add the missing typo3/ prefix
if (is_file(realpath(PATH_site . TYPO3_mainDir . $filename))) {
$filename = TYPO3_mainDir . $filename;
if (is_file(realpath(Environment::getPublicPath() . '/typo3/' . $filename))) {
$filename = 'typo3/' . $filename;
}
// build the file path relatively to the PATH_site
// build the file path relative to the public web path
if (strpos($filename, 'EXT:') === 0) {
$file = GeneralUtility::getFileAbsFileName($filename);
} elseif (strpos($filename, '../') === 0) {
$file = GeneralUtility::resolveBackPath(PATH_typo3 . $filename);
$file = GeneralUtility::resolveBackPath(Environment::getPublicPath() . '/typo3/' . $filename);
} else {
$file = PATH_site . $filename;
$file = Environment::getPublicPath() . '/' . $filename;
}
// check if the file exists, and if so, return the path relative to TYPO3_mainDir
if (is_file($file)) {
$mainDirDepth = substr_count(TYPO3_mainDir, '/');
return str_repeat('../', $mainDirDepth) . str_replace(PATH_site, '', $file);
return '../' . str_replace(Environment::getPublicPath() . '/', '', $file);
}
// none of above conditions were met, fallback to default behaviour
return $filename;
......@@ -616,10 +616,10 @@ class ResourceCompressor
protected function writeFileAndCompressed($filename, $contents)
{
// write uncompressed file
GeneralUtility::writeFile(PATH_site . $filename, $contents);
GeneralUtility::writeFile(Environment::getPublicPath() . '/' . $filename, $contents);
if ($this->createGzipped) {
// create compressed version
GeneralUtility::writeFile(PATH_site . $filename . '.gzip', gzencode($contents, $this->gzipCompressionLevel));
GeneralUtility::writeFile(Environment::getPublicPath() . '/' . $filename . '.gzip', gzencode($contents, $this->gzipCompressionLevel));
}
}
......@@ -636,7 +636,7 @@ class ResourceCompressor
if ($this->createGzipped && strpos(GeneralUtility::getIndpEnv('HTTP_ACCEPT_ENCODING'), 'gzip') !== false) {
$filename .= '.gzip';
}
return PathUtility::getRelativePath($this->rootPath, PATH_site) . $filename;
return PathUtility::getRelativePath($this->rootPath, Environment::getPublicPath() . '/') . $filename;
}
/**
......@@ -650,10 +650,10 @@ class ResourceCompressor
$externalContent = GeneralUtility::getUrl($url);
$filename = $this->targetDirectory . 'external-' . md5($url);
// Write only if file does not exist OR md5 of the content is not the same as fetched one
if (!file_exists(PATH_site . $filename)
|| (md5($externalContent) !== md5(file_get_contents(PATH_site . $filename)))
if (!file_exists(Environment::getPublicPath() . '/' . $filename)
|| (md5($externalContent) !== md5(file_get_contents(Environment::getPublicPath() . '/' . $filename)))
) {
GeneralUtility::writeFile(PATH_site . $filename, $externalContent);
GeneralUtility::writeFile(Environment::getPublicPath() . '/' . $filename, $externalContent);
}
return $filename;
}
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Resource;
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
......@@ -207,7 +208,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
/**
* Checks whether a file resides within a real storage in local file system.
* If no match is found, uid 0 is returned which is a fallback storage pointing to PATH_site.
* If no match is found, uid 0 is returned which is a fallback storage pointing to fileadmin in public web path.
*
* The file identifier is adapted accordingly to match the new storage's base path.
*
......@@ -463,9 +464,9 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
*/
public function retrieveFileOrFolderObject($input)
{
// Remove PATH_site because absolute paths under Windows systems contain ':'
// Remove Environment::getPublicPath() because absolute paths under Windows systems contain ':'
// This is done in all considered sub functions anyway
$input = str_replace(PATH_site, '', $input);
$input = str_replace(Environment::getPublicPath() . '/', '', $input);
if (GeneralUtility::isFirstPartOfStr($input, 'file:')) {
$input = substr($input, 5);
......@@ -486,7 +487,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
return null;
}
$input = PathUtility::getRelativePath(PATH_site, PathUtility::dirname($input)) . PathUtility::basename($input);
$input = PathUtility::getRelativePath(Environment::getPublicPath() . '/', PathUtility::dirname($input)) . PathUtility::basename($input);
return $this->getFileObjectFromCombinedIdentifier($input);
}
return null;
......@@ -494,7 +495,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
// this is a backwards-compatible way to access "0-storage" files or folders
// eliminate double slashes, /./ and /../
$input = PathUtility::getCanonicalPath(ltrim($input, '/'));
if (@is_file(PATH_site . $input)) {
if (@is_file(Environment::getPublicPath() . '/' . $input)) {
// only the local file
return $this->getFileObjectFromCombinedIdentifier($input);
}
......@@ -523,8 +524,8 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
// please note that getStorageObject() might modify $folderIdentifier when