Skip to content

Commit

Permalink
#24 Add citation style format form to the plugin's settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Jul 21, 2020
1 parent 83e5460 commit 21425c4
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 16 deletions.
143 changes: 138 additions & 5 deletions JatsParserPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2017-2018 Vitalii Bezsheiko
* Distributed under the GNU GPL v3.
*
* @class JatsParserSettingsForm
* @class JatsParserPlugin
* @ingroup plugins_generic_jatsParser
*
*/
Expand All @@ -17,9 +17,10 @@
import('plugins.generic.jatsParser.classes.components.forms.PublicationJATSUploadForm');
import('lib.pkp.classes.file.SubmissionFileManager');

use JATSParser\Body\Document as Document;
use JATSParser\PDF\TCPDFDocument as TCPDFDocument;
use JATSParser\Body\Document;
use JATSParser\PDF\TCPDFDocument;
use JATSParser\HTML\Document as HTMLDocument;
use \PKP\components\forms\FormComponent;

define("CREATE_PDF_QUERY", "download=pdf");

Expand Down Expand Up @@ -47,6 +48,7 @@ function register($category, $path, $mainContextId = null) {
HookRegistry::register('Publication::edit', array($this, 'editPublication'));
HookRegistry::register('Templates::Article::Main', array($this, 'displayFullText'));
HookRegistry::register('TemplateManager::display', array($this, 'themeSpecificStyles'));
HookRegistry::register('Form::config::before', array($this, 'addCitationsFormFields'));

return true;
}
Expand Down Expand Up @@ -488,8 +490,17 @@ public function addToSchema($hookName, $args) {
"nullable"
]
}';
$propRef = '{
"type": "boolean",
"multilingual": true,
"apiSummary": true,
"validation": [
"nullable"
]
}';
$schema->properties->{'jatsParser::fullTextFileId'} = json_decode($propId);
$schema->properties->{'jatsParser::fullText'} = json_decode($propText);
$schema->properties->{'jatsParser::references'} = json_decode($propRef);
}

/**
Expand Down Expand Up @@ -751,10 +762,55 @@ function _setSupplImgPath(SubmissionFile $submissionFile, string $htmlString): s
* @brief get the list of types of files that are dependent from an original JATS XML (from which full-text was generated) and are accessible to public
*/
public static function getSupportedSupplFileTypes() {
return array(
return [
'image/png',
'image/jpeg'
);
];
}

public static function getSupportedCitationStyles() {
return [
[
'id' => 'acm-sig-proceedings',
'title' => 'plugins.generic.jatsParser.style.acm-sig-proceedings',
],
[
'id' => 'acs-nano',
'title' => 'plugins.generic.jatsParser.style.acs-nano',
],
[
'id' => 'apa',
'title' => 'plugins.generic.jatsParser.style.apa',
],
[
'id' => 'associacao-brasileira-de-normas-tecnicas',
'title' => 'plugins.generic.jatsParser.style.associacao-brasileira-de-normas-tecnicas',
],
[
'id' => 'chicago-author-date',
'title' => 'plugins.generic.jatsParser.style.chicago-author-date',
],
[
'id' => 'harvard-cite-them-right',
'title' => 'plugins.generic.jatsParser.style.harvard-cite-them-right',
],
[
'id' => 'ieee',
'title' => 'plugins.generic.jatsParser.style.ieee',
],
[
'id' => 'modern-language-association',
'title' => 'plugins.generic.jatsParser.style.modern-language-association',
],
[
'id' => 'turabian-fullnote-bibliography',
'title' => 'plugins.generic.jatsParser.style.turabian-fullnote-bibliography',
],
[
'id' => 'vancouver',
'title' => 'plugins.generic.jatsParser.style.vancouver',
],
];
}

