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, $data = null) {
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 .= $this->buildSkeleton('milestone');
57                $skeleton .= '</milestone>\n';
58                $skeleton .= $this->buildSkeleton('milestone', '02');
59                break;
60            case 'milestone' :
61                if (!$data) {$data = $this->getLang('ms-data');}
62                $skeleton = '<milestone title = "' . $this->getLang('ms-title') . '" description="' . $this->getLang('ms-desc') . '" ';
63                $skeleton .= 'data="' . $data . '" backcolor="' . $this->getLang('ms-backcolor') . '">\n';
64                break;
65            default :
66                $skeleton = '<dwtimeline title="' . $this->getLang('tl-title') . '" description="' . $this->getLang('tl-desc') . '">\n';
67                $skeleton .= $this->buildSkeleton('milestone');
68                break;
69        }
70        return $skeleton;
71    }
72
73
74}
75
76