Added ~~Recipe~~ macro (thanks to @coastgnu on #1 issue) and several improvements
This commit is contained in:
parent
95f02e1bff
commit
77f2311ffe
4 changed files with 206 additions and 199 deletions
34
action.php
34
action.php
|
@ -3,7 +3,7 @@
|
|||
* Semantic Action Plugin
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
|
@ -48,11 +48,13 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
global $INFO;
|
||||
global $ID;
|
||||
|
||||
if ((bool) preg_match_all('/'.$this->getConf('excludedPages').'/', $ID)) {
|
||||
if ((bool) preg_match('/'.$this->getConf('excludedPages').'/', $ID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($INFO['perm'] > 0) {
|
||||
if (! $INFO['perm']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $license;
|
||||
global $auth;
|
||||
|
@ -70,18 +72,18 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
? $meta['semantic']['schema.org']['type']
|
||||
: $this->getConf('defaultSchemaOrgType'));
|
||||
$user_data = $auth->getUserData($meta['user']);
|
||||
$license_url = $license[$conf['license']]['url'];
|
||||
$license_url = @$license[$conf['license']]['url'];
|
||||
$page_url = wl($ID, '', true);
|
||||
$image_url = (($meta['relation']['firstimage']) ? ml($meta['relation']['firstimage'], '', true, '&', 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']);
|
||||
$modified = date(DATE_W3C, $meta['date']['modified']);
|
||||
|
||||
$json_ld = array(
|
||||
'@context' => 'http://schema.org',
|
||||
'@type' => $type,
|
||||
'headline' => $meta['title'],
|
||||
'name' => $meta['title'],
|
||||
'headline' => @$meta['title'],
|
||||
'name' => @$meta['title'],
|
||||
'image' => array($image_url),
|
||||
'datePublished' => $created,
|
||||
'dateCreated' => $created,
|
||||
|
@ -92,6 +94,7 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
);
|
||||
|
||||
if (isset($meta['creator']) && $meta['creator'] !== '') {
|
||||
|
||||
$json_ld['creator'] = array(
|
||||
'@context' => 'http://schema.org',
|
||||
'@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;
|
||||
}
|
||||
|
||||
if ($INFO['perm'] > 0) {
|
||||
if (! $INFO['perm']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = $INFO['meta'];
|
||||
|
||||
|
@ -167,7 +171,7 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
|
||||
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(
|
||||
'name' => 'description',
|
||||
|
@ -178,8 +182,6 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function meta_author(Doku_Event &$event, $params) {
|
||||
|
||||
|
@ -190,7 +192,9 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($INFO['perm'] > 0) {
|
||||
if (! $INFO['perm']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = $INFO['meta'];
|
||||
|
||||
|
@ -206,12 +210,8 @@ class action_plugin_semantic extends DokuWiki_Action_Plugin {
|
|||
'name' => 'author',
|
||||
'content' => $meta['creator'],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,5 @@
|
|||
$meta['useMetaDescription'] = array('onoff');
|
||||
$meta['useMetaAuthor'] = 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');
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
base semantic
|
||||
author Giuseppe Di Terlizzi
|
||||
email giuseppe.diterlizzi@gmail.com
|
||||
date 2015-03-30
|
||||
date 2015-10-30
|
||||
name Semantic Plugin
|
||||
desc Add Semantic Data in Dokuwiki
|
||||
desc Add Semantic Data in DokuWiki
|
||||
url http://www.dokuwiki.org/plugin:semantic
|
||||
|
|
18
syntax.php
18
syntax.php
|
@ -12,15 +12,20 @@ if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
|
|||
|
||||
class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin {
|
||||
|
||||
private $macros = array(
|
||||
'~~NewsArticle~~', '~~Article~~', '~~TechArticle~~',
|
||||
'~~BlogPosting~~', '~~Recipe~~', '~~NOSEMANTIC~~'
|
||||
);
|
||||
|
||||
function getType() { return 'substition'; }
|
||||
function getSort() { return 99; }
|
||||
|
||||
function connectTo($mode) {
|
||||
$this->Lexer->addSpecialPattern('~~NewsArticle~~', $mode, 'plugin_semantic');
|
||||
$this->Lexer->addSpecialPattern('~~Article~~', $mode, 'plugin_semantic');
|
||||
$this->Lexer->addSpecialPattern('~~TechArticle~~', $mode, 'plugin_semantic');
|
||||
$this->Lexer->addSpecialPattern('~~BlogPosting~~', $mode, 'plugin_semantic');
|
||||
$this->Lexer->addSpecialPattern('~~NOSEMANTIC~~', $mode, 'plugin_semantic');
|
||||
|
||||
foreach ($this->macros as $macro) {
|
||||
$this->Lexer->addSpecialPattern($macro, $mode, 'plugin_semantic');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
if ($match == '~~NOSEMANTIC~~') {
|
||||
$renderer->meta['semantic']['enabled'] = false;
|
||||
} else {
|
||||
|
@ -43,6 +50,7 @@ class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue