Open Journal Systems  3.3.0
GoogleScholarPlugin.inc.php
1 <?php
2 
16 import('lib.pkp.classes.plugins.GenericPlugin');
17 
22  function register($category, $path, $mainContextId = null) {
23  if (parent::register($category, $path, $mainContextId)) {
24  if ($this->getEnabled($mainContextId)) {
25  HookRegistry::register('ArticleHandler::view', array(&$this, 'submissionView'));
26  HookRegistry::register('PreprintHandler::view', array(&$this, 'submissionView'));
27  }
28  return true;
29  }
30  return false;
31  }
32 
39  return $this->getPluginPath() . '/settings.xml';
40  }
41 
48  function submissionView($hookName, $args) {
50  $applicationName = $application->getName();
51  $request = $args[0];
52  if ($applicationName == "ojs2"){
53  $issue = $args[1];
54  $submission = $args[2];
55  $submissionPath = 'article';
56  }
57  if ($applicationName == "ops"){
58  $submission = $args[1];
59  $submissionPath = 'preprint';
60  }
61  $requestArgs = $request->getRequestedArgs();
62  $context = $request->getContext();
63 
64  // Only add Google Scholar metadata tags to the canonical URL for the latest version
65  // See discussion: https://github.com/pkp/pkp-lib/issues/4870
66  if (count($requestArgs) > 1 && $requestArgs[1] === 'version') {
67  return;
68  }
69 
70  $templateMgr = TemplateManager::getManager($request);
71  $templateMgr->addHeader('googleScholarRevision', '<meta name="gs_meta_revision" content="1.1"/>');
72 
73  // Context identification
74  if ($applicationName == "ojs2"){
75  $templateMgr->addHeader('googleScholarJournalTitle', '<meta name="citation_journal_title" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . '"/>');
76  if (($abbreviation = $context->getData('abbreviation', $context->getPrimaryLocale())) || ($abbreviation = $context->getData('acronym', $context->getPrimaryLocale()))) {
77  $templateMgr->addHeader('googleScholarJournalAbbrev', '<meta name="citation_journal_abbrev" content="' . htmlspecialchars($abbreviation) . '"/>');
78  }
79  if ( ($issn = $context->getData('onlineIssn')) || ($issn = $context->getData('printIssn')) || ($issn = $context->getData('issn'))) {
80  $templateMgr->addHeader('googleScholarIssn', '<meta name="citation_issn" content="' . htmlspecialchars($issn) . '"/> ');
81  }
82  }
83  if ($applicationName == "ops"){
84  $templateMgr->addHeader('googleScholarPublisher', '<meta name="citation_publisher" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . '"/>');
85  }
86 
87 
88  // Contributors
89  foreach ($submission->getAuthors() as $i => $author) {
90  $templateMgr->addHeader('googleScholarAuthor' . $i, '<meta name="citation_author" content="' . htmlspecialchars($author->getFullName(false)) .'"/>');
91  if ($affiliation = htmlspecialchars($author->getAffiliation($submission->getLocale()))) {
92  $templateMgr->addHeader('googleScholarAuthor' . $i . 'Affiliation', '<meta name="citation_author_institution" content="' . $affiliation . '"/>');
93  }
94  }
95 
96  // Submission title
97  $templateMgr->addHeader('googleScholarTitle', '<meta name="citation_title" content="' . htmlspecialchars($submission->getFullTitle($submission->getLocale())) . '"/>');
98  if ($locale = $submission->getLocale()) $templateMgr->addHeader('googleScholarLanguage', '<meta name="citation_language" content="' . htmlspecialchars(substr($locale, 0, 2)) . '"/>');
99 
100  // Submission publish date and issue information
101  if ($applicationName == "ojs2"){
102  if (is_a($submission, 'Submission') && ($datePublished = $submission->getDatePublished()) && (!$issue->getYear() || $issue->getYear() == strftime('%Y', strtotime($datePublished)))) {
103  $templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . strftime('%Y/%m/%d', strtotime($datePublished)) . '"/>');
104  } elseif ($issue && $issue->getYear()) {
105  $templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . htmlspecialchars($issue->getYear()) . '"/>');
106  } elseif ($issue && ($datePublished = $issue->getDatePublished())) {
107  $templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . strftime('%Y/%m/%d', strtotime($datePublished)) . '"/>');
108  }
109  if ($issue) {
110  if ($issue->getShowVolume()) $templateMgr->addHeader('googleScholarVolume', '<meta name="citation_volume" content="' . htmlspecialchars($issue->getVolume()) . '"/>');
111  if ($issue->getShowNumber()) $templateMgr->addHeader('googleScholarNumber', '<meta name="citation_issue" content="' . htmlspecialchars($issue->getNumber()) . '"/>');
112  }
113  if ($submission->getPages()) {
114  if ($startPage = $submission->getStartingPage()) $templateMgr->addHeader('googleScholarStartPage', '<meta name="citation_firstpage" content="' . htmlspecialchars($startPage) . '"/>');
115  if ($endPage = $submission->getEndingPage()) $templateMgr->addHeader('googleScholarEndPage', '<meta name="citation_lastpage" content="' . htmlspecialchars($endPage) . '"/>');
116  }
117  }
118  if ($applicationName == "ops"){
119  $templateMgr->addHeader('googleScholarDate', '<meta name="citation_online_date" content="' . strftime('%Y/%m/%d', strtotime($submission->getDatePublished())) . '"/>');
120  }
121 
122  // Identifiers: DOI, URN
123  foreach((array) $templateMgr->getTemplateVars('pubIdPlugins') as $pubIdPlugin) {
124  if ($pubId = $submission->getStoredPubId($pubIdPlugin->getPubIdType())) {
125  $templateMgr->addHeader('googleScholarPubId' . $pubIdPlugin->getPubIdDisplayType(), '<meta name="citation_' . htmlspecialchars(strtolower($pubIdPlugin->getPubIdDisplayType())) . '" content="' . htmlspecialchars($pubId) . '"/>');
126  }
127  }
128 
129  // Abstract url and keywords
130  $templateMgr->addHeader('googleScholarHtmlUrl', '<meta name="citation_abstract_html_url" content="' . $request->url(null, $submissionPath, 'view', array($submission->getBestId())) . '"/>');
131 
132  $i=0;
133  $dao = DAORegistry::getDAO('SubmissionKeywordDAO');
134  $keywords = $dao->getKeywords($submission->getCurrentPublication()->getId(), array(AppLocale::getLocale()));
135  foreach ($keywords as $locale => $localeKeywords) {
136  foreach ($localeKeywords as $keyword) {
137  $templateMgr->addHeader('googleScholarKeyword' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($keyword) . '"/>');
138  }
139  }
140 
141  // Galley links
142  $i=$j=0;
143  if (is_a($submission, 'Submission')) foreach ($submission->getGalleys() as $galley) {
144  if (is_a($galley->getFile(), 'SupplementaryFile')) continue;
145  if ($galley->getFileType()=='application/pdf') {
146  $templateMgr->addHeader('googleScholarPdfUrl' . $i++, '<meta name="citation_pdf_url" content="' . $request->url(null, $submissionPath, 'download', array($submission->getBestId(), $galley->getBestGalleyId())) . '"/>');
147  } elseif ($galley->getFileType()=='text/html') {
148  $templateMgr->addHeader('googleScholarHtmlUrl' . $i++, '<meta name="citation_fulltext_html_url" content="' . $request->url(null, $submissionPath, 'view', array($submission->getBestId(), $galley->getBestGalleyId())) . '"/>');
149  }
150  }
151 
152  // Citations
153  $outputReferences = array();
154  $citationDao = DAORegistry::getDAO('CitationDAO'); /* @var $citationDao CitationDAO */
155  $parsedCitations = $citationDao->getByPublicationId($submission->getCurrentPublication()->getId());
156  if ($parsedCitations->getCount()){
157  while ($citation = $parsedCitations->next()) {
158  $outputReferences[] = $citation->getRawCitation();
159  }
160  }
161  HookRegistry::call('GoogleScholarPlugin::references', array(&$outputReferences, $submission->getId()));
162 
163  if (!empty($outputReferences)){
164  $i=0;
165  foreach ($outputReferences as $outputReference) {
166  $templateMgr->addHeader('googleScholarReference' . $i++, '<meta name="citation_reference" content="' . htmlspecialchars($outputReference) . '"/>');
167  }
168  }
169 
170  return false;
171  }
172 
177  function getDisplayName() {
178  return __('plugins.generic.googleScholar.name');
179  }
180 
185  function getDescription() {
186  return __('plugins.generic.googleScholar.description');
187  }
188 }
189 
190 
$application
$application
Definition: index.php:65
GoogleScholarPlugin\submissionView
submissionView($hookName, $args)
Definition: GoogleScholarPlugin.inc.php:48
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
GoogleScholarPlugin
Inject Google Scholar meta tags into submission views to facilitate indexing.
Definition: GoogleScholarPlugin.inc.php:18
GoogleScholarPlugin\getDisplayName
getDisplayName()
Definition: GoogleScholarPlugin.inc.php:177
Plugin\getEnabled
getEnabled()
Definition: Plugin.inc.php:868
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
GoogleScholarPlugin\getContextSpecificPluginSettingsFile
getContextSpecificPluginSettingsFile()
Definition: GoogleScholarPlugin.inc.php:38
Plugin\getPluginPath
getPluginPath()
Definition: Plugin.inc.php:330
Plugin\$request
$request
Definition: Plugin.inc.php:68
GoogleScholarPlugin\getDescription
getDescription()
Definition: GoogleScholarPlugin.inc.php:185
HookRegistry\register
static register($hookName, $callback, $hookSequence=HOOK_SEQUENCE_NORMAL)
Definition: HookRegistry.inc.php:70
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
GenericPlugin
Abstract class for generic plugins.
Definition: GenericPlugin.inc.php:18