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 return implode(':', $elms); 105 } 106 107 public function url() { 108 global $conf; 109 110 $args = func_get_args(); 111 if (count($args) > 0) { 112 if (isset($args[count($args)-1]['GET'])) { 113 $get = array_pop($args)['GET']; 114 $get = http_build_query($get); 115 } 116 $id = call_user_func_array(array($this, 'id'), $args); 117 118 //fix farmer plugin bad DOKU_URL creation for host based setup 119 if('cli' == php_sapi_name() && isset($_SERVER['animal'])) { 120 $dokuUrl = rtrim($conf['baseurl'], '/').'/'; 121 } else { 122 $dokuUrl = DOKU_URL; 123 } 124 125 if ($conf['userewrite'] == '1') { 126 if ($get) $get = "?$get"; 127 return $dokuUrl . $id. $get; 128 } elseif ($conf['userewrite'] == '2') { 129 if ($get) $get = "?$get"; 130 return $dokuUrl . 'doku.php/' . $id . $get; 131 } else { 132 if ($get) $get = "&$get"; 133 return $dokuUrl . 'doku.php?id=' . $id . $get; 134 } 135 136 } 137 } 138}