From da4bd058c11e51d59115ccfc27daa27934c5b333 Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Mon, 23 Sep 2013 12:28:35 +0200 Subject: [PATCH] The "file" insert tag now also handles UUIDs (see #5512) --- contao/file.php | 13 +++- contao/page.php | 2 +- system/docs/CHANGELOG.md | 9 +++ system/modules/core/classes/StyleSheets.php | 3 +- .../core/library/Contao/Controller.php | 66 +++++++++++-------- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/contao/file.php b/contao/file.php index caac770823..1e8ea0d5f5 100644 --- a/contao/file.php +++ b/contao/file.php @@ -86,6 +86,17 @@ public function run() } $this->Session->set('filePickerRef', \Environment::get('request')); + $arrValues = array_filter(explode(',', Input::get('value'))); + + // Convert UUIDs to binary + foreach ($arrValues as $k=>$v) + { + // Can be a UUID or a path + if (\Validator::isUuid($v)) + { + $arrValues[$k] = String::uuidToBin($v); + } + } // Prepare the widget $objFileTree = new $GLOBALS['BE_FFL']['fileSelector'](array( @@ -93,7 +104,7 @@ public function run() 'strTable' => $strTable, 'strField' => $strField, 'strName' => $strField, - 'varValue' => array_map('String::uuidToBin', array_filter(explode(',', Input::get('value')))) + 'varValue' => $arrValues ), $objDca); $this->Template->main = $objFileTree->generate(); diff --git a/contao/page.php b/contao/page.php index a408755735..b65ceb16b8 100644 --- a/contao/page.php +++ b/contao/page.php @@ -93,7 +93,7 @@ public function run() 'strTable' => $strTable, 'strField' => $strField, 'strName' => $strField, - 'varValue' => explode(',', Input::get('value')) + 'varValue' => array_filter(explode(',', Input::get('value'))) ), $objDca); $this->Template->main = $objPageTree->generate(); diff --git a/system/docs/CHANGELOG.md b/system/docs/CHANGELOG.md index 6474d64256..ca4655dc31 100644 --- a/system/docs/CHANGELOG.md +++ b/system/docs/CHANGELOG.md @@ -4,6 +4,15 @@ Contao Open Source CMS Changelog Version 3.2.beta1 (2013-XX-XX) ------------------------------ +### New +The "file" insert tag now also handles UUIDs (see #5512). + +``` + +``` + +The insert tag can also be used in the internal style sheet editor. + ### Improved Purge the search index if a page is deleted (see #5897). diff --git a/system/modules/core/classes/StyleSheets.php b/system/modules/core/classes/StyleSheets.php index 04078861cc..adbf7939f6 100644 --- a/system/modules/core/classes/StyleSheets.php +++ b/system/modules/core/classes/StyleSheets.php @@ -958,7 +958,8 @@ public function compileDefinition($row, $blnWriteToFile=false, $vars=array(), $p $return = str_replace(array_keys($vars), array_values($vars), $return); } - return $return; + // Replace insert tags (see #5512) + return $this->replaceInsertTags($return, false); } diff --git a/system/modules/core/library/Contao/Controller.php b/system/modules/core/library/Contao/Controller.php index 1b7e79db6d..e0927abdc2 100644 --- a/system/modules/core/library/Contao/Controller.php +++ b/system/modules/core/library/Contao/Controller.php @@ -1567,43 +1567,55 @@ protected function replaceInsertTags($strBuffer, $blnCache=true) } break; - // Files from the templates directory + // Files (UUID or template path) case 'file': - $arrGet = $_GET; - \Input::resetCache(); - $strFile = $elements[1]; + if (\Validator::isUuid($elements[1])) + { + $objFile = \FilesModel::findByUuid(\String::uuidToBin($elements[1])); - // Take arguments and add them to the $_GET array - if (strpos($elements[1], '?') !== false) + if ($objFile !== null) + { + $arrCache[$strTag] = $objFile->path; + } + } + else { - $arrChunks = explode('?', urldecode($elements[1])); - $strSource = \String::decodeEntities($arrChunks[1]); - $strSource = str_replace('[&]', '&', $strSource); - $arrParams = explode('&', $strSource); + $arrGet = $_GET; + \Input::resetCache(); + $strFile = $elements[1]; - foreach ($arrParams as $strParam) + // Take arguments and add them to the $_GET array + if (strpos($elements[1], '?') !== false) { - $arrParam = explode('=', $strParam); - $_GET[$arrParam[0]] = $arrParam[1]; + $arrChunks = explode('?', urldecode($elements[1])); + $strSource = \String::decodeEntities($arrChunks[1]); + $strSource = str_replace('[&]', '&', $strSource); + $arrParams = explode('&', $strSource); + + foreach ($arrParams as $strParam) + { + $arrParam = explode('=', $strParam); + $_GET[$arrParam[0]] = $arrParam[1]; + } + + $strFile = $arrChunks[0]; } - $strFile = $arrChunks[0]; - } + // Sanitize path + $strFile = str_replace('../', '', $strFile); - // Sanitize path - $strFile = str_replace('../', '', $strFile); + // Include .php, .tpl, .xhtml and .html5 files + if (preg_match('/\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) + { + ob_start(); + include TL_ROOT . '/templates/' . $strFile; + $arrCache[$strTag] = ob_get_contents(); + ob_end_clean(); + } - // Include .php, .tpl, .xhtml and .html5 files - if (preg_match('/\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) - { - ob_start(); - include TL_ROOT . '/templates/' . $strFile; - $arrCache[$strTag] = ob_get_contents(); - ob_end_clean(); + $_GET = $arrGet; + \Input::resetCache(); } - - $_GET = $arrGet; - \Input::resetCache(); break; // HOOK: pass unknown tags to callback functions