From eb577a09e55d7c9ac98d3932f9142310ccfef594 Mon Sep 17 00:00:00 2001 From: Giuseppe Di Terlizzi Date: Mon, 12 Dec 2016 23:57:13 +0100 Subject: [PATCH] Added initial support for Open Graph protocol --- action.php | 24 ++++++++++++++++++++++++ conf/default.php | 1 + conf/metadata.php | 1 + helper.php | 20 +++++++++++++++++++- lang/en/settings.php | 11 ++++++----- plugin.info.txt | 2 +- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/action.php b/action.php index 8fb7576..db6886d 100644 --- a/action.php +++ b/action.php @@ -47,6 +47,10 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin { $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'meta_dublin_core'); } + if ($this->getConf('useOpenGraph')) { + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'meta_open_graph'); + } + if ($this->getConf('exposeWebService')) { $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax'); } @@ -168,6 +172,26 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin { } + public function meta_open_graph(Doku_Event &$event, $params) { + + global $ID; + + $this->helper->getMetadata($ID); + + foreach ($this->helper->getOpenGraph() as $property => $content) { + + if (! $content) continue; + + $event->data['meta'][] = array( + 'property' => $property, + 'content' => $content, + ); + + } + + } + + public function meta_dublin_core(Doku_Event &$event, $params) { global $ID; diff --git a/conf/default.php b/conf/default.php index 22b909a..84a2c1b 100644 --- a/conf/default.php +++ b/conf/default.php @@ -11,4 +11,5 @@ $conf['exposeWebService'] = 1; $conf['useMetaDescription'] = 1; $conf['useMetaAuthor'] = 1; $conf['useDublinCore'] = 0; +$conf['useOpenGraph'] = 0; $conf['excludedPages'] = '(wiki|playground)'; diff --git a/conf/metadata.php b/conf/metadata.php index b0eec13..f1ba43d 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -8,6 +8,7 @@ $meta['useMetaDescription'] = array('onoff'); $meta['useMetaAuthor'] = array('onoff'); $meta['useDublinCore'] = array('onoff'); +$meta['useOpenGraph'] = array('onoff'); $meta['useJSONLD'] = array('onoff'); $meta['exposeWebService'] = array('onoff'); $meta['defaultSchemaOrgType'] = array('multichoice','_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting', 'Recipe')); diff --git a/helper.php b/helper.php index a30501b..fdb7dbb 100644 --- a/helper.php +++ b/helper.php @@ -52,7 +52,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin { if (! $auth_check) return false; - $this->meta = p_get_metadata($page); + $this->meta = p_get_metadata($this->page); if (isset($this->meta['plugin']['semantic']['enabled']) && ! $this->meta['plugin']['semantic']['enabled']) { return false; @@ -268,4 +268,22 @@ class helper_plugin_semantic extends DokuWiki_Plugin { } + + public function getOpenGraph() { + + global $conf; + + if (! $this->meta) return array(); + + $open_graph = array( + 'og:title' => $this->getTitle(), + 'og:description' => str_replace("\n", ' ', $this->getDescription()), + 'og:url' => wl($this->page, '', true), + 'og:type' => 'website', + ); + + return $open_graph; + + } + } diff --git a/lang/en/settings.php b/lang/en/settings.php index d8df7a6..b7c8dda 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -7,10 +7,11 @@ */ // for the configuration manager -$lang['useMetaDescription'] = 'Add description meta tag'; -$lang['useMetaAuthor'] = 'Add author meta tag'; -$lang['useDublinCore'] = 'Add Dublin Core metadata'; -$lang['useJSONLD'] = 'Add JSON-LD'; $lang['defaultSchemaOrgType'] = 'Default Schema.org type for JSON-LD'; $lang['excludedPages'] = 'Excluded pages (insert a regex)'; -$lang['exposeWebService'] = 'Expose Ajax WebService'; \ No newline at end of file +$lang['exposeWebService'] = 'Expose Ajax WebService'; +$lang['useDublinCore'] = 'Add Dublin Core metadata'; +$lang['useJSONLD'] = 'Add JSON-LD'; +$lang['useMetaAuthor'] = 'Add author meta tag'; +$lang['useMetaDescription'] = 'Add description meta tag'; +$lang['useOpenGraph'] = 'Add Open Graph protocol metadata'; diff --git a/plugin.info.txt b/plugin.info.txt index a942603..b5ea617 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base semantic author Giuseppe Di Terlizzi email giuseppe.diterlizzi@gmail.com -date 2016-10-03 +date 2016-12-12 name Semantic Plugin desc Add Semantic Data in DokuWiki url http://www.dokuwiki.org/plugin:semantic