Skip to content

Commit

Permalink
Merge branch 'adaptToOps3_4' into 'main'
Browse files Browse the repository at this point in the history
Adapta plugin para OPS 3.4.0

See merge request softwares-pkp/plugins_ojs/folhaDeRostoDoPDF!28
  • Loading branch information
iudizm committed Jan 26, 2024
2 parents 2bb2689 + febebd5 commit 0ce1b09
Show file tree
Hide file tree
Showing 34 changed files with 701 additions and 625 deletions.
12 changes: 10 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ include:
ref: main
file:
- 'templates/groups/pkp_plugin.yml'
- 'templates/groups/ops_plugins_unit_tests_model.yml'
- 'templates/groups/ops_3_4_plugins_unit_tests_model.yml'
- 'templates/groups/ops_3_4_plugins_cypress_tests_model.yml'

.unit_test_template:
before_script:
- apt update && apt install poppler-utils imagemagick php{8.1,7.4,7.3}-imagick xmlstarlet -yqq
- apt update && apt install poppler-utils imagemagick php8.2-imagick xmlstarlet -yqq
- composer install
- sed -i 's/stealth="true"\/>/stealth="true"\/> -->/' /etc/ImageMagick-6/policy.xml
- xmlstarlet edit --inplace -u "policymap/policy[@pattern='PDF']/@rights" -v 'read|write' /etc/ImageMagick-6/policy.xml
- wget https://github.com/coherentgraphics/cpdf-binaries/blob/master/Linux-Intel-64bit/cpdf?raw=true -O /usr/local/bin/cpdf
- chmod +x /usr/local/bin/cpdf

.integration_tests_template:
before_script:
- apt update && apt install poppler-utils -yqq
- composer install
- wget https://github.com/coherentgraphics/cpdf-binaries/blob/master/Linux-Intel-64bit/cpdf?raw=true -O /usr/local/bin/cpdf
- chmod +x /usr/local/bin/cpdf
15 changes: 0 additions & 15 deletions .vscode/extensions.json

This file was deleted.

4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# Title Page Plugin

This plugin creates a title page on PDF files submitted to preprint servers. The title page is a page added to the beginning of the PDF file, containing a series of information about the preprint when it is posted. After the preprint is posted, the title page is also updated if the preprint relations are changed.
This plugin creates a title page on PDF files submitted to preprint servers. The title page is a page added to the beginning of the PDF file, containing a series of information about the preprint when it is posted.

The common information obtained for PDF title page are:
After the preprint is posted, the title page is updated if the preprint relations are changed. The updating also takes place when the preprint is unposted and posted back again.

The common information obtained for the PDF title page are:

- Relation status
- Publication DOI (if it was published in a journal)
- Publication DOI (if the preprint has been published elsewhere)
- Preprint title
- Preprint authors
- Preprint DOI in current server
- Submission preparation checklist
- Submitted date
- Posted date

The plugin also adds a new page at the end of the PDF file, containing the server's submission checklist at the moment the preprint is posted first time.

## Compatibility

The latest release of this plugin is compatible with the following PKP applications:

* OPS 3.3.0
* OPS 3.4.0

## Plugin Download

