/**
  * Return if the file does not exist
  * @return string
  */
 public function generate()
 {
     $this->arrDownloadarchives = unserialize($this->downloadarchive);
     if ($this->downloadarchive != null && !is_array($this->arrDownloadarchives)) {
         $this->arrDownloadarchives = array($this->downloadarchive);
     }
     // Return if there are no categories
     if (count($this->arrDownloadarchives) < 1) {
         return '';
     }
     if (TL_MODE == 'BE') {
         $title = array();
         foreach ($this->arrDownloadarchives as $archive) {
             $objDownloadarchivee = \FelixPfeiffer\Downloadarchive\DownloadarchiveModel::findByPk($archive);
             $title[] = $objDownloadarchivee->title;
         }
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['downloadarchive'][0]) . ' - ' . implode(", ", $title) . ' ###';
         return $objTemplate->parse();
     }
     $this->checkForPublishedArchives();
     $this->import('FrontendUser', 'User');
     foreach ($this->arrDownloadarchives as $archive) {
         $objFiles = \FelixPfeiffer\Downloadarchive\DownloadarchiveitemsModel::findPublishedByPid($archive);
         if ($objFiles === null) {
             continue;
         }
         while ($objFiles->next()) {
             $objFile = \FilesModel::findByUuid($objFiles->singleSRC);
             if (!file_exists(TL_ROOT . '/' . $objFile->path) || $objFiles->guests && FE_USER_LOGGED_IN || $objFiles->protected == 1 && !FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN) {
                 continue;
             }
             $arrGroups = deserialize($objFiles->groups);
             if ($objFiles->protected == 1 && is_array($arrGroups) && count(array_intersect($this->User->groups, $arrGroups)) < 1 && !BE_USER_LOGGED_IN) {
                 continue;
             }
             $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
             if (!in_array($objFile->extension, $allowedDownload)) {
                 continue;
             }
             $arrFile = $objFiles->row();
             $filename = $objFile->path;
             $arrFile['filename'] = $filename;
             $this->arrDownloadfiles[$archive][$filename] = $arrFile;
         }
     }
     $file = \Input::get('file', true);
     // Send the file to the browser and do not send a 404 header (see #4632)
     if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
         foreach ($this->arrDownloadfiles as $k => $archive) {
             if (array_key_exists($file, $archive)) {
                 \Controller::sendFileToBrowser($file);
             }
         }
     }
     return parent::generate();
 }
 /**
  * Add the type of input field
  * @param array
  * @return string
  */
 public function loadDirectory(DC_Table $dc)
 {
     $objItems = \FelixPfeiffer\Downloadarchive\DownloadarchiveitemsModel::findPublishedByPid($dc->id);
     if ($objItems !== null && $objItems->numRows > 0 || !$dc->activeRecord->loadDirectory) {
         return;
     }
     $objFolder = \FilesModel::findByUuid($dc->activeRecord->dirSRC);
     if ($objFolder->type == 'file') {
         return;
     }
     $this->extension = $dc->activeRecord->extension != '' ? explode(',', $dc->activeRecord->extension) : false;
     $arrFiles = $this->getFiles($objFolder->uuid, $dc->activeRecords->loadSubdir);
     if (!$arrFiles) {
         return;
     }
     $i = 0;
     foreach ($arrFiles as $file) {
         $objFile = new \File($file->path, true);
         $title = specialchars($objFile->basename);
         if ($dc->activeRecord->prefix != '') {
             $title = $dc->activeRecord->prefix . ' ' . $i;
         }
         $varSet = array('pid' => $dc->activeRecord->id, 'sorting' => ++$i * 64, 'tstamp' => time(), 'title' => $title, 'singleSRC' => $file->uuid, 'published' => $dc->activeRecord->publishAll);
         \Database::getInstance()->prepare("INSERT INTO tl_downloadarchiveitems %s")->set($varSet)->execute();
     }
 }