xref: /plugin/bez/action/base.php (revision 522c019c0bd8bcd6e522fddaa2cf94cce8e0780d)
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 loadConfig() {
14        global $conf;
15
16        if (! isset($conf['plugin']['bez']['url'])) {
17            include DOKU_PLUGIN . 'config/settings/config.class.php';
18            $datafile = DOKU_PLUGIN . 'config/settings/config.metadata.php';
19            $configuration = new configuration($datafile);
20            $configuration->setting['plugin____bez____url']->update(DOKU_URL);
21            $configuration->save_settings('config');
22            $conf['plugin']['bez']['url'] = DOKU_URL;
23        }
24        parent::loadConfig();
25    }
26
27
28    public function getPluginName() {
29        return 'bez';
30    }
31
32    public function register(Doku_Event_Handler $controller) {
33    }
34
35    public function getGlobalConf($key='') {
36        global $conf;
37        if ($key == '') {
38            return $conf;
39        }
40        return $conf[$key];
41    }
42
43    public function get_model() {
44        return $this->model;
45    }
46
47    public function get_client() {
48        global $INFO;
49        return $INFO['client'];
50    }
51
52    public function get_tpl() {
53        return $this->tpl;
54    }
55
56    public function get_level() {
57        return $this->model->get_level();
58    }
59
60    public function bez_tpl_include($tpl_file='', $return=false) {
61        $file = DOKU_PLUGIN . "bez/tpl/$tpl_file.php";
62        if (!file_exists($file)) {
63            throw new Exception("$file doesn't exist");
64        }
65
66        $tpl = $this->tpl;
67        if ($return) ob_start();
68        include $file;
69        if ($return) return ob_get_clean();
70
71    }
72
73    public function createObjects($skip_acl=false) {
74        global $auth;
75        global $INFO;
76
77        $this->model = new bez\mdl\Model($auth, $INFO['client'], $this, $skip_acl);
78        $this->tpl = new bez\meta\Tpl($this);
79    }
80
81    public function id() {
82        $args = func_get_args();
83
84        if (count($args) === 0) {
85            return $_GET['id'];
86        }
87
88        $elms = array();
89        foreach ($args as $arg) {
90            if (is_array($arg)) {
91                foreach ($arg as $k => $v) {
92                    $elms[] = $k;
93                    $elms[] = $v;
94                }
95            } else {
96                $elms[] = $arg;
97            }
98        }
99        array_unshift($elms, 'bez');
100
101
102        if ($this->getGlobalConf('lang') != '') {
103            array_unshift($elms, $this->getGlobalConf('lang'));
104        }
105
106        return implode(':', $elms);
107    }
108
109    public function url() {
110        $args = func_get_args();
111        if (count($args) > 0) {
112            $id = call_user_func_array(array($this, 'id'), $args);
113            return DOKU_URL . 'doku.php?id=' . $id;
114        } else {
115            //https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
116            return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
117        }
118    }
119}