1
<?php
2
/**
3
 * ODT Plugin: Exports to ODT
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Andreas Gohr <andi@splitbrain.org>
7
 * @author     Aurelien Bompard <aurelien@bompard.org>
8
 */
9
// must be run within Dokuwiki
10
if(!defined('DOKU_INC')) die();
11
12
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13
require_once(DOKU_PLUGIN.'syntax.php');
14
15
class syntax_plugin_odt extends DokuWiki_Syntax_Plugin {
16
17
    /**
18
     * return some info
19
     */
20
    function getInfo(){
21
        return confToHash(dirname(__FILE__).'/info.txt');
22
    }
23
24
    /**
25
     * What kind of syntax are we?
26
     */
27
    function getType(){
28
        return 'substition';
29
    }
30
31
    /**
32
     * What about paragraphs?
33
     */
34
    function getPType(){
35
        return 'normal';
36
    }
37
38
    /**
39
     * Where to sort in?
40
     */
41
    function getSort(){
42
        return 319; // Before image detection, which uses {{...}} and is 320
43
    }
44
45
    /**
46
     * Connect pattern to lexer
47
     */
48
    function connectTo($mode) {
49
        $this->Lexer->addSpecialPattern('~~ODT~~',$mode,'plugin_odt');
50
        $this->Lexer->addSpecialPattern('{{odt>.+?}}',$mode,'plugin_odt');
51
    }
52
53
    /**
54
     * Handle the match
55
     */
56
    function handle($match, $state, $pos, &$handler){
57
        // Export button
58
        if ($match == '~~ODT~~') { return array(); }
59
        // Extended info
60
        $match = substr($match,6,-2); //strip markup
61
        $extinfo = explode(':',$match);
62
        $info_type = $extinfo[0];
63
        if (count($extinfo) < 2) { // no value
64
            $info_value = '';
65
        } elseif (count($extinfo) == 2) {
66
            $info_value = $extinfo[1];
67
        } else { // value may contain colons
68
            $info_value = implode(array_slice($extinfo,1), ':');
69
        }
70
        return array($info_type, $info_value);
71
    }
72
73
    /**
74
     * Create output
75
     */
76
    function render($format, &$renderer, $data) {
77
        global $ID, $REV;
78
        if (!$data) { // Export button
79
            if($format != 'xhtml') return false;
80
            $renderer->doc .= '<a href="'.exportlink($ID, 'odt', ($REV != '' ? 'rev='.$REV : '')).'" title="'.$this->getLang('view').'">';
81
            $renderer->doc .= '<img src="'.DOKU_BASE.'lib/plugins/odt/odt.png" align="right" alt="'.$this->getLang('view').'" width="48" height="48" />';
82
            $renderer->doc .= '</a>';
83
            return true;
84
        } else { // Extended info
85
            list($info_type, $info_value) = $data;
86
            if ($info_type == "template") { // Template-based export
87
                $renderer->template = $info_value;
88
                p_set_metadata($ID, array("relation"=> array("odt"=>array("template"=>$info_value))));
89
            }
90
        }
91
        return false;
92
    }
93
94
}
95
96
// vim: set et ts=4 sw=4 fileencoding=utf-8 :