@@ -27,27 +27,27 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Mail implements Validator_Base { |
29 | 29 | |
30 | - protected static $instance = null; |
|
30 | + protected static $instance = null; |
|
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
|
34 | - } |
|
32 | + public function isValide ($value): bool { |
|
33 | + return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
|
34 | + } |
|
35 | 35 | |
36 | - public function validate ($value) : string { |
|
37 | - if (!$this->isValide($value)) { |
|
38 | - throw new SecurityException("given mail '" . htmlentities($value) . "' isnt a valide mail."); |
|
39 | - } |
|
36 | + public function validate ($value) : string { |
|
37 | + if (!$this->isValide($value)) { |
|
38 | + throw new SecurityException("given mail '" . htmlentities($value) . "' isnt a valide mail."); |
|
39 | + } |
|
40 | 40 | |
41 | - return filter_var($value, FILTER_VALIDATE_EMAIL); |
|
42 | - } |
|
41 | + return filter_var($value, FILTER_VALIDATE_EMAIL); |
|
42 | + } |
|
43 | 43 | |
44 | - public static function get (string $value) : string { |
|
45 | - if (self::$instance == null) { |
|
46 | - self::$instance = new Validator_Mail(); |
|
47 | - } |
|
44 | + public static function get (string $value) : string { |
|
45 | + if (self::$instance == null) { |
|
46 | + self::$instance = new Validator_Mail(); |
|
47 | + } |
|
48 | 48 | |
49 | - return self::$instance->validate($value); |
|
50 | - } |
|
49 | + return self::$instance->validate($value); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | } |
53 | 53 |
@@ -27,24 +27,24 @@ |
||
27 | 27 | |
28 | 28 | class Validator_AlphaNumeric implements Validator_Base { |
29 | 29 | |
30 | - protected static $instance = null; |
|
30 | + protected static $instance = null; |
|
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - return ctype_alnum($value); |
|
34 | - } |
|
32 | + public function isValide ($value): bool { |
|
33 | + return ctype_alnum($value); |
|
34 | + } |
|
35 | 35 | |
36 | - public function validate ($value) : string { |
|
37 | - //remove all characters except except a-z, A-Z and 0-9 |
|
38 | - return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
|
39 | - } |
|
36 | + public function validate ($value) : string { |
|
37 | + //remove all characters except except a-z, A-Z and 0-9 |
|
38 | + return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
|
39 | + } |
|
40 | 40 | |
41 | - public static function get (string $value) : string { |
|
42 | - if (self::$instance == null) { |
|
43 | - self::$instance = new Validator_AlphaNumeric(); |
|
44 | - } |
|
41 | + public static function get (string $value) : string { |
|
42 | + if (self::$instance == null) { |
|
43 | + self::$instance = new Validator_AlphaNumeric(); |
|
44 | + } |
|
45 | 45 | |
46 | - return self::$instance->validate($value); |
|
47 | - } |
|
46 | + return self::$instance->validate($value); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
50 | 50 |
@@ -27,109 +27,109 @@ |
||
27 | 27 | |
28 | 28 | class Browser { |
29 | 29 | |
30 | - //cached values |
|
31 | - protected static $isMobile = false; |
|
32 | - protected static $mobile_checked = false; |
|
33 | - protected static $isTablet = false; |
|
34 | - protected static $tablet_checked = false; |
|
30 | + //cached values |
|
31 | + protected static $isMobile = false; |
|
32 | + protected static $mobile_checked = false; |
|
33 | + protected static $isTablet = false; |
|
34 | + protected static $tablet_checked = false; |
|
35 | 35 | |
36 | - //https://github.com/serbanghita/Mobile-Detect/blob/master/Mobile_Detect.php |
|
36 | + //https://github.com/serbanghita/Mobile-Detect/blob/master/Mobile_Detect.php |
|
37 | 37 | |
38 | - /** |
|
39 | - * check, if browser is mobile |
|
40 | - * |
|
41 | - * @return true, if browser is mobile |
|
42 | - */ |
|
43 | - public static function isMobile () : bool { |
|
44 | - //in-memory cache |
|
45 | - if (self::$mobile_checked) { |
|
46 | - return self::$isMobile; |
|
47 | - } |
|
38 | + /** |
|
39 | + * check, if browser is mobile |
|
40 | + * |
|
41 | + * @return true, if browser is mobile |
|
42 | + */ |
|
43 | + public static function isMobile () : bool { |
|
44 | + //in-memory cache |
|
45 | + if (self::$mobile_checked) { |
|
46 | + return self::$isMobile; |
|
47 | + } |
|
48 | 48 | |
49 | - //customized from: https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device |
|
50 | - //https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device |
|
51 | - $value = preg_match("/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", self::getUserAgent()); |
|
49 | + //customized from: https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device |
|
50 | + //https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device |
|
51 | + $value = preg_match("/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", self::getUserAgent()); |
|
52 | 52 | |
53 | - //cache values (in local in-memory cache) |
|
54 | - self::$isMobile = $value; |
|
55 | - self::$mobile_checked = true; |
|
53 | + //cache values (in local in-memory cache) |
|
54 | + self::$isMobile = $value; |
|
55 | + self::$mobile_checked = true; |
|
56 | 56 | |
57 | - return $value; |
|
58 | - } |
|
57 | + return $value; |
|
58 | + } |
|
59 | 59 | |
60 | - public static function isMobilePhone () : bool { |
|
61 | - throw new Exception("method Browser::isMobilePhone() isnt implemented yet."); |
|
60 | + public static function isMobilePhone () : bool { |
|
61 | + throw new Exception("method Browser::isMobilePhone() isnt implemented yet."); |
|
62 | 62 | |
63 | - //TODO: add code here |
|
64 | - } |
|
63 | + //TODO: add code here |
|
64 | + } |
|
65 | 65 | |
66 | - public static function isTablet () : bool { |
|
67 | - //in-memory cache |
|
68 | - if (self::$tablet_checked) { |
|
69 | - return self::$isTablet; |
|
70 | - } |
|
66 | + public static function isTablet () : bool { |
|
67 | + //in-memory cache |
|
68 | + if (self::$tablet_checked) { |
|
69 | + return self::$isTablet; |
|
70 | + } |
|
71 | 71 | |
72 | - //https://www.phpclasses.org/browse/file/48225.html |
|
73 | - //https://mobiforge.com/design-development/tablet-and-mobile-device-detection-php |
|
72 | + //https://www.phpclasses.org/browse/file/48225.html |
|
73 | + //https://mobiforge.com/design-development/tablet-and-mobile-device-detection-php |
|
74 | 74 | |
75 | - //TODO: ATTENTION! Rewrite this method so it will result into better performance! |
|
75 | + //TODO: ATTENTION! Rewrite this method so it will result into better performance! |
|
76 | 76 | |
77 | - $user_agent = self::getUserAgent(); |
|
77 | + $user_agent = self::getUserAgent(); |
|
78 | 78 | |
79 | - $tablet_browser = 0; |
|
79 | + $tablet_browser = 0; |
|
80 | 80 | |
81 | - if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($user_agent))) { |
|
82 | - $tablet_browser++; |
|
83 | - } |
|
81 | + if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($user_agent))) { |
|
82 | + $tablet_browser++; |
|
83 | + } |
|
84 | 84 | |
85 | - if (strpos(strtolower($user_agent),'opera mini') > 0) { |
|
86 | - //Check for tablets on opera mini alternative headers |
|
87 | - $stock_ua = strtolower(isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) ? $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'] : (isset($_SERVER['HTTP_DEVICE_STOCK_UA'])?$_SERVER['HTTP_DEVICE_STOCK_UA']:'')); |
|
85 | + if (strpos(strtolower($user_agent),'opera mini') > 0) { |
|
86 | + //Check for tablets on opera mini alternative headers |
|
87 | + $stock_ua = strtolower(isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) ? $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'] : (isset($_SERVER['HTTP_DEVICE_STOCK_UA'])?$_SERVER['HTTP_DEVICE_STOCK_UA']:'')); |
|
88 | 88 | |
89 | - if (preg_match('/(tablet|ipad|playbook)|(android(?!.*mobile))/i', $stock_ua)) { |
|
90 | - $tablet_browser++; |
|
91 | - } |
|
92 | - } |
|
89 | + if (preg_match('/(tablet|ipad|playbook)|(android(?!.*mobile))/i', $stock_ua)) { |
|
90 | + $tablet_browser++; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - $value = $tablet_browser > 0; |
|
94 | + $value = $tablet_browser > 0; |
|
95 | 95 | |
96 | - //cache values (in local in-memory cache) |
|
97 | - self::$isTablet = $value; |
|
98 | - self::$tablet_checked = true; |
|
96 | + //cache values (in local in-memory cache) |
|
97 | + self::$isTablet = $value; |
|
98 | + self::$tablet_checked = true; |
|
99 | 99 | |
100 | - return $value; |
|
101 | - } |
|
100 | + return $value; |
|
101 | + } |
|
102 | 102 | |
103 | - public static function isAppleiOS () : bool { |
|
104 | - $user_agent = self::getUserAgent(); |
|
103 | + public static function isAppleiOS () : bool { |
|
104 | + $user_agent = self::getUserAgent(); |
|
105 | 105 | |
106 | - $iPod = stripos($user_agent,"iPod"); |
|
107 | - $iPhone = stripos($user_agent,"iPhone"); |
|
108 | - $iPad = stripos($user_agent,"iPad"); |
|
109 | - //$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android"); |
|
110 | - //$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS"); |
|
106 | + $iPod = stripos($user_agent,"iPod"); |
|
107 | + $iPhone = stripos($user_agent,"iPhone"); |
|
108 | + $iPad = stripos($user_agent,"iPad"); |
|
109 | + //$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android"); |
|
110 | + //$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS"); |
|
111 | 111 | |
112 | - return $iPod !== false || $iPhone !== false || $iPad !== false; |
|
113 | - } |
|
112 | + return $iPod !== false || $iPhone !== false || $iPad !== false; |
|
113 | + } |
|
114 | 114 | |
115 | - public static function isAndroid () : bool { |
|
116 | - return stripos(self::getUserAgent(),'android') !== false; |
|
117 | - } |
|
115 | + public static function isAndroid () : bool { |
|
116 | + return stripos(self::getUserAgent(),'android') !== false; |
|
117 | + } |
|
118 | 118 | |
119 | - public static function getUserAgent () : string { |
|
120 | - $user_agent = ""; |
|
119 | + public static function getUserAgent () : string { |
|
120 | + $user_agent = ""; |
|
121 | 121 | |
122 | - if (isset($_SERVER['HTTP_USER_AGENT'])) { |
|
123 | - $user_agent = strtolower(htmlentities($_SERVER['HTTP_USER_AGENT'])); |
|
124 | - } |
|
122 | + if (isset($_SERVER['HTTP_USER_AGENT'])) { |
|
123 | + $user_agent = strtolower(htmlentities($_SERVER['HTTP_USER_AGENT'])); |
|
124 | + } |
|
125 | 125 | |
126 | - //throw event, so plugins can modify user agent |
|
127 | - Events::throwEvent("get_user_agent", array( |
|
128 | - 'user_agent' => &$user_agent, |
|
129 | - )); |
|
126 | + //throw event, so plugins can modify user agent |
|
127 | + Events::throwEvent("get_user_agent", array( |
|
128 | + 'user_agent' => &$user_agent, |
|
129 | + )); |
|
130 | 130 | |
131 | - return $user_agent; |
|
132 | - } |
|
131 | + return $user_agent; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | } |
135 | 135 |
@@ -27,128 +27,128 @@ |
||
27 | 27 | |
28 | 28 | class Groups { |
29 | 29 | |
30 | - protected $my_groups = array(); |
|
30 | + protected $my_groups = array(); |
|
31 | 31 | |
32 | - public function __construct() { |
|
33 | - // |
|
34 | - } |
|
32 | + public function __construct() { |
|
33 | + // |
|
34 | + } |
|
35 | 35 | |
36 | - public function loadMyGroups (int $userID) { |
|
37 | - if (Cache::contains("groups", "own-groups-" . $userID)) { |
|
38 | - $this->my_groups = Cache::get("groups", "own-groups-" . $userID); |
|
39 | - } else { |
|
40 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}group_members` LEFT JOIN `{praefix}groups` ON `{praefix}group_members`.`groupID` = `{praefix}groups`.`groupID` WHERE `{praefix}group_members`.`userID` = :userID AND `{praefix}group_members`.`activated` = '1'; ", array( |
|
41 | - 'userID' => array( |
|
42 | - 'type' => PDO::PARAM_INT, |
|
43 | - 'value' => $userID |
|
44 | - ) |
|
45 | - )); |
|
36 | + public function loadMyGroups (int $userID) { |
|
37 | + if (Cache::contains("groups", "own-groups-" . $userID)) { |
|
38 | + $this->my_groups = Cache::get("groups", "own-groups-" . $userID); |
|
39 | + } else { |
|
40 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}group_members` LEFT JOIN `{praefix}groups` ON `{praefix}group_members`.`groupID` = `{praefix}groups`.`groupID` WHERE `{praefix}group_members`.`userID` = :userID AND `{praefix}group_members`.`activated` = '1'; ", array( |
|
41 | + 'userID' => array( |
|
42 | + 'type' => PDO::PARAM_INT, |
|
43 | + 'value' => $userID |
|
44 | + ) |
|
45 | + )); |
|
46 | 46 | |
47 | - $this->my_groups = $rows; |
|
47 | + $this->my_groups = $rows; |
|
48 | 48 | |
49 | - //cache rows |
|
50 | - Cache::put("groups", "own-groups-" . $userID, $this->my_groups); |
|
51 | - } |
|
52 | - } |
|
49 | + //cache rows |
|
50 | + Cache::put("groups", "own-groups-" . $userID, $this->my_groups); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - public function listGroupIDs () : array { |
|
55 | - $array = array(); |
|
54 | + public function listGroupIDs () : array { |
|
55 | + $array = array(); |
|
56 | 56 | |
57 | - foreach ($this->my_groups as $group_row) { |
|
58 | - $array[] = $group_row['groupID']; |
|
59 | - } |
|
57 | + foreach ($this->my_groups as $group_row) { |
|
58 | + $array[] = $group_row['groupID']; |
|
59 | + } |
|
60 | 60 | |
61 | - return $array; |
|
62 | - } |
|
61 | + return $array; |
|
62 | + } |
|
63 | 63 | |
64 | - public function listMyGroups () : array { |
|
65 | - $array = array(); |
|
64 | + public function listMyGroups () : array { |
|
65 | + $array = array(); |
|
66 | 66 | |
67 | - foreach ($this->my_groups as $row) { |
|
68 | - $group = new Group(); |
|
69 | - $group->loadByRow($row); |
|
67 | + foreach ($this->my_groups as $row) { |
|
68 | + $group = new Group(); |
|
69 | + $group->loadByRow($row); |
|
70 | 70 | |
71 | - $array[] = $group; |
|
72 | - } |
|
71 | + $array[] = $group; |
|
72 | + } |
|
73 | 73 | |
74 | - return $array; |
|
75 | - } |
|
74 | + return $array; |
|
75 | + } |
|
76 | 76 | |
77 | - public static function createGroupIfIdAbsent (int $groupID, string $name, string $description, string $color = "#000000", bool $show = true, bool $system_group = false, bool $auto_assign_regist = false) { |
|
78 | - //check, if color is valide |
|
79 | - $validator = new Validator_Color(); |
|
77 | + public static function createGroupIfIdAbsent (int $groupID, string $name, string $description, string $color = "#000000", bool $show = true, bool $system_group = false, bool $auto_assign_regist = false) { |
|
78 | + //check, if color is valide |
|
79 | + $validator = new Validator_Color(); |
|
80 | 80 | |
81 | - if (!$validator->isValide($color)) { |
|
82 | - throw new IllegalArgumentException("color '" . $color . "' isnt a valide hex color."); |
|
83 | - } |
|
81 | + if (!$validator->isValide($color)) { |
|
82 | + throw new IllegalArgumentException("color '" . $color . "' isnt a valide hex color."); |
|
83 | + } |
|
84 | 84 | |
85 | - Database::getInstance()->execute("INSERT INTO `{praefix}groups` ( |
|
85 | + Database::getInstance()->execute("INSERT INTO `{praefix}groups` ( |
|
86 | 86 | `groupID`, `name`, `description`, `color`, `auto_assign_regist`, `system_group`, `show`, `activated` |
87 | 87 | ) VALUES ( |
88 | 88 | :groupID, :name, :description, :color, :auto_assign_regist, :system_group, :show, '1' |
89 | 89 | ) ON DUPLICATE KEY UPDATE `groupID` = :groupID; ", array( |
90 | - 'groupID' => $groupID, |
|
91 | - 'name' => Validator_String::get($name), |
|
92 | - 'description' => Validator_String::get($description), |
|
93 | - 'color' => $color, |
|
94 | - 'auto_assign_regist' => ($auto_assign_regist ? 1 : 0), |
|
95 | - 'system_group' => ($system_group ? 1 : 0), |
|
96 | - 'show' => ($show ? 1 : 0) |
|
97 | - )); |
|
98 | - |
|
99 | - //clear complete cache for all groups, so membership cache is also cleared |
|
100 | - Cache::clear("groups"); |
|
101 | - } |
|
102 | - |
|
103 | - public static function deleteGroup (int $groupID) { |
|
104 | - $group = new Group(); |
|
105 | - |
|
106 | - try { |
|
107 | - $group->loadById($groupID); |
|
108 | - } catch (IllegalStateException $e) { |
|
109 | - //group doesnt exists, we dont have to do anything |
|
110 | - return; |
|
111 | - } |
|
112 | - |
|
113 | - $group->delete(); |
|
114 | - } |
|
115 | - |
|
116 | - public static function addGroupToUser (int $groupID, int $userID, bool $group_leader = false) { |
|
117 | - Database::getInstance()->execute("INSERT INTO `{praefix}group_members` ( |
|
90 | + 'groupID' => $groupID, |
|
91 | + 'name' => Validator_String::get($name), |
|
92 | + 'description' => Validator_String::get($description), |
|
93 | + 'color' => $color, |
|
94 | + 'auto_assign_regist' => ($auto_assign_regist ? 1 : 0), |
|
95 | + 'system_group' => ($system_group ? 1 : 0), |
|
96 | + 'show' => ($show ? 1 : 0) |
|
97 | + )); |
|
98 | + |
|
99 | + //clear complete cache for all groups, so membership cache is also cleared |
|
100 | + Cache::clear("groups"); |
|
101 | + } |
|
102 | + |
|
103 | + public static function deleteGroup (int $groupID) { |
|
104 | + $group = new Group(); |
|
105 | + |
|
106 | + try { |
|
107 | + $group->loadById($groupID); |
|
108 | + } catch (IllegalStateException $e) { |
|
109 | + //group doesnt exists, we dont have to do anything |
|
110 | + return; |
|
111 | + } |
|
112 | + |
|
113 | + $group->delete(); |
|
114 | + } |
|
115 | + |
|
116 | + public static function addGroupToUser (int $groupID, int $userID, bool $group_leader = false) { |
|
117 | + Database::getInstance()->execute("INSERT INTO `{praefix}group_members` ( |
|
118 | 118 | `groupID`, `userID`, `group_leader`, `activated` |
119 | 119 | ) VALUES ( |
120 | 120 | :groupID, :userID, :group_leader, '1' |
121 | 121 | ) ON DUPLICATE KEY UPDATE `group_leader` = :group_leader; ", array( |
122 | - 'groupID' => array( |
|
123 | - 'type' => PDO::PARAM_INT, |
|
124 | - 'value' => $groupID |
|
125 | - ), |
|
126 | - 'userID' => array( |
|
127 | - 'type' => PDO::PARAM_INT, |
|
128 | - 'value' => $userID |
|
129 | - ), |
|
130 | - 'group_leader' => ($group_leader ? 1 : 0) |
|
131 | - )); |
|
132 | - |
|
133 | - //clear cache |
|
134 | - Cache::clear("groups", "own-groups-" . $userID); |
|
135 | - } |
|
136 | - |
|
137 | - public static function removeGroupFromUser (int $groupID, int $userID) { |
|
138 | - Database::getInstance()->execute("DELETE FROM `{praefix}group_members` WHERE `groupID` = :groupID AND `userID` = :userID; ", array( |
|
139 | - 'groupID' => array( |
|
140 | - 'type' => PDO::PARAM_INT, |
|
141 | - 'value' => $groupID |
|
142 | - ), |
|
143 | - 'userID' => array( |
|
144 | - 'type' => PDO::PARAM_INT, |
|
145 | - 'value' => $userID |
|
146 | - ) |
|
147 | - )); |
|
148 | - |
|
149 | - //clear cache |
|
150 | - Cache::clear("groups", "own-groups-" . $userID); |
|
151 | - } |
|
122 | + 'groupID' => array( |
|
123 | + 'type' => PDO::PARAM_INT, |
|
124 | + 'value' => $groupID |
|
125 | + ), |
|
126 | + 'userID' => array( |
|
127 | + 'type' => PDO::PARAM_INT, |
|
128 | + 'value' => $userID |
|
129 | + ), |
|
130 | + 'group_leader' => ($group_leader ? 1 : 0) |
|
131 | + )); |
|
132 | + |
|
133 | + //clear cache |
|
134 | + Cache::clear("groups", "own-groups-" . $userID); |
|
135 | + } |
|
136 | + |
|
137 | + public static function removeGroupFromUser (int $groupID, int $userID) { |
|
138 | + Database::getInstance()->execute("DELETE FROM `{praefix}group_members` WHERE `groupID` = :groupID AND `userID` = :userID; ", array( |
|
139 | + 'groupID' => array( |
|
140 | + 'type' => PDO::PARAM_INT, |
|
141 | + 'value' => $groupID |
|
142 | + ), |
|
143 | + 'userID' => array( |
|
144 | + 'type' => PDO::PARAM_INT, |
|
145 | + 'value' => $userID |
|
146 | + ) |
|
147 | + )); |
|
148 | + |
|
149 | + //clear cache |
|
150 | + Cache::clear("groups", "own-groups-" . $userID); |
|
151 | + } |
|
152 | 152 | |
153 | 153 | } |
154 | 154 |
@@ -27,212 +27,212 @@ |
||
27 | 27 | |
28 | 28 | class Group { |
29 | 29 | |
30 | - protected $groupID = -1; |
|
31 | - protected $row = null; |
|
32 | - |
|
33 | - public function __construct() { |
|
34 | - // |
|
35 | - } |
|
36 | - |
|
37 | - public function loadById (int $groupID) { |
|
38 | - if (Cache::contains("groups", "group-" . $groupID)) { |
|
39 | - $this->row = Cache::get("groups", "group-" . $groupID); |
|
40 | - } else { |
|
41 | - $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}groups` WHERE `groupID` = :groupID AND `acivated` = '1'; ", array( |
|
42 | - 'groupID' => array( |
|
43 | - 'type' => PDO::PARAM_INT, |
|
44 | - 'value' => $groupID |
|
45 | - ) |
|
46 | - )); |
|
47 | - |
|
48 | - if (!$row) { |
|
49 | - throw new IllegalStateException("Group with groupID " . $groupID . " doesnt exists."); |
|
50 | - } |
|
51 | - |
|
52 | - $this->row = $row; |
|
53 | - $this->groupID = $row['groupID']; |
|
54 | - |
|
55 | - //cache database row |
|
56 | - Cache::put("groups", "group-" . $groupID, $row); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - public function loadByRow (array $row) { |
|
61 | - $this->row = $row; |
|
62 | - $this->groupID = $row['groupID']; |
|
63 | - } |
|
64 | - |
|
65 | - public function update (string $name, string $description, string $color, bool $auto_assign_regist = false) { |
|
66 | - //throw event |
|
67 | - Events::throwEvent("before_update_group", array( |
|
68 | - 'groupID' => $this->groupID, |
|
69 | - 'old_row' => $this->row, |
|
70 | - 'name' => &$name, |
|
71 | - 'description' => &$description, |
|
72 | - 'color' => &$color, |
|
73 | - 'auto_assign_regist' => &$auto_assign_regist |
|
74 | - )); |
|
75 | - |
|
76 | - Database::getInstance()->execute("UPDATE `{praefix}groups` SET `name` = :name, `description` = :description, `color` = :color, `auto_assign_regist` = :auto_assign_regist WHERE `groupID` = :groupID; ", array( |
|
77 | - 'name' => $name, |
|
78 | - 'description' => $description, |
|
79 | - 'color' => $color, |
|
80 | - 'auto_assign_regist' => ($auto_assign_regist ? 1 : 0), |
|
81 | - 'groupID' => array( |
|
82 | - 'type' => PDO::PARAM_INT, |
|
83 | - 'value' => $this->groupID |
|
84 | - ) |
|
85 | - )); |
|
86 | - |
|
87 | - //throw event |
|
88 | - Events::throwEvent("after_update_group", array( |
|
89 | - 'groupID' => $this->groupID, |
|
90 | - 'old_row' => $this->row, |
|
91 | - )); |
|
92 | - |
|
93 | - //update row in-memory |
|
94 | - $this->row['name'] = $name; |
|
95 | - $this->row['description'] = $description; |
|
96 | - $this->row['color'] = $color; |
|
97 | - $this->row['auto_assign_regist'] = ($auto_assign_regist ? 1 : 0); |
|
98 | - |
|
99 | - //clear cache |
|
100 | - Cache::clear("groups", "group-" . $this->groupID); |
|
101 | - } |
|
102 | - |
|
103 | - public function putCache () { |
|
104 | - //cache database row |
|
105 | - Cache::put("groups", "group-" . $this->groupID, $this->row); |
|
106 | - } |
|
107 | - |
|
108 | - public function removeCache () { |
|
109 | - //clear cache data for this group |
|
110 | - Cache::clear("groups", "group-" . $this->groupID); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * get id of group |
|
115 | - * |
|
116 | - * @return id of group |
|
117 | - */ |
|
118 | - public function getGroupID () : int { |
|
119 | - return $this->groupID; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * get name of group |
|
124 | - * |
|
125 | - * @return name of group |
|
126 | - */ |
|
127 | - public function getName () : string { |
|
128 | - return $this->row['name']; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * get group description |
|
133 | - * |
|
134 | - * @return group description |
|
135 | - */ |
|
136 | - public function getDescription () : string { |
|
137 | - return $this->row['description']; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * get color of group (e.q. #FF0000) |
|
142 | - * |
|
143 | - * @return color of group in hex |
|
144 | - */ |
|
145 | - public function getColor () : string { |
|
146 | - return $this->row['color']; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * check, if group is a system group, so group cannot be deleted and is required by system |
|
151 | - * |
|
152 | - * @return true, if group is a system group |
|
153 | - */ |
|
154 | - public function isSystemGroup () : bool { |
|
155 | - return $this->row['system_group'] === 1; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * check for auto assign flag, this is means a group is automatically assigned to users on registration |
|
160 | - * |
|
161 | - * @return true, if group is a auto assign group on registration |
|
162 | - */ |
|
163 | - public function isAutoAssignGroup () : bool { |
|
164 | - return $this->row['auto_assign_regist'] === 1; |
|
165 | - } |
|
166 | - |
|
167 | - public function getRow () : array { |
|
168 | - return $this->row; |
|
169 | - } |
|
170 | - |
|
171 | - public function visible () : bool { |
|
172 | - return $this->row['show'] === 1; |
|
173 | - } |
|
174 | - |
|
175 | - public function hasRank () : bool { |
|
176 | - return $this->row['rank'] !== "none"; |
|
177 | - } |
|
178 | - |
|
179 | - public function getRank () : string { |
|
180 | - return $this->row['rank']; |
|
181 | - } |
|
182 | - |
|
183 | - public function hasRankImage () : bool { |
|
184 | - return $this->row['rank_image'] !== "none"; |
|
185 | - } |
|
186 | - |
|
187 | - public function getRankImage () : string { |
|
188 | - return $this->row['rank_image']; |
|
189 | - } |
|
190 | - |
|
191 | - public function isActivated () : bool { |
|
192 | - return $this->row['activated'] === 1; |
|
193 | - } |
|
194 | - |
|
195 | - public function delete () { |
|
196 | - if ($this->groupID <= 0) { |
|
197 | - throw new IllegalStateException("groupID cannot be <= 0, maybe group wasnt loaded with loadById() or loadByRow()?"); |
|
198 | - } |
|
199 | - |
|
200 | - $delete_group = true; |
|
201 | - |
|
202 | - //throw event, so plugins can avoid deleting of groups |
|
203 | - Events::throwEvent("before_delete_group", array( |
|
204 | - 'groupID' => $this->groupID, |
|
205 | - 'row' => $this->row, |
|
206 | - 'delete_group' => &$delete_group |
|
207 | - )); |
|
208 | - |
|
209 | - if ($delete_group) { |
|
210 | - //delete group from database |
|
211 | - Database::getInstance()->execute("DELETE * FROM `{praefix}groups` WHERE `groupID` = :groupID; ", array( |
|
212 | - 'groupID' => array( |
|
213 | - 'type' => PDO::PARAM_INT, |
|
214 | - 'value' => $this->groupID |
|
215 | - ) |
|
216 | - )); |
|
217 | - |
|
218 | - //delete all members of group |
|
219 | - Database::getInstance()->execute("DELETE * FROM `{praefix}group_members` WHERE `groupID` = :groupID; ", array( |
|
220 | - 'groupID' => array( |
|
221 | - 'type' => PDO::PARAM_INT, |
|
222 | - 'value' => $this->groupID |
|
223 | - ) |
|
224 | - )); |
|
225 | - |
|
226 | - //clear cache |
|
227 | - Cache::clear("groups", "group-" . $this->groupID); |
|
228 | - |
|
229 | - //throw event, so plugins can cleanup |
|
230 | - Events::throwEvent("after_delete_group", array( |
|
231 | - 'groupID' => $this->groupID, |
|
232 | - 'row' => $this->row |
|
233 | - )); |
|
234 | - } |
|
235 | - } |
|
30 | + protected $groupID = -1; |
|
31 | + protected $row = null; |
|
32 | + |
|
33 | + public function __construct() { |
|
34 | + // |
|
35 | + } |
|
36 | + |
|
37 | + public function loadById (int $groupID) { |
|
38 | + if (Cache::contains("groups", "group-" . $groupID)) { |
|
39 | + $this->row = Cache::get("groups", "group-" . $groupID); |
|
40 | + } else { |
|
41 | + $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}groups` WHERE `groupID` = :groupID AND `acivated` = '1'; ", array( |
|
42 | + 'groupID' => array( |
|
43 | + 'type' => PDO::PARAM_INT, |
|
44 | + 'value' => $groupID |
|
45 | + ) |
|
46 | + )); |
|
47 | + |
|
48 | + if (!$row) { |
|
49 | + throw new IllegalStateException("Group with groupID " . $groupID . " doesnt exists."); |
|
50 | + } |
|
51 | + |
|
52 | + $this->row = $row; |
|
53 | + $this->groupID = $row['groupID']; |
|
54 | + |
|
55 | + //cache database row |
|
56 | + Cache::put("groups", "group-" . $groupID, $row); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + public function loadByRow (array $row) { |
|
61 | + $this->row = $row; |
|
62 | + $this->groupID = $row['groupID']; |
|
63 | + } |
|
64 | + |
|
65 | + public function update (string $name, string $description, string $color, bool $auto_assign_regist = false) { |
|
66 | + //throw event |
|
67 | + Events::throwEvent("before_update_group", array( |
|
68 | + 'groupID' => $this->groupID, |
|
69 | + 'old_row' => $this->row, |
|
70 | + 'name' => &$name, |
|
71 | + 'description' => &$description, |
|
72 | + 'color' => &$color, |
|
73 | + 'auto_assign_regist' => &$auto_assign_regist |
|
74 | + )); |
|
75 | + |
|
76 | + Database::getInstance()->execute("UPDATE `{praefix}groups` SET `name` = :name, `description` = :description, `color` = :color, `auto_assign_regist` = :auto_assign_regist WHERE `groupID` = :groupID; ", array( |
|
77 | + 'name' => $name, |
|
78 | + 'description' => $description, |
|
79 | + 'color' => $color, |
|
80 | + 'auto_assign_regist' => ($auto_assign_regist ? 1 : 0), |
|
81 | + 'groupID' => array( |
|
82 | + 'type' => PDO::PARAM_INT, |
|
83 | + 'value' => $this->groupID |
|
84 | + ) |
|
85 | + )); |
|
86 | + |
|
87 | + //throw event |
|
88 | + Events::throwEvent("after_update_group", array( |
|
89 | + 'groupID' => $this->groupID, |
|
90 | + 'old_row' => $this->row, |
|
91 | + )); |
|
92 | + |
|
93 | + //update row in-memory |
|
94 | + $this->row['name'] = $name; |
|
95 | + $this->row['description'] = $description; |
|
96 | + $this->row['color'] = $color; |
|
97 | + $this->row['auto_assign_regist'] = ($auto_assign_regist ? 1 : 0); |
|
98 | + |
|
99 | + //clear cache |
|
100 | + Cache::clear("groups", "group-" . $this->groupID); |
|
101 | + } |
|
102 | + |
|
103 | + public function putCache () { |
|
104 | + //cache database row |
|
105 | + Cache::put("groups", "group-" . $this->groupID, $this->row); |
|
106 | + } |
|
107 | + |
|
108 | + public function removeCache () { |
|
109 | + //clear cache data for this group |
|
110 | + Cache::clear("groups", "group-" . $this->groupID); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * get id of group |
|
115 | + * |
|
116 | + * @return id of group |
|
117 | + */ |
|
118 | + public function getGroupID () : int { |
|
119 | + return $this->groupID; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * get name of group |
|
124 | + * |
|
125 | + * @return name of group |
|
126 | + */ |
|
127 | + public function getName () : string { |
|
128 | + return $this->row['name']; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * get group description |
|
133 | + * |
|
134 | + * @return group description |
|
135 | + */ |
|
136 | + public function getDescription () : string { |
|
137 | + return $this->row['description']; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * get color of group (e.q. #FF0000) |
|
142 | + * |
|
143 | + * @return color of group in hex |
|
144 | + */ |
|
145 | + public function getColor () : string { |
|
146 | + return $this->row['color']; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * check, if group is a system group, so group cannot be deleted and is required by system |
|
151 | + * |
|
152 | + * @return true, if group is a system group |
|
153 | + */ |
|
154 | + public function isSystemGroup () : bool { |
|
155 | + return $this->row['system_group'] === 1; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * check for auto assign flag, this is means a group is automatically assigned to users on registration |
|
160 | + * |
|
161 | + * @return true, if group is a auto assign group on registration |
|
162 | + */ |
|
163 | + public function isAutoAssignGroup () : bool { |
|
164 | + return $this->row['auto_assign_regist'] === 1; |
|
165 | + } |
|
166 | + |
|
167 | + public function getRow () : array { |
|
168 | + return $this->row; |
|
169 | + } |
|
170 | + |
|
171 | + public function visible () : bool { |
|
172 | + return $this->row['show'] === 1; |
|
173 | + } |
|
174 | + |
|
175 | + public function hasRank () : bool { |
|
176 | + return $this->row['rank'] !== "none"; |
|
177 | + } |
|
178 | + |
|
179 | + public function getRank () : string { |
|
180 | + return $this->row['rank']; |
|
181 | + } |
|
182 | + |
|
183 | + public function hasRankImage () : bool { |
|
184 | + return $this->row['rank_image'] !== "none"; |
|
185 | + } |
|
186 | + |
|
187 | + public function getRankImage () : string { |
|
188 | + return $this->row['rank_image']; |
|
189 | + } |
|
190 | + |
|
191 | + public function isActivated () : bool { |
|
192 | + return $this->row['activated'] === 1; |
|
193 | + } |
|
194 | + |
|
195 | + public function delete () { |
|
196 | + if ($this->groupID <= 0) { |
|
197 | + throw new IllegalStateException("groupID cannot be <= 0, maybe group wasnt loaded with loadById() or loadByRow()?"); |
|
198 | + } |
|
199 | + |
|
200 | + $delete_group = true; |
|
201 | + |
|
202 | + //throw event, so plugins can avoid deleting of groups |
|
203 | + Events::throwEvent("before_delete_group", array( |
|
204 | + 'groupID' => $this->groupID, |
|
205 | + 'row' => $this->row, |
|
206 | + 'delete_group' => &$delete_group |
|
207 | + )); |
|
208 | + |
|
209 | + if ($delete_group) { |
|
210 | + //delete group from database |
|
211 | + Database::getInstance()->execute("DELETE * FROM `{praefix}groups` WHERE `groupID` = :groupID; ", array( |
|
212 | + 'groupID' => array( |
|
213 | + 'type' => PDO::PARAM_INT, |
|
214 | + 'value' => $this->groupID |
|
215 | + ) |
|
216 | + )); |
|
217 | + |
|
218 | + //delete all members of group |
|
219 | + Database::getInstance()->execute("DELETE * FROM `{praefix}group_members` WHERE `groupID` = :groupID; ", array( |
|
220 | + 'groupID' => array( |
|
221 | + 'type' => PDO::PARAM_INT, |
|
222 | + 'value' => $this->groupID |
|
223 | + ) |
|
224 | + )); |
|
225 | + |
|
226 | + //clear cache |
|
227 | + Cache::clear("groups", "group-" . $this->groupID); |
|
228 | + |
|
229 | + //throw event, so plugins can cleanup |
|
230 | + Events::throwEvent("after_delete_group", array( |
|
231 | + 'groupID' => $this->groupID, |
|
232 | + 'row' => $this->row |
|
233 | + )); |
|
234 | + } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
238 | 238 |
@@ -27,9 +27,9 @@ |
||
27 | 27 | |
28 | 28 | class LoginHandler { |
29 | 29 | |
30 | - public static function handle () : array { |
|
31 | - // |
|
32 | - } |
|
30 | + public static function handle () : array { |
|
31 | + // |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
35 | 35 |
@@ -27,160 +27,160 @@ |
||
27 | 27 | |
28 | 28 | class PageRights { |
29 | 29 | |
30 | - protected $pageID = 0; |
|
31 | - protected $page = null; |
|
32 | - protected $group_rows = null; |
|
33 | - protected $user_rows = null; |
|
34 | - |
|
35 | - public function __construct(Page $page) { |
|
36 | - $this->pageID = $page->getPageID(); |
|
37 | - $this->page = $page; |
|
38 | - } |
|
39 | - |
|
40 | - public function load () { |
|
41 | - if (Cache::contains("page_rights", "page_" . $this->pageID)) { |
|
42 | - $this->group_rows = Cache::get("page_rights", "page_" . $this->pageID); |
|
43 | - } else { |
|
44 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_rights` WHERE `pageID` = :pageID; ", array( |
|
45 | - 'pageID' => array( |
|
46 | - 'type' => PDO::PARAM_INT, |
|
47 | - 'value' => $this->pageID |
|
48 | - ) |
|
49 | - )); |
|
50 | - |
|
51 | - $array = array(); |
|
52 | - |
|
53 | - foreach ($rows as $row) { |
|
54 | - if (!isset($array[$row['groupID']])) { |
|
55 | - $array[$row['groupID']] = array(); |
|
56 | - } |
|
57 | - |
|
58 | - $array[$row['groupID']][$row['token']] = $row['value']; |
|
59 | - } |
|
60 | - |
|
61 | - //cache results |
|
62 | - Cache::put("page_rights", "page_" . $this->pageID, $array); |
|
63 | - |
|
64 | - $this->group_rows = $array; |
|
65 | - } |
|
66 | - |
|
67 | - if (Cache::contains("page_rights", "page_user_" . $this->pageID)) { |
|
68 | - $this->user_rows = Cache::get("page_rights", "page_user_" . $this->pageID); |
|
69 | - } else { |
|
70 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_user_rights` WHERE `pageID` = :pageID; ", array( |
|
71 | - 'pageID' => array( |
|
72 | - 'type' => PDO::PARAM_INT, |
|
73 | - 'value' => $this->pageID |
|
74 | - ) |
|
75 | - )); |
|
76 | - |
|
77 | - $array = array(); |
|
78 | - |
|
79 | - foreach ($rows as $row) { |
|
80 | - if (!isset($array[$row['userID']])) { |
|
81 | - $array[$row['userID']] = array(); |
|
82 | - } |
|
83 | - |
|
84 | - $array[$row['userID']][$row['token']] = $row['value']; |
|
85 | - } |
|
86 | - |
|
87 | - //cache results |
|
88 | - Cache::put("page_rights", "page_user_" . $this->pageID, $array); |
|
89 | - |
|
90 | - $this->user_rows = $array; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * check, if user has right for this page |
|
96 | - */ |
|
97 | - public function checkRights (int $userID, array $groupIDs, string $token) : bool { |
|
98 | - $value = 0; |
|
99 | - |
|
100 | - //per default published pages are visible, if not specified |
|
101 | - if ($token == "see") { |
|
102 | - $value = -1; |
|
103 | - } |
|
104 | - |
|
105 | - //iterate through user groups |
|
106 | - foreach ($groupIDs as $groupID) { |
|
107 | - //check, if permissions exists for groupID |
|
108 | - if (!isset($this->group_rows[$groupID])) { |
|
109 | - //no rights specified for this group |
|
110 | - continue; |
|
111 | - } |
|
112 | - |
|
113 | - if (!isset($this->group_rows[$groupID][$token])) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - |
|
117 | - $row_value = $this->group_rows[$groupID][$token]; |
|
118 | - |
|
119 | - if ($row_value > $value) { |
|
120 | - $value = $row_value; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - if (isset($this->user_rows[$userID]) && isset($this->user_rows[$userID][$token])) { |
|
125 | - $row_value = $this->user_rows[$userID][$token]; |
|
126 | - |
|
127 | - if ($row_value > $value) { |
|
128 | - $value = $row_value; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - return $value == 1 || $value == -1; |
|
133 | - } |
|
134 | - |
|
135 | - protected function mergeRow (array $permissions, string $token, int $value) : array { |
|
136 | - if ($value < 0 || $value > 2) { |
|
137 | - throw new IllegalArgumentException("token ('" . $token . "') value '" . $value . "' is not allowed, value has to be >= 0 and <= 2."); |
|
138 | - } |
|
139 | - |
|
140 | - if (!isset($permissions[$token])) { |
|
141 | - $permissions[$token] = $value; |
|
142 | - } else { |
|
143 | - $current_value = $permissions[$token]; |
|
144 | - |
|
145 | - if ($value > $current_value) { |
|
146 | - $permissions[$token] = $value; |
|
147 | - } |
|
148 | - } |
|
30 | + protected $pageID = 0; |
|
31 | + protected $page = null; |
|
32 | + protected $group_rows = null; |
|
33 | + protected $user_rows = null; |
|
34 | + |
|
35 | + public function __construct(Page $page) { |
|
36 | + $this->pageID = $page->getPageID(); |
|
37 | + $this->page = $page; |
|
38 | + } |
|
39 | + |
|
40 | + public function load () { |
|
41 | + if (Cache::contains("page_rights", "page_" . $this->pageID)) { |
|
42 | + $this->group_rows = Cache::get("page_rights", "page_" . $this->pageID); |
|
43 | + } else { |
|
44 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_rights` WHERE `pageID` = :pageID; ", array( |
|
45 | + 'pageID' => array( |
|
46 | + 'type' => PDO::PARAM_INT, |
|
47 | + 'value' => $this->pageID |
|
48 | + ) |
|
49 | + )); |
|
50 | + |
|
51 | + $array = array(); |
|
52 | + |
|
53 | + foreach ($rows as $row) { |
|
54 | + if (!isset($array[$row['groupID']])) { |
|
55 | + $array[$row['groupID']] = array(); |
|
56 | + } |
|
57 | + |
|
58 | + $array[$row['groupID']][$row['token']] = $row['value']; |
|
59 | + } |
|
60 | + |
|
61 | + //cache results |
|
62 | + Cache::put("page_rights", "page_" . $this->pageID, $array); |
|
63 | + |
|
64 | + $this->group_rows = $array; |
|
65 | + } |
|
66 | + |
|
67 | + if (Cache::contains("page_rights", "page_user_" . $this->pageID)) { |
|
68 | + $this->user_rows = Cache::get("page_rights", "page_user_" . $this->pageID); |
|
69 | + } else { |
|
70 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_user_rights` WHERE `pageID` = :pageID; ", array( |
|
71 | + 'pageID' => array( |
|
72 | + 'type' => PDO::PARAM_INT, |
|
73 | + 'value' => $this->pageID |
|
74 | + ) |
|
75 | + )); |
|
76 | + |
|
77 | + $array = array(); |
|
78 | + |
|
79 | + foreach ($rows as $row) { |
|
80 | + if (!isset($array[$row['userID']])) { |
|
81 | + $array[$row['userID']] = array(); |
|
82 | + } |
|
83 | + |
|
84 | + $array[$row['userID']][$row['token']] = $row['value']; |
|
85 | + } |
|
86 | + |
|
87 | + //cache results |
|
88 | + Cache::put("page_rights", "page_user_" . $this->pageID, $array); |
|
89 | + |
|
90 | + $this->user_rows = $array; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * check, if user has right for this page |
|
96 | + */ |
|
97 | + public function checkRights (int $userID, array $groupIDs, string $token) : bool { |
|
98 | + $value = 0; |
|
99 | + |
|
100 | + //per default published pages are visible, if not specified |
|
101 | + if ($token == "see") { |
|
102 | + $value = -1; |
|
103 | + } |
|
104 | + |
|
105 | + //iterate through user groups |
|
106 | + foreach ($groupIDs as $groupID) { |
|
107 | + //check, if permissions exists for groupID |
|
108 | + if (!isset($this->group_rows[$groupID])) { |
|
109 | + //no rights specified for this group |
|
110 | + continue; |
|
111 | + } |
|
112 | + |
|
113 | + if (!isset($this->group_rows[$groupID][$token])) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + |
|
117 | + $row_value = $this->group_rows[$groupID][$token]; |
|
118 | + |
|
119 | + if ($row_value > $value) { |
|
120 | + $value = $row_value; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + if (isset($this->user_rows[$userID]) && isset($this->user_rows[$userID][$token])) { |
|
125 | + $row_value = $this->user_rows[$userID][$token]; |
|
126 | + |
|
127 | + if ($row_value > $value) { |
|
128 | + $value = $row_value; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + return $value == 1 || $value == -1; |
|
133 | + } |
|
134 | + |
|
135 | + protected function mergeRow (array $permissions, string $token, int $value) : array { |
|
136 | + if ($value < 0 || $value > 2) { |
|
137 | + throw new IllegalArgumentException("token ('" . $token . "') value '" . $value . "' is not allowed, value has to be >= 0 and <= 2."); |
|
138 | + } |
|
139 | + |
|
140 | + if (!isset($permissions[$token])) { |
|
141 | + $permissions[$token] = $value; |
|
142 | + } else { |
|
143 | + $current_value = $permissions[$token]; |
|
144 | + |
|
145 | + if ($value > $current_value) { |
|
146 | + $permissions[$token] = $value; |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - return $permissions; |
|
151 | - } |
|
150 | + return $permissions; |
|
151 | + } |
|
152 | 152 | |
153 | - public static function setDefaultAllowedGroups (int $pageID, array $groupIDs) { |
|
154 | - if (sizeof($groupIDs) == 0) { |
|
155 | - throw new IllegalArgumentException("no groupIDs was set."); |
|
156 | - } |
|
153 | + public static function setDefaultAllowedGroups (int $pageID, array $groupIDs) { |
|
154 | + if (sizeof($groupIDs) == 0) { |
|
155 | + throw new IllegalArgumentException("no groupIDs was set."); |
|
156 | + } |
|
157 | 157 | |
158 | - $lines = array(); |
|
158 | + $lines = array(); |
|
159 | 159 | |
160 | - foreach ($groupIDs as $groupID) { |
|
161 | - //validate groupID |
|
162 | - $groupID = Validator_Int::get($groupID); |
|
160 | + foreach ($groupIDs as $groupID) { |
|
161 | + //validate groupID |
|
162 | + $groupID = Validator_Int::get($groupID); |
|
163 | 163 | |
164 | - $lines[] = "('" . $groupID . "', '" . $pageID . "', 'see', '1')"; |
|
165 | - } |
|
166 | - |
|
167 | - $line_str = implode(",\n", $lines); |
|
168 | - |
|
169 | - Database::getInstance()->execute("INSERT INTO `{praefix}page_rights` ( |
|
164 | + $lines[] = "('" . $groupID . "', '" . $pageID . "', 'see', '1')"; |
|
165 | + } |
|
166 | + |
|
167 | + $line_str = implode(",\n", $lines); |
|
168 | + |
|
169 | + Database::getInstance()->execute("INSERT INTO `{praefix}page_rights` ( |
|
170 | 170 | `groupID`, `pageID`, `token`, `value` |
171 | 171 | ) VALUES |
172 | 172 | " . $line_str . " |
173 | 173 | ON DUPLICATE KEY UPDATE `value` = '1'; "); |
174 | 174 | |
175 | - //clear cache |
|
176 | - Cache::clear("page_rights", "page_" . $pageID); |
|
177 | - } |
|
175 | + //clear cache |
|
176 | + Cache::clear("page_rights", "page_" . $pageID); |
|
177 | + } |
|
178 | 178 | |
179 | - public static function setDefaultAllowedGroupsForAlias (string $alias, array $groupIDs) { |
|
180 | - $pageID = Page::getPageIDByAlias($alias); |
|
179 | + public static function setDefaultAllowedGroupsForAlias (string $alias, array $groupIDs) { |
|
180 | + $pageID = Page::getPageIDByAlias($alias); |
|
181 | 181 | |
182 | - self::setDefaultAllowedGroups($pageID, $groupIDs); |
|
183 | - } |
|
182 | + self::setDefaultAllowedGroups($pageID, $groupIDs); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | } |
186 | 186 |
@@ -27,15 +27,15 @@ |
||
27 | 27 | |
28 | 28 | class PageLoader { |
29 | 29 | |
30 | - public static function loadInstance (string $type_name) : PageType { |
|
31 | - if ($type_name == null || empty($type_name)) { |
|
32 | - throw new NullPointerException("page_type cannot be null or empty."); |
|
33 | - } |
|
30 | + public static function loadInstance (string $type_name) : PageType { |
|
31 | + if ($type_name == null || empty($type_name)) { |
|
32 | + throw new NullPointerException("page_type cannot be null or empty."); |
|
33 | + } |
|
34 | 34 | |
35 | - $class = $type_name;//DataBase::getInstance()->escape($type_name); |
|
35 | + $class = $type_name;//DataBase::getInstance()->escape($type_name); |
|
36 | 36 | |
37 | - return new $class(); |
|
38 | - } |
|
37 | + return new $class(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | } |
41 | 41 |
@@ -848,11 +848,11 @@ discard block |
||
848 | 848 | } |
849 | 849 | |
850 | 850 | if (isset($column['default']) && $column['default'] != null) { |
851 | - if ($column['default'] === "CURRENT_TIMESTAMP") { |
|
852 | - $default_str = " DEFAULT CURRENT_TIMESTAMP"; |
|
853 | - } else { |
|
854 | - $default_str = " DEFAULT '" . $column['default'] . "'"; |
|
855 | - } |
|
851 | + if ($column['default'] === "CURRENT_TIMESTAMP") { |
|
852 | + $default_str = " DEFAULT CURRENT_TIMESTAMP"; |
|
853 | + } else { |
|
854 | + $default_str = " DEFAULT '" . $column['default'] . "'"; |
|
855 | + } |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | switch ($column['type']) { |
@@ -1298,10 +1298,10 @@ discard block |
||
1298 | 1298 | //create table structure |
1299 | 1299 | $this->create(); |
1300 | 1300 | } else { |
1301 | - var_dump($this->detectTableChanges()); |
|
1301 | + var_dump($this->detectTableChanges()); |
|
1302 | 1302 | |
1303 | 1303 | //TODO: add code here |
1304 | - //throw new Exception("Upgrading of tables isnt supported yet."); |
|
1304 | + //throw new Exception("Upgrading of tables isnt supported yet."); |
|
1305 | 1305 | } |
1306 | 1306 | } |
1307 | 1307 | |
@@ -1420,109 +1420,109 @@ discard block |
||
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | protected function detectTableChanges () : array { |
1423 | - //columns |
|
1424 | - $changed_columns = array(); |
|
1425 | - $added_columns = array(); |
|
1426 | - $removed_columns = array(); |
|
1423 | + //columns |
|
1424 | + $changed_columns = array(); |
|
1425 | + $added_columns = array(); |
|
1426 | + $removed_columns = array(); |
|
1427 | 1427 | |
1428 | - //indexes |
|
1429 | - $changed_indexes = array(); |
|
1430 | - $added_indexes = array(); |
|
1431 | - $removed_indexes = array(); |
|
1428 | + //indexes |
|
1429 | + $changed_indexes = array(); |
|
1430 | + $added_indexes = array(); |
|
1431 | + $removed_indexes = array(); |
|
1432 | 1432 | |
1433 | 1433 | |
1434 | 1434 | //compare current state with should state |
1435 | - $current_columns = $this->listColumnsFromDatabase(); |
|
1436 | - $should_columns = $this->columns; |
|
1437 | - |
|
1438 | - //check for added columns |
|
1439 | - foreach ($should_columns as $name=>$column_data) { |
|
1440 | - if (!isset($current_columns[$name])) { |
|
1441 | - //new column found |
|
1442 | - $added_columns[$name] = $should_columns[$name]; |
|
1443 | - } |
|
1444 | - } |
|
1445 | - |
|
1446 | - //check for removed columns |
|
1447 | - foreach ($current_columns as $name=>$column_data) { |
|
1448 | - if (!isset($should_columns[$name])) { |
|
1449 | - //removed column found |
|
1450 | - $removed_columns[$name] = $current_columns[$name]; |
|
1451 | - } |
|
1452 | - } |
|
1453 | - |
|
1454 | - //check for changed columns |
|
1455 | - foreach ($should_columns as $name=>$column_data) { |
|
1456 | - //we dont have to check this column, if the column was added |
|
1457 | - if (isset($added_columns[$name])) { |
|
1458 | - continue; |
|
1459 | - } |
|
1460 | - |
|
1461 | - //we dont have to check this column, if the column was removed |
|
1462 | - if (isset($removed_columns[$name])) { |
|
1463 | - continue; |
|
1464 | - } |
|
1465 | - |
|
1466 | - //check for differences |
|
1467 | - foreach ($should_columns[$name] as $key=>$value) { |
|
1468 | - if (!isset($should_columns[$name][$key]) && !@is_null($should_columns[$name][$key])) { |
|
1469 | - echo "Column '" . $key . "' not found.\n\n"; |
|
1470 | - |
|
1471 | - echo "should columns:\n"; |
|
1472 | - var_dump($should_columns); |
|
1473 | - |
|
1474 | - echo "\n\ncurrent columns:\n"; |
|
1475 | - var_dump($current_columns); |
|
1476 | - |
|
1477 | - echo "\n\n"; |
|
1478 | - } |
|
1479 | - |
|
1480 | - if (strcmp($name, "charset") && @$current_columns[$name][$key] == "NULL") { |
|
1481 | - continue; |
|
1482 | - } |
|
1483 | - |
|
1484 | - if (strcmp($name, "bool(false)")) { |
|
1485 | - continue; |
|
1486 | - } |
|
1487 | - |
|
1488 | - if (!isset($current_columns[$name][$key]) && !@is_null($current_columns[$name][$key])) { |
|
1489 | - echo "$" . "current_columns['" . $name . "']['" . $key . "'] not found:\n"; |
|
1490 | - var_dump($current_columns); |
|
1491 | - |
|
1492 | - echo "\n\nshould columns:\n"; |
|
1493 | - var_dump($should_columns); |
|
1494 | - } |
|
1495 | - |
|
1496 | - if ($current_columns[$name][$key] != $value) { |
|
1497 | - $changed_columns[$name] = $should_columns[$name]; |
|
1498 | - } |
|
1499 | - } |
|
1500 | - } |
|
1501 | - |
|
1502 | - //TODO: check for changed indexes / keys |
|
1503 | - |
|
1504 | - //TODO: change database engine if neccessary |
|
1505 | - |
|
1506 | - //TODO: change charset if neccessary |
|
1507 | - |
|
1508 | - return array( |
|
1509 | - 'added_columns' => $added_columns, |
|
1510 | - "removed_columns" => $removed_columns, |
|
1511 | - "changed_columns" => $changed_columns, |
|
1512 | - "added_indexes" => $added_indexes, |
|
1513 | - "removed_indexes" => $removed_indexes, |
|
1514 | - "changed_indexes" => $changed_indexes |
|
1515 | - ); |
|
1435 | + $current_columns = $this->listColumnsFromDatabase(); |
|
1436 | + $should_columns = $this->columns; |
|
1437 | + |
|
1438 | + //check for added columns |
|
1439 | + foreach ($should_columns as $name=>$column_data) { |
|
1440 | + if (!isset($current_columns[$name])) { |
|
1441 | + //new column found |
|
1442 | + $added_columns[$name] = $should_columns[$name]; |
|
1443 | + } |
|
1444 | + } |
|
1445 | + |
|
1446 | + //check for removed columns |
|
1447 | + foreach ($current_columns as $name=>$column_data) { |
|
1448 | + if (!isset($should_columns[$name])) { |
|
1449 | + //removed column found |
|
1450 | + $removed_columns[$name] = $current_columns[$name]; |
|
1451 | + } |
|
1452 | + } |
|
1453 | + |
|
1454 | + //check for changed columns |
|
1455 | + foreach ($should_columns as $name=>$column_data) { |
|
1456 | + //we dont have to check this column, if the column was added |
|
1457 | + if (isset($added_columns[$name])) { |
|
1458 | + continue; |
|
1459 | + } |
|
1460 | + |
|
1461 | + //we dont have to check this column, if the column was removed |
|
1462 | + if (isset($removed_columns[$name])) { |
|
1463 | + continue; |
|
1464 | + } |
|
1465 | + |
|
1466 | + //check for differences |
|
1467 | + foreach ($should_columns[$name] as $key=>$value) { |
|
1468 | + if (!isset($should_columns[$name][$key]) && !@is_null($should_columns[$name][$key])) { |
|
1469 | + echo "Column '" . $key . "' not found.\n\n"; |
|
1470 | + |
|
1471 | + echo "should columns:\n"; |
|
1472 | + var_dump($should_columns); |
|
1473 | + |
|
1474 | + echo "\n\ncurrent columns:\n"; |
|
1475 | + var_dump($current_columns); |
|
1476 | + |
|
1477 | + echo "\n\n"; |
|
1478 | + } |
|
1479 | + |
|
1480 | + if (strcmp($name, "charset") && @$current_columns[$name][$key] == "NULL") { |
|
1481 | + continue; |
|
1482 | + } |
|
1483 | + |
|
1484 | + if (strcmp($name, "bool(false)")) { |
|
1485 | + continue; |
|
1486 | + } |
|
1487 | + |
|
1488 | + if (!isset($current_columns[$name][$key]) && !@is_null($current_columns[$name][$key])) { |
|
1489 | + echo "$" . "current_columns['" . $name . "']['" . $key . "'] not found:\n"; |
|
1490 | + var_dump($current_columns); |
|
1491 | + |
|
1492 | + echo "\n\nshould columns:\n"; |
|
1493 | + var_dump($should_columns); |
|
1494 | + } |
|
1495 | + |
|
1496 | + if ($current_columns[$name][$key] != $value) { |
|
1497 | + $changed_columns[$name] = $should_columns[$name]; |
|
1498 | + } |
|
1499 | + } |
|
1500 | + } |
|
1501 | + |
|
1502 | + //TODO: check for changed indexes / keys |
|
1503 | + |
|
1504 | + //TODO: change database engine if neccessary |
|
1505 | + |
|
1506 | + //TODO: change charset if neccessary |
|
1507 | + |
|
1508 | + return array( |
|
1509 | + 'added_columns' => $added_columns, |
|
1510 | + "removed_columns" => $removed_columns, |
|
1511 | + "changed_columns" => $changed_columns, |
|
1512 | + "added_indexes" => $added_indexes, |
|
1513 | + "removed_indexes" => $removed_indexes, |
|
1514 | + "changed_indexes" => $changed_indexes |
|
1515 | + ); |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | /** |
1519 | 1519 | * backup table |
1520 | - * |
|
1521 | - * @param $output_file file where sql query should be written in |
|
1520 | + * |
|
1521 | + * @param $output_file file where sql query should be written in |
|
1522 | 1522 | */ |
1523 | 1523 | public function backup (string $output_file) : void { |
1524 | - //TODO: implement this feature |
|
1525 | - } |
|
1524 | + //TODO: implement this feature |
|
1525 | + } |
|
1526 | 1526 | |
1527 | 1527 | public function truncate () { |
1528 | 1528 | $this->db_driver->query("TRUNCATE `" . $this->table_name . "`; "); |