Added initial support for Open Graph protocol

This commit is contained in:
Giuseppe Di Terlizzi 2016-12-12 23:57:13 +01:00
parent 5c8fdeb240
commit eb577a09e5
6 changed files with 52 additions and 7 deletions

View file

@ -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;

View file

@ -11,4 +11,5 @@ $conf['exposeWebService'] = 1;
$conf['useMetaDescription'] = 1;
$conf['useMetaAuthor'] = 1;
$conf['useDublinCore'] = 0;
$conf['useOpenGraph'] = 0;
$conf['excludedPages'] = '(wiki|playground)';

View file

@ -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'));

View file

@ -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;
}
}

View file

@ -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';
$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';

View file

@ -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