1<?php
2/**
3 * DokuWiki Plugin sapnotelink (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Florian Lamml <info@florian-lamml.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12class syntax_plugin_sapnotelink extends DokuWiki_Syntax_Plugin {
13
14    public function getType() {
15        return 'substition';
16    }
17
18    public function getPType() {
19        return 'normal';
20    }
21
22    public function getSort() {
23        return 256;
24    }
25
26	# responds to everything starts with SAP# or sap# followed by  1 - 10 numbers
27    public function connectTo($mode) {
28	    $this->Lexer->addSpecialPattern('SAP#[0-9]{1,10}',$mode,'plugin_sapnotelink');
29		$this->Lexer->addSpecialPattern('sap#[0-9]{1,10}',$mode,'plugin_sapnotelink');
30    }
31
32    public function handle($match, $state, $pos, Doku_Handler $handler){
33        $data = array($match, $state);
34
35        return $data;
36    }
37
38	public function render($mode, Doku_Renderer $renderer, $data) {
39		# Dokuwiki Renderer
40        if($mode == 'xhtml'){
41            $sapnote = explode('#', $data[0]);
42            $url = $this->getConf('sapnoteurl')."/".$sapnote[1];
43                $renderer->doc .= "<a href=\"".$url."\" target=\"_blank\"><img src=\"".DOKU_BASE."lib/plugins/sapnotelink/images/sap.gif\" alt=\"".$this->getLang('url_alt')." ".$sapnote[1]."\"> ".$sapnote[1]."</a>";
44            return true;
45        }
46		# ODT Export Renderer
47		elseif ($mode == 'odt'){
48			if (!class_exists('ODTDocument')) {
49				// support of "old" dokuwiki-plugin-odt
50				$sapnote = explode('#', $data[0]);
51                $renderer->doc .= "$sapnote[1]";
52				return true;
53			} else {
54				// support of redesign dokuwiki-plugin-odt
55				$sapnote = explode('#', $data[0]);
56                $renderer->cdata ("$sapnote[1]");
57				return true;
58			}
59        }
60        return false;
61    }
62}
63