PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
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 beta-4, at wpf-includes/wpf-actions.php

519 lines 19.1 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 wp_redirect( $wpforo->member->get_profile_url( $userid, 'account' ) );
13 exit();
14 }
15
16 if(isset($_POST['wpforologin']) && isset($_POST['log']) && isset($_POST['pwd'])){
17 if ( !is_wp_error( $user = wp_signon() ) ) {
18 $wpforo->notice->add('Welcome to our Community!', 'success');
19 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_full_url()) );
20 exit();
21 }else{
22 $args = array();
23 foreach($user->errors as $u_err) $args[] = $u_err[0];
24 $wpforo->notice->add($args, 'error');
25 wp_redirect( wpforo_full_url() );
26 exit();
27 }
28 }
29
30 if(isset($_GET['wpfs'])) $wpforo->current_object['template'] = 'search';
31
32 if( isset($_GET['wpforo']) ){
33 switch($_GET['wpforo']){
34 case 'register':
35 if(!is_user_logged_in()) $wpforo->current_object['template'] = 'register';
36 break;
37 case 'login':
38 if(!is_user_logged_in()) $wpforo->current_object['template'] = 'login';
39 break;
40 case 'logout':
41 wp_logout();
42 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_full_url()) );
43 exit();
44 break;
45 }
46 }
47
48 extract($wpforo->current_object, EXTR_OVERWRITE);
49
50 if( $template == 'profile' && !isset($username) && !isset($userid) ){
51 wp_redirect( WPFORO_BASE_URL );
52 exit();
53 }
54
55 if(isset($_POST['wpforo_member_submit'])){
56 if(isset($_POST['member']['userid']) && $_POST['member']['userid']){
57 wpforo_verify_form();
58 $wpforo->member->edit();
59 if( isset($_POST['member']['avatar_type']) && $_POST['member']['avatar_type'] == 'custom' ) $wpforo->member->upload_avatar();
60 if( isset($_POST['member']['old_pass']) &&
61 isset($_POST['member']['new_pass']) &&
62 isset($_POST['member']['re_new_pass']) &&
63 $_POST['member']['new_pass'] == $_POST['member']['re_new_pass'] &&
64 !$_POST['member']['re_new_pass'] ){
65 $old_pass = trim(substr($_POST['member']['old_pass'], 0, 100));
66 $new_pass = trim(substr($_POST['member']['user_pass'], 0, 100));
67 $userid = intval($_POST['member']['userid']);
68 if ( wp_check_password( $old_pass, $new_pass, $userid) ){
69 wp_set_password( $new_pass, $userid );
70 }
71 }
72 $wpforo->member->reset(intval($_POST['member']['userid']));
73 }
74 wp_redirect(wpforo_full_url());
75 exit();
76 }
77
78 if( isset($_POST['topic']['save']) && isset($_REQUEST['topic']['action']) ){
79 if( $_REQUEST['topic']['action'] == 'add' ){
80 wpforo_verify_form();
81 if( $topicid = $wpforo->topic->add() ){
82 wp_redirect( $wpforo->topic->get_topic_url($topicid) );
83 exit();
84 }
85 }elseif( $_REQUEST['topic']['action'] == 'edit' ){
86 wpforo_verify_form();
87 if( $topicid = $wpforo->topic->edit() ){
88 wp_redirect( $wpforo->topic->get_topic_url($topicid) );
89 exit();
90 }
91 }
92 wp_redirect( wpforo_full_url() );
93 exit();
94 }
95
96 if( isset($_POST['post']['save']) ){
97 if( $_POST['post']['save'] != 'move' && isset($_REQUEST['post']['action']) ){
98 if($_REQUEST['post']['action'] == 'add'){
99 wpforo_verify_form();
100 if( $postid = $wpforo->post->add() ){
101 wp_redirect( $wpforo->post->get_post_url( $postid ) );
102 exit();
103 }
104 }elseif($_REQUEST['post']['action'] == 'edit'){
105 wpforo_verify_form();
106 if( $postid = $wpforo->post->edit() ){
107 wp_redirect( $wpforo->post->get_post_url( $postid ) );
108 exit();
109 }
110 }
111 }
112
113 if($_POST['post']['save'] == 'move' && isset($_POST['movetopicid']) && isset($_POST['topic']['forumid'])){
114 wpforo_verify_form();
115 $move_topicid = intval($_POST['movetopicid']);
116 $move_forumid = intval($_POST['topic']['forumid']);
117 $wpforo->topic->move( $move_topicid, $move_forumid );
118 wp_redirect( wpforo_full_url() );
119 exit();
120 }
121
122 wp_redirect( wpforo_full_url() );
123 exit();
124 }
125
126 ## Subscriptions
127 if( isset($_GET['wpforo']) && ($_GET['wpforo'] == 'sbscrbconfirm' || $_GET['wpforo'] == 'unsbscrb') && isset($_GET['key']) && $_GET['key'] ){
128 $sbs_key = sanitize_text_field($_GET['key']);
129 if( $_GET['wpforo'] == 'sbscrbconfirm' ){
130 $wpforo->sbscrb->edit($sbs_key);
131 }else{
132 $wpforo->sbscrb->delete($sbs_key);
133 }
134 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_full_url()) );
135 exit();
136 }
137
138 ###############################################################
139 /**
140 *
141 * BACK-END
142 *
143 */
144
145 ##Settings action
146 if( is_admin() && isset($_POST['wpforo_screen_option']['value']) ){
147 if(!current_user_can('administrator')) return;
148 update_option('wpforo_count_per_page', $_POST['wpforo_screen_option']['value']);
149 }
150
151 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-settings' ){
152
153 if(!current_user_can('administrator')){
154 $wpforo->notice->add('Permission denied', 'error');
155 wp_redirect(admin_url());
156 exit();
157 }
158
159 ##General options
160 if( isset($_POST['wpforo_general_options']) ){
161 check_admin_referer( 'wpforo-settings-general' );
162 if( isset($_POST['wpforo_url']) && $wpforo_page_slug = sanitize_title_with_dashes( basename($_POST['wpforo_url']) ) )
163 $sql = "UPDATE `".$wpforo->db->prefix."posts` SET `post_name` = '" . esc_sql($wpforo_page_slug) . "' WHERE `ID` = " . intval($wpforo->pageid);
164 if(FALSE !== $wpforo->db->query($sql)){
165 if( update_option('wpforo_url', trim(get_permalink($wpforo->pageid), '/') . '/') ){
166 $wpforo->notice->add('Forum Base URL successfully updated', 'success');
167 }else{
168 $wpforo->notice->add('Successfully updated', 'success');
169 }
170 }
171
172 if( update_option('wpforo_general_options', $_POST['wpforo_general_options']) ){
173 $wpforo->notice->add('General options successfully updated', 'success');
174 }else{
175 $wpforo->notice->add('Successfully updated', 'success');
176 }
177
178 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=general' ) );
179 exit();
180 }
181
182 ##add new lang action
183 if( isset($_FILES['add_lang']) ){
184 check_admin_referer( 'wpforo-settings-language' );
185 $wpforo->phrase->add_lang();
186 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=general' ) );
187 exit();
188 }
189
190 ##Forums
191 if( isset($_POST['wpforo_forum_options']) ){
192 check_admin_referer( 'wpforo-settings-forums' );
193 if( update_option('wpforo_forum_options', $_POST['wpforo_forum_options']) ){
194 $wpforo->notice->add('Forum options successfully updated', 'success');
195 }else{
196 $wpforo->notice->add('Forum options successfully updated, but previous value not changed', 'success');
197 }
198 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=forums' ) );
199 exit();
200 }
201
202 ##Posts
203 if( isset($_POST['wpforo_post_options']) ){
204 check_admin_referer( 'wpforo-settings-posts' );
205 $_POST['wpforo_post_options']['eot_durr'] = intval($_POST['wpforo_post_options']['eot_durr']) * 60;
206 $_POST['wpforo_post_options']['dot_durr'] = intval($_POST['wpforo_post_options']['dot_durr']) * 60;
207 $_POST['wpforo_post_options']['eor_durr'] = intval($_POST['wpforo_post_options']['eor_durr']) * 60;
208 $_POST['wpforo_post_options']['dor_durr'] = intval($_POST['wpforo_post_options']['dor_durr']) * 60;
209 $_POST['wpforo_post_options']['max_upload_size'] = intval(wpforo_human_size_to_bytes($_POST['wpforo_post_options']['max_upload_size'].'M'));
210 if( update_option('wpforo_post_options', $_POST['wpforo_post_options']) ){
211 $wpforo->notice->add('Post options successfully updated', 'success');
212 }else{
213 $wpforo->notice->add('Post options successfully updated, but previous value not changed', 'success');
214 }
215 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=posts' ) );
216 exit();
217 }
218
219 ##Members
220 if( isset($_POST['wpforo_member_options']) ){
221 check_admin_referer( 'wpforo-settings-members' );
222 $_POST['wpforo_member_options']['online_status_timeout'] = intval($_POST['wpforo_member_options']['online_status_timeout']) * 60;
223 if( update_option('wpforo_member_options', $_POST['wpforo_member_options']) ){
224 $wpforo->notice->add('Member options successfully updated', 'success');
225 }else{
226 $wpforo->notice->add('Member options successfully updated, but previous value not changed', 'success');
227 }
228 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=members' ) );
229 exit();
230 }
231
232 ##Features
233 if( isset($_POST['wpforo_features']) ){
234 check_admin_referer( 'wpforo-features' );
235 if( update_option('wpforo_features', $_POST['wpforo_features']) ){
236 $wpforo->notice->add('Features successfully updated', 'success');
237 }else{
238 $wpforo->notice->add('Features successfully updated, but previous value not changed', 'success');
239 }
240 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=features' ) );
241 exit();
242 }
243
244 ##Theme options
245 if( isset($_POST['wpforo_theme_options']) && isset($_POST['wpforo_style_options']) ){
246 check_admin_referer( 'wpforo-settings-styles' );
247 $wpforo->theme_options['style'] = sanitize_text_field($_POST['wpforo_theme_options']['style']);
248 $wpforo->theme_options['styles'] = $_POST['wpforo_theme_options']['styles'];
249 if( update_option('wpforo_theme_options', $wpforo->theme_options) || update_option('wpforo_style_options', $_POST['wpforo_style_options']) ){
250 $wpforo->notice->add('Theme options successfully updated', 'success');
251 }else{
252 $wpforo->notice->add('Theme options successfully updated, but previous value not changed', 'success');
253 }
254 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=styles' ) );
255 exit();
256 }
257
258 ##Subscription
259 if( isset($_POST['wpforo_subscribe_options']) ){
260 check_admin_referer( 'wpforo-settings-emails' );
261 if( update_option('wpforo_subscribe_options', $_POST['wpforo_subscribe_options']) ){
262 $wpforo->notice->add('Subscribe options successfully updated', 'success');
263 }else{
264 $wpforo->notice->add('Subscribe options successfully updated, but previous value not changed', 'success');
265 }
266 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=subscriptions' ) );
267 exit();
268 }
269
270 }
271
272 ### forum action ###
273 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-forums' ){
274
275 if(!current_user_can('administrator')){
276 $wpforo->notice->add('Permission denied', 'error');
277 wp_redirect(admin_url());
278 exit();
279 }
280
281 if( isset($_POST['wpforo_submit']) && isset($_REQUEST['forum']) && isset($_GET['action']) ){
282 check_admin_referer( 'wpforo-forum-addedit' );
283 if( $_GET['action'] == 'add' ){
284 $forumid = $wpforo->forum->add();
285 }elseif( $_GET['action'] == 'edit' && isset($_GET['id']) ){
286 $forumid = $wpforo->forum->edit();
287 }
288 if( isset($forumid) && $forumid ){
289 wp_redirect( admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=edit' ) );
290 }else{
291 wp_redirect( wpforo_full_url() );
292 }
293 exit();
294 }
295
296 if(isset($_POST['wpforo_delete']) && $_GET['action'] == 'del'){
297 check_admin_referer( 'wpforo-forum-delete' );
298 $wpforo->forum->delete();
299 wp_redirect( admin_url( 'admin.php?page=wpforo-forums' ) );
300 exit();
301 }
302
303 if(isset($_POST['forums_hierarchy_submit'])){
304 check_admin_referer( 'wpforo-forums-hierarchy' );
305 $wpforo->forum->update_hierarchy();
306 wp_redirect( admin_url( 'admin.php?page=wpforo-forums' ) );
307 exit();
308 }
309 }
310
311 ##Phrases
312 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-phrases' ){
313
314 if(!current_user_can('administrator')){
315 $wpforo->notice->add('Permission denied', 'error');
316 wp_redirect(admin_url());
317 exit();
318 }
319
320 if(isset($_POST['phrase']['save'])){
321 check_admin_referer( 'wpforo-phrases-edit' );
322 $wpforo->phrase->edit();
323 wp_redirect( admin_url( 'admin.php?page=wpforo-phrases' ) );
324 exit();
325 }
326
327 if( isset($_POST['phrase']['add']) && !empty($_POST['phrase']['value']) ){
328 check_admin_referer( 'wpforo-phrase-add' );
329 $wpforo->phrase->add();
330 wp_redirect( admin_url( 'admin.php?page=wpforo-phrases' ) );
331 exit();
332 }
333 }
334
335
336 ##Members
337 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-members' ){
338
339 if(!current_user_can('administrator')){
340 $wpforo->notice->add('Permission denied', 'error');
341 wp_redirect(admin_url());
342 exit();
343 }
344
345 if( isset( $_GET['action'] ) && $_GET['action'] == 'del' && isset( $_GET['id'] ) && $_GET['id'] ){
346
347 if(!check_admin_referer( 'wpforo_admin_table_action_delete' )){
348 $wpforo->notice->add('Permission denied', 'error');
349 wp_redirect(admin_url());
350 exit();
351 }
352
353 if( !$wpforo->perm->usergroup_can( $wpforo->current_user_groupid , 'dm' )){
354 $wpforo->notice->add('Permission denied for this action', 'error');
355 wp_redirect( admin_url( 'admin.php?page=wpforo-members' ) );
356 exit();
357 }
358 $wpforo->member->delete( intval($_GET['id']) );
359 wp_redirect( admin_url( 'admin.php?page=wpforo-members' ) );
360 exit();
361 }
362 }
363
364
365 ##Usergroups
366 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-usergroups' ){
367
368 if(!current_user_can('administrator')){
369 $wpforo->notice->add('Permission denied', 'error');
370 wp_redirect(admin_url());
371 exit();
372 }
373
374 if(isset( $_POST['usergroup']['action'] ) && ( $_POST['usergroup']['action'] == 'add' || $_POST['usergroup']['action'] == 'edit' ) ){
375 check_admin_referer( 'wpforo-usergroup-addedit' );
376 $board_cans = ( isset($_POST['cans']) ? $_POST['cans'] : array() );
377 if( $_POST['usergroup']['action'] == 'add' ){
378 $insert_usergroup_name = sanitize_text_field($_POST['usergroup']['name']);
379 $wpforo->usergroup->add( $insert_usergroup_name, $board_cans );
380 wp_redirect( admin_url( 'admin.php?page=wpforo-usergroups' ) );
381 exit();
382 }elseif( $_POST['usergroup']['action'] == 'edit' ){
383 $insert_usergroup_id = intval($_GET['gid']);
384 $insert_usergroup_name = sanitize_text_field($_POST['usergroup']['name']);
385 $wpforo->usergroup->edit( $insert_usergroup_id, $insert_usergroup_name, $board_cans );
386 wp_redirect( admin_url( 'admin.php?page=wpforo-usergroups' ) );
387 exit();
388 }
389
390 }
391 if(isset($_GET['action']) && $_GET['action']=='del' && isset($_POST['usergroup']['submit']) && $_POST['usergroup']['submit'] == 'Delete'){
392 check_admin_referer( 'wpforo-usergroup-delete' );
393 $wpforo->usergroup->delete();
394 wp_redirect( admin_url( 'admin.php?page=wpforo-usergroups' ) );
395 exit();
396 }
397 }
398
399 ##### Admin Accesses action ######
400 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-settings' && isset($_GET['tab']) && $_GET['tab'] == 'accesses' ){
401
402 if(!current_user_can('administrator')){
403 $wpforo->notice->add('Permission denied', 'error');
404 wp_redirect(admin_url());
405 exit();
406 }
407
408 if( isset( $_POST['access'] ) && $_POST['access']['action'] == 'add' ){
409 check_admin_referer( 'wpforo-access-addedit' );
410 $cans = ( isset($_POST['cans'] ) ? $_POST['cans'] : array() );
411 $insert_access_name = sanitize_text_field($_POST['access']['name']);
412 $wpforo->perm->add( $insert_access_name, $cans );
413 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=accesses' ) );
414 exit();
415 }elseif( isset( $_POST['access'] ) && $_POST['access']['action'] == 'edit' ){
416 check_admin_referer( 'wpforo-access-addedit' );
417 $cans = ( isset($_POST['cans'] ) ? $_POST['cans'] : array() );
418 $insert_access_key = sanitize_text_field($_POST['access']['key']);
419 $insert_access_name = sanitize_text_field($_POST['access']['name']);
420 $wpforo->perm->edit( $insert_access_name, $cans, $insert_access_key );
421 wp_redirect( wpforo_full_url() );
422 exit();
423 }elseif( isset($_GET['action']) && $_GET['action'] == 'del' && isset($_GET['accessid']) ){
424
425 if( !check_admin_referer( 'wpforo_access_delete' )){
426 $wpforo->notice->add('Permission denied', 'error');
427 wp_redirect(admin_url());
428 exit();
429 }
430
431 $insert_access_id = intval($_GET['accessid']);
432 $wpforo->perm->delete( $insert_access_id );
433 wp_redirect( admin_url( 'admin.php?page=wpforo-settings&tab=accesses' ) );
434 exit();
435 }
436 }
437
438 ##Themes
439 if( is_admin() && isset($_GET['page']) && $_GET['page'] == 'wpforo-themes' && isset($_GET['theme']) ){
440
441 if(!current_user_can('administrator')){
442 $wpforo->notice->add('Permission denied', 'error');
443 wp_redirect(admin_url());
444 exit();
445 }
446
447 $theme = sanitize_text_field( $_GET['theme'] );
448 if( $_GET['action'] == 'activate' || $_GET['action'] == 'install' || $_GET['action'] == 'reset' ){
449 if( $_GET['action'] == 'activate' ){
450 $new_theme = get_option( 'wpforo_theme_archive_' . $theme );
451 }
452 elseif( $_GET['action'] == 'install' || $_GET['action'] == 'reset' ){
453 $new_theme = $wpforo->tpl->find_theme( $theme );
454 if( $_GET['action'] == 'reset' ){
455 delete_option( 'wpforo_theme_archive_' . $theme );
456 }
457 }
458 $current_theme = $wpforo->theme_options;
459 if( !empty($new_theme) ){
460 update_option( 'wpforo_theme_options', $new_theme );
461 if( $_GET['action'] != 'reset' ){
462 update_option( 'wpforo_theme_archive_' . $wpforo->theme, $current_theme );
463 }
464 }
465 wp_redirect( admin_url( 'admin.php?page=wpforo-themes' ) );
466 exit();
467 }
468 if( $_GET['action'] == 'delete' ){
469 $remove_dir = WPFORO_THEME_DIR . '/' . $theme;
470 if( is_dir($remove_dir) && strlen($theme) > 0 ){
471 wpforo_remove_directory( $remove_dir );
472 }
473 wp_redirect( admin_url( 'admin.php?page=wpforo-themes' ) );
474 exit();
475 }
476 }
477
478
479 if( isset($_GET['forum']) && $_GET['forum'] && isset($_GET['type']) && $_GET['type'] == 'rss2' ){
480 $forumid = intval($_GET['forum']);
481 $forum = $wpforo->forum->get_forum($forumid);
482 $forum['forumurl'] = $wpforo->forum->get_forum_url($forumid);
483
484 if(isset($_GET['topic']) && $_GET['topic']){
485 $topicid = intval($_GET['topic']);
486 $topic = $wpforo->topic->get_topic($topicid);
487 $topic['topicurl'] = $wpforo->topic->get_topic_url($topicid);
488 $posts = $wpforo->post->get_posts( array( 'topicid' => $topicid, 'row_count' => 10, 'orderby' => 'created', 'order' => 'DESC' ) );
489 foreach($posts as $key => $post){
490 $member = $wpforo->member->get_member($post['userid']);
491 $posts[$key]['description'] = wpforo_text( trim(strip_tags($post['body'])), 190, false );
492 $posts[$key]['content'] = trim($post['body']);
493 $posts[$key]['posturl'] = $wpforo->post->get_post_url($post['postid']);
494 $posts[$key]['author'] = $member['display_name'];
495 }
496 $wpforo->feed->rss2_topic($forum, $topic, $posts);
497 }
498 else{
499 $topics = $wpforo->topic->get_topics( array( 'forumid' => $forumid, 'row_count' => 10, 'orderby' => 'created', 'order' => 'DESC' ) );
500 foreach($topics as $key => $topic){
501 $post = $wpforo->post->get_post($topic['first_postid']);
502 $member = $wpforo->member->get_member($topic['userid']);
503 $topics[$key]['description'] = wpforo_text( trim(strip_tags($post['body'])), 190, false );
504 $topics[$key]['content'] = trim($post['body']);
505 $topics[$key]['topicurl'] = $wpforo->topic->get_topic_url($topic['topicid']);
506 $topics[$key]['author'] = $member['display_name'];
507 }
508 $wpforo->feed->rss2_forum($forum, $topics);
509 }
510 exit();
511 }
512
513
514 do_action( 'wpforo_actions_end' );
515
516 }
517
518
519 ?>