Skip to content

Commit eb92df3

Browse files
Merge pull request #30 from lepidus/main
Feature/fix plugin issues
2 parents 8d1465a + 8e824ba commit eb92df3

17 files changed

Lines changed: 223 additions & 36 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ This is required to use the API credentials provided, that are stored encrypted
3131

3232
## Usage
3333

34+
### Guidelines
35+
36+
- Only basic HTML tags are preserved (`<strong>`, `<mark>`, `<em>`, `<i>`, `<u>`, `<sup>`, `<sub>`, `<ul>`, `<ol>` and `<li>`); all others will be removed
37+
- ISBN must be properly formatted (e.g., 978-3-16-148410-0)
38+
3439
### Configuration
3540

3641
To configure the plugin:

ThothPlugin.inc.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import('plugins.generic.thoth.classes.api.ThothEndpoint');
2525
import('plugins.generic.thoth.classes.components.forms.config.PublishFormConfig');
26-
import('plugins.generic.thoth.classes.filters.ThothSectionFilter');
26+
import('plugins.generic.thoth.classes.templateFilters.ThothSectionTemplateFilter');
2727
import('plugins.generic.thoth.classes.listeners.PublicationEditListener');
2828
import('plugins.generic.thoth.classes.listeners.PublicationPublishListener');
2929
import('plugins.generic.thoth.classes.notification.ThothNotification');
@@ -132,7 +132,7 @@ public function addTemplateFilters($hookName, $args)
132132
$templateMgr = $args[0];
133133
$template = $args[1];
134134

135-
$thothSectionFilter = new ThothSectionFilter();
135+
$thothSectionFilter = new ThothSectionTemplateFilter();
136136
$thothSectionFilter->registerFilter($templateMgr, $template, $this);
137137
}
138138

@@ -142,7 +142,7 @@ public function addScripts($hookName, $args)
142142
$template = $args[1];
143143
$request = Application::get()->getRequest();
144144

145-
$thothSectionFilter = new ThothSectionFilter();
145+
$thothSectionFilter = new ThothSectionTemplateFilter();
146146
$thothSectionFilter->addJavaScriptData($request, $templateMgr, $template);
147147
$thothSectionFilter->addJavaScript($request, $templateMgr, $this);
148148
$thothSectionFilter->addStyleSheet($request, $templateMgr, $this);
@@ -189,15 +189,17 @@ public function addMenu($hookName, $args)
189189
}
190190

191191
if (in_array(ROLE_ID_MANAGER, $userRoles)) {
192-
$menu = array_slice($menu, 0, 3, true) +
192+
$offset = array_search("settings", array_keys($menu));
193+
194+
$menu = array_slice($menu, 0, $offset, true) +
193195
[
194196
'thoth' => [
195197
'name' => __('plugins.generic.thoth.navigation.thoth'),
196198
'url' => $router->url($request, null, 'thoth'),
197199
'isCurrent' => $router->getRequestedPage($request) === 'thoth',
198200
]
199201
] +
200-
array_slice($menu, 2, null, true);
202+
array_slice($menu, ($offset - 1), null, true);
201203
}
202204

203205
$templateMgr->setState(['menu' => $menu]);

classes/container/providers/ThothRepositoryProvider.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function register($container)
5454

5555
$testEnvironment = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'testEnvironment');
5656
$email = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'email');
57-
$password = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'password');
57+
$password = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'password') ?? '';
5858