/**
Expand Down Expand Up @@ -791,6 +847,10 @@ function themeSpecificStyles(string $hookname, array $args) {
return false;
}

/**
* @return void
* @brief iterate through all submissions and add full-text from galleys
*/
public function importGalleys() {
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
$request = $this->getRequest();
Expand Down Expand Up @@ -846,4 +906,77 @@ public function importGalleys() {
}
}
}

/**
* @param $hookName string Form::config::before
* @param $form FormComponent The form object
*/
public function addCitationsFormFields(string $hookName, FormComponent $form): void {
if ($form->id !== 'citations' || !empty($form->errors)) return;

$path = parse_url($form->action)['path'];
if (!$path) return;

$args = explode('/', $path);
$publicationId = 0;
if ($key = array_search('publications', $args)) {
if (array_key_exists($key+1, $args)) {
$publicationId = intval($args[$key+1]);
}
}

if (!$publicationId) return;

$publication = Services::get('publication')->get($publicationId);
if (!$publication) return;

$submissionFileIds = array_unique($publication->getData('jatsParser::fullTextFileId'));
if (empty($submissionFileIds)) return;

$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');

$submissionFiles = [];
foreach ($submissionFileIds as $submissionFileId) {
$submissionFiles[] = $submissionFileDao->getLatestRevision($submissionFileId);
}

if (empty($submissionFiles)) return;

if (count($submissionFiles) > 1) {
$options = [];
foreach ($submissionFiles as $submissionFile) {
$options[] = [
'value' => $submissionFile->getId(),
'label' => $submissionFile->getLocalizedName(),
];
}

$options[] = [
'value' => null,
'label' => __('common.default'),
];

$form->addField(new \PKP\components\forms\FieldOptions('jatsParser::references', [
'label' => __('plugins.generic.jatsParser.publication.jats.references.label'),
'description' => __('plugins.generic.jatsParser.publication.jats.references.description'),
'type' => 'radio',
'options' => $options,
]));
} else {
$submissionFile = array_shift($submissionFiles);
$form->addField(new \PKP\components\forms\FieldOptions('jatsParser::references', [
'label' => __('plugins.generic.jatsParser.publication.jats.references.label'),
'description' => __('plugins.generic.jatsParser.publication.jats.references.description'),
'type' => 'checkbox',
'options' => [
[
'value' => $submissionFile->getId(),
'label' => $submissionFile->getLocalizedName(),
],
],

]));
}

}
}
27 changes: 20 additions & 7 deletions JatsParserSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@


/**
* @file plugins/generic/jatsParser/JatsParserSettingsForm.inc.php
*
* @file plugins/generic/jatsParser/JatsParserSettingsForm.inc.php
*
* Copyright (c) 2017-2018 Vitaliy Bezsheiko, MD, Department of Psychosomatic Medicine and Psychotherapy, Bogomolets National Medical University, Kyiv, Ukraine
* Distributed under the GNU GPL v3.
* Distributed under the GNU GPL v3.
*
* @class JatsParserSettingsForm
* @ingroup plugins_generic_jatsParser
*
*
* @brief Form for journal managers to modify jatsParser plugin settings
*/
*/

import('lib.pkp.classes.form.Form');

Expand Down Expand Up @@ -48,13 +48,14 @@ function initData() {

$this->setData('references', $plugin->getSetting($contextId, 'references'));
$this->setData('convertToPdf', $plugin->getSetting($contextId, 'convertToPdf'));
$this->setData('citationStyle', $plugin->getSetting($contextId, 'citationStyle'));
}

/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$this->readUserVars(array('references', 'convertToPdf', 'galleysImport'));
$this->readUserVars(array('references', 'convertToPdf', 'citationStyle', 'customStyleInput', 'galleysImport'));
}

/**
Expand All @@ -63,7 +64,10 @@ function readInputData() {
*/
function fetch($request, $template = null, $display = false) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->_plugin->getName());
$templateMgr->assign([
'pluginName' => $this->_plugin->getName(),
'citationStyles' => $this->_plugin::getSupportedCitationStyles()
]);
return parent::fetch($request, $template, $display);
}

