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..591cc93 --- /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