Added ~~Recipe~~ macro (thanks to @coastgnu on #1 issue) and several improvements

This commit is contained in:
Giuseppe Di Terlizzi 2015-10-30 16:25:39 +01:00
parent 95f02e1bff
commit 77f2311ffe
4 changed files with 206 additions and 199 deletions

View file

@ -3,7 +3,7 @@
* Semantic Action Plugin * Semantic Action Plugin
* *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi> * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @copyright (C) 2015, Giuseppe Di Terlizzi * @copyright (C) 2015, Giuseppe Di Terlizzi
*/ */
@ -48,11 +48,13 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
global $INFO; global $INFO;
global $ID; global $ID;
if ((bool) preg_match_all('/'.$this->getConf('excludedPages').'/', $ID)) { if ((bool) preg_match('/'.$this->getConf('excludedPages').'/', $ID)) {
return false; return false;
} }
if ($INFO['perm'] > 0) { if (! $INFO['perm']) {
return false;
}
global $license; global $license;
global $auth; global $auth;
@ -70,18 +72,18 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
? $meta['semantic']['schema.org']['type'] ? $meta['semantic']['schema.org']['type']
: $this->getConf('defaultSchemaOrgType')); : $this->getConf('defaultSchemaOrgType'));
$user_data = $auth->getUserData($meta['user']); $user_data = $auth->getUserData($meta['user']);
$license_url = $license[$conf['license']]['url']; $license_url = @$license[$conf['license']]['url'];
$page_url = wl($ID, '', true); $page_url = wl($ID, '', true);
$image_url = (($meta['relation']['firstimage']) ? ml($meta['relation']['firstimage'], '', true, '&amp;', true) : null); $image_url = (($meta['relation']['firstimage']) ? ml($meta['relation']['firstimage'], '', true, '&amp;', true) : null);
$description = trim(ltrim($meta['description']['abstract'], $meta['title'])); $description = trim(ltrim($meta['description']['abstract'], @$meta['title']));
$created = date(DATE_W3C, $meta['date']['created']); $created = date(DATE_W3C, $meta['date']['created']);
$modified = date(DATE_W3C, $meta['date']['modified']); $modified = date(DATE_W3C, $meta['date']['modified']);
$json_ld = array( $json_ld = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org',
'@type' => $type, '@type' => $type,
'headline' => $meta['title'], 'headline' => @$meta['title'],
'name' => $meta['title'], 'name' => @$meta['title'],
'image' => array($image_url), 'image' => array($image_url),
'datePublished' => $created, 'datePublished' => $created,
'dateCreated' => $created, 'dateCreated' => $created,
@ -92,6 +94,7 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
); );
if (isset($meta['creator']) && $meta['creator'] !== '') { if (isset($meta['creator']) && $meta['creator'] !== '') {
$json_ld['creator'] = array( $json_ld['creator'] = array(
'@context' => 'http://schema.org', '@context' => 'http://schema.org',
'@type' => 'Person', '@type' => 'Person',
@ -143,7 +146,6 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
); );
} }
}
} }
@ -157,7 +159,9 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
return false; return false;
} }
if ($INFO['perm'] > 0) { if (! $INFO['perm']) {
return false;
}
$meta = $INFO['meta']; $meta = $INFO['meta'];
@ -167,7 +171,7 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
if (isset($meta['date']) && $meta['date'] !== '') { if (isset($meta['date']) && $meta['date'] !== '') {
$description = str_replace("\n", ' ', trim(ltrim($meta['description']['abstract'], $meta['title']))); $description = str_replace("\n", ' ', trim(ltrim($meta['description']['abstract'], @$meta['title'])));
$event->data['meta'][] = array( $event->data['meta'][] = array(
'name' => 'description', 'name' => 'description',
@ -178,8 +182,6 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
} }
}
public function meta_author(Doku_Event &$event, $params) { public function meta_author(Doku_Event &$event, $params) {
@ -190,7 +192,9 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
return false; return false;
} }
if ($INFO['perm'] > 0) { if (! $INFO['perm']) {
return false;
}
$meta = $INFO['meta']; $meta = $INFO['meta'];
@ -206,12 +210,8 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
'name' => 'author', 'name' => 'author',
'content' => $meta['creator'], 'content' => $meta['creator'],
); );
} }
} }
} }
}

View file

@ -8,6 +8,5 @@
$meta['useMetaDescription'] = array('onoff'); $meta['useMetaDescription'] = array('onoff');
$meta['useMetaAuthor'] = array('onoff'); $meta['useMetaAuthor'] = array('onoff');
$meta['useJSONLD'] = array('onoff'); $meta['useJSONLD'] = array('onoff');
$meta['defaultSchemaOrgType'] = array('multichoice','_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting')); $meta['defaultSchemaOrgType'] = array('multichoice','_choices' => array('Article', 'NewsArticle', 'TechArticle', 'BlogPosting', 'Recipe'));
$meta['excludedPages'] = array('regex'); $meta['excludedPages'] = array('regex');

View file

@ -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 2015-03-30 date 2015-10-30
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

View file

@ -12,15 +12,20 @@ if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin { class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin {
private $macros = array(
'~~NewsArticle~~', '~~Article~~', '~~TechArticle~~',
'~~BlogPosting~~', '~~Recipe~~', '~~NOSEMANTIC~~'
);
function getType() { return 'substition'; } function getType() { return 'substition'; }
function getSort() { return 99; } function getSort() { return 99; }
function connectTo($mode) { function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~NewsArticle~~', $mode, 'plugin_semantic');
$this->Lexer->addSpecialPattern('~~Article~~', $mode, 'plugin_semantic'); foreach ($this->macros as $macro) {
$this->Lexer->addSpecialPattern('~~TechArticle~~', $mode, 'plugin_semantic'); $this->Lexer->addSpecialPattern($macro, $mode, 'plugin_semantic');
$this->Lexer->addSpecialPattern('~~BlogPosting~~', $mode, 'plugin_semantic'); }
$this->Lexer->addSpecialPattern('~~NOSEMANTIC~~', $mode, 'plugin_semantic');
} }
function handle($match, $state, $pos, Doku_Handler $handler) { function handle($match, $state, $pos, Doku_Handler $handler) {
@ -35,6 +40,8 @@ class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin {
list($match, $state, $pos) = $data; list($match, $state, $pos) = $data;
if ($match == '~~NOSEMANTIC~~') { if ($match == '~~NOSEMANTIC~~') {
$renderer->meta['semantic']['enabled'] = false; $renderer->meta['semantic']['enabled'] = false;
} else { } else {
@ -43,6 +50,7 @@ class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin {
} }
} }
} }
} }