Expand All @@ -84,6 +88,15 @@ function execute(...$functionArgs) {
}
$plugin->updateSetting($contextId, 'convertToPdf', $convertToPdf);

// Citation Style Format
$citationStyle = $this->getData('citationStyle');
if ($citationStyle == 'customStyle') {
$plugin->updateSetting($contextId, 'citationStyle', $this->getData('customStyleInput'));
} else {
$plugin->updateSetting($contextId, 'citationStyle', $this->getData('citationStyle'));
}

// Import galleys
if ($importGalleys = $this->getData('galleysImport')) {
$plugin->importGalleys();
}
Expand Down
16 changes: 13 additions & 3 deletions classes/components/forms/PublicationJATSUploadForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function __construct($action, $locales, $publication, $submissionFiles, $
$this->successMessage = __('plugins.generic.jatsParser.publication.jats.fulltext.success');
$this->locales = $locales;

$options = array();
$options = [];
foreach ($locales as $value) {
$locale = $value['key'];
$lang = array();
$lang = [];
if (empty($submissionFiles)) break;
foreach ($submissionFiles as $submissionFile) {
$subName = $submissionFile->getName($locale);
Expand Down Expand Up @@ -64,9 +64,19 @@ public function __construct($action, $locales, $publication, $submissionFiles, $
'type' => 'radio',
'options' => $options,
'value' => $publication->getData('jatsParser::fullTextFileId'),
]))->addField(new FieldOptions('jatsParser::linksToRefs', [
'label' => __('plugins.generic.jatsParser.publication.jats.links.label'),
'type' => 'checkbox',
'showWhen' => 'jatsParser::references',
'options' => [
[
'value' => true,
'label' => __('common.yes')
]
],
]));
} else {
$this->addField(new FieldHTML("preview", array(
$this->addField(new FieldHTML("addProductionReadyFiles", array(
'description' => $msg
)));
}
Expand Down
20 changes: 20 additions & 0 deletions locale/en_US/locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<message key="plugins.generic.jatsParser.galley.import">Import of JATS XML galleys</message>
<message key="plugins.generic.jatsParser.galley.import.description">This options allows to save JATS XML galleys as a full-text across all publications in the journal. Import is omitted if a publication already has full-text for a given galley. Import starts immediately after saving the form</message>
<message key="plugins.generic.jatsParser.galley.import.title">Import full-text from galleys</message>

<!-- Plugin galley settings -->
<message key="plugins.generic.jatsParser.galley.settings.display">Display Settings</message>
<message key="plugins.generic.jatsParser.galley.settings.display.description">These settings are applied to XML galleys on individual basis.</message>
Expand All @@ -48,4 +49,23 @@
<message key="plugins.generic.jatsParser.publication.jats.label">Generate article's fulltext from submission file in JATS XML format</message>
<message key="plugins.generic.jatsParser.publication.jats.description"><![CDATA[The file can be uploaded as a <a href="#workflow" id="jatsParser__linkToProduction">production ready</a> to be listed below. To see the preview, please, follow the <a id="jatsParser__linkPreview" href="{$previewPath}" target="_blank">link</a> after choosing an item from the list.]]></message>
<message key="plugins.generic.jatsParser.publication.jats.descriptionEmpty"><![CDATA[The list of JATS XML files is empty. Please, upload the file to the <a href="#workflow" id="jatsParser__linkToProduction">production stage</a> and it will appear below for full-text generation.]]></message>
<message key="plugins.generic.jatsParser.publication.jats.references.label">Retrieve references from JATS XML?</message>
<message key="plugins.generic.jatsParser.publication.jats.references.description">Reference list will be retrieved from JATS XML and saved as a part of the publication. If references are already included into the publication, they are going to be rewritten.</message>
<message key="plugins.generic.jatsParser.publication.jats.links.label">Format in-text links to references?</message>

<!-- Citation Style Formats -->
<message key="plugins.generic.jatsParser.style.acm-sig-proceedings">ACM</message>
<message key="plugins.generic.jatsParser.style.acs-nano">ACS</message>
<message key="plugins.generic.jatsParser.style.apa">APA</message>
<message key="plugins.generic.jatsParser.style.associacao-brasileira-de-normas-tecnicas">ABNT</message>
<message key="plugins.generic.jatsParser.style.chicago-author-date">Chicago</message>
<message key="plugins.generic.jatsParser.style.harvard-cite-them-right">Harvard</message>
<message key="plugins.generic.jatsParser.style.ieee">IEEE</message>
<message key="plugins.generic.jatsParser.style.modern-language-association">MLA</message>
<message key="plugins.generic.jatsParser.style.turabian-fullnote-bibliography">Turabian</message>
<message key="plugins.generic.jatsParser.style.vancouver">Vancouver</message>
<message key="plugins.generic.jatsParser.style.custom">Other citation style formats</message>
<message key="plugins.generic.jatsParser.style.description"><![CDATA[The style format for references parsed by the plugin. For other styles, visit <a target="_blank" href="https://github.com/citation-style-language/styles">CSL repository</a> to see if it's supported.]]></message>
<message key="plugins.generic.jatsParser.style.label">e.g.: american-medical-association</message>

</locale>
38 changes: 37 additions & 1 deletion templates/settingsForm.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{**
{**
* plugins/generic/JATSParserPlugin/settingsForm.tpl
*
* Copyright (c) 2017-2018 Vitalii Bezsheiko
Expand Down Expand Up @@ -27,6 +27,24 @@
{fbvFormSection list=true}
{fbvElement type="checkbox" id="convertToPdf" name="convertToPdf" checked=$convertToPdf label="plugins.generic.jatsParser.settings.display.pdf"}
{/fbvFormSection}

{assign var='otherStyleValue' value=true}
{fbvFormSection list=true description="plugins.generic.jatsParser.style.description"}
{foreach from=$citationStyles item="citationStyleItem"}
{if $citationStyleItem["id"]|compare:$citationStyle}
{assign var='otherStyleValue' value=false}
{/if}
{fbvElement type="radio" id=$citationStyleItem["id"] name="citationStyle" value=$citationStyleItem["id"] checked=$citationStyleItem["id"]|compare:$citationStyle label=$citationStyleItem["title"]}
{/foreach}
{fbvElement type="radio" id="customStyle" name="citationStyle" value="customStyle" checked=$otherStyleValue label="plugins.generic.jatsParser.style.custom"}
{/fbvFormSection}
{fbvFormSection}
{if $otherStyleValue}
{fbvElement type="text" id="customStyleInput" name="customStyleInput" value=$citationStyle label="plugins.generic.jatsParser.style.label"}
{else}
{fbvElement type="text" id="customStyleInput" name="customStyleInput" disabled=true label="plugins.generic.jatsParser.style.label"}
{/if}
{/fbvFormSection}
{/fbvFormArea}

{fbvFormArea id="jatsParserGalleyImport" title="plugins.generic.jatsParser.galley.import"}
Expand All @@ -39,3 +57,21 @@
<p><span class="formRequired">{translate key="common.requiredField"}</span></p>

</form>
<script type="text/javascript">
{literal}
$(document).ready(function() {
var customStyleInput = $('input[name="customStyleInput"]');
var inputs = $('input[name="citationStyle"]');
inputs.change(function () {
if ($(this).is(':checked')) {
var checkedItemId = $(this).attr('id');
if (checkedItemId === 'customStyle') {
customStyleInput.removeAttr('disabled');
} else {
customStyleInput.attr('disabled', 'disabled');
}
}
});
});
{/literal}
</script>

0 comments on commit 21425c4

Please sign in to comment.