downloadFile() public method

Download a file.
public downloadFile ( $fileId, $revision = null, $inline = false, $filename = null ) : boolean
$fileId int the file id of the file to download
$revision int the revision of the file to download
$inline boolean print file as inline instead of attachment, optional
$filename string The client-side download filename (optional)
return boolean
コード例 #1
0
ファイル: ArticleHandler.inc.php プロジェクト: selwyntcy/ojs
 /**
  * Download an article file
  * @param array $args
  * @param PKPRequest $request
  */
 function download($args, $request)
 {
     $articleId = isset($args[0]) ? $args[0] : 0;
     $galleyId = isset($args[1]) ? $args[1] : 0;
     $fileId = isset($args[2]) ? (int) $args[2] : 0;
     if ($this->userCanViewGalley($request, $articleId, $galleyId)) {
         if (!$fileId) {
             $submissionFile = $this->galley->getFile();
             if ($submissionFile) {
                 $fileId = $submissionFile->getFileId();
                 // The file manager expects the real article id.  Extract it from the submission file.
                 $articleId = $submissionFile->getSubmissionId();
             } else {
                 // no proof files assigned to this galley!
                 assert(false);
                 return null;
             }
         }
         if (!HookRegistry::call('ArticleHandler::download', array($this->article, &$this->galley, &$fileId))) {
             import('lib.pkp.classes.file.SubmissionFileManager');
             $submissionFileManager = new SubmissionFileManager($this->article->getContextId(), $articleId);
             $submissionFileManager->downloadFile($fileId, null, $request->getUserVar('inline') ? true : false);
         }
     }
 }
コード例 #2
0
ファイル: CatalogBookHandler.inc.php プロジェクト: NateWr/omp
 /**
  * Download a published monograph publication format file.
  * @param $args array
  * @param $request PKPRequest
  * @param $view boolean True iff inline viewer should be used, if available
  */
 function download($args, $request, $view = false)
 {
     $dispatcher = $request->getDispatcher();
     $publishedMonograph = $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLISHED_MONOGRAPH);
     $this->setupTemplate($request, $publishedMonograph);
     $press = $request->getPress();
     $monographId = array_shift($args);
     // Validated thru auth
     $representationId = array_shift($args);
     $bestFileId = array_shift($args);
     $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
     $publicationFormat = $publicationFormatDao->getByBestId($representationId, $publishedMonograph->getId());
     if (!$publicationFormat || !$publicationFormat->getIsApproved() || !$publicationFormat->getIsAvailable() || ($remoteURL = $publicationFormat->getRemoteURL())) {
         fatalError('Invalid publication format specified.');
     }
     $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
     import('lib.pkp.classes.submission.SubmissionFile');
     // File constants
     $submissionFile = $submissionFileDao->getByBestId($bestFileId, $publishedMonograph->getId());
     if (!$submissionFile) {
         $dispatcher->handle404();
     }
     $fileIdAndRevision = $submissionFile->getFileIdAndRevision();
     list($fileId, $revision) = array_map(create_function('$a', 'return (int) $a;'), preg_split('/-/', $fileIdAndRevision));
     import('lib.pkp.classes.file.SubmissionFileManager');
     $monographFileManager = new SubmissionFileManager($publishedMonograph->getContextId(), $publishedMonograph->getId());
     switch ($submissionFile->getAssocType()) {
         case ASSOC_TYPE_PUBLICATION_FORMAT:
             // Publication format file
             if ($submissionFile->getAssocId() != $publicationFormat->getId() || $submissionFile->getDirectSalesPrice() === null) {
                 fatalError('Invalid monograph file specified!');
             }
             break;
         case ASSOC_TYPE_SUBMISSION_FILE:
             // Dependent file
             $genreDao = DAORegistry::getDAO('GenreDAO');
             $genre = $genreDao->getById($submissionFile->getGenreId());
             if (!$genre->getDependent()) {
                 fatalError('Invalid monograph file specified!');
             }
             return $monographFileManager->downloadFile($fileId, $revision);
             break;
         default:
             fatalError('Invalid monograph file specified!');
     }
     $ompCompletedPaymentDao = DAORegistry::getDAO('OMPCompletedPaymentDAO');
     $user = $request->getUser();
     if ($submissionFile->getDirectSalesPrice() === '0' || $user && $ompCompletedPaymentDao->hasPaidPurchaseFile($user->getId(), $fileIdAndRevision)) {
         // Paid purchase or open access.
         if (!$user && $press->getSetting('restrictMonographAccess')) {
             // User needs to register first.
             Validation::redirectLogin();
         }
         // If inline viewing is requested, permit plugins to
         // handle the document.
         PluginRegistry::loadCategory('viewableFiles', true);
         if ($view) {
             if (HookRegistry::call('CatalogBookHandler::view', array(&$this, &$publishedMonograph, &$publicationFormat, &$submissionFile))) {
                 // If the plugin handled the hook, prevent further default activity.
                 exit;
             }
         }
         // Inline viewer not available, or viewing not wanted.
         // Download or show the file.
         $inline = $request->getUserVar('inline') ? true : false;
         if (!HookRegistry::call('CatalogBookHandler::download', array(&$this, &$publishedMonograph, &$publicationFormat, &$submissionFile, &$inline))) {
             return $monographFileManager->downloadFile($fileId, $revision, $inline);
         }
     }
     // Fall-through: user needs to pay for purchase.
     // Users that are not logged in need to register/login first.
     if (!$user) {
         return $request->redirect(null, 'login', null, null, array('source' => $request->url(null, null, null, array($monographId, $representationId, $bestFileId))));
     }
     // They're logged in but need to pay to view.
     import('classes.payment.omp.OMPPaymentManager');
     $ompPaymentManager = new OMPPaymentManager($request);
     if (!$ompPaymentManager->isConfigured()) {
         $request->redirect(null, 'catalog');
     }
     $queuedPayment = $ompPaymentManager->createQueuedPayment($press->getId(), PAYMENT_TYPE_PURCHASE_FILE, $user->getId(), $fileIdAndRevision, $submissionFile->getDirectSalesPrice(), $press->getSetting('currency'));
     $ompPaymentManager->displayPaymentForm($ompPaymentManager->queuePayment($queuedPayment), $queuedPayment);
 }