1<?php
2/**
3 * Plugin websvn: Deep-links to files in a WebSVN repository
4 *                      http://websvn.tigris.org/
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Stefan Hechenberger <foss@stefanix.net>
8 */
9
10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14
15
16//-----------------------------------CONFIGURE WEBSVN ROOT HERE---------
17global $websvn_root_url;
18$websvn_root_url = "http://svn.stefanix.net/";
19//----------------------------------------------------------------------
20
21
22
23/**
24 * All DokuWiki plugins to extend the parser/rendering mechanism
25 * need to inherit from this class
26 */
27class syntax_plugin_websvn extends DokuWiki_Syntax_Plugin {
28
29    /**
30     * return some info
31     */
32    function getInfo(){
33        return array(
34            'author' => 'Stefan Hechenberger',
35            'email'  => 'foss@stefanix.net',
36            'date'   => '2007-02-06',
37            'name'   => 'websvn Plugin',
38            'desc'   => 'Generates deep links to files in a WebSVN repository.',
39            'url'    => 'http://wiki.splitbrain.org/plugin:websvn',
40        );
41    }
42
43    /**
44     * What kind of syntax are we?
45     */
46    function getType(){
47        return 'substition';
48    }
49
50
51    /**
52     * Where to sort in?
53     */
54    function getSort(){
55        return 921;
56    }
57
58
59    /**
60     * Connect pattern to lexer
61     */
62    function connectTo($mode) {
63      $this->Lexer->addSpecialPattern('<websvn .*?>',$mode, substr(get_class($this), 7));
64    }
65
66
67    /**
68     * Handle the match
69     */
70    function handle($match, $state, $pos, &$handler){
71        $match = html_entity_decode(substr($match, 8, -1));
72        if(substr($match, -1, 1) == ' ') {
73            $iframe = 1;
74            $match = substr($match, 0, -1);
75        }else {
76            $iframe = 0;
77        }
78        list($repository, $reppath) = explode('/', $match, 2);
79        $reppath = '/'.$reppath;
80        $sourcefilename = substr(strrchr($reppath, "/"), 1);
81        $reppath = urlencode($reppath);
82        return array($repository, $reppath, $sourcefilename, $iframe);
83    }
84
85    /**
86     * Create output
87     */
88    function render($mode, &$renderer, $data) {
89        global $websvn_root_url;
90        list($repository, $reppath, $sourcefilename, $iframe) = $data;
91        $url = $websvn_root_url."filedetails.php?repname=$repository&path=$reppath";
92        if($mode == 'xhtml'){
93            if($iframe) {
94                $w = "100%";
95                $h = "400px";
96                $renderer->doc .= '<iframe title="'.$sourcefilename.'" src="'.$url.'" style="width:'.$w.'; height: '.$h.';">'.$sourcefilename.'</iframe>';
97            } else {
98                $renderer->doc .= "<a href=\"".$url."\">$sourcefilename</a>";
99            }
100            return true;
101        }
102        return false;
103    }
104}
105