/** * Display the files associated with a journal. * @param $args array * @param $request PKPRequest */ function files($args, $request) { $this->validate(); $this->setupTemplate($request, true); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $templateMgr = TemplateManager::getManager($request); $this->_parseDirArg($args, $currentDir, $parentDir); $currentPath = $this->_getRealFilesDir($request, $currentDir); if (@is_file($currentPath)) { if ($request->getUserVar('download')) { $fileManager->downloadFile($currentPath); } else { $fileManager->downloadFile($currentPath, $this->_fileMimeType($currentPath), true); } } else { $files = array(); if ($dh = @opendir($currentPath)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $filePath = $currentPath . '/' . $file; $isDir = is_dir($filePath); $info = array('name' => $file, 'isDir' => $isDir, 'mimetype' => $isDir ? '' : $this->_fileMimeType($filePath), 'mtime' => filemtime($filePath), 'size' => $isDir ? '' : $fileManager->getNiceFileSize(filesize($filePath))); $files[$file] = $info; } } closedir($dh); } ksort($files); $templateMgr->assign('files', $files); $templateMgr->assign('currentDir', $currentDir); $templateMgr->assign('parentDir', $parentDir); $templateMgr->display('manager/files/index.tpl'); } }
/** * Provide an endpoint for the PLN staging server to retrieve a deposit * @param array $args * @param Request $request */ function deposits($args, &$request) { $journal =& $request->getJournal(); $depositDao =& DAORegistry::getDAO('DepositDAO'); $fileManager = new FileManager(); $dispatcher = $request->getDispatcher(); $depositUuid = !isset($args[0]) || empty($args[0]) ? null : $args[0]; // sanitize the input if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/', $depositUuid)) { error_log(__("plugins.generic.pln.error.handler.uuid.invalid")); $dispatcher->handle404(); return FALSE; } $deposit =& $depositDao->getDepositByUUID($journal->getId(), $depositUuid); if (!$deposit) { error_log(__("plugins.generic.pln.error.handler.uuid.notfound")); $dispatcher->handle404(); return FALSE; } $depositPackage = new DepositPackage($deposit, null); $depositBag = $depositPackage->getPackageFilePath(); if (!$fileManager->fileExists($depositBag)) { error_log("plugins.generic.pln.error.handler.file.notfound"); $dispatcher->handle404(); return FALSE; } return $fileManager->downloadFile($depositBag, mime_content_type($depositBag), TRUE); }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($fileId, $userId, $inline = false) { $temporaryFile =& $this->getFile($fileId, $userId); if (isset($temporaryFile)) { $filePath = $this->filesDir . $temporaryFile->getFileName(); return parent::downloadFile($filePath, null, $inline); } else { return false; } }
/** * Provide an endpoint for the PLN staging server to retrieve a deposit * @param array $args * @param Request $request */ function deposits($args, &$request) { $journal =& $request->getJournal(); $plnPlugin =& PluginRegistry::getPlugin('generic', PLN_PLUGIN_NAME); $depositDao =& DAORegistry::getDAO('DepositDAO'); $fileManager = new FileManager(); $depositUuid = !isset($args[0]) || empty($args[0]) ? null : $args[0]; // sanitize the input if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/', $depositUuid)) { return FALSE; } $deposit =& $depositDao->getDepositByUUID($journal->getId(), $depositUuid); if (!$deposit) { return FALSE; } $depositPackage = new DepositPackage($deposit); $depositBag = $depositPackage->getPackageFilePath(); if (!$fileManager->fileExists($depositBag)) { return FALSE; } //TODO: Additional check here for journal UUID in HTTP header from staging server return $fileManager->downloadFile($depositBag, mime_content_type($depositBag), TRUE); }
/** * Display the files associated with a journal. */ function files($args) { $this->validate(); $this->setupTemplate(true); import('lib.pkp.classes.file.FileManager'); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageHierarchy', array(array(Request::url(null, 'manager'), 'manager.journalManagement'))); FilesHandler::parseDirArg($args, $currentDir, $parentDir); $currentPath = FilesHandler::getRealFilesDir($currentDir); if (@is_file($currentPath)) { $fileMgr = new FileManager(); if (Request::getUserVar('download')) { $fileMgr->downloadFile($currentPath); } else { $fileMgr->viewFile($currentPath, FilesHandler::fileMimeType($currentPath)); } } else { $files = array(); if ($dh = @opendir($currentPath)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $filePath = $currentPath . '/' . $file; $isDir = is_dir($filePath); $info = array('name' => $file, 'isDir' => $isDir, 'mimetype' => $isDir ? '' : FilesHandler::fileMimeType($filePath), 'mtime' => filemtime($filePath), 'size' => $isDir ? '' : FileManager::getNiceFileSize(filesize($filePath))); $files[$file] = $info; } } closedir($dh); } ksort($files); $templateMgr->assign_by_ref('files', $files); $templateMgr->assign('currentDir', $currentDir); $templateMgr->assign('parentDir', $parentDir); $templateMgr->assign('helpTopicId', 'journal.managementPages.fileBrowser'); $templateMgr->display('manager/files/index.tpl'); } }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $press = $request->getPress(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'export': $exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * View a file inline (variant of downloadFile). * @see FileManager::downloadFile */ function viewFile($filePath, $type = null) { FileManager::downloadFile($filePath, $type, true); }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($fileId, $inline = false) { $issueFileDao =& DAORegistry::getDAO('IssueFileDAO'); $issueFile =& $issueFileDao->getIssueFile($fileId); if ($issueFile) { $fileType = $issueFile->getFileType(); $filePath = $this->getFilesDir() . $this->contentTypeToPath($issueFile->getContentType()) . '/' . $issueFile->getFileName(); return parent::downloadFile($filePath, $fileType, $inline); } else { return false; } }
/** * Download all monograph files as an archive * @param $monographId integer * @param $monographFiles ArrayItemIterator * @return boolean */ function downloadFilesArchive($monographId, &$monographFiles) { $filesDir = MonographFileManager::_getFilesDir($monographId); $filePaths = array(); while ($monographFile =& $monographFiles->next()) { /* @var $monographFile MonographFile */ // Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path) $filePath = str_replace($filesDir, '', $monographFile->getFilePath()); // Add files to be archived to array $filePaths[] = escapeshellarg($filePath); } // Create the archive and download the file $archivePath = $filesDir . "monograph_" . $monographId . "_files.tar.gz"; $tarCommand = "tar czf " . $archivePath . " -C \"" . $filesDir . "\" " . implode(" ", $filePaths); exec($tarCommand); if (file_exists($archivePath)) { parent::downloadFile($archivePath); return true; } else { return false; } }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $revision int the revision of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($fileId, $revision = null, $inline = false) { $articleFile =& $this->getFile($fileId, $revision); if (isset($articleFile)) { $fileType = $articleFile->getFileType(); $filePath = $this->filesDir . $this->fileStageToPath($articleFile->getFileStage()) . '/' . $articleFile->getFileName(); return parent::downloadFile($filePath, $fileType, $inline); } else { return false; } }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $press = $request->getPress(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.native.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION); $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.inportexport.native.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); $deployment = new NativeImportExportDeployment($press, $user); libxml_use_internal_errors(true); $submissions = $this->importSubmissions(file_get_contents($temporaryFilePath), $deployment); $templateMgr->assign('submissions', $submissions); $validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;')); $templateMgr->assign('validationErrors', $validationErrors); libxml_clear_errors(); // Are there any submissions import errors $processedSubmissionsIds = $deployment->getProcessedObjectsIds(ASSOC_TYPE_SUBMISSION); if (!empty($processedSubmissionsIds)) { $submissionsErrors = array_filter($processedSubmissionsIds, create_function('$a', 'return !empty($a);')); if (!empty($submissionsErrors)) { $templateMgr->assign('submissionsErrors', $processedSubmissionsIds); } } // If there are any submissions or validataion errors // delete imported submissions. if (!empty($submissionsErrors) || !empty($validationErrors)) { // remove all imported sumissions $deployment->removeImportedObjects(ASSOC_TYPE_SUBMISSION); } // Display the results $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * Download all of the monograph files as one compressed file. * @param $args array * @param $request Request */ function downloadAllFiles($args, &$request) { // Retrieve the monograph. $monograph =& $this->getMonograph(); $monographId = $monograph->getId(); // Find out the paths of all files in this grid. import('classes.file.MonographFileManager'); $filesDir = MonographFileManager::_getFilesDir($monographId); $filePaths = array(); foreach ($this->getGridDataElements($request) as $submissionFileData) { $monographFile =& $submissionFileData['submissionFile']; /* @var $monographFile MonographFile */ // Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path) $filePath = str_replace($filesDir, '', $monographFile->getFilePath()); // Add files to be archived to array $filePaths[] = escapeshellarg($filePath); unset($monographFile); } // Create a temporary file. $archivePath = tempnam('/tmp', 'sf-'); // Create the archive and download the file. exec(Config::getVar('cli', 'tar') . ' -c -z ' . '-f ' . escapeshellarg($archivePath) . ' ' . '-C ' . escapeshellarg($filesDir) . ' ' . implode(' ', array_map('escapeshellarg', $filePaths))); if (file_exists($archivePath)) { FileManager::downloadFile($archivePath); FileManager::deleteFile($archivePath); } else { fatalError('Creating archive with submission files failed!'); } }
/** * Download all passed files. * @param $args array * @param $request Request */ function downloadAllFiles($args, $request) { // Retrieve the authorized objects. $submissionFiles = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION_FILES); $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION); // Find out the paths of all files in this grid. $context = $request->getContext(); $filePaths = array(); $fileManager = $this->_getFileManager($context->getId(), $submission->getId()); $filesDir = $fileManager->getBasePath(); foreach ($submissionFiles as $submissionFile) { // Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path) $filePaths[str_replace($filesDir, '', $submissionFile->getFilePath())] = $submissionFile->getClientFileName(); } import('lib.pkp.classes.file.FileArchive'); $fileArchive = new FileArchive(); $archivePath = $fileArchive->create($filePaths, $filesDir); if (file_exists($archivePath)) { $fileManager = new FileManager(); if ($fileArchive->zipFunctional()) { $fileManager->downloadFile($archivePath, 'application/x-zip', false, 'files.zip'); } else { $fileManager->downloadFile($archivePath, 'application/x-gtar', false, 'files.tar.gz'); } $fileManager->deleteFile($archivePath); } else { fatalError('Creating archive with submission files failed!'); } }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $context = $request->getContext(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.importexport.users.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); libxml_use_internal_errors(true); $users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user); $validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;')); $templateMgr->assign('validationErrors', $validationErrors); libxml_clear_errors(); $templateMgr->assign('users', $users); $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; case 'exportAllUsers': $exportXml = $this->exportAllUsers($request->getContext(), $request->getUser()); import('lib.pkp.classes.file.TemporaryFileManager'); $fileManager = new TemporaryFileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $revision int the revision of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($monographId, $fileId, $revision = null, $inline = false) { $returner = false; $monographFile =& MonographFileManager::_getFile($fileId, $revision); if (isset($monographFile)) { // Make sure that the file belongs to the monograph. if ($monographFile->getMonographId() != $monographId) { fatalError('Invalid file id!'); } // Mark the file as viewed by this user. $sessionManager =& SessionManager::getManager(); $session =& $sessionManager->getUserSession(); $user =& $session->getUser(); if (is_a($user, 'User')) { $viewsDao =& DAORegistry::getDAO('ViewsDAO'); $viewsDao->recordView(ASSOC_TYPE_MONOGRAPH_FILE, $monographFile->getFileIdAndRevision(), $user->getId()); } // Send the file to the user. $filePath = $monographFile->getFilePath(); $mediaType = $monographFile->getFileType(); $returner = parent::downloadFile($filePath, $mediaType, $inline); } return $returner; }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $revision int the revision of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($fileId, $revision = null, $inline = false, $format = "docx", $issueId = 0, $articleId = 0) { //%CBP% if we are passed a DSID and PID if (intval($fileId) == false && intval($revision) == false) { $CBPPlatformDao =& DAORegistry::getDAO('CBPPlatformDAO'); $pid = $fileId; $dsid = $revision; if ($issueId != 0) { $issueDao =& DAORegistry::getDAO('IssueDAO'); $issue = $issueDao->getIssueById($issueId); $label = $issue->getIssueTitle(); switch ($dsid) { case 'content': $label .= ".pdf"; break; case 'content02': $label .= ".epub"; break; case 'content03': $label .= ".mobi"; break; } } elseif ($articleId != 0) { $articleDao =& DAORegistry::getDAO('ArticleDAO'); $article = $articleDao->getArticle($articleId); $label = $article->getArticleTitle(); switch ($dsid) { case 'content': $label .= ".docx"; break; case 'content02': $label .= ".pdf"; break; case 'content03': $label .= ".epub"; break; case 'content04': $label .= ".mobi"; break; } } $filePath = Config::getVar('general', 'repository_url'); $filePath = "{$filePath}/" . $pid . "/datastreams/" . $dsid . "/content"; } else { $articleFile =& $this->getFile($fileId, $revision); if (isset($articleFile)) { $fileType = $articleFile->getFileType(); $filePath = $this->filesDir . $articleFile->getType() . '/' . $articleFile->getFileName(); return parent::downloadFile($filePath, $fileType, $inline); } else { return false; } } parent::downloadFile($filePath, null, null, $label, true); }
/** * @copydoc PubObjectsExportPlugin::executeExportAction() */ function executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart) { $context = $request->getContext(); $path = array('plugin', $this->getName()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); // Export if ($request->getUserVar(EXPORT_ACTION_EXPORT)) { $result = $this->_checkForTar(); if ($result === true) { $exportedFiles = array(); foreach ($objects as $object) { // Get the XML $exportXml = $this->exportXML($object, $filter, $context); // Write the XML to a file. // export file name example: datacite-20160723-160036-articles-1-1.xml $objectFileNamePart = $objectsFileNamePart . '-' . $object->getId(); $exportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $exportedFiles[] = $exportFileName; } // If we have more than one export file we package the files // up as a single tar before going on. assert(count($exportedFiles) >= 1); if (count($exportedFiles) > 1) { // tar file name: e.g. datacite-20160723-160036-articles-1.tar.gz $finalExportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.tar.gz'); $this->_tarFiles($this->getExportPath(), $finalExportFileName, $exportedFiles); // remove files foreach ($exportedFiles as $exportedFile) { $fileManager->deleteFile($exportedFile); } } else { $finalExportFileName = array_shift($exportedFiles); } $fileManager->downloadFile($finalExportFileName); $fileManager->deleteFile($finalExportFileName); } else { if (is_array($result)) { foreach ($result as $error) { assert(is_array($error) && count($error) >= 1); $this->_sendNotification($request->getUser(), $error[0], NOTIFICATION_TYPE_ERROR, isset($error[1]) ? $error[1] : null); } } // redirect back to the right tab $request->redirect(null, null, null, $path, null, $tab); } } elseif ($request->getUserVar(EXPORT_ACTION_DEPOSIT)) { $resultErrors = array(); foreach ($objects as $object) { // Get the XML $exportXml = $this->exportXML($object, $filter, $context); // Write the XML to a file. // export file name example: datacite-20160723-160036-articles-1-1.xml $objectFileNamePart = $objectsFileNamePart . '-' . $object->getId(); $exportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); // Deposit the XML file. $result = $this->depositXML($object, $context, $exportFileName); if (is_array($result)) { $resultErrors[] = $result; } // Remove all temporary files. $fileManager->deleteFile($exportFileName); } // send notifications if (empty($resultErrors)) { $this->_sendNotification($request->getUser(), $this->getDepositSuccessNotificationMessageKey(), NOTIFICATION_TYPE_SUCCESS); } else { foreach ($resultErrors as $error) { foreach ($errors as $error) { assert(is_array($error) && count($error) >= 1); $this->_sendNotification($request->getUser(), $error[0], NOTIFICATION_TYPE_ERROR, isset($error[1]) ? $error[1] : null); } } } // redirect back to the right tab $request->redirect(null, null, null, $path, null, $tab); } else { return parent::executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart); } }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($fileId, $inline = false) { $minutesFile =& $this->getFile($fileId); if (isset($minutesFile)) { $fileType = $minutesFile->getFileType(); $filePath = $this->filesDir . $minutesFile->getType() . '/' . $minutesFile->getFileName(); return parent::downloadFile($filePath, $fileType, $inline); } else { return false; } }
/** * Download a file. * @param $fileId int the file id of the file to download * @param $revision int the revision of the file to download * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($fileId, $revision = null, $inline = false) { $paperFile =& $this->getFile($fileId, $revision); if (isset($paperFile)) { $fileType = $paperFile->getFileType(); $filePath = $this->filesDir . $paperFile->getType() . '/' . $paperFile->getFileName(); return parent::downloadFile($filePath, $fileType, $inline); } else { return false; } }
/** * Output PDF generated from the XML/XSL/FO source to browser * This function performs any necessary filtering, like image URL replacement. * @return string */ function viewFileContents() { import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $pdfFileName = CacheManager::getFileCachePath() . DIRECTORY_SEPARATOR . 'fc-xsltGalley-' . str_replace($fileManager->parseFileExtension($this->getFileName()), 'pdf', $this->getFileName()); // if file does not exist or is outdated, regenerate it from FO if (!$fileManager->fileExists($pdfFileName) || filemtime($pdfFileName) < filemtime($this->getFilePath())) { // render XML into XSL-FO $cache =& $this->_getXSLTCache($this->getFileName() . '-' . $this->getId()); $contents = $cache->getContents(); if ($contents == "") { return false; } // if for some reason the XSLT failed, show original file // Replace image references $images =& $this->getImageFiles(); if ($images !== null) { // TODO: this should "smart replace" the file path ($this->getFilePath()) in the XSL-FO // in lieu of requiring XSL parameters, and transparently for FO that are hardcoded foreach ($images as $image) { $contents = preg_replace('/src\\s*=\\s*"([^"]*)' . preg_quote($image->getOriginalFileName()) . '([^"]*)"/i', 'src="${1}' . dirname($this->getFilePath()) . DIRECTORY_SEPARATOR . $image->getFileName() . '$2"', $contents); } } // Replace supplementary file references $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO'); $suppFiles = $this->suppFileDao->getSuppFilesByArticle($this->getArticleId()); if ($suppFiles) { $journal =& Request::getJournal(); foreach ($suppFiles as $supp) { $suppUrl = Request::url(null, 'article', 'downloadSuppFile', array($this->getArticleId(), $supp->getBestSuppFileId($journal))); $contents = preg_replace('/external-destination\\s*=\\s*"([^"]*)' . preg_quote($supp->getOriginalFileName()) . '([^"]*)"/i', 'external-destination="' . $suppUrl . '"', $contents); } } // create temporary FO file and write the contents import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $tempFoName = $temporaryFileManager->filesDir . $this->getFileName() . '-' . $this->getId() . '.fo'; $temporaryFileManager->writeFile($tempFoName, $contents); // perform %fo and %pdf replacements for fully-qualified shell command $journal =& Request::getJournal(); $xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName); $fopCommand = str_replace(array('%fo', '%pdf'), array($tempFoName, $pdfFileName), $xmlGalleyPlugin->getSetting($journal->getId(), 'externalFOP')); // check for safe mode and escape the shell command if (!ini_get('safe_mode')) { $fopCommand = escapeshellcmd($fopCommand); } // run the shell command and get the results exec($fopCommand . ' 2>&1', $contents, $status); // if there is an error, spit out the shell results to aid debugging if ($status != false) { if ($contents != '') { echo implode("\n", $contents); $cache->flush(); // clear the XSL cache in case it's a FO error return true; } else { return false; } } // clear the temporary FO file $fileManager->deleteFile($tempFoName); } // use FileManager to send file to browser $fileManager->downloadFile($pdfFileName, $this->getFileType(), true); return true; }
function downloadFile($filePath, $fileType, $inline = false) { return parent::downloadFile($this->filesDir . $filePath, $fileType, $inline); }
/** * Execute export action. * @param $request Request * @param $objects array Array of objects to be exported * @param $filter string Filter to use * @param $tab string Tab to return to * @param $objectsFileNamePart string Export file name part for this kind of objects */ function executeExportAction($request, $objects, $filter, $tab, $objectsFileNamePart) { $context = $request->getContext(); $path = array('plugin', $this->getName()); if ($request->getUserVar(EXPORT_ACTION_EXPORT)) { assert($filter != null); // Get the XML $exportXml = $this->exportXML($objects, $filter, $context); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), $objectsFileNamePart, $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); } elseif ($request->getUserVar(EXPORT_ACTION_MARKREGISTERED)) { $this->markRegistered($context, $objects); // redirect back to the right tab $request->redirect(null, null, null, $path, null, $tab); } else { $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }