From 2ed0887221fc4216c936488de9f6ff205e173f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Wed, 24 Jun 2015 15:04:25 +0200 Subject: [PATCH 1/7] add svg and doku urls - display svg object with png fallback for xhtml - display png only for dw2pdf - use dokuwiki urls inside the graph Inactive[ URL="[[statuses#inactive KPI]]", ]; --- img.php | 10 +++++++- syntax.php | 71 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/img.php b/img.php index 3c7bc9c..407b350 100644 --- a/img.php +++ b/img.php @@ -13,8 +13,16 @@ $plugin = plugin_load('syntax','graphviz'); $cache = $plugin->_imgfile($data); if(!$cache) _fail(); +// Update: support both png and svg +$img_format = ($data['format'] == 'png' ? 'png' : 'svg'); +if ($img_format == 'svg'){ + header('Content-Type: image/svg+xml;'); +} +else +{ + header('Content-Type: image/png;'); +} -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'); diff --git a/syntax.php b/syntax.php index 518d027..34a99d4 100644 --- a/syntax.php +++ b/syntax.php @@ -8,8 +8,7 @@ */ -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); -if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +if (!defined('DOKU_INC')) define('DOKU_INC',realpath(DOKU_PLUGIN.'/../../').'/'); require_once(DOKU_PLUGIN.'syntax.php'); class syntax_plugin_graphviz extends DokuWiki_Syntax_Plugin { @@ -39,7 +38,8 @@ function getSort(){ * Connect pattern to lexer */ function connectTo($mode) { - $this->Lexer->addSpecialPattern('\n.*?\n',$mode,'plugin_graphviz'); + //Fix: removed newline requirements, as a accidental space before newline can break the pattern + $this->Lexer->addSpecialPattern('.*?',$mode,'plugin_graphviz'); } /** @@ -73,14 +73,38 @@ function handle($match, $state, $pos, &$handler) { } 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]; + + - + //Update: add dokulink support to URL tags (they can contain [[dokulink]] urls. $input = join("\n",$lines); - $return['md5'] = md5($input); // we only pass a hash around + $input = preg_replace_callback('~\b(|head|label|tail|edge)URL="\[\[(?:(\w+\://[^\]\|]*)|(?:(\w+)>([^\]\|]*))|([^\]\|#]+)?(#[^\]\|]*)?)(?:\|([^\]]*))?\]\]"~U',function($matches){ + global $ID; + $pref = @$matches[1]; // the prefix of the URL (i.e. "head" from "headURL") + $url = @$matches[2]; // external link (it's already url) + $int_t = @$matches[3]; // interwiki prefix (i.e. "wp" from "[[wp>blabla]]") + $int_u = @$matches[4]; // interwiki url (i.e. "blabla" from "[[wp>blabla]]") + $page = @$matches[5]; // dokuwiki internal page link + $frag = @$matches[6] ? '#'.preg_replace('~\W+~','-',strtolower(ltrim($matches[6],"#"))) : ""; // fragment for dokuwiki internal link, simple cleaning + $text = @$matches[7]; // text of link (i.e. "blabla" from "[[.:mylink:|blabla]]" + if ($page || $frag){ + resolve_pageid(getNS($ID),$page,$exists); + $url = wl($page).$frag; + } + elseif($int_t){ + static $xhtml_renderer = null; + if(is_null($xhtml_renderer)){ + $xhtml_renderer = p_get_renderer('xhtml'); + $xhtml_renderer->interwiki = getInterwiki(); + } + $url = $xhtml_renderer->_resolveInterWiki($int_t,$int_u,$exists); + } + return "{$pref}URL=\"{$url}\";{$pref}target=_top".($text ? ";{$pref}tooltip=\"{$text}\"" : ""); + },$input); + $return['md5'] = md5($input); // we only pass a hash around // store input for later use io_saveFile($this->_cachename($return,'txt'),$input); - return $return; } @@ -91,6 +115,7 @@ function _cachename($data,$ext){ unset($data['width']); unset($data['height']); unset($data['align']); + unset($data['format']); return getcachename(join('x',array_values($data)),'.graphviz.'.$ext); } @@ -99,18 +124,40 @@ function _cachename($data,$ext){ */ function render($format, &$R, $data) { if($format == 'xhtml'){ - $img = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams($data); - $R->doc .= ''svg'))); + $img_png = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'png'))); + // embed svg as object: the links in svg can be clicked (and also animations are supported) + $R->doc .= '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 .= '>'; + // embed fallback: if browser does not support svg bia object embed, it will display the png image instead. + $R->doc .= '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 .= '/>'; + + $R->doc .=''; return true; }elseif($format == 'odt'){ $src = $this->_imgfile($data); $R->_odtAddImage($src,$data['width'],$data['height'],$data['align']); return true; + }elseif($format == 'dw2pdf'){ + //Update: dw2pdf does not support svg, so return only png image. + $img = DOKU_BASE.'lib/plugins/graphviz/img.php?'.strtr('&','&',buildURLparams(array_merge($data,array('format'=>'png')))); + $R->doc .= '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; } return false; } @@ -119,7 +166,9 @@ function render($format, &$R, $data) { * Return path to the rendered image on our local system */ function _imgfile($data){ - $cache = $this->_cachename($data,'png'); + // Update: support pnd and svg format as well. + $format = ($data['format'] == 'png' ? 'png' : 'svg'); + $cache = $this->_cachename($data,$format); // create the file if needed if(!file_exists($cache)){ @@ -182,11 +231,11 @@ function _run($data,$in,$out) { } $cmd = $this->getConf('path'); - $cmd .= ' -Tpng'; + // Update: support both svg and png + $cmd .= ' -T'.($data['format'] == 'png' ? 'png' : 'svg'); $cmd .= ' -K'.$data['layout']; $cmd .= ' -o'.escapeshellarg($out); //output $cmd .= ' '.escapeshellarg($in); //input - exec($cmd, $output, $error); if ($error != 0){ From f8ff5ac64334035a9a8491a81b05f64ffd458164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Thu, 25 Jun 2015 09:40:26 +0200 Subject: [PATCH 2/7] broken svg added - display svg broken image for object embed. --- broken.svg | 23 +++++++++++++++++++++++ img.php | 21 ++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 broken.svg diff --git a/broken.svg b/broken.svg new file mode 100644 index 0000000..e3b6d97 --- /dev/null +++ b/broken.svg @@ -0,0 +1,23 @@ + + + + + + +broken + + +broke + +?? + + +broke->broke + + + + + diff --git a/img.php b/img.php index 407b350..b059107 100644 --- a/img.php +++ b/img.php @@ -12,15 +12,16 @@ $data = $_REQUEST; $plugin = plugin_load('syntax','graphviz'); $cache = $plugin->_imgfile($data); -if(!$cache) _fail(); +// Update: show svg or png depending on format. +if(!$cache) _fail($data['format']); // Update: support both png and svg $img_format = ($data['format'] == 'png' ? 'png' : 'svg'); if ($img_format == 'svg'){ - header('Content-Type: image/svg+xml;'); + header('Content-Type: image/svg+xml'); } else { - header('Content-Type: image/png;'); + header('Content-Type: image/png'); } header('Expires: '.gmdate("D, d M Y H:i:s", time()+max($conf['cachetime'], 3600)).' GMT'); @@ -30,10 +31,16 @@ 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); +function _fail($format){ + if ($format == 'svg'){ + header("HTTP/1.0 404 Not Found"); + header('Content-Type: image/svg+xml'); + echo io_readFile('broken.svg',false); + }else{ + header("HTTP/1.0 404 Not Found"); + header('Content-Type: image/png'); + echo io_readFile('broken.png',false); + } exit; } From 0289153fa732221fc635b844db7aff4e5af80e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Thu, 25 Jun 2015 10:25:05 +0200 Subject: [PATCH 3/7] add config for using svg --- conf/default.php | 1 + conf/metadata.php | 2 +- lang/en/settings.php | 1 + syntax.php | 96 ++++++++++++++++++++++++++++---------------- 4 files changed, 64 insertions(+), 36 deletions(-) diff --git a/conf/default.php b/conf/default.php index 76c8989..35e35f4 100644 --- a/conf/default.php +++ b/conf/default.php @@ -1,3 +1,4 @@ /usr/bin/dot). Leave empty to use remote rendering at google.com.'; +$lang['use_svg'] = 'Use embeded svg objects. Svg objects support clickable dokuwiki links in the graphs. This is automatically disabled if "path" is left empty.'; \ No newline at end of file diff --git a/syntax.php b/syntax.php index 34a99d4..849233d 100644 --- a/syntax.php +++ b/syntax.php @@ -13,6 +13,14 @@ class syntax_plugin_graphviz extends DokuWiki_Syntax_Plugin { + /** + * Constructor to check config + */ + function __construct(){ + // disable use_svg if 'path' is not set. + if(!$this->getConf('path')) $this->conf['use_svg'] = 0; + } + /** * What about paragraphs? */ @@ -78,36 +86,51 @@ function handle($match, $state, $pos, &$handler) { //Update: add dokulink support to URL tags (they can contain [[dokulink]] urls. $input = join("\n",$lines); - $input = preg_replace_callback('~\b(|head|label|tail|edge)URL="\[\[(?:(\w+\://[^\]\|]*)|(?:(\w+)>([^\]\|]*))|([^\]\|#]+)?(#[^\]\|]*)?)(?:\|([^\]]*))?\]\]"~U',function($matches){ - global $ID; - $pref = @$matches[1]; // the prefix of the URL (i.e. "head" from "headURL") - $url = @$matches[2]; // external link (it's already url) - $int_t = @$matches[3]; // interwiki prefix (i.e. "wp" from "[[wp>blabla]]") - $int_u = @$matches[4]; // interwiki url (i.e. "blabla" from "[[wp>blabla]]") - $page = @$matches[5]; // dokuwiki internal page link - $frag = @$matches[6] ? '#'.preg_replace('~\W+~','-',strtolower(ltrim($matches[6],"#"))) : ""; // fragment for dokuwiki internal link, simple cleaning - $text = @$matches[7]; // text of link (i.e. "blabla" from "[[.:mylink:|blabla]]" - if ($page || $frag){ - resolve_pageid(getNS($ID),$page,$exists); - $url = wl($page).$frag; - } - elseif($int_t){ - static $xhtml_renderer = null; - if(is_null($xhtml_renderer)){ - $xhtml_renderer = p_get_renderer('xhtml'); - $xhtml_renderer->interwiki = getInterwiki(); - } - $url = $xhtml_renderer->_resolveInterWiki($int_t,$int_u,$exists); - } - return "{$pref}URL=\"{$url}\";{$pref}target=_top".($text ? ";{$pref}tooltip=\"{$text}\"" : ""); - },$input); - + if ($this->getConf('use_svg')){ + $input = preg_replace_callback( + '~\b(|head|label|tail|edge)'. // match 0 -> prefix for URL + 'URL="\[\[(?:'. // alternative urls to catch + '(\w+\://[^\]\|]*)'. // simple url with any shema + '|(?:(\w+)>([^\]\|]*))'. // interwiki link + '|([^\]\|#]+)?(#[^\]\|]*)?)'. // dokuwiki link and/or fragment + '(?:\|([^\]]*))?'. // text + '\]\]"~U', + array(__CLASS__,'_parse_links'), + $input); + } $return['md5'] = md5($input); // we only pass a hash around // store input for later use io_saveFile($this->_cachename($return,'txt'),$input); return $return; } + /** + * callback function to preg_replace_callback, that fixes urls. + */ + public static function _parse_links($matches){ + global $ID; + $pref = @$matches[1]; // the prefix of the URL (i.e. "head" from "headURL") + $url = @$matches[2]; // external link (it's already url) + $int_t = @$matches[3]; // interwiki prefix (i.e. "wp" from "[[wp>blabla]]") + $int_u = @$matches[4]; // interwiki url (i.e. "blabla" from "[[wp>blabla]]") + $page = @$matches[5]; // dokuwiki internal page link + $frag = @$matches[6] ? '#'.preg_replace('~\W+~','-',strtolower(ltrim($matches[6],"#"))) : ""; // fragment for dokuwiki internal link, simple cleaning + $text = @$matches[7]; // text of link (i.e. "blabla" from "[[.:mylink:|blabla]]" + if ($page || $frag){ + resolve_pageid(getNS($ID),$page,$exists); + $url = wl($page).$frag; + } + elseif($int_t){ + static $xhtml_renderer = null; + if(is_null($xhtml_renderer)){ + $xhtml_renderer = p_get_renderer('xhtml'); + $xhtml_renderer->interwiki = getInterwiki(); + } + $url = $xhtml_renderer->_resolveInterWiki($int_t,$int_u,$exists); + } + return "{$pref}URL=\"{$url}\";{$pref}target=_top".($text ? ";{$pref}tooltip=\"{$text}\"" : ""); + } + /** * Cache file is based on parameters that influence the result image */ @@ -124,16 +147,18 @@ function _cachename($data,$ext){ */ function render($format, &$R, $data) { if($format == 'xhtml'){ - //Update: generate both png and svg, embed svg but with fallback to png. - $img_svg = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'svg'))); + if ($this->getConf('use_svg')){ + //Update: generate both png and svg, embed svg but with fallback to png. + $img_svg = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'svg'))); + // embed svg as object: the links in svg can be clicked (and also animations are supported) + $R->doc .= '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 .= '>'; + } $img_png = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'png'))); - // embed svg as object: the links in svg can be clicked (and also animations are supported) - $R->doc .= '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 .= '>'; // embed fallback: if browser does not support svg bia object embed, it will display the png image instead. $R->doc .= 'doc .= ' width="'.$data['width'].'"'; @@ -141,8 +166,9 @@ function render($format, &$R, $data) { if($data['align'] == 'right') $R->doc .= ' align="right"'; if($data['align'] == 'left') $R->doc .= ' align="left"'; $R->doc .= '/>'; - - $R->doc .=''; + if ($this->getConf('use_svg')){ + $R->doc .=''; + } return true; }elseif($format == 'odt'){ $src = $this->_imgfile($data); From 1495b01ba77172a4d5bfe77ed13674f587449bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Thu, 25 Jun 2015 10:39:37 +0200 Subject: [PATCH 4/7] add url to data if use_svg enabled - add hash of the current url to data only when use_svg is enabled: This ensures that the same image is recreated if the same code is placed to different pages, or the same page is opened from alternative urls -> the links in the svg object are always relative to it's place. --- syntax.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax.php b/syntax.php index 849233d..0f15ad7 100644 --- a/syntax.php +++ b/syntax.php @@ -55,7 +55,6 @@ function connectTo($mode) { */ function handle($match, $state, $pos, &$handler) { $info = $this->getInfo(); - // prepare default data $return = array( 'width' => 0, @@ -87,6 +86,8 @@ function handle($match, $state, $pos, &$handler) { //Update: add dokulink support to URL tags (they can contain [[dokulink]] urls. $input = join("\n",$lines); if ($this->getConf('use_svg')){ + global $ID; + $return['url'] = md5(wl($ID,true)); // add current page's url to 'data' to ensure exported links work on page $input = preg_replace_callback( '~\b(|head|label|tail|edge)'. // match 0 -> prefix for URL 'URL="\[\[(?:'. // alternative urls to catch From b8f385db5e7d1f6d1d5933dbab325a26532a615d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Thu, 25 Jun 2015 11:58:30 +0200 Subject: [PATCH 5/7] Feature: styles - config to set up styles - _parseStyles to parse styles into array - update syntax to accept styles in tag - _injectSytles to prepend styles into the graph body --- conf/default.php | 1 + conf/metadata.php | 1 + lang/en/settings.php | 4 +++- syntax.php | 52 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/conf/default.php b/conf/default.php index 35e35f4..114a181 100644 --- a/conf/default.php +++ b/conf/default.php @@ -2,3 +2,4 @@ $conf['path'] = ''; $conf['use_svg'] = 1; +$conf['styles'] = ''; diff --git a/conf/metadata.php b/conf/metadata.php index b1d13d8..d2ed31a 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -2,3 +2,4 @@ $meta['path'] = array('string'); $meta['use_svg'] = array('onoff'); +$meta['styles'] = array(''); // textarea diff --git a/lang/en/settings.php b/lang/en/settings.php index d0fa1de..15c515a 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -1,4 +1,6 @@ /usr/bin/dot). Leave empty to use remote rendering at google.com.'; -$lang['use_svg'] = 'Use embeded svg objects. Svg objects support clickable dokuwiki links in the graphs. This is automatically disabled if "path" is left empty.'; \ No newline at end of file +$lang['use_svg'] = 'Use embeded svg objects. Svg objects support clickable dokuwiki links in the graphs. This is automatically disabled if "path" is left empty.'; +$lang['styles'] = 'A block of DOT codes, that can be included to the graphs. Meant to include styling. To set a style put it inside <style name="stylename"> style code here lgt;/style>. The stylename can only contain alphanumeric and underscore characters.'. + 'E.g. '.htmlspecialchars('').''; diff --git a/syntax.php b/syntax.php index 0f15ad7..59218d1 100644 --- a/syntax.php +++ b/syntax.php @@ -13,12 +13,19 @@ class syntax_plugin_graphviz extends DokuWiki_Syntax_Plugin { + /** + * array holding defined styles. + */ + protected $_styles = array(); + + /** * Constructor to check config */ function __construct(){ // disable use_svg if 'path' is not set. if(!$this->getConf('path')) $this->conf['use_svg'] = 0; + $this->_parseStyles($s); } /** @@ -80,11 +87,23 @@ function handle($match, $state, $pos, &$handler) { } 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]; - - + + // Added code for styles. + $styles = array(); + // match stylenames that are written into the graphviz tag + if(preg_match_all('/\b(\w+)\b/i',$conf,$match)){ + foreach ($match[1] as $style){ + if (array_key_exists($tmp = strtolower($style),$this->_styles)){ + $styles[] = $tmp; + } + } + } + $styles = array_unique($styles); // remove duplicated styles + $input = join("\n",$lines); + $this->_injectStyles($input,$styles); + //Update: add dokulink support to URL tags (they can contain [[dokulink]] urls. - $input = join("\n",$lines); if ($this->getConf('use_svg')){ global $ID; $return['url'] = md5(wl($ID,true)); // add current page's url to 'data' to ensure exported links work on page @@ -274,6 +293,33 @@ function _run($data,$in,$out) { return true; } + /** + * parse styles form configuration + */ + function _parseStyles(){ + if (preg_match_all('~(.*)~U',$this->getConf('styles'),$matches,PREG_SET_ORDER)){ + foreach ($matches as $match){ + $this->_styles[strtolower($match[2])] = $match[3]; + } + } + } + + /** + * parse styles form configuration + */ + function _injectStyles(&$input,$styles){ + // if there are no styles or the beginning of the graph is not found, leave it as is + if (!empty($styles) && (($p = strpos($input,"{")) !== false)){ + $beg = substr($input,0,$p+1); // beginning, i.e. "digraph name{" + $rest = substr($input,$p+1); // the rest of the string + $input = $beg; + foreach ($styles as $style){ // add each matched style right after the beginning. + $input .= "\n".$this->_styles[$style]."\n"; + } + $input .= $rest; // the graph code itself. + } + } + } From 847d93cc454960b0f3c6c234d8e7e95ac4c11063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Mon, 29 Jun 2015 12:23:30 +0200 Subject: [PATCH 6/7] update syntax parser - use preg to separate tags from graph - fallback old behavior (first / last line are tags) if preg pattern fails. --- syntax.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/syntax.php b/syntax.php index 59218d1..c07ef1e 100644 --- a/syntax.php +++ b/syntax.php @@ -71,10 +71,17 @@ function handle($match, $state, $pos, &$handler) { 'version' => $info['date'], //force rebuild of images on update ); - // prepare input - $lines = explode("\n",$match); - $conf = array_shift($lines); - array_pop($lines); + // prepare input, UPDATE: separate tags from data by preg instead of first/last line, but leave the old behavior as fallback + if (preg_match('~]*)>((?:[\n]|.)*)~Ui',$match,$parts)){ + $input = $parts[2]; + $conf = $parts[1]; + } + else{ + $lines = explode("\n",$match); + $conf = array_shift($lines); + array_pop($lines); + $input = join("\n",$lines); + } // match config options if(preg_match('/\b(left|center|right)\b/i',$conf,$match)) $return['align'] = $match[1]; @@ -99,7 +106,6 @@ function handle($match, $state, $pos, &$handler) { } } $styles = array_unique($styles); // remove duplicated styles - $input = join("\n",$lines); $this->_injectStyles($input,$styles); From ed264924091735846d39b390488e0c755d8e182e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Fekete?= Date: Mon, 29 Jun 2015 12:29:07 +0200 Subject: [PATCH 7/7] fix: dw2pdf generation - fixed ways to distinguish dw2pdf and xhtml export (they both use 'xhtml' format) - auth update: dw2pdf fetches links by calling the url, which causes unauthorized failure for various auth plugins. Hence if dw2pdf is the renderer, create graph and put the filesystem path in src. --- syntax.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/syntax.php b/syntax.php index c07ef1e..1530f57 100644 --- a/syntax.php +++ b/syntax.php @@ -172,8 +172,8 @@ function _cachename($data,$ext){ * Create output */ function render($format, &$R, $data) { - if($format == 'xhtml'){ - if ($this->getConf('use_svg')){ + if($format == 'xhtml' || $format == 'dw2pdf'){ + if ($this->getConf('use_svg') && get_class($R) != 'renderer_plugin_dw2pdf'){ //Update: generate both png and svg, embed svg but with fallback to png. $img_svg = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'svg'))); // embed svg as object: the links in svg can be clicked (and also animations are supported) @@ -184,7 +184,13 @@ function render($format, &$R, $data) { if($data['align'] == 'left') $R->doc .= ' align="left"'; $R->doc .= '>'; } - $img_png = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'png'))); + if (get_class($R) == 'renderer_plugin_dw2pdf'){ + // for pdf export: mpdf fetches the url, and without authorization it is automatic fail. We need to set a file src as real path. + $cache = $this->_imgfile(array_merge($data,array('format'=>'png'))); + $img_png = $cache; + }else{ + $img_png = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams(array_merge($data,array('format'=>'png'))); + } // embed fallback: if browser does not support svg bia object embed, it will display the png image instead. $R->doc .= 'doc .= ' width="'.$data['width'].'"'; @@ -192,7 +198,7 @@ function render($format, &$R, $data) { if($data['align'] == 'right') $R->doc .= ' align="right"'; if($data['align'] == 'left') $R->doc .= ' align="left"'; $R->doc .= '/>'; - if ($this->getConf('use_svg')){ + if ($this->getConf('use_svg') && get_class($R) != 'renderer_plugin_dw2pdf'){ $R->doc .=''; } return true; @@ -200,16 +206,6 @@ function render($format, &$R, $data) { $src = $this->_imgfile($data); $R->_odtAddImage($src,$data['width'],$data['height'],$data['align']); return true; - }elseif($format == 'dw2pdf'){ - //Update: dw2pdf does not support svg, so return only png image. - $img = DOKU_BASE.'lib/plugins/graphviz/img.php?'.strtr('&','&',buildURLparams(array_merge($data,array('format'=>'png')))); - $R->doc .= '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; } return false; }