From 9654870cf641457d22724a6685da942aa979942e Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Tue, 25 Nov 2014 10:35:05 +0100 Subject: [PATCH] Back port the fixes from #7473 --- system/docs/CHANGELOG.md | 3 + system/modules/core/classes/Theme.php | 116 +++++++++++--------------- 2 files changed, 52 insertions(+), 67 deletions(-) diff --git a/system/docs/CHANGELOG.md b/system/docs/CHANGELOG.md index 2f89a43461..4cfdbdb528 100644 --- a/system/docs/CHANGELOG.md +++ b/system/docs/CHANGELOG.md @@ -4,6 +4,9 @@ Contao Open Source CMS changelog Version 3.2.17 (2015-01-XX) --------------------------- +### Fixed +Back port the fixes from #7475 and #7473. + ### Fixed Send the same cache headers for cached and uncached pages (see #7455). diff --git a/system/modules/core/classes/Theme.php b/system/modules/core/classes/Theme.php index c616220a59..6b56e0194e 100644 --- a/system/modules/core/classes/Theme.php +++ b/system/modules/core/classes/Theme.php @@ -315,21 +315,7 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) // Extract the files try { - $strFileName = $objArchive->file_name; - - // Support the old "tl_files" directory - if (strncmp($strFileName, 'tl_files/', 9) === 0) - { - $strFileName = substr($strFileName, 3); - } - - // Override the files directory - if ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files' && strncmp($strFileName, 'files/', 6) === 0) - { - $strFileName = preg_replace('@^files/@', $GLOBALS['TL_CONFIG']['uploadPath'] . '/', $strFileName); - } - - \File::putContent($strFileName, $objArchive->unzip()); + \File::putContent($this->customizeUploadPath($objArchive->file_name), $objArchive->unzip()); } catch (\Exception $e) { @@ -373,19 +359,7 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) { foreach ($arrNewFolders as $strFolder) { - // Support the old "tl_files" folder - if (strncmp($strFolder, 'tl_files/', 9) === 0) - { - $strFolder = substr($strFolder, 3); - } - - // Override the files directory - if ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files') - { - $strFolder = preg_replace('@^files/@', $GLOBALS['TL_CONFIG']['uploadPath'] . '/', $strFolder); - } - - \Dbafs::addResource($strFolder); + \Dbafs::addResource($this->customizeUploadPath($strFolder)); } } @@ -446,12 +420,6 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) $value = $fields->item($k)->nodeValue; $name = $fields->item($k)->getAttribute('name'); - // Support the old "tl_files" folder - if (strncmp($value, 'tl_files/', 9) === 0) - { - $value = substr($value, 3); - } - // Skip NULL values if ($value == 'NULL') { @@ -534,7 +502,7 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) } // Adjust the file paths in style sheets - elseif ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files' && ($table == 'tl_style_sheet' || $table == 'tl_style') && strpos($value, 'files') !== false) + elseif (($table == 'tl_style_sheet' || $table == 'tl_style') && strpos($value, 'files') !== false) { $tmp = deserialize($value); @@ -542,14 +510,14 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) { foreach ($tmp as $kk=>$vv) { - $tmp[$kk] = preg_replace('@^files/@', $GLOBALS['TL_CONFIG']['uploadPath'] . '/', $vv); + $tmp[$kk] = $this->customizeUploadPath($vv); } $value = serialize($tmp); } else { - $value = preg_replace('@^files/@', $GLOBALS['TL_CONFIG']['uploadPath'] . '/', $value); + $value = $this->customizeUploadPath($value); } } @@ -565,7 +533,7 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) // Do not use the FilesModel here – tables are locked! $objFile = $this->Database->prepare("SELECT uuid FROM tl_files WHERE path=?") ->limit(1) - ->execute($value); + ->execute($this->customizeUploadPath($value)); $value = $objFile->uuid; } @@ -580,16 +548,10 @@ protected function extractThemeFiles($arrFiles, $arrDbFields) { foreach ($tmp as $kk=>$vv) { - // Support the old "tl_files" folder - if (strncmp($vv, 'tl_files/', 9) === 0) - { - $vv = substr($vv, 3); - } - // Do not use the FilesModel here – tables are locked! $objFile = $this->Database->prepare("SELECT uuid FROM tl_files WHERE path=?") ->limit(1) - ->execute($vv); + ->execute($this->customizeUploadPath($vv)); $tmp[$kk] = $objFile->uuid; } @@ -892,15 +854,7 @@ protected function addDataRow(\DOMDocument $xml, \DOMElement $table, \Database\R if ($objFile !== null) { - // Standardize the upload path if it is not "files" - if ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files') - { - $v = 'files/' . preg_replace('@^'.preg_quote($GLOBALS['TL_CONFIG']['uploadPath'], '@').'/@', '', $objFile->path); - } - else - { - $v = $objFile->path; - } + $v = $this->standardizeUploadPath($objFile->path); } else { @@ -919,22 +873,14 @@ protected function addDataRow(\DOMDocument $xml, \DOMElement $table, \Database\R if ($objFiles !== null) { - // Standardize the upload path if it is not "files" - if ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files') - { - $arrTmp = array(); - - while ($objFiles->next()) - { - $arrTmp[] = 'files/' . preg_replace('@^'.preg_quote($GLOBALS['TL_CONFIG']['uploadPath'], '@').'/@', '', $objFiles->path); - } + $arrTmp = array(); - $v = serialize($arrTmp); - } - else + while ($objFiles->next()) { - $v = serialize($objFiles->fetchEach('path')); + $arrTmp[] = $this->standardizeUploadPath($objFiles->path); } + + $v = serialize($arrTmp); } else { @@ -942,6 +888,10 @@ protected function addDataRow(\DOMDocument $xml, \DOMElement $table, \Database\R } } } + elseif ($t == 'tl_style' && ($k == 'bgimage' || $k == 'liststyleimage')) + { + $v = $this->standardizeUploadPath($v); + } $value = $xml->createTextNode($v); $field->appendChild($value); @@ -1046,4 +996,36 @@ protected function addTemplatesToArchive(\ZipWriter $objArchive, $strFolder) } } } + + + /** + * Replace files/ with the custom upload folder name + * @param string + * @return string + */ + protected function customizeUploadPath($strPath) + { + if ($strPath == '') + { + return ''; + } + + return preg_replace('@^(tl_)?files/@', $GLOBALS['TL_CONFIG']['uploadPath'] . '/', $strPath); + } + + + /** + * Replace a custom upload folder name with files/ + * @param string + * @return string + */ + protected function standardizeUploadPath($strPath) + { + if ($strPath == '') + { + return ''; + } + + return preg_replace('@^' . preg_quote($GLOBALS['TL_CONFIG']['uploadPath'], '@') . '/@', 'files/', $strPath); + } }