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

Commit

Permalink
Limit the selectable file types depending on the element type (see #7003
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leofeyer committed Sep 23, 2014
1 parent 82ec73d commit 6940971
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 8 deletions.
3 changes: 3 additions & 0 deletions system/docs/CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS changelog
Version 3.4.0-beta1 (2014-10-XX)
--------------------------------

### Improved
Limit the selectable file types depending on the element type (see #7003).

### New
Prevent timing attacks when verifying passwords (see #7115, #5853).

Expand Down
27 changes: 27 additions & 0 deletions system/modules/core/controllers/BackendFile.php
Expand Up @@ -78,6 +78,16 @@ public function run()
$this->loadDataContainer($strTable);
$strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'];
$objDca = new $strDriver($strTable);
$objDca->field = $strField;

// Set the active record
$strModel = \Model::getClassFromTable($strTable);
$objModel = $strModel::findByPk(\Input::get('id'));

if ($objModel !== null)
{
$objDca->activeRecord = $objModel;
}

// AJAX request
if ($_POST && \Environment::get('isAjaxRequest'))
Expand All @@ -98,6 +108,23 @@ public function run()
}
}

// Call the load_callback
if (is_array($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback']))
{
foreach ($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$arrValues = $this->$callback[0]->$callback[1]($arrValues, $objDca);
}
elseif (is_callable($callback))
{
$arrValues = $callback($arrValues, $objDca);
}
}
}

// Prepare the widget
$class = $GLOBALS['BE_FFL']['fileSelector'];
$objFileTree = new $class($class::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, $arrValues, $strField, $strTable, $objDca));
Expand Down
30 changes: 29 additions & 1 deletion system/modules/core/controllers/BackendPage.php
Expand Up @@ -78,6 +78,16 @@ public function run()
$this->loadDataContainer($strTable);
$strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'];
$objDca = new $strDriver($strTable);
$objDca->field = $strField;

// Set the active record
$strModel = \Model::getClassFromTable($strTable);
$objModel = $strModel::findByPk(\Input::get('id'));

if ($objModel !== null)
{
$objDca->activeRecord = $objModel;
}

// AJAX request
if ($_POST && \Environment::get('isAjaxRequest'))
Expand All @@ -86,10 +96,28 @@ public function run()
}

$this->Session->set('filePickerRef', \Environment::get('request'));
$arrValues = array_filter(explode(',', \Input::get('value')));

// Call the load_callback
if (is_array($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback']))
{
foreach ($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$arrValues = $this->$callback[0]->$callback[1]($arrValues, $objDca);
}
elseif (is_callable($callback))
{
$arrValues = $callback($arrValues, $objDca);
}
}
}

// Prepare the widget
$class = $GLOBALS['BE_FFL']['pageSelector'];
$objPageTree = new $class($class::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, array_filter(explode(',', \Input::get('value'))), $strField, $strTable, $objDca));
$objPageTree = new $class($class::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, $arrValues, $strField, $strTable, $objDca));

$this->Template->main = $objPageTree->generate();
$this->Template->theme = \Backend::getTheme();
Expand Down
51 changes: 44 additions & 7 deletions system/modules/core/dca/tl_content.php
Expand Up @@ -217,6 +217,10 @@
'inputType' => 'fileTree',
'eval' => array('filesOnly'=>true, 'fieldType'=>'radio', 'mandatory'=>true, 'tl_class'=>'clr'),
'sql' => "binary(16) NULL",
'load_callback' => array
(
array('tl_content', 'setSingleSrcFlags')
),
'save_callback' => array
(
array('tl_content', 'storeFileMetaInformation')
Expand Down Expand Up @@ -533,7 +537,7 @@
'sql' => "blob NULL",
'load_callback' => array
(
array('tl_content', 'setFileTreeFlags')
array('tl_content', 'setMultiSrcFlags')
)
),
'orderSRC' => array
Expand Down Expand Up @@ -1576,22 +1580,55 @@ public function deleteElement($row, $href, $label, $title, $icon, $attributes)


/**
* Dynamically set the "isGallery" or "isDownloads" flag depending on the type
* Dynamically add flags to the "singleSRC" field
* @param mixed
* @param \DataContainer
* @return mixed
*/
public function setFileTreeFlags($varValue, DataContainer $dc)
public function setSingleSrcFlags($varValue, DataContainer $dc)
{
if ($dc->activeRecord)
{
if ($dc->activeRecord->type == 'gallery')
switch ($dc->activeRecord->type)
{
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['isGallery'] = true;
case 'text':
case 'hyperlink':
case 'image':
case 'accordionSingle':
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Config::get('validImageTypes');
break;

case 'download':
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Config::get('allowedDownload');
break;
}
elseif ($dc->activeRecord->type == 'downloads')
}

return $varValue;
}


/**
* Dynamically add flags to the "multiSRC" field
* @param mixed
* @param \DataContainer
* @return mixed
*/
public function setMultiSrcFlags($varValue, DataContainer $dc)
{
if ($dc->activeRecord)
{
switch ($dc->activeRecord->type)
{
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['isDownloads'] = true;
case 'gallery':
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['isGallery'] = true;
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Config::get('validImageTypes');
break;

case 'downloads':
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['isDownloads'] = true;
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Config::get('allowedDownload');
break;
}
}

Expand Down

0 comments on commit 6940971

Please sign in to comment.