Skip to content

Commit

Permalink
Merge pull request #12 from bozana/8406
Browse files Browse the repository at this point in the history
pkp/pkp-lib#8406 Improve GoogleScholarPlugin according to the changes…
  • Loading branch information
bozana authored Feb 9, 2023
2 parents f940dc9 + 6b58e60 commit 931f799
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions GoogleScholarPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use APP\core\Application;
use APP\facades\Repo;
use APP\submission\Submission;
use APP\template\TemplateManager;
use PKP\db\DAORegistry;
use PKP\plugins\GenericPlugin;
Expand Down Expand Up @@ -105,7 +104,8 @@ public function submissionView($hookName, $args)
$submissionBestId = $publication->getData('urlPath') ?? $submission->getId();

// Contributors
foreach ($publication->getData('authors') as $i => $author) {
$authors = $publication->getData('authors');
foreach ($authors as $i => $author) {
$templateMgr->addHeader('googleScholarAuthor' . $i, '<meta name="citation_author" content="' . htmlspecialchars($author->getFullName(false)) . '"/>');
if ($affiliation = htmlspecialchars($author->getLocalizedData('affiliation', $publicationLocale))) {
$templateMgr->addHeader('googleScholarAuthor' . $i . 'Affiliation', '<meta name="citation_author_institution" content="' . $affiliation . '"/>');
Expand All @@ -114,11 +114,12 @@ public function submissionView($hookName, $args)

// Submission title
$templateMgr->addHeader('googleScholarTitle', '<meta name="citation_title" content="' . htmlspecialchars($publication->getLocalizedFullTitle($publicationLocale)) . '"/>');

$templateMgr->addHeader('googleScholarLanguage', '<meta name="citation_language" content="' . htmlspecialchars(substr($publicationLocale, 0, 2)) . '"/>');

// Submission publish date and issue information
if ($applicationName == 'ojs2') {
if ($submission instanceof Submission && ($datePublished = $publication->getData('datePublished')) && (!$issue || !$issue->getYear() || $issue->getYear() == date('Y', strtotime($datePublished)))) {
if (($datePublished = $publication->getData('datePublished')) && (!$issue || !$issue->getYear() || $issue->getYear() == date('Y', strtotime($datePublished)))) {
$templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . date('Y/m/d', strtotime($datePublished)) . '"/>');
} elseif ($issue && $issue->getYear()) {
$templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . htmlspecialchars($issue->getYear()) . '"/>');
Expand All @@ -143,7 +144,9 @@ public function submissionView($hookName, $args)
}
}
if ($applicationName == 'ops') {
$templateMgr->addHeader('googleScholarDate', '<meta name="citation_online_date" content="' . date('Y/m/d', strtotime($publication->getData('datePublished'))) . '"/>');
if ($datePublished = $publication->getData('datePublished')) {
$templateMgr->addHeader('googleScholarDate', '<meta name="citation_online_date" content="' . date('Y/m/d', strtotime($datePublished)) . '"/>');
}
}

// DOI
Expand All @@ -166,34 +169,28 @@ public function submissionView($hookName, $args)
}

// Subjects
$i = 0;
$submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO');
/** @var SubmissionSubjectDAO $submissionSubjectDao */
if ($subjects = $submissionSubjectDao->getSubjects($publication->getId(), [$publicationLocale])) {
foreach ($subjects as $locale => $subjectLocale) {
foreach ($subjectLocale as $gsKeyword) {
$templateMgr->addHeader('googleScholarSubject' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($gsKeyword) . '"/>');
if ($subjects = $publication->getData('subjects')) {
foreach ($subjects as $locale => $localeSubjects) {
foreach ($localeSubjects as $i => $subject) {
$templateMgr->addHeader('googleScholarSubject' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($subject) . '"/>');
}
}
}

// Keywords
$i = 0;
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
/** @var SubmissionKeywordDAO $submissionKeywordDao */
if ($keywords = $submissionKeywordDao->getKeywords($publication->getId(), [$publicationLocale])) {
foreach ($keywords as $locale => $keywordLocale) {
foreach ($keywordLocale as $gsKeyword) {
$templateMgr->addHeader('googleScholarKeyword' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($gsKeyword) . '"/>');
if ($keywords = $publication->getData('keywords')) {
foreach ($keywords as $locale => $localeKeywords) {
foreach ($localeKeywords as $i => $keyword) {
$templateMgr->addHeader('googleScholarKeyword' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($keyword) . '"/>');
}
}
}

// Galley links
$i = 0;
if ($submission instanceof Submission) {
foreach ($publication->getData('galleys') as $galley) {
$submissionFile = Repo::submissionFile()->get($galley->getData('submissionFileId'));
$galleys = $publication->getData('galleys');
foreach ($galleys as $i => $galley) {
$submissionFileId = $galley->getData('submissionFileId');
if ($submissionFileId && $submissionFile = Repo::submissionFile()->get($submissionFileId)) {
if ($submissionFile->getData('mimetype') == 'application/pdf') {
$templateMgr->addHeader('googleScholarPdfUrl' . $i++, '<meta name="citation_pdf_url" content="' . $request->url(null, $submissionPath, 'download', [$submissionBestId, $galley->getBestGalleyId()]) . '"/>');
} elseif ($submissionFile->getData('mimetype') == 'text/html') {
Expand All @@ -211,11 +208,8 @@ public function submissionView($hookName, $args)
}
Hook::call('GoogleScholarPlugin::references', [&$outputReferences, $submission->getId()]);

if (!empty($outputReferences)) {
$i = 0;
foreach ($outputReferences as $outputReference) {
$templateMgr->addHeader('googleScholarReference' . $i++, '<meta name="citation_reference" content="' . htmlspecialchars($outputReference) . '"/>');
}
foreach ($outputReferences as $i => $outputReference) {
$templateMgr->addHeader('googleScholarReference' . $i++, '<meta name="citation_reference" content="' . htmlspecialchars($outputReference) . '"/>');
}

return false;
Expand Down

0 comments on commit 931f799

Please sign in to comment.