1<?php 2 3namespace dokuwiki\plugin\bez\meta; 4 5class Tpl { 6 7 /** @var \action_plugin_bez */ 8 private $action; 9 10 private $conf; 11 12 private $variables = array(); 13 14 //form values from $_POST or from database 15 private $values = array(); 16 17 public function __construct(\action_plugin_bez_default $action, $conf) { 18 19 $this->action = $action; 20 $this->conf = $conf; 21 22 //constas 23 $this->set('client', $this->model->user_nick); 24 25 $info = $action->getInfo(); 26 $this->set('version', $info['date']); 27 28 //common one 29 $this->set('users', $this->action->get_model()->userFactory->get_all()); 30 $this->set('groups', $this->action->get_model()->userFactory->get_groups()); 31 } 32 33 public function action($default=null) { 34 $action = $this->action->get_action(); 35 if ($action == '' && !is_null($default)) { 36 return $default; 37 } 38 return $action; 39 } 40 41 public function param($id, $default='') { 42 return $this->action->get_param($id, $default); 43 } 44 45 public function url() { 46 return call_user_func_array(array($this->action, 'url'), func_get_args()); 47 } 48 49 public function mailto($to, $subject, $body) { 50 return 'mailto:'.$to.'?subject='.rawurlencode($subject).'&body='.rawurlencode($body); 51 } 52 53// public function get_dummy_of($name) { 54// return $this->action->get_model_of($name)->get_dummy_object(); 55// } 56 57 public function static_acl($table, $field) { 58 return $this->action->get_model()->acl->check_static_field($table, $field); 59 } 60 61 /*users info function for shorten the code*/ 62 public function user_name($login=NULL) { 63 $name = $this->action->get_model()->userFactory->get_user_full_name($login); 64 if ($name === '') { 65 return $login; 66 } 67 return $name; 68 } 69 70 public function user_email($login=NULL) { 71 return $this->action->get_model()->userFactory->get_user_email($login); 72 } 73 /*end users info functions*/ 74 75 public function prevent_rendering() { 76 77 } 78 79 public function set($id, $value) { 80 $this->variables[$id] = $value; 81 } 82 83 public function get($id, $default='') { 84 $arr = explode(' ', $id); 85 $var = $this->variables; 86 foreach($arr as $item) { 87 if (isset($var[$item])) { 88 $var = $var[$item]; 89 } else { 90 return $default; 91 } 92 } 93 return $var; 94 } 95 96 public function set_values($values) { 97 foreach ($values as $name => $value) { 98 $this->values[$name] = $value; 99 } 100 } 101 102 public function value($name) { 103 return (isset($this->values[$name]) ? $this->values[$name] : ''); 104 } 105 106 public function getLang($id) { 107 return $this->action->getLang($id); 108 } 109 110 /** 111 * @return mixed 112 */ 113 public function current_user() { 114 return $this->action->get_model()->user_nick; 115 } 116 117 public function user_acl_level() { 118 return $this->action->get_model()->acl->get_level(); 119 } 120 121 public function date($date) { 122 return dformat(strtotime($date), '%Y-%m-%d'); 123 } 124 125 public function datetime($datetime) { 126 return dformat(strtotime($datetime), '%Y-%m-%d %H:%M'); 127 } 128 129 public function date_fuzzy_age($datetime) { 130 return datetime_h(strtotime($datetime)); 131 } 132 133 public function date_diff_days($rDate, $lDate='now', $format='%R%a') { 134 $interval = date_diff(date_create($lDate), date_create($rDate)); 135 return $interval->format("$format ".$this->getLang('days')); 136 } 137 138 public function date_diff_hours($rDate, $lDate='now') { 139 $interval = date_diff(date_create($lDate), date_create($rDate)); 140 return $interval->format('%h:%I'); 141 } 142 143// public function days($lDate, $rDate='now') { 144// $diff = strtotime($lDate) - strtotime($rDate); 145// 146// if ($diff >= 0 && $diff < 5) { 147// return $this->getLang('just_now'); 148// } 149// 150// $time_str = ''; 151// $minutes = floor($diff/60); 152// if ($minutes > 0) { 153// $hours = floor($minutes/60); 154// if ($hours > 0) { 155// $days = floor($hours/24); 156// if ($days > 0) { 157// $time_str = $days.' '.$this->getLang('days'); 158// } else { 159// $time_str = $hours.' '.$this->getLang('hours'); 160// } 161// } else { 162// $time_str = $minutes.' '.$this->getLang('minutes'); 163// } 164// } else { 165// $time_str = $diff.' '.$this->getLang('seconds'); 166// } 167// 168// if ($diff > 0) { 169// $time_str .= ' '.$this->getLang('ago'); 170// } 171// 172// return $time_str; 173// } 174// 175// public function days_left($date) { 176// $d = date_create($date); 177// $now = date_create('now'); 178// $interval = date_diff($now, $d); 179// return $interval->format('%R%a '.$this->getLang('days')); 180// } 181 182// public function string_time_to_now($value) { 183// $diff = time() - $value; 184// if ($diff < 5) { 185// return $this->getLang('just_now'); 186// } 187// return self::days($diff).' '.$this->getLang('ago'); 188// } 189} 190