Loading ArticleImageDataHandler.inc.php +60 −7 Changes for ArticleImageDataHandler.inc.php: 60 added lines, 7 removed lines. Original line number Diff line number Diff line <?php import('pages.article.ArticleHandler'); use APP\pages\article\ArticleHandler; use APP\core\Services; use League\Flysystem\Filesystem; use League\Flysystem\Local\LocalFilesystemAdapter; use League\Flysystem\UnixVisibility\PortableVisibilityConverter; use PKP\config\Config; use PKP\file\FileManager; use PKP\plugins\Hook; class ArticleImageDataHandler extends ArticleHandler { private $fs; public function __construct() { parent::__construct(); $umask = Config::getVar('files', 'umask', 0022); $adapter = new LocalFilesystemAdapter( Config::getVar('files', 'files_dir'), PortableVisibilityConverter::fromArray([ 'file' => [ 'public' => FileManager::FILE_MODE_MASK & ~$umask, 'private' => FileManager::FILE_MODE_MASK & ~$umask, ], 'dir' => [ 'public' => FileManager::DIRECTORY_MODE_MASK & ~$umask, 'private' => FileManager::DIRECTORY_MODE_MASK & ~$umask, ] ]), LOCK_EX, LocalFilesystemAdapter::DISALLOW_LINKS ); Hook::call('File::adapter', [&$adapter, $this]); $this->fs = new Filesystem($adapter); } /** * Image from zip archive galley file * @param array $args * @param Request $request * @param APP\core\Request $request * @return mixed */ public function zimage(array $args, Request $request) public function zimage(array $args, APP\core\Request $request) { $galleyId = $args[1]; $galleyId = (int)$args[1]; $imgName = $args[2]; $galley = Services::get('galley')->get($galleyId); $galley = NULL; foreach ($this->publication->getData('galleys') as $g) { if($galleyId == $g->getId()){ $galley = $g; } } if($galley != NULL){ $file = $galley->getFile(); $filename = Services::get('file') ->formatFilename($file->getData('path'), $file->getLocalizedData('path')); $pathInfo = pathinfo($filename); $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName; return Services::get('file')->download($imagePath, $imgName); $mimetype = 'application/octet-stream'; $filesize = $this->fs->fileSize($imagePath); $encodedFilename = urlencode($filename); header("Content-Type: $mimetype"); header("Content-Length: $filesize"); header('Accept-Ranges: none'); header('Content-Disposition: attachment' . ";filename=\"$encodedFilename\";filename*=UTF-8''$encodedFilename"); header('Cache-Control: private'); // Workarounds for IE weirdness header('Pragma: public'); fpassthru($this->fs->readStream($imagePath)); exit(); } return NULL; } Loading BookImageDataHandler.inc.php +1 −41 Changes for BookImageDataHandler.inc.php: 1 added line, 41 removed lines. Original line number Diff line number Diff line <?php import('pages.catalog.CatalogBookHandler'); use APP\pages\catalog\CatalogBookHandler; class BookImageDataHandler extends CatalogBookHandler { // /** // * @param array $args // * @param Request $request // * @return mixed // */ // public function image(array $args, Request $request) // { // $fileId = $args[1]; // $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION); // import('lib.pkp.classes.submission.SubmissionFile'); // $dependentFilesIterator = Services::get('submissionFile')->getMany([ // 'assocTypes' => [ASSOC_TYPE_SUBMISSION_FILE], // 'submissionIds' => [$submission->getId()], // 'fileStages' => [SUBMISSION_FILE_DEPENDENT], // 'includeDependentFiles' => true, // ]); // // $submissionFile = null; // foreach ($dependentFilesIterator as $dependentFile) { // if ($fileId == $dependentFile->getData('fileId')) { // $submissionFile = $dependentFile; // break; // } // } // // // Download file if exists // if (!Services::get('file')->fs->has($submissionFile->getData('path'))) { // $request->getDispatcher()->handle404(); // } // // $filename = Services::get('file') // ->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name')); // // return Services::get('file')->download($submissionFile->getData('path'), $filename); // } /** * Image from zip archive submission file * @param array $args Loading @@ -66,9 +29,6 @@ class BookImageDataHandler extends CatalogBookHandler $publicationFile = $file; } } // $filename = Services::get('file') // ->formatFilename($publicationFile->getData('path'), $publicationFile->getLocalizedData('path')); // var_dump($filename); $pathInfo = pathinfo($publicationFile->getData('path')); $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName; return Services::get('file')->download($imagePath, $imgName); Loading Loading
ArticleImageDataHandler.inc.php +60 −7 Changes for ArticleImageDataHandler.inc.php: 60 added lines, 7 removed lines. Original line number Diff line number Diff line <?php import('pages.article.ArticleHandler'); use APP\pages\article\ArticleHandler; use APP\core\Services; use League\Flysystem\Filesystem; use League\Flysystem\Local\LocalFilesystemAdapter; use League\Flysystem\UnixVisibility\PortableVisibilityConverter; use PKP\config\Config; use PKP\file\FileManager; use PKP\plugins\Hook; class ArticleImageDataHandler extends ArticleHandler { private $fs; public function __construct() { parent::__construct(); $umask = Config::getVar('files', 'umask', 0022); $adapter = new LocalFilesystemAdapter( Config::getVar('files', 'files_dir'), PortableVisibilityConverter::fromArray([ 'file' => [ 'public' => FileManager::FILE_MODE_MASK & ~$umask, 'private' => FileManager::FILE_MODE_MASK & ~$umask, ], 'dir' => [ 'public' => FileManager::DIRECTORY_MODE_MASK & ~$umask, 'private' => FileManager::DIRECTORY_MODE_MASK & ~$umask, ] ]), LOCK_EX, LocalFilesystemAdapter::DISALLOW_LINKS ); Hook::call('File::adapter', [&$adapter, $this]); $this->fs = new Filesystem($adapter); } /** * Image from zip archive galley file * @param array $args * @param Request $request * @param APP\core\Request $request * @return mixed */ public function zimage(array $args, Request $request) public function zimage(array $args, APP\core\Request $request) { $galleyId = $args[1]; $galleyId = (int)$args[1]; $imgName = $args[2]; $galley = Services::get('galley')->get($galleyId); $galley = NULL; foreach ($this->publication->getData('galleys') as $g) { if($galleyId == $g->getId()){ $galley = $g; } } if($galley != NULL){ $file = $galley->getFile(); $filename = Services::get('file') ->formatFilename($file->getData('path'), $file->getLocalizedData('path')); $pathInfo = pathinfo($filename); $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName; return Services::get('file')->download($imagePath, $imgName); $mimetype = 'application/octet-stream'; $filesize = $this->fs->fileSize($imagePath); $encodedFilename = urlencode($filename); header("Content-Type: $mimetype"); header("Content-Length: $filesize"); header('Accept-Ranges: none'); header('Content-Disposition: attachment' . ";filename=\"$encodedFilename\";filename*=UTF-8''$encodedFilename"); header('Cache-Control: private'); // Workarounds for IE weirdness header('Pragma: public'); fpassthru($this->fs->readStream($imagePath)); exit(); } return NULL; } Loading
BookImageDataHandler.inc.php +1 −41 Changes for BookImageDataHandler.inc.php: 1 added line, 41 removed lines. Original line number Diff line number Diff line <?php import('pages.catalog.CatalogBookHandler'); use APP\pages\catalog\CatalogBookHandler; class BookImageDataHandler extends CatalogBookHandler { // /** // * @param array $args // * @param Request $request // * @return mixed // */ // public function image(array $args, Request $request) // { // $fileId = $args[1]; // $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION); // import('lib.pkp.classes.submission.SubmissionFile'); // $dependentFilesIterator = Services::get('submissionFile')->getMany([ // 'assocTypes' => [ASSOC_TYPE_SUBMISSION_FILE], // 'submissionIds' => [$submission->getId()], // 'fileStages' => [SUBMISSION_FILE_DEPENDENT], // 'includeDependentFiles' => true, // ]); // // $submissionFile = null; // foreach ($dependentFilesIterator as $dependentFile) { // if ($fileId == $dependentFile->getData('fileId')) { // $submissionFile = $dependentFile; // break; // } // } // // // Download file if exists // if (!Services::get('file')->fs->has($submissionFile->getData('path'))) { // $request->getDispatcher()->handle404(); // } // // $filename = Services::get('file') // ->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name')); // // return Services::get('file')->download($submissionFile->getData('path'), $filename); // } /** * Image from zip archive submission file * @param array $args Loading @@ -66,9 +29,6 @@ class BookImageDataHandler extends CatalogBookHandler $publicationFile = $file; } } // $filename = Services::get('file') // ->formatFilename($publicationFile->getData('path'), $publicationFile->getLocalizedData('path')); // var_dump($filename); $pathInfo = pathinfo($publicationFile->getData('path')); $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName; return Services::get('file')->download($imagePath, $imgName); Loading