forked from ethymos/delibera
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdelibera_plan_restriction.php
348 lines (246 loc) · 9.5 KB
/
delibera_plan_restriction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/**
* On this file we implement plan restriction.
* We have 5 diferent levels:
*
* Caucaso - level 1 - until 30 users - max 5 foruns - no multilang - 1GB space - no private foruns.
* Miscenas - level 2 - until 120 users - max 20 foruns - multilang - 2GB space - no private foruns.
* Creta - level 3 - until 300 users - max 50 foruns - multilang - 3GB space - no private foruns.
* Atenas - level 4 - unlimited users - unlimited - multilang - unlimited - private foruns.
* Olimpo - level 5 - unlimited users - unlimited - multilang - unlimited - private foruns.
*/
/*-------------------------------------- Limited Users ----------------------------------------------------*/
add_filter('wpmu_validate_user_signup','verify_new_user',10,3);
function verify_new_user($var){
if(!is_user_logged_in())
return $var;
$errors = new WP_Error();
$errors = $var['errors'];
// get pricing plan level for the current blog
$blogid = get_current_blog_id();
$princing_plan = get_blog_option($blogid,'product_id');
// get pricing plan level for the current blog
//$princing_plan = get_option('pricing_plan');
//get number of users for this blog
//$users = get_users_of_blog();
//$nusers = count($users);
$nusers =0;
global $blog_id;
switch_to_blog($blog_id);
$adminemail = get_bloginfo('admin_email');
$admin = get_user_by_email($adminemail);
restore_current_blog();
$user_blogs = get_blogs_of_user($admin->ID);
foreach ($user_blogs as $blog)
{
$bid = $blog->userblog_id ;
if($bid == 1)
continue; // does not count
$email = get_blog_option($bid, 'admin_email');
if($email != $adminemail)
continue;//eh apenas membro
$u = get_users_of_blog($bid);
$nusers = $nusers+ count($u);
}
$pname = get_plan_name($princing_plan);
switch ($pname)
{
case 'Cáucaso':
if($nusers == 30)
{
//$errors->add('pricing_plan', __('You have reached the maximum number of users. To add a new user pelase upgrade your plan.','delibera'));
$errors->add('pricing_plan', __('Atingiu o número máximo de usuários permitido. Para adicionar mais usuários por favor actualize o seu plano.','delibera'));
}
break;
case 'Miscenas':
if($nusers == 120)
{
// $errors->add('pricing_plan', __('You have reached the maximum number of users. To add a new user pelase upgrade your plan.','delibera'));
$errors->add('pricing_plan', __('Atingiu o número máximo de usuários permitido. Para adicionar mais usuários por favor actualize o seu plano.','delibera'));
}
break;
case 'Creta':
if($nusers == 300)
{
// $errors->add('pricing_plan', __('You have reached the maximum number of users. To add a new user pelase upgrade your plan.','delibera'));
$errors->add('pricing_plan', __('Atingiu o número máximo de usuários permitido. Para adicionar mais usuários por favor actualize o seu plano.','delibera'));
}
break;
}
$var['errors'] =$errors;
return $var;
}
/*-------------------------------------- End Limited Users ----------------------------------------------------*/
/*-------------------------------------- Limited Forum ----------------------------------------------------*/
add_filter( 'wp_insert_post_data', 'limit_forum',99);
function limit_forum( $data) {
$nposts =0;
global $blog_id;
// get pricing plan level for the current blog
$princing_plan = get_blog_option($blog_id,'product_id');
$current_admin_email = get_blog_option($bid, 'admin_email');
$admin = get_user_by_email($current_admin_email);
$user_blogs = get_blogs_of_user($admin->ID);
foreach ($user_blogs as $blog)
{
$bid = $blog->userblog_id ;
if($bid == 1)
continue; // does not count
$email = get_blog_option($bid, 'admin_email');
error_log('current admin email '.$current_admin_email);
error_log('admin deste blog '.$email);
if($email != $current_admin_email)
continue;//eh apenas membro
switch_to_blog($bid);
$qposts = new WP_Query( array(
'post_type' => 'pauta',
'post_status' => 'publish'
) );
if ( $qposts->posts ){
$nposts = $nposts + count($qposts->posts);
error_log('para o blog '.$bid).'ja tenho este paustas '.count($qposts->posts);
}
restore_current_blog();
}
error_log('total de pautas '.$nposts);
$pname = get_plan_name($princing_plan);
switch ($pname)
{
case 'Cáucaso':
if($nposts > 4)
{
if($_REQUEST['action'] == '')
{
// wp_die(__('You have reached the maximum number of forums. To add a new forum pelase upgrade your plan.','delibera'));
wp_die(__('Atingiu o número máximo de foruns permitido. Para adicionar novo forum por favor actualize o seu plano.','delibera'));
}
}
break;
case 'Miscenas':
if($nposts > 19)
{
if($_REQUEST['action'] == '')
{
// wp_die(__('You have reached the maximum number of forums. To add a new forum pelase upgrade your plan.','delibera'));
wp_die(__('Atingiu o número máximo de foruns permitido. Para adicionar novo forum por favor actualize o seu plano.','delibera'));
}
}
break;
case 'Creta':
if($nposts > 49)
{
if($_REQUEST['action'] == '')
{
// wp_die(__('You have reached the maximum number of forums. To add a new forum pelase upgrade your plan.','delibera'));
wp_die(__('Atingiu o número máximo de foruns permitido. Para adicionar novo forum por favor actualize o seu plano.','delibera'));
}
}
break;
}
return $data;
}
/*-------------------------------------- End Limited Forum ----------------------------------------------------*/
/*-------------------------------------- MultiLang----------------------------------------------------*/
add_action( 'add_meta_boxes_pauta', 'limit_multilang',10,3 );
function limit_multilang( $post_id ) {
// get pricing plan level for the current blog
$blogid = get_current_blog_id();
$princing_plan = get_blog_option($blogid,'product_id');
$pname = get_plan_name($princing_plan);
switch ($pname)
{
case 'Cáucaso':
remove_meta_box('idiomadiv','pauta','side');
break;
}
// No restrictions for others pricing plans
return $post_id;
}
/*-------------------------------------- End Multilang ----------------------------------------------------*/
/*-------------------------------------- Private Forum ----------------------------------------------------*/
/*
* Restriction was directly applied on delibera_registered_users_only.php file.
*
*/
/*-------------------------------------- End Private Forum ----------------------------------------------------*/
/*-------------------------------------- Limited Spance ----------------------------------------------------*/
add_filter( 'wp_handle_upload', 'limit_space',10,1);
function removemediabuttons($cap)
{
$pname = get_plan_name($princing_plan);
$nposts =0;
global $blog_id;
// get pricing plan level for the current blog
$princing_plan = get_blog_option($blog_id,'product_id');
$current_admin_email = get_blog_option($blog_id, 'admin_email');
$admin = get_user_by_email($current_admin_email);
$user_blogs = get_blogs_of_user($admin->ID);
$total = 0;
if(is_array($user_blogs))
{
foreach ($user_blogs as $blog)
{
$bid = $blog->userblog_id ;
if($bid == 1)
continue; // does not count
$email = get_blog_option($bid, 'admin_email');
if($email != $current_admin_email)
continue;//eh apenas membro
switch_to_blog($bid);
$mu = get_option('media_uploaded');
if(!$mu)
$mu=0; //sets to 0 if not yet stored
$total = $total + $mu;
restore_current_blog();
}
}
switch ($pname)
{
case 'Cáucaso':
if($total > 1073741824)
{
remove_all_actions('media_buttons');
// $message = __('You have reached 1GB storage. Please upgrade your plan to keep uploading.','delibera');
$message = __('Atingiu 1GB de upload de arquivos. Para continuar a fazer upload por favor actualize o seu plano.','delibera');
// if we are in Add New Media page
if(isset($_GET['inline'])&& $_GET['inline'])
wp_die($message);
}
break;
case 'Miscenas':
if($total > 2147483648)
{
remove_all_actions('media_buttons');
$message = __('Atingiu 2GB de upload de arquivos. Para continuar a fazer upload por favor actualize o seu plano.','delibera');
//$message = __('You have reached 2GB storage. Please upgrade your plan to keep uploading.','delibera');
// if we are in Add New Media page
if(isset($_GET['inline'])&& $_GET['inline'])
wp_die($message);
}
break;
case 'Creta':
if($total > 3221225472)
{
remove_all_actions('media_buttons');
$message = __('Atingiu 3GB de upload de arquivos. Para continuar a fazer upload por favor actualize o seu plano.','delibera');
// $message = __('You have reached 3GB storage. Please upgrade your plan to keep uploading.','delibera');
// if we are in Add New Media page
if(isset($_GET['inline'])&& $_GET['inline'])
wp_die($message);
}
break;
}
return $cap;
}
add_action('role_has_cap','removemediabuttons',10,1);
//stores size uploaded
function limit_space( $args) {
$mu = get_option('media_uploaded');
if(!$mu)
$mu=0; //sets to 0 if not yet stored
$now = $mu + filesize($args['file']);
update_option('media_uploaded',$now);
return $args;
}
/*-------------------------------------- End Limited Space ----------------------------------------------------*/
?>