From b237fd7328421e038d40220dea9e3f781164ebfc Mon Sep 17 00:00:00 2001 From: marsilius Date: Mon, 31 May 2021 11:26:57 +0200 Subject: [PATCH 1/6] Add OMP 3.3 compatibility. --- CitationStyleLanguagePlugin.inc.php | 246 ++++++++++++++++----- CitationStyleLanguageSettingsForm.inc.php | 1 + css/citationStyleLanguagePlugin.css | 103 +++++++++ locale/de_DE/locale.po | 6 + locale/en_US/locale.po | 6 + pages/CitationStyleLanguageHandler.inc.php | 30 ++- readme.md | 6 +- templates/citation-styles/ris.tpl | 48 +++- templates/citationblock.tpl | 51 +++++ templates/settings.tpl | 8 +- 10 files changed, 437 insertions(+), 68 deletions(-) create mode 100644 css/citationStyleLanguagePlugin.css create mode 100644 templates/citationblock.tpl diff --git a/CitationStyleLanguagePlugin.inc.php b/CitationStyleLanguagePlugin.inc.php index b7d02ad..c7920de 100644 --- a/CitationStyleLanguagePlugin.inc.php +++ b/CitationStyleLanguagePlugin.inc.php @@ -35,7 +35,8 @@ public function getDisplayName() { * @copydoc Plugin::getDescription() */ public function getDescription() { - return __('plugins.generic.citationStyleLanguage.description'); + return self::isApplicationOmp() ? __('plugins.generic.citationStyleLanguage.description.omp') + : __('plugins.generic.citationStyleLanguage.description'); } /** @@ -45,7 +46,12 @@ public function register($category, $path, $mainContextId = null) { $success = parent::register($category, $path, $mainContextId); if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return $success; if ($success && $this->getEnabled($mainContextId)) { - HookRegistry::register('ArticleHandler::view', array($this, 'getArticleTemplateData')); + if (self::isApplicationOmp()) { + HookRegistry::register('CatalogBookHandler::book', array($this, 'getTemplateData')); + HookRegistry::register('Templates::Catalog::Book::Details', array($this, 'displayCitationMonograph')); + } else { + HookRegistry::register('ArticleHandler::view', array($this, 'getTemplateData')); + } HookRegistry::register('LoadHandler', array($this, 'setPageHandler')); } return $success; @@ -257,24 +263,43 @@ public function getCitationStyleConfig($styleId) { * @param $args array * @return false */ - public function getArticleTemplateData($hookName, $args) { + public function getTemplateData($hookName, $args) { + $templateMgr = TemplateManager::getManager(); $request = $args[0]; - $issue = $args[1]; - $article = $args[2]; - $publication = $args[3]; + if (self::isApplicationOmp()) { + $submission =& $args[1]; + $publication = $submission->getCurrentPublication(); + $issue = NULL; + if (NULL === $publication) { + return FALSE; + } + $templateMgr->addStyleSheet( + 'cslPluginStyles', + $request->getBaseUrl() . '/' . $this->getPluginPath() . '/css/citationStyleLanguagePlugin.css', + array( + 'priority' => STYLE_SEQUENCE_LAST, + 'contexts' => array('frontend'), + 'inline' => FALSE, + ) + ); + } else { + $issue = $args[1]; + $submission = $args[2]; + $publication = $args[3]; + } + $context = $request->getContext(); $contextId = $context ? $context->getId() : 0; - $templateMgr = TemplateManager::getManager(); $citationArgs = array( - 'submissionId' => $article->getId(), + 'submissionId' => $submission->getId(), 'publicationId' => $publication->getId(), ); $citationArgsJson = $citationArgs; $citationArgsJson['return'] = 'json'; $templateMgr->assign(array( - 'citation' => $this->getCitation($request, $article, $this->getPrimaryStyleName($contextId), $issue, $publication), + 'citation' => $this->getCitation($request, $submission, $this->getPrimaryStyleName($contextId), $issue, $publication), 'citationArgs' => $citationArgs, 'citationArgsJson' => $citationArgsJson, 'citationStyles' => $this->getEnabledCitationStyles($contextId), @@ -289,6 +314,25 @@ public function getArticleTemplateData($hookName, $args) { return false; } + /** + * Add citation style language to book view page + * Hooked to `Templates::Catalog::Book::Main` + * + * @param $hookName string + * @param $params array array [ + * @option Smarty + * @option string HTML output to return + * ] + * @return false + */ + public function displayCitationMonograph($hookName, $params) { + $smarty =& $params[1]; + $output =& $params[2]; + $output .= $smarty->fetch($this->getTemplateResource('citationblock.tpl')); + + return FALSE; + } + /** * Get a specified citation for a given article * @@ -299,50 +343,102 @@ public function getArticleTemplateData($hookName, $args) { * @see Zotero's mappings https://aurimasv.github.io/z2csl/typeMap.xml#map-journalArticle * @see Mendeley's mappings http://support.mendeley.com/customer/portal/articles/364144-csl-type-mapping * @param $request Request - * @param $article Submission + * @param $submission Submission * @param $citationStyle string Name of the citation style to use. * @param $issue Issue Optional. Will fetch from db if not passed. * @param $publication Publication Optional. A particular version * @return string */ - public function getCitation($request, $article, $citationStyle = 'apa', $issue = null, $publication = null) { - $publication = $publication ?? $article->getCurrentPublication(); - $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ - $issue = $issue ?? $issueDao->getById($publication->getData('issueId')); + public function getCitation($request, Submission $submission, $citationStyle = 'apa', $issue = null, $publication = null) { + $publication = $publication ?? $submission->getCurrentPublication(); $context = $request->getContext(); import('lib.pkp.classes.core.PKPString'); $citationData = new stdClass(); - $citationData->type = 'article-journal'; - $citationData->id = $article->getId(); - $citationData->title = $publication->getLocalizedFullTitle(); - $citationData->{'container-title'} = htmlspecialchars($context->getLocalizedName()); - $citationData->{'publisher-place'} = $this->getSetting($context->getId(), 'publisherLocation'); - $citationData->abstract = htmlspecialchars($publication->getLocalizedData('abstract')); + if (self::isApplicationOmp()){ + $citationData->type = 'book'; + $citationData->risType = 'BOOK'; + $citationData->publisher = htmlspecialchars($context->getLocalizedName()); + + /* @var $submissionKeywordDao SubmissionKeywordDAO */ + $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); + $keywords = $submissionKeywordDao->getKeywords($publication->getId(), array(AppLocale::getLocale())); + $citationData->keywords = $keywords[AppLocale::getLocale()]; + + /* @var $submissionLanguageDao SubmissionLanguageDAO */ + $submissionLanguageDao = DAORegistry::getDAO('SubmissionLanguageDAO'); + $languages = $submissionLanguageDao->getLanguages($publication->getId(), array(AppLocale::getLocale())); + if (array_key_exists(AppLocale::getLocale(), $languages)) { + $citationData->languages = $languages[AppLocale::getLocale()]; + } + $citationData->serialNumber = array(); + $publicationFormats = $publication->getData('publicationFormats'); + /** @var PublicationFormat $publicationFormat */ + foreach ($publicationFormats as $publicationFormat) { + if ($publicationFormat->getIsApproved()) { + $identificationCodes = $publicationFormat->getIdentificationCodes(); + $identificationCodes = $identificationCodes->toArray(); + foreach ($identificationCodes as $identificationCode) { + $citationData->serialNumber[] = htmlspecialchars($identificationCode->getValue()); + } + } + } - $abbreviation = $context->getData('abbreviation', $context->getPrimaryLocale()) ?? $context->getData('acronym', $context->getPrimaryLocale()); - if ($abbreviation) $citationData->{'container-title-short'} = htmlspecialchars($abbreviation); + $seriesId = $publication->getData('seriesId'); + if ($seriesId) { + /** @var SeriesDAO $seriesDao */ + $seriesDao = DAORegistry::getDAO('SeriesDAO'); + if (NULL !== $seriesDao) { + $series = $seriesDao->getById($seriesId); + if (NULL !== $series) { + $citationData->{'collection-title'} = htmlspecialchars(trim($series->getLocalizedFullTitle())); + $citationData->volume = htmlspecialchars($publication->getData('seriesPosition')); + $citationData->{'collection-editor'} = htmlspecialchars($series->getEditorsString()); + $onlineISSN = $series->getOnlineISSN(); + if (NULL !== $onlineISSN && !empty($onlineISSN)) { + $citationData->serialNumber[] = htmlspecialchars($onlineISSN); + } + $printISSN = $series->getPrintISSN(); + if (NULL !== $printISSN && !empty($printISSN)) { + $citationData->serialNumber[] = htmlspecialchars($printISSN); + } + } + } + } + } else { + $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ + $issue = $issue ?? $issueDao->getById($publication->getData('issueId')); + $citationData->type = 'article-journal'; + $citationData->risType = 'JOUR'; + $citationData->{'container-title'} = htmlspecialchars($context->getLocalizedName()); + if ($issue) { + $citationData->volume = htmlspecialchars($issue->getData('volume')); + // Zotero prefers issue and Mendeley uses `number` to store revisions + $citationData->issue = htmlspecialchars($issue->getData('number')); + } - if ($issue) { - $citationData->volume = htmlspecialchars($issue->getData('volume')); - // Zotero prefers issue and Mendeley uses `number` to store revisions - $citationData->issue = htmlspecialchars($issue->getData('number')); + $sectionDao = DAORegistry::getDAO('SectionDAO'); /** @var $sectionDao SectionDAO */ + if ($sectionId = $publication->getData('sectionId')) { + $section = $sectionDao->getById($sectionId); + if ($section && !$section->getHideTitle()) $citationData->section = htmlspecialchars($section->getTitle($context->getPrimaryLocale())); + } } + $citationData->id = $submission->getId(); + $citationData->title = htmlspecialchars($publication->getLocalizedFullTitle()); + $citationData->{'publisher-place'} = $this->getSetting($context->getId(), 'publisherLocation'); + $citationData->abstract = htmlspecialchars(strip_tags($publication->getLocalizedData('abstract'))); - $sectionDao = DAORegistry::getDAO('SectionDAO'); /** @var $sectionDao SectionDAO */ - if ($sectionId = $publication->getData('sectionId')) { - $section = $sectionDao->getById($sectionId); - if ($section && !$section->getHideTitle()) $citationData->section = htmlspecialchars($section->getTitle($context->getPrimaryLocale())); - } + $abbreviation = $context->getData('abbreviation', $context->getPrimaryLocale()) ?? $context->getData('acronym', $context->getPrimaryLocale()); + if ($abbreviation) $citationData->{'container-title-short'} = htmlspecialchars($abbreviation); $citationData->URL = $request->getDispatcher()->url( $request, ROUTE_PAGE, null, - 'article', - 'view', - $article->getBestId() + self::isApplicationOmp() ? 'catalog' : 'article', + self::isApplicationOmp() ? 'book' : 'view', + (string) $submission->getId() ); $citationData->accessed = new stdClass(); $citationData->accessed->raw = date('Y-m-d'); @@ -358,14 +454,41 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = $currentAuthor->family = htmlspecialchars($author->getLocalizedFamilyName()); $currentAuthor->given = htmlspecialchars($author->getLocalizedGivenName()); } - $citationData->author[] = $currentAuthor; + if (self::isApplicationOmp() ) { + $userGroup = $author->getUserGroup(); + if (NULL !== $userGroup) { + switch ($userGroup->getData('nameLocaleKey')) { + case 'default.groups.name.volumeEditor': + if (!isset($citationData->editor)) { + $citationData->editor = array(); + } + $citationData->editor[] = $currentAuthor; + break; + case 'default.groups.name.author': + if (!isset($citationData->author)) { + $citationData->author = array(); + } + $citationData->author[] = $currentAuthor; + break; + case 'default.groups.name.translator': + if (!isset($citationData->translator)) { + $citationData->translator = array(); + } + $citationData->translator[] = $currentAuthor; + break; + default: + } + } + } else { + $citationData->author[] = $currentAuthor; + } } } if ($publication->getData('datePublished')) { $citationData->issued = new stdClass(); $citationData->issued->raw = htmlspecialchars($publication->getData('datePublished')); - $publishedPublications = $article->getPublishedPublications(); + $publishedPublications = $submission->getPublishedPublications(); if (count($publishedPublications) > 1) { $originalPublication = array_reduce($publishedPublications, function($a, $b) { return $a && $a->getId() < $b->getId() ? $a : $b; @@ -376,16 +499,20 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = $citationData->{'original-date'}->raw = htmlspecialchars($originalPublication->getData('datePublished')); } } - } elseif ($issue && $issue->getPublished()) { + } elseif ( !self::isApplicationOmp() && $issue && $issue->getPublished()) { $citationData->issued = new stdClass(); $citationData->issued->raw = htmlspecialchars($issue->getDatePublished()); } + if ($publication->getData('pub-id::doi')) { + $citationData->DOI = htmlspecialchars($publication->getData('pub-id::doi')); + } + if ($publication->getData('pages')) { $citationData->page = htmlspecialchars($publication->getData('pages')); } - HookRegistry::call('CitationStyleLanguage::citation', array(&$citationData, &$citationStyle, $article, $issue, $context, $publication)); + HookRegistry::call('CitationStyleLanguage::citation', array(&$citationData, &$citationStyle, $submission, $issue, $context, $publication)); $citation = ''; @@ -395,14 +522,20 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = if (!empty($styleConfig)) { if (!empty($styleConfig['useTemplate'])) { $templateMgr = TemplateManager::getManager($request); - $templateMgr->assign(array( + $assignArray = array( 'citationData' => $citationData, 'citationStyle' => $citationStyle, - 'article' => $article, 'publication' => $publication, - 'issue' => $issue, - 'journal' => $context, - )); + ); + if (self::isApplicationOmp()) { + $assignArray['book'] = $submission; + $assignArray['press'] = $context; + } else { + $assignArray['article'] = $submission; + $assignArray['issue'] = $issue; + $assignArray['journal'] = $context; + } + $templateMgr->assign($assignArray); $citation = $templateMgr->fetch($styleConfig['useTemplate']); } else { $style = $this->loadStyle($styleConfig); @@ -448,17 +581,20 @@ public function loadStyle($styleConfig) { * software. * * @param $request Request - * @param $article Submission + * @param $submission Submission * @param $citationStyle string Name of the citation style to use. * @param $issue Issue Optional. Will fetch from db if not passed. * @return string */ - public function downloadCitation($request, $article, $citationStyle = 'ris', $issue = null) { - $journal = $request->getContext(); - - if (empty($issue)) { - $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ - $issue = $issueDao->getById($article->getCurrentPublication()->getData('issueId')); + public function downloadCitation($request, $submission, $citationStyle = 'ris', $issue = null) { + if ( !self::isApplicationOmp() ) + { + $journal = $request->getContext(); + + if (empty($issue)) { + $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ + $issue = $issueDao->getById($submission->getCurrentPublication()->getData('issueId')); + } } $styleConfig = $this->getCitationStyleConfig($citationStyle); @@ -466,14 +602,15 @@ public function downloadCitation($request, $article, $citationStyle = 'ris', $is return false; } - $citation = trim(strip_tags($this->getCitation($request, $article, $citationStyle, $issue))); + $publication = $submission->getCurrentPublication(); + $citation = trim(strip_tags($this->getCitation($request, $submission, $citationStyle, $issue))); // TODO this is likely going to cause an error in a citation some day, // but is necessary to get the .ris downloadable format working. The // CSL language doesn't seem to offer a way to indicate a line break. // See: https://github.com/citation-style-language/styles/issues/2831 $citation = str_replace('\n', "\n", $citation); - $encodedFilename = urlencode(substr($article->getLocalizedTitle(), 0, 60)) . '.' . $styleConfig['fileExtension']; + $encodedFilename = urlencode(substr(($publication ? $publication->getLocalizedTitle() : ''), 0, 60)) . '.' . $styleConfig['fileExtension']; header("Content-Disposition: attachment; filename*=UTF-8''\"$encodedFilename\""); header('Content-Type: ' . $styleConfig['contentType']); @@ -559,4 +696,9 @@ public function setPageHandler($hookName, $params) { } return false; } + + public static function isApplicationOmp() : bool { + $applicationName = Application::get()->getName(); + return stripos($applicationName, 'omp') !== FALSE; + } } diff --git a/CitationStyleLanguageSettingsForm.inc.php b/CitationStyleLanguageSettingsForm.inc.php index bd21004..a3a3366 100644 --- a/CitationStyleLanguageSettingsForm.inc.php +++ b/CitationStyleLanguageSettingsForm.inc.php @@ -81,6 +81,7 @@ public function fetch($request, $template = null, $display = false) { 'primaryCitationStyle' => $this->getData('primaryCitationStyle'), 'enabledStyles' => $this->plugin->mapCitationIds($this->plugin->getEnabledCitationStyles($contextId)), 'enabledDownloads' => $this->plugin->mapCitationIds($this->plugin->getEnabledCitationDownloads($contextId)), + 'isApplicationOmp' => CitationStyleLanguagePlugin::isApplicationOmp(), )); return parent::fetch($request, $template, $display); diff --git a/css/citationStyleLanguagePlugin.css b/css/citationStyleLanguagePlugin.css new file mode 100644 index 0000000..109220e --- /dev/null +++ b/css/citationStyleLanguagePlugin.css @@ -0,0 +1,103 @@ +.citation_display .value +{ + font-size: 0.75rem; +} + +.citation_display .csl-left-margin +{ + display: none; +} + +.citation_display [aria-hidden="true"] +{ + display: none; +} + +.citation_display .citation_formats +{ + margin-top: 1em; + border: 1px solid rgba(0, 0, 0, 0.4); + border-radius: 2px; +} + +.citation_display .citation_formats_button +{ + position: relative; + background: transparent; + border: none; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + box-shadow: none; + padding: 0 1em; + width: 100%; + font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif; + font-weight: 400; + color: #777; + text-align: left; +} + +.citation_display .citation_formats_button:after +{ + display: inline-block; + font: normal normal normal 14px/1 FontAwesome; + font-size: inherit; + text-rendering: auto; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + content: "\f0d7"; + position: absolute; + top: 50%; + right: 1em; + transform: translate(0, -50%); +} +.citation_display .citation_formats_button[aria-expanded="true"]:after +{ + content: "\f0d8"; +} + +.citation_display .citation_formats_button:focus +{ + background: #ddd; + outline: 0; +} + +.citation_display .citation_formats_styles +{ + margin: 0; + padding: 0; + list-style: none; +} + +.citation_display .citation_formats_styles a +{ + display: block; + padding: 0.5em 1em; + border-bottom: 1px solid #bbb; + text-decoration: none; +} + +.citation_display .citation_formats_styles a:focus +{ + background: #ddd; + outline: 0; +} + +.citation_display .citation_formats_styles li:last-child a +{ + border-bottom: none; +} + +.citation_display .citation_formats_list .label +{ + padding: 1em 1em 0.25em 1em; +} + +.citation_display .citation_formats_styles + .label +{ + border-top: 1px solid #bbb; +} + +.citation_display span +{ + margin-right: 0.5em; +} diff --git a/locale/de_DE/locale.po b/locale/de_DE/locale.po index 9388ab1..c6abf9e 100644 --- a/locale/de_DE/locale.po +++ b/locale/de_DE/locale.po @@ -20,6 +20,9 @@ msgstr "Citation Style Language" msgid "plugins.generic.citationStyleLanguage.description" msgstr "Ermöglicht es Leser/innen, die bibliografischen Angaben für einen veröffentlichten Artikel in einem von mehreren Formaten in der Citation Style Language zu erhalten." +msgid "plugins.generic.citationStyleLanguage.description.omp" +msgstr "Ermöglicht es Leser/innen, die bibliografischen Angaben für ein veröffentlichtes Buch in einem von mehreren Formaten in der Citation Style Language zu erhalten." + msgid "plugins.generic.citationStyleLanguage.style.acm-sig-proceedings" msgstr "ACM" @@ -74,6 +77,9 @@ msgstr "Primäres Format für bibliographische Angaben" msgid "plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription" msgstr "Wählen Sie aus, in welchem Format Sie bibliografische Angaben standardmäßig auf der Artikelseite anzeigen möchten." +msgid "plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription.omp" +msgstr "Wählen Sie aus, in welchem Format Sie bibliografische Angaben standardmäßig auf der Buchseite anzeigen möchten." + msgid "plugins.generic.citationStyleLanguage.settings.publisherLocation.description" msgstr "" "Einige Zitierstile erfordern die Angabe des geografischen Standortes des " diff --git a/locale/en_US/locale.po b/locale/en_US/locale.po index 5e40c69..acb0b50 100644 --- a/locale/en_US/locale.po +++ b/locale/en_US/locale.po @@ -17,6 +17,9 @@ msgstr "Citation Style Language" msgid "plugins.generic.citationStyleLanguage.description" msgstr "Allow readers to get a published article's citation in one of several formats supported by the Citation Style Language." +msgid "plugins.generic.citationStyleLanguage.description.omp" +msgstr "Allow readers to get a published book's citation in one of several formats supported by the Citation Style Language." + msgid "plugins.generic.citationStyleLanguage.style.acm-sig-proceedings" msgstr "ACM" @@ -71,6 +74,9 @@ msgstr "Primary Citation Format" msgid "plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription" msgstr "Select which citation format you would like to display by default on your article landing page." +msgid "plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription.omp" +msgstr "Select which citation format you would like to display by default on your book landing page." + msgid "plugins.generic.citationStyleLanguage.settings.publisherLocation" msgstr "Publisher Location" diff --git a/pages/CitationStyleLanguageHandler.inc.php b/pages/CitationStyleLanguageHandler.inc.php index 2a7cabb..a8bbb73 100644 --- a/pages/CitationStyleLanguageHandler.inc.php +++ b/pages/CitationStyleLanguageHandler.inc.php @@ -16,8 +16,8 @@ import('classes.handler.Handler'); class CitationStyleLanguageHandler extends Handler { - /** @var Submission article being requested */ - public $article = null; + /** @var Submission $submission being requested */ + public $submission = null; /** @var Publication publication being requested */ public $publication = null; @@ -42,7 +42,13 @@ public function get($args, $request) { $this->_setupRequest($args, $request); $plugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin'); - $citation = $plugin->getCitation($request, $this->article, $this->citationStyle, $this->issue, $this->publication); + if (NULL === $plugin) { + if ($this->returnJson) { + return new JSONMessage(false); + } + exit; + } + $citation = $plugin->getCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication); if ($citation === false ) { if ($this->returnJson) { @@ -69,7 +75,9 @@ public function download($args, $request) { $this->_setupRequest($args, $request); $plugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin'); - $plugin->downloadCitation($request, $this->article, $this->citationStyle, $this->issue, $this->publication); + if (NULL !== $plugin) { + $plugin->downloadCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication); + } exit; } @@ -94,17 +102,17 @@ public function _setupRequest($args, $request) { $this->citationStyle = $args[0]; $this->returnJson = isset($userVars['return']) && $userVars['return'] === 'json'; - $this->article = Services::get('submission')->get($userVars['submissionId']); + $this->submission = Services::get('submission')->get($userVars['submissionId']); - if (!$this->article) { + if (!$this->submission) { $request->getDispatcher()->handle404(); } $this->publication = !empty($userVars['publicationId']) ? Services::get('publication')->get($userVars['publicationId']) - : $this->article->getCurrentPublication(); + : $this->submission->getCurrentPublication(); - if ($this->article) { + if ($this->submission && !CitationStyleLanguagePlugin::isApplicationOmp()) { $issueDao = DAORegistry::getDAO('IssueDAO'); // Support OJS 3.1.x and 3.2 $issueId = method_exists($this->article, 'getCurrentPublication') ? $this->article->getCurrentPublication()->getData('issueId') : $this->article->getIssueId(); @@ -114,14 +122,16 @@ public function _setupRequest($args, $request) { // Disallow access to unpublished submissions, unless the user is a // journal manager or an assigned subeditor or assistant. This ensures the // article preview will work for those who can see it. - if (!$this->issue || !$this->issue->getPublished() || $this->article->getStatus() != STATUS_PUBLISHED) { + if ($this->submission->getData('status') !== STATUS_PUBLISHED + || (!CitationStyleLanguagePlugin::isApplicationOmp() && !$this->issue ) + || (!CitationStyleLanguagePlugin::isApplicationOmp() && !$this->issue->getPublished())) { $userCanAccess = false; if ($user && $user->hasRole([ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT], $context->getId())) { $isAssigned = false; $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); - $assignments = $stageAssignmentDao->getBySubmissionAndStageId($this->article->getId()); + $assignments = $stageAssignmentDao->getBySubmissionAndStageId($this->submission->getId()); foreach ($assignments as $assignment) { if ($assignment->getUser()->getId() !== $user->getId()) { continue; diff --git a/readme.md b/readme.md index 1664ee0..ab6f657 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ -# Citation Style Language plugin for OJS 3 +# Citation Style Language plugin for OJS 3 and OMP 3 -An OJS 3 plugin to generate an article citation in any CSL citation style using [citeproc-php](https://github.com/seboettg/citeproc-php). +An OJS 3/OMP 3 plugin to generate an article or book citation in any CSL citation style using [citeproc-php](https://github.com/seboettg/citeproc-php). ## License This plugin is licensed under the GNU General Public License v2. @@ -10,4 +10,4 @@ Consult the [citeproc-php](https://github.com/seboettg/citeproc-php) licensing i Each CSL file has it's own licensing information attached to the XML. ## Compatibility -This plugin is compatible with OJS 3.1.x. +This plugin is compatible with OJS 3.3.x and OMP 3.3.x. diff --git a/templates/citation-styles/ris.tpl b/templates/citation-styles/ris.tpl index 259a6fc..bed5efd 100644 --- a/templates/citation-styles/ris.tpl +++ b/templates/citation-styles/ris.tpl @@ -16,20 +16,64 @@ *} {assign var="containerTitle" value="container-title"} {assign var="containerTitleShort" value="container-title-short"} -TY - JOUR +{assign var="collectionTitle" value="collection-title"} +{assign var="collectionEditor" value="collection-editor"} +{assign var="publisherPlace" value="publisher-place"} +TY - {$citationData->risType} {foreach from=$citationData->author item="author"} AU - {$author->family}, {$author->given} {/foreach} +{foreach from=$citationData->$collectionEditor item="editor"} +A2 - {$editor->family}, {$editor->given} +{/foreach} +{foreach from=$citationData->translator item="translator"} +A4 - {$translator->family}, {$translator->given} +{/foreach} +{foreach from=$citationData->editor item="editor"} +ED - {$editor->family}, {$editor->given} +{/foreach} +TI - {$citationData->title} +{if $citationData->risType === 'JOUR'}{** OJS only **} PY - {$citationData->issued->raw|date_format:"%Y/%m/%d"} Y2 - {$citationData->accessed->raw|date_format:"%Y/%m/%d"} -TI - {$citationData->title} JF - {$citationData->$containerTitle} JA - {$citationData->$containerTitleShort} VL - {$citationData->volume} IS - {$citationData->issue} SE - {$citationData->section} +{else}{** OMP only **} +{if $citationData->$containerTitle} +T2 - {trim($citationData->$containerTitle)} +{/if} +{if $citationData->$collectionTitle} +T3 - {trim($citationData->$collectionTitle)} +{/if} +{if $citationData->volume} +M1 - {$citationData->volume} +{/if} +PP - {$citationData->$publisherPlace} +PB - {$citationData->publisher} +PY - {$citationData->issued->raw|date_format:"%Y"} +{/if} +{foreach from=$citationData->languages item="language"} +LA - {$language} +{/foreach} +{foreach from=$citationData->serialNumber item="serialNumber"} +SN - {$serialNumber} +{/foreach} +{foreach from=$citationData->keywords item="keyword"} +KW - {$keyword} +{/foreach} DO - {$citationData->DOI} +{if $citationData->DOI} +UR - https://doi.org/{$citationData->DOI} +{else} UR - {$citationData->URL} +{/if} +{if $citationData->page} SP - {$citationData->page} +{/if} +{if $citationData->abstract} AB - {$citationData->abstract|replace:"\r\n":""|replace:"\n":""} +{/if} ER - diff --git a/templates/citationblock.tpl b/templates/citationblock.tpl new file mode 100644 index 0000000..3d23a76 --- /dev/null +++ b/templates/citationblock.tpl @@ -0,0 +1,51 @@ +{* How to cite *} +{if $citation} +
+
+

+ {translate key="submission.howToCite"} +

+
+
+ {$citation} +
+
+ + +
+
+
+
+{/if} diff --git a/templates/settings.tpl b/templates/settings.tpl index 34ad784..b797b37 100644 --- a/templates/settings.tpl +++ b/templates/settings.tpl @@ -20,7 +20,13 @@ {fbvFormArea id="citationStyleLanguagePluginSettings"} {fbvFormSection list=true title="plugins.generic.citationStyleLanguage.settings.citationFormatsPrimary"} -

{translate key="plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription"}

+

+ {if $isApplicationOmp} + {translate key="plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription.omp"} + {else} + {translate key="plugins.generic.citationStyleLanguage.settings.citationFormatsPrimaryDescription"} + {/if} +

{foreach from=$allStyles item="style" key="id"} {fbvElement type="radio" name="primaryCitationStyle" id="primaryCitationStyle"|concat:$id value=$id checked=($id === $primaryCitationStyle) label=$style translate=false} {/foreach} From 1d7f5fe584c32df810a76a73d866993a3639cb7a Mon Sep 17 00:00:00 2001 From: marsilius Date: Mon, 31 May 2021 13:58:28 +0200 Subject: [PATCH 2/6] Fix: OMP compatibility --- pages/CitationStyleLanguageHandler.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/CitationStyleLanguageHandler.inc.php b/pages/CitationStyleLanguageHandler.inc.php index a8bbb73..3e84bfc 100644 --- a/pages/CitationStyleLanguageHandler.inc.php +++ b/pages/CitationStyleLanguageHandler.inc.php @@ -115,7 +115,7 @@ public function _setupRequest($args, $request) { if ($this->submission && !CitationStyleLanguagePlugin::isApplicationOmp()) { $issueDao = DAORegistry::getDAO('IssueDAO'); // Support OJS 3.1.x and 3.2 - $issueId = method_exists($this->article, 'getCurrentPublication') ? $this->article->getCurrentPublication()->getData('issueId') : $this->article->getIssueId(); + $issueId = method_exists($this->submission, 'getCurrentPublication') ? $this->submission->getCurrentPublication()->getData('issueId') : $this->submission->getIssueId(); $this->issue = $issueDao->getById($issueId, $context->getId()); } From b7565156e4478a6656b4a5bfabe48c9744bb82e1 Mon Sep 17 00:00:00 2001 From: marsilius Date: Mon, 31 May 2021 14:10:14 +0200 Subject: [PATCH 3/6] Change readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ab6f657..f4f22a0 100644 --- a/readme.md +++ b/readme.md @@ -10,4 +10,4 @@ Consult the [citeproc-php](https://github.com/seboettg/citeproc-php) licensing i Each CSL file has it's own licensing information attached to the XML. ## Compatibility -This plugin is compatible with OJS 3.3.x and OMP 3.3.x. +This plugin is compatible with OJS 3.2.x, OJS 3.3.x and OMP 3.3.x. From 5b68c41761c0e10499d277334f47cddff3dbca43 Mon Sep 17 00:00:00 2001 From: marsilius Date: Wed, 2 Jun 2021 16:48:36 +0200 Subject: [PATCH 4/6] Add select a role for author, editor and translator to settings and reformat code --- CitationStyleLanguagePlugin.inc.php | 200 +++++++++++++-------- CitationStyleLanguageSettingsForm.inc.php | 23 ++- css/citationStyleLanguagePlugin.css | 12 +- locale/de_DE/locale.po | 31 ++++ locale/en_US/locale.po | 30 ++++ pages/CitationStyleLanguageHandler.inc.php | 30 ++-- templates/citation-styles/ris.tpl | 2 +- templates/citationblock.tpl | 2 +- templates/settings.tpl | 47 +++++ 9 files changed, 275 insertions(+), 102 deletions(-) diff --git a/CitationStyleLanguagePlugin.inc.php b/CitationStyleLanguagePlugin.inc.php index c7920de..863b2c2 100644 --- a/CitationStyleLanguagePlugin.inc.php +++ b/CitationStyleLanguagePlugin.inc.php @@ -24,6 +24,18 @@ class CitationStyleLanguagePlugin extends GenericPlugin { /** @var array List of citation download formats available */ public $_citationDownloads = array(); + /** @var bool $applicationOmp */ + private bool $applicationOmp; + + /** + * Constructor + */ + public function __construct() { + parent::__construct(); + $applicationName = Application::get()->getName(); + $this->applicationOmp = stripos($applicationName, 'omp') !== false; + } + /** * @copydoc Plugin::getDisplayName() */ @@ -35,7 +47,7 @@ public function getDisplayName() { * @copydoc Plugin::getDescription() */ public function getDescription() { - return self::isApplicationOmp() ? __('plugins.generic.citationStyleLanguage.description.omp') + return $this->isApplicationOmp() ? __('plugins.generic.citationStyleLanguage.description.omp') : __('plugins.generic.citationStyleLanguage.description'); } @@ -46,12 +58,9 @@ public function register($category, $path, $mainContextId = null) { $success = parent::register($category, $path, $mainContextId); if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return $success; if ($success && $this->getEnabled($mainContextId)) { - if (self::isApplicationOmp()) { - HookRegistry::register('CatalogBookHandler::book', array($this, 'getTemplateData')); - HookRegistry::register('Templates::Catalog::Book::Details', array($this, 'displayCitationMonograph')); - } else { - HookRegistry::register('ArticleHandler::view', array($this, 'getTemplateData')); - } + HookRegistry::register('CatalogBookHandler::book', array($this, 'getTemplateData')); + HookRegistry::register('Templates::Catalog::Book::Details', array($this, 'displayCitationMonograph')); + HookRegistry::register('ArticleHandler::view', array($this, 'getTemplateData')); HookRegistry::register('LoadHandler', array($this, 'setPageHandler')); } return $success; @@ -266,12 +275,12 @@ public function getCitationStyleConfig($styleId) { public function getTemplateData($hookName, $args) { $templateMgr = TemplateManager::getManager(); $request = $args[0]; - if (self::isApplicationOmp()) { + if ($this->isApplicationOmp()) { $submission =& $args[1]; $publication = $submission->getCurrentPublication(); - $issue = NULL; - if (NULL === $publication) { - return FALSE; + $issue = null; + if (null === $publication) { + return false; } $templateMgr->addStyleSheet( 'cslPluginStyles', @@ -279,7 +288,7 @@ public function getTemplateData($hookName, $args) { array( 'priority' => STYLE_SEQUENCE_LAST, 'contexts' => array('frontend'), - 'inline' => FALSE, + 'inline' => false, ) ); } else { @@ -330,7 +339,7 @@ public function displayCitationMonograph($hookName, $params) { $output =& $params[2]; $output .= $smarty->fetch($this->getTemplateResource('citationblock.tpl')); - return FALSE; + return false; } /** @@ -356,22 +365,10 @@ public function getCitation($request, Submission $submission, $citationStyle = ' import('lib.pkp.classes.core.PKPString'); $citationData = new stdClass(); - if (self::isApplicationOmp()){ + if ($this->isApplicationOmp()){ $citationData->type = 'book'; $citationData->risType = 'BOOK'; $citationData->publisher = htmlspecialchars($context->getLocalizedName()); - - /* @var $submissionKeywordDao SubmissionKeywordDAO */ - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); - $keywords = $submissionKeywordDao->getKeywords($publication->getId(), array(AppLocale::getLocale())); - $citationData->keywords = $keywords[AppLocale::getLocale()]; - - /* @var $submissionLanguageDao SubmissionLanguageDAO */ - $submissionLanguageDao = DAORegistry::getDAO('SubmissionLanguageDAO'); - $languages = $submissionLanguageDao->getLanguages($publication->getId(), array(AppLocale::getLocale())); - if (array_key_exists(AppLocale::getLocale(), $languages)) { - $citationData->languages = $languages[AppLocale::getLocale()]; - } $citationData->serialNumber = array(); $publicationFormats = $publication->getData('publicationFormats'); /** @var PublicationFormat $publicationFormat */ @@ -389,18 +386,18 @@ public function getCitation($request, Submission $submission, $citationStyle = ' if ($seriesId) { /** @var SeriesDAO $seriesDao */ $seriesDao = DAORegistry::getDAO('SeriesDAO'); - if (NULL !== $seriesDao) { + if (null !== $seriesDao) { $series = $seriesDao->getById($seriesId); - if (NULL !== $series) { + if (null !== $series) { $citationData->{'collection-title'} = htmlspecialchars(trim($series->getLocalizedFullTitle())); $citationData->volume = htmlspecialchars($publication->getData('seriesPosition')); $citationData->{'collection-editor'} = htmlspecialchars($series->getEditorsString()); $onlineISSN = $series->getOnlineISSN(); - if (NULL !== $onlineISSN && !empty($onlineISSN)) { + if (null !== $onlineISSN && !empty($onlineISSN)) { $citationData->serialNumber[] = htmlspecialchars($onlineISSN); } $printISSN = $series->getPrintISSN(); - if (NULL !== $printISSN && !empty($printISSN)) { + if (null !== $printISSN && !empty($printISSN)) { $citationData->serialNumber[] = htmlspecialchars($printISSN); } } @@ -424,6 +421,19 @@ public function getCitation($request, Submission $submission, $citationStyle = ' if ($section && !$section->getHideTitle()) $citationData->section = htmlspecialchars($section->getTitle($context->getPrimaryLocale())); } } + + /* @var $submissionKeywordDao SubmissionKeywordDAO */ + $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); + $keywords = $submissionKeywordDao->getKeywords($publication->getId(), array(AppLocale::getLocale())); + $citationData->keywords = $keywords[AppLocale::getLocale()]; + + /* @var $submissionLanguageDao SubmissionLanguageDAO */ + $submissionLanguageDao = DAORegistry::getDAO('SubmissionLanguageDAO'); + $languages = $submissionLanguageDao->getLanguages($publication->getId(), array(AppLocale::getLocale())); + if (array_key_exists(AppLocale::getLocale(), $languages)) { + $citationData->languages = $languages[AppLocale::getLocale()]; + } + $citationData->id = $submission->getId(); $citationData->title = htmlspecialchars($publication->getLocalizedFullTitle()); $citationData->{'publisher-place'} = $this->getSetting($context->getId(), 'publisherLocation'); @@ -436,8 +446,8 @@ public function getCitation($request, Submission $submission, $citationStyle = ' $request, ROUTE_PAGE, null, - self::isApplicationOmp() ? 'catalog' : 'article', - self::isApplicationOmp() ? 'book' : 'view', + $this->isApplicationOmp() ? 'catalog' : 'article', + $this->isApplicationOmp() ? 'book' : 'view', (string) $submission->getId() ); $citationData->accessed = new stdClass(); @@ -454,33 +464,30 @@ public function getCitation($request, Submission $submission, $citationStyle = ' $currentAuthor->family = htmlspecialchars($author->getLocalizedFamilyName()); $currentAuthor->given = htmlspecialchars($author->getLocalizedGivenName()); } - if (self::isApplicationOmp() ) { - $userGroup = $author->getUserGroup(); - if (NULL !== $userGroup) { - switch ($userGroup->getData('nameLocaleKey')) { - case 'default.groups.name.volumeEditor': - if (!isset($citationData->editor)) { - $citationData->editor = array(); - } - $citationData->editor[] = $currentAuthor; - break; - case 'default.groups.name.author': - if (!isset($citationData->author)) { - $citationData->author = array(); - } - $citationData->author[] = $currentAuthor; - break; - case 'default.groups.name.translator': - if (!isset($citationData->translator)) { - $citationData->translator = array(); - } - $citationData->translator[] = $currentAuthor; - break; - default: - } + $userGroup = $author->getUserGroup(); + if (null !== $userGroup) { + switch ($userGroup->getId()) { + case $this->getEditorGroup($context->getId()): + if (!isset($citationData->editor)) { + $citationData->editor = array(); + } + $citationData->editor[] = $currentAuthor; + break; + case $this->getTranslatorGroup($context->getId()): + if (!isset($citationData->translator)) { + $citationData->translator = array(); + } + $citationData->translator[] = $currentAuthor; + break; + case $this->getAuthorGroup($context->getId()): + if (!isset($citationData->author)) { + $citationData->author = array(); + } + $citationData->author[] = $currentAuthor; + break; + default: + break; } - } else { - $citationData->author[] = $currentAuthor; } } } @@ -499,15 +506,11 @@ public function getCitation($request, Submission $submission, $citationStyle = ' $citationData->{'original-date'}->raw = htmlspecialchars($originalPublication->getData('datePublished')); } } - } elseif ( !self::isApplicationOmp() && $issue && $issue->getPublished()) { + } elseif ( !$this->isApplicationOmp() && $issue && $issue->getPublished()) { $citationData->issued = new stdClass(); $citationData->issued->raw = htmlspecialchars($issue->getDatePublished()); } - if ($publication->getData('pub-id::doi')) { - $citationData->DOI = htmlspecialchars($publication->getData('pub-id::doi')); - } - if ($publication->getData('pages')) { $citationData->page = htmlspecialchars($publication->getData('pages')); } @@ -522,20 +525,23 @@ public function getCitation($request, Submission $submission, $citationStyle = ' if (!empty($styleConfig)) { if (!empty($styleConfig['useTemplate'])) { $templateMgr = TemplateManager::getManager($request); - $assignArray = array( + $templateMgr->assign([ 'citationData' => $citationData, 'citationStyle' => $citationStyle, 'publication' => $publication, - ); - if (self::isApplicationOmp()) { - $assignArray['book'] = $submission; - $assignArray['press'] = $context; + ]); + if ($this->isApplicationOmp()) { + $templateMgr->assign([ + 'book' => $submission, + 'press' => $context, + ]); } else { - $assignArray['article'] = $submission; - $assignArray['issue'] = $issue; - $assignArray['journal'] = $context; + $templateMgr->assign([ + 'article' => $submission, + 'issue' => $issue, + 'journal' => $context, + ]); } - $templateMgr->assign($assignArray); $citation = $templateMgr->fetch($styleConfig['useTemplate']); } else { $style = $this->loadStyle($styleConfig); @@ -587,8 +593,7 @@ public function loadStyle($styleConfig) { * @return string */ public function downloadCitation($request, $submission, $citationStyle = 'ris', $issue = null) { - if ( !self::isApplicationOmp() ) - { + if (!$this->isApplicationOmp()) { $journal = $request->getContext(); if (empty($issue)) { @@ -697,8 +702,49 @@ public function setPageHandler($hookName, $params) { return false; } - public static function isApplicationOmp() : bool { - $applicationName = Application::get()->getName(); - return stripos($applicationName, 'omp') !== FALSE; + /** + * @return bool + */ + public function isApplicationOmp() : bool { + return $this->applicationOmp; + } + + /** + * @param int $contextId + * + * @return int|null + */ + public function getEditorGroup(int $contextId = 0) : ?int { + $editorGroup = $this->getSetting($contextId, 'groupEditor'); + if ($editorGroup) { + return (int) $editorGroup; + } + return null; + } + + /** + * @param int $contextId + * + * @return int|null + */ + public function getTranslatorGroup(int $contextId = 0) : ?int { + $translatorGroup = $this->getSetting($contextId, 'groupTranslator'); + if ($translatorGroup) { + return (int) $translatorGroup; + } + return null; + } + + /** + * @param int $contextId + * + * @return int|null + */ + public function getAuthorGroup(int $contextId = 0) : ?int { + $authorGroup = $this->getSetting($contextId, 'groupAuthor'); + if ($authorGroup) { + return (int) $authorGroup; + } + return null; } } diff --git a/CitationStyleLanguageSettingsForm.inc.php b/CitationStyleLanguageSettingsForm.inc.php index a3a3366..b4b8aad 100644 --- a/CitationStyleLanguageSettingsForm.inc.php +++ b/CitationStyleLanguageSettingsForm.inc.php @@ -42,6 +42,9 @@ public function initData() { $this->setData('enabledCitationStyles', array_keys($this->plugin->getEnabledCitationStyles($contextId))); $this->setData('enabledCitationDownloads', $this->plugin->getEnabledCitationDownloads($contextId)); $this->setData('publisherLocation', $this->plugin->getSetting($contextId, 'publisherLocation')); + $this->setData('groupAuthor', $this->plugin->getSetting($contextId, 'groupAuthor')); + $this->setData('groupEditor', $this->plugin->getSetting($contextId, 'groupEditor')); + $this->setData('groupTranslator', $this->plugin->getSetting($contextId, 'groupTranslator')); } /** @@ -53,6 +56,9 @@ public function readInputData() { 'enabledCitationStyles', 'enabledCitationDownloads', 'publisherLocation', + 'groupAuthor', + 'groupEditor', + 'groupTranslator' )); } @@ -73,6 +79,13 @@ public function fetch($request, $template = null, $display = false) { $allDownloads[$style['id']] = $style['title']; } + $allUserGroups = []; + $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */ + $userGroups = $userGroupDao->getByContextId($contextId); + while ($userGroup = $userGroups->next()) { + $allUserGroups[(int) $userGroup->getId()] = $userGroup->getLocalizedName(); + } + $templateMgr = TemplateManager::getManager($request); $templateMgr->assign(array( 'pluginName' => $this->plugin->getName(), @@ -81,7 +94,11 @@ public function fetch($request, $template = null, $display = false) { 'primaryCitationStyle' => $this->getData('primaryCitationStyle'), 'enabledStyles' => $this->plugin->mapCitationIds($this->plugin->getEnabledCitationStyles($contextId)), 'enabledDownloads' => $this->plugin->mapCitationIds($this->plugin->getEnabledCitationDownloads($contextId)), - 'isApplicationOmp' => CitationStyleLanguagePlugin::isApplicationOmp(), + 'isApplicationOmp' => $this->plugin->isApplicationOmp(), + 'groupAuthor' => $this->getData('groupAuthor') ? (int) $this->getData('groupAuthor') : 0, + 'groupEditor' => $this->getData('groupEditor') ? (int) $this->getData('groupEditor') : 0, + 'groupTranslator' => $this->getData('groupTranslator') ? (int) $this->getData('groupTranslator') : 0, + 'allUserGroups' => $allUserGroups, )); return parent::fetch($request, $template, $display); @@ -100,6 +117,9 @@ public function execute(...$functionArgs) { $enabledCitationDownloads = $this->getData('enabledCitationDownloads') ? $this->getData('enabledCitationDownloads') : array(); $this->plugin->updateSetting($contextId, 'enabledCitationDownloads', $enabledCitationDownloads); $this->plugin->updateSetting($contextId, 'publisherLocation', $this->getData('publisherLocation')); + $this->plugin->updateSetting($contextId, 'groupAuthor', $this->getData('groupAuthor')); + $this->plugin->updateSetting($contextId, 'groupEditor', $this->getData('groupEditor')); + $this->plugin->updateSetting($contextId, 'groupTranslator', $this->getData('groupTranslator')); import('classes.notification.NotificationManager'); $notificationMgr = new NotificationManager(); @@ -109,4 +129,3 @@ public function execute(...$functionArgs) { return parent::execute(...$functionArgs); } } - diff --git a/css/citationStyleLanguagePlugin.css b/css/citationStyleLanguagePlugin.css index 109220e..1dce410 100644 --- a/css/citationStyleLanguagePlugin.css +++ b/css/citationStyleLanguagePlugin.css @@ -1,8 +1,3 @@ -.citation_display .value -{ - font-size: 0.75rem; -} - .citation_display .csl-left-margin { display: none; @@ -30,9 +25,7 @@ box-shadow: none; padding: 0 1em; width: 100%; - font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif; - font-weight: 400; - color: #777; + min-height: 2.5em; text-align: left; } @@ -57,7 +50,6 @@ .citation_display .citation_formats_button:focus { - background: #ddd; outline: 0; } @@ -74,11 +66,11 @@ padding: 0.5em 1em; border-bottom: 1px solid #bbb; text-decoration: none; + font-size: 0.75rem; } .citation_display .citation_formats_styles a:focus { - background: #ddd; outline: 0; } diff --git a/locale/de_DE/locale.po b/locale/de_DE/locale.po index c6abf9e..cd65090 100644 --- a/locale/de_DE/locale.po +++ b/locale/de_DE/locale.po @@ -87,3 +87,34 @@ msgstr "" msgid "plugins.generic.citationStyleLanguage.settings.publisherLocation" msgstr "Standort des Verlags" + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroups" +msgstr "Autoren und Übersetzer" + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroupsDescription" +msgstr "In manchen Fällen gibt es neben den Autoren noch Übersetzer. Wählen Sie bitte je eine Rolle für Autoren und Übersetzer." + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroups.omp" +msgstr "Autoren, Herausgeber und Übersetzer" + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroupsDescription.omp" +msgstr "In manchen Fällen gibt es neben den Autoren noch Herausgeber oder Übersetzer. Wählen Sie bitte je eine Rolle für Autoren, Herausgeber und Übersetzer." + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseAuthor" +msgstr "Autor:" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseEditor" +msgstr "Herausgeber:" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseTranslator" +msgstr "Übersetzer:" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseAuthor" +msgstr "Bitte wählen Sie eine Rolle für die Autoren" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseEditor" +msgstr "Bitte wählen Sie eine Rolle für die Herausgeber" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseTranslator" +msgstr "Bitte wählen Sie eine Rolle für die Übersetzer" + diff --git a/locale/en_US/locale.po b/locale/en_US/locale.po index acb0b50..434a00f 100644 --- a/locale/en_US/locale.po +++ b/locale/en_US/locale.po @@ -82,3 +82,33 @@ msgstr "Publisher Location" msgid "plugins.generic.citationStyleLanguage.settings.publisherLocation.description" msgstr "Some citation formats request the geographic location of the publisher, such as \"London, U.K.\"." + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroups" +msgstr "Author and Translator" + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroupsDescription" +msgstr "In some cases beside authors there also exists translators. Please choose a role for authors and translators." + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroups.omp" +msgstr "Author, Editor and Translator" + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroupsDescription.omp" +msgstr "In some cases beside authors there also exist editors or translators. Please choose a role for authors, editors and translators." + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseAuthor" +msgstr "Author:" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseEditor" +msgstr "Editor:" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseTranslator" +msgstr "Translator:" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseAuthor" +msgstr "Please choose a role for authors" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseEditor" +msgstr "Please choose a role for editors" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseTranslator" +msgstr "Please choose a role for translators" diff --git a/pages/CitationStyleLanguageHandler.inc.php b/pages/CitationStyleLanguageHandler.inc.php index 3e84bfc..4d118c4 100644 --- a/pages/CitationStyleLanguageHandler.inc.php +++ b/pages/CitationStyleLanguageHandler.inc.php @@ -31,6 +31,17 @@ class CitationStyleLanguageHandler extends Handler { /** @var bool Whether or not to return citation in JSON format */ public $returnJson = false; + /** @var $plugin object */ + public $plugin; + + /** + * Constructor + */ + public function __construct() { + parent::__construct(); + $this->plugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin'); + } + /** * Get a citation style * @@ -41,12 +52,9 @@ class CitationStyleLanguageHandler extends Handler { public function get($args, $request) { $this->_setupRequest($args, $request); - $plugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin'); - if (NULL === $plugin) { - if ($this->returnJson) { - return new JSONMessage(false); - } - exit; + $plugin = $this->plugin; + if (null === $plugin) { + $request->getDispatcher()->handle404(); } $citation = $plugin->getCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication); @@ -74,8 +82,8 @@ public function get($args, $request) { public function download($args, $request) { $this->_setupRequest($args, $request); - $plugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin'); - if (NULL !== $plugin) { + $plugin = $this->plugin; + if (null !== $plugin) { $plugin->downloadCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication); } exit; @@ -112,7 +120,7 @@ public function _setupRequest($args, $request) { ? Services::get('publication')->get($userVars['publicationId']) : $this->submission->getCurrentPublication(); - if ($this->submission && !CitationStyleLanguagePlugin::isApplicationOmp()) { + if ($this->submission && !$this->plugin->isApplicationOmp()) { $issueDao = DAORegistry::getDAO('IssueDAO'); // Support OJS 3.1.x and 3.2 $issueId = method_exists($this->submission, 'getCurrentPublication') ? $this->submission->getCurrentPublication()->getData('issueId') : $this->submission->getIssueId(); @@ -123,8 +131,8 @@ public function _setupRequest($args, $request) { // journal manager or an assigned subeditor or assistant. This ensures the // article preview will work for those who can see it. if ($this->submission->getData('status') !== STATUS_PUBLISHED - || (!CitationStyleLanguagePlugin::isApplicationOmp() && !$this->issue ) - || (!CitationStyleLanguagePlugin::isApplicationOmp() && !$this->issue->getPublished())) { + || (!$this->plugin->isApplicationOmp() && !$this->issue ) + || (!$this->plugin->isApplicationOmp() && !$this->issue->getPublished())) { $userCanAccess = false; if ($user && $user->hasRole([ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT], $context->getId())) { diff --git a/templates/citation-styles/ris.tpl b/templates/citation-styles/ris.tpl index bed5efd..a908219 100644 --- a/templates/citation-styles/ris.tpl +++ b/templates/citation-styles/ris.tpl @@ -64,8 +64,8 @@ SN - {$serialNumber} {foreach from=$citationData->keywords item="keyword"} KW - {$keyword} {/foreach} -DO - {$citationData->DOI} {if $citationData->DOI} +DO - {$citationData->DOI} UR - https://doi.org/{$citationData->DOI} {else} UR - {$citationData->URL} diff --git a/templates/citationblock.tpl b/templates/citationblock.tpl index 3d23a76..ec71892 100644 --- a/templates/citationblock.tpl +++ b/templates/citationblock.tpl @@ -10,7 +10,7 @@ {$citation}
- {if $isApplicationOmp} + {if $isChapterFrontendPagePluginEnabled} +
+

{translate key='plugins.generic.citationStyleLanguage.settings.citationChooseChapterAuthor'} + +

+
+ {/if}

{translate key='plugins.generic.citationStyleLanguage.settings.citationChooseEditor'} - - {foreach from=$allUserGroups item="group" key="id"} - - {/foreach} - -

-
+ {fbvFormArea title="plugins.generic.citationStyleLanguage.settings.citationUserGroups" class="pkpFormField--options"} +

{translate key="plugins.generic.citationStyleLanguage.settings.citationUserGroupsDescription"}

+ {fbvFormSection list=true label="plugins.generic.citationStyleLanguage.settings.citationChooseAuthor"} +

{translate key='plugins.generic.citationStyleLanguage.settings.citationOptionChooseAuthor'}

+ {foreach from=$allUserGroups item="group" key="id"} + {fbvElement type="checkbox" id="groupAuthor[]" value=$id checked=in_array($id, $groupAuthor) label=$group translate=false} + {/foreach} + {/fbvFormSection} {if $isApplicationOmp} {if $isChapterFrontendPagePluginEnabled} -
-

{translate key='plugins.generic.citationStyleLanguage.settings.citationChooseChapterAuthor'} - -

-
- {/if} -
-

{translate key='plugins.generic.citationStyleLanguage.settings.citationChooseEditor'} - -

-
- {/if} -
-

{translate key='plugins.generic.citationStyleLanguage.settings.citationChooseTranslator'} - -

-
- {/fbvFormSection} + {/fbvFormSection} + {/if} + {fbvFormSection list=true label="plugins.generic.citationStyleLanguage.settings.citationChooseEditor"} +

{translate key='plugins.generic.citationStyleLanguage.settings.citationOptionChooseEditor'}

+ {foreach from=$allUserGroups item="group" key="id"} + {fbvElement type="checkbox" id="groupEditor[]" value=$id checked=in_array($id, $groupEditor) label=$group translate=false} + {/foreach} + {/fbvFormSection} + {/if} + {fbvFormSection list=true label="plugins.generic.citationStyleLanguage.settings.citationChooseTranslator"} +

{translate key='plugins.generic.citationStyleLanguage.settings.citationOptionChooseTranslator'}

+ {foreach from=$allUserGroups item="group" key="id"} + {fbvElement type="checkbox" id="groupTranslator[]" value=$id checked=in_array($id, $groupTranslator) label=$group translate=false} + {/foreach} + {/fbvFormSection} + {/fbvFormArea} +
{fbvFormSection}
{translate key="plugins.generic.citationStyleLanguage.settings.publisherLocation.description"}
{fbvElement type="text" id="publisherLocation" value=$publisherLocation label="plugins.generic.citationStyleLanguage.settings.publisherLocation"}