xref: /plugin/bez/action/base.php (revision 3be16e0fcfd6542977ea03d1d93826140a52d61e)
1<?php
2
3use \dokuwiki\plugin\bez;
4
5class action_plugin_bez_base extends DokuWiki_Action_Plugin {
6
7    /** @var  bez\mdl\Model */
8    protected $model;
9
10    /** @var  bez\meta\Tpl */
11    protected $tpl;
12
13
14    public function getPluginName() {
15        return 'bez';
16    }
17
18    public function register(Doku_Event_Handler $controller) {
19    }
20
21    public function getGlobalConf($key='') {
22        global $conf;
23        if ($key == '') {
24            return $conf;
25        }
26        return $conf[$key];
27    }
28
29    public function get_model() {
30        return $this->model;
31    }
32
33    public function get_client() {
34        global $INFO;
35        return $INFO['client'];
36    }
37
38    public function get_tpl() {
39        return $this->tpl;
40    }
41
42    public function get_level() {
43        return $this->model->get_level();
44    }
45
46    public function bez_tpl_include($tpl_file='', $return=false) {
47        $file = DOKU_PLUGIN . "bez/tpl/$tpl_file.php";
48        if (!file_exists($file)) {
49            throw new Exception("$file doesn't exist");
50        }
51
52        $tpl = $this->tpl;
53        if ($return) ob_start();
54        include $file;
55        if ($return) return ob_get_clean();
56
57    }
58
59    public function createObjects() {
60        global $auth;
61        global $INFO;
62
63        $this->model = new bez\mdl\Model($auth, $INFO['client'], $this);
64        $this->tpl = new bez\meta\Tpl($this);
65    }
66
67    public function id() {
68        $args = func_get_args();
69
70        if (count($args) === 0) {
71            return $_GET['id'];
72        }
73
74        $elms = array();
75        foreach ($args as $arg) {
76            if (is_array($arg)) {
77                foreach ($arg as $k => $v) {
78                    $elms[] = $k;
79                    $elms[] = $v;
80                }
81            } else {
82                $elms[] = $arg;
83            }
84        }
85        array_unshift($elms, 'bez');
86
87
88        if ($this->getGlobalConf('lang') != '') {
89            array_unshift($elms, $this->getGlobalConf('lang'));
90        }
91
92        return implode(':', $elms);
93    }
94
95    public function url() {
96        $args = func_get_args();
97        if (count($args) > 0) {
98            $id = call_user_func_array(array($this, 'id'), $args);
99            return DOKU_URL . 'doku.php?id=' . $id;
100        }
101    }
102}