-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.php
101 lines (84 loc) · 2.86 KB
/
syntax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Charter Plugin
*
* Renders customized charts using the pChart library.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Gina Haeussge <[email protected]>
*/
if (!defined('DOKU_INC'))
define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/');
if (!defined('DOKU_PLUGIN'))
define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once (DOKU_PLUGIN . 'syntax.php');
class syntax_plugin_charter extends DokuWiki_Syntax_Plugin {
function getInfo() {
return array (
'author' => 'Gina Haeussge',
'email' => '[email protected]',
'date' => @file_get_contents(DOKU_PLUGIN.'charter/VERSION'),
'name' => 'Charter Plugin (syntax component)',
'desc' => 'Renders customized charts using the pChart library',
'url' => 'http://foosel.org/snippets/dokuwiki/charter',
);
}
function getType() {
return 'substition';
}
function getSort() {
return 123;
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('<charter>.*?</charter>', $mode, 'plugin_charter');
}
function handle($match, $state, $pos, & $handler) {
global $ID;
$match = trim($match);
$lines = explode("\n", substr($match, 9, -10));
if (trim($lines[0]) === '')
array_shift($lines);
if (trim($lines[-1]) === '')
array_pop($lines);
$flags = array();
$data = array();
$indata = false;
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') { // begin data field
$indata = true;
} else {
if ($indata) { // reading in data
array_push($data, $line);
} else { // reading in flags
list($name, $value) = explode('=', $line, 2);
$flags[trim($name)] = trim($value);
}
}
}
if (isset($flags['title'])) {
$mediaid = getNS($ID) . ':chart-' . cleanID($flags['title'], false, true) . '.png';
} else {
$mediaid = getNS($ID) . ':chart-' . cleanID('notitle_' . md5($match)) . '.png';
}
$filename = mediaFN($mediaid);
$helper =& plugin_load('helper', 'charter');
$helper->setFlags($flags);
$helper->setData($data);
io_makeFileDir($filename);
io_lock($filename);
$helper->render($filename);
io_unlock($filename);
return array($mediaid, $helper->flags);
}
function render($mode, & $renderer, $indata) {
list($mediaid, $flags) = $indata;
if ($mode == 'xhtml') {
$renderer->doc .= '<img src="'.ml($mediaid, 'cache=nocache').'" alt="'.$flags['title'].'" width="'.$flags['size']['width'].'" height="'.$flags['size']['height'].'" class="media'.$flags['align'].'" />';
return true;
}
// unsupported $mode
return false;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :