Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Use DIRECTORY_SEPARATOR in conjunction with str_replace() (see #7769
Browse files Browse the repository at this point in the history
).
  • Loading branch information
leofeyer committed Apr 20, 2015
1 parent e4a5b62 commit de0e6f5
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions system/docs/CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS changelog
Version 3.5.0-RC1 (2015-04-XX)
------------------------------

### Fixed
Use `DIRECTORY_SEPARATOR` in conjunction with `str_replace()` (see #7769).

### Changed
`Controller::replaceInsertTags()` is now public static.

Expand Down
8 changes: 4 additions & 4 deletions system/helper/functions.php
Expand Up @@ -58,10 +58,10 @@ function __error($intType, $strMessage, $strFile, $intLine)
$strMessage = sprintf('<strong>%s</strong>: %s in <strong>%s</strong> on line <strong>%s</strong>',
$arrErrors[$intType],
$strMessage,
str_replace(TL_ROOT . '/', '', $strFile), // see #4971
str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $strFile), // see #4971
$intLine);

$strMessage .= "\n" . '<pre style="margin:11px 0 0">' . "\n" . str_replace(TL_ROOT . '/', '', $e->getTraceAsString()) . "\n" . '</pre>';
$strMessage .= "\n" . '<pre style="margin:11px 0 0">' . "\n" . str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $e->getTraceAsString()) . "\n" . '</pre>';
echo '<br>' . $strMessage;
}

Expand Down Expand Up @@ -99,10 +99,10 @@ function __exception(Exception $e)
$strMessage = sprintf('<strong>Fatal error</strong>: Uncaught exception <strong>%s</strong> with message <strong>%s</strong> thrown in <strong>%s</strong> on line <strong>%s</strong>',
get_class($e),
$e->getMessage(),
str_replace(TL_ROOT . '/', '', $e->getFile()),
str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $e->getFile()),
$e->getLine());

$strMessage .= "\n" . '<pre style="margin:11px 0 0">' . "\n" . str_replace(TL_ROOT . '/', '', $e->getTraceAsString()) . "\n" . '</pre>';
$strMessage .= "\n" . '<pre style="margin:11px 0 0">' . "\n" . str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $e->getTraceAsString()) . "\n" . '</pre>';
echo '<br>' . $strMessage;
}

Expand Down
2 changes: 1 addition & 1 deletion system/modules/core/controllers/BackendInstall.php
Expand Up @@ -647,7 +647,7 @@ protected function importExampleWebsite()
// Add the relative paths
foreach ($objFiles as $objFile)
{
$arrTemplates[] = str_replace(TL_ROOT . '/templates/', '', $objFile->getPathname());
$arrTemplates[] = str_replace(TL_ROOT . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR, '', $objFile->getPathname());
}

$strTemplates = '<option value="">-</option>';
Expand Down
2 changes: 1 addition & 1 deletion system/modules/core/dca/tl_templates.php
Expand Up @@ -302,7 +302,7 @@ public function addNewTemplate()

if (in_array($strExtension, $arrAllowed))
{
$strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
$strRelpath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $objFile->getPathname());
$arrAllTemplates[$strModule][basename($strRelpath)] = $strRelpath;
}
}
Expand Down
10 changes: 5 additions & 5 deletions system/modules/core/drivers/DC_Folder.php
Expand Up @@ -809,7 +809,7 @@ public function delete($source=null)
}

// Add a log entry
$this->log('File or folder "'.str_replace(TL_ROOT.'/', '', $source).'" has been deleted', __METHOD__, TL_FILES);
$this->log('File or folder "' . str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $source) . '" has been deleted', __METHOD__, TL_FILES);

// Redirect
if (!$blnDoNotRedirect)
Expand Down Expand Up @@ -1943,7 +1943,7 @@ protected function save($varValue)
{
foreach (glob(TL_ROOT . '/assets/images/*/' . $this->varValue . '-*' . $this->strExtension) as $strThumbnail)
{
$this->Files->delete(str_replace(TL_ROOT, '', $strThumbnail));
$this->Files->delete(str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $strThumbnail));
}
}

