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

Commit

Permalink
The "file" insert tag now also handles UUIDs (see #5512)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 23, 2013
1 parent d4f7b65 commit da4bd05
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 30 deletions.
13 changes: 12 additions & 1 deletion contao/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ 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(
'strId' => $strField,
'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();
Expand Down
2 changes: 1 addition & 1 deletion contao/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions system/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

```
<img src="{{file::bb643d42-0026-ba97-11e3-ccd6e14e1c8a}}" alt="">
```

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).

Expand Down
3 changes: 2 additions & 1 deletion system/modules/core/classes/StyleSheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
66 changes: 39 additions & 27 deletions system/modules/core/library/Contao/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da4bd05

Please sign in to comment.