use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
if (!$this->fileMode) {
$str = '<span class="text-muted">' . $str . '</span>';
} elseif (ExtensionManagementUtility::isLoaded('filelist')) {
- $str = '<a href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('file_list', ['id' => dirname($rec)])) . '">' . $str . '</a>';
+ $str = '<a href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('file_list', ['id' => PathUtility::dirname($rec)])) . '">' . $str . '</a>';
}
}
return $str;
$labelKey = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.' . ($this->currentMode() === 'copy' ? 'copy' : 'move') . ($this->current === 'normal' ? '' : 'cb') . '_' . $type;
$msg = $this->getLanguageService()->sL($labelKey . ($columnLabel ? '_colPos' : ''));
if ($table === '_FILE') {
- $thisRecTitle = basename($rec);
+ $thisRecTitle = PathUtility::basename($rec);
if ($this->current === 'normal') {
$selItem = reset($clElements);
- $selRecTitle = basename($selItem);
+ $selRecTitle = PathUtility::basename($selItem);
} else {
$selRecTitle = count($clElements);
}
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Renders the icon "insert record from clipboard",
$title = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_file'), count($clipboardElements));
foreach ($clipboardElements as $clipboardElement) {
$value = $clipboardElement['value'];
- $title = 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(basename($clipboardElement['title']))) . ')';
+ $title = 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(PathUtility::basename($clipboardElement['title']))) . ')';
$clipboardOnClick[] = 'setFormValueFromBrowseWin('
. GeneralUtility::quoteJSvalue($elementName) . ','
. 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(str_replace('%20', ' ', $value))) . '),'
$mainParams = ['id' => $mainParams];
}
if (!$script) {
- $script = basename(Environment::getCurrentScript());
+ $script = PathUtility::basename(Environment::getCurrentScript());
}
if ($routePath = GeneralUtility::_GP('route')) {
*/
use TYPO3\CMS\Belog\Domain\Model\LogEntry;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
protected static function stripPathFromFilenames(array $files = [])
{
foreach ($files as $key => $file) {
- $files[$key] = basename($file);
+ $files[$key] = PathUtility::basename($file);
}
return $files;
}
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
if (!is_string($data)) {
throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1204481674);
}
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073032);
}
if ($entryIdentifier === '') {
if ($this->frozen === true) {
return isset($this->cacheEntryIdentifiers[$entryIdentifier]) ? file_get_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension) : false;
}
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073033);
}
$pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
if ($this->frozen === true) {
return isset($this->cacheEntryIdentifiers[$entryIdentifier]);
}
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073034);
}
return !$this->isCacheFileExpired($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
*/
public function remove($entryIdentifier)
{
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073035);
}
if ($entryIdentifier === '') {
}
return false;
}
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073036);
}
$pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
if (!is_string($data)) {
throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1334756734);
}
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756735);
}
if ($entryIdentifier === '') {
*/
public function get($entryIdentifier)
{
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756877);
}
$pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
*/
public function has($entryIdentifier)
{
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756878);
}
return file_exists($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
*/
public function remove($entryIdentifier)
{
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756960);
}
if ($entryIdentifier === '') {
public function requireOnce($entryIdentifier)
{
$pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
- if ($entryIdentifier !== basename($entryIdentifier)) {
+ if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073037);
}
return file_exists($pathAndFilename) ? require_once $pathAndFilename : false;
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
*/
protected static function getRootPathFromScriptPath($scriptPath, $entryPointLevel)
{
- $entryScriptDirectory = dirname($scriptPath);
+ $entryScriptDirectory = PathUtility::dirnameDuringBootstrap($scriptPath);
if ($entryPointLevel > 0) {
list($rootPath) = GeneralUtility::revExplode('/', $entryScriptDirectory, $entryPointLevel + 1);
} else {
if ($this->autoVersioningUpdate === true) {
foreach ($valueArray as $key => $theFile) {
// If it is an already attached file...
- if ($theFile === basename($theFile)) {
+ if ($theFile === PathUtility::basename($theFile)) {
$valueArray[$key] = PATH_site . $tcaFieldConf['uploadfolder'] . '/' . $theFile;
}
}
$this->copiedFileMap[$theFile] = $theDestFile;
clearstatcache();
if (!@is_file($theDestFile)) {
- $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, dirname($theDestFile), $recFID], $propArr['event_pid']);
+ $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, PathUtility::dirname($theDestFile), $recFID], $propArr['event_pid']);
}
} else {
$this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, [$theFile, $theDestFile, $recFID], $propArr['event_pid']);
if (@is_file(PATH_site . $this->alternativeFilePath[$theFile])) {
$theFile = PATH_site . $this->alternativeFilePath[$theFile];
} elseif (@is_file($theFile)) {
- $dest = dirname(PATH_site . $this->alternativeFilePath[$theFile]);
+ $dest = PathUtility::dirname(PATH_site . $this->alternativeFilePath[$theFile]);
if (!@is_dir($dest)) {
GeneralUtility::mkdir_deep($dest);
}
$this->copiedFileMap[$theFile] = $theDestFile;
clearstatcache();
if (!@is_file($theDestFile)) {
- $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, dirname($theDestFile), $recFID], $propArr['event_pid']);
+ $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, PathUtility::dirname($theDestFile), $recFID], $propArr['event_pid']);
}
} else {
$this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, [$theFile, $theDestFile, $recFID], $propArr['event_pid']);
return;
}
foreach ($rteFileRecords as $rteFileRecord) {
- $filename = basename($rteFileRecord['ref_string']);
+ $filename = PathUtility::basename($rteFileRecord['ref_string']);
if (!GeneralUtility::isFirstPartOfStr($filename, 'RTEmagicC_')) {
continue;
}
continue;
}
// Initialize; Get directory prefix for file and set the original name:
- $dirPrefix = dirname($rteFileRecord['ref_string']) . '/';
- $rteOrigName = basename($fileInfo['original']);
+ $dirPrefix = PathUtility::dirname($rteFileRecord['ref_string']) . '/';
+ $rteOrigName = PathUtility::basename($fileInfo['original']);
// If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file!
if ($rteOrigName && GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) {
// RTE:
$origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
// Create copy file name:
$pI = pathinfo($rteFileRecord['ref_string']);
- $copyDestName = dirname($origDestName) . '/RTEmagicC_' . mb_substr(basename($origDestName), 10) . '.' . $pI['extension'];
+ $copyDestName = PathUtility::dirname($origDestName) . '/RTEmagicC_' . mb_substr(PathUtility::basename($origDestName), 10) . '.' . $pI['extension'];
if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) {
// Making copies:
GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName);
if (trim($file)) {
$realFile = $destinationFolder . '/' . trim($file);
$newValueFile = [
- 'filename' => basename($file),
+ 'filename' => PathUtility::basename($file),
'ID' => md5($realFile),
'ID_absFile' => $realFile
];
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
/**
$elements[$k] = [];
$elements[$k]['matchString'] = $v;
// If the image seems to be an RTE image, then proceed to set up substitution token:
- if (GeneralUtility::isFirstPartOfStr($srcRef, 'uploads/') && preg_match('/^RTEmagicC_/', basename($srcRef))) {
+ if (GeneralUtility::isFirstPartOfStr($srcRef, 'uploads/') && preg_match('/^RTEmagicC_/', PathUtility::basename($srcRef))) {
// Token and substitute value:
// Make sure the value we work on is found and will get substituted in the content (Very important that the src-value is not DeHSC'ed)
if (strstr($splitContent[$k], $attribs[0]['src'])) {
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Class UploadedFile which represents one uploaded file, usually coming
}
if (!empty($this->file) && is_uploaded_file($this->file)) {
- if (GeneralUtility::upload_copy_move($this->file, $targetPath . basename($this->file)) === false) {
+ if (GeneralUtility::upload_copy_move($this->file, $targetPath . PathUtility::basename($this->file)) === false) {
throw new \RuntimeException('An error occurred while moving uploaded file', 1436717310);
}
} elseif ($this->stream) {
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Standard graphical functions
$command .= ' -colorspace ' . $this->colorspace;
$cropscale = $data['crs'] ? 'crs-V' . $data['cropV'] . 'H' . $data['cropH'] : '';
if ($this->alternativeOutputKey) {
- $theOutputName = GeneralUtility::shortMD5($command . $cropscale . basename($imagefile) . $this->alternativeOutputKey . '[' . $frame . ']');
+ $theOutputName = GeneralUtility::shortMD5($command . $cropscale . PathUtility::basename($imagefile) . $this->alternativeOutputKey . '[' . $frame . ']');
} else {
$theOutputName = GeneralUtility::shortMD5($command . $cropscale . $imagefile . filemtime($imagefile) . '[' . $frame . ']');
}
if (($type === 'IM' || !$type) && $gfxConf['processor_enabled'] && $gfxConf['processor_path_lzw']) {
// Use temporary file to prevent problems with read and write lock on same file on network file systems
- $temporaryName = dirname($theFile) . '/' . md5(uniqid('', true)) . '.gif';
+ $temporaryName = PathUtility::dirname($theFile) . '/' . md5(uniqid('', true)) . '.gif';
// Rename could fail, if a simultaneous thread is currently working on the same thing
if (@rename($theFile, $temporaryName)) {
$cmd = CommandUtility::imageMagickCommand('convert', '"' . $temporaryName . '" "' . $theFile . '"', $gfxConf['processor_path_lzw']);
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\RelationHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* This class holds functions used by the TYPO3 backend to check the integrity of the database (The DBint module, 'lowlevel' extension)
$references = 1;
}
// The directory must be empty (prevents checking of the root directory)
- $directory = dirname($file);
+ $directory = PathUtility::dirname($file);
if ($directory !== '') {
- $newCheckFileRefs[$directory][basename($file)] = $references;
+ $newCheckFileRefs[$directory][PathUtility::basename($file)] = $references;
}
}
}
use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException;
use TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Abstract class for XML based parser.
protected function getLocalizedFileName($fileRef, $language, $sameLocation = false)
{
// If $fileRef is already prefixed with "[language key]" then we should return it as is
- $fileName = basename($fileRef);
+ $fileName = PathUtility::basename($fileRef);
if (GeneralUtility::isFirstPartOfStr($fileName, $language . '.')) {
return GeneralUtility::getFileAbsFileName($fileRef);
}
if (file_exists($this->logFile)) {
return;
}
- $logFileDirectory = dirname($this->logFile);
+ $logFileDirectory = PathUtility::dirname($this->logFile);
if (!@is_dir($logFileDirectory)) {
GeneralUtility::mkdir_deep($logFileDirectory);
// create .htaccess file if log file is within the site path
/** @var SplFileInfo $fileInfo */
foreach ($finder as $fileInfo) {
- $path = dirname($fileInfo->getPathname());
- $extensionName = basename($path);
+ $path = PathUtility::dirname($fileInfo->getPathname());
+ $extensionName = PathUtility::basename($path);
// Fix Windows backslashes
// we can't use GeneralUtility::fixWindowsFilePath as we have to keep double slashes for Unit Tests (vfs://)
$currentPath = str_replace('\\', '/', $path) . '/';
$json = file_get_contents($manifestPath . 'composer.json');
$composerManifest = json_decode($json);
if (!$composerManifest instanceof \stdClass) {
- throw new Exception\InvalidPackageManifestException('The composer.json found for extension "' . basename($manifestPath) . '" is invalid!', 1439555561);
+ throw new Exception\InvalidPackageManifestException('The composer.json found for extension "' . PathUtility::basename($manifestPath) . '" is invalid!', 1439555561);
}
}
$extensionManagerConfiguration = $this->getExtensionEmConf($manifestPath);
$composerManifest = $this->mapExtensionManagerConfigurationToComposerManifest(
- basename($manifestPath),
+ PathUtility::basename($manifestPath),
$extensionManagerConfiguration,
$composerManifest ?: new \stdClass()
);
*/
protected function getExtensionEmConf($packagePath)
{
- $packageKey = basename($packagePath);
+ $packageKey = PathUtility::basename($packagePath);
$_EXTKEY = $packageKey;
$path = $packagePath . 'ext_emconf.php';
$EM_CONF = null;
throw new Exception\InvalidPackageManifestException('Invalid composer manifest in package path: ' . $packagePath, 1348146451);
}
if (isset($manifest->type) && substr($manifest->type, 0, 10) === 'typo3-cms-') {
- $packageKey = basename($packagePath);
+ $packageKey = PathUtility::basename($packagePath);
return preg_replace('/[^A-Za-z0-9._-]/', '', $packageKey);
}
$packageKey = str_replace('/', '.', $manifest->name);
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Imaging\GifBuilder;
/**
if (!file_exists($temporaryFileName)) {
// Create a error image
$graphicalFunctions = $this->getGraphicalFunctionsObject();
- $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', basename($originalFileName));
+ $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', PathUtility::basename($originalFileName));
}
}
if (!file_exists($temporaryFileName)) {
// Create a error image
$graphicalFunctions = $this->getGraphicalFunctionsObject();
- $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', basename($originalFileName));
+ $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', PathUtility::basename($originalFileName));
}
}
} else {
// Apparently this is not a folder, so the restriction
// is the folder so we restrict into this folder
- $finder->in(dirname($absoluteFileName));
+ $finder->in(PathUtility::dirname($absoluteFileName));
if (!is_file($absoluteFileName)
- && strpos(basename($absoluteFileName), '*') === false
- && substr(basename($absoluteFileName), -11) !== '.typoscript') {
+ && strpos(PathUtility::basename($absoluteFileName), '*') === false
+ && substr(PathUtility::basename($absoluteFileName), -11) !== '.typoscript') {
$absoluteFileName .= '*.typoscript';
}
- $finder->name(basename($absoluteFileName));
- $readableFilePrefix = dirname($filename);
+ $finder->name(PathUtility::basename($absoluteFileName));
+ $readableFilePrefix = PathUtility::dirname($filename);
}
foreach ($finder as $fileObject) {
$cmd = @self::exec('which ' . $cmd);
if (@is_executable($cmd)) {
self::$applications[$cmd]['app'] = $cmd;
- self::$applications[$cmd]['path'] = dirname($cmd) . '/';
+ self::$applications[$cmd]['path'] = PathUtility::dirname($cmd) . '/';
self::$applications[$cmd]['valid'] = true;
return true;
}
continue;
}
list($cmd, $cmdPath) = GeneralUtility::trimExplode('=', $val, true, 2);
- $cmdArr[$cmd]['app'] = basename($cmdPath);
- $cmdArr[$cmd]['path'] = dirname($cmdPath) . '/';
+ $cmdArr[$cmd]['app'] = PathUtility::basename($cmdPath);
+ $cmdArr[$cmd]['path'] = PathUtility::dirname($cmdPath) . '/';
$cmdArr[$cmd]['valid'] = true;
}
}
if (defined('TYPO3_PATH_WEB')) {
$retVal = $url;
} elseif (Environment::getCurrentScript() && defined('PATH_site')) {
- $lPath = PathUtility::stripPathSitePrefix(dirname(Environment::getCurrentScript())) . '/';
+ $lPath = PathUtility::stripPathSitePrefix(PathUtility::dirnameDuringBootstrap(Environment::getCurrentScript())) . '/';
$siteUrl = substr($url, 0, -strlen($lPath));
if (substr($siteUrl, -1) !== '/') {
$siteUrl .= '/';
self::mkdir_deep($temporaryPath);
}
if ($fileSuffix === '') {
- $tempFileName = $temporaryPath . basename(tempnam($temporaryPath, $filePrefix));
+ $tempFileName = $temporaryPath . PathUtility::basename(tempnam($temporaryPath, $filePrefix));
} else {
do {
$tempFileName = $temporaryPath . $filePrefix . mt_rand(1, PHP_INT_MAX) . $fileSuffix;
{
trigger_error('This method will be removed in TYPO3 v10.0, the functionality has been moved into AbstractXmlParser', E_USER_DEPRECATED);
// If $fileRef is already prefixed with "[language key]" then we should return it as is
- $fileName = basename($fileRef);
+ $fileName = PathUtility::basename($fileRef);
if (self::isFirstPartOfStr($fileName, $language . '.')) {
return $fileRef;
}
*/
public static function getRelativePathTo($targetPath)
{
- return self::getRelativePath(dirname(Environment::getCurrentScript()), $targetPath);
+ return self::getRelativePath(self::dirname(Environment::getCurrentScript()), $targetPath);
}
/**
return $targetPath;
} else {
// Make an absolute path out of it
- $targetPath = GeneralUtility::resolveBackPath(dirname(Environment::getCurrentScript()) . '/' . $targetPath);
+ $targetPath = GeneralUtility::resolveBackPath(self::dirname(Environment::getCurrentScript()) . '/' . $targetPath);
$targetPath = self::stripPathSitePrefix($targetPath);
if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
$targetPath = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . $targetPath;
return $result;
}
+ /**
+ * Returns parent directory's path
+ * Early during bootstrap there is no TYPO3_CONF_VARS yet so the setting for the system locale
+ * is also unavailable. The path of the parent directory is determined with a regular expression
+ * to avoid issues with locales.
+ *
+ * @param string $path
+ *
+ * @return string
+ */
+ public static function dirnameDuringBootstrap($path): string
+ {
+ return preg_replace('#(.*)(/|\\\\)([^\\\\/]+)$#', '$1', $path);
+ }
+
+ /**
+ * Returns filename part of a path
+ * Early during bootstrap there is no TYPO3_CONF_VARS yet so the setting for the system locale
+ * is also unavailable. The filename part is determined with a regular expression to avoid issues
+ * with locales.
+ *
+ * @param string $path
+ *
+ * @return string
+ */
+ public static function basenameDuringBootstrap($path): string
+ {
+ return preg_replace('#([^\\\\/]+)$#', '$1', $path);
+ }
+
/*********************
*
* Cleaning methods
*/
use TYPO3\CMS\Core\Resource\ResourceCompressor;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Testcase for the ResourceCompressor class
// we have to fix relative paths, if we aren't working on a file in our target directory
$relativeFilename = str_replace(PATH_site, '', $cssFile);
if (strpos($relativeFilename, $this->subject->_get('targetDirectory')) === false) {
- $compressedCss = $this->subject->_call('cssFixRelativeUrlPaths', $compressedCss, dirname($relativeFilename) . '/');
+ $compressedCss = $this->subject->_call('cssFixRelativeUrlPaths', $compressedCss, PathUtility::dirname($relativeFilename) . '/');
}
$this->assertEquals(file_get_contents($expected), $compressedCss, 'Group of file CSS assets optimized correctly.');
}
public function sendZipFileToBrowserAndDelete($fileName, $downloadName = '')
{
if ($downloadName === '') {
- $downloadName = basename($fileName, '.zip');
+ $downloadName = PathUtility::basename($fileName, '.zip');
}
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($fileName));
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Http\UrlHandlerInterface;
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
// This is a hack to work around ___FILE___ resolving symbolic links
- $PATH_site_real = dirname(realpath(PATH_site . 'typo3')) . '/';
+ $PATH_site_real = PathUtility::dirname(realpath(PATH_site . 'typo3')) . '/';
$file = $trace[0]['file'];
if (strpos($file, $PATH_site_real) === 0) {
$file = str_replace($PATH_site_real, '', $file);
use TYPO3\CMS\Core\Utility\File\BasicFileUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
case 'IMAGE':
$fileInfo = $this->getResource($conf['file'], $conf['file.']);
if ($fileInfo) {
- $this->combinedFileNames[] = preg_replace('/\\.[[:alnum:]]+$/', '', basename($fileInfo[3]));
+ $this->combinedFileNames[] = preg_replace('/\\.[[:alnum:]]+$/', '', PathUtility::basename($fileInfo[3]));
if ($fileInfo['processedFile'] instanceof ProcessedFile) {
// Use processed file, if a FAL file has been processed by GIFBUILDER (e.g. scaled/cropped)
$this->setup[$theKey . '.']['file'] = $fileInfo['processedFile']->getForLocalProcessing(false);
}
if ((string)$conf['text'] != '') {
// Char range map thingie:
- $fontBaseName = basename($conf['fontFile']);
+ $fontBaseName = PathUtility::basename($conf['fontFile']);
if (is_array($this->charRangeMap[$fontBaseName])) {
// Initialize splitRendering array:
if (!is_array($conf['splitRendering.'])) {
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
}
if ($languageFilePath === '' && $this->scriptRelPath) {
- $languageFilePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xlf';
+ $languageFilePath = 'EXT:' . $this->extKey . '/' . PathUtility::dirname($this->scriptRelPath) . '/locallang.xlf';
}
if ($languageFilePath !== '') {
/** @var $languageFactory LocalizationFactory */
use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Impexp\Domain\Repository\PresetRepository;
use TYPO3\CMS\Impexp\Export;
$mimeType = 'application/octet-stream';
header('Content-Type: ' . $mimeType);
header('Content-Length: ' . strlen($out));
- header('Content-Disposition: attachment; filename=' . basename($dlFile));
+ header('Content-Disposition: attachment; filename=' . PathUtility::basename($dlFile));
echo $out;
die;
}
// Just for security, check again. Should actually not be necessary.
if (!$bypassMountCheck) {
try {
- ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier(dirname($fileName));
+ ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier(PathUtility::dirname($fileName));
} catch (InsufficientFolderAccessPermissionsException $e) {
$this->error('ERROR: Filename "' . $fileName . '" was not allowed in destination path!');
return false;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* External standard parsers for indexed_search
unset($res);
$content = $this->pObj->convertHTMLToUtf8($content);
$contentArr = $this->pObj->splitHTMLContent($this->removeEndJunk($content));
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
$this->setLocaleForServerFileSystem(true);
}
break;
unset($res);
$content = $this->pObj->convertHTMLToUtf8($content);
$contentArr = $this->pObj->splitHTMLContent($this->removeEndJunk($content));
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
$this->setLocaleForServerFileSystem(true);
}
break;
$utf8_content = trim(strip_tags(str_replace('<', ' <', $content_xml)));
$contentArr = $this->pObj->splitRegularContent($utf8_content);
// Make sure the title doesn't expose the absolute path!
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
// Meta information
$cmd = $this->app['unzip'] . ' -p ' . escapeshellarg($absFile) . ' docProps/core.xml';
CommandUtility::exec($cmd, $res);
unset($res);
$utf8_content = trim(strip_tags(str_replace('<', ' <', $content_xml)));
$contentArr = $this->pObj->splitRegularContent($utf8_content);
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
// Make sure the title doesn't expose the absolute path!
// Meta information
$metaContent = GeneralUtility::xml2tree($meta_xml);
$contentCharset = 'utf-8';
$content = $this->pObj->convertHTMLToUtf8($content, $contentCharset);
$contentArr = $this->pObj->splitRegularContent($content);
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
// Make sure the title doesn't expose the absolute path!
$this->setLocaleForServerFileSystem(true);
break;
// Converting content:
$fileContent = $this->pObj->convertHTMLToUtf8(strip_tags(str_replace('<', ' <', $fileContent)), $charset);
$contentArr = $this->pObj->splitRegularContent($fileContent);
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
// Make sure the title doesn't expose the absolute path!
$this->setLocaleForServerFileSystem(true);
break;
$comment = '';
}
$contentArr = $this->pObj->splitRegularContent($comment);
- $contentArr['title'] = basename($absFile);
+ $contentArr['title'] = PathUtility::basename($absFile);
// Make sure the title doesn't expose the absolute path!
$this->setLocaleForServerFileSystem(true);
break;
// If no title (and why should there be...) then the file-name is set as title. This will raise the hits considerably if the search matches the document name.
if (is_array($contentArr) && !$contentArr['title']) {
// Substituting "_" for " " because many filenames may have this instead of a space char.
- $contentArr['title'] = str_replace('_', ' ', basename($absFile));
+ $contentArr['title'] = str_replace('_', ' ', PathUtility::basename($absFile));
}
return $contentArr;
}
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility;
$cParts = $this->fileContentParts($ext, $absFile);
foreach ($cParts as $cPKey) {
$this->internal_log = [];
- $this->log_push('Index: ' . str_replace('.', '_', basename($file)) . ($cPKey ? '#' . $cPKey : ''), '');
+ $this->log_push('Index: ' . str_replace('.', '_', PathUtility::basename($file)) . ($cPKey ? '#' . $cPKey : ''), '');
$Pstart = GeneralUtility::milliseconds();
$subinfo = ['key' => $cPKey];
// Setting page range. This is "0" (zero) when no division is made, otherwise a range like "1-3"
'contentHash' => $content_md5h,
'data_filename' => $file,
'item_type' => $storeItemType,
- 'item_title' => trim($contentParts['title']) ?: basename($file),
+ 'item_title' => trim($contentParts['title']) ?: PathUtility::basename($file),
'item_description' => $this->bodyDescription($contentParts),
'item_mtime' => $mtime,
'item_size' => $size,
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Upgrade wizard which goes through all files referenced in backend_layout.icon
$fileUid = null;
$sourcePath = PATH_site . $this->sourcePath . $item;
$targetDirectory = PATH_site . $fileadminDirectory . $this->targetPath;
- $targetPath = $targetDirectory . basename($item);
+ $targetPath = $targetDirectory . PathUtility::basenameDuringBootstrap($item);
// maybe the file was already moved, so check if the original file still exists
if (file_exists($sourcePath)) {
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Upgrade wizard which goes through all files referenced in fe_users::image
$fileUid = null;
$sourcePath = PATH_site . $this->sourcePath . $item;
$targetDirectory = PATH_site . $fileadminDirectory . $this->targetPath;
- $targetPath = $targetDirectory . basename($item);
+ $targetPath = $targetDirectory . PathUtility::basename($item);
// maybe the file was already moved, so check if the original file still exists
if (file_exists($sourcePath)) {
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Provide information about documentation files
$documentationFiles = [];
if ($this->isRelevantDirectory($docDirectory, $version)) {
$documentationFiles[$version] = [];
- $absolutePath = strtr(dirname($docDirectory), '\\', '/') . '/' . $version;
+ $absolutePath = strtr(PathUtility::dirname($docDirectory), '\\', '/') . '/' . $version;
$rstFiles = scandir($docDirectory);
foreach ($rstFiles as $file) {
$fileInfo = pathinfo($file);
$io->writeln('Keeping "' . $fileName . '" for record "' . $recReference . '"');
} else {
// Create unique name for file
- $newName = $fileFunc->getUniqueName(basename($fileName), dirname($absoluteFileName));
+ $newName = $fileFunc->getUniqueName(PathUtility::basename($fileName), PathUtility::dirname($absoluteFileName));
$io->writeln('Copying "' . $fileName . '" to "' . PathUtility::stripPathSitePrefix($newName) . '" for record "' . $recReference . '"');
if (!$dryRun) {
GeneralUtility::upload_copy_move($absoluteFileName, $newName);
clearstatcache();
if (@is_file($newName)) {
- $error = $referenceIndex->setReferenceValue($hash, basename($newName));
+ $error = $referenceIndex->setReferenceValue($hash, PathUtility::basename($newName));
if ($error) {
$io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"');
}
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Finds files within uploads/ which are not needed anymore
}
// If the file is a RTEmagic-image name and if so, we allow it
- if (preg_match('/^RTEmagic[P|C]_/', basename($value))) {
+ if (preg_match('/^RTEmagic[P|C]_/', PathUtility::basenameDuringBootstrap($value))) {
continue;
}
// Traverse the files and put into a large table:
while ($rec = $result->fetch()) {
$file = $rec['ref_string'];
- $filename = basename($file);
+ $filename = PathUtility::basenameDuringBootstrap($file);
if (strpos($filename, 'RTEmagicC_') === 0) {
// First time the file is referenced => build index
if (!is_array($allRteImagesInUse[$file])) {
// Traverse files
foreach ($files as $key => $value) {
// If the file is a RTEmagic-image name
- if (preg_match('/^RTEmagic[P|C]_/', basename($value))) {
+ if (preg_match('/^RTEmagic[P|C]_/', PathUtility::basenameDuringBootstrap($value))) {
$filesFound[] = $value;
continue;
}
if ($c === 0) {
$io->writeln('Keeping file ' . $fileName . ' for record ' . $recordID);
} else {
- $io->writeln('Copying file ' . basename($fileName) . ' for record ' . $recordID);
+ $io->writeln('Copying file ' . PathUtility::basenameDuringBootstrap($fileName) . ' for record ' . $recordID);
// Get directory prefix for file and set the original name
- $dirPrefix = dirname($fileName) . '/';
- $rteOrigName = basename($fileInfo['original']);
+ $dirPrefix = PathUtility::dirnameDuringBootstrap($fileName) . '/';
+ $rteOrigName = PathUtility::basenameDuringBootstrap($fileInfo['original']);
// If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file!
if ($rteOrigName && strpos($dirPrefix, 'uploads/') === 0 && @is_dir(PATH_site . $dirPrefix)) {
// From the "original" RTE filename, produce a new "original" destination filename which is unused.
$origDestName = $fileProcObj->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
// Create copy file name
$pI = pathinfo($fileName);
- $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension'];
+ $copyDestName = PathUtility::dirnameDuringBootstrap($origDestName) . '/RTEmagicC_' . substr(PathUtility::basenameDuringBootstrap($origDestName), 10) . '.' . $pI['extension'];
if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) {
- $io->writeln('Copying file ' . basename($fileName) . ' for record ' . $recordID . ' to ' . basename($copyDestName));
+ $io->writeln('Copying file ' . PathUtility::basenameDuringBootstrap($fileName) . ' for record ' . $recordID . ' to ' . PathUtility::basenameDuringBootstrap($copyDestName));
if (!$dryRun) {
// Making copies
GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName);
protected function resolvePath($resourcePath)
{
$absoluteFilePath = GeneralUtility::getFileAbsFileName($resourcePath);
- $absolutePath = dirname($absoluteFilePath);
- $fileName = basename($absoluteFilePath);
+ $absolutePath = PathUtility::dirname($absoluteFilePath);
+ $fileName = PathUtility::basename($absoluteFilePath);
return PathUtility::getRelativePathTo($absolutePath) . $fileName;
}