Added initial support for Open Graph protocol
This commit is contained in:
parent
5c8fdeb240
commit
eb577a09e5
6 changed files with 52 additions and 7 deletions
24
action.php
24
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');
|
$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')) {
|
if ($this->getConf('exposeWebService')) {
|
||||||
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax');
|
$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) {
|
public function meta_dublin_core(Doku_Event &$event, $params) {
|
||||||
|
|
||||||
global $ID;
|
global $ID;
|
||||||
|
|
|
@ -11,4 +11,5 @@ $conf['exposeWebService'] = 1;
|
||||||
$conf['useMetaDescription'] = 1;
|
$conf['useMetaDescription'] = 1;
|
||||||
$conf['useMetaAuthor'] = 1;
|
$conf['useMetaAuthor'] = 1;
|
||||||
$conf['useDublinCore'] = 0;
|
$conf['useDublinCore'] = 0;
|
||||||
|
$conf['useOpenGraph'] = 0;
|
||||||
$conf['excludedPages'] = '(wiki|playground)';
|
$conf['excludedPages'] = '(wiki|playground)';
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
$meta['useMetaDescription'] = array('onoff');
|
$meta['useMetaDescription'] = array('onoff');
|
||||||
$meta['useMetaAuthor'] = array('onoff');
|
$meta['useMetaAuthor'] = array('onoff');
|
||||||
$meta['useDublinCore'] = array('onoff');
|
$meta['useDublinCore'] = array('onoff');
|
||||||
|
$meta['useOpenGraph'] = array('onoff');
|
||||||
$meta['useJSONLD'] = array('onoff');
|
$meta['useJSONLD'] = array('onoff');
|
||||||
$meta['exposeWebService'] = array('onoff');
|
$meta['exposeWebService'] = array('onoff');
|
||||||
$meta['defaultSchemaOrgType'] = array('multichoice','_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting', 'Recipe'));
|
$meta['defaultSchemaOrgType'] = array('multichoice','_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting', 'Recipe'));
|
||||||
|
|
20
helper.php
20
helper.php
|
@ -52,7 +52,7 @@ class helper_plugin_semantic extends DokuWiki_Plugin {
|
||||||
|
|
||||||
if (! $auth_check) return false;
|
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']) {
|
if (isset($this->meta['plugin']['semantic']['enabled']) && ! $this->meta['plugin']['semantic']['enabled']) {
|
||||||
return false;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// for the configuration manager
|
// 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['defaultSchemaOrgType'] = 'Default Schema.org type for JSON-LD';
|
||||||
$lang['excludedPages'] = 'Excluded pages (insert a regex)';
|
$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';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
base semantic
|
base semantic
|
||||||
author Giuseppe Di Terlizzi
|
author Giuseppe Di Terlizzi
|
||||||
email giuseppe.diterlizzi@gmail.com
|
email giuseppe.diterlizzi@gmail.com
|
||||||
date 2016-10-03
|
date 2016-12-12
|
||||||
name Semantic Plugin
|
name Semantic Plugin
|
||||||
desc Add Semantic Data in DokuWiki
|
desc Add Semantic Data in DokuWiki
|
||||||
url http://www.dokuwiki.org/plugin:semantic
|
url http://www.dokuwiki.org/plugin:semantic
|
||||||
|
|
Loading…
Reference in a new issue