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

Commit

Permalink
Back port the fixes from #7473
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jan 20, 2015
1 parent db1c2cc commit b51a146
Showing 1 changed file with 49 additions and 67 deletions.
116 changes: 49 additions & 67 deletions contao/classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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')
{
Expand Down Expand Up @@ -534,22 +502,22 @@ 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);

if (is_array($tmp))
{
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);
}
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
{
Expand All @@ -919,29 +873,25 @@ 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
{
$v = 'NULL';
}
}
}
elseif ($t == 'tl_style' && ($k == 'bgimage' || $k == 'liststyleimage'))
{
$v = $this->standardizeUploadPath($v);
}

$value = $xml->createTextNode($v);
$field->appendChild($value);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit b51a146

Please sign in to comment.