Expand Down Expand Up @@ -2279,7 +2279,7 @@ protected function generateTree($path, $intMargin, $mount=false, $blnProtected=f
{
if ($v == '__new__')
{
$this->Files->rmdir(str_replace(TL_ROOT.'/', '', $path) . '/' . $v);
$this->Files->rmdir(str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $path) . '/' . $v);
}
else
{
Expand All @@ -2300,7 +2300,7 @@ protected function generateTree($path, $intMargin, $mount=false, $blnProtected=f
{
$md5 = substr(md5($folders[$f]), 0, 8);
$content = scan($folders[$f]);
$currentFolder = str_replace(TL_ROOT.'/', '', $folders[$f]);
$currentFolder = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $folders[$f]);
$session['filetree'][$md5] = is_numeric($session['filetree'][$md5]) ? $session['filetree'][$md5] : 0;
$currentEncoded = $this->urlEncode($currentFolder);
$countFiles = count($content);
Expand Down Expand Up @@ -2374,7 +2374,7 @@ protected function generateTree($path, $intMargin, $mount=false, $blnProtected=f
$thumbnail = '';
$popupWidth = 600;
$popupHeight = 161;
$currentFile = str_replace(TL_ROOT.'/', '', $files[$h]);
$currentFile = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $files[$h]);

$objFile = new \File($currentFile, true);

Expand Down
4 changes: 2 additions & 2 deletions system/modules/core/forms/Form.php
Expand Up @@ -425,7 +425,7 @@ protected function processFormData($arrSubmitted, $arrLabels, $arrFields)
// Add a link to the uploaded file
if ($file['uploaded'])
{
$uploaded .= "\n" . \Environment::get('base') . str_replace(TL_ROOT . '/', '', dirname($file['tmp_name'])) . '/' . rawurlencode($file['name']);
$uploaded .= "\n" . \Environment::get('base') . str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', dirname($file['tmp_name'])) . '/' . rawurlencode($file['name']);
continue;
}

Expand Down Expand Up @@ -474,7 +474,7 @@ protected function processFormData($arrSubmitted, $arrLabels, $arrFields)
{
if ($v['uploaded'])
{
$arrSet[$k] = str_replace(TL_ROOT . '/', '', $v['tmp_name']);
$arrSet[$k] = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $v['tmp_name']);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/modules/core/library/Contao/BaseTemplate.php
Expand Up @@ -106,7 +106,7 @@ public function parse()
// Add start and end markers in debug mode
if (\Config::get('debugMode'))
{
$strRelPath = str_replace(TL_ROOT . '/', '', $this->getTemplate($this->strTemplate, $this->strFormat));
$strRelPath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $this->getTemplate($this->strTemplate, $this->strFormat));
$strBuffer = "\n<!-- TEMPLATE START: $strRelPath -->\n$strBuffer\n<!-- TEMPLATE END: $strRelPath -->\n";
}

Expand Down
4 changes: 2 additions & 2 deletions system/modules/core/library/Contao/Dbafs.php
Expand Up @@ -118,7 +118,7 @@ public static function addResource($strResource, $blnUpdateFolders=true)
// Add the relative path
foreach ($objFiles as $objFile)
{
$strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
$strRelpath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $objFile->getPathname());

if ($objFile->isDir())
{
Expand Down Expand Up @@ -493,7 +493,7 @@ public static function syncFiles()
// Create or update the database entries
foreach ($objFiles as $objFile)
{
$strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
$strRelpath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $objFile->getPathname());

// Get all subfiles in a single query
if ($objFile->isDir())
Expand Down
2 changes: 1 addition & 1 deletion system/modules/core/library/Contao/Filter/SyncExclude.php
Expand Up @@ -60,7 +60,7 @@ public function accept()
return false;
}

$strRelpath = str_replace(TL_ROOT . '/', '', $this->current()->getPathname());
$strRelpath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $this->current()->getPathname());

// The resource is an exempt folder
if (in_array($strRelpath, $this->arrExempt))
Expand Down
2 changes: 1 addition & 1 deletion system/modules/core/library/Contao/Folder.php
Expand Up @@ -357,7 +357,7 @@ protected function getHash()
{
if (strncmp($i->getFilename(), '.', 1) !== 0)
{
$arrFiles[] = str_replace(TL_ROOT . '/' . $this->strFolder . '/', '', $i->getPathname());
$arrFiles[] = str_replace(TL_ROOT . DIRECTORY_SEPARATOR . $this->strFolder . DIRECTORY_SEPARATOR, '', $i->getPathname());
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/modules/core/widgets/FileSelector.php
Expand Up @@ -287,7 +287,7 @@ protected function renderFiletree($path, $intMargin, $mount=false, $blnProtected
$tid = md5($folders[$f]);
$folderAttribute = 'style="margin-left:20px"';
$session[$node][$tid] = is_numeric($session[$node][$tid]) ? $session[$node][$tid] : 0;
$currentFolder = str_replace(TL_ROOT.'/', '', $folders[$f]);
$currentFolder = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $folders[$f]);
$blnIsOpen = ($session[$node][$tid] == 1 || count(preg_grep('/^' . preg_quote($currentFolder, '/') . '\//', $this->varValue)) > 0);

// Add a toggle button if there are childs
Expand Down Expand Up @@ -345,7 +345,7 @@ protected function renderFiletree($path, $intMargin, $mount=false, $blnProtected
for ($h=0, $c=count($files); $h<$c; $h++)
{
$thumbnail = '';
$currentFile = str_replace(TL_ROOT . '/', '', $files[$h]);
$currentFile = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $files[$h]);
$currentEncoded = $this->urlEncode($currentFile);

$objFile = new \File($currentFile, true);
Expand Down

0 comments on commit de0e6f5

Please sign in to comment.