Expand All @@ -26,7 +29,7 @@ To download the plugin, go to the [Releases page](https://github.com/lepidus/tit
## Installation dependencies
* [poppler-utils](https://poppler.freedesktop.org/)

This plugin requires the installation of the CPDF binary in your system. You can download it at the [GitHub repository](https://github.com/coherentgraphics/cpdf-binaries). After that, you should make it executable from the command line. In linux systems it can be done by placing the binary in the `/usr/local/bin` directory and running `chmod +x /usr/local/bin/cpdf`.
This plugin requires the installation of the CPDF binary in your system. You can download it at the [GitHub repository](https://github.com/coherentgraphics/cpdf-binaries). After that, you should make it executable from the command line. In Linux systems it can be done by placing the binary in the `/usr/local/bin` directory and running `chmod +x /usr/local/bin/cpdf`.

This plugin also requires a logo on your OPS, defined on `Website Settings` > `Appearance` > `Logo`, so you need to upload an image. Images with any kind of transparency (alpha channel) are not supported and **should not** be used.

Expand Down Expand Up @@ -57,6 +60,6 @@ Since this plugin uses the CPDF library, make sure to check [its license](https:

__This plugin is licensed under the GNU General Public License v3.0__

__Copyright (c) 2020-2021 Lepidus Tecnologia__
__Copyright (c) 2020-2024 Lepidus Tecnologia__

__Copyright (c) 2020-2021 SciELO__
__Copyright (c) 2020-2024 SciELO__
51 changes: 31 additions & 20 deletions TitlePagePlugin.inc.php → TitlePageForPreprintPlugin.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
<?php
/**
* @file plugins/generic/TitlePageForPreprint/TitlePagePlugin.inc.php
* @file plugins/generic/TitlePageForPreprint/TitlePageForPreprintPlugin.inc.php
*
* Copyright (c) 2020-2021 Lepidus Tecnologia
* Copyright (c) 2020-2021 SciELO
* Copyright (c) 2020-2024 Lepidus Tecnologia
* Copyright (c) 2020-2024 SciELO
* Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt
*
* @class TitlePagePlugin
* @class TitlePageForPreprintPlugin
* @ingroup plugins_generic_TitlePageForPreprint
*
* @brief Plugin class for the TitlePageForPreprint plugin.
*/
import('lib.pkp.classes.plugins.GenericPlugin');
import('plugins.generic.titlePageForPreprint.classes.SubmissionPressFactory');
import('plugins.generic.titlePageForPreprint.classes.SubmissionFileUpdater');
import('plugins.generic.titlePageForPreprint.classes.TitlePageRequirements');

class TitlePagePlugin extends GenericPlugin
namespace APP\plugins\generic\titlePageForPreprint;

use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use APP\core\Application;
use APP\facades\Repo;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionPressFactory;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionFileUpdater;
use APP\plugins\generic\titlePageForPreprint\classes\TitlePageRequirements;

class TitlePageForPreprintPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$registeredPlugin = parent::register($category, $path);
$success = parent::register($category, $path, $mainContextId);

if (Application::isUnderMaintenance()) {
return $success;
}

if ($registeredPlugin && $this->getEnabled()) {
HookRegistry::register('Publication::publish::before', [$this, 'insertTitlePageWhenPublishing']);
HookRegistry::register('Publication::edit', [$this, 'insertTitlePageWhenChangeRelation']);
HookRegistry::register('Schema::get::submissionFile', array($this, 'modifySubmissionFileSchema'));
if ($success && $this->getEnabled($mainContextId)) {
Hook::add('Publication::publish::before', [$this, 'insertTitlePageOnPosting']);
Hook::add('Publication::edit', [$this, 'insertTitlePageWhenChangeRelation']);
Hook::add('Schema::get::submissionFile', array($this, 'modifySubmissionFileSchema'));
}
return $registeredPlugin;

return $success;
}

public function setEnabled($enabled)
Expand Down Expand Up @@ -67,12 +78,12 @@ public function modifySubmissionFileSchema($hookName, $params)
return false;
}

public function insertTitlePageWhenPublishing($hookName, $arguments)
public function insertTitlePageOnPosting($hookName, $params)
{
$titlePageRequirements = new TitlePageRequirements();

if ($titlePageRequirements->checkRequirements()) {
$publication = $arguments[0];
$publication = $params[0];
$this->insertTitlePageInPreprint($publication);
}
}
Expand All @@ -93,11 +104,11 @@ public function insertTitlePageWhenChangeRelation($hookName, $arguments)

public function insertTitlePageInPreprint($publication)
{
$submission = Services::get('submission')->get($publication->getData('submissionId'));
$submission = Repo::submission()->get($publication->getData('submissionId'));
$context = Application::getContextDAO()->getById($submission->getContextId());
$this->addLocaleData("pt_BR");
$this->addLocaleData("en_US");
$this->addLocaleData("es_ES");
$this->addLocaleData("en");
$this->addLocaleData("es");
$submissionPressFactory = new SubmissionPressFactory();
$submissionFileUpdater = new SubmissionFileUpdater();
$press = $submissionPressFactory->createSubmissionPress($submission, $publication, $context);
Expand Down
4 changes: 4 additions & 0 deletions classes/GalleyAdapter.inc.php → classes/GalleyAdapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace APP\plugins\generic\titlePageForPreprint\classes;

use PKP\config\Config;

class GalleyAdapter
{
public $file;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php

import('plugins.generic.titlePageForPreprint.classes.GalleyAdapter');
import('plugins.generic.titlePageForPreprint.classes.TitlePageDAO');
namespace APP\plugins\generic\titlePageForPreprint\classes;

use APP\facades\Repo;
use APP\plugins\generic\titlePageForPreprint\classes\GalleyAdapter;
use APP\plugins\generic\titlePageForPreprint\classes\TitlePageDAO;

class GalleyAdapterFactory
{
private $submissionFileDao;
private $submissionFileRepo;

public function __construct($submissionFileDao)
public function __construct($submissionFileRepo)
{
$this->submissionFileDao = $submissionFileDao;
$this->submissionFileRepo = $submissionFileRepo;
}

public function createGalleyAdapter($submission, $galley): GalleyAdapter
Expand All @@ -18,17 +21,17 @@ public function createGalleyAdapter($submission, $galley): GalleyAdapter
list($lastRevisionId, $lastRevisionPath) = $this->getLatestRevision($submissionFile->getId());

if ($this->submissionFileHasNewRevisionWithoutTitlePage($submissionFile, $lastRevisionId)) {
Services::get('submissionFile')->edit($submissionFile, [
Repo::submissionFile()->edit($submissionFile, [
'folhaDeRosto' => 'nao',
], Application::get()->getRequest());
]);
}

return new GalleyAdapter($lastRevisionPath, $galley->getLocale(), $submissionFile->getId(), $lastRevisionId);
}

public function getLatestRevision($submissionFileId)
{
$revisions = $this->submissionFileDao->getRevisions($submissionFileId)->toArray();
$revisions = $this->submissionFileRepo->getRevisions($submissionFileId)->toArray();
$lastRevision = get_object_vars($revisions[0]);

foreach ($revisions as $revision) {
Expand Down
4 changes: 4 additions & 0 deletions classes/Pdf.inc.php → classes/Pdf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace APP\plugins\generic\titlePageForPreprint\classes;

use InvalidArgumentException;

class Pdf
{
private $path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

namespace APP\plugins\generic\titlePageForPreprint\classes;

use APP\core\Application;
use APP\facades\Repo;

class SubmissionFileUpdater
{
public function updateRevisions($submissionFileId, $newRevisionId, $hasTitlePage)
{
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
$submissionFile = $submissionFileDao->getById($submissionFileId);
$submissionFile = Repo::submissionFile()->get($submissionFileId);
$revisions = !is_null($submissionFile->getData('revisoes')) ? json_decode($submissionFile->getData('revisoes')) : array();

if (!$hasTitlePage) {
array_push($revisions, $newRevisionId);
}

Services::get('submissionFile')->edit($submissionFile, [
Repo::submissionFile()->edit($submissionFile, [
'folhaDeRosto' => 'sim',
'revisoes' => json_encode($revisions)
], Application::get()->getRequest());
]);
}
}
14 changes: 13 additions & 1 deletion classes/SubmissionModel.inc.php → classes/SubmissionModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace APP\plugins\generic\titlePageForPreprint\classes;

class SubmissionModel
{
private $status;
Expand All @@ -14,8 +16,9 @@ class SubmissionModel
private $endorserName;
private $endorserOrcid;

public function __construct(string $status, $doi, $doiJournal, string $authors, string $submissionDate, string $publicationDate, $endorserName, $endorserOrcid, string $version, $versionJustification, array $galleys = null)
public function __construct(array $title, string $status, $doi, $doiJournal, string $authors, string $submissionDate, string $publicationDate, $endorserName, $endorserOrcid, string $version, $versionJustification, array $galleys = null)
{
$this->title = $title;
$this->status = $status;
$this->doi = ((empty($doi)) ? ("Not informed") : ($doi));
$this->doiJournal = ((empty($doiJournal)) ? ("Not informed") : ($doiJournal));
Expand All @@ -29,6 +32,15 @@ public function __construct(string $status, $doi, $doiJournal, string $authors,
$this->versionJustification = $versionJustification;
}

public function getTitle(string $locale): string
{
if (isset($this->title[$locale])) {
return $this->title[$locale];
}

return '';
}

public function getStatus(): string
{
return $this->status;
Expand Down
27 changes: 14 additions & 13 deletions classes/SubmissionPress.inc.php → classes/SubmissionPress.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?php

import('plugins.generic.titlePageForPreprint.classes.Pdf');
import('plugins.generic.titlePageForPreprint.classes.SubmissionModel');
import('plugins.generic.titlePageForPreprint.classes.Translator');
import('plugins.generic.titlePageForPreprint.classes.TitlePage');
namespace APP\plugins\generic\titlePageForPreprint\classes;

use APP\facades\Repo;
use APP\plugins\generic\titlePageForPreprint\classes\Pdf;
use APP\plugins\generic\titlePageForPreprint\classes\SubmissionModel;
use APP\plugins\generic\titlePageForPreprint\classes\TitlePage;

class SubmissionPress
{
private $logoForTitlePage;
private $submission;
private $translator;
private $checklist;
private $logoForTitlePage;

public function __construct(string $logoForTitlePage, SubmissionModel $submission, Translator $translator)
public function __construct(SubmissionModel $submission, array $checklist, string $logoForTitlePage)
{
$this->logoForTitlePage = $logoForTitlePage;
$this->submission = $submission;
$this->translator = $translator;
$this->checklist = $checklist;
$this->logoForTitlePage = $logoForTitlePage;
}

private function galleyHasTitlePage($galley)
{
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
$submissionFile = $submissionFileDao->getById($galley->submissionFileId);
$submissionFile = Repo::submissionFile()->get($galley->submissionFileId);

$hasTitlePage = $submissionFile->getData('folhaDeRosto');
return $hasTitlePage == 'sim';
Expand All @@ -30,7 +31,7 @@ private function galleyHasTitlePage($galley)
public function insertTitlePage($submissionFileUpdater): void
{
foreach ($this->submission->getGalleys() as $galley) {
$titlePage = new TitlePage($this->submission, $this->logoForTitlePage, $galley->locale, $this->translator);
$titlePage = new TitlePage($this->submission, $this->checklist, $this->logoForTitlePage, $galley->locale);
$pdfPath = $galley->getFullFilePath();

if (Pdf::isPdf($pdfPath)) {
Expand All @@ -42,7 +43,7 @@ public function insertTitlePage($submissionFileUpdater): void
try {
$hasTitlePage ? $titlePage->updateTitlePage($pdf) : $titlePage->insertTitlePageFirstTime($pdf);
$submissionFileUpdater->updateRevisions($submissionFileId, $galley->revisionId, $hasTitlePage);
} catch(Exception $e) {
} catch (\Exception $e) {
error_log('Caught exception: ' . $e->getMessage());
}
}
Expand Down
Loading

0 comments on commit 0ce1b09

Please sign in to comment.