1<?php
2/**
3 * Plugin Visio: Insert a ActiveX object to view Visio diagrams.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Marc Hauswirth <marc@practeo.ch>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class syntax_plugin_visio extends DokuWiki_Syntax_Plugin {
20
21    function getInfo(){
22      return array(
23        'author' => 'Marc Hauswirth',
24        'email'  => 'marc@practeo.ch',
25        'date'   => '2007-12-05',
26        'name'   => 'visio',
27        'desc'   => 'Use the Microsoft ActiveX Visio Viewer to display visio diagrams \n simply put the file as
28                     {{my_visio_file.vsd[,width,height]|Alternate text}}',
29        'url'    => 'https://www.dokuwiki.org/plugin:visio',
30      );
31    }
32
33    function getType() { return 'substition'; }
34
35    function getSort() { return 10; }
36
37    function connectTo($mode) {
38        $this->Lexer->addSpecialPattern('{{[^}|]*\.vsd[^}]*}}',$mode,'plugin_visio');
39    }
40    function handle($match, $state, $pos, &$handler){
41        $data['full_data'] = $match;
42        $match = substr($match,2,-2);
43        list($filename,$alternate_text) = explode('|',$match);
44        $data['alternate_text'] = $alternate_text;
45
46        if (preg_match_all('/(.*),(.*),(.*)/',$filename,$matches))
47        {
48            $data['file'] = $matches[1][0];
49            $data['width'] = $matches[2][0];
50            $data['height'] = $matches[3][0];
51        }
52        else
53        {
54            $data['file'] = $filename;
55        }
56        return array($data, $state, $pos);
57
58    }
59    function render($mode, &$renderer, $data) {
60
61      if($mode == 'xhtml'){
62          $data = $data[0];
63
64          if (isset($data['width'])) { $width = $data['width']; } else { $width = $this->getConf('width');}
65          if (isset($data['height'])) { $height = $data['height']; } else { $height = $this->getConf('height');}
66
67
68          $renderer->doc .= '<OBJECT classid="'.$this->getConf('classid').'" ';
69          $renderer->doc .= 'codebase="'.$this->getConf('codebase').'" id="viewer1" width="'.$width.'" height="'.$height.'">'."\n";
70          $renderer->doc .= '  <param name="BackColor" value="16777200">'."\n";
71          $renderer->doc .= '  <param name="AlertsEnabled" value="1">'."\n";
72          $renderer->doc .= '  <param name="ContextMenuEnabled" value="1">'."\n";
73          $renderer->doc .= '  <param name="GridVisible" value="0">'."\n";
74          $renderer->doc .= '  <param name="HighQualityRender" value="0">'."\n";
75          $renderer->doc .= '  <param name="PageColor" value="16777215">'."\n";
76          $renderer->doc .= '  <param name="PageVisible" value="1">'."\n";
77          $renderer->doc .= '  <param name="PropertyDialogEnabled" value="1">'."\n";
78          $renderer->doc .= '  <param name="ScrollbarsVisible" value="1">'."\n";
79          $renderer->doc .= '  <param name="SizeGripVisible" value="1">'."\n";
80          $renderer->doc .= '  <param name="ToolbarVisible" value="1">'."\n";
81          $renderer->doc .= '  <param name="SRC" value="';
82          $renderer->doc .= DOKU_URL."lib/exe/fetch.php?id=".$data['file']."&cache=cache&media=".$data['file'];
83          $renderer->doc .= '">'."\n";
84          $renderer->doc .= '  <param name="CurrentPageIndex" value="0">'."\n";
85          $renderer->doc .= '  <param name="Zoom" value="-1">'."\n";
86          $renderer->doc .= '</object>'."\n";
87
88          $renderer->doc .= '<a href="'.DOKU_URL.'lib/exe/fetch.php?id='.$data['file'].'&cache=cache&media='.$data['file'].'" class="media mediafile mf_vsd" title="'.$data['file'].'">'.$data['file'].'</a><br/>';
89
90          return true;
91      }
92      return false;
93    }
94}