Exemple #1
0
 /**
  * @param int $id
  * @return array
  * @throws Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id)
 {
     if ($this->filesRepository->resultExists($id, $this->date->getCurrentDateTime()) === true) {
         $this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
         $file = $this->filesCache->getCache($id);
         $this->breadcrumb->append($this->translator->t('files', 'files'), 'files')->append($file['category_title'], 'files/index/files/cat_' . $file['category_id'])->append($file['title']);
         $settings = $this->config->getSettings(Files\Installer\Schema::MODULE_NAME);
         $file['text'] = $this->view->fetchStringAsTemplate($file['text']);
         return ['file' => $file, 'dateformat' => $settings['dateformat'], 'comments_allowed' => $settings['comments'] == 1 && $file['comments'] == 1];
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }
Exemple #2
0
 /**
  * @param int $id
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  * @throws Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id)
 {
     if ($this->filesRepository->resultExists($id, $this->date->getCurrentDateTime()) === true) {
         $file = $this->filesCache->getCache($id);
         $path = $this->appPath->getUploadsDir() . 'files/';
         if (is_file($path . $file['file'])) {
             $ext = strrchr($file['file'], '.');
             $filename = $this->stringFormatter->makeStringUrlSafe($file['title']) . $ext;
             $response = new BinaryFileResponse($path . $file['file']);
             $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
             return $response;
         } elseif (preg_match('/^([a-z]+):\\/\\//', $file['file'])) {
             // External file
             return $this->redirect()->toNewPage($file['file']);
         }
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }