PluginProbe
wpForo Forum / 2.3.0
wpForo Forum v2.3.0
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 / classes / Actions.php

Actions.php in wpForo Forum 2.3.0, at classes/Actions.php

2,946 lines 102.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\classes;
4
5 // Exit if accessed directly
6 if( ! defined( 'ABSPATH' ) ) exit();
7
8 class Actions {
9 /**
10 * wpForoAction constructor.
11 */
12 public function __construct() {
13 $this->init_hooks();
14 }
15
16 /**
17 * method for initializing all necessary hooks
18 */
19 public function init_hooks() {
20 add_action( 'wpforo_after_init_classes', function() { if( WPF()->need_activation() ) wpforo_activation(); }, 0 );
21
22 add_action( 'wpforo_after_init', [ $this, 'do_actions' ], 999 );
23 add_action( 'wpforo_action_user_delete', [ $this, 'user_delete' ] );
24 add_action( 'deleted_user', [ $this, 'deleted_user' ], 10, 2 );
25
26 add_action( 'wp_ajax_wpforo_profiles_default_cover_upload', [ $this, 'profiles_default_cover_upload' ] );
27 add_action( 'wp_ajax_wpforo_deactivate', [ $this, 'deactivate' ] );
28
29 if( ! wpforo_is_admin() ) {
30 add_action( 'wpforo_actions', function(){
31 if( wpfval($_REQUEST, 'wpfaction') === 'topic_add' ) unregister_post_type( 'topic' );
32 } );
33
34 add_action( 'wpforo_actions', [ $this, 'init_default_attach_hooks' ] );
35 add_action( 'wpforo_actions', [ $this, 'init_wp_emoji_hooks' ] );
36
37 add_action( 'wpforo_actions', [ $this, 'feed_rss2' ] );
38 add_action( 'wpforo_actions', [ $this, 'mark_all_read' ] );
39 add_action( 'wpforo_actions', [ $this, 'mark_notification_read' ] );
40
41 add_action( 'wpforo_action_registration', [ $this, 'registration' ] );
42 add_action( 'wpforo_action_login', [ $this, 'login' ] );
43 add_action( 'wpforo_action_lostpassword', [ $this, 'lostpassword' ] );
44 add_action( 'wpforo_action_resetpassword_form', [ $this, 'resetpassword_form' ] );
45 add_action( 'wpforo_action_resetpassword', [ $this, 'resetpassword' ] );
46 add_action( 'wpforo_action_profile_update', [ $this, 'profile_update' ] );
47 add_action( 'wpforo_action_ucf_file_delete', [ $this, 'ucf_file_delete' ] );
48 add_action( 'wpforo_action_cantlogin_contact', [ $this, 'cantlogin_contact' ] );
49
50 add_action( 'wpforo_action_topic_add', [ $this, 'topic_add' ] );
51 add_action( 'wpforo_action_topic_edit', [ $this, 'topic_edit' ] );
52 add_action( 'wpforo_action_topic_move', [ $this, 'topic_move' ] );
53 add_action( 'wpforo_action_topic_merge', [ $this, 'topic_merge' ] );
54 add_action( 'wpforo_action_topic_split', [ $this, 'topic_split' ] );
55
56 add_action( 'wpforo_action_post_add', [ $this, 'post_add' ] );
57 add_action( 'wpforo_action_post_edit', [ $this, 'post_edit' ] );
58
59 ## ajax actions ##
60 add_action( 'wp_ajax_wpforo_dissmiss_recaptcha_note', [ $this, 'dissmiss_recaptcha_note' ] );
61 add_action( 'wp_ajax_wpforo_acp_toggle', [ $this, 'acp_toggle' ] );
62 add_action( 'wp_ajax_wpforo_clear_all_notifications', [ $this, 'clear_all_notifications' ] );
63 add_action( 'wp_ajax_wpforo_profile_cover_upload', [ $this, 'profile_cover_upload' ] );
64 add_action( 'wp_ajax_wpforo_profile_cover_delete', [ $this, 'profile_cover_delete' ] );
65 add_action( 'wp_ajax_wpforo_get_topic_head_more_info', [ $this, 'get_topic_head_more_info' ] );
66 add_action( 'wp_ajax_nopriv_wpforo_get_topic_head_more_info', [ $this, 'get_topic_head_more_info' ] );
67 add_action( 'wp_ajax_wpforo_get_topic_overview_chunk', [ $this, 'get_topic_overview_chunk' ] );
68 add_action( 'wp_ajax_nopriv_wpforo_get_topic_overview_chunk', [ $this, 'get_topic_overview_chunk' ] );
69 add_action( 'wp_ajax_wpforo_get_overview', [ $this, 'get_overview' ] );
70 add_action( 'wp_ajax_nopriv_wpforo_get_overview', [ $this, 'get_overview' ] );
71 add_action( 'wp_ajax_wpforo_user_ban', [ $this, 'user_ban_ajax' ] );
72 add_action( 'wp_ajax_wpforo_get_member_template', [ $this, 'get_member_template' ] );
73 add_action( 'wp_ajax_nopriv_wpforo_get_member_template', [ $this, 'get_member_template' ] );
74 add_action( 'wp_ajax_wpforo_search_existed_topics', [ $this, 'search_existed_topics' ] );
75 add_action( 'wp_ajax_nopriv_wpforo_search_existed_topics', [ $this, 'search_existed_topics' ] );
76 } else {
77 add_action( 'wpforo_actions', [ $this, 'check_dashboard_permissions' ], 1 );
78 add_action( 'wpforo_actions', [ $this, 'repair_lost_main_shortcode_page' ] );
79
80 add_action( 'wpforo_action_synch_user_profiles', [ $this, 'synch_user_profiles' ] );
81 add_action( 'wpforo_action_reset_user_cache', [ $this, 'reset_user_cache' ] );
82 add_action( 'wpforo_action_reset_forums_stats', [ $this, 'reset_forums_stats' ] );
83 add_action( 'wpforo_action_reset_topics_stats', [ $this, 'reset_topics_stats' ] );
84 add_action( 'wpforo_action_reset_users_stats', [ $this, 'reset_users_stats' ] );
85 add_action( 'wpforo_action_rebuild_threads', [ $this, 'rebuild_threads' ] );
86 add_action( 'wpforo_action_reset_phrase_cache', [ $this, 'reset_phrase_cache' ] );
87 add_action( 'wpforo_action_recrawl_phrases', [ $this, 'recrawl_phrases' ] );
88 add_action( 'wpforo_action_clean_up', [ $this, 'clean_up' ] );
89 add_action( 'wpforo_action_flush_permalinks', [ $this, 'flush_permalinks' ] );
90
91 add_action( 'wpforo_action_base_slugs_settings_save', [ $this, 'base_slugs_settings_save' ] );
92 add_action( 'wpforo_action_general_settings_save', [ $this, 'general_settings_save' ] );
93
94 add_action( 'wpforo_action_slugs_settings_save', [ $this, 'slugs_settings_save' ] );
95 add_action( 'wpforo_action_board_settings_save', [ $this, 'board_settings_save' ] );
96
97 add_action( 'wpforo_action_akismet_settings_save', [ $this, 'akismet_settings_save' ] );
98 add_action( 'wpforo_action_antispam_settings_save', [ $this, 'antispam_settings_save' ] );
99 add_action( 'wpforo_action_authorization_settings_save', [ $this, 'authorization_settings_save' ] );
100 add_action( 'wpforo_action_buddypress_settings_save', [ $this, 'buddypress_settings_save' ] );
101 add_action( 'wpforo_action_components_settings_save', [ $this, 'components_settings_save' ] );
102 add_action( 'wpforo_action_email_settings_save', [ $this, 'email_settings_save' ] );
103 add_action( 'wpforo_action_forums_settings_save', [ $this, 'forums_settings_save' ] );
104 add_action( 'wpforo_action_logging_settings_save', [ $this, 'logging_settings_save' ] );
105 add_action( 'wpforo_action_members_settings_save', [ $this, 'members_settings_save' ] );
106 add_action( 'wpforo_action_notifications_settings_save', [ $this, 'notifications_settings_save' ] );
107 add_action( 'wpforo_action_posting_settings_save', [ $this, 'posting_settings_save' ] );
108 add_action( 'wpforo_action_profiles_settings_save', [ $this, 'profiles_settings_save' ] );
109 add_action( 'wpforo_action_rating_settings_save', [ $this, 'rating_settings_save' ] );
110 add_action( 'wpforo_action_recaptcha_settings_save', [ $this, 'recaptcha_settings_save' ] );
111 add_action( 'wpforo_action_rss_settings_save', [ $this, 'rss_settings_save' ] );
112 add_action( 'wpforo_action_seo_settings_save', [ $this, 'seo_settings_save' ] );
113 add_action( 'wpforo_action_social_settings_save', [ $this, 'social_settings_save' ] );
114 add_action( 'wpforo_action_styles_settings_save', [ $this, 'styles_settings_save' ] );
115 add_action( 'wpforo_action_tags_settings_save', [ $this, 'tags_settings_save' ] );
116 add_action( 'wpforo_action_topics_settings_save', [ $this, 'topics_settings_save' ] );
117 add_action( 'wpforo_action_um_settings_save', [ $this, 'um_settings_save' ] );
118 add_action( 'wpforo_action_legal_settings_save', [ $this, 'legal_settings_save' ] );
119
120 add_action( 'wpforo_action_board_add', [ $this, 'board_add' ] );
121 add_action( 'wpforo_action_board_edit', [ $this, 'board_edit' ] );
122 add_action( 'wpforo_action_board_repair', [ $this, 'board_repair' ] );
123 add_action( 'wpforo_action_board_delete', [ $this, 'board_delete' ] );
124
125 add_action( 'wpforo_action_add_new_xml_translation', [ $this, 'add_new_xml_translation' ] );
126 add_action( 'wpforo_action_phrases_change_lang', [ $this, 'phrases_change_lang' ] );
127 add_action( 'wpforo_action_dashboard_options_save', [ $this, 'dashboard_options_save' ] );
128 add_action( 'wpforo_action_colors_css_download', [ $this, 'colors_css_download' ] );
129 // add_action( 'wpforo_action_cleanup_options_save', [ $this, 'cleanup_options_save' ] );
130 add_action( 'wpforo_action_misc_options_save', [ $this, 'misc_options_save' ] );
131 add_action( 'wpforo_action_legal_options_save', [ $this, 'legal_options_save' ] );
132 add_action( 'wpforo_action_delete_spam_file', [ $this, 'delete_spam_file' ] );
133 add_action( 'wpforo_action_delete_all_spam_files', [ $this, 'delete_all_spam_files' ] );
134 add_action( 'wpforo_action_database_update', [ $this, 'database_update' ] );
135
136 add_action( 'wpforo_action_forum_copy', [ $this, 'forum_copy' ] );
137 add_action( 'wpforo_action_forum_add', [ $this, 'forum_add' ] );
138 add_action( 'wpforo_action_forum_edit', [ $this, 'forum_edit' ] );
139 add_action( 'wpforo_action_forum_delete', [ $this, 'forum_delete' ] );
140 add_action( 'wpforo_action_forum_hierarchy_save', [ $this, 'forum_hierarchy_save' ] );
141
142 add_action( 'wpforo_action_dashboard_post_unapprove', [ $this, 'dashboard_post_unapprove' ] );
143 add_action( 'wpforo_action_dashboard_post_approve', [ $this, 'dashboard_post_approve' ] );
144 add_action( 'wpforo_action_dashboard_post_delete', [ $this, 'dashboard_post_delete' ] );
145 add_action( 'wpforo_action_bulk_moderation', [ $this, 'bulk_moderation' ] );
146
147 add_action( 'wpforo_action_phrase_add', [ $this, 'phrase_add' ] );
148 add_action( 'wpforo_action_phrase_edit_form', [ $this, 'phrase_edit_form' ] );
149 add_action( 'wpforo_action_phrase_edit', [ $this, 'phrase_edit' ] );
150
151 add_action( 'wpforo_action_user_ban', [ $this, 'user_ban' ] );
152 add_action( 'wpforo_action_user_unban', [ $this, 'user_unban' ] );
153 add_action( 'wpforo_action_user_activate', [ $this, 'user_activate' ] );
154 add_action( 'wpforo_action_user_deactivate', [ $this, 'user_deactivate' ] );
155 add_action( 'wpforo_action_bulk_members', [ $this, 'bulk_members' ] );
156
157 add_action( 'wpforo_action_usergroup_add', [ $this, 'usergroup_add' ] );
158 add_action( 'wpforo_action_usergroup_edit', [ $this, 'usergroup_edit' ] );
159 add_action( 'wpforo_action_usergroup_delete', [ $this, 'usergroup_delete' ] );
160 add_action( 'wpforo_action_default_groupid_change', [ $this, 'default_groupid_change' ] );
161 add_action( 'wpforo_action_usergroup_delete_form', [ $this, 'usergroup_delete_form' ] );
162
163 add_action( 'wpforo_action_access_add', [ $this, 'access_add' ] );
164 add_action( 'wpforo_action_access_edit', [ $this, 'access_edit' ] );
165 add_action( 'wpforo_action_access_delete', [ $this, 'access_delete' ] );
166
167 add_action( 'wpforo_action_theme_activate', [ $this, 'theme_activate' ] );
168 add_action( 'wpforo_action_theme_delete', [ $this, 'theme_delete' ] );
169
170 add_action( 'wpforo_action_update_addons_css', [ $this, 'update_addons_css' ] );
171 add_action( 'wpforo_action_dissmiss_poll_version_is_old', [ $this, 'dissmiss_poll_version_is_old' ] );
172
173 add_action( 'wpforo_action_uninstall', [ $this, 'uninstall' ] );
174 }
175 add_action( 'wpforo_action_reset_all_caches', [ $this, 'reset_all_caches' ] );
176 }
177
178 /**
179 * wpforo main actions doing place
180 */
181 public function do_actions() {
182 do_action( 'wpforo_actions' );
183 $wpforo_actions = array_unique( array_merge( (array) wpfval( $_POST, 'wpfaction' ), (array) wpfval( WPF()->GET, 'wpfaction' ) ) );
184 if( ! empty( $wpforo_actions ) ) {
185 foreach( $wpforo_actions as $wpforo_action ) {
186 $wpforo_action = sanitize_title( $wpforo_action );
187 do_action( "wpforo_action_{$wpforo_action}" );
188 }
189 }
190 do_action( 'wpforo_actions_end' );
191 }
192
193 /**
194 * init wpforo default attachments system when wpforo advanced attachments addon has not exists
195 */
196 public function init_default_attach_hooks() {
197 add_action( 'delete_attachment', 'wpforo_delete_attachment', 10 );
198 if( has_action( 'wpforo_topic_form_extra_fields_after', [ WPF()->tpl, 'add_default_attach_input' ] ) ) {
199 add_filter( 'wpforo_add_topic_data_filter', 'wpforo_add_default_attachment' );
200 add_filter( 'wpforo_edit_topic_data_filter', 'wpforo_add_default_attachment' );
201 add_filter( 'wpforo_add_post_data_filter', 'wpforo_add_default_attachment' );
202 add_filter( 'wpforo_edit_post_data_filter', 'wpforo_add_default_attachment' );
203 add_filter( 'wpforo_body_text_filter', 'wpforo_default_attachments_filter' );
204 }
205 }
206
207 /**
208 * init wp emojis when wpforo emoticons addon has not exists
209 */
210 public function init_wp_emoji_hooks() {
211 if( ! class_exists( 'wpForoSmiles' ) ) {
212 add_filter( 'wpforo_body_text_filter', 'wp_encode_emoji', 9 );
213 add_filter( 'wpforo_body_text_filter', 'convert_smilies' );
214 }
215 }
216
217 /**
218 * get request_uri redirect to url with concatenation of &can_do=do
219 * @return bool true if you can do action now | false if you can not do action now
220 */
221 private function can_do() {
222 if( wpfval( $_GET, 'can_do' ) === 'do' ) return true;
223
224 $refresh_url = preg_replace( '#&can_do=?[^=?&\r\n]*#isu', '', wpforo_get_request_uri() );
225 $refresh_url .= '&can_do=do';
226 header( "refresh:0.1;url=" . $refresh_url );
227
228 add_filter( 'wpforo_admin_loading', '__return_true' );
229
230 return false;
231 }
232
233 /**
234 * @return string $u_action return union bulk action
235 */
236 private function get_current_bulk_action() {
237 $u_action = '';
238 if( ! empty( $_GET['action'] ) && $_GET['action'] !== '-1' ) {
239 $u_action = sanitize_textarea_field( $_GET['action'] );
240 } elseif( ! empty( $_GET['action2'] ) && $_GET['action2'] !== '-1' ) {
241 $u_action = sanitize_textarea_field( $_GET['action2'] );
242 }
243
244 return $u_action;
245 }
246
247 /**
248 * catch if rss url show rss feed for given arguments
249 */
250 public function feed_rss2() {
251 if( wpfval( WPF()->GET, 'type' ) === 'rss2' ) {
252 $forum_rss_items = apply_filters( 'wpforo_forum_feed_limit', 10 );
253 $topic_rss_items = apply_filters( 'wpforo_topic_feed_limit', 10 );
254
255 $forumid = intval( wpfval( WPF()->GET, 'forum' ) );
256 if( ! $forumid ) {
257 $forum = [];
258 $forum['forumurl'] = wpforo_home_url();
259 $forum['title'] = '';
260 } elseif( $forum = wpforo_forum( $forumid ) ) {
261 $forum['forumurl'] = $forum['url'];
262 }
263
264 if( wpfval( WPF()->GET, 'topic' ) ) {
265 $topicid = intval( WPF()->GET['topic'] );
266 if( ! $topicid ) {
267 $posts = WPF()->post->get_posts( [
268 'row_count' => $topic_rss_items,
269 'orderby' => '`created` DESC, `postid` DESC',
270 'check_private' => true,
271 ] );
272 $topic['title'] = '';
273 $topic['topicurl'] = wpforo_home_url();
274 } else {
275 $topic = wpforo_topic( $topicid );
276 $topic['topicurl'] = ( wpfval( $topic, 'url' ) ) ? $topic['url'] : WPF()->topic->get_url( $topicid );
277 $posts = WPF()->post->get_posts( [
278 'topicid' => $topicid,
279 'row_count' => $topic_rss_items,
280 'orderby' => '`created` DESC, `postid` DESC',
281 'check_private' => true,
282 ] );
283 }
284 foreach( $posts as $key => $post ) {
285 $member = wpforo_member( $post );
286 $posts[ $key ]['description'] = wpforo_text( trim( strip_tags( (string) $post['body'] ) ), 190, false );
287 $posts[ $key ]['content'] = trim( (string) $post['body'] );
288 $posts[ $key ]['posturl'] = WPF()->post->get_url( $post['postid'] );
289 $posts[ $key ]['author'] = $member['display_name'];
290 }
291 WPF()->feed->rss2_topic( $forum, $topic, $posts );
292 } else {
293 if( ! $forumid ) {
294 $topics = WPF()->topic->get_topics( [
295 'row_count' => $forum_rss_items,
296 'orderby' => 'created',
297 'order' => 'DESC',
298 ] );
299 } else {
300 $topics = WPF()->topic->get_topics( [
301 'forumid' => $forumid,
302 'row_count' => $forum_rss_items,
303 'orderby' => 'created',
304 'order' => 'DESC',
305 ] );
306 }
307 foreach( $topics as $key => $topic ) {
308 $post = wpforo_post( $topic['first_postid'] );
309 $member = wpforo_member( $topic );
310 $topics[ $key ]['description'] = wpforo_text( trim( strip_tags( (string) $post['body'] ) ), 190, false );
311 $topics[ $key ]['content'] = trim( (string) $post['body'] );
312 $topics[ $key ]['topicurl'] = WPF()->topic->get_url( $topic['topicid'] );
313 $topics[ $key ]['author'] = $member['display_name'];
314 }
315 WPF()->feed->rss2_forum( $forum, $topics );
316 }
317 exit();
318 }
319 }
320
321 /**
322 * ucf_file_delete delete /wp-content/uploads/UCFFILENAME
323 */
324 public function ucf_file_delete() {
325 $userid = 0;
326 if( wpfval( WPF()->GET, 'foro_f' ) && wpfval( WPF()->GET, 'foro_u' ) && wpfval( WPF()->GET, 'foro_n' ) ) {
327 if( wp_verify_nonce( WPF()->GET['foro_n'], 'wpforo_delete_profile_field' ) ) {
328 $userid = intval( WPF()->GET['foro_u'] );
329 $field = sanitize_title( WPF()->GET['foro_f'] );
330 if( $file = WPF()->member->get_custom_field( $userid, $field ) ) {
331 $file = wpforo_fix_upload_dir( $file );
332 $result = WPF()->member->update_custom_field( $userid, $field, '' );
333 if( $result ) {
334 if( file_exists( $file ) ) @unlink( $file );
335 WPF()->phrase->clear_cache();
336 WPF()->notice->add( 'Deleted Successfully!', 'success' );
337 } else {
338 WPF()->notice->clear();
339 WPF()->notice->add( 'Sorry, this file cannot be deleted', 'error' );
340 }
341 }
342 }
343 }
344
345 wp_safe_redirect( $userid ? WPF()->member->get_profile_url( $userid, 'account' ) : wpforo_home_url() );
346 exit();
347 }
348
349 /**
350 * mark all bold forum topics as read
351 */
352 public function mark_all_read() {
353 if( wpfval( WPF()->GET, 'foro' ) === 'allread' ) {
354 if( wpfval( WPF()->GET, 'foro_n' ) && wp_verify_nonce( WPF()->GET['foro_n'], 'wpforo_mark_all_read' ) ) {
355 WPF()->log->mark_all_read();
356 $current_url = wpforo_get_request_uri();
357 $current_url = strtok( $current_url, '?' );
358 wp_safe_redirect( $current_url );
359 exit();
360 }
361 }
362 }
363
364 /**
365 * Open/Close Frontend Admin CPanel
366 */
367 public function acp_toggle() {
368 wpforo_verify_nonce( 'wpforo_acp_toggle' );
369 $toggle_status = wpfval( $_POST, 'toggle_status' );
370 if( in_array( $toggle_status, [ 'open', 'close' ] ) ) {
371 update_user_meta( WPF()->current_userid, 'wpf-acp-toggle', $toggle_status );
372 wp_send_json_success();
373 } else {
374 wp_send_json_error();
375 }
376 }
377
378 /**
379 * set a notification read
380 */
381 public function mark_notification_read() {
382 if( wpfval( WPF()->GET, '_nread' ) && is_user_logged_in() ) {
383 if( wpfval( WPF()->GET, 'foro_n' ) && wp_verify_nonce( WPF()->GET['foro_n'], 'wpforo_mark_notification_read' ) ) {
384 $id = intval( WPF()->GET['_nread'] );
385 WPF()->activity->read_notification( $id );
386 $current_url = wpforo_get_request_uri();
387 $current_url = strtok( $current_url, '?' );
388 wp_safe_redirect( $current_url );
389 exit();
390 }
391 }
392 }
393
394 /**
395 * clear all notifications
396 */
397 public function clear_all_notifications() {
398 if( wpfval( $_POST, 'foro_n' ) && wp_verify_nonce( $_POST['foro_n'], 'wpforo_clear_notifications' ) ) {
399 WPF()->activity->clear_notifications();
400 echo WPF()->activity->get_no_notifications_html();
401 }
402 exit();
403 }
404
405 public function profile_cover_upload() {
406 wpforo_verify_nonce( 'wpforo_profile_cover_upload' );
407 if( WPF()->current_object['user'] && WPF()->usergroup->can( 'upc' ) && WPF()->perm->user_can_edit_account( WPF()->current_object['user'] ) && ($image_blob = wpfval( $_POST, 'image_blob' )) ){
408 $data = explode( ',', $image_blob );
409 if(
410 preg_match('#^data:image/(?:png|jpe?g|gif);base64$#iu', (string) $data[0])
411 && ( $file_content = isset( $data[1] ) ? base64_decode( $data[1] ) : '' )
412 ){
413 $file_basename = WPF()->current_object['user']['user_login'] . '_' . WPF()->current_object['user']['userid'] . '.jpg';
414 $file_dir = WPF()->folders['covers']['dir'] . DIRECTORY_SEPARATOR . $file_basename;
415 $file_url = WPF()->folders['covers']['url//'] . '/' . $file_basename;
416 if( file_put_contents($file_dir, $file_content) ){
417 WPF()->member->update_profile_field( WPF()->current_object['user']['userid'], 'cover', $file_url );
418 wp_send_json_success();
419 }
420 }
421 }
422 wp_send_json_error();
423 }
424
425 public function profile_cover_delete() {
426 wpforo_verify_nonce( 'wpforo_profile_cover_delete' );
427
428 if( WPF()->current_object['user'] && WPF()->usergroup->can( 'upc' ) && WPF()->perm->user_can_edit_account( WPF()->current_object['user'] ) ){
429 WPF()->member->update_profile_field( WPF()->current_object['user']['userid'], 'cover', '' );
430 wp_send_json_success( [ 'background_url' => wpforo_setting( 'profiles', 'default_cover' ) ] );
431 }
432 wp_send_json_error();
433 }
434
435 public function profiles_default_cover_upload() {
436 wpforo_verify_nonce( 'wpforo_profiles_default_cover_upload' );
437 if( (wpforo_current_user_is('admin') || WPF()->usergroup->can('ms')) && $image_blob = wpfval( $_POST, 'image_blob' ) ){
438 $data = explode( ',', $image_blob );
439 if(
440 preg_match('#^data:image/(?:png|jpe?g|gif);base64$#iu', $data[0])
441 && ( $file_content = isset( $data[1] ) ? base64_decode( $data[1] ) : '' )
442 ){
443 $file_basename = 'profiles_custom_default_cover.jpg';
444 $file_dir = WPF()->folders['covers']['dir'] . DIRECTORY_SEPARATOR . $file_basename;
445 $file_url = WPF()->folders['covers']['url//'] . '/' . $file_basename;
446 if( file_put_contents($file_dir, $file_content) ){
447 WPF()->settings->profiles['default_cover'] = $file_url;
448 wpforo_update_option( 'wpforo_profiles', WPF()->settings->profiles );
449 wp_send_json_success();
450 }
451 }
452 }
453 wp_send_json_error();
454 }
455
456 public function get_topic_head_more_info() {
457 wpforo_verify_nonce( 'wpforo_get_topic_head_more_info' );
458 if( $topicid = wpforo_bigintval( wpfval( $_POST, 'topicid' ) ) ){
459 wp_send_json_success( [ 'html' => wpforo_topic_active_participants( $topicid ) . wpforo_topic_overview( $topicid ) ] );
460 }
461
462 wp_send_json_error();
463 }
464
465 public function get_topic_overview_chunk() {
466 wpforo_verify_nonce( 'wpforo_get_topic_overview_chunk' );
467 if( $topicid = wpforo_bigintval( wpfval( $_POST, 'topicid' ) ) ){
468 if( !( $chunksize = (int) wpfval( $_POST, 'chunksize' ) ) ) $chunksize = 5;
469 $offset = (int) wpfval( $_POST, 'offset' );
470
471 wp_send_json_success( wpforo_get_topic_overview_chunk( $topicid, $chunksize, $offset ) );
472 }
473
474 wp_send_json_error();
475 }
476
477 public function get_overview() {
478 wpforo_verify_nonce( 'wpforo_get_overview' );
479 if( $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ){
480 if( $post = wpforo_post( $postid ) ){
481 wp_send_json_success(
482 [
483 'title' => '<i class="fas fa-user"></i> &nbsp;' . wpforo_phrase( 'Posted by ', false )
484 . ' ' . wpforo_member_link(wpforo_member($post), '', 20, '', false)
485 . '&nbsp;&bullet;&nbsp;'
486 . ' ' . wpforo_date($post['created'], 'ago', false),
487 'content' => trim( (string) wpforo_content( $post, false ) ),
488 ]
489 );
490 }
491 }
492
493 wp_send_json_error();
494 }
495
496 /**
497 * registration form submit action
498 */
499 public function registration() {
500 if( ! empty( $_POST['wpfreg'] ) ) {
501 wpforo_verify_form( 'wpforo_user_register' );
502 if( $userid = WPF()->member->create( $_POST ) ) {
503 if( wpforo_setting( 'authorization', 'redirect_url_after_register' ) ) {
504 $redirect_url = wpforo_setting( 'authorization', 'redirect_url_after_register' );
505 } elseif( ( $redirect_to = wpfval( $_GET, 'redirect_to' ) ) && wpforo_is_url_internal( urldecode( (string) $redirect_to ) ) ) {
506 $redirect_url = urldecode( (string) $redirect_to );
507 } elseif( is_wpforo_url() ) {
508 $redirect_url = preg_replace( '#\?.*$#is', '', wpforo_get_request_uri() );
509 } else {
510 $redirect_url = ( wpforo_setting( 'authorization', 'user_register_email_confirm' ) ? wpforo_home_url() : WPF()->member->get_profile_url( $userid, 'account' ) );
511 }
512
513 wp_safe_redirect( $redirect_url );
514 exit();
515 }
516 }
517 }
518
519 /**
520 * login form submit action
521 */
522 public function login() {
523 wpforo_verify_form( 'login' );
524 if( isset( $_POST['wpforologin'] ) && isset( $_POST['log'] ) && isset( $_POST['pwd'] ) ) {
525 if( ! is_wp_error( $user = wp_signon() ) ) {
526 $wpf_login_times = intval( get_user_meta( $user->ID, '_wpf_login_times', true ) );
527 if( isset( $user->ID ) && $wpf_login_times >= 1 ) {
528 $name = ( isset( $user->data->display_name ) ) ? $user->data->display_name : '';
529 WPF()->notice->add( 'Welcome back %s!', 'success', $name );
530 } else {
531 WPF()->notice->add( 'Welcome to our Community!', 'success' );
532 }
533 $wpf_login_times ++;
534 update_user_meta( $user->ID, '_wpf_login_times', $wpf_login_times );
535 if( wpforo_setting( 'authorization', 'redirect_url_after_login' ) ) {
536 $redirect_url = wpforo_setting( 'authorization', 'redirect_url_after_login' );
537 } elseif( ( $redirect_to = wpfval( $_GET, 'redirect_to' ) ) && wpforo_is_url_internal( urldecode( (string) $redirect_to ) ) ) {
538 $redirect_url = urldecode( (string) $redirect_to );
539 } elseif( is_wpforo_url() ) {
540 $redirect_url = preg_replace( '#\?.*$#is', '', wpforo_get_request_uri() );
541 } else {
542 $redirect_url = wpforo_home_url();
543 }
544 wp_safe_redirect( $redirect_url );
545 } else {
546 $args = [];
547 foreach( $user->errors as $u_err ) $args[] = $u_err[0];
548 WPF()->notice->add( $args, 'error' );
549 wp_safe_redirect( wpforo_get_request_uri() );
550 }
551 exit();
552 }
553 }
554
555 public function lostpassword() {
556 wpforo_verify_form( 'lostpassword' );
557 $redirect_url = wp_get_raw_referer();
558 if( wpfval( $_POST, 'user_login' ) ) {
559 $errors = retrieve_password();
560 if( is_wp_error( $errors ) ) {
561 $redirect_url = wpforo_lostpassword_url();
562 WPF()->notice->add( implode( ',', $errors->get_error_messages() ), 'error' );
563 } else {
564 $redirect_url = wpforo_login_url();
565 WPF()->notice->add( 'Email has been sent', 'success' );
566 }
567 }
568
569 wp_safe_redirect( $redirect_url );
570 exit();
571 }
572
573 public function resetpassword_form() {
574 $rp_key = sanitize_text_field( wp_unslash( $_REQUEST['rp_key'] ) );
575 $rp_login = sanitize_user( wp_unslash( $_REQUEST['rp_login'] ) );
576 $user = check_password_reset_key( $rp_key, $rp_login );
577 if( ! $user || is_wp_error( $user ) ) {
578 if( $user && $user->get_error_code() === 'expired_key' ) {
579 WPF()->notice->add( 'The key is expired', 'error' );
580 } else {
581 WPF()->notice->add( 'The key is invalid', 'error' );
582 }
583 wp_safe_redirect( wpforo_login_url() );
584 exit();
585 }
586 }
587
588 public function resetpassword() {
589 $this->resetpassword_form();
590
591 $pass1 = wpfval( $_POST, 'pass1' );
592 $pass2 = wpfval( $_POST, 'pass2' );
593
594 if( ! $pass1 ) {
595 WPF()->notice->add( 'The password reset empty', 'error' );
596 wp_safe_redirect( wp_get_raw_referer() );
597 exit();
598 }
599
600 if( strlen( (string) $pass1 ) < WPF()->member->pass_min_length || strlen( (string) $pass1 ) > WPF()->member->pass_max_length ) {
601 WPF()->notice->add( 'Password length must be between %d characters and %d characters.', 'error', [
602 WPF()->member->pass_min_length,
603 WPF()->member->pass_max_length,
604 ] );
605 wp_safe_redirect( wp_get_raw_referer() );
606 exit();
607 }
608
609 if( $pass1 !== $pass2 ) {
610 WPF()->notice->add( 'The password reset mismatch', 'error' );
611 wp_safe_redirect( wp_get_raw_referer() );
612 exit();
613 }
614
615 $rp_login = sanitize_user( wp_unslash( $_REQUEST['rp_login'] ) );
616 reset_password( get_user_by( 'login', $rp_login ), $pass1 );
617 wp_signon( [ 'user_login' => $rp_login, 'user_password' => $pass1 ] );
618
619 WPF()->notice->add( 'The password has been changed', 'success' );
620 wp_safe_redirect( wpforo_home_url() );
621 exit();
622 }
623
624 public function logout() {
625 wpforo_verify_nonce( 'wpforo_logout', 'full' );
626 wp_logout();
627 $redirect_url = wpforo_home_url();
628 if( ( $redirect_to = wpfval( $_GET, 'redirect_to' ) ) && wpforo_is_url_internal( urldecode( (string) $redirect_to ) ) ) {
629 $redirect_url = urldecode( (string) $redirect_to );
630 if( strpos( $redirect_url, 'lostpassword' ) !== false ) $redirect_url = wpforo_login_url();
631 }
632 wp_safe_redirect( $redirect_url );
633 exit();
634 }
635
636 /**
637 * profile_update form submit action
638 */
639 public function profile_update() {
640 if( wpfval( $_POST, 'member', 'userid' ) ) {
641 wpforo_verify_form();
642 $uid = intval( $_POST['member']['userid'] );
643 if( ! ( $uid === WPF()->current_userid || ( WPF()->usergroup->can( 'em' ) && WPF()->perm->user_can_manage_user( WPF()->current_userid, $uid ) ) ) ) {
644 WPF()->notice->clear();
645 WPF()->notice->add( 'Permission denied', 'error' );
646 wp_safe_redirect( wpforo_get_request_uri() );
647 exit();
648 }
649 if( WPF()->member->update( $_POST ) ) {
650 if( $profile_url = WPF()->member->get_profile_url( $uid, 'account', false ) ) {
651 wp_safe_redirect( $profile_url );
652 exit();
653 }
654 }
655 }
656
657 wp_safe_redirect( wpforo_get_request_uri() );
658 exit();
659 }
660
661 public function cantlogin_contact() {
662 if( wpforo_setting( 'authorization', 'manually_approval_contact_form' ) && ($msg = wpfval( $_POST, 'msg' )) ){
663 $admin_emails = wpforo_setting( 'email', 'admin_emails' );
664 $admin_email = wpfval($admin_emails, 0);
665 $sbj = wpforo_phrase( 'Request for account approval', false ) . ' ( '. wpfval( $_POST, 'user_login' ) .' )';
666
667 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type', 999 );
668 if( @wpforo_send_email( $admin_email, $sbj, $msg, wpforo_admin_mail_headers() ) ) {
669 WPF()->notice->add( 'Message has been sent', 'success' );
670 } else {
671 WPF()->notice->add( 'Can\'t send report email', 'error' );
672 }
673 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
674 }
675
676 wp_safe_redirect( wpforo_home_url() );
677 exit();
678 }
679
680 /**
681 * topic_add form submit action
682 */
683 public function topic_add() {
684 wpforo_verify_form();
685 $args = $_REQUEST['thread'];
686 $args['postmetas'] = (array) wpfval( $_REQUEST, 'data' );
687 if( $topicid = WPF()->topic->add( $args ) ) {
688 wp_safe_redirect( WPF()->topic->get_url( $topicid ) );
689 exit();
690 }
691 wp_safe_redirect( wpforo_get_request_uri() );
692 exit();
693 }
694
695 /**
696 * topic_edit form submit action
697 */
698 public function topic_edit() {
699 wpforo_verify_form();
700 $args = $_REQUEST['thread'];
701 $args['postmetas'] = (array) wpfval( $_REQUEST, 'data' );
702 if( $topicid = WPF()->topic->edit( $args ) ) {
703 wp_safe_redirect( WPF()->topic->get_url( $topicid ) );
704 exit();
705 }
706 wp_safe_redirect( wpforo_get_request_uri() );
707 exit();
708 }
709
710 /**
711 * post_add form submit action
712 */
713 public function post_add() {
714 wpforo_verify_form();
715 $args = $_REQUEST['post'];
716 $args['postmetas'] = (array) wpfval( $_REQUEST, 'data' );
717 if( $postid = WPF()->post->add( $args ) ) {
718 wp_safe_redirect( WPF()->post->get_url( $postid ) );
719 exit();
720 }
721 wp_safe_redirect( wpforo_get_request_uri() );
722 exit();
723 }
724
725 /**
726 * post_edit form submit action
727 */
728 public function post_edit() {
729 wpforo_verify_form();
730 $args = $_REQUEST['post'];
731 $args['postmetas'] = (array) wpfval( $_REQUEST, 'data' );
732 if( $postid = WPF()->post->edit( $args ) ) {
733 wp_safe_redirect( WPF()->post->get_url( $postid ) );
734 exit();
735 }
736 wp_safe_redirect( wpforo_get_request_uri() );
737 exit();
738 }
739
740 /**
741 * topic_move form submit action
742 */
743 public function topic_move() {
744 if( ! empty( $_POST['topic_move'] ) ) {
745 wpforo_verify_form();
746 $topicid = intval( wpfval( $_POST['topic_move'], 'topicid' ) );
747 $forumid = intval( wpfval( $_POST['topic_move'], 'forumid' ) );
748 if( $topicid && $forumid ) {
749 WPF()->topic->move( $topicid, $forumid );
750 $url = WPF()->topic->get_url( $topicid, [], false );
751 wpforo_clean_cache();
752 wp_safe_redirect( $url );
753 exit();
754 }
755 }
756
757 wp_safe_redirect( wpforo_get_request_uri() );
758 exit();
759 }
760
761 /**
762 * topic_merge form submit action
763 */
764 public function topic_merge() {
765 wpforo_verify_form();
766 $redirect_to = wpforo_get_request_uri();
767 if( WPF()->current_object['topic'] && ! empty( $_POST['wpforo'] ) && ! empty( $_POST['wpforo']['target_topic_url'] ) ) {
768 $target_slug = wpforo_get_topic_slug_from_url( esc_url( (string) $_POST['wpforo']['target_topic_url'] ) );
769 if( ! is_null( $target_slug ) && $target = WPF()->topic->get_topic( $target_slug ) ) {
770 $append = ( empty( $_POST['wpforo']['update_date_and_append'] ) ? 0 : 1 );
771 $to_target_title = ( empty( $_POST['wpforo']['to_target_title'] ) ? 0 : 1 );
772
773 if( WPF()->topic->merge( $target, WPF()->current_object['topic'], [], $to_target_title, $append ) ) {
774 $redirect_to = WPF()->topic->get_url( $target, [], false );
775 wpforo_clean_cache();
776 }
777 } else {
778 WPF()->notice->add( 'Target Topic not found', 'error' );
779 }
780 }
781 wp_safe_redirect( $redirect_to );
782 exit();
783 }
784
785 /**
786 * topic_split form submit action
787 */
788 public function topic_split() {
789 wpforo_verify_form();
790 $redirect_to = wpforo_get_request_uri();
791 if( WPF()->current_object['topic'] && ! empty( $_POST['wpforo'] ) ) {
792 if( ! empty( $_POST['wpforo']['create_new'] ) ) {
793 $args = [
794 'title' => sanitize_text_field( $_POST['wpforo']['new_topic_title'] ),
795 'forumid' => intval( $_POST['wpforo']['new_topic_forumid'] ),
796 'postids' => array_map( 'intval', $_POST['wpforo']['posts'] ),
797 ];
798 $to_target_title = ( empty( $_POST['wpforo']['to_target_title'] ) ? 0 : 1 );
799 if( $topicid = WPF()->topic->split( $args, $to_target_title ) ) {
800 $redirect_to = WPF()->topic->get_url( $topicid );
801 }
802 } else {
803 if( ! empty( $_POST['wpforo']['target_topic_url'] ) && ! empty( $_POST['wpforo']['posts'] ) ) {
804 $target_slug = wpforo_get_topic_slug_from_url( esc_url( (string) $_POST['wpforo']['target_topic_url'] ) );
805 if( ! is_null( $target_slug ) && $target = WPF()->topic->get_topic( $target_slug ) ) {
806 $append = ( empty( $_POST['wpforo']['update_date_and_append'] ) ? 0 : 1 );
807 $to_target_title = ( empty( $_POST['wpforo']['to_target_title'] ) ? 0 : 1 );
808 $postids = array_map( 'intval', $_POST['wpforo']['posts'] );
809 if( WPF()->topic->merge( $target, WPF()->current_object['topic'], $postids, $to_target_title, $append ) ) {
810 $redirect_to = WPF()->topic->get_url( $target );
811 }
812 } else {
813 WPF()->notice->add( 'Target Topic not found', 'error' );
814 }
815 }
816 }
817 }
818 wp_safe_redirect( $redirect_to );
819 exit();
820 }
821
822 /**
823 * board add action
824 */
825 public function board_add() {
826 check_admin_referer( 'wpforo-board-add' );
827 if( $board = (array) wpfval( $_POST, 'board' ) ) {
828 if( ! ( $board['locale'] = trim( (string) $board['locale'] ) ) ) $board['locale'] = 'en_US';
829 $status = wpfkey( $board, 'status' ) ? (int) wpfval( $board, 'status' ) : 1;
830 if( $boardid = WPF()->board->add( $board ) ) {
831 // Handle translation installation.
832 if( $status && $board['locale'] && current_user_can( 'install_languages' ) ) {
833 require_once ABSPATH . 'wp-admin/includes/file.php';
834 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
835 if( wp_can_install_language_pack() ) wp_download_language_pack( $board['locale'] );
836 }
837
838 if( ( $board = WPF()->board->_get_board( $boardid ) ) && $status ) {
839 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-' . $boardid . '-settings' ) );
840 exit();
841 }
842 }
843 }
844
845 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-boards' ) );
846 exit();
847 }
848
849 /**
850 * board edit action
851 */
852 public function board_edit() {
853 check_admin_referer( 'wpforo-board-edit' );
854 if( $board = (array) wpfval( $_POST, 'board' ) ) {
855 $boardid = (int) wpfval( $board, 'boardid' );
856 $status = wpfkey( $board, 'status' ) ? (int) wpfval( $board, 'status' ) : 1;
857 if( ! ( $board['locale'] = trim( (string) $board['locale'] ) ) ) $board['locale'] = 'en_US';
858 if( WPF()->board->edit( $board, $boardid ) ) {
859 if( $status && ! is_wpforo_multiboard() ){
860 wp_update_post(
861 [
862 'ID' => $board['pageid'],
863 'post_name' => $board['slug'],
864 ]
865 );
866 }
867 // Handle translation installation.
868 if( $status && $board['locale'] && current_user_can( 'install_languages' ) ) {
869 require_once ABSPATH . 'wp-admin/includes/file.php';
870 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
871 if( wp_can_install_language_pack() ) wp_download_language_pack( $board['locale'] );
872 }
873 }
874 }
875
876 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-boards' ) );
877 exit();
878 }
879
880 /**
881 * board delete action
882 */
883 public function board_repair() {
884 $boardid = (int) wpfval( $_GET, 'boardid' );
885 if( $boardid === WPF()->board->get_current( 'boardid' ) ) {
886 check_admin_referer( 'wpforo-board-repair-' . $boardid );
887 wpforo_board_repair( $boardid );
888 }
889
890 wp_safe_redirect( wp_get_raw_referer() );
891 exit();
892 }
893
894 /**
895 * board delete action
896 */
897 public function board_delete() {
898 if( ( $boardid = (int) wpfval( $_GET, 'boardid' ) ) && $boardid === WPF()->board->get_current( 'boardid' ) ) {
899 check_admin_referer( 'wpforo-board-delete-' . $boardid );
900 wpforo_board_uninstall( $boardid );
901 }
902
903 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-boards' ) );
904 exit();
905 }
906
907 /**
908 * action to synchronize wp_users to wp_wpforo_profiles
909 */
910 public function synch_user_profiles() {
911 check_admin_referer( 'wpforo_synch_user_profiles' );
912
913 if( $this->can_do() ) {
914 wpforo_set_max_execution_time();
915 wp_raise_memory_limit();
916
917 if( WPF()->member->synchronize_users( apply_filters( 'wpforo_rebuild_per_request', 200 ) ) ) {
918 WPF()->member->clear_db_cache();
919 wpforo_clean_cache();
920 WPF()->notice->add( 'Synched Successfully!', 'success' );
921 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-overview' ) );
922 } else {
923 wp_safe_redirect( htmlspecialchars_decode( wp_nonce_url( admin_url( 'admin.php?page=wpforo-overview&wpfaction=synch_user_profiles' ), 'wpforo_synch_user_profiles' ) ) );
924 }
925 exit();
926 }
927 }
928
929 /**
930 * reset user caches
931 */
932 public function reset_user_cache() {
933 check_admin_referer( 'wpforo_reset_user_cache' );
934
935 if( ! current_user_can( 'administrator' ) ) {
936 WPF()->notice->add( 'Permission denied', 'error' );
937 wp_safe_redirect( admin_url() );
938 exit();
939 }
940
941 wpforo_set_max_execution_time();
942 wp_raise_memory_limit();
943
944 WPF()->member->clear_db_cache();
945 WPF()->notice->add( 'Deleted Successfully!', 'success' );
946
947 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-overview' ) );
948 exit();
949 }
950
951 /**
952 * rebuild forums statistics first|last posts etc.
953 */
954 public function reset_forums_stats() {
955 check_admin_referer( 'wpforo_reset_forums_stat' );
956
957 if( ! current_user_can( 'administrator' ) ) {
958 WPF()->notice->add( 'Permission denied', 'error' );
959 wp_safe_redirect( admin_url() );
960 exit();
961 }
962
963 wpforo_set_max_execution_time();
964 wp_raise_memory_limit();
965
966 $forumids = WPF()->db->get_col( "SELECT `forumid` FROM " . WPF()->tables->forums . " WHERE `is_cat` = 0 ORDER BY `forumid` ASC" );
967 if( ! empty( $forumids ) ) {
968 foreach( $forumids as $forumid ) {
969 WPF()->forum->rebuild_stats( $forumid );
970 WPF()->forum->rebuild_last_infos( $forumid, false );
971 }
972 WPF()->statistic_cache_clean();
973 WPF()->forum->delete_tree_cache();
974 wpforo_clean_cache();
975 WPF()->notice->add( 'Updated Successfully!', 'success' );
976 }
977
978 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
979 exit();
980 }
981
982 /**
983 * rebuild topics statistics first|last posts etc.
984 */
985 public function reset_topics_stats() {
986 check_admin_referer( 'wpforo_reset_topics_stat' );
987
988 if( ! current_user_can( 'administrator' ) ) {
989 WPF()->notice->add( 'Permission denied', 'error' );
990 wp_safe_redirect( admin_url() );
991 exit();
992 }
993
994 if( $this->can_do() ) {
995 wpforo_set_max_execution_time();
996 wp_raise_memory_limit();
997
998 $lastid = (int) wpfval( $_GET, 'topic_lastid' );
999 $sql = "SELECT `topicid` FROM " . WPF()->tables->topics . " WHERE `topicid` > %d ORDER BY `topicid` ASC LIMIT %d";
1000 $topicids = WPF()->db->get_col( WPF()->db->prepare( $sql, $lastid, apply_filters( 'wpforo_rebuild_per_request', 200 ) ) );
1001 if( $topicids ) {
1002 foreach( $topicids as $topicid ) {
1003 $topic = WPF()->topic->get_topic( $topicid );
1004 WPF()->topic->rebuild_first_last( $topic );
1005 WPF()->topic->rebuild_stats( $topic );
1006 }
1007 wp_safe_redirect( htmlspecialchars_decode( wp_nonce_url( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) . '&wpfaction=reset_topics_stats&topic_lastid=' . end( $topicids ) ), 'wpforo_reset_topics_stat' ) ) );
1008 } else {
1009 @WPF()->db->query(
1010 "UPDATE `" . WPF()->tables->topics . "` t
1011 INNER JOIN `" . WPF()->tables->posts . "` p ON p.`topicid` = t.`topicid` AND p.`is_answer` = 1
1012 SET t.`solved` = 1
1013 WHERE t.`solved` = 0"
1014 );
1015 WPF()->statistic_cache_clean();
1016 WPF()->notice->add( 'Updated Successfully!', 'success' );
1017 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
1018 }
1019 exit();
1020 }
1021 }
1022
1023 /**
1024 * rebuild users statistics etc.
1025 */
1026 public function reset_users_stats() {
1027 check_admin_referer( 'wpforo_reset_users_stat' );
1028
1029 if( ! current_user_can( 'administrator' ) ) {
1030 WPF()->notice->add( 'Permission denied', 'error' );
1031 wp_safe_redirect( admin_url() );
1032 exit();
1033 }
1034
1035 if( $this->can_do() ) {
1036 wpforo_set_max_execution_time();
1037 wp_raise_memory_limit();
1038
1039 $lastid = (int) wpfval( $_GET, 'user_lastid' );
1040 $sql = "SELECT `userid` FROM " . WPF()->tables->profiles . " WHERE `userid` > %d ORDER BY `userid` ASC LIMIT %d";
1041 $userids = WPF()->db->get_col( WPF()->db->prepare( $sql, $lastid, apply_filters( 'wpforo_rebuild_per_request', 200 ) ) );
1042 if( $userids ) {
1043 foreach( $userids as $userid ) {
1044 WPF()->member->rebuild_stats( $userid );
1045 }
1046
1047 wp_safe_redirect( htmlspecialchars_decode( wp_nonce_url( admin_url( 'admin.php?page=wpforo-overview&wpfaction=reset_users_stats&user_lastid=' . end( $userids ) ), 'wpforo_reset_users_stat' ) ) );
1048 } else {
1049 WPF()->notice->add( 'Updated Successfully!', 'success' );
1050 wp_safe_redirect( admin_url( 'admin.php?page=wpforo-overview' ) );
1051 }
1052 exit();
1053 }
1054 }
1055
1056 /**
1057 * rebuild 4 layout forum topics threads root
1058 */
1059 public function rebuild_threads() {
1060 check_admin_referer( 'wpforo_rebuild_threads' );
1061
1062 if( ! current_user_can( 'administrator' ) ) {
1063 WPF()->notice->add( 'Permission denied', 'error' );
1064 wp_safe_redirect( admin_url() );
1065 exit();
1066 }
1067
1068 wpforo_set_max_execution_time( 3600 );
1069 wp_raise_memory_limit();
1070
1071 WPF()->topic->rebuild_forum_threads();
1072 wpforo_clean_cache();
1073 WPF()->notice->add( 'Threads rebuilt successfully', 'success' );
1074
1075 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
1076 exit();
1077 }
1078
1079 /**
1080 * reset phrases cache from db
1081 */
1082 public function reset_phrase_cache() {
1083 check_admin_referer( 'wpforo_reset_phrase_cache' );
1084
1085 if( ! current_user_can( 'administrator' ) ) {
1086 WPF()->notice->add( 'Permission denied', 'error' );
1087 wp_safe_redirect( admin_url() );
1088 exit();
1089 }
1090
1091 wpforo_set_max_execution_time();
1092 wp_raise_memory_limit();
1093
1094 WPF()->phrase->clear_cache();
1095 WPF()->notice->add( 'Deleted Successfully!', 'success' );
1096
1097 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
1098 exit();
1099 }
1100
1101 /**
1102 * recrawling phrases from all wpforo, wpforo-addons code files
1103 */
1104 public function recrawl_phrases() {
1105 check_admin_referer( 'wpforo_recrawl_phrases' );
1106
1107 if( ! current_user_can( 'administrator' ) ) {
1108 WPF()->notice->add( 'Permission denied', 'error' );
1109 wp_safe_redirect( admin_url() );
1110 exit();
1111 }
1112
1113 wpforo_set_max_execution_time();
1114 wp_raise_memory_limit();
1115
1116 WPF()->phrase->crawl_phrases();
1117 WPF()->phrase->clear_cache();
1118 WPF()->notice->clear();
1119 WPF()->notice->add( 'Rebuilt Successfully!', 'success' );
1120
1121 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
1122 exit();
1123 }
1124
1125 /**
1126 * reset wpforo all caches (phrase, user, forum, post, stats) etc.
1127 */
1128 public function reset_all_caches() {
1129 check_admin_referer( 'wpforo_reset_cache' );
1130
1131 if( ! current_user_can( 'administrator' ) ) {
1132 WPF()->notice->add( 'Permission denied', 'error' );
1133 wp_safe_redirect( admin_url() );
1134 exit();
1135 }
1136
1137 wpforo_set_max_execution_time();
1138 wp_raise_memory_limit();
1139
1140 WPF()->member->clear_db_cache();
1141 wpforo_clean_cache();
1142
1143 // Flush WordPress Cache
1144 wp_cache_flush();
1145
1146 WPF()->notice->add( 'Deleted Successfully!', 'success' );
1147
1148 $redirect = ( is_admin() ) ? admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) : wpforo_home_url();
1149 wp_safe_redirect( $redirect );
1150 exit();
1151 }
1152
1153 /**
1154 * Clean Up damaged content in database
1155 */
1156 public function clean_up() {
1157 check_admin_referer( 'wpforo_clean_up' );
1158
1159 if( ! current_user_can( 'administrator' ) ) {
1160 WPF()->notice->add( 'Permission denied', 'error' );
1161 wp_safe_redirect( admin_url() );
1162 exit();
1163 }
1164
1165 wpforo_set_max_execution_time();
1166 wp_raise_memory_limit();
1167
1168 wpforo_clean_up();
1169 WPF()->notice->add( 'Cleaned Up!', 'success' );
1170
1171 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
1172 exit();
1173 }
1174
1175 /**
1176 * Flush Permalinks
1177 */
1178 public function flush_permalinks() {
1179 check_admin_referer( 'wpforo_flush_permalinks' );
1180
1181 if( ! current_user_can( 'administrator' ) ) {
1182 WPF()->notice->add( 'Permission denied', 'error' );
1183 wp_safe_redirect( admin_url() );
1184 exit();
1185 }
1186
1187 wpforo_set_max_execution_time();
1188 wp_raise_memory_limit();
1189
1190 if( 'hard' === wpfval( WPF()->GET, 'flush_type' ) ) {
1191 $bk_time = time();
1192 $current = get_option('rewrite_rules');
1193 update_option( 'rewrite_rules_bk_' . $bk_time, $current );
1194 copy( ABSPATH . '/.htaccess', ABSPATH . '/.htaccess-bk-' . $bk_time );
1195 flush_rewrite_rules( true );
1196 delete_option('rewrite_rules');
1197 } else {
1198 flush_rewrite_rules( false );
1199 }
1200
1201 WPF()->phrase->clear_cache();
1202 WPF()->notice->clear();
1203 WPF()->notice->add( 'Flushed Successfully!', 'success' );
1204
1205 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
1206 exit();
1207 }
1208
1209 /**
1210 * dashboard_options_save form submit action
1211 */
1212 public function dashboard_options_save() {
1213 if( ! current_user_can( 'administrator' ) ) {
1214 WPF()->notice->add( 'Permission denied', 'error' );
1215 wp_safe_redirect( admin_url() );
1216 exit();
1217 }
1218 if( $dashboard_count_per_page = (int) wpfval( $_POST, 'wpforo_dashboard_count_per_page' ) ) {
1219 wpforo_update_option( 'count_per_page', $dashboard_count_per_page );
1220 }
1221 wp_safe_redirect( wpforo_get_request_uri() );
1222 exit();
1223 }
1224
1225 /**
1226 * checking accesses to forum admin menu pages settings etc...
1227 */
1228 public function check_dashboard_permissions() {
1229 $page = wpfval( WPF()->GET, 'page' );
1230 if( $page === wpforo_prefix_slug( 'settings' ) ) {
1231 if( ! WPF()->usergroup->can( 'ms' ) ) {
1232 WPF()->notice->add( 'Permission denied', 'error' );
1233 wp_safe_redirect( admin_url() );
1234 exit();
1235 }
1236 }
1237 }
1238
1239 /**
1240 * check if [wpforo] page has been deleted, restore or create new [wpforo] page
1241 */
1242 public function repair_lost_main_shortcode_page() {
1243 if( wpfval( WPF()->GET, 'page' ) === wpforo_prefix_slug( 'settings' ) ) wpforo_repair_main_shortcode_page();
1244 }
1245
1246 /**
1247 * add_new_xml_translation form submit action
1248 */
1249 public function add_new_xml_translation() {
1250 check_admin_referer( 'wpforo-settings-language' );
1251
1252 if( ! WPF()->usergroup->can( 'ms' ) ) {
1253 WPF()->notice->add( 'Permission denied', 'error' );
1254 wp_safe_redirect( admin_url() );
1255 exit();
1256 }
1257
1258 if( ! empty( $_FILES['add_lang'] ) ) {
1259 WPF()->phrase->add_lang();
1260 wpforo_clean_cache();
1261 }
1262 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'settings' ) . '&tab=general' ) );
1263 exit();
1264 }
1265
1266 /**
1267 * add_new_xml_translation form submit action
1268 */
1269 public function phrases_change_lang() {
1270 check_admin_referer( 'wpforo-phrases-change-language' );
1271
1272 if( $langid = (int) wpfval( $_POST, 'langid' ) ){
1273 if( WPF()->phrase->set_language_status( $langid ) ){
1274 WPF()->notice->add( 'Successfully updated', 'success' );
1275 }else{
1276 WPF()->notice->add( 'Invalid request!', 'error' );
1277 }
1278 }
1279
1280 wp_safe_redirect( wp_get_raw_referer() );
1281 exit();
1282 }
1283
1284 /**
1285 * colors.css download action
1286 */
1287 public function colors_css_download() {
1288 check_admin_referer( 'dynamic_css_download' );
1289
1290 if( ! WPF()->usergroup->can( 'ms' ) ) {
1291 WPF()->notice->add( 'Permission denied', 'error' );
1292 wp_safe_redirect( admin_url() );
1293 exit();
1294 }
1295
1296 $dynamic_css = WPF()->tpl->generate_dynamic_css();
1297 header( 'Content-Type: application/download' );
1298 header( 'Content-Disposition: attachment; filename="colors.css"' );
1299 header( 'Content-Transfer-Encoding: binary' );
1300 header( "Content-Length: " . strlen( $dynamic_css ) );
1301 echo $dynamic_css;
1302 exit();
1303 }
1304
1305
1306 /**
1307 * cleanup_options_save form submit action
1308 */
1309 public function cleanup_options_save() {
1310 check_admin_referer( 'wpforo-tools-cleanup' );
1311
1312 if( ! WPF()->usergroup->can( 'mt' ) ) {
1313 WPF()->notice->add( 'Permission denied', 'error' );
1314 wp_safe_redirect( admin_url() );
1315 exit();
1316 }
1317
1318 if( ! wpfkey( $_POST, 'reset' ) ) {
1319 if( $options = wpfval( $_POST, 'wpforo_tools_cleanup' ) ) {
1320 if( wpforo_update_option( 'tools_cleanup', $options ) ) {
1321 WPF()->notice->add( 'Settings successfully updated', 'success' );
1322 }
1323 }
1324 } else {
1325 wpforo_delete_option( 'tools_cleanup' );
1326 WPF()->notice->add( 'Cleanup options reset successfully', 'success' );
1327 }
1328
1329 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=cleanup' ) );
1330 exit();
1331 }
1332
1333 /**
1334 * misc_options_save form submit action
1335 */
1336 public function misc_options_save() {
1337 check_admin_referer( 'wpforo-tools-misc' );
1338
1339 if( ! WPF()->usergroup->can( 'mt' ) ) {
1340 WPF()->notice->add( 'Permission denied', 'error' );
1341 wp_safe_redirect( admin_url() );
1342 exit();
1343 }
1344
1345 if( ! wpfkey( $_POST, 'reset' ) ) {
1346 if( $options = wpfval( $_POST, 'wpforo_tools_misc' ) ) {
1347 $options['admin_note'] = wpforo_kses( $options['admin_note'] );
1348 $options['admin_note_groups'] = ( wpfval( $_POST, 'wpforo_tools_misc', 'admin_note_groups' ) ) ? array_map( 'intval', $options['admin_note_groups'] ) : [];
1349 $options['admin_note_pages'] = ( wpfval( $_POST, 'wpforo_tools_misc', 'admin_note_pages' ) ) ? array_map( 'sanitize_textarea_field', $options['admin_note_pages'] ) : [];
1350 if( wpforo_update_option( 'tools_misc', $options ) ) {
1351 wpforo_clean_cache( 'forum-soft' );
1352 WPF()->notice->add( 'Settings successfully updated', 'success' );
1353 }
1354 }
1355 } else {
1356 wpforo_delete_option( 'tools_misc' );
1357 WPF()->notice->add( 'Misc options reset successfully', 'success' );
1358 }
1359
1360 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=misc' ) );
1361 exit();
1362 }
1363
1364 /**
1365 * legal_options_save form submit action
1366 */
1367 public function legal_options_save() {
1368 check_admin_referer( 'wpforo-tools-legal' );
1369
1370 if( ! WPF()->usergroup->can( 'mt' ) ) {
1371 WPF()->notice->add( 'Permission denied', 'error' );
1372 wp_safe_redirect( admin_url() );
1373 exit();
1374 }
1375
1376 if( ! wpfkey( $_POST, 'reset' ) ) {
1377 if( $options = wpfval( $_POST, 'wpforo_tools_legal' ) ) {
1378 $options['contact_page_url'] = esc_url( (string) $options['contact_page_url'] );
1379 $options['checkbox_terms_privacy'] = intval( $options['checkbox_terms_privacy'] );
1380 $options['checkbox_email_password'] = intval( $options['checkbox_email_password'] );
1381 $options['page_terms'] = esc_url( (string) $options['page_terms'] );
1382 $options['page_privacy'] = esc_url( (string) $options['page_privacy'] );
1383 $options['checkbox_forum_privacy'] = intval( $options['checkbox_forum_privacy'] );
1384 $options['forum_privacy_text'] = wpforo_kses( $options['forum_privacy_text'], 'post' );
1385 $options['checkbox_fb_login'] = intval( $options['checkbox_fb_login'] );
1386 $options['cookies'] = intval( $options['cookies'] );
1387 $options['rules_checkbox'] = intval( $options['rules_checkbox'] );
1388 $options['rules_text'] = wpforo_kses( $options['rules_text'], 'post' );
1389 if( wpforo_update_option( 'tools_legal', $options ) ) {
1390 WPF()->notice->add( 'Settings successfully updated', 'success' );
1391 }
1392 }
1393 } else {
1394 wpforo_delete_option( 'tools_legal' );
1395 WPF()->notice->add( 'Settings reset successfully', 'success' );
1396 }
1397
1398 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=legal' ) );
1399 exit();
1400 }
1401
1402 /**
1403 * delete detected spam file
1404 */
1405 public function delete_spam_file() {
1406 check_admin_referer( 'wpforo_tools_antispam_files' );
1407
1408 if( ! WPF()->usergroup->can( 'mt' ) ) {
1409 WPF()->notice->add( 'Permission denied', 'error' );
1410 wp_safe_redirect( admin_url() );
1411 exit();
1412 }
1413
1414 if( $filename = trim( (string) wpfval( $_GET, 'sfname' ) ) ) {
1415 $filename = str_replace( [ '../', './', '/' ], '', sanitize_file_name( $filename ) );
1416 $filename = urldecode( (string) $filename );
1417 if( $filename ) {
1418 $attachmentid = WPF()->post->get_attachment_id( '/' . $filename );
1419 if( ! wp_delete_attachment( $attachmentid ) ) {
1420 @unlink( WPF()->folders['default_attachments']['dir'] . DIRECTORY_SEPARATOR . $filename );
1421 }
1422 WPF()->notice->add( 'Deleted', 'success' );
1423 }
1424 }
1425
1426 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=antispam' ) );
1427 exit();
1428 }
1429
1430 /**
1431 * delete_all_spam_files all detected spam file using level attribute
1432 */
1433 public function delete_all_spam_files() {
1434 check_admin_referer( 'wpforo_tools_antispam_files' );
1435
1436 if( ! WPF()->usergroup->can( 'mt' ) ) {
1437 WPF()->notice->add( 'Permission denied', 'error' );
1438 wp_safe_redirect( admin_url() );
1439 exit();
1440 }
1441
1442 if( $delete_level = (int) wpfval( $_GET, 'level' ) ) {
1443 $default_attachments_dir = WPF()->folders['default_attachments']['dir'];
1444 if( is_dir( $default_attachments_dir ) ) {
1445 if( $handle = opendir( $default_attachments_dir ) ) {
1446 while( false !== ( $filename = readdir( $handle ) ) ) {
1447 if( $filename === '.' || $filename === '..' ) continue;
1448 if( ! $level = WPF()->moderation->spam_file( $filename ) ) continue;
1449 if( $delete_level === $level ) {
1450 $attachmentid = WPF()->post->get_attachment_id( '/' . $filename );
1451 if( ! wp_delete_attachment( $attachmentid ) ) {
1452 @unlink( $default_attachments_dir . DIRECTORY_SEPARATOR . $filename );
1453 }
1454 }
1455 }
1456 closedir( $handle );
1457 WPF()->notice->add( 'Deleted', 'success' );
1458 }
1459 }
1460 }
1461
1462 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=antispam' ) );
1463 exit();
1464 }
1465
1466 /**
1467 * do database alter fixing using install.sql db-strukture
1468 */
1469 public function database_update() {
1470 check_admin_referer( 'wpforo_update_database' );
1471
1472 if( ! WPF()->usergroup->can( 'mt' ) ) {
1473 WPF()->notice->add( 'Permission denied', 'error' );
1474 wp_safe_redirect( admin_url() );
1475 exit();
1476 }
1477
1478 wpforo_set_max_execution_time( 3600 );
1479
1480 wpforo_update_db();
1481
1482 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=debug&view=tables' ) );
1483 exit();
1484 }
1485
1486 public function forum_copy() {
1487 wpforo_verify_nonce( 'forum_copy', 'full' );
1488
1489 if( ! WPF()->usergroup->can_manage_forum() ) {
1490 WPF()->notice->add( 'Permission denied', 'error' );
1491 wp_safe_redirect( admin_url() );
1492 exit();
1493 }
1494
1495 $forumid = (int) wpfval( $_GET, 'forumid' );
1496
1497 if( $forumid ){
1498 WPF()->forum->copy( $forumid );
1499 }
1500
1501 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) ) );
1502 exit();
1503 }
1504
1505 /**
1506 * forum_add form submit action
1507 */
1508 public function forum_add() {
1509 check_admin_referer( 'wpforo-forum-add' );
1510
1511 if( ! WPF()->usergroup->can_manage_forum() ) {
1512 WPF()->notice->add( 'Permission denied', 'error' );
1513 wp_safe_redirect( admin_url() );
1514 exit();
1515 }
1516
1517 if( ! empty( $_REQUEST['forum'] ) ) {
1518 WPF()->forum->add();
1519 }
1520
1521 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) ) );
1522 exit();
1523 }
1524
1525 /**
1526 * forum_edit form submit action
1527 */
1528 public function forum_edit() {
1529 check_admin_referer( 'wpforo-forum-edit' );
1530
1531 if( ! WPF()->usergroup->can_manage_forum() ) {
1532 WPF()->notice->add( 'Permission denied', 'error' );
1533 wp_safe_redirect( admin_url() );
1534 exit();
1535 }
1536
1537 if( ! empty( $_REQUEST['forum'] ) ) {
1538 WPF()->forum->edit();
1539 }
1540
1541 wp_safe_redirect( wpforo_get_request_uri() );
1542 exit();
1543 }
1544
1545 /**
1546 * forum_delete form submit action
1547 */
1548 public function forum_delete() {
1549 check_admin_referer( 'wpforo-forum-delete' );
1550
1551 if( ! WPF()->usergroup->can_manage_forum() ) {
1552 WPF()->notice->add( 'Permission denied', 'error' );
1553 wp_safe_redirect( admin_url() );
1554 exit();
1555 }
1556
1557 $delete = (int) wpfval( $_REQUEST, 'forum', 'delete' );
1558 if( $delete === 1 ) {
1559 WPF()->forum->delete( 0, false );
1560 } elseif( $delete === 0 ) {
1561 WPF()->forum->merge();
1562 }
1563
1564 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) ) );
1565 exit();
1566 }
1567
1568 /**
1569 * forum_hierarchy_save form submit action
1570 */
1571 public function forum_hierarchy_save() {
1572 check_admin_referer( 'wpforo-forums-hierarchy' );
1573
1574 if( ! WPF()->usergroup->can_manage_forum() ) {
1575 WPF()->notice->add( 'Permission denied', 'error' );
1576 wp_safe_redirect( admin_url() );
1577 exit();
1578 }
1579
1580 if( ! empty( $_REQUEST['forum'] ) ) {
1581 WPF()->forum->update_hierarchy();
1582 wpforo_clean_cache( 'forum' );
1583 }
1584
1585 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) ) );
1586 exit();
1587 }
1588
1589 /**
1590 * dashboard_post_unapprove action
1591 */
1592 public function dashboard_post_unapprove() {
1593 $postid = wpfval( $_GET, 'postid' );
1594 check_admin_referer( "wpforo-unapprove-post-{$postid}" );
1595
1596 if( ! WPF()->usergroup->can( 'aum' ) ) {
1597 WPF()->notice->add( 'Permission denied', 'error' );
1598 wp_safe_redirect( admin_url() );
1599 exit();
1600 }
1601
1602 WPF()->moderation->post_unapprove( $postid );
1603 wpforo_clean_cache( 'post', $postid );
1604
1605 wp_safe_redirect( wp_get_referer() );
1606 exit();
1607 }
1608
1609 /**
1610 * dashboard_post_approve action
1611 */
1612 public function dashboard_post_approve() {
1613 $postid = wpfval( $_GET, 'postid' );
1614 check_admin_referer( "wpforo-approve-post-{$postid}" );
1615
1616 if( ! WPF()->usergroup->can( 'aum' ) ) {
1617 WPF()->notice->add( 'Permission denied', 'error' );
1618 wp_safe_redirect( admin_url() );
1619 exit();
1620 }
1621
1622 WPF()->moderation->post_approve( $postid );
1623 wpforo_clean_cache( 'post', $postid );
1624
1625 wp_safe_redirect( wp_get_referer() );
1626 exit();
1627 }
1628
1629 /**
1630 * dashboard_post_delete action
1631 */
1632 public function dashboard_post_delete() {
1633 $postid = wpfval( $_GET, 'postid' );
1634 check_admin_referer( "wpforo-delete-post-{$postid}" );
1635
1636 if( ! WPF()->usergroup->can( 'aum' ) ) {
1637 WPF()->notice->add( 'Permission denied', 'error' );
1638 wp_safe_redirect( admin_url() );
1639 exit();
1640 }
1641
1642 WPF()->post->delete( $postid );
1643
1644 wp_safe_redirect( wp_get_referer() );
1645 exit();
1646 }
1647
1648 /**
1649 * doing bulk moderation actions ( approve, unapprove, delete )
1650 */
1651 public function bulk_moderation() {
1652 check_admin_referer( 'bulk-moderations' );
1653
1654 if( ! WPF()->usergroup->can( 'aum' ) ) {
1655 WPF()->notice->add( 'Permission denied', 'error' );
1656 wp_safe_redirect( admin_url() );
1657 exit();
1658 }
1659
1660 $u_action = $this->get_current_bulk_action();
1661 $postids = (array) wpfval( $_GET, 'postids' );
1662 if( $u_action && ! empty( $postids ) ) {
1663 if( $u_action === 'delete' ) {
1664 foreach( $postids as $postid ) WPF()->post->delete( $postid );
1665 } elseif( $u_action === 'approve' ) {
1666 foreach( $postids as $postid ) WPF()->moderation->post_approve( $postid );
1667 } elseif( $u_action === 'unapprove' ) {
1668 foreach( $postids as $postid ) WPF()->moderation->post_unapprove( $postid );
1669 }
1670 }
1671
1672 wp_safe_redirect( wp_get_referer() );
1673 exit();
1674 }
1675
1676 /**
1677 * phrase_add form submit action
1678 */
1679 public function phrase_add() {
1680 check_admin_referer( 'wpforo-phrase-add' );
1681
1682 if( ! WPF()->usergroup->can( 'mp' ) ) {
1683 WPF()->notice->add( 'Permission denied', 'error' );
1684 wp_safe_redirect( admin_url() );
1685 exit();
1686 }
1687
1688 if( ! empty( $_POST['phrase'] ) ) {
1689 WPF()->phrase->add();
1690 }
1691
1692 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) ) );
1693 exit();
1694 }
1695
1696 /**
1697 * phrase_edit_form action redirect to phrase list page when phraseid(s) not chosen
1698 */
1699 public function phrase_edit_form() {
1700 $phraseids = array_filter( array_map( 'intval', array_merge( (array) wpfval( $_GET, 'phraseid' ), (array) wpfval( $_GET, 'phraseids' ) ) ) );
1701 if( ! $phraseids ) {
1702 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) ) );
1703 exit();
1704 }
1705 }
1706
1707 /**
1708 * phrase_edit form submit action
1709 */
1710 public function phrase_edit() {
1711 check_admin_referer( 'wpforo-phrases-edit' );
1712
1713 if( ! WPF()->usergroup->can( 'mp' ) ) {
1714 WPF()->notice->add( 'Permission denied', 'error' );
1715 wp_safe_redirect( admin_url() );
1716 exit();
1717 }
1718
1719 if( ! empty( $_POST['phrases'] ) ) {
1720 WPF()->phrase->edit();
1721 }
1722
1723 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) ) );
1724 exit();
1725 }
1726
1727 /**
1728 * user_ban action
1729 */
1730 public function user_ban() {
1731 $userid = intval( wpfval( $_GET, 'userid' ) );
1732 check_admin_referer( 'wpforo-user-ban-' . $userid );
1733
1734 if( ! WPF()->usergroup->can( 'vm' ) || ! WPF()->usergroup->can( 'bm' ) || $userid === WPF()->current_userid ) {
1735 WPF()->notice->add( 'Permission denied', 'error' );
1736 wp_safe_redirect( admin_url() );
1737 exit();
1738 }
1739
1740 WPF()->member->ban( $userid );
1741 wpforo_clean_cache( 'user' );
1742
1743 wp_safe_redirect( wp_get_referer() );
1744 exit();
1745 }
1746
1747 /**
1748 * user_unban action
1749 */
1750 public function user_unban() {
1751 $userid = intval( wpfval( $_GET, 'userid' ) );
1752 check_admin_referer( 'wpforo-user-unban-' . $userid );
1753
1754 if( ! WPF()->usergroup->can( 'vm' ) || ! WPF()->usergroup->can( 'bm' ) || $userid === WPF()->current_userid ) {
1755 WPF()->notice->add( 'Permission denied', 'error' );
1756 wp_safe_redirect( admin_url() );
1757 exit();
1758 }
1759
1760 WPF()->member->unban( $userid );
1761 wpforo_clean_cache( 'user' );
1762
1763 wp_safe_redirect( wp_get_referer() );
1764 exit();
1765 }
1766
1767 /**
1768 * user_activate action
1769 */
1770 public function user_activate() {
1771 $userid = intval( wpfval( $_GET, 'userid' ) );
1772 check_admin_referer( 'wpforo-user-activate-' . $userid );
1773
1774 if( ! WPF()->usergroup->can( 'vm' ) || ! WPF()->usergroup->can( 'bm' ) || $userid === WPF()->current_userid ) {
1775 WPF()->notice->add( 'Permission denied', 'error' );
1776 wp_safe_redirect( admin_url() );
1777 exit();
1778 }
1779
1780 WPF()->member->activate( $userid );
1781
1782 wp_safe_redirect( wp_get_referer() );
1783 exit();
1784 }
1785
1786 /**
1787 * user_deactivate action
1788 */
1789 public function user_deactivate() {
1790 $userid = intval( wpfval( $_GET, 'userid' ) );
1791 check_admin_referer( 'wpforo-user-deactivate-' . $userid );
1792
1793 if( ! WPF()->usergroup->can( 'vm' ) || ! WPF()->usergroup->can( 'bm' ) || $userid === WPF()->current_userid ) {
1794 WPF()->notice->add( 'Permission denied', 'error' );
1795 wp_safe_redirect( admin_url() );
1796 exit();
1797 }
1798
1799 WPF()->member->deactivate( $userid );
1800
1801 wp_safe_redirect( wp_get_referer() );
1802 exit();
1803 }
1804
1805 public function user_ban_ajax() {
1806 wpforo_verify_nonce( 'wpforo_user_ban' );
1807 $userid = WPF()->current_object['user']['userid'];
1808 $currentstate = (int) wpfval( $_POST, 'currentstate' );
1809 if( $currentstate ){
1810 $r = WPF()->member->unban( $userid );
1811 }else{
1812 $r = WPF()->member->ban( $userid );
1813 }
1814
1815 if( $r ){
1816 wp_send_json_success( [
1817 'currentstate' => (int) !$currentstate,
1818 'notice' => WPF()->notice->get_notices(),
1819 ] );
1820 }else{
1821 wp_send_json_error( [ 'notice' => WPF()->notice->get_notices() ] );
1822 }
1823 }
1824
1825 public function get_member_template() {
1826 wpforo_verify_nonce( 'wpforo_get_member_template' );
1827 $href = wpfval( $_POST, 'href' );
1828 WPF()->init_current_url( $href );
1829 WPF()->init_current_object();
1830 if( wpforo_is_member_template() ){
1831 if( ( $template = WPF()->tpl->get_template( WPF()->current_object['template'] ) ) && $template['type'] === 'callback' && is_callable( $template['callback_for_page'] ) ){
1832 ob_start();
1833 echo call_user_func( $template['callback_for_page'], $template );
1834 wp_send_json_success( [ 'html' => ob_get_clean() ] );
1835 }
1836 }
1837 wp_send_json_error();
1838 }
1839
1840 public function search_existed_topics() {
1841 if( !apply_filters('wpforo_topic_suggestion', true ) ){
1842 wp_send_json_error();
1843 }
1844 wpforo_verify_nonce( 'wpforo_search_existed_topics' );
1845 $title = trim( (string) wpfval( $_POST, 'title' ) );
1846 $topicids = WPF()->topic->search( $title, 'title' );
1847 if( $topicids ){
1848 $topics = WPF()->topic->get_topics( [ 'include' => $topicids, 'row_count' => apply_filters( 'wpforo_suggested_topics_limit', 5 ), 'orderby' => 'created' ] );
1849 if( $topics ){
1850 $topics = array_map( function( $topic ){
1851 $topic['url'] = WPF()->topic->get_url( $topic );
1852 return $topic;
1853 }, $topics );
1854
1855 wp_send_json_success( $topics );
1856 }
1857 }
1858
1859 wp_send_json_error();
1860 }
1861
1862 public function user_delete() {
1863 wpforo_verify_nonce( 'user_delete', 'full' );
1864 if(
1865 WPF()->current_object['user']
1866 && ( $action = WPF()->member->get_action( WPF()->current_object['user'], 'delete' ) )
1867 && is_callable( $action['callback_for_can'] )
1868 && call_user_func( $action['callback_for_can'] )
1869 ){
1870 if( ! function_exists( 'wp_delete_user' ) ) require_once ABSPATH . "wp-admin/includes/user.php";
1871 if( wp_delete_user( WPF()->current_object['user']['userid'] ) ){
1872 WPF()->notice->add( 'User successfully deleted', 'success' );
1873 }else{
1874 WPF()->notice->add( 'User delete error', 'error' );
1875 }
1876 }else{
1877 WPF()->notice->add( 'Permission denied for this action', 'error' );
1878 }
1879
1880 wp_safe_redirect( wpforo_url( '', 'members' ) );
1881 exit();
1882 }
1883
1884 /**
1885 * action after WordPress native deleted_user hook
1886 *
1887 * @param int $userid already deleted user ID
1888 */
1889 public function deleted_user( $userid, $reassign = null ) {
1890 if( wpfval( $_REQUEST, 'wpforo_user_delete_option' ) === 'reassign' ){
1891 WPF()->member->delete( $userid, wpforo_bigintval( wpfval( $_REQUEST, 'wpforo_reassign_userid' ) ) );
1892 }elseif( wpfval( $_REQUEST, 'wpforo_user_delete_option' ) === 'delete' ){
1893 WPF()->member->delete( $userid );
1894 }elseif( $reassign ){
1895 WPF()->member->delete( $userid, $reassign );
1896 }else{
1897 WPF()->member->delete( $userid, ( wpforo_setting( 'authorization', 'user_delete_method' ) === 'soft' ? 0 : null ) );
1898 }
1899 WPF()->notice->clear();
1900 }
1901
1902 /**
1903 * doing bulk member actions ( ban, unban, delete )
1904 */
1905 public function bulk_members() {
1906 check_admin_referer( 'bulk-members' );
1907
1908 if( ! WPF()->usergroup->can( 'vm' ) ) {
1909 WPF()->notice->add( 'Permission denied', 'error' );
1910 wp_safe_redirect( admin_url() );
1911 exit();
1912 }
1913
1914 $new_groupid = - 1;
1915 if( ! empty( $_GET['new_groupid'] ) && $_GET['new_groupid'] !== '-1' ) {
1916 $new_groupid = intval( $_GET['new_groupid'] );
1917 } elseif( ! empty( $_GET['new_groupid2'] ) && $_GET['new_groupid2'] !== '-1' ) {
1918 $new_groupid = intval( $_GET['new_groupid2'] );
1919 }
1920
1921 $u_action = $this->get_current_bulk_action();
1922 if( in_array( $u_action, [ 'ban', 'unban', 'activate', 'deactivate' ] ) && ! WPF()->usergroup->can( 'bm' ) ) {
1923 WPF()->notice->add( 'Permission denied', 'error' );
1924 wp_safe_redirect( admin_url() );
1925 exit();
1926 } elseif( $u_action === 'delete' && ! WPF()->usergroup->can( 'dm' ) ) {
1927 WPF()->notice->add( 'Permission denied', 'error' );
1928 wp_safe_redirect( admin_url() );
1929 exit();
1930 }
1931
1932 $userids = (array) wpfval( $_GET, 'userids' );
1933 $userids = array_filter( array_map( 'wpforo_bigintval', $userids ) );
1934 $userids = array_diff( $userids, (array) WPF()->current_userid );
1935 if( $u_action && ! empty( $userids ) ) {
1936 if( $u_action === 'delete' ) {
1937 $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) );
1938 $url = str_replace( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
1939 wp_safe_redirect( $url );
1940 exit();
1941 } elseif( $u_action === 'ban' ) {
1942 foreach( $userids as $userid ) {
1943 WPF()->member->ban( $userid );
1944 }
1945 } elseif( $u_action === 'unban' ) {
1946 foreach( $userids as $userid ) {
1947 WPF()->member->unban( $userid );
1948 }
1949 } elseif( $u_action === 'activate' ) {
1950 foreach( $userids as $userid ) {
1951 WPF()->member->activate( $userid );
1952 }
1953 } elseif( $u_action === 'deactivate' ) {
1954 foreach( $userids as $userid ) {
1955 WPF()->member->deactivate( $userid );
1956 }
1957 }
1958 } elseif( ! $u_action && wpfkey( $_GET, 'change_group' ) ) {
1959 if( ! empty( $userids ) && $new_groupid !== - 1 ) {
1960 $status = WPF()->usergroup->set_users_groupid( [ $new_groupid => $userids ] );
1961 if( $status['success'] ) WPF()->notice->add( 'Usergroup is successfully changed for selected users', 'success' );
1962 } else {
1963 WPF()->notice->add( 'Please select users and usergroup', 'error' );
1964 }
1965 }
1966 wpforo_clean_cache( 'user' );
1967
1968 wp_safe_redirect( wp_get_referer() );
1969 exit();
1970 }
1971
1972 /**
1973 * usergroup_add form submit action
1974 */
1975 public function usergroup_add() {
1976 check_admin_referer( 'wpforo-usergroup-add' );
1977
1978 if( ! WPF()->usergroup->can( 'vmg' ) ) {
1979 WPF()->notice->add( 'Permission denied', 'error' );
1980 wp_safe_redirect( admin_url() );
1981 exit();
1982 }
1983
1984 if( ! empty( $_POST['usergroup'] ) ) {
1985 $group = WPF()->usergroup->fix_group( $_POST['usergroup'] );
1986 $color = wpfval( $group, 'wpfugc' ) ? '' : sanitize_text_field( $group['color'] );
1987 $groupid = WPF()->usergroup->add( $group['name'], $group['cans'], $group['description'], $group['role'], $group['access'], $color, $group['visible'], $group['secondary'] );
1988 if( $groupid ) wpforo_clean_cache( 'loop', $groupid );
1989 }
1990
1991 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) ) );
1992 exit();
1993 }
1994
1995 /**
1996 * usergroup_edit form submit action
1997 */
1998 public function usergroup_edit() {
1999 check_admin_referer( 'wpforo-usergroup-edit' );
2000
2001 if( ! WPF()->usergroup->can( 'vmg' ) ) {
2002 WPF()->notice->add( 'Permission denied', 'error' );
2003 wp_safe_redirect( admin_url() );
2004 exit();
2005 }
2006
2007 if( ! empty( $_POST['usergroup'] ) ) {
2008 $group = WPF()->usergroup->fix_group( $_POST['usergroup'] );
2009 $color = wpfval( $group, 'wpfugc' ) ? '' : sanitize_text_field( $group['color'] );
2010 WPF()->usergroup->edit( $group['groupid'], $group['name'], $group['cans'], $group['description'], $group['role'], null, $color, $group['visible'], $group['secondary'] );
2011 wpforo_clean_cache( 'loop', $group['groupid'] );
2012 }
2013
2014 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) ) );
2015 exit();
2016 }
2017
2018 /**
2019 * usergroup_delete form submit action
2020 */
2021 public function usergroup_delete() {
2022 check_admin_referer( 'wpforo-usergroup-delete' );
2023
2024 if( ! WPF()->usergroup->can( 'vmg' ) ) {
2025 WPF()->notice->add( 'Permission denied', 'error' );
2026 wp_safe_redirect( admin_url() );
2027 exit();
2028 }
2029
2030 if( wpfval( $_POST, 'usergroup', 'delete' ) ) {
2031 $args = [ 'groupid' => wpfval( $_POST, 'usergroup', 'groupid' ) ];
2032 if( $userids = WPF()->member->get_userids( $args ) ) {
2033 $redirect_to = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) );
2034 $redirect_to = str_replace( '&amp;', '&', wp_nonce_url( $redirect_to, 'bulk-users' ) );
2035 wp_safe_redirect( $redirect_to );
2036 exit();
2037 }
2038 }
2039
2040 if( ! empty( $_POST['usergroup'] ) ) {
2041 WPF()->usergroup->delete( wpfval( $_POST['usergroup'], 'groupid' ), wpfval( $_POST['usergroup'], 'mergeid' ) );
2042 wpforo_clean_cache( 'user' );
2043 }
2044
2045 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) ) );
2046 exit();
2047 }
2048
2049 /**
2050 * default_groupid_change action
2051 */
2052 public function default_groupid_change() {
2053 $default_groupid = intval( wpfval( $_GET, 'default_groupid' ) );
2054 check_admin_referer( 'wpforo-default-groupid-change-' . $default_groupid );
2055
2056 if( ! WPF()->usergroup->can( 'vmg' ) ) {
2057 WPF()->notice->add( 'Permission denied', 'error' );
2058 wp_safe_redirect( admin_url() );
2059 exit();
2060 }
2061
2062 if( $default_groupid ) WPF()->usergroup->set_default( $default_groupid );
2063
2064 wp_safe_redirect( wp_get_raw_referer() );
2065 exit();
2066 }
2067
2068 /**
2069 * prevent to show usergroup delete form when !$groupid || $groupid <= 5
2070 */
2071 public function usergroup_delete_form() {
2072 if( intval( wpfval( $_GET, 'groupid' ) ) <= 5 ) {
2073 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) ) );
2074 exit();
2075 }
2076 }
2077
2078 /**
2079 * access_add form submit action
2080 */
2081 public function access_add() {
2082 check_admin_referer( 'wpforo-access-add' );
2083
2084 if( ! WPF()->usergroup->can( 'ms' ) ) {
2085 WPF()->notice->add( 'Permission denied', 'error' );
2086 wp_safe_redirect( admin_url() );
2087 exit();
2088 }
2089
2090 if( ! empty( $_POST['access'] ) ) {
2091 WPF()->perm->add( WPF()->perm->fix_access( $_POST['access'] ) );
2092 }
2093
2094 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'accesses' ) ) );
2095 exit();
2096 }
2097
2098 /**
2099 * access_edit form submit action
2100 */
2101 public function access_edit() {
2102 check_admin_referer( 'wpforo-access-edit' );
2103
2104 if( ! WPF()->usergroup->can( 'ms' ) ) {
2105 WPF()->notice->add( 'Permission denied', 'error' );
2106 wp_safe_redirect( admin_url() );
2107 exit();
2108 }
2109
2110 if( ! empty( $_POST['access'] ) ) {
2111 WPF()->perm->edit( WPF()->perm->fix_access( $_POST['access'] ) );
2112 wpforo_clean_cache( 'loop' );
2113 }
2114
2115 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'accesses' ) ) );
2116 exit();
2117 }
2118
2119 /**
2120 * access_delete form submit action
2121 */
2122 public function access_delete() {
2123 $accessid = intval( wpfval( $_GET, 'accessid' ) );
2124 check_admin_referer( 'wpforo-access-delete-' . $accessid );
2125
2126 if( ! WPF()->usergroup->can( 'ms' ) ) {
2127 WPF()->notice->add( 'Permission denied', 'error' );
2128 wp_safe_redirect( admin_url() );
2129 exit();
2130 }
2131
2132 WPF()->perm->delete( $accessid );
2133 wpforo_clean_cache( 'loop' );
2134
2135 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'accesses' ) ) );
2136 exit();
2137 }
2138
2139 public function theme_activate() {
2140 check_admin_referer( 'wpforo-theme-activate' );
2141
2142 if( ! WPF()->usergroup->can( 'mth' ) ) {
2143 WPF()->notice->add( 'Permission denied', 'error' );
2144 wp_safe_redirect( admin_url() );
2145 exit();
2146 }
2147
2148 $notice = __( 'Theme file not readable', 'wpforo' );
2149 $notice_type = 'error';
2150 if( ( $theme = trim( sanitize_text_field( (string) wpfval( $_GET, 'theme' ) ) ) ) && WPF()->tpl->theme_exists( $theme ) ) {
2151 $general = WPF()->settings->general;
2152 $general['current_theme'] = $theme;
2153 wpforo_update_option( 'wpforo_general', $general );
2154 $notice = __( 'Theme Successfully Activated', 'wpforo' );
2155 $notice_type = 'success';
2156 }
2157
2158 WPF()->notice->add( $notice, $notice_type );
2159 wp_safe_redirect( wp_get_raw_referer() );
2160 exit();
2161 }
2162
2163 /**
2164 * theme_delete action
2165 */
2166 public function theme_delete() {
2167 check_admin_referer( 'wpforo-theme-delete' );
2168
2169 if( ! WPF()->usergroup->can( 'mth' ) ) {
2170 WPF()->notice->add( 'Permission denied', 'error' );
2171 wp_safe_redirect( admin_url() );
2172 exit();
2173 }
2174
2175 $notice = __( 'Theme delete error', 'wpforo' );
2176 $notice_type = 'error';
2177 if( $theme = trim( sanitize_text_field( (string) wpfval( $_GET, 'theme' ) ) ) ) {
2178 if( WPF()->tpl->theme !== $theme ) {
2179 $remove_dir = WPFORO_THEME_DIR . '/' . $theme;
2180 if( is_dir( $remove_dir ) ) {
2181 wpforo_remove_directory( $remove_dir );
2182 $notice = __( 'Theme delete success', 'wpforo' );
2183 $notice_type = 'success';
2184 }
2185 }
2186 }
2187
2188 WPF()->notice->add( $notice, $notice_type );
2189 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'themes' ) ) );
2190 exit();
2191 }
2192
2193 /**
2194 * update wpForo addons CSS styles to make compatible with the current version of wpForo
2195 */
2196 function update_addons_css() {
2197 check_admin_referer( 'wpforo-update-addons-css' );
2198 wpforo_wrap_in_all_addons_css();
2199 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'settings' ) ) );
2200 exit();
2201 }
2202
2203 /**
2204 * dissmiss the poll version is old notification for admins
2205 */
2206 public function dissmiss_poll_version_is_old() {
2207 check_admin_referer( 'wpforo-dissmiss-poll-version-is-old' );
2208 WPF()->dissmissed['poll_version_is_old'] = 1;
2209 wpforo_update_option( 'dissmissed', WPF()->dissmissed );
2210 wp_safe_redirect( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ) );
2211 exit();
2212 }
2213
2214 /**
2215 * dissmiss the recaptcha not configured notification for admins
2216 */
2217 public function dissmiss_recaptcha_note() {
2218 if( wpfval( $_POST, 'backend' ) ) {
2219 WPF()->dissmissed['recaptcha_backend_note'] = 1;
2220 } else {
2221 WPF()->dissmissed['recaptcha_note'] = 1;
2222 }
2223 $response = wpforo_update_option( 'dissmissed', WPF()->dissmissed );
2224 if( $response ) {
2225 wp_send_json_success();
2226 } else {
2227 wp_send_json_error();
2228 }
2229 }
2230
2231 /**
2232 * wpforo before deactivate action
2233 */
2234 public function deactivate() {
2235 $response = [ 'code' => 0 ];
2236 $json = filter_input( INPUT_POST, 'deactivateData' );
2237 if( $json ) {
2238 parse_str( $json, $data );
2239
2240 $blogTitle = get_option( 'blogname' );
2241 $to = 'feedback@wpforo.com';
2242 $subject = '[wpForo Feedback - ' . WPFORO_VERSION . ']';
2243 $headers = [];
2244 $contentType = 'text/html';
2245 $fromName = apply_filters( 'wp_mail_from_name', $blogTitle );
2246 $fromName = html_entity_decode( $fromName, ENT_QUOTES );
2247 $siteUrl = get_site_url();
2248 $parsedUrl = parse_url( $siteUrl );
2249 $domain = isset( $parsedUrl['host'] ) ? $parsedUrl['host'] : '';
2250 $fromEmail = 'no-reply@' . $domain;
2251 $headers[] = "Content-Type: $contentType; charset=UTF-8";
2252 $headers[] = "From: " . $fromName . " <" . $fromEmail . "> \r\n";
2253 $message = "Dismiss and never show again";
2254
2255 if( isset( $data['never_show'] ) && ( $v = intval( $data['never_show'] ) ) ) {
2256 wpforo_update_option( 'deactivation_dialog_never_show', $v );
2257 $response['code'] = 'dismiss_and_deactivate';
2258 } elseif( isset( $data['deactivation_reason'] ) && ( $reason = trim( (string) $data['deactivation_reason'] ) ) ) {
2259 $subject .= ' - ' . $reason;
2260 $message = "<strong>Deactivation reason:</strong> " . $reason . "\r\n" . "<br/>";
2261 if( isset( $data['deactivation_reason_desc'] ) && ( $reasonDesc = trim( (string) $data['deactivation_reason_desc'] ) ) ) {
2262 $message .= "<strong>Deactivation reason description:</strong> " . $reasonDesc . "\r\n" . "<br/>";
2263 }
2264 if( isset( $data['deactivation_feedback_email'] ) && ( $feedback_email = trim( (string) $data['deactivation_feedback_email'] ) ) ) {
2265 $to = 'support@wpforo.com';
2266 $message .= "<strong>Feedback Email:</strong> " . $feedback_email . "\r\n" . "<br/>";
2267 }
2268 $subject = html_entity_decode( $subject, ENT_QUOTES );
2269 $message = html_entity_decode( $message, ENT_QUOTES );
2270 $response['code'] = 'send_and_deactivate';
2271 }
2272
2273 wp_mail( $to, $subject, $message, $headers );
2274 }
2275 wp_die( json_encode( $response ) );
2276 }
2277
2278 /**
2279 * base_slugs_settings_save from submit action
2280 *
2281 * @return void
2282 */
2283 public function base_slugs_settings_save() {
2284 check_admin_referer( 'wpforo_settings_save_general' );
2285
2286 if( wpfkey( $_POST, 'reset' ) ) {
2287 wpforo_delete_option( 'wpforo_base_slugs' );
2288 WPF()->notice->add( 'Successfully Done', 'success' );
2289 } else {
2290 $slugs = wpforo_array_args_cast_and_merge( array_filter( array_map( 'sanitize_title', wp_unslash( $_POST['slugs'] ) ) ), WPF()->settings->_slugs );
2291 $slugs = array_intersect_key($slugs, WPF()->settings->_slugs);
2292 $slugs = array_diff_key( $slugs, WPF()->tpl->templates );
2293 if( $slugs == array_unique( $slugs ) ){
2294 wpforo_update_option( 'wpforo_base_slugs', $slugs );
2295 WPF()->notice->add( 'Successfully Done', 'success' );
2296 }else{
2297 WPF()->notice->add( 'Please save "Forum template slugs" uniqueness', 'error' );
2298 }
2299 }
2300
2301 /*wp_safe_redirect( wp_get_raw_referer() );
2302 exit();*/
2303 }
2304
2305 /**
2306 * general_settings_save from submit action
2307 *
2308 * @return void
2309 */
2310 public function general_settings_save() {
2311 check_admin_referer( 'wpforo_settings_save_general' );
2312
2313 if( wpfkey( $_POST, 'reset' ) ) {
2314 wpforo_delete_option( 'wpforo_general' );
2315 } else {
2316 $general = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['general'] ), WPF()->settings->_general );
2317 $general['admin_bar'] = array_map( 'intval', (array) wpfval( $_POST['general'], 'admin_bar' ) );
2318 $general['current_theme'] = WPF()->tpl->theme;
2319 wpforo_update_option( 'wpforo_general', $general );
2320 }
2321
2322 WPF()->notice->add( 'Successfully Done', 'success' );
2323 wp_safe_redirect( wp_get_raw_referer() );
2324 exit();
2325 }
2326
2327 /**
2328 * base_slugs_settings_save from submit action
2329 *
2330 * @return void
2331 */
2332 public function slugs_settings_save() {
2333 check_admin_referer( 'wpforo_settings_save_board' );
2334
2335 if( wpfkey( $_POST, 'reset' ) ) {
2336 wpforo_delete_option( 'slugs' );
2337 WPF()->notice->add( 'Successfully Done', 'success' );
2338 } else {
2339 $slugs = wpforo_array_args_cast_and_merge( array_filter( array_map( 'sanitize_title', wp_unslash( $_POST['slugs'] ) ) ), WPF()->settings->_slugs );
2340 $slugs = array_intersect_key($slugs, WPF()->tpl->templates);
2341 if( $slugs == array_unique( $slugs ) ){
2342 foreach( $this->generate_option_names( 'slugs' ) as $option_name ) {
2343 wpforo_update_option( $option_name, $slugs );
2344 }
2345 WPF()->notice->add( 'Successfully Done', 'success' );
2346 }else{
2347 WPF()->notice->add( 'Please save "Forum template slugs" uniqueness', 'error' );
2348 }
2349 }
2350
2351 /*wp_safe_redirect( wp_get_raw_referer() );
2352 exit();*/
2353 }
2354
2355 /**
2356 * general_settings_save from submit action
2357 *
2358 * @return void
2359 */
2360 public function board_settings_save() {
2361 check_admin_referer( 'wpforo_settings_save_board' );
2362
2363 if( wpfkey( $_POST, 'reset' ) ) {
2364 wpforo_delete_option( 'board' );
2365 } else {
2366 $board = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['board'] ), WPF()->settings->_board );
2367 foreach( $this->generate_option_names( 'board' ) as $option_name ) {
2368 wpforo_update_option( $option_name, $board );
2369 }
2370 }
2371
2372 wpforo_clean_cache();
2373
2374 WPF()->notice->add( 'Successfully Done', 'success' );
2375 wp_safe_redirect( wp_get_raw_referer() );
2376 exit();
2377 }
2378
2379 /**
2380 * akismet_settings_save from submit action
2381 *
2382 * @return void
2383 */
2384 public function akismet_settings_save() {
2385 check_admin_referer( 'wpforo_settings_save_akismet' );
2386
2387 if( wpfkey( $_POST, 'reset' ) ) {
2388 wpforo_delete_option( 'akismet' );
2389 } else {
2390 $akismet = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['akismet'] ), WPF()->settings->_akismet );
2391 foreach( $this->generate_option_names( 'akismet' ) as $option_name ) {
2392 wpforo_update_option( $option_name, $akismet );
2393 }
2394 }
2395
2396 WPF()->notice->add( 'Successfully Done', 'success' );
2397 wp_safe_redirect( wp_get_raw_referer() );
2398 exit();
2399 }
2400
2401 /**
2402 * antispam_settings_save from submit action
2403 *
2404 * @return void
2405 */
2406 public function antispam_settings_save() {
2407 check_admin_referer( 'wpforo_settings_save_antispam' );
2408
2409 if( wpfkey( $_POST, 'reset' ) ) {
2410 wpforo_delete_option( 'antispam' );
2411 } else {
2412 $antispam = wp_unslash( $_POST['antispam'] );
2413 $antispam['limited_file_ext'] = array_unique( array_filter( preg_split( '#\s*\|\s*|\s*,\s*|\s+#', trim( sanitize_textarea_field( (string) wpfval( $antispam, 'limited_file_ext' ) ) ) ) ) );
2414 $antispam['exclude_file_ext'] = array_unique( array_filter( preg_split( '#\s*\|\s*|\s*,\s*|\s+#', trim( sanitize_textarea_field( (string) wpfval( $antispam, 'exclude_file_ext' ) ) ) ) ) );
2415 $antispam = wpforo_array_args_cast_and_merge( $antispam, WPF()->settings->_antispam );
2416 foreach( $this->generate_option_names( 'antispam' ) as $option_name ) {
2417 wpforo_update_option( $option_name, $antispam );
2418 }
2419 }
2420
2421 WPF()->notice->add( 'Successfully Done', 'success' );
2422 wp_safe_redirect( wp_get_raw_referer() );
2423 exit();
2424 }
2425
2426 /**
2427 * authorization_settings_save after submit action
2428 *
2429 * @return void
2430 */
2431 public function authorization_settings_save() {
2432 check_admin_referer( 'wpforo_settings_save_authorization' );
2433
2434 if( wpfkey( $_POST, 'reset' ) ) {
2435 wpforo_delete_option( 'wpforo_authorization' );
2436 } else {
2437 $authorization = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['authorization'] ), WPF()->settings->_authorization );
2438
2439 if( preg_match( '#^https?://\S+$#iu', (string) $authorization['login_url'] ) ) $authorization['login_url'] = '';
2440 if( preg_match( '#^https?://\S+$#iu', (string) $authorization['register_url'] ) ) $authorization['register_url'] = '';
2441 if( preg_match( '#^https?://\S+$#iu', (string) $authorization['lost_password_url'] ) ) $authorization['lost_password_url'] = '';
2442
2443 if( ! preg_match( '#^https?://\S+$#iu', (string) $authorization['redirect_url_after_login'] ) ) $authorization['redirect_url_after_login'] = '';
2444 if( ! preg_match( '#^https?://\S+$#iu', (string) $authorization['redirect_url_after_register'] ) ) $authorization['redirect_url_after_register'] = '';
2445 if( ! preg_match( '#^https?://\S+$#iu', (string) $authorization['redirect_url_after_confirm_sbscrb'] ) ) $authorization['redirect_url_after_confirm_sbscrb'] = '';
2446
2447 $authorization['login_url'] = esc_url_raw( (string) $authorization['login_url'] );
2448 $authorization['register_url'] = esc_url_raw( (string) $authorization['register_url'] );
2449 $authorization['lost_password_url'] = esc_url_raw( (string) $authorization['lost_password_url'] );
2450 $authorization['redirect_url_after_login'] = esc_url_raw( (string) $authorization['redirect_url_after_login'] );
2451 $authorization['redirect_url_after_register'] = esc_url_raw( (string) $authorization['redirect_url_after_register'] );
2452 $authorization['redirect_url_after_confirm_sbscrb'] = esc_url_raw( (string) $authorization['redirect_url_after_confirm_sbscrb'] );
2453 $authorization['fb_api_id'] = sanitize_text_field( (string) $authorization['fb_api_id'] );
2454 $authorization['fb_api_secret'] = sanitize_text_field( (string) $authorization['fb_api_secret'] );
2455 $authorization['fb_redirect_url'] = esc_url_raw( (string) $authorization['fb_redirect_url'] );
2456
2457 wpforo_update_option( 'wpforo_authorization', $authorization );
2458 }
2459
2460 WPF()->notice->add( 'Successfully Done', 'success' );
2461 wp_safe_redirect( wp_get_raw_referer() );
2462 exit();
2463 }
2464
2465 /**
2466 * buddypress_settings_save from submit action
2467 *
2468 * @return void
2469 */
2470 public function buddypress_settings_save() {
2471 check_admin_referer( 'wpforo_settings_save_buddypress' );
2472
2473 if( wpfkey( $_POST, 'reset' ) ) {
2474 wpforo_delete_option( 'wpforo_buddypress' );
2475 } else {
2476 $buddypress = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['buddypress'] ), WPF()->settings->_buddypress );
2477 wpforo_update_option( 'wpforo_buddypress', $buddypress );
2478 }
2479
2480 WPF()->notice->add( 'Successfully Done', 'success' );
2481 wp_safe_redirect( wp_get_raw_referer() );
2482 exit();
2483 }
2484
2485 /**
2486 * components_settings_save from submit action
2487 *
2488 * @return void
2489 */
2490 public function components_settings_save() {
2491 check_admin_referer( 'wpforo_settings_save_components' );
2492
2493 if( wpfkey( $_POST, 'reset' ) ) {
2494 wpforo_delete_option( 'components' );
2495 } else {
2496 $components = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['components'] ), WPF()->settings->_components );
2497 foreach( $this->generate_option_names( 'components' ) as $option_name ) {
2498 wpforo_update_option( $option_name, $components );
2499 }
2500 }
2501
2502 WPF()->notice->add( 'Successfully Done', 'success' );
2503 wp_safe_redirect( wp_get_raw_referer() );
2504 exit();
2505 }
2506
2507 /**
2508 * email_settings_save from submit action
2509 *
2510 * @return void
2511 */
2512 public function email_settings_save() {
2513 check_admin_referer( 'wpforo_settings_save_email' );
2514
2515 if( wpfkey( $_POST, 'reset' ) ) {
2516 wpforo_delete_option( 'wpforo_email' );
2517 } else {
2518 $email = wp_unslash( $_POST['email'] );
2519 $email['admin_emails'] = sanitize_text_field( (string) $email['admin_emails'] );
2520 $email['admin_emails'] = array_map( 'sanitize_email', preg_split('#\s*,\s*#u', trim($email['admin_emails'])) );
2521 $email['admin_emails'] = array_filter( $email['admin_emails'] );
2522 if( !$email['admin_emails'] ) $email['admin_emails'] = (array) get_option( 'admin_email' );
2523 $email = wpforo_array_args_cast_and_merge( $email, WPF()->settings->_email );
2524
2525 $email['from_name'] = sanitize_text_field( $email['from_name'] );
2526 $email['from_email'] = sanitize_text_field( $email['from_email'] );
2527 $email['report_email_subject'] = sanitize_text_field( $email['report_email_subject'] );
2528 $email['report_email_message'] = wpforo_kses( $email['report_email_message'], 'email' );
2529 $email['wp_new_user_notification_email_admin_subject'] = sanitize_text_field( $email['wp_new_user_notification_email_admin_subject'] );
2530 $email['wp_new_user_notification_email_admin_message'] = wpforo_kses( $email['wp_new_user_notification_email_admin_message'], 'email' );
2531 $email['wp_new_user_notification_email_subject'] = sanitize_text_field( $email['wp_new_user_notification_email_subject'] );
2532 $email['wp_new_user_notification_email_message'] = wpforo_kses( $email['wp_new_user_notification_email_message'], 'email' );
2533 $email['reset_password_email_message'] = wpforo_kses( $email['reset_password_email_message'], 'email' );
2534 $email['after_user_approve_email_subject'] = sanitize_text_field( $email['after_user_approve_email_subject'] );
2535 $email['after_user_approve_email_message'] = wpforo_kses( $email['after_user_approve_email_message'], 'email' );
2536
2537 wpforo_update_option( 'wpforo_email', $email );
2538 }
2539
2540 WPF()->notice->add( 'Successfully Done', 'success' );
2541 wp_safe_redirect( wp_get_raw_referer() );
2542 exit();
2543 }
2544
2545 /**
2546 * forums_settings_save from submit action
2547 *
2548 * @return void
2549 */
2550 public function forums_settings_save() {
2551 check_admin_referer( 'wpforo_settings_save_forums' );
2552
2553 if( wpfkey( $_POST, 'reset' ) ) {
2554 wpforo_delete_option( 'forums' );
2555 } else {
2556 $forums = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['forums'] ), WPF()->settings->_forums );
2557 foreach( $this->generate_option_names( 'forums' ) as $option_name ) {
2558 wpforo_update_option( $option_name, $forums );
2559 }
2560 }
2561
2562 WPF()->notice->add( 'Successfully Done', 'success' );
2563 wp_safe_redirect( wp_get_raw_referer() );
2564 exit();
2565 }
2566
2567 /**
2568 * logging_settings_save from submit action
2569 *
2570 * @return void
2571 */
2572 public function logging_settings_save() {
2573 check_admin_referer( 'wpforo_settings_save_logging' );
2574
2575 if( wpfkey( $_POST, 'reset' ) ) {
2576 wpforo_delete_option( 'logging' );
2577 } else {
2578 $logging = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['logging'] ), WPF()->settings->_logging );
2579 foreach( $this->generate_option_names( 'logging' ) as $option_name ) {
2580 wpforo_update_option( $option_name, $logging );
2581 }
2582 }
2583
2584 WPF()->notice->add( 'Successfully Done', 'success' );
2585 wp_safe_redirect( wp_get_raw_referer() );
2586 exit();
2587 }
2588
2589 /**
2590 * members_settings_save from submit action
2591 *
2592 * @return void
2593 */
2594 public function members_settings_save() {
2595 check_admin_referer( 'wpforo_settings_save_members' );
2596
2597 if( wpfkey( $_POST, 'reset' ) ) {
2598 wpforo_delete_option( 'wpforo_members' );
2599 } else {
2600 $members = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['members'] ), WPF()->settings->_members );
2601 wpforo_update_option( 'wpforo_members', $members );
2602 }
2603
2604 WPF()->notice->add( 'Successfully Done', 'success' );
2605 wp_safe_redirect( wp_get_raw_referer() );
2606 exit();
2607 }
2608
2609 /**
2610 * notifications_settings_save from submit action
2611 *
2612 * @return void
2613 */
2614 public function notifications_settings_save() {
2615 check_admin_referer( 'wpforo_settings_save_notifications' );
2616
2617 if( wpfkey( $_POST, 'reset' ) ) {
2618 wpforo_delete_option( 'notifications' );
2619 } else {
2620 $notifications = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['notifications'] ), WPF()->settings->_notifications );
2621 foreach( $this->generate_option_names( 'notifications' ) as $option_name ) {
2622 wpforo_update_option( $option_name, $notifications );
2623 }
2624 }
2625
2626 WPF()->notice->add( 'Successfully Done', 'success' );
2627 wp_safe_redirect( wp_get_raw_referer() );
2628 exit();
2629 }
2630
2631 /**
2632 * posting_settings_save from submit action
2633 *
2634 * @return void
2635 */
2636 public function posting_settings_save() {
2637 check_admin_referer( 'wpforo_settings_save_posting' );
2638
2639 if( wpfkey( $_POST, 'reset' ) ) {
2640 wpforo_delete_option( 'posting' );
2641 } else {
2642 $posting = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['posting'] ), WPF()->settings->_posting );
2643 $posting['max_upload_size'] = $posting['max_upload_size'] * 1024 * 1024;
2644 $posting['edit_own_topic_durr'] = $posting['edit_own_topic_durr'] * 60;
2645 $posting['delete_own_topic_durr'] = $posting['delete_own_topic_durr'] * 60;
2646 $posting['edit_own_post_durr'] = $posting['edit_own_post_durr'] * 60;
2647 $posting['delete_own_post_durr'] = $posting['delete_own_post_durr'] * 60;
2648 $posting['extra_html_tags'] = sanitize_textarea_field( $posting['extra_html_tags'] );
2649 foreach( $this->generate_option_names( 'posting' ) as $option_name ) {
2650 wpforo_update_option( $option_name, $posting );
2651 }
2652 }
2653
2654 WPF()->notice->add( 'Successfully Done', 'success' );
2655 wp_safe_redirect( wp_get_raw_referer() );
2656 exit();
2657 }
2658
2659 /**
2660 * profiles_settings_save from submit action
2661 *
2662 * @return void
2663 */
2664 public function profiles_settings_save() {
2665 check_admin_referer( 'wpforo_settings_save_profiles' );
2666
2667 if( wpfkey( $_POST, 'reset' ) ) {
2668 wpforo_delete_option( 'wpforo_profiles' );
2669 } else {
2670 $profiles = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['profiles'] ), WPF()->settings->_profiles );
2671 $profiles['default_cover'] = WPF()->settings->profiles['default_cover'];
2672 $profiles['default_title'] = sanitize_text_field( $profiles['default_title'] );
2673 $profiles['online_status_timeout'] = $profiles['online_status_timeout'] * 60;
2674 $profiles['title_groupids'] = array_map( 'intval', (array) wpfval( $_POST['profiles'], 'title_groupids' ) );
2675 $profiles['title_secondary_groupids'] = array_map( 'intval', (array) wpfval( $_POST['profiles'], 'title_secondary_groupids' ) );
2676 wpforo_update_option( 'wpforo_profiles', $profiles );
2677 }
2678
2679 WPF()->notice->add( 'Successfully Done', 'success' );
2680 wp_safe_redirect( wp_get_raw_referer() );
2681 exit();
2682 }
2683
2684 /**
2685 * rating_settings_save from submit action
2686 *
2687 * @return void
2688 */
2689 public function rating_settings_save() {
2690 check_admin_referer( 'wpforo_settings_save_rating' );
2691
2692 if( wpfkey( $_POST, 'reset' ) ) {
2693 wpforo_delete_option( 'wpforo_rating' );
2694 } else {
2695 $rating = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['rating'] ), WPF()->settings->_rating );
2696 $rating['rating_title_ug'] = array_map( 'intval', (array) wpfval( $_POST['rating'], 'rating_title_ug' ) );
2697 $rating['rating_badge_ug'] = array_map( 'intval', (array) wpfval( $_POST['rating'], 'rating_badge_ug' ) );
2698 wpforo_update_option( 'wpforo_rating', $rating );
2699 }
2700
2701 WPF()->notice->add( 'Successfully Done', 'success' );
2702 wp_safe_redirect( wp_get_raw_referer() );
2703 exit();
2704 }
2705
2706 /**
2707 * recaptcha_settings_save from submit action
2708 *
2709 * @return void
2710 */
2711 public function recaptcha_settings_save() {
2712 check_admin_referer( 'wpforo_settings_save_recaptcha' );
2713
2714 if( wpfkey( $_POST, 'reset' ) ) {
2715 wpforo_delete_option( 'wpforo_recaptcha' );
2716 } else {
2717 $recaptcha = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['recaptcha'] ), WPF()->settings->_recaptcha );
2718 $recaptcha['site_key'] = sanitize_text_field( $recaptcha['site_key'] );
2719 $recaptcha['secret_key'] = sanitize_text_field( $recaptcha['secret_key'] );
2720 wpforo_update_option( 'wpforo_recaptcha', $recaptcha );
2721 }
2722
2723 WPF()->notice->add( 'Successfully Done', 'success' );
2724 wp_safe_redirect( wp_get_raw_referer() );
2725 exit();
2726 }
2727
2728 /**
2729 * rss_settings_save from submit action
2730 *
2731 * @return void
2732 */
2733 public function rss_settings_save() {
2734 check_admin_referer( 'wpforo_settings_save_rss' );
2735
2736 if( wpfkey( $_POST, 'reset' ) ) {
2737 wpforo_delete_option( 'rss' );
2738 } else {
2739 $rss = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['rss'] ), WPF()->settings->_rss );
2740 foreach( $this->generate_option_names( 'rss' ) as $option_name ) {
2741 wpforo_update_option( $option_name, $rss );
2742 }
2743 }
2744
2745 WPF()->notice->add( 'Successfully Done', 'success' );
2746 wp_safe_redirect( wp_get_raw_referer() );
2747 exit();
2748 }
2749
2750 /**
2751 * seo_settings_save from submit action
2752 *
2753 * @return void
2754 */
2755 public function seo_settings_save() {
2756 check_admin_referer( 'wpforo_settings_save_seo' );
2757
2758 if( wpfkey( $_POST, 'reset' ) ) {
2759 wpforo_delete_option( 'seo' );
2760 } else {
2761 $seo = wp_unslash( $_POST['seo'] );
2762 $seo['dofollow'] = array_filter( preg_split( '#\s+#', sanitize_textarea_field( (string) wpfval( $seo, 'dofollow' ) ) ) );
2763 $seo['noindex'] = array_filter( preg_split( '#\s+#', sanitize_textarea_field( (string) wpfval( $seo, 'noindex' ) ) ) );
2764 $seo['noindex'] = array_map( 'esc_url_raw', $seo['noindex'] );
2765 $seo = wpforo_array_args_cast_and_merge( $seo, WPF()->settings->_seo );
2766 foreach( $this->generate_option_names( 'seo' ) as $option_name ) {
2767 wpforo_update_option( $option_name, $seo );
2768 }
2769 wpforo_clean_cache( 'forum-soft' );
2770 }
2771
2772 WPF()->notice->add( 'Successfully Done', 'success' );
2773 wp_safe_redirect( wp_get_raw_referer() );
2774 exit();
2775 }
2776
2777 /**
2778 * social_settings_save from submit action
2779 *
2780 * @return void
2781 */
2782 public function social_settings_save() {
2783 check_admin_referer( 'wpforo_settings_save_social' );
2784
2785 if( wpfkey( $_POST, 'reset' ) ) {
2786 wpforo_delete_option( 'social' );
2787 } else {
2788 $social = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['social'] ), WPF()->settings->_social );
2789 $social['sb'] = wpforo_array_args_cast_and_merge( (array) wpfval( $_POST['social'], 'sb' ), array_map( '__return_false', WPF()->settings->_social['sb'] ) );
2790 $social['sb_location'] = wpforo_array_args_cast_and_merge( (array) wpfval( $_POST['social'], 'sb_location' ), array_map( '__return_false', WPF()->settings->_social['sb_location'] ) );
2791 foreach( $this->generate_option_names( 'social' ) as $option_name ) {
2792 wpforo_update_option( $option_name, $social );
2793 }
2794 }
2795
2796 WPF()->notice->add( 'Successfully Done', 'success' );
2797 wp_safe_redirect( wp_get_raw_referer() );
2798 exit();
2799 }
2800
2801 /**
2802 * styles_settings_save from submit action
2803 *
2804 * @return void
2805 */
2806 public function styles_settings_save() {
2807 check_admin_referer( 'wpforo_settings_save_styles' );
2808
2809 if( wpfkey( $_POST, 'reset' ) ) {
2810 wpforo_delete_option( 'styles_' . WPF()->tpl->theme );
2811 } else {
2812 $styles = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['styles'] ), WPF()->settings->_styles );
2813 $styles['custom_css'] = sanitize_textarea_field( $styles['custom_css'] );
2814 foreach( $this->generate_option_names( 'styles_' . WPF()->tpl->theme ) as $option_name ) {
2815 wpforo_update_option( $option_name, $styles );
2816 }
2817 }
2818
2819 WPF()->notice->add( 'Successfully Done', 'success' );
2820 wp_safe_redirect( wp_get_raw_referer() );
2821 exit();
2822 }
2823
2824 /**
2825 * tags_settings_save from submit action
2826 *
2827 * @return void
2828 */
2829 public function tags_settings_save() {
2830 check_admin_referer( 'wpforo_settings_save_tags' );
2831
2832 if( wpfkey( $_POST, 'reset' ) ) {
2833 wpforo_delete_option( 'tags' );
2834 } else {
2835 $tags = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['tags'] ), WPF()->settings->_tags );
2836 foreach( $this->generate_option_names( 'tags' ) as $option_name ) {
2837 wpforo_update_option( $option_name, $tags );
2838 }
2839 }
2840
2841 WPF()->notice->add( 'Successfully Done', 'success' );
2842 wp_safe_redirect( wp_get_raw_referer() );
2843 exit();
2844 }
2845
2846 /**
2847 * topics_settings_save from submit action
2848 *
2849 * @return void
2850 */
2851 public function topics_settings_save() {
2852 check_admin_referer( 'wpforo_settings_save_topics' );
2853
2854 if( wpfkey( $_POST, 'reset' ) ) {
2855 wpforo_delete_option( 'topics' );
2856 } else {
2857 $topics = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['topics'] ), WPF()->settings->_topics );
2858 foreach( $this->generate_option_names( 'topics' ) as $option_name ) {
2859 wpforo_update_option( $option_name, $topics );
2860 }
2861 }
2862
2863 WPF()->notice->add( 'Successfully Done', 'success' );
2864 wp_safe_redirect( wp_get_raw_referer() );
2865 exit();
2866 }
2867
2868 /**
2869 * um_settings_save from submit action
2870 *
2871 * @return void
2872 */
2873 public function um_settings_save() {
2874 check_admin_referer( 'wpforo_settings_save_um' );
2875
2876 if( wpfkey( $_POST, 'reset' ) ) {
2877 wpforo_delete_option( 'wpforo_um' );
2878 } else {
2879 $um = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['um'] ), WPF()->settings->_um );
2880 wpforo_update_option( 'wpforo_um', $um );
2881 }
2882
2883 WPF()->notice->add( 'Successfully Done', 'success' );
2884 wp_safe_redirect( wp_get_raw_referer() );
2885 exit();
2886 }
2887
2888 /**
2889 * um_settings_save from submit action
2890 *
2891 * @return void
2892 */
2893 public function legal_settings_save() {
2894 check_admin_referer( 'wpforo_settings_save_legal' );
2895
2896 if( wpfkey( $_POST, 'reset' ) ) {
2897 wpforo_delete_option( 'wpforo_legal' );
2898 } else {
2899 $legal = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['legal'] ), WPF()->settings->_legal );
2900 wpforo_update_option( 'wpforo_legal', $legal );
2901 }
2902
2903 WPF()->notice->add( 'Successfully Done', 'success' );
2904 wp_safe_redirect( wp_get_raw_referer() );
2905 exit();
2906 }
2907
2908 /**
2909 * @return array with all boardids where need to save options
2910 */
2911 private function get_boardids_to_be_saved() {
2912 $boardids = (array) WPF()->board->get_current( 'boardid' );
2913 if( wpfkey( $_POST, 'save_for_all' ) ) {
2914 $boardids = array_unique( array_merge( $boardids, WPF()->board->get_active_boardids() ) );
2915 }
2916
2917 return $boardids;
2918 }
2919
2920 /**
2921 * @param string $basename
2922 *
2923 * @return string[]
2924 */
2925 public function generate_option_names( $basename ) {
2926 return array_map(
2927 function( $boardid ) use ( $basename ) {
2928 return 'wpforo_' . ( $boardid ? $boardid . '_' : '' ) . $basename;
2929 },
2930 $this->get_boardids_to_be_saved()
2931 );
2932 }
2933
2934 /**
2935 * uninstall all wpforo
2936 */
2937 public function uninstall() {
2938 check_admin_referer( 'wpforo_uninstall' );
2939 if( current_user_can('administrator') && current_user_can( 'activate_plugins' ) ){
2940 wpforo_uninstall();
2941 }
2942 wp_safe_redirect( wp_get_referer() );
2943 exit();
2944 }
2945 }
2946