Skip to content

Commit

Permalink
Support 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnyga committed Dec 4, 2024
1 parent 416ec70 commit d4eabbb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
56 changes: 45 additions & 11 deletions OpenGraphPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
/**
* @file OpenGraphPlugin.inc.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class OpenGraphPlugin
* @ingroup plugins_generic_openGraph
*
* @brief Inject Open Graph meta tags into submission views to facilitate indexing.
* @brief Inject Open Graph meta tags into submission views in OJS, OMP and OPS and issue view in OJS.
*/

import('lib.pkp.classes.plugins.GenericPlugin');
Expand All @@ -24,7 +24,8 @@ function register($category, $path, $mainContextId = null) {
if ($this->getEnabled($mainContextId)) {
HookRegistry::register('ArticleHandler::view', array(&$this, 'submissionView'));
HookRegistry::register('PreprintHandler::view', array(&$this, 'submissionView'));
HookRegistry::register('CatalogBookHandler::book',array(&$this, 'submissionView'));
HookRegistry::register('CatalogBookHandler::book',array(&$this, 'submissionView'));
HookRegistry::register('TemplateManager::display',array(&$this, 'issueView'));
}
return true;
}
Expand All @@ -40,6 +41,41 @@ function getContextSpecificPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}

/**
* Inject Open Graph metadata into issue landing page view
* @param $hookName string
* @param $args array
* @return boolean
*/
function issueView($hookName, $args) {
$template = $args[1];

if ($template == 'frontend/pages/issue.tpl') {
$templateMgr = $args[0];
$request = $this->getRequest();
$context = $request->getContext();
$issue = $templateMgr->getTemplateVars('issue');
if ($issue){
$templateMgr = TemplateManager::getManager($request);
$templateMgr->addHeader('openGraphSiteName', '<meta property="og:site_name" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . '"/>');
$templateMgr->addHeader('openGraphObjectType', '<meta property="og:type" content="website"/>');
$templateMgr->addHeader('openGraphTitle', '<meta property="og:title" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . " " . htmlspecialchars($issue->getIssueIdentification()) . '"/>');
$templateMgr->addHeader('openGraphUrl', '<meta property="og:url" content="' . $request->url(null, 'issue', 'view', array($issue->getBestIssueId())) . '"/>');
$templateMgr->addHeader('openGraphLocale', '<meta property="og:locale" content="' . htmlspecialchars($context->getPrimaryLocale()) . '"/>');
if ($issue && $issueCoverImage = $issue->getLocalizedCoverImageUrl()){
$templateMgr->addHeader('openGraphImage', '<meta name="image" property="og:image" content="' . htmlspecialchars($issueCoverImage) . '"/>');
$templateMgr->addHeader('twitterCard', '<meta name="twitter:card" content="summary_large_image" />');
$templateMgr->addHeader('twitterSiteName', '<meta name="twitter:site" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . '"/>');
$templateMgr->addHeader('twitterTitle', '<meta name="twitter:title" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . " " . htmlspecialchars($issue->getIssueIdentification()) . '"/>');
$templateMgr->addHeader('twitterImage', '<meta name="twitter:image" content="' . htmlspecialchars($issueCoverImage) . '"/>');
}
}
}

return false;

}

/**
* Inject Open Graph metadata into submission landing page view
* @param $hookName string
Expand Down Expand Up @@ -69,11 +105,11 @@ function submissionView($hookName, $args) {
}

$templateMgr = TemplateManager::getManager($request);
$templateMgr->addHeader('openGraphSiteName', '<meta name="og:site_name" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . '"/>');
$templateMgr->addHeader('openGraphObjectType', '<meta name="og:type" content="' . htmlspecialchars($objectType) . '"/>');
$templateMgr->addHeader('openGraphTitle', '<meta name="og:title" content="' . htmlspecialchars($submission->getFullTitle($submission->getLocale())) . '"/>');
$templateMgr->addHeader('openGraphSiteName', '<meta property="og:site_name" content="' . htmlspecialchars($context->getName($context->getPrimaryLocale())) . '"/>');
$templateMgr->addHeader('openGraphObjectType', '<meta property="og:type" content="' . htmlspecialchars($objectType) . '"/>');
$templateMgr->addHeader('openGraphTitle', '<meta property="og:title" content="' . htmlspecialchars($submission->getFullTitle($submission->getLocale())) . '"/>');
if ($abstract = PKPString::html2text($submission->getAbstract($submission->getLocale()))) $templateMgr->addHeader('openGraphDescription', '<meta name="description" property="og:description" content="' . htmlspecialchars($abstract) . '"/>');
$templateMgr->addHeader('openGraphUrl', '<meta name="og:url" content="' . $request->url(null, $submissionPath[0], $submissionPath[1], array($submission->getBestId())) . '"/>');
$templateMgr->addHeader('openGraphUrl', '<meta property="og:url" content="' . $request->url(null, $submissionPath[0], $submissionPath[1], array($submission->getBestId())) . '"/>');
if ($locale = $submission->getLocale()) $templateMgr->addHeader('openGraphLocale', '<meta name="og:locale" content="' . htmlspecialchars($locale) . '"/>');

$openGraphImage = "";
Expand Down Expand Up @@ -132,6 +168,4 @@ function getDisplayName() {
function getDescription() {
return __('plugins.generic.openGraph.description');
}
}


}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Open Graph
Exposes OJS, OMP and OPS metadata using the Open Graph protocol (https://ogp.me/). The metadata is used when published submissions are shared in Facebook and LinkedIn.
Exposes OJS, OMP and OPS metadata using the Open Graph protocol (https://ogp.me/). Tags are visible in the article, book and preprint landing pages and in the issue landing page in OJS.

The metadata is used when published submissions and issues are shared in Facebook and LinkedIn.

OJS, OMP and OPS 3.3

***
Plugin created by The Federation of Finnish Learned Societies (https://tsv.fi/en/).
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/**
* @file plugins/generic/openGraph/index.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @ingroup plugins_generic_openGraph
Expand Down
4 changes: 2 additions & 2 deletions settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<!--
* plugins/generic/openGraph/settings.xml
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* Default plugin settings.
Expand Down
8 changes: 4 additions & 4 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<!--
* plugins/generic/openGraph/version.xml
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* Plugin version information.
-->
<version>
<application>openGraph</application>
<type>plugins.generic</type>
<release>1.0.1.0</release>
<date>2021-02-08</date>
<release>3.3.0.0</release>
<date>2024-12-04</date>
<lazy-load>1</lazy-load>
<class>OpenGraphPlugin</class>
</version>

0 comments on commit d4eabbb

Please sign in to comment.