From 5ad3186d5fd9d5bb457ba503a5bf723029fa0afd Mon Sep 17 00:00:00 2001 From: yves Date: Wed, 27 Mar 2024 14:29:13 -0400 Subject: [PATCH 1/5] Adapts plugin to OJS 3.4 Signed-off-by: Yves Signed-off-by: Iudi --- OpenGraphPlugin.inc.php | 137 ------------------------------ OpenGraphPlugin.php | 151 +++++++++++++++++++++++++++++++++ index.php | 23 ----- locale/{en_US => en}/locale.po | 0 locale/{fi_FI => fi}/locale.po | 0 version.xml | 2 - 6 files changed, 151 insertions(+), 162 deletions(-) delete mode 100644 OpenGraphPlugin.inc.php create mode 100644 OpenGraphPlugin.php delete mode 100644 index.php rename locale/{en_US => en}/locale.po (100%) rename locale/{fi_FI => fi}/locale.po (100%) diff --git a/OpenGraphPlugin.inc.php b/OpenGraphPlugin.inc.php deleted file mode 100644 index 1986c12..0000000 --- a/OpenGraphPlugin.inc.php +++ /dev/null @@ -1,137 +0,0 @@ -getEnabled($mainContextId)) { - HookRegistry::register('ArticleHandler::view', array(&$this, 'submissionView')); - HookRegistry::register('PreprintHandler::view', array(&$this, 'submissionView')); - HookRegistry::register('CatalogBookHandler::book',array(&$this, 'submissionView')); - } - return true; - } - return false; - } - - /** - * Get the name of the settings file to be installed on new context - * creation. - * @return string - */ - function getContextSpecificPluginSettingsFile() { - return $this->getPluginPath() . '/settings.xml'; - } - - /** - * Inject Open Graph metadata into submission landing page view - * @param $hookName string - * @param $args array - * @return boolean - */ - function submissionView($hookName, $args) { - $application = Application::get(); - $applicationName = $application->getName(); - $request = $args[0]; - $context = $request->getContext(); - if ($applicationName == "ops"){ - $submission = $args[1]; - $submissionPath = array('preprint', 'view'); - $objectType = "article"; - } - elseif ($applicationName == "omp"){ - $submission = $args[1]; - $submissionPath = array('catalog', 'book'); - $objectType = "book"; - } - else { - $issue = $args[1]; - $submission = $args[2]; - $submissionPath = array('article', 'view'); - $objectType = "article"; - } - - $templateMgr = TemplateManager::getManager($request); - $templateMgr->addHeader('openGraphSiteName', ''); - $templateMgr->addHeader('openGraphObjectType', ''); - $templateMgr->addHeader('openGraphTitle', ''); - if ($abstract = PKPString::html2text($submission->getAbstract($submission->getLocale()))) $templateMgr->addHeader('openGraphDescription', ''); - $templateMgr->addHeader('openGraphUrl', ''); - if ($locale = $submission->getLocale()) $templateMgr->addHeader('openGraphLocale', ''); - - $openGraphImage = ""; - if ($contextPageHeaderLogo = $context->getLocalizedData('pageHeaderLogoImage')){ - $openGraphImage = $templateMgr->getTemplateVars('publicFilesDir') . "/" . $contextPageHeaderLogo['uploadName']; - } - if ($issue && $issueCoverImage = $issue->getLocalizedCoverImageUrl()){ - $openGraphImage = $issueCoverImage; - } - if ($submissionCoverImage = $submission->getCurrentPublication()->getLocalizedCoverImageUrl($submission->getData('contextId'))){ - $openGraphImage = $submissionCoverImage; - } - $templateMgr->addHeader('openGraphImage', ''); - - if ($datePublished = $submission->getDatePublished()) { - $openGraphDateName = $applicationName == "omp" ? "book:release_date" : "article:published_time"; - $templateMgr->addHeader('openGraphDate', ''); - } - - if ($applicationName == "omp") { - $publicationFormats = $submission->getCurrentPublication()->getData('publicationFormats'); - foreach ($publicationFormats as $publicationFormat) { - $identificationCodes = $publicationFormat->getIdentificationCodes(); - while ($identificationCode = $identificationCodes->next()) { - if ($identificationCode->getCode() == "02" || $identificationCode->getCode() == "15") { - $templateMgr->addHeader('openGraphBookIsbn', ''); - } - } - } - } - - $i=0; - $dao = DAORegistry::getDAO('SubmissionKeywordDAO'); - $keywords = $dao->getKeywords($submission->getCurrentPublication()->getId(), array(AppLocale::getLocale())); - foreach ($keywords as $locale => $localeKeywords) { - foreach ($localeKeywords as $keyword) { - $templateMgr->addHeader('openGraphArticleTag' . $i++, ''); - } - } - - return false; - } - - /** - * Get the display name of this plugin - * @return string - */ - function getDisplayName() { - return __('plugins.generic.openGraph.name'); - } - - /** - * Get the description of this plugin - * @return string - */ - function getDescription() { - return __('plugins.generic.openGraph.description'); - } -} - - diff --git a/OpenGraphPlugin.php b/OpenGraphPlugin.php new file mode 100644 index 0000000..e5d23b0 --- /dev/null +++ b/OpenGraphPlugin.php @@ -0,0 +1,151 @@ +getEnabled($mainContextId)) { + Hook::add('ArticleHandler::view', array(&$this, 'submissionView')); + Hook::add('PreprintHandler::view', array(&$this, 'submissionView')); + Hook::add('CatalogBookHandler::book', array(&$this, 'submissionView')); + } + return true; + } + return false; + } + + /** + * Get the name of the settings file to be installed on new context + * creation. + * @return string + */ + public function getContextSpecificPluginSettingsFile() + { + return $this->getPluginPath() . '/settings.xml'; + } + + /** + * Inject Open Graph metadata into submission landing page view + * @param $hookName string + * @param $args array + * @return boolean + */ + public function submissionView($hookName, $args) + { + $application = Application::get(); + $applicationName = $application->getName(); + $request = $args[0]; + $context = $request->getContext(); + if ($applicationName == "ops") { + $submission = $args[1]; + $submissionPath = array('preprint', 'view'); + $objectType = "article"; + } elseif ($applicationName == "omp") { + $submission = $args[1]; + $submissionPath = array('catalog', 'book'); + $objectType = "book"; + } else { + $issue = $args[1]; + $submission = $args[2]; + $submissionPath = array('article', 'view'); + $objectType = "article"; + } + + $templateMgr = TemplateManager::getManager($request); + $templateMgr->addHeader('openGraphSiteName', ''); + $templateMgr->addHeader('openGraphObjectType', ''); + $templateMgr->addHeader('openGraphTitle', ''); + if ($abstract = PKPString::html2text($submission->getAbstract($submission->getLocale()))) { + $templateMgr->addHeader('openGraphDescription', ''); + } + $templateMgr->addHeader('openGraphUrl', ''); + if ($locale = $submission->getLocale()) { + $templateMgr->addHeader('openGraphLocale', ''); + } + + $openGraphImage = ""; + if ($contextPageHeaderLogo = $context->getLocalizedData('pageHeaderLogoImage')) { + $openGraphImage = $templateMgr->getTemplateVars('publicFilesDir') . "/" . $contextPageHeaderLogo['uploadName']; + } + if ($issue && $issueCoverImage = $issue->getLocalizedCoverImageUrl()) { + $openGraphImage = $issueCoverImage; + } + if ($submissionCoverImage = $submission->getCurrentPublication()->getLocalizedCoverImageUrl($submission->getData('contextId'))) { + $openGraphImage = $submissionCoverImage; + } + $templateMgr->addHeader('openGraphImage', ''); + + if ($datePublished = $submission->getDatePublished()) { + $openGraphDateName = $applicationName == "omp" ? "book:release_date" : "article:published_time"; + $templateMgr->addHeader('openGraphDate', ''); + } + + if ($applicationName == "omp") { + $publicationFormats = $submission->getCurrentPublication()->getData('publicationFormats'); + foreach ($publicationFormats as $publicationFormat) { + $identificationCodes = $publicationFormat->getIdentificationCodes(); + while ($identificationCode = $identificationCodes->next()) { + if ($identificationCode->getCode() == "02" || $identificationCode->getCode() == "15") { + $templateMgr->addHeader('openGraphBookIsbn', ''); + } + } + } + } + + $i = 0; + $dao = DAORegistry::getDAO('SubmissionKeywordDAO'); + $keywords = $dao->getKeywords($submission->getCurrentPublication()->getId(), array(Locale::getLocale())); + foreach ($keywords as $locale => $localeKeywords) { + foreach ($localeKeywords as $keyword) { + $templateMgr->addHeader('openGraphArticleTag' . $i++, ''); + } + } + + return false; + } + + /** + * Get the display name of this plugin + * @return string + */ + public function getDisplayName() + { + return __('plugins.generic.openGraph.name'); + } + + /** + * Get the description of this plugin + * @return string + */ + public function getDescription() + { + return __('plugins.generic.openGraph.description'); + } +} diff --git a/index.php b/index.php deleted file mode 100644 index e1b6fd4..0000000 --- a/index.php +++ /dev/null @@ -1,23 +0,0 @@ -plugins.generic 1.0.1.0 2021-02-08 - 1 - OpenGraphPlugin From ff1943987d9c2a95273d015e1fa95dd30b4ea2be Mon Sep 17 00:00:00 2001 From: yves Date: Thu, 28 Mar 2024 14:51:43 -0400 Subject: [PATCH 2/5] Updates image and description meta tags. Signed-off-by: Yves Signed-off-by: Iudi --- OpenGraphPlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenGraphPlugin.php b/OpenGraphPlugin.php index e5d23b0..74df485 100644 --- a/OpenGraphPlugin.php +++ b/OpenGraphPlugin.php @@ -83,7 +83,7 @@ public function submissionView($hookName, $args) $templateMgr->addHeader('openGraphObjectType', ''); $templateMgr->addHeader('openGraphTitle', ''); if ($abstract = PKPString::html2text($submission->getAbstract($submission->getLocale()))) { - $templateMgr->addHeader('openGraphDescription', ''); + $templateMgr->addHeader('openGraphDescription', ''); } $templateMgr->addHeader('openGraphUrl', ''); if ($locale = $submission->getLocale()) { @@ -100,7 +100,7 @@ public function submissionView($hookName, $args) if ($submissionCoverImage = $submission->getCurrentPublication()->getLocalizedCoverImageUrl($submission->getData('contextId'))) { $openGraphImage = $submissionCoverImage; } - $templateMgr->addHeader('openGraphImage', ''); + $templateMgr->addHeader('openGraphImage', ''); if ($datePublished = $submission->getDatePublished()) { $openGraphDateName = $applicationName == "omp" ? "book:release_date" : "article:published_time"; From 21684ac0e77864c55f1c019c16f8a049f641a79d Mon Sep 17 00:00:00 2001 From: yves Date: Thu, 12 Sep 2024 15:26:18 -0400 Subject: [PATCH 3/5] Updates Open Graph meta tags --- OpenGraphPlugin.php | 12 ++++++------ version.xml | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OpenGraphPlugin.php b/OpenGraphPlugin.php index 74df485..6b54495 100644 --- a/OpenGraphPlugin.php +++ b/OpenGraphPlugin.php @@ -79,15 +79,15 @@ public function submissionView($hookName, $args) } $templateMgr = TemplateManager::getManager($request); - $templateMgr->addHeader('openGraphSiteName', ''); - $templateMgr->addHeader('openGraphObjectType', ''); - $templateMgr->addHeader('openGraphTitle', ''); + $templateMgr->addHeader('openGraphSiteName', ''); + $templateMgr->addHeader('openGraphObjectType', ''); + $templateMgr->addHeader('openGraphTitle', ''); if ($abstract = PKPString::html2text($submission->getAbstract($submission->getLocale()))) { $templateMgr->addHeader('openGraphDescription', ''); } - $templateMgr->addHeader('openGraphUrl', ''); + $templateMgr->addHeader('openGraphUrl', ''); if ($locale = $submission->getLocale()) { - $templateMgr->addHeader('openGraphLocale', ''); + $templateMgr->addHeader('openGraphLocale', ''); } $openGraphImage = ""; @@ -100,7 +100,7 @@ public function submissionView($hookName, $args) if ($submissionCoverImage = $submission->getCurrentPublication()->getLocalizedCoverImageUrl($submission->getData('contextId'))) { $openGraphImage = $submissionCoverImage; } - $templateMgr->addHeader('openGraphImage', ''); + $templateMgr->addHeader('openGraphImage', ''); if ($datePublished = $submission->getDatePublished()) { $openGraphDateName = $applicationName == "omp" ? "book:release_date" : "article:published_time"; diff --git a/version.xml b/version.xml index 293ca75..fc90eab 100644 --- a/version.xml +++ b/version.xml @@ -13,6 +13,6 @@ openGraph plugins.generic - 1.0.1.0 - 2021-02-08 + 1.0.3.2 + 2024-09-12 From f6ca33036bfcfa9f07110ba5129c0304f2afb10a Mon Sep 17 00:00:00 2001 From: yves Date: Thu, 12 Sep 2024 16:11:27 -0400 Subject: [PATCH 4/5] Updates Open Graph meta tags --- OpenGraphPlugin.php | 8 ++++---- version.xml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenGraphPlugin.php b/OpenGraphPlugin.php index 6b54495..591cc93 100644 --- a/OpenGraphPlugin.php +++ b/OpenGraphPlugin.php @@ -83,7 +83,7 @@ public function submissionView($hookName, $args) $templateMgr->addHeader('openGraphObjectType', ''); $templateMgr->addHeader('openGraphTitle', ''); if ($abstract = PKPString::html2text($submission->getAbstract($submission->getLocale()))) { - $templateMgr->addHeader('openGraphDescription', ''); + $templateMgr->addHeader('openGraphDescription', ''); } $templateMgr->addHeader('openGraphUrl', ''); if ($locale = $submission->getLocale()) { @@ -104,7 +104,7 @@ public function submissionView($hookName, $args) if ($datePublished = $submission->getDatePublished()) { $openGraphDateName = $applicationName == "omp" ? "book:release_date" : "article:published_time"; - $templateMgr->addHeader('openGraphDate', ''); + $templateMgr->addHeader('openGraphDate', ''); } if ($applicationName == "omp") { @@ -113,7 +113,7 @@ public function submissionView($hookName, $args) $identificationCodes = $publicationFormat->getIdentificationCodes(); while ($identificationCode = $identificationCodes->next()) { if ($identificationCode->getCode() == "02" || $identificationCode->getCode() == "15") { - $templateMgr->addHeader('openGraphBookIsbn', ''); + $templateMgr->addHeader('openGraphBookIsbn', ''); } } } @@ -124,7 +124,7 @@ public function submissionView($hookName, $args) $keywords = $dao->getKeywords($submission->getCurrentPublication()->getId(), array(Locale::getLocale())); foreach ($keywords as $locale => $localeKeywords) { foreach ($localeKeywords as $keyword) { - $templateMgr->addHeader('openGraphArticleTag' . $i++, ''); + $templateMgr->addHeader('openGraphArticleTag' . $i++, ''); } } diff --git a/version.xml b/version.xml index fc90eab..5f9a5cb 100644 --- a/version.xml +++ b/version.xml @@ -13,6 +13,6 @@ openGraph plugins.generic - 1.0.3.2 + 1.0.3.3 2024-09-12 From 2e4840a61cbe373c0144ccac32d4c47f6402ea5a Mon Sep 17 00:00:00 2001 From: yves Date: Thu, 12 Sep 2024 16:22:15 -0400 Subject: [PATCH 5/5] Changes version.xml to the current state of the original plugin --- version.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.xml b/version.xml index 5f9a5cb..293ca75 100644 --- a/version.xml +++ b/version.xml @@ -13,6 +13,6 @@ openGraph plugins.generic - 1.0.3.3 - 2024-09-12 + 1.0.1.0 + 2021-02-08