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