Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib/issues/6201 Adapt to support OMP #79

Draft
wants to merge 6 commits into
base: stable-3_3_0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 263 additions & 50 deletions CitationStyleLanguagePlugin.inc.php

Large diffs are not rendered by default.

68 changes: 67 additions & 1 deletion CitationStyleLanguageSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class CitationStyleLanguageSettingsForm extends Form {
/** @var $plugin object */
public $plugin;

/** @var null|bool ChapterFrontendPagePluginEnabled */
private ?bool $ChapterFrontendPagePluginEnabled;

/**
* Constructor
* @param $plugin object
Expand All @@ -29,6 +32,7 @@ public function __construct($plugin) {
$this->plugin = $plugin;
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
$this->ChapterFrontendPagePluginEnabled = null;
}

/**
Expand All @@ -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));
}
}
}

/**
Expand All @@ -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']);
}
}
}

/**
Expand All @@ -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();
}
NateWr marked this conversation as resolved.
Show resolved Hide resolved
asort($allUserGroups);

$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array(
'pluginName' => $this->plugin->getName(),
Expand All @@ -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);
}
Expand All @@ -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();
Expand All @@ -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;
}
}
95 changes: 95 additions & 0 deletions css/citationStyleLanguagePlugin.css
Original file line number Diff line number Diff line change
@@ -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;
}
36 changes: 36 additions & 0 deletions locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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."
44 changes: 31 additions & 13 deletions pages/CitationStyleLanguageHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*
Expand All @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Loading