stefan pushed a commit to branch master. http://git.enlightenment.org/website/www.git/commit/?id=2ab3e3f29293774a18940dd832d7e1042ad72b44
commit 2ab3e3f29293774a18940dd832d7e1042ad72b44 Author: Stefan Schmidt <ste...@osg.samsung.com> Date: Tue Nov 29 15:40:53 2016 +0100 www: plugins: install graphivz plugin for graphs in eo docs --- public_html/lib/plugins/graphviz/README | 25 +++ public_html/lib/plugins/graphviz/broken.png | Bin 0 -> 3085 bytes public_html/lib/plugins/graphviz/conf/default.php | 3 + public_html/lib/plugins/graphviz/conf/metadata.php | 4 + public_html/lib/plugins/graphviz/img.php | 32 ++++ .../lib/plugins/graphviz/lang/en/settings.php | 3 + .../lib/plugins/graphviz/lang/ko/settings.php | 8 + public_html/lib/plugins/graphviz/manager.dat | 3 + public_html/lib/plugins/graphviz/plugin.info.txt | 8 + public_html/lib/plugins/graphviz/syntax.php | 204 +++++++++++++++++++++ 10 files changed, 290 insertions(+) diff --git a/public_html/lib/plugins/graphviz/README b/public_html/lib/plugins/graphviz/README new file mode 100644 index 0000000..7eaebcd --- /dev/null +++ b/public_html/lib/plugins/graphviz/README @@ -0,0 +1,25 @@ +graphviz Plugin for DokuWiki + +All documentation for this plugin can be found at +http://www.dokuwiki.org/plugin:graphviz + +If you install this plugin manually, make sure it is installed in +lib/plugins/graphviz/ - if the folder is called different it +will not work! + +Please refer to http://www.dokuwiki.org/plugins for additional info +on how to install plugins in DokuWiki. + +---- +Copyright (C) Andreas Gohr <a...@splitbrain.org> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See the COPYING file in your DokuWiki folder for details diff --git a/public_html/lib/plugins/graphviz/broken.png b/public_html/lib/plugins/graphviz/broken.png new file mode 100644 index 0000000..657697c Binary files /dev/null and b/public_html/lib/plugins/graphviz/broken.png differ diff --git a/public_html/lib/plugins/graphviz/conf/default.php b/public_html/lib/plugins/graphviz/conf/default.php new file mode 100644 index 0000000..76c8989 --- /dev/null +++ b/public_html/lib/plugins/graphviz/conf/default.php @@ -0,0 +1,3 @@ +<?php + +$conf['path'] = ''; diff --git a/public_html/lib/plugins/graphviz/conf/metadata.php b/public_html/lib/plugins/graphviz/conf/metadata.php new file mode 100644 index 0000000..11aefb6 --- /dev/null +++ b/public_html/lib/plugins/graphviz/conf/metadata.php @@ -0,0 +1,4 @@ +<?php + +$meta['path'] = array('string'); + diff --git a/public_html/lib/plugins/graphviz/img.php b/public_html/lib/plugins/graphviz/img.php new file mode 100644 index 0000000..3c7bc9c --- /dev/null +++ b/public_html/lib/plugins/graphviz/img.php @@ -0,0 +1,32 @@ +<?php +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <a...@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','graphviz'); +$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 : diff --git a/public_html/lib/plugins/graphviz/lang/en/settings.php b/public_html/lib/plugins/graphviz/lang/en/settings.php new file mode 100644 index 0000000..69bf6b0 --- /dev/null +++ b/public_html/lib/plugins/graphviz/lang/en/settings.php @@ -0,0 +1,3 @@ +<?php + +$lang['path'] = 'The path to your local graphviz dot binary (eg. <code>/usr/bin/dot</code>). Leave empty to use remote rendering at google.com.'; diff --git a/public_html/lib/plugins/graphviz/lang/ko/settings.php b/public_html/lib/plugins/graphviz/lang/ko/settings.php new file mode 100644 index 0000000..b5eb4f0 --- /dev/null +++ b/public_html/lib/plugins/graphviz/lang/ko/settings.php @@ -0,0 +1,8 @@ +<?php +/** + * Korean language file + * + * @author Myeongjin <aranet...@gmail.com> + */ + +$lang['path'] = '로컬 graphviz dot 바이너리로의 경로 (예를 들어 <code>/usr/bin/dot</code>). google.com에서 원격 렌더하기를 사용하려면 비워 두세요.'; diff --git a/public_html/lib/plugins/graphviz/manager.dat b/public_html/lib/plugins/graphviz/manager.dat new file mode 100644 index 0000000..04e3d7c --- /dev/null +++ b/public_html/lib/plugins/graphviz/manager.dat @@ -0,0 +1,3 @@ +downloadurl=https://github.com/splitbrain/dokuwiki-plugin-graphviz/zipball/master +installed=Thu, 12 May 2016 07:01:44 +0000 +updated=Wed, 03 Aug 2016 13:39:53 +0000 diff --git a/public_html/lib/plugins/graphviz/plugin.info.txt b/public_html/lib/plugins/graphviz/plugin.info.txt new file mode 100644 index 0000000..98bafb5 --- /dev/null +++ b/public_html/lib/plugins/graphviz/plugin.info.txt @@ -0,0 +1,8 @@ +base graphviz +author Andreas Gohr +email a...@splitbrain.org +date 2016-02-03 +name Graphviz Plugin +desc Create graph images from Graphviz dot language +url http://www.dokuwiki.org/plugin:graphviz + diff --git a/public_html/lib/plugins/graphviz/syntax.php b/public_html/lib/plugins/graphviz/syntax.php new file mode 100644 index 0000000..bf9a137 --- /dev/null +++ b/public_html/lib/plugins/graphviz/syntax.php @@ -0,0 +1,204 @@ +<?php +/** + * graphviz-Plugin: Parses graphviz-blocks + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Carl-Christian Salvesen <ca...@ioslo.net> + * @author Andreas Gohr <a...@splitbrain.org> + */ + + +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_graphviz extends DokuWiki_Syntax_Plugin { + + /** + * What about paragraphs? + */ + function getPType(){ + return 'normal'; + } + + /** + * What kind of syntax are we? + */ + function getType(){ + return 'substition'; + } + + /** + * Where to sort in? + */ + function getSort(){ + return 200; + } + + /** + * Connect pattern to lexer + */ + function connectTo($mode) { + $this->Lexer->addSpecialPattern('<graphviz.*?>\n.*?\n</graphviz>',$mode,'plugin_graphviz'); + } + + /** + * Handle the match + */ + function handle($match, $state, $pos, Doku_Handler $handler) { + $info = $this->getInfo(); + + // prepare default data + $return = array( + 'width' => 0, + 'height' => 0, + 'layout' => 'dot', + 'align' => '', + 'version' => $info['date'], //force rebuild of images on update + ); + + // prepare input + $lines = explode("\n",$match); + $conf = array_shift($lines); + array_pop($lines); + + // match config options + if(preg_match('/\b(left|center|right)\b/i',$conf,$match)) $return['align'] = $match[1]; + if(preg_match('/\b(\d+)x(\d+)\b/',$conf,$match)){ + $return['width'] = $match[1]; + $return['height'] = $match[2]; + } + if(preg_match('/\b(dot|neato|twopi|circo|fdp)\b/i',$conf,$match)){ + $return['layout'] = strtolower($match[1]); + } + if(preg_match('/\bwidth=([0-9]+)\b/i', $conf,$match)) $return['width'] = $match[1]; + if(preg_match('/\bheight=([0-9]+)\b/i', $conf,$match)) $return['height'] = $match[1]; + + + $input = join("\n",$lines); + $return['md5'] = md5($input); // we only pass a hash around + + // store input for later use + io_saveFile($this->_cachename($return,'txt'),$input); + + return $return; + } + + /** + * 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)),'.graphviz.'.$ext); + } + + /** + * Create output + */ + function render($format, Doku_Renderer $R, $data) { + if($format == 'xhtml'){ + $img = DOKU_BASE.'lib/plugins/graphviz/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') $R->doc .= ' align="right"'; + if($data['align'] == 'left') $R->doc .= ' 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; + } + + /** + * Return path to the rendered image on our local system + */ + 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('path')){ + $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 google + */ + function _remote($data,$in,$out){ + if(!file_exists($in)){ + if($conf['debug']){ + dbglog($in,'no such graphviz input file'); + } + return false; + } + + $http = new DokuHTTPClient(); + $http->timeout=30; + + $pass = array(); + $pass['cht'] = 'gv:'.$data['layout']; + $pass['chl'] = io_readFile($in); + + $img = $http->post('http://chart.apis.google.com/chart',$pass,'&'); + if(!$img) return false; + + return io_saveFile($out,$img); + } + + /** + * Run the graphviz program + */ + function _run($data,$in,$out) { + global $conf; + + if(!file_exists($in)){ + if($conf['debug']){ + dbglog($in,'no such graphviz input file'); + } + return false; + } + + $cmd = $this->getConf('path'); + $cmd .= ' -Tpng'; + $cmd .= ' -K'.$data['layout']; + $cmd .= ' -o'.escapeshellarg($out); //output + $cmd .= ' '.escapeshellarg($in); //input + + exec($cmd, $output, $error); + + if ($error != 0){ + if($conf['debug']){ + dbglog(join("\n",$output),'graphviz command failed: '.$cmd); + } + return false; + } + return true; + } + +} + + + --