1<?php
2/**
3 * DokuWiki Plugin processing (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Edwin Dertien <mail@edwindertien.nl>
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
18require_once DOKU_INC.'inc/geshi.php';
19require_once DOKU_INC.'inc/parser/code.php';
20
21
22class syntax_plugin_processing extends DokuWiki_Syntax_Plugin {
23	function getInfo() {
24	        return array('author' => 'Edwin Dertien',
25                     'email'  => 'mail@edwindertien.nl',
26                     'date'   => '2010-08-22',
27                     'name'   => 'Processing code Plugin',
28                     'desc'   => 'Include processing code and embedded processing.js applet',
29                     'url'    => 'http://www.dokuwiki.org/plugin:tutorial');
30	}
31    function getType() {
32        return 'substition';
33    }
34
35    function getPType() {
36        return 'normal';
37    }
38
39    function getSort() {
40        return 100;
41    }
42
43
44    function connectTo($mode) {
45        $this->Lexer->addEntryPattern('<processing>',$mode,'plugin_processing');
46    }
47
48 function postConnect() {
49        $this->Lexer->addExitPattern('</processing>','plugin_processing');
50    }
51
52 function handle($match, $state, $pos, &$handler){
53 $width = 300;
54 $height = 300;
55      switch ($state) {
56          case DOKU_LEXER_ENTER :
57            break;
58          case DOKU_LEXER_MATCHED :
59            break;
60          case DOKU_LEXER_UNMATCHED :
61          // ugly piece of string decomposition to get width and hight from the sketch
62                $numbers = substr($match,strpos($match,"size(")+5,20);
63                $width = trim(substr($numbers,0,strpos($numbers,",")));
64                $height = trim(substr($numbers,strpos($numbers,",")+1,strpos($numbers,");")-strpos($numbers,",")-1));
65                return array($state,$match,$width,$height);
66            	break;
67          case DOKU_LEXER_EXIT :
68            break;
69          case DOKU_LEXER_SPECIAL :
70            break;
71        }
72
73    }
74
75
76    function render($mode, &$renderer, $data) {
77        if($mode == 'xhtml'){
78        list($state, $match,$width,$height) = $data;
79        switch ($state) {
80        case DOKU_LEXER_ENTER :
81        	break;
82        case DOKU_LEXER_UNMATCHED :
83       $renderer->doc .=
84  		"<script type=\"application/processing\">".
85       $renderer->_xmlEntities($match).
86        "</script><canvas width=\"".
87        $width.
88        "\" height=\"".
89        $height.
90        "\"></canvas>";
91
92        $renderer->code($match,'java');
93
94        $renderer->doc .= "<br>build with <a href=\"http://www.processing.org\">processing</a> and <a href=\"http://www.processingjs.org\">processing.js</a><br>";
95
96        break;
97        case DOKU_LEXER_EXIT :
98        	break;
99        default:
100        break;
101        }
102
103            return true;
104        }
105        return false;
106    }
107
108}
109
110?>
111