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