PluginProbe
wpForo Forum / 1.2.0
wpForo Forum v1.2.0
3.1.7 3.1.6 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 All 139 releases
wpforo / wpf-includes / wpf-actions.php

wpf-actions.php in wpForo Forum 1.2.0, at wpf-includes/wpf-actions.php

754 lines 29.2 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 function wpforo_actions(){
6
7 global $wpforo;
8
9 do_action( 'wpforo_actions' );
10
11 if( isset($_POST['wpfreg']) && !empty($_POST['wpfreg']) && $userid = $wpforo->member->create($_POST['wpfreg'])){
12 wpforo_verify_form('ref');
13 wp_redirect( $wpforo->member->get_profile_url( $userid, ( is_user_logged_in() ? 'account' : 'profile' ) ) );
14 exit();
15 }
16
17 if(isset($_POST['wpforologin']) && isset($_POST['log']) && isset($_POST['pwd'])){
18 wpforo_verify_form('ref');
19 if ( !is_wp_error( $user = wp_signon() ) ) {
20 $wpf_login_times = get_user_meta($user->ID, '_wpf_login_times', true);
21 if( isset($user->ID) && $wpf_login_times >= 1) {
22 $name = ( isset($user->data->display_name) ) ? $user->data->display_name : '';
23 $wpforo->notice->add( sprintf( 'Welcome back %s!', esc_html($name) ) , 'success');
24 }
25 else{
26 $wpforo->notice->add('Welcome to our Community!', 'success');
27 }
28 (int)$wpf_login_times++;
29 update_user_meta( $user->ID, '_wpf_login_times', $wpf_login_times );
30 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) );
31 exit();
32 }else{
33 $args = array();
34 foreach($user->errors as $u_err) $args[] = $u_err[0];
35 $wpforo->notice->add($args, 'error');
36 wp_redirect( wpforo_get_request_uri() );
37 exit();
38 }
39 }
40
41 extract($wpforo->current_object, EXTR_OVERWRITE);
42
43 if( $template == 'profile' && !isset($username) && !isset($userid) ){
44 wp_redirect( WPFORO_BASE_URL );
45 exit();
46 }
47
48 if(isset($_POST['wpforo_member_submit'])){
49 if(isset($_POST['member']['userid']) && $_POST['member']['userid']){
50 wpforo_verify_form();
51
52 if( !( intval($_POST['member']['userid']) == $wpforo->current_userid ||
53 ( $wpforo->perm->usergroup_can('em') && $wpforo->perm->user_can_manage_user( $wpforo->current_userid, intval($_POST['member']['userid']) )) ) ){
54 $wpforo->notice->clear();
55 $wpforo->notice->add('Permission denied', 'error');
56 wp_redirect(wpforo_get_request_uri());
57 exit();
58 }
59
60 $edit_response = $wpforo->member->edit();
61 if( isset($_POST['member']['avatar_type']) && $_POST['member']['avatar_type'] == 'custom' ) $wpforo->member->upload_avatar();
62
63 if( isset($_POST['member']['old_pass'])
64 && isset($_POST['member']['new_pass'])
65 && isset($_POST['member']['re_new_pass'])
66 && $_POST['member']['new_pass'] && $_POST['member']['re_new_pass'] && $_POST['member']['old_pass'] ){
67 if( $_POST['member']['new_pass'] == $_POST['member']['re_new_pass'] ){
68 $old_pass = $_POST['member']['old_pass'];
69 $user_pass = $_POST['member']['user_pass'];
70 $userid = intval($_POST['member']['userid']);
71 $new_pass = $_POST['member']['new_pass'];
72 if ( wp_check_password( $old_pass, $user_pass, $userid) ){
73 wp_set_password( $new_pass, $userid );
74 }else{
75 $wpforo->notice->clear();
76 $wpforo->notice->add('Old password is wrong', 'error');
77 }
78 }else{
79 $wpforo->notice->clear();
80 $wpforo->notice->add('New Passwords do not match', 'error');
81 }
82 }
83
84 $wpforo->member->reset(intval($_POST['member']['userid']));
85 if( $edit_response && $profile_url = $wpforo->member->get_profile_url( sanitize_title($_POST['member']['user_nickname']), 'account') ){
86 wp_redirect($profile_url);
87 exit();
88 }
89 }
90 wp_redirect(wpforo_get_request_uri());
91 exit();
92 }
93
94 if( isset($_POST['topic']['save']) && isset($_REQUEST['topic']['action']) ){
95 if( $_REQUEST['topic']['action'] == 'add' ){
96 wpforo_verify_form();
97 if( $topicid = $wpforo->topic->add() ){
98 wpforo_clean_cache();
99 wp_redirect( $wpforo->topic->get_topic_url($topicid) );
100 exit();
101 }
102 }elseif( $_REQUEST['topic']['action'] == 'edit' ){
103 wpforo_verify_form();
104 if( $topicid = $wpforo->topic->edit() ){
105 wpforo_clean_cache();
106 wp_redirect( $wpforo->topic->get_topic_url($topicid) );
107 exit();
108 }
109 }
110 wp_redirect( wpforo_get_request_uri() );
111 exit();
112 }
113
114 if( isset($_POST['post']['save']) ){
115 if( $_POST['post']['save'] != 'move' && isset($_REQUEST['post']['action']) ){
116 if($_REQUEST['post']['action'] == 'add'){
117 wpforo_verify_form();
118 if( $postid = $wpforo->post->add() ){
119 wpforo_clean_cache();
120 wp_redirect( $wpforo->post->get_post_url( $postid ) );
121 exit();
122 }
123 }elseif($_REQUEST['post']['action'] == 'edit'){
124 wpforo_verify_form();
125 if( $postid = $wpforo->post->edit() ){
126 wpforo_clean_cache();
127 wp_redirect( $wpforo->post->get_post_url( $postid ) );
128 exit();
129 }
130 }
131 }
132
133 if($_POST['post']['save'] == 'move' && isset($_POST['movetopicid']) && isset($_POST['topic']['forumid'])){
134 wpforo_verify_form();
135 $move_topicid = intval($_POST['movetopicid']);
136 $move_forumid = intval($_POST['topic']['forumid']);
137 $wpforo->topic->move( $move_topicid, $move_forumid );
138 wpforo_clean_cache();
139 wp_redirect( wpforo_get_request_uri() );
140 exit();
141 }
142
143 wp_redirect( wpforo_get_request_uri() );
144 exit();
145 }
146
147 ## Subscriptions
148 if( isset($_GET['wpforo']) && ($_GET['wpforo'] == 'sbscrbconfirm' || $_GET['wpforo'] == 'unsbscrb') && isset($_GET['key']) && $_GET['key'] ){
149 $sbs_key = sanitize_text_field($_GET['key']);
150 if( $_GET['wpforo'] == 'sbscrbconfirm' ){
151 $wpforo->sbscrb->edit($sbs_key);
152 }else{
153 $wpforo->sbscrb->delete($sbs_key);
154 }
155 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) );
156 exit();
157 }
158
159 ## Resolved
160 if( isset($_GET['wpforo']) && $_GET['wpforo'] == 'solved' && $_GET['tid'] ){
161 $topicid = intval($_GET['tid']);
162
163 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) );
164 exit();
165 }
166
167 ## Private
168 if( isset($_GET['wpforo']) && $_GET['wpforo'] == 'private' && $_GET['tid'] ){
169 $topicid = intval($_GET['tid']);
170
171 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) );
172 exit();
173 }
174
175 ###############################################################
176 /**
177 *
178 * BACK-END
179 *
180 */
181
182 ##Settings action
183 if( wpforo_is_admin() && isset($_POST['wpforo_screen_option']['value']) ){
184 if(!current_user_can('administrator')) return;
185 update_option('wpforo_count_per_page', $_POST['wpforo_screen_option']['value']);
186 }
187
188 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-community' && isset($_GET['action']) && $_GET['action'] ){
189 if(!current_user_can('administrator')){
190 $wpforo->notice->add('Permission denied', 'error');
191 wp_redirect(admin_url());
192 exit();
193 }
194 if( $_GET['action'] == 'reset_fstat' && check_admin_referer( 'wpforo_reset_forums_stat' ) ){
195 $forums = $wpforo->db->get_results("SELECT `forumid` FROM " . $wpforo->db->prefix . "wpforo_forums ORDER BY `forumid` ASC", ARRAY_A);
196 if(!empty($forums)){
197 foreach($forums as $forum){
198 $topics = $wpforo->db->get_var( "SELECT COUNT(*) as count FROM `" . $wpforo->db->prefix . "wpforo_topics` WHERE `forumid` = " . intval($forum['forumid']) );
199 $posts = $wpforo->db->get_var( "SELECT COUNT(*) as count FROM `" . $wpforo->db->prefix . "wpforo_posts` WHERE `forumid` = " . intval($forum['forumid']) );
200 $wpforo->db->query("UPDATE `" . $wpforo->db->prefix . "wpforo_forums` SET `topics` = " . intval($topics) . ", `posts` = " . intval($posts) . " WHERE `forumid` = " . intval($forum['forumid']) );
201 }
202 $wpforo->notice->add('Updated Successfully!', 'success');
203 }
204 }
205 if( $_GET['action'] == 'reset_ustat' && check_admin_referer( 'wpforo_reset_users_stat' ) ){
206 $users = $wpforo->db->get_results("SELECT `userid` FROM " . $wpforo->db->prefix . "wpforo_profiles ORDER BY `posts` DESC", ARRAY_A);
207 if(!empty($users)){
208 foreach($users as $user){
209 $questions = $wpforo->member->get_questions_count( $user['userid'] );
210 $answers = $wpforo->member->get_answers_count( $user['userid'] );
211 $posts = $wpforo->member->get_replies_count( $user['userid'] );
212 $question_comments = $wpforo->member->get_question_comments_count( $user['userid'] );
213 $wpforo->db->query("UPDATE `" . $wpforo->db->prefix . "wpforo_profiles`
214 SET `posts` = " . intval($posts) . ", `answers` = " . intval($answers) . ", `comments` = " . intval($question_comments) . ", `questions` = " . intval($questions) . "
215 WHERE `userid` = " . intval( $user['userid'] ) );
216 }
217 $wpforo->notice->add('Updated Successfully!', 'success');
218 }
219 }
220 if( $_GET['action'] == 'reset_phrase_cache' && check_admin_referer( 'wpforo_reset_phrase_cache' ) ){
221 $wpforo->phrase->clear_cache();
222 $wpforo->notice->add('Deleted Successfully!', 'success');
223 }
224 if( $_GET['action'] == 'reset_user_cache' && check_admin_referer( 'wpforo_reset_user_cache' ) ){
225 $wpforo->member->clear_db_cache();
226 $wpforo->notice->add('Deleted Successfully!', 'success');
227 }
228 }
229
230 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-settings' ){
231
232 if(!current_user_can('administrator')){
233 $wpforo->notice->add('Permission denied', 'error');
234 wp_redirect(admin_url());
235 exit();
236 }
237
238 ##General options
239 if( isset($_POST['wpforo_general_options']) ){
240 check_admin_referer( 'wpforo-settings-general' );
241
242 if( isset($_POST['wpforo_use_home_url']) && $_POST['wpforo_use_home_url'] ){
243 update_option('wpforo_use_home_url', 1);
244 if( isset($_POST['wpforo_excld_urls']) && $_POST['wpforo_excld_urls'] )
245 update_option('wpforo_excld_urls', trim($_POST['wpforo_excld_urls']));
246 }else{
247 update_option('wpforo_use_home_url', 0);
248 }
249
250 if( isset($_POST['wpforo_url']) && $permastruct = utf8_uri_encode( $_POST['wpforo_url'] ) )
251 if( update_option('wpforo_url', esc_url( home_url('/') ) . trim($permastruct, '/') . "/")
252 && update_option('wpforo_permastruct', trim($permastruct, '/')) ){
253 $wpforo->notice->add('Forum Base URL successfully updated', 'success');
254 }else{
255 $wpforo->notice->add('Successfully updated', 'success');
256 }
257
258 if( update_option('wpforo_general_options', $_POST['wpforo_general_options']) ){
259 $wpforo->notice->add('General options successfully updated', 'success');
260 }else{
261 $wpforo->notice->add('Successfully updated', 'success');
262 }
263
264 $wpforo->member->clear_db_cache();
265
266 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=general' ) );
267 exit();
268 }
269
270 ##add new lang action
271 if( isset($_FILES['add_lang']) ){
272 check_admin_referer( 'wpforo-settings-language' );
273 $wpforo->phrase->add_lang();
274 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=general' ) );
275 exit();
276 }
277
278 ##Forums
279 if( isset($_POST['wpforo_forum_options']) ){
280 check_admin_referer( 'wpforo-settings-forums' );
281 if( update_option('wpforo_forum_options', $_POST['wpforo_forum_options']) ){
282 $wpforo->notice->add('Forum options successfully updated', 'success');
283 }else{
284 $wpforo->notice->add('Forum options successfully updated, but previous value not changed', 'success');
285 }
286 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=forums' ) );
287 exit();
288 }
289
290 ##Posts
291 if( isset($_POST['wpforo_post_options']) ){
292 check_admin_referer( 'wpforo-settings-posts' );
293 $_POST['wpforo_post_options']['eot_durr'] = intval($_POST['wpforo_post_options']['eot_durr']) * 60;
294 $_POST['wpforo_post_options']['dot_durr'] = intval($_POST['wpforo_post_options']['dot_durr']) * 60;
295 $_POST['wpforo_post_options']['eor_durr'] = intval($_POST['wpforo_post_options']['eor_durr']) * 60;
296 $_POST['wpforo_post_options']['dor_durr'] = intval($_POST['wpforo_post_options']['dor_durr']) * 60;
297 $_POST['wpforo_post_options']['max_upload_size'] = intval(wpforo_human_size_to_bytes($_POST['wpforo_post_options']['max_upload_size'].'M'));
298 if( update_option('wpforo_post_options', $_POST['wpforo_post_options']) ){
299 $wpforo->notice->add('Post options successfully updated', 'success');
300 }else{
301 $wpforo->notice->add('Post options successfully updated, but previous value not changed', 'success');
302 }
303 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=posts' ) );
304 exit();
305 }
306
307 ##Members
308 if( isset($_POST['wpforo_member_options']) ){
309 check_admin_referer( 'wpforo-settings-members' );
310 $_POST['wpforo_member_options']['online_status_timeout'] = intval($_POST['wpforo_member_options']['online_status_timeout']) * 60;
311 if( update_option('wpforo_member_options', $_POST['wpforo_member_options']) ){
312 $wpforo->notice->add('Member options successfully updated', 'success');
313 }else{
314 $wpforo->notice->add('Member options successfully updated, but previous value not changed', 'success');
315 }
316 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=members' ) );
317 exit();
318 }
319
320 ##Features
321 if( isset($_POST['wpforo_features']) ){
322 check_admin_referer( 'wpforo-features' );
323 if( update_option('wpforo_features', $_POST['wpforo_features']) ){
324 $wpforo->notice->add('Features successfully updated', 'success');
325 }else{
326 $wpforo->notice->add('Features successfully updated, but previous value not changed', 'success');
327 }
328 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=features' ) );
329 exit();
330 }
331
332 ##Theme options
333 if( isset($_POST['wpforo_theme_options']) && isset($_POST['wpforo_style_options']) ){
334 check_admin_referer( 'wpforo-settings-styles' );
335 $wpforo->theme_options['style'] = sanitize_text_field($_POST['wpforo_theme_options']['style']);
336 $wpforo->theme_options['styles'] = $_POST['wpforo_theme_options']['styles'];
337 update_option('wpforo_style_options', $_POST['wpforo_style_options']);
338 update_option('wpforo_theme_options', $wpforo->theme_options);
339 $wpforo->notice->add('Theme options successfully updated', 'success');
340 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=styles' ) );
341 exit();
342 }
343
344 ##Subscription
345 if( isset($_POST['wpforo_subscribe_options']) ){
346 check_admin_referer( 'wpforo-settings-emails' );
347 if( update_option('wpforo_subscribe_options', $_POST['wpforo_subscribe_options']) ){
348 $wpforo->notice->add('Subscribe options successfully updated', 'success');
349 }else{
350 $wpforo->notice->add('Subscribe options successfully updated, but previous value not changed', 'success');
351 }
352 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=emails' ) );
353 exit();
354 }
355
356 }
357
358 ### forum action ###
359 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-forums' ){
360
361 if(!current_user_can('administrator')){
362 $wpforo->notice->add('Permission denied', 'error');
363 wp_redirect(admin_url());
364 exit();
365 }
366
367 if( isset($_POST['wpforo_submit']) && isset($_REQUEST['forum']) && isset($_GET['action']) ){
368 check_admin_referer( 'wpforo-forum-addedit' );
369 if( $_GET['action'] == 'add' ){
370 if( $forumid = $wpforo->forum->add() ){
371 wp_redirect( admin_url( 'admin.php?page=wpforo-forums' ) );
372 exit();
373 }
374 }elseif( $_GET['action'] == 'edit' && isset($_GET['id']) ){
375 $forumid = $wpforo->forum->edit();
376 }
377 if( isset($forumid) && $forumid ){
378 wp_redirect( admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=edit' ) );
379 }else{
380 wp_redirect( wpforo_get_request_uri() );
381 }
382 exit();
383 }
384
385 if(isset($_POST['wpforo_delete']) && $_GET['action'] == 'del'){
386 check_admin_referer( 'wpforo-forum-delete' );
387 $wpforo->forum->delete();
388 wp_redirect( admin_url( 'admin.php?page=wpforo-forums' ) );
389 exit();
390 }
391
392 if(isset($_POST['forums_hierarchy_submit'])){
393 check_admin_referer( 'wpforo-forums-hierarchy' );
394 $wpforo->forum->update_hierarchy();
395 wp_redirect( admin_url( 'admin.php?page=wpforo-forums' ) );
396 exit();
397 }
398 }
399
400 ##Moderation
401 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-moderations' ){
402
403 if(!$wpforo->perm->usergroup_can('aum')){
404 $wpforo->notice->add('Permission denied', 'error');
405 wp_redirect(admin_url());
406 exit();
407 }
408
409 $u_action = '';
410 if( !empty($_GET['action']) && $_GET['action'] != '-1' ){
411 $u_action = $_GET['action'];
412 }elseif( !empty($_GET['action2']) && $_GET['action2'] != '-1' ){
413 $u_action = $_GET['action2'];
414 }
415 $bulk = FALSE;
416 $pids = array();
417 if( !empty($_GET['id']) && ($pid = wpforo_bigintval($_GET['id'])) ){
418 $pids = (array) $pid;
419 }elseif( !empty($_GET['ids']) && ($ids = trim($_GET['ids'])) ){
420 $bulk = TRUE;
421 $ids = explode(',', urldecode($ids));
422 $pids = array_map('wpforo_bigintval', array_filter($ids));
423 }
424 $pids = array_diff($pids, (array) $wpforo->current_userid);
425
426 if( $u_action && !empty($pids) ) {
427 if ($u_action == 'del') {
428 if( $bulk ){
429 !check_admin_referer( 'bulk_action_moderation' );
430 }else{
431 !check_admin_referer( 'wpforo_admin_table_action_delete' );
432 }
433 foreach ($pids as $pid) $wpforo->post->delete($pid);
434 wp_redirect(admin_url('admin.php?page=wpforo-moderations'));
435 exit();
436 } elseif ($u_action == 'approve') {
437 if( $bulk ){
438 !check_admin_referer( 'bulk_action_moderation' );
439 }else{
440 !check_admin_referer( 'wpforo_admin_table_action_approve' );
441 }
442 foreach ($pids as $pid) $wpforo->moderation->post_approve($pid);
443 wp_redirect(admin_url('admin.php?page=wpforo-moderations'));
444 exit();
445 } elseif ($u_action == 'unapprove') {
446 if( $bulk ){
447 !check_admin_referer( 'bulk_action_moderation' );
448 }else{
449 !check_admin_referer( 'wpforo_admin_table_action_approve' );
450 }
451 foreach ($pids as $pid) $wpforo->moderation->post_unapprove($pid);
452 wp_redirect(admin_url('admin.php?page=wpforo-moderations'));
453 exit();
454 }
455 }
456 }
457
458 ##Phrases
459 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-phrases' ){
460
461 if(!current_user_can('administrator')){
462 $wpforo->notice->add('Permission denied', 'error');
463 wp_redirect(admin_url());
464 exit();
465 }
466
467 if(isset($_POST['phrase']['save'])){
468 check_admin_referer( 'wpforo-phrases-edit' );
469 $wpforo->phrase->edit();
470 wp_redirect( admin_url( 'admin.php?page=wpforo-phrases' ) );
471 exit();
472 }
473
474 if( isset($_POST['phrase']['add']) && !empty($_POST['phrase']['value']) ){
475 check_admin_referer( 'wpforo-phrase-add' );
476 $wpforo->phrase->add();
477 wp_redirect( admin_url( 'admin.php?page=wpforo-phrases' ) );
478 exit();
479 }
480 }
481
482
483 ##Members
484 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-members' ){
485 $u_action = '';
486 if( !empty($_GET['action']) && $_GET['action'] != '-1' ){
487 $u_action = $_GET['action'];
488 }elseif( !empty($_GET['action2']) && $_GET['action2'] != '-1' ){
489 $u_action = $_GET['action2'];
490 }
491 $bulk = FALSE;
492 $uids = array();
493 if( !empty($_GET['id']) && ($uid = intval($_GET['id'])) ){
494 $uids = (array) $uid;
495 }elseif( !empty($_GET['ids']) && ($ids = trim($_GET['ids'])) ){
496 $bulk = TRUE;
497 $ids = explode(',', urldecode($ids));
498 $uids = array_map('intval', array_filter($ids));
499 }
500 $uids = array_diff($uids, (array) $wpforo->current_userid);
501
502 if( $u_action && !empty($uids) ){
503
504 if($u_action == 'del'){
505 $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $uids ) );
506 $url = str_replace( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
507 wp_redirect( $url );
508 exit();
509 }elseif($u_action == 'ban'){
510 if( $bulk ){
511 !check_admin_referer( 'bulk_action_member' );
512 }else{
513 !check_admin_referer( 'wpforo_admin_table_action_ban' );
514 }
515 foreach($uids as $uid) $wpforo->member->ban($uid);
516 }elseif($u_action == 'unban'){
517 if( $bulk ){
518 !check_admin_referer( 'bulk_action_member' );
519 }else{
520 !check_admin_referer( 'wpforo_admin_table_action_ban' );
521 }
522 foreach($uids as $uid) $wpforo->member->unban($uid);
523 }
524
525 wp_redirect( admin_url( 'admin.php?page=wpforo-members' ) );
526 exit();
527 }
528 }
529
530
531 ##Usergroups
532 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-usergroups' ){
533
534 if(!current_user_can('administrator')){
535 $wpforo->notice->add('Permission denied', 'error');
536 wp_redirect(admin_url());
537 exit();
538 }
539
540 if(isset( $_POST['usergroup']['action'] ) && ( $_POST['usergroup']['action'] == 'add' || $_POST['usergroup']['action'] == 'edit' ) ){
541 check_admin_referer( 'wpforo-usergroup-addedit' );
542 $board_cans = ( isset($_POST['cans']) ? $_POST['cans'] : array() );
543 if( $_POST['usergroup']['action'] == 'add' ){
544 $insert_usergroup_name = sanitize_text_field($_POST['usergroup']['name']);
545 $wpforo->usergroup->add( $insert_usergroup_name, $board_cans );
546 wp_redirect( admin_url( 'admin.php?page=wpforo-usergroups' ) );
547 exit();
548 }elseif( $_POST['usergroup']['action'] == 'edit' ){
549 $insert_usergroup_id = intval($_GET['gid']);
550 $insert_usergroup_name = sanitize_text_field($_POST['usergroup']['name']);
551 $wpforo->usergroup->edit( $insert_usergroup_id, $insert_usergroup_name, $board_cans );
552 wp_redirect( admin_url( 'admin.php?page=wpforo-usergroups' ) );
553 exit();
554 }
555
556 }
557 if(isset($_GET['action']) && $_GET['action']=='del' && isset($_POST['usergroup']['submit']) && $_POST['usergroup']['submit'] == 'Delete'){
558 check_admin_referer( 'wpforo-usergroup-delete' );
559 $wpforo->usergroup->delete();
560 wp_redirect( admin_url( 'admin.php?page=wpforo-usergroups' ) );
561 exit();
562 }
563 }
564
565 ##### Admin Accesses action ######
566 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-settings' && isset($_GET['tab']) && $_GET['tab'] == 'accesses' ){
567
568 if(!current_user_can('administrator')){
569 $wpforo->notice->add('Permission denied', 'error');
570 wp_redirect(admin_url());
571 exit();
572 }
573
574 if( isset( $_POST['access'] ) && $_POST['access']['action'] == 'add' ){
575 check_admin_referer( 'wpforo-access-addedit' );
576 $cans = ( isset($_POST['cans'] ) ? $_POST['cans'] : array() );
577 $insert_access_name = sanitize_text_field($_POST['access']['name']);
578 $wpforo->perm->add( $insert_access_name, $cans );
579 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=accesses' ) );
580 exit();
581 }elseif( isset( $_POST['access'] ) && $_POST['access']['action'] == 'edit' ){
582 check_admin_referer( 'wpforo-access-addedit' );
583 $cans = ( isset($_POST['cans'] ) ? $_POST['cans'] : array() );
584 $insert_access_key = sanitize_text_field($_POST['access']['key']);
585 $insert_access_name = sanitize_text_field($_POST['access']['name']);
586 $wpforo->perm->edit( $insert_access_name, $cans, $insert_access_key );
587 wp_redirect( wpforo_get_request_uri() );
588 exit();
589 }elseif( isset($_GET['action']) && $_GET['action'] == 'del' && isset($_GET['accessid']) ){
590
591 if( !check_admin_referer( 'wpforo_access_delete' )){
592 $wpforo->notice->add('Permission denied', 'error');
593 wp_redirect(admin_url());
594 exit();
595 }
596
597 $insert_access_id = intval($_GET['accessid']);
598 $wpforo->perm->delete( $insert_access_id );
599 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=accesses' ) );
600 exit();
601 }
602 }
603
604 ##Themes
605 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-themes' && isset($_GET['theme']) ){
606
607 if(!current_user_can('administrator')){
608 $wpforo->notice->add('Permission denied', 'error');
609 wp_redirect(admin_url());
610 exit();
611 }
612
613 $theme = sanitize_text_field( $_GET['theme'] );
614 if( $_GET['action'] == 'activate' || $_GET['action'] == 'install' || $_GET['action'] == 'reset' ){
615 if( $_GET['action'] == 'activate' ){
616 $new_theme = get_option( 'wpforo_theme_archive_' . $theme );
617 }
618 elseif( $_GET['action'] == 'install' || $_GET['action'] == 'reset' ){
619 $new_theme = $wpforo->tpl->find_theme( $theme );
620 if( $_GET['action'] == 'reset' ){
621 delete_option( 'wpforo_theme_archive_' . $theme );
622 }
623 }
624 $current_theme = $wpforo->theme_options;
625 if( !empty($new_theme) ){
626 update_option( 'wpforo_theme_options', $new_theme );
627 if( $_GET['action'] != 'reset' ){
628 update_option( 'wpforo_theme_archive_' . $wpforo->theme, $current_theme );
629 }
630 }
631 wp_redirect( admin_url( 'admin.php?page=wpforo-themes' ) );
632 exit();
633 }
634 if( $_GET['action'] == 'delete' ){
635 $remove_dir = WPFORO_THEME_DIR . '/' . $theme;
636 if( is_dir($remove_dir) && strlen($theme) > 0 ){
637 wpforo_remove_directory( $remove_dir );
638 }
639 wp_redirect( admin_url( 'admin.php?page=wpforo-themes' ) );
640 exit();
641 }
642 }
643
644
645 if( isset($_GET['forum']) && $_GET['forum'] && isset($_GET['type']) && $_GET['type'] == 'rss2' ){
646 $forumid = intval($_GET['forum']);
647 $forum = $wpforo->forum->get_forum($forumid);
648 $forum['forumurl'] = $wpforo->forum->get_forum_url($forumid);
649
650 if(isset($_GET['topic']) && $_GET['topic']){
651 $topicid = intval($_GET['topic']);
652 $topic = $wpforo->topic->get_topic($topicid);
653 $topic['topicurl'] = $wpforo->topic->get_topic_url($topicid);
654 $posts = $wpforo->post->get_posts( array( 'topicid' => $topicid, 'row_count' => 10, 'orderby' => 'created', 'order' => 'DESC', 'check_private' => true ) );
655 foreach($posts as $key => $post){
656 $member = $wpforo->member->get_member($post['userid']);
657 $posts[$key]['description'] = wpforo_text( trim(strip_tags($post['body'])), 190, false );
658 $posts[$key]['content'] = trim($post['body']);
659 $posts[$key]['posturl'] = $wpforo->post->get_post_url($post['postid']);
660 $posts[$key]['author'] = $member['display_name'];
661 }
662 $wpforo->feed->rss2_topic($forum, $topic, $posts);
663 }
664 else{
665 $topics = $wpforo->topic->get_topics( array( 'forumid' => $forumid, 'row_count' => 10, 'orderby' => 'created', 'order' => 'DESC' ) );
666 foreach($topics as $key => $topic){
667 $post = $wpforo->post->get_post($topic['first_postid']);
668 $member = $wpforo->member->get_member($topic['userid']);
669 $topics[$key]['description'] = wpforo_text( trim(strip_tags($post['body'])), 190, false );
670 $topics[$key]['content'] = trim($post['body']);
671 $topics[$key]['topicurl'] = $wpforo->topic->get_topic_url($topic['topicid']);
672 $topics[$key]['author'] = $member['display_name'];
673 }
674 $wpforo->feed->rss2_forum($forum, $topics);
675 }
676 exit();
677 }
678
679 ##Tools
680 if( wpforo_is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-tools' ){
681
682 if(!current_user_can('administrator')){
683 $wpforo->notice->add('Permission denied', 'error');
684 wp_redirect(admin_url());
685 exit();
686 }
687
688 if( isset($_POST['wpforo_tools_antispam']) ){
689 check_admin_referer( 'wpforo-tools-antispam' );
690 if( update_option('wpforo_tools_antispam', $_POST['wpforo_tools_antispam']) ){
691 $wpforo->notice->add('Settings successfully updated', 'success');
692 }
693 wp_redirect( admin_url( 'admin.php?page=wpforo-tools&tab=antispam' ) );
694 exit();
695 }
696
697 if(isset($_GET['action']) && $_GET['action']=='delete-spam-file' && isset($_GET['sfname']) && $_GET['sfname']){
698 $filename = sanitize_file_name($_GET['sfname']);
699 if(check_admin_referer( 'wpforo_tools_antispam_files')){
700 if(!empty($filename)){
701 $filename = str_replace( array('../', './', '/'), '', $filename );
702 $filename = urldecode( $filename );
703 $upload_dir = wp_upload_dir();
704 $default_attachments_dir = $upload_dir['basedir'] . '/wpforo/default_attachments/';
705 $file = $default_attachments_dir . $filename;
706 $attachmentid = $wpforo->post->get_attachment_id( '/' . $filename );
707 if ( !wp_delete_attachment( $attachmentid ) ){
708 @unlink($file);
709 }
710 $wpforo->notice->add( 'Deleted', 'success' );
711 wp_redirect( admin_url( 'admin.php?page=wpforo-tools&tab=antispam' ) );
712 exit();
713 }
714 }
715 wp_redirect( admin_url( 'admin.php?page=wpforo-tools&tab=antispam' ) );
716 exit();
717 }
718
719 if(isset($_GET['action']) && $_GET['action']=='delete-all' && isset($_GET['level']) && $_GET['level']){
720 if(check_admin_referer( 'wpforo_tools_antispam_files')){
721 $delete_level = intval($_GET['level']);
722 $upload_dir = wp_upload_dir();
723 $default_attachments_dir = $upload_dir['basedir'] . '/wpforo/default_attachments/';
724 if(is_dir($default_attachments_dir)){
725 if ($handle = opendir($default_attachments_dir)){
726 while (false !== ($filename = readdir($handle))){
727 $level = 0;
728 if( $filename == '.' || $filename == '..') continue;
729 if( !$level = $wpforo->moderation->spam_file($filename) ) continue;
730 if( $delete_level == $level ){
731 $attachmentid = $wpforo->post->get_attachment_id( '/' . $filename );
732 if ( !wp_delete_attachment( $attachmentid ) ){
733 $file = $default_attachments_dir . $filename; @unlink($file);
734 }
735 }
736 }
737 closedir($handle);
738 $wpforo->notice->add( 'Deleted', 'success' );
739 wp_redirect( admin_url( 'admin.php?page=wpforo-tools&tab=antispam' ) );
740 exit();
741 }
742 }
743 }
744 wp_redirect( admin_url( 'admin.php?page=wpforo-tools&tab=antispam' ) );
745 exit();
746 }
747 }
748
749 do_action( 'wpforo_actions_end' );
750
751 }
752
753
754 ?>