1<?php
2/**
3 * Semantic plugin: Add Schema.org News Article using JSON-LD
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @copyright  (C) 2015-2023, Giuseppe Di Terlizzi
8 */
9
10class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin
11{
12
13    private $macros = array(
14        '~~NewsArticle~~', '~~Article~~', '~~TechArticle~~',
15        '~~BlogPosting~~', '~~Recipe~~', '~~NOSEMANTIC~~',
16    );
17
18    public function getType()
19    {return 'substition';}
20    public function getSort()
21    {return 99;}
22
23    public function connectTo($mode)
24    {
25
26        foreach ($this->macros as $macro) {
27            $this->Lexer->addSpecialPattern($macro, $mode, 'plugin_semantic');
28        }
29
30    }
31
32    public function handle($match, $state, $pos, Doku_Handler $handler)
33    {
34        return array($match, $state, $pos);
35    }
36
37    public function render($mode, Doku_Renderer $renderer, $data)
38    {
39
40        if ($mode == 'metadata') {
41
42            list($match, $state, $pos) = $data;
43
44            if ($match == '~~NOSEMANTIC~~') {
45                $renderer->meta['plugin']['semantic']['enabled'] = false;
46            } else {
47                $renderer->meta['plugin']['semantic']['schema.org']['type'] = trim(str_replace('Schema.org/', '', $match), '~~');
48                $renderer->meta['plugin']['semantic']['enabled']            = true;
49            }
50
51        }
52
53        return false;
54
55    }
56
57}
58