PluginProbe
wpForo Forum / 1.4.1
wpForo Forum v1.4.1
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.1, at wpf-includes/class-usergroups.php

258 lines 9.8 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 private $wpforo;
7 public $default;
8 public $default_groupid;
9 public $cans;
10
11 static $cache = array( 'usergroup' => array(), 'user' => array() );
12
13 function __construct( $wpForo ){
14 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
15 $this->init_defaults();
16 $this->init_options();
17 }
18
19 private function init_defaults(){
20 $this->default = new stdClass;
21
22 $this->default->default_groupid = 3;
23
24 $this->default->cans = array (
25 'cf' => 'Dashboard - Can create forum',
26 'ef' => 'Dashboard - Can edit forum',
27 'df' => 'Dashboard - Can delete forum',
28 'vm' => 'Dashboard - Members Menu',
29 'aum' => 'Dashboard - Moderation Menu',
30 'em' => 'Dashboard - Can edit member',
31 'bm' => 'Dashboard - Can ban member',
32 'dm' => 'Dashboard - Can delete member',
33 'vmg' => 'Dashboard - Usergroup Menu',
34 'aup' => 'Front - Can pass moderation',
35 'vmem' => 'Front - Can view members',
36 'vprf' => 'Front - Can view profiles',
37
38 'upa' => 'Front - Can upload avatar',
39 'ups' => 'Front - Can have signature',
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 = $this->wpforo->db->get_results('SELECT `groupid`, `name` FROM '.$this->wpforo->db->prefix.'wpforo_usergroups ORDER BY `name` ', ARRAY_A);
69 foreach($ugroups as $ugroup){
70 $user_count = $this->wpforo->db->get_var('SELECT COUNT(userid) FROM '.$this->wpforo->db->prefix.'wpforo_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 }
75 return $ugdata;
76 }
77
78 function add($title, $cans = array(), $description = '', $role = 'subscriber', $access = 'standard' ){
79 $i = 2;
80 $real_title = $title;
81 while( $this->wpforo->db->get_var(
82 $this->wpforo->db->prepare(
83 "SELECT name FROM ".$this->wpforo->db->prefix."wpforo_usergroups
84 WHERE name = %s", sanitize_text_field($title) )))
85 {
86 $title = $title . '-' . $i;
87 $i++;
88 }
89
90 $cans = wpforo_parse_args( $cans, array_map('wpforo_return_zero', $this->cans) );
91
92 if( $this->wpforo->db->insert(
93 $this->wpforo->db->prefix . 'wpforo_usergroups',
94 array(
95 'name' => sanitize_text_field($title),
96 'cans' => serialize( $cans ),
97 'description' => $description,
98 'utitle' => sanitize_text_field($real_title),
99 'role' => $role,
100 'access' => $access
101 ),
102 array(
103 '%s',
104 '%s',
105 '%s',
106 '%s',
107 '%s',
108 '%s'
109 )
110 )
111 ){
112 $ugid = $this->wpforo->db->insert_id;
113 $forums = $this->wpforo->forum->get_forums();
114 if(!empty($forums) && $ugid){
115 $new_permission = array();
116 foreach($forums as $forum){
117 if(isset($forum['permissions'])){
118 $permissions = unserialize($forum['permissions']);
119 if(!empty($permissions)){
120 $permissions[$ugid] = $access;
121 $permissions = serialize($permissions);
122 $this->wpforo->db->update( $this->wpforo->db->prefix . 'wpforo_forums', array('permissions' => $permissions), array('forumid' => $forum['forumid']), array('%s'), array('%d') );
123 }
124 }
125 }
126 }
127 $this->wpforo->notice->add('User group successfully added', 'success');
128 return $this->wpforo->db->insert_id;
129 }
130
131 $this->wpforo->notice->add('User group add error', 'error');
132 return FALSE;
133 }
134
135 function edit( $groupid, $title, $cans, $description = '', $role = NULL, $access = NULL ){
136
137 if( $groupid == 1 ) return false;
138 if( !current_user_can('administrator') ){
139 $this->wpforo->notice->add('Permission denied', 'error');
140 return FALSE;
141 }
142
143 $cans = wpforo_parse_args( $cans, array_map('wpforo_return_zero', $this->cans) );
144 $usergroup = $this->get_usergroup( $groupid );
145 $role = is_null($role) ? $usergroup['role'] : $role;
146 $access = is_null($access) ? $usergroup['access'] : $access;
147
148 if( FALSE !== $this->wpforo->db->update(
149 $this->wpforo->db->prefix . 'wpforo_usergroups',
150 array(
151 'name' => sanitize_text_field($title),
152 'cans' => serialize( $cans ),
153 'description' => $description,
154 'utitle' => $usergroup['utitle'],
155 'role' => $role,
156 'access' => $access
157 ),
158 array( 'groupid' => intval($groupid) ),
159 array(
160 '%s',
161 '%s',
162 '%s',
163 '%s',
164 '%s',
165 '%s'
166 ),
167 array( '%d' ))
168 ){
169 $this->wpforo->notice->add('User group successfully edited', 'success');
170 return $groupid;
171 }
172
173 $this->wpforo->notice->add('User group edit error', 'error');
174 return FALSE;
175 }
176
177 function delete(){
178
179 if( !current_user_can('administrator') ){
180 $this->wpforo->notice->add('Permission denied', 'error');
181 return FALSE;
182 }
183
184 if( isset($_GET['action']) && $_GET['action'] == 'del' && isset($_GET['gid']) && $_GET['gid'] != 1 && $_GET['gid'] != 4 ){
185 $status = FALSE;
186 extract($_POST['usergroup'], EXTR_OVERWRITE);
187 $mergeid = intval($mergeid);
188 $insert_gid = $_GET['gid'];
189 #################################################### USERS
190 if(isset($mergeid)){
191 $status = $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix ."wpforo_profiles` SET `groupid` = " . intval($mergeid) . " WHERE `groupid` = " . intval($insert_gid) );
192 $notice = wpforo_phrase('Usergroup has been successfully deleted. All users of this usergroup have been moved to the usergroup you\'ve chosen', false);
193 }else{
194 $status = $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix ."wpforo_profiles` SET `status` = 'trashed' WHERE `groupid` = " . intval($insert_gid) );
195 $notice = wpforo_phrase('Usergroup has been successfully deleted.');
196 }
197 #################################################### END USERS
198 if( $status !== FALSE ){
199 if( $this->wpforo->db->query("DELETE FROM `".$this->wpforo->db->prefix ."wpforo_usergroups` WHERE `groupid` = " . intval($insert_gid) ) ){
200 $this->wpforo->notice->add($notice, 'success');
201 return TRUE;
202 }
203 }
204 }
205 $this->wpforo->notice->add('Can\'t delete this Usergroup', 'error');
206 return FALSE;
207 }
208
209 function get_usergroup( $groupid = 4 ){
210 // Guest UsergroupID = 4
211 $cache = $this->wpforo->cache->on('memory_cashe');
212 if( $cache && isset(self::$cache['usergroup'][$groupid]) ){
213 return self::$cache['usergroup'][$groupid];
214 }
215 $usergroup = $this->wpforo->db->get_row("SELECT * FROM `".$this->wpforo->db->prefix."wpforo_usergroups` WHERE `groupid` = ".intval($groupid), ARRAY_A);
216 if($cache && isset($groupid)){
217 self::$cache['usergroup'][$groupid] = $usergroup;
218 }
219 return $usergroup;
220 }
221
222 function get_usergroups( $field = 'full' ){
223 $cache = $this->wpforo->cache->on('memory_cashe');
224 if( $cache && isset(self::$cache['usergroups'][$field]) ) return self::$cache['usergroups'][$field];
225
226 if( $field == 'full' ){
227 $results = $this->wpforo->db->get_results("SELECT * FROM `".$this->wpforo->db->prefix."wpforo_usergroups`", ARRAY_A);
228 }else{
229 $results = $this->wpforo->db->get_col("SELECT `$field` FROM `".$this->wpforo->db->prefix."wpforo_usergroups`");
230 }
231
232 if( $cache ) self::$cache['usergroups'][$field] = $results;
233 return $results;
234 }
235
236 function get_groupid_by_userid( $userid ){
237 $cache = $this->wpforo->cache->on('memory_cashe');
238 if( $cache && isset(self::$cache['user'][$userid]) ){
239 return self::$cache['user'][$userid];
240 }
241 $groupid = $this->wpforo->db->get_var("SELECT `groupid` FROM `".$this->wpforo->db->prefix ."wpforo_profiles` WHERE `userid` = " . intval($userid));
242 if($cache && isset($groupid)){
243 self::$cache['user'][$userid] = $groupid;
244 }
245 return $groupid;
246 }
247
248 function show_selectbox( $groupid = 0, $exclude = array() ){
249 if( !$groupid = intval($groupid) ) $groupid = (isset($_POST['usergroup']['groupid'])) ? intval($_POST['usergroup']['groupid']) : 0;
250 if( !$groupid ) $groupid = $this->default_groupid;
251 if( empty($exclude) && isset($_GET['gid']) && intval($_GET['gid']) ) $exclude[] = intval($_GET['gid']);
252 $ugroups = $this->usergroup_list_data();
253 foreach($ugroups as $ugroup){
254 if( in_array($ugroup['groupid'], $exclude) ) continue;
255 echo '<option value="'.esc_attr($ugroup['groupid']).'" '.($groupid == $ugroup['groupid'] ? 'selected' : '').'>' . esc_html( __($ugroup['name'], 'wpforo') ) . '</option>';
256 }
257 }
258 }