1<?php
2/**
3 * Plugin Ticket Linker: Automatic links to Cerberus tickets"
4 *
5 * @license    GNU General Public License (GPL)
6 * @author     Dominik Smatana <dominiks@users.sourceforge.net>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13class syntax_plugin_ticketlinker extends DokuWiki_Syntax_Plugin {
14
15    function getInfo(){
16        return array(
17            'author' => 'Dominik Smatana',
18            'email'  => 'dominiks@users.sourceforge.net',
19            'date'   => '2007-08-04',
20            'name'   => 'Ticket linker',
21            'desc'   => 'Automatic links to Cerberus tickets',
22            'url'    => 'https://sourceforge.net/projects/ticket-linker',
23        );
24    }
25
26    function getType(){
27        return 'substition';
28    }
29
30    function getSort(){
31        return 999;
32    }
33
34    function connectTo($mode) {
35      $this->Lexer->addSpecialPattern('ticket#.{'.$this->getConf('ticketMaskLength').'}', $mode, 'plugin_ticketlinker');
36    }
37
38    function handle($match, $state, $pos, &$handler){
39        switch ($state) {
40          case DOKU_LEXER_ENTER :
41            break;
42          case DOKU_LEXER_MATCHED :
43            break;
44          case DOKU_LEXER_UNMATCHED :
45            break;
46          case DOKU_LEXER_EXIT :
47            break;
48          case DOKU_LEXER_SPECIAL :
49			return array(0 => $match);
50            break;
51        }
52        return array();
53    }
54
55    function render($mode, &$renderer, $data) {
56        if($mode == 'xhtml'){
57			$ticketId = substr($data[0], -1 * $this->getConf('ticketMaskLength'));
58            $renderer->doc .= '<a href="'.$this->getConf('cerberusUrl').$ticketId.'" target="_blank" title="Ticket #'.$ticketId.'">#'.$ticketId.'</a>';
59            return true;
60        }
61        return false;
62    }
63
64}
65?>
66