1<?php
2/**
3 * DokuWiki Plugin shorturl (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Frank Schiebel <frank@linuxmuster.net>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15
16require_once(DOKU_PLUGIN.'syntax.php');
17require_once(dirname(__FILE__) . "/action.php");
18
19class syntax_plugin_shorturl extends DokuWiki_Syntax_Plugin {
20
21    function syntax_plugin_shorturl() { }
22
23    function getType() {
24        return 'substition';
25    }
26
27    function getPType() {
28        return 'block';
29    }
30
31    function getSort() {
32        return 302;
33    }
34
35    function connectTo($mode) {
36        $this->Lexer->addSpecialPattern('\~\~SHORTURL\~\~',$mode,'plugin_shorturl');
37    }
38
39    function handle($match, $state, $pos, &$handler){
40
41        $data['todo'] = "print";
42        return $data;
43    }
44
45    function render($mode, &$renderer, $data) {
46        global $ID;
47
48        if($mode != 'xhtml') return false;
49
50        if ( $data['todo'] == "print" ) {
51            $shorturl =& plugin_load('helper', 'shorturl');
52            if ($shorturl) {
53                $shortID = $shorturl->autoGenerateShortUrl($ID);
54                $renderer->doc .= "<a href=". wl($shortID, "", true) ." class=\"shortlinkinpage\" >" . $this->getLang('shortlinktext')  . "</a>\n";
55            }
56        }
57
58        return true;
59    }
60}
61
62// vim:ts=4:sw=4:et:enc=utf-8:
63