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 / wpf-actions.php

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

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