public static function addEnclosuresToTemplate($objTemplate, $arrItem, $strKey = 'enclosure')
{
$arrEnclosures = \StringUtil::deserialize($arrItem[$strKey]);
if (!is_array($arrEnclosures) || empty($arrEnclosures)) {
return;
}
$objFiles = \FilesModel::findMultipleByUuids($arrEnclosures);
if ($objFiles === null) {
return;
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #5178)
if ($file != '') {
while ($objFiles->next()) {
if ($file == $objFiles->path) {
static::sendFileToBrowser($file);
}
}
$objFiles->reset();
}
/** @var PageModel $objPage */
global $objPage;
$arrEnclosures = array();
$allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
// Add download links
while ($objFiles->next()) {
if ($objFiles->type == 'file') {
if (!in_array($objFiles->extension, $allowedDownload) || !is_file(TL_ROOT . '/' . $objFiles->path)) {
continue;
}
$objFile = new \File($objFiles->path);
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFiles->path);
$arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
if (empty($arrMeta) && $objPage->rootFallbackLanguage !== null) {
$arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
}
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
}
$arrEnclosures[] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => static::getReadableSize($objFile->filesize), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname, 'enclosure' => $objFiles->path);
}
}
$objTemplate->enclosure = $arrEnclosures;
}