1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Robert Nitsch <r.s.nitsch@gmail.com>
5 *
6 * Based on the first socialshareprivacy plugin by Frank Schiebel.
7 */
8
9if (!defined('DOKU_INC')) die();
10require_once DOKU_PLUGIN.'syntax.php';
11
12class syntax_plugin_socialshareprivacy2 extends DokuWiki_Syntax_Plugin {
13    public function getType() {
14        return 'substition';
15    }
16
17    public function getPType() {
18        return 'block';
19    }
20
21    public function getSort() {
22        return 222;
23    }
24
25    public function connectTo($mode) {
26        $this->Lexer->addSpecialPattern('\{\{socialshareprivacy2\}\}', $mode, 'plugin_socialshareprivacy2');
27        $this->Lexer->addSpecialPattern('\{\{socialshareprivacy2>.+?\}\}', $mode, 'plugin_socialshareprivacy2');
28    }
29
30    public function handle($match, $state, $pos, &$handler){
31        $match = substr($match, 2, -2);
32        $pos = strrpos($match, ">");
33        if ( $pos === false ) {
34            $type = "socialshareprivacy2";
35            $params = array();
36            return array($type, $params);
37        } else {
38            list($type, $options) = split('>', $match, 2);
39        }
40
41        $options = split('&', $options);
42
43        foreach($options as $option) {
44            list($name, $value) = split('=', $option);
45            $params[trim($name)] = trim($value);
46        }
47
48        return array($type, $params);
49    }
50
51    public function render($mode, &$renderer, $data) {
52        if($mode != 'xhtml') return false;
53
54        $renderer->doc .= '<div class="socialshareprivacy"></div>'. DOKU_LF;
55        return true;
56    }
57}
58