1<?php
2/**
3 * DokuWiki Plugin sugar (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Damien Clocchard <damien@taadeem.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';
17
18class syntax_plugin_sugar extends DokuWiki_Syntax_Plugin {
19    function getType() {
20        return 'substition';
21    }
22
23    function getPType() {
24        return 'normal';
25    }
26
27    function getSort() {
28        return 156;
29    }
30
31
32    function connectTo($mode) {
33        $this->Lexer->addSpecialPattern('~~SugarOpportunity:[-0-9a-f]+~~', $mode, 'plugin_sugar');
34        $this->Lexer->addSpecialPattern('~~SugarAccount:[-0-9a-f]+~~', $mode, 'plugin_sugar');
35        $this->Lexer->addSpecialPattern('~~SugarContact:[-0-9a-f]+~~', $mode, 'plugin_sugar');
36    }
37
38    function handle($match, $state, $pos, Doku_Handler $handler){
39        $data = array();
40        // trim the ~~ characters
41        $match_clean = trim($match, "~");
42
43        // separate the command and id
44        list($command,$id) = explode(':', $match_clean);
45
46        // Build the url
47        $url = $this->getConf("sugar_base_url")."/index.php?action=DetailView";
48        $comment = "";
49        switch($command){
50                case "SugarOpportunity":
51                        $url.="&module=Opportunities&record=".$id;
52                        $comment="SugarCRM Opportunity # ".$id;
53                        break;
54                case "SugarAccount" :
55                        $url.="&module=Accounts&record=".$id;
56                        $comment="SugarCRM Account #".$id;
57                        break;
58
59                case "SugarContact" :
60                         $url.="&module=Contacts&record=".$id;
61                         $comment="SugarCRM Contact #".$id;
62                         break;
63
64
65        }
66
67        // url
68        $data[0] = $url;
69        // id
70        $data[1] = $comment;
71        return $data;
72    }
73
74    function render($mode, Doku_Renderer $renderer, $data) {
75        if ( $mode == 'xhtml' ) {
76		$renderer->externallink( $data[0],$data[1]);
77                return true;
78        }
79        return false;
80    }
81}
82
83// vim:ts=4:sw=4:et:enc=utf-8:
84