PluginProbe
wpForo Forum / 1.4.12
wpForo Forum v1.4.12
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / class-usergroups.php

class-usergroups.php in wpForo Forum 1.4.12, at wpf-includes/class-usergroups.php

273 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5 class wpForoUsergroup{
6 public $default;
7 public $default_groupid;
8 public $cans;
9
10 static $cache = array( 'usergroup' => array(), 'user' => array() );
11
12 function __construct(){
13 $this->init_defaults();
14 $this->init_options();
15 }
16
17 private function init_defaults(){
18 $this->default = new stdClass;
19
20 $this->default->default_groupid = 3;
21
22 $this->default->cans = array (
23 'cf' => 'Dashboard - Can create forum',
24 'ef' => 'Dashboard - Can edit forum',
25 'df' => 'Dashboard - Can delete forum',
26 'vm' => 'Dashboard - Members Menu',
27 'aum' => 'Dashboard - Moderation Menu',
28 'em' => 'Dashboard - Can edit member',
29 'bm' => 'Dashboard - Can ban member',
30 'dm' => 'Dashboard - Can delete member',
31 'vmg' => 'Dashboard - Usergroup Menu',
32 'aup' => 'Front - Can pass moderation',
33 'vmem' => 'Front - Can view members',
34 'vprf' => 'Front - Can view profiles',
35 'vpra' => 'Front - Can view member activity',
36 'vprs' => 'Front - Can view member subscriptions',
37
38 'upa' => 'Front - Can upload avatar',
39 'ups' => 'Front - Can have signaturee',
40 'va' => 'Front - Can view avatars',
41
42 'vmu' => 'Front - Can view member username',
43 'vmm' => 'Front - Can view member email',
44 'vmt' => 'Front - Can view member title',
45 'vmct' => 'Front - Can view member custom title',
46 'vmr' => 'Front - Can view member reputation',
47 'vmw' => 'Front - Can view member website',
48 'vmsn' => 'Front - Can view member social networks',
49 'vmrd' => 'Front - Can view member reg. date',
50 'vmlad'=> 'Front - Can view member last active date',
51 'vip' => 'Front - Can view member IP address',
52 'vml' => 'Front - Can view member location',
53 'vmo' => 'Front - Can view member occupation',
54 'vms' => 'Front - Can view member signature',
55 'vmam' => 'Front - Can view member about me',
56 'vmpn' => 'Front - Can view member phone number',
57 'vwpm' => 'Front - Can write PM'
58 );
59 }
60
61 private function init_options(){
62 $this->default_groupid = get_wpf_option('wpforo_default_groupid', $this->default->default_groupid);
63 $this->cans = apply_filters('wpforo_usergroup_cans', $this->default->cans);
64 }
65
66 function usergroup_list_data(){
67 $ugdata = array();
68 $ugroups = WPF()->db->get_results('SELECT `groupid`, `name`, `access`, `color` FROM '.WPF()->tables->usergroups.' ORDER BY `name` ', ARRAY_A);
69 foreach($ugroups as $ugroup){
70 $user_count = WPF()->db->get_var('SELECT COUNT(*) FROM '.WPF()->tables->profiles.' WHERE `groupid` = ' . intval($ugroup['groupid']));
71 $ugdata[$ugroup['groupid']]['groupid'] = $ugroup['groupid'];
72 $ugdata[$ugroup['groupid']]['name'] = wpforo_phrase($ugroup['name'], FALSE);
73 $ugdata[$ugroup['groupid']]['count'] = intval($user_count);
74 $ugdata[$ugroup['groupid']]['access'] = $ugroup['access'];
75 $ugdata[$ugroup['groupid']]['color'] = $ugroup['color'];
76 }
77 return $ugdata;
78 }
79
80 function add($title, $cans = array(), $description = '', $role = 'subscriber', $access = 'standard', $color = '', $visible = 1 ){
81 $i = 2;
82 $real_title = $title;
83 while( WPF()->db->get_var(
84 WPF()->db->prepare(
85 "SELECT `groupid` FROM `".WPF()->tables->usergroups."`
86 WHERE `name` = '%s'", sanitize_text_field($title) )))
87 {
88 $title = $title . '-' . $i;
89 $i++;
90 }
91
92 $cans = wpforo_parse_args( $cans, array_map('wpforo_return_zero', $this->cans) );
93
94 if( WPF()->db->insert(
95 WPF()->tables->usergroups,
96 array(
97 'name' => sanitize_text_field($title),
98 'cans' => serialize( $cans ),
99 'description' => $description,
100 'utitle' => sanitize_text_field($real_title),
101 'role' => $role,
102 'access' => $access,
103 'color' => $color,
104 'visible' => $visible
105 ),
106 array(
107 '%s',
108 '%s',
109 '%s',
110 '%s',
111 '%s',
112 '%s',
113 '%s',
114 '%d'
115 )
116 )
117 ){
118 $ugid = WPF()->db->insert_id;
119 $forums = WPF()->forum->get_forums();
120 if(!empty($forums) && $ugid){
121 foreach($forums as $forum){
122 if(isset($forum['permissions'])){
123 $permissions = unserialize($forum['permissions']);
124 if(!empty($permissions)){
125 $permissions[$ugid] = $access;
126 $permissions = serialize($permissions);
127 WPF()->db->update( WPF()->tables->forums, array('permissions' => $permissions), array('forumid' => $forum['forumid']), array('%s'), array('%d') );
128 }
129 }
130 }
131 }
132 WPF()->notice->add('User group successfully added', 'success');
133 return WPF()->db->insert_id;
134 }
135
136 WPF()->notice->add('User group add error', 'error');
137 return FALSE;
138 }
139
140 function edit( $groupid, $title, $cans, $description = '', $role = NULL, $access = NULL, $color = '', $visible = 1 ){
141
142 //if( $groupid == 1 ) return false;
143 if( !current_user_can('administrator') ){
144 WPF()->notice->add('Permission denied', 'error');
145 return FALSE;
146 }
147
148 $cans = wpforo_parse_args( $cans, array_map('wpforo_return_zero', $this->cans) );
149 $usergroup = $this->get_usergroup( $groupid );
150 $role = is_null($role) ? $usergroup['role'] : $role;
151 $access = is_null($access) ? $usergroup['access'] : $access;
152
153 if( FALSE !== WPF()->db->update(
154 WPF()->tables->usergroups,
155 array(
156 'name' => sanitize_text_field($title),
157 'cans' => serialize( $cans ),
158 'description' => $description,
159 'utitle' => $usergroup['utitle'],
160 'role' => $role,
161 'access' => $access,
162 'color' => $color,
163 'visible' => $visible
164 ),
165 array( 'groupid' => intval($groupid) ),
166 array(
167 '%s',
168 '%s',
169 '%s',
170 '%s',
171 '%s',
172 '%s',
173 '%s',
174 '%d'
175 ),
176 array( '%d' ))
177 ){
178 WPF()->notice->add('User group successfully edited', 'success');
179 return $groupid;
180 }
181
182 WPF()->notice->add('User group edit error', 'error');
183 return FALSE;
184 }
185
186 function delete(){
187
188 if( !current_user_can('administrator') ){
189 WPF()->notice->add('Permission denied', 'error');
190 return FALSE;
191 }
192
193 if( isset($_GET['action']) && $_GET['action'] == 'del' && isset($_GET['gid']) && $_GET['gid'] != 1 && $_GET['gid'] != 4 ){
194 $status = FALSE;
195 extract($_POST['usergroup'], EXTR_OVERWRITE);
196 $mergeid = intval($mergeid);
197 $insert_gid = $_GET['gid'];
198 #################################################### USERS
199 if(isset($mergeid)){
200 $status = WPF()->db->query("UPDATE `".WPF()->tables->profiles."` SET `groupid` = " . intval($mergeid) . " WHERE `groupid` = " . intval($insert_gid) );
201 $notice = wpforo_phrase('Usergroup has been successfully deleted. All users of this usergroup have been moved to the usergroup you\'ve chosen', false);
202 }else{
203 $status = WPF()->db->query("UPDATE `".WPF()->tables->profiles."` SET `status` = 'trashed' WHERE `groupid` = " . intval($insert_gid) );
204 $notice = wpforo_phrase('Usergroup has been successfully deleted.');
205 }
206 #################################################### END USERS
207 if( $status !== FALSE ){
208 if( WPF()->db->query("DELETE FROM `".WPF()->tables->usergroups."` WHERE `groupid` = " . intval($insert_gid) ) ){
209 WPF()->notice->add($notice, 'success');
210 return TRUE;
211 }
212 }
213 }
214 WPF()->notice->add('Can\'t delete this Usergroup', 'error');
215 return FALSE;
216 }
217
218 function get_usergroup( $groupid = 4 ){
219 // Guest UsergroupID = 4
220 $cache = WPF()->cache->on('memory_cashe');
221 if( $cache && isset(self::$cache['usergroup'][$groupid]) ){
222 return self::$cache['usergroup'][$groupid];
223 }
224 $usergroup = WPF()->db->get_row("SELECT * FROM `".WPF()->tables->usergroups."` WHERE `groupid` = ".intval($groupid), ARRAY_A);
225 if($cache && isset($groupid)){
226 self::$cache['usergroup'][$groupid] = $usergroup;
227 }
228 return $usergroup;
229 }
230
231 function get_usergroups( $field = 'full' ){
232 $cache = WPF()->cache->on('memory_cashe');
233 if( $cache && isset(self::$cache['usergroups'][$field]) ) return self::$cache['usergroups'][$field];
234
235 if( $field == 'full' ){
236 $results = WPF()->db->get_results("SELECT * FROM `".WPF()->tables->usergroups."`", ARRAY_A);
237 }else{
238 $results = WPF()->db->get_col("SELECT `$field` FROM `".WPF()->tables->usergroups."`");
239 }
240
241 if( $cache ) self::$cache['usergroups'][$field] = $results;
242 return $results;
243 }
244
245 function get_groupid_by_userid( $userid ){
246 $cache = WPF()->cache->on('memory_cashe');
247 if( $cache && isset(self::$cache['user'][$userid]) ){
248 return self::$cache['user'][$userid];
249 }
250 $groupid = WPF()->db->get_var("SELECT `groupid` FROM `".WPF()->tables->profiles."` WHERE `userid` = " . intval($userid));
251 if($cache && isset($groupid)){
252 self::$cache['user'][$userid] = $groupid;
253 }
254 return $groupid;
255 }
256
257 function show_selectbox( $groupid = 0, $exclude = array() ){
258 if( !$groupid = intval($groupid) ) $groupid = (isset($_POST['usergroup']['groupid'])) ? intval($_POST['usergroup']['groupid']) : 0;
259 if( !$groupid ) $groupid = $this->default_groupid;
260 if( empty($exclude) && isset($_GET['gid']) && intval($_GET['gid']) ) $exclude[] = intval($_GET['gid']);
261 $ugroups = $this->usergroup_list_data();
262 foreach($ugroups as $ugroup){
263 if( in_array($ugroup['groupid'], $exclude) ) continue;
264 echo '<option value="'.esc_attr($ugroup['groupid']).'" '.($groupid == $ugroup['groupid'] ? 'selected' : '').'>' . esc_html( __($ugroup['name'], 'wpforo') ) . '</option>';
265 }
266 }
267
268 function get_visible_usergroup_ids(){
269 return $results = WPF()->db->get_col("SELECT `groupid` FROM `".WPF()->tables->usergroups."` WHERE `visible` = 1");
270
271 }
272
273 }