5959
return [
6060
'testEnvironment' => $testEnvironment,

classes/factories/ThothBookFactory.inc.php

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
use APP\facades\Repo;
1818
use APP\submission\Submission;
19+
use PKP\core\Core;
20+
use PKP\doi\Doi;
21+
use PKP\submission\PKPSubmission;
1922
use ThothApi\GraphQL\Models\Work as ThothWork;
2023

2124
import('plugins.generic.thoth.classes.formatters.HtmlStripper');
@@ -31,18 +34,26 @@ public function createFromPublication($publication)
3134

3235
return new ThothWork([
3336
'workType' => $thothWorkType ?? $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
34-
'workStatus' => empty($publication->getData('datePublished'))
35-
? ThothWork::WORK_STATUS_FORTHCOMING
36-
: ThothWork::WORK_STATUS_ACTIVE,
37+
'workStatus' => $this->getWorkStatusByDatePublished($publication->getData('datePublished')),
3738
'fullTitle' => $publication->getLocalizedFullTitle(),
3839
'title' => $publication->getLocalizedTitle(),
3940
'subtitle' => $publication->getLocalizedData('subtitle'),
4041
'longAbstract' => HtmlStripper::stripTags($publication->getLocalizedData('abstract')),
4142
'edition' => $publication->getData('version'),
42-
'doi' => $publication->getData('doiObject')?->getResolvingUrl(),
43+
'doi' => $this->getDoi($publication),
4344
'publicationDate' => $publication->getData('datePublished'),
44-
'license' => $publication->getData('licenseUrl'),
45-
'copyrightHolder' => $publication->getLocalizedData('copyrightHolder'),
45+
'license' => $publication->getData('licenseUrl')
46+
?? $submission->_getContextLicenseFieldValue(
47+
null,
48+
PKPSubmission::PERMISSIONS_FIELD_LICENSE_URL,
49+
$publication
50+
),
51+
'copyrightHolder' => $publication->getLocalizedData('copyrightHolder')
52+
?? $submission->_getContextLicenseFieldValue(
53+
$submission->getData('locale'),
54+
PKPSubmission::PERMISSIONS_FIELD_COPYRIGHT_HOLDER,
55+
$publication
56+
),
4657
'coverUrl' => $publication->getLocalizedCoverImageUrl($submission->getData('contextId')),
4758
'landingPage' => $request->getDispatcher()->url(
4859
$request,
@@ -55,7 +66,7 @@ public function createFromPublication($publication)
5566
]);
5667
}
5768

58-
private function getWorkTypeBySubmissionWorkType($submissionWorkType)
69+
public function getWorkTypeBySubmissionWorkType($submissionWorkType)
5970
{
6071
$workTypeMapping = [
6172
Submission::WORK_TYPE_EDITED_VOLUME => ThothWork::WORK_TYPE_EDITED_BOOK,
@@ -64,4 +75,43 @@ private function getWorkTypeBySubmissionWorkType($submissionWorkType)
6475

6576
return $workTypeMapping[$submissionWorkType];
6677
}
78+
79+
public function getWorkStatusByDatePublished($datePublished)
80+
{
81+
if ($datePublished && $datePublished <= Core::getCurrentDate()) {
82+
return ThothWork::WORK_STATUS_ACTIVE;
83+
}
84+
85+
return ThothWork::WORK_STATUS_FORTHCOMING;
86+
}
87+
88+
public function getDoi($publication)
89+
{
90+
$doiObject = $publication->getData('doiObject');
91+
92+
if ($doiObject === null) {
93+
$publicationFormats = DAORegistry::getDAO('PublicationFormatDAO')
94+
->getByPublicationId($publication->getId());
95+
foreach ($publicationFormats as $publicationFormat) {
96+
$identificationCodes = $publicationFormat->getIdentificationCodes()->toArray();
97+
foreach ($identificationCodes as $identificationCode) {
98+
if ($identificationCode->getCode() == '06') {
99+
$doi = $identificationCode->getValue();
100+
if (str_contains($doi, 'doi.org')) {
101+
$doi = str_replace('https://doi.org/', '', $doi);
102+
}
103+
$doiObject = new Doi();
104+
$doiObject->setDoi($doi);
105+
break 2;
106+
}
107+
}
108+
}
109+
}
110+
111+
if ($doiObject === null) {
112+
return $doiObject;
113+
}
114+
115+
return $doiObject->getResolvingUrl();
116+
}
67117
}

classes/factories/ThothChapterFactory.inc.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
use APP\facades\Repo;
18+
use PKP\core\Core;
1819
use ThothApi\GraphQL\Models\Work as ThothWork;
1920

2021
import('plugins.generic.thoth.classes.formatters.HtmlStripper');
@@ -30,9 +31,7 @@ public function createFromChapter($chapter)
3031

3132
return new ThothWork([
3233
'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER,
33-
'workStatus' => (empty($chapter->getDatePublished()) && empty($publication->getData('datePublished')))
34-
? ThothWork::WORK_STATUS_FORTHCOMING
35-
: ThothWork::WORK_STATUS_ACTIVE,
34+
'workStatus' => $this->getWorkStatusByDatePublished($chapter, $publication),
3635
'fullTitle' => $chapter->getLocalizedFullTitle(),
3736
'title' => $chapter->getLocalizedTitle(),
3837
'subtitle' => $chapter->getLocalizedData('subtitle'),
@@ -50,4 +49,15 @@ public function createFromChapter($chapter)
5049
)
5150
]);
5251
}
52+
53+
public function getWorkStatusByDatePublished($chapter, $publication)
54+
{
55+
$dataPublished = $chapter->getDatePublished() ?? $publication->getData('datePublished');
56+
57+
if ($dataPublished && $dataPublished <= Core::getCurrentDate()) {
58+
return ThothWork::WORK_STATUS_ACTIVE;
59+
}
60+
61+
return ThothWork::WORK_STATUS_FORTHCOMING;
62+
}
5363
}

