xref: /plugin/bez/action/base.php (revision 0071da6c300b62f7843210b526bf84f7fb764601)
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    public function getPluginName() {
14        return 'bez';
15    }
16
17    public function register(Doku_Event_Handler $controller) {
18    }
19
20    public function getGlobalConf($key='') {
21        global $conf;
22        if ($key == '') {
23            return $conf;
24        }
25        return $conf[$key];
26    }
27
28    public function get_model() {
29        return $this->model;
30    }
31
32    public function get_client() {
33        global $INFO;
34        return $INFO['client'];
35    }
36
37    public function get_tpl() {
38        return $this->tpl;
39    }
40
41    public function get_level() {
42        return $this->model->get_level();
43    }
44
45    public function bez_tpl_include($tpl_file='', $return=false) {
46        $file = DOKU_PLUGIN . "bez/tpl/$tpl_file.php";
47        if (!file_exists($file)) {
48            throw new Exception("$file doesn't exist");
49        }
50
51        $tpl = $this->tpl;
52        if ($return) ob_start();
53        include $file;
54        if ($return) return ob_get_clean();
55
56    }
57
58    public function createObjects($skip_acl=false) {
59        global $auth;
60        global $INFO;
61
62        if ($skip_acl) {
63            $client = false;
64        } else {
65            $client = $INFO['client'];
66        }
67
68        $this->model = new bez\mdl\Model($auth, $client, $this, $skip_acl);
69        $this->tpl = new bez\meta\Tpl($this);
70    }
71
72    public function id() {
73        $args = func_get_args();
74
75        if (count($args) === 0) {
76            return $_GET['id'];
77        }
78
79        $elms = array();
80        foreach ($args as $arg) {
81            if (is_array($arg)) {
82                foreach ($arg as $k => $v) {
83                    //replace special chars
84                    list($k, $v) = str_replace(array(':', '#'), '', array($k, $v));
85                    //don't create id with empty value
86                    if (empty($k) || empty($v)) {
87                        continue;
88                    }
89                    $elms[] = $k;
90                    $elms[] = $v;
91                }
92            } else {
93                $elms[] = $arg;
94            }
95        }
96        array_unshift($elms, 'bez');
97
98
99        //pl is default language
100        if ($this->getGlobalConf('lang') != '' && $this->getGlobalConf('lang') != 'pl') {
101            array_unshift($elms, $this->getGlobalConf('lang'));
102        }
103
104//        $elms = array_map(function ($elm) {
105//            return str_replace(array(':', '#'), '', $elm);
106//        }, $elms);
107        return implode(':', $elms);
108    }
109
110    public function url() {
111        global $conf;
112
113        $args = func_get_args();
114        if (count($args) > 0) {
115            $id = call_user_func_array(array($this, 'id'), $args);
116            if ($conf['userewrite'] == '1') {
117                return DOKU_URL . $id;
118            } elseif ($conf['userewrite'] == '2') {
119                return DOKU_URL . 'doku.php/' . $id;
120            } else {
121                return DOKU_URL . 'doku.php?id=' . $id;
122            }
123
124        }
125    }
126}