Skip to content

Commit f44dab2

Browse files
Merge pull request #31 from lepidus/stable-3_3_0
Feature/fix plugin issues (OMP 3.3.0)
2 parents 18e8526 + 433a747 commit f44dab2

17 files changed

Lines changed: 202 additions & 30 deletions

README.md

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

3131
## Usage
3232

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

3540
To configure the plugin:

ThothPlugin.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import('lib.pkp.classes.plugins.GenericPlugin');
2121
import('plugins.generic.thoth.classes.api.ThothEndpoint');
2222
import('plugins.generic.thoth.classes.components.forms.config.PublishFormConfig');
23-
import('plugins.generic.thoth.classes.filters.ThothSectionFilter');
23+
import('plugins.generic.thoth.classes.templateFilters.ThothSectionTemplateFilter');
2424
import('plugins.generic.thoth.classes.listeners.PublicationEditListener');
2525
import('plugins.generic.thoth.classes.listeners.PublicationPublishListener');
2626
import('plugins.generic.thoth.classes.notification.ThothNotification');
@@ -122,7 +122,7 @@ public function addTemplateFilters($hookName, $args)
122122
$templateMgr = $args[0];
123123
$template = $args[1];
124124

125-
$thothSectionFilter = new ThothSectionFilter();
125+
$thothSectionFilter = new ThothSectionTemplateFilter();
126126
$thothSectionFilter->registerFilter($templateMgr, $template, $this);
127127
}
128128

@@ -155,7 +155,7 @@ public function addScripts($hookName, $args)
155155
$thothNotification->addJavaScriptData($request, $templateMgr);
156156
$thothNotification->addJavaScript($request, $templateMgr, $this);
157157

158-
$thothSectionFilter = new ThothSectionFilter();
158+
$thothSectionFilter = new ThothSectionTemplateFilter();
159159
$thothSectionFilter->addJavaScriptData($request, $templateMgr, $template);
160160
$thothSectionFilter->addJavaScript($request, $templateMgr, $this);
161161
$thothSectionFilter->addStyleSheet($request, $templateMgr, $this);

classes/container/providers/ThothRepositoryProvider.inc.php

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

5252
$testEnvironment = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'testEnvironment');
5353
$email = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'email');
54-
$password = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'password');
54+
$password = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'password') ?? '';
5555

5656
return [
5757
'testEnvironment' => $testEnvironment,

classes/factories/ThothBookFactory.inc.php

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,26 @@ public function createFromPublication($publication)
3030

3131
return new ThothWork([
3232
'workType' => $thothWorkType ?? $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
33-
'workStatus' => empty($publication->getData('datePublished'))
34-
? ThothWork::WORK_STATUS_FORTHCOMING
35-
: ThothWork::WORK_STATUS_ACTIVE,
33+
'workStatus' => $this->getWorkStatusByDatePublished($publication->getData('datePublished')),
3634
'fullTitle' => $publication->getLocalizedFullTitle(),
3735
'title' => $publication->getLocalizedTitle(),
3836
'subtitle' => $publication->getLocalizedData('subtitle'),
3937
'longAbstract' => HtmlStripper::stripTags($publication->getLocalizedData('abstract')),
4038
'edition' => $publication->getData('version'),
41-
'doi' => DoiFormatter::resolveUrl($publication->getStoredPubId('doi')),
39+
'doi' => $this->getDoi($publication),
4240
'publicationDate' => $publication->getData('datePublished'),
43-
'license' => $publication->getData('licenseUrl'),
44-
'copyrightHolder' => $publication->getLocalizedData('copyrightHolder'),
41+
'license' => $publication->getData('licenseUrl')
42+
?? $submission->_getContextLicenseFieldValue(
43+
null,
44+
PERMISSIONS_FIELD_LICENSE_URL,
45+
$publication
46+
),
47+
'copyrightHolder' => $publication->getLocalizedData('copyrightHolder')
48+
?? $submission->_getContextLicenseFieldValue(
49+
$submission->getData('locale'),
50+
PERMISSIONS_FIELD_COPYRIGHT_HOLDER,
51+
$publication
52+
),
4553
'coverUrl' => $publication->getLocalizedCoverImageUrl($submission->getContextId()),
4654
'landingPage' => $request->getDispatcher()->url(
4755
$request,
@@ -54,7 +62,7 @@ public function createFromPublication($publication)
5462
]);
5563
}
5664

57-
private function getWorkTypeBySubmissionWorkType($submissionWorkType)
65+
public function getWorkTypeBySubmissionWorkType($submissionWorkType)
5866
{
5967
$workTypeMapping = [
6068
WORK_TYPE_EDITED_VOLUME => ThothWork::WORK_TYPE_EDITED_BOOK,
@@ -63,4 +71,43 @@ private function getWorkTypeBySubmissionWorkType($submissionWorkType)
6371

6472
return $workTypeMapping[$submissionWorkType];
6573
}
74+
75+
public function getWorkStatusByDatePublished($datePublished)
76+
{
77+
if ($datePublished && $datePublished <= \Core::getCurrentDate()) {
78+
return ThothWork::WORK_STATUS_ACTIVE;
79+
}
80+
81+
return ThothWork::WORK_STATUS_FORTHCOMING;
82+
}
83+
84+
public function getDoi($publication)
85+
{
86+
$doi = $publication->getStoredPubId('doi');
87+
88+
if ($doi === null) {
89+
$publicationFormats = DAORegistry::getDAO('PublicationFormatDAO')
90+
->getByPublicationId($publication->getId())
91+
->toArray();
92+
93+
foreach ($publicationFormats as $publicationFormat) {
94+
$identificationCodes = $publicationFormat->getIdentificationCodes()->toArray();
95+
foreach ($identificationCodes as $identificationCode) {
96+
if ($identificationCode->getCode() == '06') {
97+
$doi = $identificationCode->getValue();
98+
if (str_contains($doi, 'doi.org')) {
99+
$doi = str_replace('https://doi.org/', '', $doi);
100+
}
101+
break 2;
102+
}
103+
}
104+
}
105+
}
106+
107+
if ($doi === null) {
108+
return $doi;
109+
}
110+
111+
return DoiFormatter::resolveUrl($doi);
112+
}
66113
}

classes/factories/ThothChapterFactory.inc.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public function createFromChapter($chapter)
3030

3131
return new ThothWork([
3232
'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,
33+
'workStatus' => $this->getWorkStatusByDatePublished($chapter, $publication),
3634
'fullTitle' => $chapter->getLocalizedFullTitle(),
3735
'title' => $chapter->getLocalizedTitle(),
3836
'subtitle' => $chapter->getLocalizedData('subtitle'),
@@ -50,4 +48,15 @@ public function createFromChapter($chapter)
5048
)
5149
]);
5250
}
51+
52+
public function getWorkStatusByDatePublished($chapter, $publication)
53+
{
54+
$dataPublished = $chapter->getDatePublished() ?? $publication->getData('datePublished');
55+
56+
if ($dataPublished && $dataPublished <= \Core::getCurrentDate()) {
57+
return ThothWork::WORK_STATUS_ACTIVE;
58+
}
59+
60+
return ThothWork::WORK_STATUS_FORTHCOMING;
61+
}
5362
}

classes/formatters/HtmlStripper.inc.php

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

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

2020
public static function stripTags($string)
2121
{

classes/services/ThothContributionService.inc.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public function registerByPublication($publication)
5555
{
5656
$authors = DAORegistry::getDAO('AuthorDAO')->getByPublicationId($publication->getId());
5757
$primaryContactId = $publication->getData('primaryContactId');
58+
59+
$chapterAuthorDao = DAORegistry::getDAO('ChapterAuthorDAO');
60+
$chapterAuthors = $chapterAuthorDao->getAuthors($publication->getId())->toArray();
61+
$chapterAuthorIds = array_map(fn ($chapterAuthor) => $chapterAuthor->getId(), $chapterAuthors);
62+
63+
$authors = array_filter($authors, function ($author) use ($chapterAuthorIds, $primaryContactId) {
64+
return $author->getId() === $primaryContactId || !in_array($author->getId(), $chapterAuthorIds);
65+
});
66+
5867
$thothBookId = $publication->getData('thothBookId');
5968
foreach ($authors as $author) {
6069
$this->register($author, $thothBookId, $primaryContactId);

classes/services/ThothPublicationService.inc.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ public function registerByPublication($publication)
5050
{
5151
$thothBookId = $publication->getData('thothBookId');
5252
$publicationFormats = DAORegistry::getDAO('PublicationFormatDAO')
53-
->getApprovedByPublicationId($publication->getId())
53+
->getByPublicationId($publication->getId())
5454
->toArray();
5555
foreach ($publicationFormats as $publicationFormat) {
56-
if ($publicationFormat->getIsAvailable()) {
57-
$this->register($publicationFormat, $thothBookId);
58-
}
56+
$this->register($publicationFormat, $thothBookId);
5957
}
6058
}
6159

@@ -76,9 +74,7 @@ public function registerByChapter($chapter)
7674
$publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
7775
foreach ($chapterSubmissionFiles as $chapterSubmissionFile) {
7876
$publicationFormat = $publicationFormatDao->getById($chapterSubmissionFile->getData('assocId'));
79-
if ($publicationFormat->getIsAvailable()) {
80-
$this->register($publicationFormat, $thothChapterId, $chapter->getId());
81-
}
77+
$this->register($publicationFormat, $thothChapterId, $chapter->getId());
8278
}
8379
}
8480

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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)