コード例 #1
0
ファイル: DownloadController.php プロジェクト: ojs/ojs
 /**
  * @param ArticleFile $articleFile
  * @return BinaryFileResponse
  */
 public function articleFileAction(ArticleFile $articleFile)
 {
     $fileManager = $this->get('jb_fileuploader.file_history.manager');
     $rootDir = $this->getParameter('kernel.root_dir');
     $assetHelper = $this->get('templating.helper.assets');
     $fileHistory = $fileManager->findOneByFileName($articleFile->getFile());
     $path = $rootDir . '/../web' . $fileManager->getUrl($fileHistory);
     $path = preg_replace('/\\?' . $assetHelper->getVersion() . '$/', '', $path);
     $explode = explode('.', $fileHistory->getOriginalName());
     $mime = end($explode);
     if (!empty($articleFile->getArticle()->getDoi())) {
         $fileOriginalName = $articleFile->getArticle()->getDoi() . '-' . $articleFile->getId() . '.' . $mime;
     } else {
         $fileOriginalName = $articleFile->getArticle() . '-' . $articleFile->getId() . '.' . $mime;
     }
     $fileOriginalName = str_replace('/', '-', $fileOriginalName);
     $fileOriginalName = str_replace('\\', '-', $fileOriginalName);
     $fs = new Filesystem();
     if (!$fs->exists($path)) {
         throw $this->createNotFoundException();
     }
     $response = new BinaryFileResponse($path);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, preg_replace('/[[:^print:]]/', '_', $fileOriginalName));
     $event = new DownloadArticleFileEvent($articleFile);
     $dispatcher = $this->get('event_dispatcher');
     $dispatcher->dispatch(SiteEvents::DOWNLOAD_ARTICLE_FILE, $event);
     return $response;
 }
コード例 #2
0
 /**
  * Deletes a ArticleFile entity.
  *
  * @param  Request          $request
  * @param  ArticleFile      $articleFile
  * @param  Article          $article
  * @return RedirectResponse
  */
 public function deleteAction(Request $request, ArticleFile $articleFile, Article $article)
 {
     $journal = $this->get('ojs.journal_service')->getSelectedJournal();
     $em = $this->getDoctrine()->getManager();
     if (!$this->isGranted('EDIT', $journal, 'articles')) {
         throw new AccessDeniedException("You not authorized for this page!");
     }
     if ($articleFile->getArticle() !== $article) {
         $this->throw404IfNotFound($articleFile);
     }
     $csrf = $this->get('security.csrf.token_manager');
     $token = $csrf->getToken('ojs_journal_article_file' . $articleFile->getId());
     if ($token != $request->get('_token')) {
         throw new TokenNotFoundException("Token Not Found!");
     }
     $em->remove($articleFile);
     $em->flush();
     $this->successFlashBag('successful.remove');
     return $this->redirectToRoute('ojs_journal_article_file_index', ['articleId' => $article->getId(), 'journalId' => $journal->getId()]);
 }