1<?php
2/**
3 * DokuWiki Plugin dwtimeline (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  saggi <saggi@gmx.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_dwtimeline extends DokuWiki_Action_Plugin {
13
14    /**
15     * Register the eventhandlers
16     */
17    public function register(Doku_Event_Handler $controller) {
18        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insert_button', array ());
19    }
20
21    /**
22     * Inserts the toolbar button
23     */
24    public function insert_button(Doku_Event $event, $param) {
25
26        $event->data[] = array (
27            'type' => 'picker',
28            'title' => $this->getLang('tl-picker'),
29            'icon' => '../../plugins/dwtimeline/icons/timeline_picker.png',
30            'list' => array(
31                array(
32                    'type' => 'format',
33                    'title' => $this->getLang('tl-button'),
34                    'icon' => '../../plugins/dwtimeline/icons/timeline_marker.png',
35                    'open' => $this->buildSkeleton('complete'),
36                    'sample' => $this->getLang('ms-content'),
37                    'close' => '\n</milestone>\n</dwtimeline title="'.$this->getLang('tl-end').'">',
38                ),
39                array(
40                    'type' => 'format',
41                    'title' => $this->getLang('ms-button'),
42                    'icon' => '../../plugins/dwtimeline/icons/page_white_code.png',
43                    'open' => $this->buildSkeleton('milestone'),
44                    'sample' => $this->getLang('ms-content'),
45                    'close' => '\n</milestone>',
46                ),
47            )
48        );
49    }
50
51    private function buildSkeleton($skeletontype) {
52        $skeleton = '';
53        switch ($skeletontype){
54            case 'complete' :
55                $skeleton = '<dwtimeline align="'.$this->getConf('align').'" title="'.$this->getLang('tl-title').'" description="'.$this->getLang('tl-desc').'">\n';
56                $skeleton .= '<milestone title="'.$this->getLang('ms-title').'" description="'.$this->getLang('ms-desc').'" ';
57                $skeleton .= 'data="'.$this->getLang('ms-data').'">\n'.$this->getLang('ms-content').'\n';
58                $skeleton .= '</milestone>\n';
59                $skeleton .= '<milestone title="'.$this->getLang('ms-title').'" description="'.$this->getLang('ms-desc').'" ';
60                $skeleton .= 'data="02">\n';
61                break;
62            case 'milestone' :
63                $skeleton = '<milestone title="'.$this->getLang('ms-title').'" description="'.$this->getLang('ms-desc').'" ';
64                $skeleton .= 'data="'.$this->getLang('ms-data').'" backcolor="'.$this->getLang('ms-backcolor').'">\n';
65                break;
66            default :
67                $skeleton = '<dwtimeline title="'.$this->getLang('tl-title').'" description="'.$this->getLang('tl-desc').'">\n';
68                $skeleton .= '<milestone title="'.$this->getLang('ms-title').'" description="'.$this->getLang('ms-desc').'" ';
69                $skeleton .= 'data="'.$this->getLang('ms-data').'">\n';
70                break;
71        }
72        return $skeleton;
73    }
74
75
76}
77
78