dokuwiki-gnuplot-plugin – Diff between revs 1 and 2

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 2
Line 1... Line 1...
1 <?php 1 <?php
2 /** 2 /**
3 * plot-Plugin: Parses gnuplot-blocks 3 * plot-Plugin: Parses gnuplot-blocks
4 * 4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
-   6 * @author Wizardry and Steamworks <wizardry.steamworks@outlook.com>,
6 * @author Alexander 'E-Razor' Krause <alexander.krause@erazor-zone.de> 7 * Alexander 'E-Razor' Krause <alexander.krause@erazor-zone.de>
-   8 *
-   9 * [WaS] The following plugin is a revision of the GNUplot Plugin by
-   10 * Alexander 'E-Razor' Krause from 2005 that uses the original gnuplot binary
-   11 * in order to render graphs that has been patched up to work on modern
-   12 * DokuWki versions.
-   13 *
7 */ 14 */
8 15  
9 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 16 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 17 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11 require_once(DOKU_PLUGIN.'syntax.php'); 18 require_once(DOKU_PLUGIN.'syntax.php');
Line 12... Line -...
12   -  
13 if (!is_callable("file_put_contents")) { -  
14 @require_once('/usr/lib/php/PHP/Compat/Function/file_put_contents.php'); -  
15 if (!is_callable("file_put_contents")) { -  
16 echo 'Please install dev-php/PEAR-PHP_Compat or >=php-5.0.0 !'; -  
17 } -  
18 } -  
19 19  
20 /** 20 /**
21 * All DokuWiki plugins to extend the parser/rendering mechanism 21 * All DokuWiki plugins to extend the parser/rendering mechanism
22 * need to inherit from this class 22 * need to inherit from this class
23 */ 23 */
24 class syntax_plugin_plot extends DokuWiki_Syntax_Plugin { -  
25 function getInfo(){ -  
26 return array( -  
27 'author' => 'Alexander Krause', -  
28 'email' => 'alexander.krause@erazor-zone.de', -  
29 'date' => '2006-05-23', -  
30 'name' => 'Plot Plugin', -  
31 'desc' => 'render functions nicely', -  
32 'url' => 'http://wiki.erazor-zone.de/doku.php?id=wiki:projects:php:dokuwiki:plugins:plot' -  
33 ); -  
34 } 24 class syntax_plugin_plot extends DokuWiki_Syntax_Plugin {
35 /** 25 /**
36 * What kind of syntax are we? 26 * What kind of syntax are we?
37 */ 27 */
38 function getType(){ 28 //function accepts($m) { return true; }
39 return 'protected'; -  
40 } -  
41 -  
42 /** 29 function getType() { return 'protected'; }
43 * Where to sort in? -  
44 */ 30 function getPType() { return 'normal'; }
45 function getSort(){ -  
46 return 100; -  
47 } -  
Line 48... Line 31...
48 31 function getSort() { return 200; }
49 32
50 /** 33 /**
51 * Connect pattern to lexer 34 * Connect pattern to lexer
52 */ 35 */
53 function connectTo($mode) { 36 function connectTo($mode) {
54 $this->Lexer->addEntryPattern('<plot(?=.*\x3C/plot\x3E)',$mode,'plugin_plot'); 37 $this->Lexer->addEntryPattern('<plot(?=.*\x3C/plot\x3E)', $mode, 'plugin_plot');
55 } 38 }
56 39
57 function postConnect() { 40 function postConnect() {
58 $this->Lexer->addExitPattern('</plot>','plugin_plot'); 41 $this->Lexer->addExitPattern('</plot>', 'plugin_plot');
59 } 42 }
60 43
61 /** 44 /**
62 * Handle the match -  
63 */ -  
64 45 * Handle the match
65 46 */
66 function handle($match, $state, $pos, Doku_Handler $handler) { 47 function handle($match, $state, $pos, Doku_Handler $handler) {
67 if ( $state == DOKU_LEXER_UNMATCHED ) { 48 if ( $state == DOKU_LEXER_UNMATCHED ) {
68 $matches = preg_split('/>/u',$match,2); 49 $matches = preg_split('/>/u', $match, 2);
69 $matches[0] = trim($matches[0]); 50 $matches[0] = trim($matches[0]);
70 if ( trim($matches[0]) == '' ) { 51 if ( trim($matches[0]) == '' ) {
71 $matches[0] = NULL; 52 $matches[0] = NULL;
72 } 53 }
73 return array($matches[1],$matches[0]); 54 return array($matches[1],$matches[0]);
74 } 55 }
75 return TRUE; 56 return array($state, '', '');
76 } 57 }
77 /** 58 /**
78 * Create output 59 * Create output
79 */ 60 */
80 function render($mode, Doku_Renderer $renderer, $data) { 61 function render($mode, Doku_Renderer $renderer, $data) {
-   62 global $conf;
81 global $conf; 63 if($mode == 'xhtml' && strlen($data[0]) > 1) {
-   64 if ( !is_dir($conf['mediadir'] . '/plot') ) {
-   65 mkdir($conf['mediadir'] . '/plot', 0777 - $conf['dmask']);
82 if($mode == 'xhtml' && strlen($data[0]) > 1) { 66 }
83 if ( !is_dir($conf['mediadir'] . '/plot') ) mkdir($conf['mediadir'] . '/plot', 0777-$conf['dmask']); 67
Line 84... Line 68...
84 $hash = md5(serialize($data[0])); 68 $hash = md5(serialize($data[0]));
Line 96... Line 80...
96 } else { 80 } else {
97 $renderer->doc .= '**ERROR RENDERING GNUPLOT**'; 81 $renderer->doc .= '**ERROR RENDERING GNUPLOT**';
98 } 82 }
99 return true; 83 return true;
100 } 84 }
-   85
101 return false; 86 return false;
102 } 87 }
Line 103... Line 88...
103 88
104 function createImage($filename, &$data) { -  
105 global $conf; -  
106   89 function createImage($filename, &$data) {
Line 107... Line 90...
107 $tmpfname = tempnam("/tmp", "dokuwiki.plot"); 90 $tmpfname = tempnam("/tmp", "dokuwiki.plot");
108   91  
Line 122... Line 105...
122 function plugin_render($text, $format='xhtml') { 105 function plugin_render($text, $format='xhtml') {
123 return p_render($format, p_get_instructions($text),$info); 106 return p_render($format, p_get_instructions($text),$info);
124 } 107 }
125 } 108 }
Line 126... Line -...
126   -