Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wiki links support #2

Open
glensc opened this issue Oct 3, 2010 · 2 comments · May be fixed by #5
Open

wiki links support #2

glensc opened this issue Oct 3, 2010 · 2 comments · May be fixed by #5

Comments

@glensc
Copy link

glensc commented Oct 3, 2010

would be nice to have imagemap support in images, like similiar trac plugin has:

http://trac-hacks.org/wiki/GraphvizPlugin

#!graphviz
  digraph G {
    rankdir = "LR"
    GraphvizPlugin [ URL=GraphvizPlugin ]
    Trac [ 
      URL="http://trac.edgewall.org/"   
      fontcolor=red
    ]
    GraphvizPlugin -> Trac
    }

idea is simple: you run graphviz with -Tcmap and include that in output

see the logic somewhere here:
http://trac-hacks.org/browser/graphvizplugin/0.11/graphviz/graphviz.py?rev=5995#L321

$ cat *.map
<area shape="rect" href="GraphvizPlugin" title="GraphvizPlugin" alt="" coords="7,6,159,54">
<area shape="rect" href="http://trac.edgewall.org/" title="Trac" alt="" coords="208,6,280,54">

and output html:

<map name="G3acf9129314733d74676902e3ed6c4ceec1d2c92" id="G3acf9129314733d74676902e3ed6c4ceec1d2c92">
<area shape="rect" href="GraphvizPlugin" title="GraphvizPlugin" alt="" coords="7,6,159,54">
<area shape="rect" href="http://trac.edgewall.org/" title="Trac" alt="" coords="208,6,280,54"></map>

<img src="3acf9129314733d74676902e3ed6c4ceec1d2c92.dot.png" alt="GraphViz image" usemap="#G3acf9129314733d74676902e3ed6c4ceec1d2c92"/>
@MichaelKling
Copy link

I wanted to have that future too but it looked like nobody took care about that issue in one year and i wanted to have it now :D

So i decided to modify the module a little bit. Its working fine but you have to put in total pathes, wiki links like [[wiki:testtest]] are not resolved and therewore dont work.

For patching the actual version from 2010-11-24 do this:

In the class syntax_plugin_graphviz in file syntax.php add the following 2 methods:

/**
     * Run the graphviz program to generate the map
     * @Author: Michael Kling
     */ 
    function _map($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 .= ' -Tcmap';
        $cmd .= ' -K'.$data['layout'];
        $cmd .= ' -o'.escapeshellarg($out); //output
        $cmd .= ' '.escapeshellarg($in); //input

        $result = exec($cmd, $output, $error);

        if ($error != 0){
            if($conf['debug']){
                dbglog(join("\n",$output),'graphviz command failed: '.$cmd);
            }
            return false;
        }   

        return true;

    }

/**
     * Return path to the rendered map on our local system
     * @Todo: Doesnt resize the map in case the image was resized
     * @Todo: Remotehandling on google isnt realized
     * @Author: Michael Kling
     */ 
    function _mapfile($data){

        $cache  = $this->_cachename($data,'map');

        // create the file if needed
        if(!file_exists($cache)){
            $in = $this->_cachename($data,'txt');
            if($this->getConf('path')){
                $ok = $this->_map($data,$in,$cache);
            }else{
                //Dont handle it remote at google cause i dont know how to do
            }
            if(!$ok) return false;
            clearstatcache();
        }

        // something went wrong, we're missing the file
        if(!file_exists($cache)) return false;

        return $cache;
    }   

In the class syntax_plugin_graphviz in file syntax.php the method render has to be changed like this:

    /**
     * Create output
     * Edited by Michael Kling for the MAP patch.
     * @todo ODT format doesnt support maps
     */
    function render($format, &$R, $data) {
        if($format == 'xhtml'){
            $img = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams($data);
            $mapcache  = $this->_mapfile($data);
            $map = io_readFile($mapcache,false);
            if ($mapcache !== false) {
              $R->doc .= '<map name="'.$data['md5'].'" id="'.$data['md5'].'">'.$map.'</map>'; 
            }
            $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"';
        if($mapcache !== false)  $R->doc .= ' usemap="#'.$data['md5'].'"';
            $R->doc .= '/>';
            return true;
        }elseif($format == 'odt'){
            $src = $this->_imgfile($data);
            $R->_odtAddImage($src,$data['width'],$data['height'],$data['align']);
            return true;
        }
        return false;
    }

Edit: Left some print_r's inside :P

@MichaelKling
Copy link

I implemented it in my repo and made a pull request in #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants