示例#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();
 }
示例#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();
 }
 /**
  * @param ModelSaveEvent $event
  */
 public function execute(ModelSaveEvent $event)
 {
     if (!$event->isDeleteStatement()) {
         return;
     }
     $upload = new Upload($this->applicationPath, Schema::MODULE_NAME);
     foreach ($event->getEntryId() as $item) {
         $upload->removeUploadedFile($this->filesRepository->getFileById($item));
         if ($this->commentsHelpers) {
             $this->commentsHelpers->deleteCommentsByModuleAndResult($this->modules->getModuleId(Schema::MODULE_NAME), $item);
         }
         $this->cache->getCacheDriver()->delete(Cache::CACHE_ID . $item);
         if ($this->uriAliasManager) {
             $this->uriAliasManager->deleteUriAlias(sprintf(Helpers::URL_KEY_PATTERN, $item));
         }
     }
 }
 /**
  * @param ModelSaveEvent $event
  */
 public function execute(ModelSaveEvent $event)
 {
     $this->cache->saveCache($event->getEntryId());
 }