1<?php 2 3namespace dokuwiki\plugin\bez\mdl; 4 5//ACL level defines 6define('BEZ_AUTH_NONE', 0); 7define('BEZ_AUTH_VIEWER', 2); 8define('BEZ_AUTH_USER', 5); 9define('BEZ_AUTH_LEADER', 10); 10define('BEZ_AUTH_ADMIN', 20); 11 12define('BEZ_PERMISSION_UNKNOWN', -1); 13define('BEZ_PERMISSION_NONE', 0); 14define('BEZ_PERMISSION_VIEW', 1); 15define('BEZ_PERMISSION_CHANGE', 2); 16define('BEZ_PERMISSION_DELETE', 3); 17 18 19class Model { 20 /** @var \helper_plugin_sqlite */ 21 protected $sqlite; 22 23 /** @var \SQLite3 */ 24 protected $db; 25 26 protected $level = BEZ_AUTH_NONE; 27 28 protected $dw_auth, $user_nick, $action, $conf; 29 30 /** @var ThreadFactory */ 31 protected $threadFactory; 32 33 /** @var UserFactory */ 34 protected $userFactory; 35 36 /** @var LabelFactory */ 37 protected $labelFactory; 38 39 /** @var Thread_commentFactory */ 40 protected $thread_commentFactory; 41 42 /** @var TaskFactory */ 43 protected $taskFactory; 44 45 /** @var Task_programFactory */ 46 protected $task_programFactory; 47 48 /** @var Task_commentFactory */ 49 protected $task_commentFactory; 50 51 /** @var Authentication_tokenFactory */ 52 protected $authentication_tokenFactory; 53 54 public function __get($property) { 55 $models = array('userFactory', 'threadFactory', 'labelFactory', 'thread_commentFactory', 'taskFactory', 'task_programFactory', 'task_commentFactory', 'authentication_tokenFactory'); 56 if (in_array($property, $models) || 57 in_array($property, array('sqlite', 'db', 'acl', 'dw_auth', 'user_nick', 'action', 'conf'))) { 58 return $this->$property; 59 } 60 } 61 62 public function factory($table) { 63 $prop = $table . 'Factory'; 64 65 return $this->$prop; 66 } 67 68 private function update_level($level) { 69 if ($level > $this->level) { 70 $this->level = $level; 71 } 72 } 73 74 public function get_level() { 75 return $this->level; 76 } 77 78 public function __construct($dw_auth, $user_nick, $action, $conf) { 79 $this->dw_auth = $dw_auth; 80 $this->user_nick = $user_nick; 81 $this->action = $action; 82 $this->conf = $conf; 83 84 $this->db_helper = plugin_load('helper', 'bez_db'); 85 86 $this->sqlite = $this->db_helper->getDB(); 87 $this->db = $this->sqlite->getAdapter()->getDb(); 88 $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); 89 90 //$this->acl = new Acl($this); 91 92 $this->userFactory = new UserFactory($this); 93 94 $this->threadFactory = new ThreadFactory($this); 95 96 $this->labelFactory = new LabelFactory($this); 97 98 $this->thread_commentFactory = new Thread_commentFactory($this); 99 100 $this->taskFactory = new TaskFactory($this); 101 102 $this->task_programFactory = new Task_programFactory($this); 103 104 $this->task_commentFactory = new Task_commentFactory($this); 105 106 $this->authentication_tokenFactory = new Authentication_tokenFactory($this); 107 108 $userd = $this->dw_auth->getUserData($this->user_nick); 109 if ($userd !== false && is_array($userd['grps'])) { 110 $grps = $userd['grps']; 111 if (in_array('admin', $grps ) || in_array('bez_admin', $grps )) { 112 $this->update_level(BEZ_AUTH_ADMIN); 113 } elseif (in_array('bez_leader', $grps )) { 114 $this->update_level(BEZ_AUTH_LEADER); 115 } else { 116 $this->update_level(BEZ_AUTH_USER); 117 } 118 } elseif (isset($_GET['t'])) { 119 $page_id = $this->action->id(); 120 121 $user_tok = trim($_GET['t']); 122 if ($this->authentication_tokenFactory->get_token($page_id) == $user_tok) { 123 $this->update_level(BEZ_AUTH_VIEWER); 124 } 125 } 126 } 127} 128