Commit 158dee93 authored by Charles Bourdot's avatar Charles Bourdot
Browse files

initial commit

parent 8d498409
Loading
Loading
Loading
Loading
+37 −16
Original line number Diff line number Diff line
<?php

import('pages.article.ArticleHandler');
namespace APP\plugins\generic\xml2html;

require_once(__DIR__ . '/ImageUtils.php');

class ArticleImageDataHandler extends ArticleHandler
use APP\core\Request;
use APP\facades\Repo;
use APP\handler\Handler;

class ArticleImageDataHandler extends Handler
{
    private $fs;

    public function __construct()
    {
        parent::__construct();
        $this->fs = ImageUtils::buildFileSystem($this);
    }

    /**
     * Image from zip archive galley file
     * @param array $args
     * @param Request $request
     * @return mixed
     */
    public function zimage(array $args, Request $request)
    {
        $galleyId = $args[1];
        $submissionId = (int)$args[0];
        $galleyId = (int)$args[1];
        $imgName = $args[2];
        $galley = Services::get('galley')->get($galleyId);

        $submission = Repo::submission()->get($submissionId);
        if (!$submission) {
            header('HTTP/1.0 404 Not Found');
            exit;
        }

        $galley = Repo::galley()->get($galleyId);
        if (!$galley) {
            header('HTTP/1.0 404 Not Found');
            exit;
        }

        $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);
        if (!$file) {
            header('HTTP/1.0 404 Not Found');
            exit;
        }

        $filename = $file->getData('path');
        $pathInfo = pathinfo($filename);
        $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName;

        ImageUtils::downloadImage($this->fs, $imagePath, $imgName);
    }
}
 No newline at end of file
+23 −47
Original line number Diff line number Diff line
<?php

import('pages.catalog.CatalogBookHandler');
namespace APP\plugins\generic\xml2html;

require_once(__DIR__ . '/ImageUtils.php');

class BookImageDataHandler extends CatalogBookHandler
use APP\core\Application;
use APP\facades\Repo;
use APP\core\Request;
use APP\handler\Handler;

class BookImageDataHandler extends Handler
{

    private $fs;

//    /**
//     * @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);
//    }
    public function __construct()
    {
        parent::__construct();
        $this->fs = ImageUtils::buildFileSystem($this);
    }

    /**
     * Image from zip archive submission file
@@ -53,12 +30,14 @@ class BookImageDataHandler extends CatalogBookHandler
    {
        $pubId= $args[1];
        $imgName = $args[2];
        $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
        $submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);

        $pubFormatFiles = Services::get('submissionFile')->getMany([
			'submissionIds' => [$submission->getId()],
			'assocTypes' => [ASSOC_TYPE_PUBLICATION_FORMAT],
		]);

        $pubFormatFiles = Repo::submissionFile()
            ->getCollector()
            ->filterBySubmissionIds([$submission->getId()])
            ->filterByAssoc(Application::ASSOC_TYPE_PUBLICATION_FORMAT)
            ->getMany();

        $publicationFile = NULL;
        foreach ($pubFormatFiles as $file){
@@ -66,13 +45,10 @@ 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);

        ImageUtils::downloadImage($this->fs, $imagePath, $imgName);

    }

+4 −0
Original line number Diff line number Diff line
<?php

namespace APP\plugins\generic\xml2html;

use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
@@ -6,6 +9,7 @@ use PKP\config\Config;
use PKP\file\FileManager;
use PKP\plugins\Hook;
use APP\handler\Handler;

class ImageUtils
{
    public static function buildFileSystem(Handler $handler) : Filesystem{
+174 −195

File changed.

Preview size limit exceeded, changes collapsed.

+10 −3
Original line number Diff line number Diff line
<?php

import('lib.pkp.classes.form.Form');
import('classes.notification.NotificationManager');
namespace APP\plugins\generic\xml2html;

use APP\core\Application;
use APP\notification\NotificationManager;
use APP\plugins\generic\xml2html\XML2HTMLPlugin;
use APP\template\TemplateManager;
use PKP\form\validation\FormValidatorCSRF;
use PKP\form\validation\FormValidatorPost;
use PKP\form\Form;
use PKP\notification\Notification;

class XML2HTMLSettingsForm extends Form
{
@@ -91,7 +98,7 @@ class XML2HTMLSettingsForm extends Form
        $notificationMgr = new NotificationManager();
        $notificationMgr->createTrivialNotification(
            Application::get()->getRequest()->getUser()->getId(),
            NOTIFICATION_TYPE_SUCCESS,
            notification::NOTIFICATION_TYPE_SUCCESS,
            ['contents' => __('common.changesSaved')]
        );

Loading