diff --git a/CitationStyleLanguagePlugin.inc.php b/CitationStyleLanguagePlugin.inc.php
index 7903063..58f2ecc 100644
--- a/CitationStyleLanguagePlugin.inc.php
+++ b/CitationStyleLanguagePlugin.inc.php
@@ -36,6 +36,9 @@ class CitationStyleLanguagePlugin extends GenericPlugin
/** @var array List of citation download formats available */
public $_citationDownloads = [];
+ /** @var string Name of the application */
+ public $applicationName = '';
+
/**
* @copydoc Plugin::getDisplayName()
*/
@@ -64,7 +67,10 @@ public function register($category, $path, $mainContextId = null)
return $success;
}
if ($success && $this->getEnabled($mainContextId)) {
+ $this->applicationName = Application::get()->getName();
+
HookRegistry::register('ArticleHandler::view', [$this, 'getArticleTemplateData']);
+ HookRegistry::register('PreprintHandler::view', array($this, 'getPreprintTemplateData'));
HookRegistry::register('LoadHandler', [$this, 'setPageHandler']);
}
return $success;
@@ -281,7 +287,15 @@ public function getCitationStyleConfig($styleId)
return array_shift($styleConfig);
}
- /**
+ protected function getPublicationTypeUrlPath(): string {
+ switch ($this->applicationName) {
+ case 'ojs2': return 'article';
+ case 'ops': return 'preprint';
+ }
+ return '';
+ }
+
+ /**
* Retrieve citation information for the article details template. This
* method is hooked in before a template displays.
*
@@ -325,7 +339,49 @@ public function getArticleTemplateData($hookName, $args)
}
/**
- * Get a specified citation for a given article
+ * Retrieve citation information for the preprint details template. This
+ * method is hooked in before a template displays.
+ *
+ * @see PreprintHandler::view()
+ *
+ * @param array $args
+ *
+ * @return false
+ */
+ public function getPreprintTemplateData($hookName, $args)
+ {
+ $request = $args[0];
+ $preprint = $args[1];
+ $publication = $args[2];
+ $context = $request->getContext();
+ $contextId = $context ? $context->getId() : 0;
+ $templateMgr = TemplateManager::getManager();
+
+ $citationArgs = [
+ 'submissionId' => $preprint->getId(),
+ 'publicationId' => $publication->getId(),
+ ];
+ $citationArgsJson = $citationArgs;
+ $citationArgsJson['return'] = 'json';
+
+ $templateMgr->assign([
+ 'citation' => $this->getCitation($request, $preprint, $this->getPrimaryStyleName($contextId), null, $publication),
+ 'citationArgs' => $citationArgs,
+ 'citationArgsJson' => $citationArgsJson,
+ 'citationStyles' => $this->getEnabledCitationStyles($contextId),
+ 'citationDownloads' => $this->getEnabledCitationDownloads($contextId),
+ ]);
+
+ $templateMgr->addJavaScript(
+ 'citationStyleLanguage',
+ $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/articleCitation.js'
+ );
+
+ return false;
+ }
+
+ /**
+ * Get a specified citation for a given submission
*
* This citation format follows the csl-json schema and takes some direction
* from existing CSL mappings documented by Zotero and Mendeley.
@@ -335,24 +391,25 @@ public function getArticleTemplateData($hookName, $args)
* @see Mendeley's mappings http://support.mendeley.com/customer/portal/articles/364144-csl-type-mapping
*
* @param Request $request
- * @param Submission $article
+ * @param Submission $submission
* @param string $citationStyle 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 ??= $article->getCurrentPublication();
- $issue ??= Repo::issue()->get($publication->getData('issueId'));
+ public function getCitation($request, $submission, $citationStyle = 'apa', $issue = null, $publication = null) {
+ $publication ??= $submission->getCurrentPublication();
$context = $request->getContext();
+ if($this->applicationName == 'ojs2') {
+ $issue ??= Repo::issue()->get($publication->getData('issueId'));
+ }
import('lib.pkp.classes.core.PKPString');
$citationData = new stdClass();
- $citationData->type = 'article-journal';
- $citationData->id = $article->getId();
+ $citationData->type = ($this->applicationName == 'ojs2' ? 'article-journal' : 'article');
+ $citationData->id = $submission->getId();
$citationData->title = $publication->getLocalizedFullTitle();
$citationData->{'container-title'} = $context->getLocalizedName();
$citationData->{'publisher-place'} = $this->getSetting($context->getId(), 'publisherLocation');
@@ -381,9 +438,9 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue =
$request,
PKPApplication::ROUTE_PAGE,
null,
- 'article',
+ $this->getPublicationTypeUrlPath(),
'view',
- $article->getBestId()
+ $submission->getBestId()
);
$citationData->accessed = new stdClass();
$citationData->accessed->raw = date('Y-m-d');
@@ -406,7 +463,7 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue =
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;
@@ -427,11 +484,11 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue =
}
// DOI
- if ($issue && $issue->getPublished()) {
- $citationData->DOI = $article->getStoredPubId('doi');
+ if ($publication->getDoi()) {
+ $citationData->DOI = $publication->getDoi();
}
- HookRegistry::call('CitationStyleLanguage::citation', [&$citationData, &$citationStyle, $article, $issue, $context, $publication]);
+ HookRegistry::call('CitationStyleLanguage::citation', [&$citationData, &$citationStyle, $submission, $issue, $context, $publication]);
$citation = '';
@@ -444,7 +501,7 @@ public function getCitation($request, $article, $citationStyle = 'apa', $issue =
$templateMgr->assign([
'citationData' => $citationData,
'citationStyle' => $citationStyle,
- 'article' => $article,
+ 'article' => $submission,
'publication' => $publication,
'issue' => $issue,
'journal' => $context,
@@ -496,33 +553,27 @@ public function loadStyle($styleConfig)
* software.
*
* @param Request $request
- * @param Submission $article
+ * @param Submission $submission
* @param string $citationStyle 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)
+ public function downloadCitation($request, $submission, $citationStyle = 'ris', $issue = null)
{
- $journal = $request->getContext();
-
- if (empty($issue)) {
- $issue = Repo::issue()->get($article->getCurrentPublication()->getData('issueId'));
- }
-
$styleConfig = $this->getCitationStyleConfig($citationStyle);
if (empty($styleConfig)) {
return false;
}
- $citation = trim(strip_tags($this->getCitation($request, $article, $citationStyle, $issue)));
+ $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($submission->getLocalizedTitle(), 0, 60)) . '.' . $styleConfig['fileExtension'];
header("Content-Disposition: attachment; filename*=UTF-8''\"${encodedFilename}\"");
header('Content-Type: ' . $styleConfig['contentType']);
diff --git a/citation-styles/acs-nano.csl b/citation-styles/acs-nano.csl
index ae798de..2ccbd1c 100644
--- a/citation-styles/acs-nano.csl
+++ b/citation-styles/acs-nano.csl
@@ -1,217 +1,18 @@
-
diff --git a/citation-styles/apa.csl b/citation-styles/apa.csl
index 25a6eb9..5ba01a9 100644
--- a/citation-styles/apa.csl
+++ b/citation-styles/apa.csl
@@ -1,37 +1,20 @@
-
diff --git a/citation-styles/associacao-brasileira-de-normas-tecnicas.csl b/citation-styles/associacao-brasileira-de-normas-tecnicas.csl
index 73c4070..dfd1482 100644
--- a/citation-styles/associacao-brasileira-de-normas-tecnicas.csl
+++ b/citation-styles/associacao-brasileira-de-normas-tecnicas.csl
@@ -1,9 +1,9 @@