1<?php
2/**
3 * DokuWiki Plugin signavio (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Christian Zinke <zinke@informatik.uni-leipzig.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
15
16require_once DOKU_PLUGIN . 'syntax.php';
17
18class syntax_plugin_signavio extends DokuWiki_Syntax_Plugin
19{
20
21    public function getType()
22    {
23        return 'substition';
24    }
25
26    /**
27    public function getPType() {
28    return 'block';
29    }
30     **/
31    public function getSort()
32    {
33        return 999;
34    }
35
36    function connectTo($mode)
37    {
38        $this->Lexer->addEntryPattern('<signavio[\s]*?.*?>(?=.*?</signavio>)', $mode, 'plugin_signavio');
39    }
40
41    function postConnect()
42    {
43        $this->Lexer->addExitPattern('</signavio>', 'plugin_signavio');
44    }
45
46    function handle($match, $state, $pos, &$handler){
47
48
49            switch ($state) {
50              case DOKU_LEXER_ENTER :
51                break;
52              case DOKU_LEXER_MATCHED :
53                break;
54              case DOKU_LEXER_UNMATCHED :
55
56
57                $span = '<script type="text/javascript"
58                                 src="http://academic.signavio.com/mashup/signavio.js"></script>
59                                 <script type="text/plain">
60                                 {';
61                /**
62                 * <h3 class="signavio-title"><a href="http://www.signavio.com">Tourbus besorgen (Kopie)</a></h3>
63                 <script type="text/javascript"
64                 src="http://academic.signavio.com/mashup/signavio.js"></script>
65                 <script type="text/plain">
66                 {
67                      url:
68                 "http://academic.signavio.com/p/model/9d803e2368f54263a1bd0df62038dc89",
69                      authToken:
70                 "ee2293c5d156849ae326a8ddcf704977d0c5673c1181ecabb16fd2af57f893_c3748750f5599852abd3a2aa63fb9bdbc66bd43d01e6616bb326ca01db1f2_195063cdda70e7d8e46c4c23c5496cb188a52acefd013e1395991eac58c329a",
71                      overflowX: "fit",
72                      overflowY: "fit",
73                      zoomSlider: true,
74                      linkSubProcesses: false
75                 }
76
77                 <a class="signavio-logo" href="http://www.signavio.com"
78                 rel="external"><img
79                 src="http://academic.signavio.com/mashup/img/signavio.png" alt="BPM Personalbedarf jBPM" /></a>
80                </script>
81                 */
82    			if(trim($match) != ""){
83    				$begin = $span;
84
85    				$end = '
86                    }
87    				<a class="signavio-logo" href="http://www.signavio.com"
88    				                 rel="external"><img
89    				                 src="http://academic.signavio.com/mashup/img/signavio.png" alt="BPM Personalbedarf jBPM" /></a>
90    				</script>';
91
92                    $sigData = explode(':',$match);
93
94                    if(empty($sigData[1])){
95                        return array($state, '<span>Parameter do not match, expacted someURLId:SomeAuthTokenId</span>');
96                    }
97
98
99    				return array($state, array($begin, $sigData[0], $sigData[1], $end));
100    			}
101    			break;
102              case DOKU_LEXER_EXIT :
103                break;
104              case DOKU_LEXER_SPECIAL :
105                break;
106            }
107            return array();
108        }
109
110      /*
111        * @public
112        * @see handle()
113        */
114        function render($mode, &$renderer, $data) {
115            if($mode == 'xhtml'){
116                if($data[0] == DOKU_LEXER_UNMATCHED){
117
118                  if(!is_array($data[1])){
119                      $renderer->doc .= $data[1];
120                      return true;
121                  }
122                  $text = $data[1][0];
123                   $text .= '
124                    url:
125                 "http://academic.signavio.com/p/model/'.$data[1][1].'",
126                      authToken:
127                 "'.$data[1][2].'",
128                      overflowX: "fit",
129                      overflowY: "fit",
130                      zoomSlider: true,
131                      linkSubProcesses: false
132                      ';
133                  $text .= $data[1][3];
134
135                  $renderer->doc .= $text;   // ptype = 'normal'
136                  return true;
137                }
138            }
139            return false;
140        }
141
142
143}
144
145// vim:ts=4:sw=4:et:
146