1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4
5 */
6
7if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_INC.'inc/common.php');
10
11require_once(DOKU_PLUGIN.'syntax.php');
12
13class syntax_plugin_dyncontent extends DokuWiki_Syntax_Plugin {
14
15    function getInfo(){
16        return array(
17            'author' => 'Fr1z',
18            'email'  => 'franxcava@gmail.com',
19            'date'   => '2020-02-08',
20            'name'   => 'Dynamic Content Plugin',
21            'desc'   => "Write any content once to display it in different wiki pages",
22            'url'    => 'http://dokuwiki.org/plugin:dyncontent',
23        );
24    }
25
26
27     // What kind of syntax are we?
28    function getType(){ return 'formatting'; }
29
30    // What kind of syntax do we allow (optional)
31    function getAllowedTypes() {
32        return array('formatting', 'substition', 'disabled');
33    }
34	// What about paragraphs? (optional)
35   function getPType(){ return 'normal'; }
36
37    // Where to sort in?
38    function getSort(){ return 90; }
39
40
41    // Connect pattern to lexer
42    function connectTo($mode) {
43      $this->Lexer->addEntryPattern('(?i)<dyn(?: .+?)?>(?=.+</dyn>)',$mode,'plugin_dyncontent');
44    }
45
46    function postConnect() {
47      	$this->Lexer->addExitPattern('(?i)</dyn>','plugin_dyncontent');
48	}
49
50	    // Handle the match
51    function handle($match, $state, $pos, Doku_Handler $handler){
52        switch ($state) {
53          case DOKU_LEXER_ENTER :
54            preg_match("/(?i)<dyn (.+?)>/", $match, $pagename); // get the color
55            return array($state, $pagename[1]);
56            break;
57          case DOKU_LEXER_MATCHED :
58            break;
59          case DOKU_LEXER_UNMATCHED :
60            return array($state, $match);
61            break;
62          case DOKU_LEXER_EXIT :
63            break;
64          case DOKU_LEXER_SPECIAL :
65            break;
66        } //$match = substr($match,9,-2);
67        return array($state, "");
68    }
69
70    // Create output
71    function render($mode, Doku_Renderer $renderer, $data) {
72        if($mode == 'xhtml'){
73          list($state, $contenuto) = $data;
74          switch ($state) {
75            case DOKU_LEXER_ENTER :
76              $renderer->doc .= "<span style=\"border-bottom: 1px dashed #a29b8a;\">";
77              break;
78            case DOKU_LEXER_MATCHED :
79              break;
80            case DOKU_LEXER_UNMATCHED :
81              $renderer->doc .= $renderer->_xmlEntities($contenuto);
82              break;
83            case DOKU_LEXER_EXIT :
84              $renderer->doc .= "</span>";
85              break;
86            case DOKU_LEXER_SPECIAL :
87              break;
88          }
89          return true;
90        }
91        return false;
92    }
93
94
95
96}
97