Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

streamlined code with graphviz plugin

ODT export should work now
  • Loading branch information...
commit 95615d6c9d0f4f656d9f64521d7ea9c14a40d45e 1 parent 05cbae8
Andreas Gohr authored
Showing with 92 additions and 76 deletions.
  1. +0 −57 ditaa.php
  2. +32 −0 img.php
  3. +1 −1  plugin.info.txt
  4. +59 −18 syntax.php
57 ditaa.php
View
@@ -1,57 +0,0 @@
-<?php
-/**
- * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
- * @author Andreas Gohr <gohr@cosmocode.de>
- */
-
-if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../');
-define('NOSESSION',true);
-require_once(DOKU_INC.'inc/init.php');
-require_once(DOKU_INC.'inc/pageutils.php');
-require_once(DOKU_INC.'inc/httputils.php');
-require_once(DOKU_INC.'inc/io.php');
-
-$data = $_REQUEST;
-$w = (int) $data['width'];
-$h = (int) $data['height'];
-unset($data['width']);
-unset($data['height']);
-unset($data['align']);
-
-$plugin = plugin_load('syntax','ditaa');
-$cache = $plugin->_cachename($data,'png');
-
-// create the file if needed
-if(!file_exists($cache)){
- $in = $plugin->_cachename($data,'txt');
- if($plugin->getConf('java')){
- $ok = $plugin->_run($data,$in,$cache);
- }else{
- $ok = $plugin->_remote($data,$in,$cache);
- }
- if(!$ok) _fail();
- clearstatcache();
-}
-
-// resized version
-if($w) $cache = media_resize_image($cache,'png',$w,$h);
-
-// something went wrong, we're missing the file
-if(!file_exists($cache)) _fail();
-
-header('Content-Type: image/png;');
-header('Expires: '.gmdate("D, d M Y H:i:s", time()+max($conf['cachetime'], 3600)).' GMT');
-header('Cache-Control: public, proxy-revalidate, no-transform, max-age='.max($conf['cachetime'], 3600));
-header('Pragma: public');
-http_conditionalRequest($time);
-echo io_readFile($cache,false);
-
-
-function _fail(){
- header("HTTP/1.0 404 Not Found");
- header('Content-Type: image/png');
- echo io_readFile('broken.png',false);
- exit;
-}
-
-//Setup VIM: ex: et ts=4 enc=utf-8 :
32 img.php
View
@@ -0,0 +1,32 @@
+<?php
+/**
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+
+if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../');
+define('NOSESSION',true);
+require_once(DOKU_INC.'inc/init.php');
+
+// let the syntax plugin do the work
+$data = $_REQUEST;
+$plugin = plugin_load('syntax','ditaa');
+$cache = $plugin->_imgfile($data);
+if(!$cache) _fail();
+
+header('Content-Type: image/png;');
+header('Expires: '.gmdate("D, d M Y H:i:s", time()+max($conf['cachetime'], 3600)).' GMT');
+header('Cache-Control: public, proxy-revalidate, no-transform, max-age='.max($conf['cachetime'], 3600));
+header('Pragma: public');
+http_conditionalRequest($time);
+echo io_readFile($cache,false);
+
+
+function _fail(){
+ header("HTTP/1.0 404 Not Found");
+ header('Content-Type: image/png');
+ echo io_readFile('broken.png',false);
+ exit;
+}
+
+//Setup VIM: ex: et ts=4 enc=utf-8 :
2  plugin.info.txt
View
@@ -1,7 +1,7 @@
base ditaa
author Andreas Gohr
email andi@splitbrain.org
-date 2010-08-29
+date 2010-11-15
name Ditaa-Plugin (ditaa 0.9)
desc Renders ASCII flowcharts contained in a DokuWiki page to images
url http://www.dokuwiki.org/plugin:ditaa
77 syntax.php
View
@@ -94,34 +94,77 @@ function handle($match, $state, $pos, &$handler) {
}
/**
+ * Cache file is based on parameters that influence the result image
+ */
+ function _cachename($data,$ext){
+ unset($data['width']);
+ unset($data['height']);
+ unset($data['align']);
+ return getcachename(join('x',array_values($data)),'.ditaa.'.$ext);
+ }
+
+ /**
* Create output
*/
function render($format, &$R, $data) {
- if($format != 'xhtml') return;
- $img = DOKU_BASE.'lib/plugins/ditaa/ditaa.php?'.buildURLparams($data,'&');
-
- $R->doc .= '<img src="'.$img.'" class="media'.$data['align'].'" alt=""';
- if($data['width']) $R->doc .= ' width="'.$data['width'].'"';
- if($data['height']) $R->doc .= ' height="'.$data['height'].'"';
- if($data['align'] == 'right') $ret .= ' align="right"';
- if($data['align'] == 'left') $ret .= ' align="left"';
- $R->doc .= '/>';
+ if($format == 'xhtml'){
+ $img = DOKU_BASE.'lib/plugins/ditaa/img.php?'.buildURLparams($data);
+ $R->doc .= '<img src="'.$img.'" class="media'.$data['align'].'" alt=""';
+ if($data['width']) $R->doc .= ' width="'.$data['width'].'"';
+ if($data['height']) $R->doc .= ' height="'.$data['height'].'"';
+ if($data['align'] == 'right') $ret .= ' align="right"';
+ if($data['align'] == 'left') $ret .= ' align="left"';
+ $R->doc .= '/>';
+ return true;
+ }elseif($format == 'odt'){
+ $src = $this->_imgfile($data);
+ $R->_odtAddImage($src,$data['width'],$data['height'],$data['align']);
+ return true;
+ }
+ return false;
}
+
/**
- * Cache file is based on data
+ * Return path to the rendered image on our local system
*/
- function _cachename($data,$ext){
- unset($data['width']);
- unset($data['height']);
- unset($data['align']);
- return getcachename(join('x',array_values($data)),'.ditaa.'.$ext);
+ function _imgfile($data){
+ $cache = $this->_cachename($data,'png');
+
+ // create the file if needed
+ if(!file_exists($cache)){
+ $in = $this->_cachename($data,'txt');
+ if($this->getConf('java')){
+ $ok = $this->_run($data,$in,$cache);
+ }else{
+ $ok = $this->_remote($data,$in,$cache);
+ }
+ if(!$ok) return false;
+ clearstatcache();
+ }
+
+ // resized version
+ if($data['width']){
+ $cache = media_resize_image($cache,'png',$data['width'],$data['height']);
+ }
+
+ // something went wrong, we're missing the file
+ if(!file_exists($cache)) return false;
+
+ return $cache;
}
/**
* Render the output remotely at ditaa.org
*/
function _remote($data,$in,$out){
+ if(!file_exists($in)){
+ if($conf['debug']){
+ dbglog($in,'no such ditaa input file');
+ }
+ return false;
+ }
+
$http = new DokuHTTPClient();
$http->timeout=30;
@@ -137,11 +180,9 @@ function _remote($data,$in,$out){
$img = $http->post('http://ditaa.org/ditaa/render',$pass);
if(!$img) return false;
- io_saveFile($out,$img);
- return true;
+ return io_saveFile($out,$img);
}
-
/**
* Run the ditaa Java program
*/
Please sign in to comment.
Something went wrong with that request. Please try again.