classes/formatters/HtmlStripper.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class HtmlStripper
1818
{
19-
private const ALLOWED_TAGS = '<b><strong><em><i><u><ul><ol><li><p><h1><h2><h3><h4><h5><h6>';
19+
private const ALLOWED_TAGS = '<strong><mark><em><i><u><sup><sub><ul><ol><li>';
2020

2121
public static function stripTags($string)
2222
{

classes/services/ThothContributionService.inc.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
use APP\facades\Repo;
18+
use PKP\db\DAORegistry;
1819

1920
import('plugins.generic.thoth.classes.facades.ThothService');
2021
import('plugins.generic.thoth.classes.facades.ThothRepository');
@@ -58,8 +59,27 @@ public function registerByPublication($publication)
5859
{
5960
$authors = Repo::author()->getCollector()
6061
->filterByPublicationIds([$publication->getId()])
61-
->getMany();
62+
->getMany()
63+
->toArray();
6264
$primaryContactId = $publication->getData('primaryContactId');
65+
66+
$chapterDao = DAORegistry::getDAO('ChapterDAO');
67+
$chapters = $chapterDao->getByPublicationId($publication->getId())->toArray();
68+
69+
$chapterAuthorIds = [];
70+
foreach ($chapters as $chapter) {
71+
$chapterAuthorIds = array_merge($chapterAuthorIds, (array) Repo::author()->getCollector()
72+
->filterByChapterId($chapter->getId())
73+
->filterByPublicationIds([$publication->getId()])
74+
->getIds()
75+
->toArray());
76+
}
77+
$chapterAuthorIds = array_unique($chapterAuthorIds);
78+
79+
$authors = array_filter($authors, function ($author) use ($chapterAuthorIds, $primaryContactId) {
80+
return $author->getId() === $primaryContactId || !in_array($author->getId(), $chapterAuthorIds);
81+
});
82+
6383
$thothBookId = $publication->getData('thothBookId');
6484
foreach ($authors as $author) {
6585
$this->register($author, $thothBookId, $primaryContactId);

classes/services/ThothPublicationService.inc.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ public function registerByPublication($publication)
5252
{
5353
$thothBookId = $publication->getData('thothBookId');
5454
$publicationFormats = DAORegistry::getDAO('PublicationFormatDAO')
55-
->getApprovedByPublicationId($publication->getId())
56-
->toArray();
55+
->getByPublicationId($publication->getId());
5756
foreach ($publicationFormats as $publicationFormat) {
58-
if ($publicationFormat->getIsAvailable()) {
59-
$this->register($publicationFormat, $thothBookId);
60-
}
57+
$this->register($publicationFormat, $thothBookId);
6158
}
6259
}
6360

@@ -78,9 +75,7 @@ public function registerByChapter($chapter)
7875
$publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
7976
foreach ($chapterSubmissionFiles as $chapterSubmissionFile) {
8077
$publicationFormat = $publicationFormatDao->getById($chapterSubmissionFile->getData('assocId'));
81-
if ($publicationFormat->getIsAvailable()) {
82-
$this->register($publicationFormat, $thothChapterId, $chapter->getId());
83-
}
78+
$this->register($publicationFormat, $thothChapterId, $chapter->getId());
8479
}
8580
}
8681

classes/services/ThothSubjectService.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public function __construct($repository)
2424
$this->repository = $repository;
2525
}
2626

27-
public function register($citation, $sequence, $thothWorkId)
27+
public function register($subject, $sequence, $thothWorkId)
2828
{
2929
$thothSubject = $this->repository->new([
3030
'workId' => $thothWorkId,
3131
'subjectType' => ThothSubject::SUBJECT_TYPE_KEYWORD,
32-
'subjectCode' => 'Psychology',
32+
'subjectCode' => $subject,
3333
'subjectOrdinal' => $sequence
3434
]);
3535

classes/filters/ThothSectionFilter.inc.php renamed to classes/templateFilters/ThothSectionTemplateFilter.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php
22

33
/**
4-
* @file plugins/generic/thoth/classes/filters/ThothSectionFilter.inc.php
4+
* @file plugins/generic/thoth/classes/filters/ThothSectionTemplateFilter.inc.php
55
*
66
* Copyright (c) 2024-2025 Lepidus Tecnologia
77
* Copyright (c) 2024-2025 Thoth
88
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
99
*
10-
* @class ThothSectionFilter
10+
* @class ThothSectionTemplateFilter
1111
* @ingroup plugins_generic_thoth
1212
*
1313
* @brief Template filter to include Thoth section in workflow page
1414
*/
1515

16-
class ThothSectionFilter
16+
class ThothSectionTemplateFilter
1717
{
1818
private $plugin;
1919

0 commit comments

Comments
 (0)