/** * Add templates to the archive * * @param ZipWriter $objArchive * @param string $strFolder */ protected function addTemplatesToArchive(ZipWriter $objArchive, $strFolder) { // Strip the templates folder name $strFolder = preg_replace('@^templates/@', '', $strFolder); // Re-add the templates folder name if ($strFolder == '') { $strFolder = 'templates'; } else { $strFolder = 'templates/' . $strFolder; } if (\Validator::isInsecurePath($strFolder)) { throw new \RuntimeException('Insecure path ' . $strFolder); } // Return if the folder does not exist if (!is_dir(TL_ROOT . '/' . $strFolder)) { return; } $arrAllowed = \StringUtil::trimsplit(',', strtolower(\Config::get('templateFiles'))); array_push($arrAllowed, 'sql'); // see #7048 // Add all template files to the archive foreach (scan(TL_ROOT . '/' . $strFolder) as $strFile) { if (preg_match('/\\.(' . implode('|', $arrAllowed) . ')$/', $strFile) && strncmp($strFile, 'be_', 3) !== 0 && strncmp($strFile, 'nl_', 3) !== 0) { $objArchive->addFile($strFolder . '/' . $strFile); } } }
protected function exportToDownload() { $strTmpFile = 'system/tmp/' . $this->strFilename; $strTmpFolder = str_replace('.' . $this->compressionType, '', $strTmpFile); $arrExportFields = array(); $arrDca = $GLOBALS['TL_DCA'][$this->linkedTable]['fields']; foreach (deserialize($this->tableFieldsForExport, true) as $strField) { if (strpos($strField, EXPORTER_RAW_FIELD_SUFFIX) !== false) { $arrExportFields[] = str_replace(EXPORTER_RAW_FIELD_SUFFIX, '', $strField) . ' AS ' . $strField; } else { $arrExportFields[] = $strField; } } $objDbResult = \Database::getInstance()->prepare("SELECT " . implode(',', $arrExportFields) . " FROM " . $this->linkedTable)->execute(); if (!$objDbResult->numRows > 0) { return; } switch ($this->compressionType) { default: $objZip = new ZipWriter($strTmpFile); break; } // write files while ($objDbResult->next()) { $arrRow = $objDbResult->row(); foreach ($arrRow as $key => $varValue) { $objDc = new DC_Table($this->linkedTable); $objDc->activeRecord = $objDbResult; $varValue = FormSubmission::prepareSpecialValueForPrint($varValue, $arrDca['fields'][$key], $this->linkedTable, $objDc); if (!is_array($varValue)) { $varValue = array($varValue); } foreach ($varValue as $strPath) { if ($strPath && ($objFile = new \File($strPath, true)) !== null && $objFile->exists()) { if (isset($GLOBALS['TL_HOOKS']['exporter_modifyMediaFilename']) && is_array($GLOBALS['TL_HOOKS']['exporter_modifyMediaFilename'])) { foreach ($GLOBALS['TL_HOOKS']['exporter_modifyMediaFilename'] as $callback) { $objCallback = \System::importStatic($callback[0]); $strFixedFilename = $objCallback->{$callback}[1]($objFile, $key, $strPath, $this); if ($strFixedFilename) { $strTmpFixedFilename = $strTmpFolder . '/' . ltrim($strFixedFilename, '/'); $objFile->copyTo($strTmpFixedFilename); $objFile->path = $strTmpFixedFilename; } } } switch ($this->compressionType) { default: $objZip->addFile($objFile->path); break; } } } } } switch ($this->compressionType) { default: $objZip->close(); break; } $objTmpFolder = new \Folder($strTmpFolder); if (is_dir(TL_ROOT . '/' . $objTmpFolder->path)) { $objTmpFolder->delete(); } $objFile = new \File($strTmpFile); $objFile->sendToBrowser(); }