7
7
8
8
/**
9
9
blockdiag_example:
10
- {
10
+ blockdiag {
11
11
A -> B -> C
12
12
B -> D
13
13
}
@@ -54,7 +54,14 @@ function blockdiagDisplay( $input, $args, $parser ){
54
54
* Blockdiag
55
55
**/
56
56
class Blockdiag {
57
- private $ _blockdiag_path = '/usr/bin/blockdiag ' ;
57
+ private $ _path_array = array (
58
+ 'blockdiag ' => '/usr/local/bin/blockdiag ' ,
59
+ 'seqdiag ' => '/usr/local/bin/seqdiag ' ,
60
+ 'actdiag ' => '/usr/local/bin/actdiag ' ,
61
+ 'nwdiag ' => '/usr/local/bin/nwdiag ' ,
62
+ 'rackdiag ' => '/usr/local/bin/rackdiag ' , # in nwdiag
63
+ 'packetdiag ' => '/usr/local/bin/packetdiag ' , # in nwdiag
64
+ );
58
65
private $ _imgType = 'png ' ;
59
66
private $ _hash ;
60
67
private $ _source ;
@@ -64,11 +71,6 @@ class Blockdiag {
64
71
65
72
public function __construct ( $ blockdiagDir , $ blockdiagUrl , $ tmpDir , $ source )
66
73
{
67
- if (!is_file ($ this ->_blockdiag_path ))
68
- {
69
- throw new Exception ('blockdiag is not found at the specified place ($_blockdiag_path). ' , 1 );
70
- return false ;
71
- }
72
74
$ this ->_blockdiagDir = $ blockdiagDir ;
73
75
$ this ->_blockdiagUrl = $ blockdiagUrl ;
74
76
$ this ->_tmpDir = $ tmpDir ;
@@ -87,6 +89,19 @@ public function showImage() {
87
89
}
88
90
89
91
private function _generate () {
92
+ if (preg_match ('/^\s*(\w+)\s*{/ ' , $ this ->_source , $ matches )) {
93
+ $ diagram_type = $ matches [1 ];
94
+ } else {
95
+ #return $this->_error("diagtype is not specified.");
96
+ $ diagram_type = 'blockdiag ' ; # blockdiag for default
97
+ }
98
+
99
+ $ diagprog_path = $ this ->_path_array [$ diagram_type ];
100
+ if (!is_file ($ diagprog_path ))
101
+ {
102
+ return $ this ->_error ("$ diagram_type is not found at the specified place. " );
103
+ }
104
+
90
105
// temporary directory check
91
106
if ( !file_exists ( $ this ->_tmpDir ) ){
92
107
if ( !wfMkdirParents ( $ this ->_tmpDir ) ) {
@@ -108,7 +123,7 @@ private function _generate() {
108
123
fclose ($ fp );
109
124
110
125
// generate blockdiag image
111
- $ cmd = $ this -> _blockdiag_path . ' -T ' .
126
+ $ cmd = $ diagprog_path . ' -T ' .
112
127
escapeshellarg ( $ this ->_imgType ) . ' -o ' .
113
128
escapeshellarg ( $ dstTmpName ) . ' ' .
114
129
escapeshellarg ( $ srcTmpName );
0 commit comments