Open Monograph Press  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('CatalogBookHandler::view', array($this, 'monographFileView'));
26  }
27  return true;
28  }
29  return false;
30  }
31 
38  return $this->getPluginPath() . '/settings.xml';
39  }
40 
47  function monographFileView($hookName, $args) {
48  $monograph =& $args[1];
49  $publication = $monograph->getCurrentPublication();
50  $publicationFormat =& $args[2];
51  $submissionFile =& $args[3];
52 
53  if ($submissionFile->getFileType() == 'application/pdf') {
54  $request = Application::get()->getRequest();
55  $templateMgr = TemplateManager::getManager($request);
56  $press = $request->getContext();
57  $chapter = $templateMgr->getTemplateVars('chapter');
58  $series = $templateMgr->getTemplateVars('series');
59 
60  $templateMgr->addHeader('googleScholarRevision', '<meta name="gs_meta_revision" content="1.1"/>');
61  $templateMgr->addHeader('googleScholarPressTitle', '<meta name="citation_journal_title" content="' . htmlspecialchars($press->getName($press->getPrimaryLocale())) . '"/>');
62  if ($series && $issn = $series->getOnlineISSN()) {
63  $templateMgr->addHeader('googleScholarIssn', '<meta name="citation_issn" content="' . htmlspecialchars($issn) . '"/> ');
64  }
65 
66  $identificationCodes = $publicationFormat->getIdentificationCodes();
67  while ($identificationCode = $identificationCodes->next()) {
68  if ($identificationCode->getCode() == "02" || $identificationCode->getCode() == "15") {
69  // 02 and 15: ONIX codes for ISBN-10 or ISBN-13
70  $templateMgr->addHeader('googleScholarIsbn' . $identificationCode->getCode(), '<meta name="citation_isbn" content="' . htmlspecialchars($identificationCode->getValue()) . '"/>');
71  }
72  }
73 
74  foreach ($chapter?$chapter->getAuthors()->toArray():$publication->getData('authors') as $i => $author) {
75  $templateMgr->addHeader('googleScholarAuthor' . $i, '<meta name="citation_author" content="' . htmlspecialchars($author->getFullName(false)) . '"/>');
76  if ($affiliation = htmlspecialchars($author->getAffiliation($publication->getData('locale')))) {
77  $templateMgr->addHeader('googleScholarAuthor' . $i . 'Affiliation', '<meta name="citation_author_institution" content="' . $affiliation . '"/>');
78  }
79  }
80 
81  if ($chapter) {
82  $templateMgr->addHeader('googleScholarTitle', '<meta name="citation_title" content="' . htmlspecialchars($chapter->getTitle($publication->getData('locale'))) . '"/>');
83  } else {
84  $templateMgr->addHeader('googleScholarTitle', '<meta name="citation_title" content="' . htmlspecialchars($publication->getData('title', $publication->getData('locale'))) . '"/>');
85  }
86 
87  $templateMgr->addHeader('googleScholarDate', '<meta name="citation_publication_date" content="' . strftime('%Y/%m/%d', strtotime($publication->getData('datePublished'))) . '"/>');
88 
89  foreach((array) $templateMgr->getTemplateVars('pubIdPlugins') as $pubIdPlugin) {
90  if ($pubId = $monograph->getStoredPubId($pubIdPlugin->getPubIdType())) {
91  $templateMgr->addHeader('googleScholarPubId' . $pubIdPlugin->getPubIdDisplayType(), '<meta name="citation_' . htmlspecialchars(strtolower($pubIdPlugin->getPubIdDisplayType())) . '" content="' . htmlspecialchars($pubId) . '"/>');
92  }
93  }
94 
95  if ($languages = $publication->getData('languages')) foreach ($languages as $language) {
96  $templateMgr->addHeader('googleScholarLanguage', '<meta name="citation_language" content="' . htmlspecialchars($language) . '"/>');
97  }
98 
99  $i=0;
100  $submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /* @var $submissionSubjectDao SubmissionSubjectDAO */
101  $supportedLocales = array_keys(AppLocale::getSupportedFormLocales());
102  if ($subjects = $submissionSubjectDao->getSubjects($publication->getId(), $supportedLocales)) foreach ($subjects as $locale => $subjectLocale) {
103  foreach ($subjectLocale as $gsKeyword) $templateMgr->addHeader('googleScholarSubject' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($gsKeyword) . '"/>');
104  }
105 
106  $i=0;
107  $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /* @var $submissionKeywordDao SubmissionKeywordDAO */
108  if ($keywords = $submissionKeywordDao->getKeywords($publication->getId(), $supportedLocales)) foreach ($keywords as $locale => $keywordLocale) {
109  foreach ($keywordLocale as $gsKeyword) $templateMgr->addHeader('googleScholarKeyword' . $i++, '<meta name="citation_keywords" xml:lang="' . htmlspecialchars(substr($locale, 0, 2)) . '" content="' . htmlspecialchars($gsKeyword) . '"/>');
110  }
111 
112  $templateMgr->addHeader('googleScholarPdfUrl' . $i++, '<meta name="citation_pdf_url" content="' . $request->url(null, 'catalog', 'download', array($monograph->getBestId(), $publicationFormat->getId(), $submissionFile->getFileIdAndRevision())) . '"/>');
113  }
114 
115  return false;
116  }
117 
122  function getDisplayName() {
123  return __('plugins.generic.googleScholar.name');
124  }
125 
130  function getDescription() {
131  return __('plugins.generic.googleScholar.description');
132  }
133 }
134 
135 
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
GoogleScholarPlugin
Inject Google Scholar meta tags into monograph views to facilitate indexing.
Definition: GoogleScholarPlugin.inc.php:18
GoogleScholarPlugin\getDisplayName
getDisplayName()
Definition: GoogleScholarPlugin.inc.php:122
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:37
Plugin\getPluginPath
getPluginPath()
Definition: Plugin.inc.php:330
Plugin\$request
$request
Definition: Plugin.inc.php:68
GoogleScholarPlugin\getDescription
getDescription()
Definition: GoogleScholarPlugin.inc.php:130
HookRegistry\register
static register($hookName, $callback, $hookSequence=HOOK_SEQUENCE_NORMAL)
Definition: HookRegistry.inc.php:70
GoogleScholarPlugin\monographFileView
monographFileView($hookName, $args)
Definition: GoogleScholarPlugin.inc.php:47
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
AppLocale\getSupportedFormLocales
static getSupportedFormLocales()
Definition: env1/MockAppLocale.inc.php:124
GenericPlugin
Abstract class for generic plugins.
Definition: GenericPlugin.inc.php:18