diff --git a/CitationStyleLanguagePlugin.inc.php b/CitationStyleLanguagePlugin.inc.php index b7d02ad..a62becd 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,8 @@ public function getDisplayName() { * @copydoc Plugin::getDescription() */ public function getDescription() { - return __('plugins.generic.citationStyleLanguage.description'); + return $this->isApplicationOmp() ? __('plugins.generic.citationStyleLanguage.description.omp') + : __('plugins.generic.citationStyleLanguage.description'); } /** @@ -45,7 +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)) { - HookRegistry::register('ArticleHandler::view', array($this, 'getArticleTemplateData')); + 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; @@ -257,24 +272,40 @@ 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 ($this->isApplicationOmp()) { + $submission =& $args[1]; + $publication = $submission->getCurrentPublication(); + $issue = null; + $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 +320,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,55 +349,111 @@ 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 ($this->isApplicationOmp()){ + $citationData->type = 'book'; + $citationData->risType = 'BOOK'; + $citationData->publisher = htmlspecialchars($context->getLocalizedName()); + $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())); + } } - $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())); + /* @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'); + $citationData->abstract = htmlspecialchars(strip_tags($publication->getLocalizedData('abstract'))); + + $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() + $this->isApplicationOmp() ? 'catalog' : 'article', + $this->isApplicationOmp() ? 'book' : 'view', + (string) $submission->getId() ); $citationData->accessed = new stdClass(); $citationData->accessed->raw = date('Y-m-d'); $authors = $publication->getData('authors'); + $authorsGroup = $this->getAuthorGroup($context->getId()); + $editorsGroup = $this->getEditorGroup($context->getId()); + $translatorsGroup = $this->getTranslatorGroup($context->getId()); if (count($authors)) { $citationData->author = array(); foreach ($authors as $author) { @@ -358,14 +464,38 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = $currentAuthor->family = htmlspecialchars($author->getLocalizedFamilyName()); $currentAuthor->given = htmlspecialchars($author->getLocalizedGivenName()); } - $citationData->author[] = $currentAuthor; + $userGroup = $author->getUserGroup(); + if (null !== $userGroup) { + switch (true) { + case in_array($userGroup->getId(),$editorsGroup,false): + if (!isset($citationData->editor)) { + $citationData->editor = array(); + } + $citationData->editor[] = $currentAuthor; + break; + case in_array($userGroup->getId(),$translatorsGroup,false): + if (!isset($citationData->translator)) { + $citationData->translator = array(); + } + $citationData->translator[] = $currentAuthor; + break; + case in_array($userGroup->getId(),$authorsGroup,false): + if (!isset($citationData->author)) { + $citationData->author = array(); + } + $citationData->author[] = $currentAuthor; + break; + default: + break; + } + } } } 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,7 +506,7 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = $citationData->{'original-date'}->raw = htmlspecialchars($originalPublication->getData('datePublished')); } } - } elseif ($issue && $issue->getPublished()) { + } elseif ( !$this->isApplicationOmp() && $issue && $issue->getPublished()) { $citationData->issued = new stdClass(); $citationData->issued->raw = htmlspecialchars($issue->getDatePublished()); } @@ -385,7 +515,7 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = $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 +525,23 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue = if (!empty($styleConfig)) { if (!empty($styleConfig['useTemplate'])) { $templateMgr = TemplateManager::getManager($request); - $templateMgr->assign(array( + $templateMgr->assign([ 'citationData' => $citationData, 'citationStyle' => $citationStyle, - 'article' => $article, 'publication' => $publication, - 'issue' => $issue, - 'journal' => $context, - )); + ]); + if ($this->isApplicationOmp()) { + $templateMgr->assign([ + 'book' => $submission, + 'press' => $context, + ]); + } else { + $templateMgr->assign([ + 'article' => $submission, + 'issue' => $issue, + 'journal' => $context, + ]); + } $citation = $templateMgr->fetch($styleConfig['useTemplate']); } else { $style = $this->loadStyle($styleConfig); @@ -448,17 +587,19 @@ 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(); + public function downloadCitation($request, $submission, $citationStyle = 'ris', $issue = null) { + if (!$this->isApplicationOmp()) { + $journal = $request->getContext(); - if (empty($issue)) { - $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ - $issue = $issueDao->getById($article->getCurrentPublication()->getData('issueId')); + if (empty($issue)) { + $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ + $issue = $issueDao->getById($submission->getCurrentPublication()->getData('issueId')); + } } $styleConfig = $this->getCitationStyleConfig($citationStyle); @@ -466,14 +607,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 +701,75 @@ public function setPageHandler($hookName, $params) { } return false; } + + /** + * @return bool + */ + public function isApplicationOmp() : bool { + return $this->applicationOmp; + } + + /** + * @param int $contextId + * + * @return array + */ + public function getEditorGroup(int $contextId = 0) : array { + $editorGroup = $this->getSetting($contextId, 'groupEditor'); + $editors = array(); + if (is_array($editorGroup)) { + $editors = $editorGroup; + } else if ($editorGroup) { + $editors[] = $editorGroup; + } + return $editors; + } + + /** + * @param int $contextId + * + * @return array + */ + public function getTranslatorGroup(int $contextId = 0) : array { + $translatorGroup = $this->getSetting($contextId, 'groupTranslator'); + $translators = array(); + if (is_array($translatorGroup)) { + $translators = $translatorGroup; + } else if ($translatorGroup) { + $translators[] = $translatorGroup; + } + return $translators; + } + + /** + * @param int $contextId + * + * @return array + */ + public function getAuthorGroup(int $contextId = 0) : array { + $authorGroup = $this->getSetting($contextId, 'groupAuthor'); + $authors = array(); + if (is_array($authorGroup)) { + $authors = $authorGroup; + } else if ($authorGroup) { + $authors[] = $authorGroup; + } + return $authors; + } + + /** + * @param int $contextId + * + * @return array + */ + public function getChapterAuthorGroup(int $contextId = 0) : array { + $chapterAuthorGroup = $this->getSetting($contextId, 'groupChapterAuthor'); + $chapterAuthors = array(); + if (is_array($chapterAuthorGroup)) { + $chapterAuthors = $chapterAuthorGroup; + } else if ($chapterAuthorGroup) { + $chapterAuthors[] = $chapterAuthorGroup; + } + return $chapterAuthors; + } } diff --git a/CitationStyleLanguageSettingsForm.inc.php b/CitationStyleLanguageSettingsForm.inc.php index bd21004..cf5c18d 100644 --- a/CitationStyleLanguageSettingsForm.inc.php +++ b/CitationStyleLanguageSettingsForm.inc.php @@ -20,6 +20,9 @@ class CitationStyleLanguageSettingsForm extends Form { /** @var $plugin object */ public $plugin; + /** @var null|bool ChapterFrontendPagePluginEnabled */ + private ?bool $ChapterFrontendPagePluginEnabled; + /** * Constructor * @param $plugin object @@ -29,6 +32,7 @@ public function __construct($plugin) { $this->plugin = $plugin; $this->addCheck(new FormValidatorPost($this)); $this->addCheck(new FormValidatorCSRF($this)); + $this->ChapterFrontendPagePluginEnabled = null; } /** @@ -42,6 +46,14 @@ 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->getAuthorGroup($contextId)); + $this->setData('groupTranslator', $this->plugin->getTranslatorGroup($contextId)); + if ($this->plugin->isApplicationOmp()) { + $this->setData('groupEditor', $this->plugin->getEditorGroup($contextId)); + if ($this->isChapterFrontendPagePluginEnabled()) { + $this->setData('groupChapterAuthor', $this->plugin->getChapterAuthorGroup($contextId)); + } + } } /** @@ -53,7 +65,15 @@ public function readInputData() { 'enabledCitationStyles', 'enabledCitationDownloads', 'publisherLocation', + 'groupAuthor', + 'groupTranslator' )); + if ($this->plugin->isApplicationOmp()) { + $this->readUserVars(['groupEditor']); + if ($this->isChapterFrontendPagePluginEnabled()) { + $this->readUserVars(['groupChapterAuthor']); + } + } } /** @@ -73,6 +93,14 @@ public function fetch($request, $template = null, $display = false) { $allDownloads[$style['id']] = $style['title']; } + $allUserGroups = []; + $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */ + $userGroups = $userGroupDao->getByRoleId( $contextId, ROLE_ID_AUTHOR ); + while ($userGroup = $userGroups->next()) { + $allUserGroups[(int) $userGroup->getId()] = $userGroup->getLocalizedName(); + } + asort($allUserGroups); + $templateMgr = TemplateManager::getManager($request); $templateMgr->assign(array( 'pluginName' => $this->plugin->getName(), @@ -81,7 +109,20 @@ 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' => $this->plugin->isApplicationOmp(), + 'groupAuthor' => $this->getData('groupAuthor'), + 'groupTranslator' => $this->getData('groupTranslator'), + 'allUserGroups' => $allUserGroups, )); + if ($this->plugin->isApplicationOmp()) { + $templateMgr->assign([ + 'groupEditor' => $this->getData('groupEditor'), + 'isChapterFrontendPagePluginEnabled' => $this->isChapterFrontendPagePluginEnabled() + ]); + if ($this->isChapterFrontendPagePluginEnabled()) { + $templateMgr->assign(['groupChapterAuthor' => $this->getData('groupChapterAuthor')]); + } + } return parent::fetch($request, $template, $display); } @@ -99,6 +140,14 @@ 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, 'groupTranslator', $this->getData('groupTranslator')); + if( $this->plugin->isApplicationOmp()){ + $this->plugin->updateSetting($contextId, 'groupEditor', $this->getData('groupEditor')); + if( $this->isChapterFrontendPagePluginEnabled() ){ + $this->plugin->updateSetting($contextId, 'groupChapterAuthor', $this->getData('groupChapterAuthor')); + } + } import('classes.notification.NotificationManager'); $notificationMgr = new NotificationManager(); @@ -107,5 +156,22 @@ public function execute(...$functionArgs) { return parent::execute(...$functionArgs); } -} + /** + * @return bool + */ + private function isChapterFrontendPagePluginEnabled() : bool { + if (null === $this->ChapterFrontendPagePluginEnabled) { + if ($this->plugin->isApplicationOmp()) { + $request = Application::get()->getRequest(); + $context = $request->getContext(); + $contextId = $context ? $context->getId() : 0; + $chapterPlugin = PluginRegistry::getPlugin('generic', 'chapterfrontendpageplugin'); + $this->ChapterFrontendPagePluginEnabled = null !== $chapterPlugin && $chapterPlugin->getEnabled($contextId); + } else { + $this->ChapterFrontendPagePluginEnabled = false; + } + } + return $this->ChapterFrontendPagePluginEnabled; + } +} diff --git a/css/citationStyleLanguagePlugin.css b/css/citationStyleLanguagePlugin.css new file mode 100644 index 0000000..1dce410 --- /dev/null +++ b/css/citationStyleLanguagePlugin.css @@ -0,0 +1,95 @@ +.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%; + min-height: 2.5em; + 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 +{ + 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; + font-size: 0.75rem; +} + +.citation_display .citation_formats_styles a:focus +{ + 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/en_US/locale.po b/locale/en_US/locale.po index 5e40c69..1cd743d 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,8 +74,41 @@ 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" 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 "Contributors" + +msgid "plugins.generic.citationStyleLanguage.settings.citationUserGroupsDescription" +msgstr "In some citation styles, contributors must be identified differently depending on their role. Please identify the appropriate roles." + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseAuthor" +msgstr "Authors" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseEditor" +msgstr "Editors" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseTranslator" +msgstr "Translators" + +msgid "plugins.generic.citationStyleLanguage.settings.citationChooseChapterAuthor" +msgstr "Chapter Authors" + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseAuthor" +msgstr "Select the roles that should be identified as authors." + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseEditor" +msgstr "Select the roles that should be identified as editors." + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseTranslator" +msgstr "Select the roles that should be identified as translators." + +msgid "plugins.generic.citationStyleLanguage.settings.citationOptionChooseChapterAuthor" +msgstr "Select the roles that should be identified as chapter authors." diff --git a/pages/CitationStyleLanguageHandler.inc.php b/pages/CitationStyleLanguageHandler.inc.php index 2a7cabb..4d118c4 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; @@ -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,8 +52,11 @@ class CitationStyleLanguageHandler extends Handler { 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); + $plugin = $this->plugin; + if (null === $plugin) { + $request->getDispatcher()->handle404(); + } + $citation = $plugin->getCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication); if ($citation === false ) { if ($this->returnJson) { @@ -68,8 +82,10 @@ public function get($args, $request) { 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); + $plugin = $this->plugin; + if (null !== $plugin) { + $plugin->downloadCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication); + } exit; } @@ -94,34 +110,36 @@ 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 && !$this->plugin->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()); } // 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 + || (!$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())) { $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..f4f22a0 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.2.x, 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..a908219 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} +{if $citationData->DOI} DO - {$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..ec71892 --- /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..668034a 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} @@ -37,6 +43,38 @@ {fbvElement type="checkbox" id="enabledCitationDownloads[]" value=$id checked=in_array($id, $enabledDownloads) label=$style translate=false} {/foreach} {/fbvFormSection} + {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} + {fbvFormSection list=true label="plugins.generic.citationStyleLanguage.settings.citationChooseChapterAuthor"} +

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

+ {foreach from=$allUserGroups item="group" key="id"} + {fbvElement type="checkbox" id="groupChapterAuthor[]" value=$id checked=in_array($id, $groupChapterAuthor) label=$group translate=false} + {/foreach} + {/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"}