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 / includes / hooks.php

hooks.php in wpForo Forum 2.3.0, at includes/hooks.php

2,877 lines 119.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 add_filter( 'plugin_action_links_' . WPFORO_BASENAME, function ( $links ) {
8 $uninstall_url = wp_nonce_url( admin_url( 'plugins.php?wpfaction=uninstall' ), 'wpforo_uninstall' );
9 $links[] = '<a href="'.esc_url( (string) $uninstall_url ).'" class="wpforo-uninstall" style="color:#a00;" onclick="return confirm(\'' . __('IMPORTANT! Uninstall is not a simple deactivation action. This action will permanently remove all forum data (forums, topics, replies, attachments...) from database. Please backup database before this action, you may need this forum data in future. If you are sure that you want to delete all forum data please confirm. If not, just cancel it, then you can deactivate this plugin, that will not remove forum data.', 'wpforo').'\')">' . __( 'Uninstall', 'wpforo' ) . '</a>';
10 $settings_link = '<a href="'.esc_url( (string) admin_url( 'admin.php?page=wpforo-boards' ) ).'">' . __( 'Boards', 'wpforo' ) . '</a>';
11 array_unshift( $links, $settings_link );
12 return $links;
13 } );
14
15 function wpforo_notice_show() {
16 WPF()->notice->show();
17 }
18
19 add_action( 'wp_footer', 'wpforo_notice_show' );
20
21 add_action( 'show_admin_bar', function( $show_admin_bar ) {
22 if( ! is_super_admin() && is_user_logged_in() && WPF()->wp_current_user && ! array_intersect( [ 'editor', 'administrator', 'author', ], (array) WPF()->wp_current_user->roles ) ) {
23 $show_admin_bar = (bool) array_intersect( WPF()->current_user_groupids, wpforo_setting( 'general', 'admin_bar' ) );
24 }
25
26 return $show_admin_bar;
27 });
28
29 add_action( 'admin_notices', function () {
30 if( strpos( wpforo_get_request_uri(), 'nav-menus.php' ) !== false ) {
31 $message = '';
32 foreach( WPF()->tpl->menu as $key => $value ) $message .= "<tr><td> " . $value['label'] . ": </td><td> /%$key%/ </td></tr>";
33 $message .=
34 "<tr><td> " . wpforo_phrase( 'register', false ) . ": </td><td> /%wpforo-register%/ </td></tr>
35 <tr><td> " . wpforo_phrase( 'login', false ) . ": </td><td> /%wpforo-login%/ </td></tr>";
36 printf(
37 '<div class="notice notice-warning wpforo-menu-shortcodes">
38 <p class="wpforo-menu-shortcodes-head" style="cursor: pointer;">wpForo Menu Shortcodes hint <span class="dashicons dashicons-arrow-down-alt2"></span></p>
39 <div class="wpforo-menu-shortcodes-body" style="display: none;">
40 <hr/><table>%1$s</table>
41 </div>
42 </div>',
43 $message
44 );
45 ?>
46 <script>
47 jQuery(document).ready( function($){
48 $( 'body' ).on('click', '.wpforo-menu-shortcodes .wpforo-menu-shortcodes-head', {}, function(){
49 var $this = $( this );
50 var wrap = $this.closest( '.wpforo-menu-shortcodes' );
51 var body = $( '.wpforo-menu-shortcodes-body', wrap );
52 body.toggle();
53 });
54 } );
55 </script>
56 <?php
57 }
58 });
59
60 add_filter( 'comments_open', function( $open ) {
61 if( is_wpforo_page() ) $open = false;
62
63 return $open;
64 } );
65
66 add_filter( 'comments_array', function( $comments ) {
67 if( is_wpforo_page() ) $comments = [];
68
69 return $comments;
70 }, 10, 2 );
71
72 add_action( 'wpforo_actions_end', function() {
73 if( is_wpforo_page() ) {
74 remove_post_type_support( 'post', 'comments' );
75 remove_post_type_support( 'page', 'comments' );
76 }
77 }, 100 );
78
79 add_action( 'wpforo_actions_end', function() {
80 if( ! WPF()->board->get_current( 'is_standalone' ) && ! is_front_page() && ! is_home() && is_wpforo_url() ) {
81 global $wp_query, $post;
82 $pageid = WPF()->board->get_current( 'pageid' );
83 if( is_a( $post, 'WP_Post' ) && $post->ID !== $pageid ) {
84 $args = [
85 'post_count' => 1,
86 'found_posts' => 1,
87 'max_num_pages' => 0,
88 'is_404' => false,
89 'is_page' => true,
90 'is_singular' => true,
91 ];
92
93 $target_post = get_post( $pageid );
94 if( ! is_a( $target_post, 'WP_Post' ) ) {
95 return;
96 }
97
98 $post = $target_post;
99
100 $wp_query->posts = [ $post ];
101 $wp_query->queried_object_id = $post->ID;
102 $wp_query->queried_object = $post;
103
104 foreach( $args as $key => $value ) {
105 $wp_query->$key = $value;
106 }
107
108 setup_postdata( $post );
109 }
110 }
111 } );
112
113 add_filter( 'author_link', function( $link, $author_id ) {
114 if( wpforo_setting( 'profiles', 'profile' ) === 'wpforo' ) return WPF()->member->get_profile_url( $author_id );
115
116 return $link;
117 }, 10, 2 );
118
119 add_filter( 'get_comment_author_url', function( $link, $ID = 0, $object = null ) {
120 if( isset( $object->user_id ) && $object->user_id && wpforo_setting( 'profiles', 'profile' ) === 'wpforo' ) return WPF()->member->get_profile_url( $object->user_id );
121
122 return $link;
123 }, 10, 3 );
124
125 add_filter( 'register_url', function( $register_url ) {
126 if( wpforo_setting( 'authorization', 'use_our_register_url' ) ) $register_url = wpforo_register_url();
127
128 return $register_url;
129 } );
130
131 add_filter( 'login_url', function( $login_url ) {
132 if(
133 wpforo_setting( 'authorization', 'use_our_login_url' )
134 && strpos( (string) $_SERVER['REQUEST_URI'], '/wp-json/' ) !== 0
135 && strpos( (string) wp_debug_backtrace_summary(), 'wp_auth_check_html, wp_login_url,' ) === false
136 ) {
137 $login_url = wpforo_login_url();
138 }
139
140 return $login_url;
141 } );
142
143 add_filter( 'logout_url', function( $logout_url ) {
144 if( wpforo_setting( 'authorization', 'use_our_login_url' ) ) $logout_url = wpforo_logout_url();
145
146 return $logout_url;
147 } );
148
149 add_filter( 'pre_trash_post', function( $check, $post ) {
150 if( in_array( $post->ID, WPF()->board->get_boards_pageids(), true ) ){
151 $check = false;
152 WPF()->notice->add( 'DO NOT DELETE WPFORO PAGE!!!', 'error' );
153 }
154 return $check;
155 }, 10, 2 );
156
157 add_filter( 'wp_dropdown_pages', function( $output, $r ) {
158 $pageids = WPF()->board->get_boards_pageids();
159 if( $r['name'] === 'page_for_posts' || ( $r['name'] === 'page_on_front' && wpforo_get_shortcode_pageid( $pageids ) ) ) {
160 $pattern = '#[\r\n\t\s]*<option[^<>]*?value=[\'"](' . implode( '|', $pageids ) . ')[\'"][^<>]*?>[^<>]*?</option>#isu';
161 $output = preg_replace( $pattern, '', (string) $output );
162 }
163 return $output;
164 }, 10, 2 );
165
166 add_filter( 'pre_update_option', function ( $value, $option, $old_value ) {
167 if ( $option === 'page_on_front' ) {
168 $pageids = WPF()->board->get_boards_pageids();
169 if( in_array( wpforo_bigintval( $value ), $pageids, true ) ){
170 if ( ! $page_id = wpforo_get_shortcode_pageid( $pageids ) ) {
171 $page_id = wp_insert_post(
172 [
173 'post_date' => current_time( 'mysql', 1 ),
174 'post_date_gmt' => current_time( 'mysql', 1 ),
175 'post_content' => '[wpforo]',
176 'post_title' => 'Forum page_on_front',
177 'post_status' => 'publish',
178 'comment_status' => 'close',
179 'ping_status' => 'close',
180 'post_name' => 'front-community',
181 'post_modified' => current_time( 'mysql', 1 ),
182 'post_modified_gmt' => current_time( 'mysql', 1 ),
183 'post_parent' => 0,
184 'menu_order' => 0,
185 'post_type' => 'page',
186 ]
187 );
188 }
189 $value = ( $page_id && ! is_wp_error( $page_id ) ? $page_id : $old_value );
190 }
191 }
192
193 return $value;
194 }, 10, 3 );
195
196 function wpftpl_url( $filename ) {
197 $tpl_url = '';
198 if( $filename ) {
199 if( $tpl_url = locate_template( 'wpforo/' . $filename ) ) $tpl_url = get_template_directory_uri() . '/wpforo/' . $filename;
200 if( ! $tpl_url ) $tpl_url = WPF()->tpl->template_url . '/' . $filename;
201 }
202
203 return apply_filters( 'wpforo_wpftpl_url', $tpl_url, $filename );
204 }
205
206 function wpftpl( $filename ) {
207 $tpl = '';
208 if( $filename ) {
209 $tpl = locate_template( 'wpforo/' . $filename );
210 if( ! $tpl ) $tpl = WPF()->tpl->template_dir . '/' . $filename;
211 }
212
213 return apply_filters( 'wpforo_wpftpl', $tpl, $filename );
214 }
215
216 add_shortcode( 'wpforo', function ( $atts ) {
217 if( defined( 'REST_REQUEST' ) && REST_REQUEST ) return '';
218 if( ! is_wpforo_url() ) {
219 if( ! $atts ) $atts = [ 'item' => 'forum' ];
220 WPF()->init_current_url( $atts );
221 WPF()->init_current_object();
222 wpforo_frontend_enqueue_scripts();
223 }
224 if( apply_filters( 'on_wpforo_load_remove_the_content_all_filters', false ) ) {
225 remove_all_filters( 'the_content' );
226 }
227
228 ob_start();
229 if( wpforo_current_user_is( 'admin' ) || ! wpforo_setting( 'board', 'under_construction' ) ){
230 include( wpftpl( 'index.php' ) );
231 }else{
232 include( wpftpl( 'uc.php' ) );
233 }
234 $output = ob_get_clean();
235 $output = trim( (string) $output );
236 if( ! $output ) $output = wpforo_hook_usage( 'the_content' );
237
238 return $output;
239 } );
240
241 function wpforo_hook_usage( $hook = '' ) {
242 global $wp_filter;
243
244 $output = '<div style="color: #990000; font-size: 16px;">Notice: a plugin conflict has been detected. wpForo forums are affected by other plugin errors.
245 Please deactivate all plugins, delete all caches and test again.
246 Then activate all plugins back one by one and find the conflict maker plugin.</div>
247 <pre style="display: none;">' . ( empty( $hook ) || ! isset( $wp_filter[ $hook ] ) ? 'No hook usage' : print_r( $wp_filter[ $hook ], true ) ) . '</pre>';
248
249 return $output;
250 }
251
252 add_action( 'wpforo_actions_end', 'wpforo_set_header_status' );
253 function wpforo_set_header_status() {
254 if( is_wpforo_page() ) {
255 global $wp_query;
256
257 $status = ( WPF()->current_object['is_404'] ? 404 : 200 );
258 status_header( $status );
259 if( $status === 404 ) nocache_headers();
260 $wp_query->is_404 = false;
261 }
262 }
263
264 add_filter( 'pre_handle_404', function( $bypass ){
265 if( is_wpforo_page() ) return true;
266 return $bypass;
267 } );
268
269 add_action( 'wpforo_actions_end', function() {
270 if( is_wpforo_page() && WPF()->board->get_current( 'is_standalone' ) ) {
271 add_rewrite_rule( '(.*)', 'index.php?page_id=' . WPF()->board->get_current( 'pageid' ), 'top' );
272 add_filter( 'template_include', function( $template ) {
273 if( is_wpforo_page() && ! is_wpforo_shortcode_page() && ( $wpforo_template = wpftpl( 'index.php' ) ) ) return $wpforo_template;
274
275 return $template;
276 } );
277 }
278 } );
279
280 add_filter( 'rewrite_rules_array', function( $rules ) {
281 $rewrite_prefix = '(?:([a-z]{2,3})/)?';
282 if( function_exists('pll_languages_list') ) $rewrite_prefix = '(?:(' . implode('|', pll_languages_list()) . ')/)?';
283
284 if( ! WPF()->board->get_current( 'is_standalone' ) ) {
285 $pageid = 0;
286 $boards = WPF()->board->get_boards( [ 'status' => true ] );
287 foreach( $boards as $board ) {
288 if( $board['boardid'] === 0 ) $pageid = $board['pageid'];
289 $route = urldecode( (string) $board['slug'] );
290 $route = preg_replace( '#^/?index\.php/?#iu', '', $route );
291 $route = trim( (string) $route, '/' );
292 $pattern = $rewrite_prefix . preg_quote( $route ) . '(?:/|$).*$';
293 $to_url = 'index.php?lang=$matches[1]&page_id=' . $board['pageid'];
294 if( ! array_key_exists( $pattern, $rules ) ) $rules = array_merge( [ $pattern => $to_url ], $rules );
295 }
296
297 if( ! $pageid ) $pageid = wpforo_get_option( 'wpforo_pageid', 0 );
298 foreach( WPF()->board->routes as $route ) {
299 // $route = utf8_uri_encode( urldecode( (string) $route ) );
300 $route = urldecode( (string) $route );
301 $route = preg_replace( '#^/?index\.php/?#isu', '', $route );
302 $route = trim( (string) $route, '/' );
303 $pattern = $rewrite_prefix . preg_quote( $route ) . '(?:/|$).*$';
304 $to_url = 'index.php?lang=$matches[1]&page_id=' . $pageid;
305 if( ! array_key_exists( $pattern, $rules ) ) $rules = array_merge( [ $pattern => $to_url ], $rules );
306 }
307 }
308
309 return $rules;
310 } );
311
312 add_action( 'wpforo_actions_end', function() {
313 $pageid = WPF()->board->get_current( 'pageid' );
314 if( is_wpforo_url() && $pageid && WPF()->board->route && get_the_ID() !== $pageid ) wpforo_repair_main_shortcode_page();
315 } );
316
317 add_action( 'wpforo_after_init', function() {
318 $path = wpftpl( 'functions.php' );
319 if( file_exists( $path ) ) include_once( $path );
320
321 $path = wpftpl( 'functions-wp.php' );
322 if( file_exists( $path ) ) include_once( $path );
323 } );
324
325 function wpforo_meta_title( $title ) {
326 $meta_title = [];
327
328 if( ! wpforo_setting( 'seo', 'seo_title' ) ) return $title;
329
330 if( is_wpforo_page() ) {
331 $template = WPF()->current_object['template'];
332 if( ! WPF()->current_object['is_404'] ) {
333 $paged = ( WPF()->current_object['paged'] > 1 ) ? wpforo_phrase( 'page', false ) . ' ' . WPF()->current_object['paged'] . ' ' : '';
334 if( ! empty( WPF()->current_object['forum'] ) ) {
335 $forum = WPF()->current_object['forum'];
336 }
337 if( ! empty( WPF()->current_object['topic'] ) ) {
338 $topic = WPF()->current_object['topic'];
339 }
340 if( ! empty( WPF()->current_object['user'] ) ) {
341 $user = WPF()->current_object['user'];
342 }
343 if( isset( $topic['title'] ) && isset( $forum['title'] ) && isset( WPF()->board->get_current( 'settings' )['title'] ) ) {
344 $meta_title = [ $topic['title'], $paged, $forum['title'], WPF()->board->get_current( 'settings' )['title'] ];
345 $meta_title = apply_filters( 'wpforo_seo_topic_title', $meta_title );
346 } elseif( ! isset( $topic['title'] ) && isset( $forum['title'] ) && isset( WPF()->board->get_current( 'settings' )['title'] ) ) {
347 $meta_title = [ $forum['title'], $paged, WPF()->board->get_current( 'settings' )['title'] ];
348 $meta_title = apply_filters( 'wpforo_seo_forum_title', $meta_title );
349 } elseif( ! in_array( $template, ['forum','topic','post'], true ) ) {
350 if( wpforo_is_member_template( $template ) ) {
351 if( isset( $user['display_name'] ) ) {
352 $meta_title = [
353 $user['display_name'],
354 wpforo_phrase( ucfirst( (string) $template ), false ),
355 WPF()->board->get_current( 'settings' )['title'],
356 $paged
357 ];
358 } elseif( isset( WPF()->current_object['user_nicename'] ) ) {
359 $meta_title = [
360 WPF()->current_object['user_nicename'],
361 wpforo_phrase( ucfirst( (string) $template ), false ),
362 WPF()->board->get_current( 'settings' )['title'],
363 $paged
364 ];
365 } else {
366 $meta_title = [
367 wpforo_phrase( 'Member', false ),
368 wpforo_phrase( ucfirst( (string) $template ), false ),
369 WPF()->board->get_current( 'settings' )['title'],
370 $paged
371 ];
372 }
373 $meta_title = apply_filters( 'wpforo_seo_profile_title', $meta_title );
374 } elseif( $template === 'recent' ) {
375 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false ) . ' ' . $_GET['wpfpaged'] . ' ' : '';
376 $view = wpfval( $_GET, 'view' );
377 if( $view == 'unread' ) {
378 $main_title = wpforo_phrase( 'Unread Posts', false );
379 } elseif( $view == 'prefix' ) {
380 $main_title = wpforo_phrase( 'Topic Prefix', false );
381 } else {
382 $main_title = wpforo_phrase( 'Recent Posts', false );
383 }
384 $meta_title = [ $main_title . $wpfpaged, WPF()->board->get_current( 'settings' )['title'] ];
385 $meta_title = apply_filters( 'wpforo_seo_recent_posts_title', $meta_title );
386 } elseif( $template === 'tags' ) {
387 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false ) . ' ' . $_GET['wpfpaged'] . ' ' : '';
388 $meta_title = [ wpforo_phrase( 'Tags', false ) . $wpfpaged, WPF()->board->get_current( 'settings' )['title'] ];
389 $meta_title = apply_filters( 'wpforo_seo_tags_title', $meta_title );
390 } elseif( $template === 'search' && wpfval( $_GET, 'wpfin' ) && wpfval( $_GET, 'wpfs' ) && $_GET['wpfin'] === 'tag' ) {
391 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false ) . ' ' . $_GET['wpfpaged'] . ' ' : '';
392 $meta_title = [
393 wpforo_phrase( 'Topic Tag:', false ) . ' ' . esc_html( $_GET['wpfs'] ),
394 $wpfpaged,
395 WPF()->board->get_current( 'settings' )['title'],
396 ];
397 $meta_title = apply_filters( 'wpforo_seo_tag_title', $meta_title );
398 } elseif( $template ) {
399 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false ) . ' ' . $_GET['wpfpaged'] . ' ' : '';
400 $meta_title = [
401 wpforo_phrase( ucfirst( (string) $template ), false ) . $wpfpaged,
402 WPF()->board->get_current( 'settings' )['title'],
403 ];
404 $meta_title = apply_filters( 'wpforo_seo_template_title', $meta_title );
405 } elseif( $title ) {
406 $meta_title = ( is_array( $title ) ) ? $title : [ $title ];
407 $meta_title = apply_filters( 'wpforo_seo_x_title', $meta_title );
408 } else {
409 $meta_title = [ wpforo_phrase( 'Forum', false ), get_bloginfo( 'name' ) ];
410 $meta_title = apply_filters( 'wpforo_seo_general_title', $meta_title );
411 }
412 } elseif( isset( WPF()->board->get_current( 'settings' )['title'] ) && WPF()->board->get_current( 'settings' )['title'] ) {
413 $meta_title = [ WPF()->board->get_current( 'settings' )['title'], get_bloginfo( 'name' ) ];
414 $meta_title = apply_filters( 'wpforo_seo_main_title', $meta_title );
415 } elseif( $title ) {
416 $meta_title = ( is_array( $title ) ) ? $title : [ $title ];
417 $meta_title = apply_filters( 'wpforo_seo_x_title', $meta_title );
418 } else {
419 $meta_title = [ wpforo_phrase( 'Forum', false ), get_bloginfo( 'name' ) ];
420 $meta_title = apply_filters( 'wpforo_seo_general_title', $meta_title );
421 }
422 } else {
423 $meta_title = [ wpforo_phrase( '404 - Page not found', false ), WPF()->board->get_current( 'settings' )['title'] ];
424 $meta_title = apply_filters( 'wpforo_seo_404_title', $meta_title );
425 }
426 }
427 if( ! empty( $meta_title ) ) {
428 return $meta_title;
429 } else {
430 return $title;
431 }
432 }
433
434 add_filter( 'document_title_parts', 'wpforo_meta_title', 100 );
435
436 function wpforo_meta_wp_title( $title ) {
437 if( ! wpforo_setting( 'seo', 'seo_title' ) ) return $title;
438 $meta_title = wpforo_meta_title( $title );
439 if( is_array( $meta_title ) && ! empty( $meta_title ) ) {
440 $title = implode( ' &#8211; ', $meta_title );
441 }
442
443 return $title;
444 }
445
446 add_filter( 'wp_title', 'wpforo_meta_wp_title', 100 );
447
448 function wpforo_add_meta_tags() {
449 if( ! wpforo_setting( 'seo', 'seo_meta' ) ) {
450 return;
451 }
452
453 if( is_wpforo_page() && ! is_wpforo_shortcode_page() ) {
454 $title = '';
455 $og_img = '';
456 $tw_img = '';
457 $schema = '';
458 $noindex = '';
459 $template = '';
460 $description = '';
461 $udata = [];
462 if( preg_match( '#\?.*$#is', (string) WPF()->canonical_url, $requests ) ) {
463 if( strpos( (string) $requests[0], 'orderby') !== FALSE ){
464 $canonical = preg_replace( '#\?.*$#is', '', (string) WPF()->canonical_url );
465 } else {
466 $canonical = wpforo_home_url( $requests[0] );
467 }
468 } else {
469 $canonical = WPF()->canonical_url;
470 }
471 $noindex_urls = wpforo_setting( 'seo', 'noindex' );
472 $image = wpforo_find_image_urls( '', true, 'og:image' );
473 foreach( $noindex_urls as $noindex_url ) {
474 $noindex_url = strtok( $noindex_url, "#" );
475 if( strpos( (string) $noindex_url, '*' ) !== false ) {
476 $noindex_url = strtok( $noindex_url, "*" );
477 if( preg_match( '|^' . preg_quote( $noindex_url ) . '|is', (string) $canonical ) ) {
478 $noindex = "<meta name=\"robots\" content=\"noindex\">\r\n";
479 break;
480 }
481 } elseif( $canonical == $noindex_url ) {
482 $noindex = "<meta name=\"robots\" content=\"noindex\">\r\n";
483 break;
484 }
485 }
486 $paged = ( WPF()->current_object['paged'] > 1 ) ? wpforo_phrase( 'page', false ) . ' ' . WPF()->current_object['paged'] . ' | ' : '';
487 if( isset( WPF()->current_object['template'] ) ) {
488 $template = WPF()->current_object['template'];
489 }
490 if( ! empty( WPF()->current_object['forum'] ) ) {
491 $forum = WPF()->current_object['forum'];
492 }
493 if( ! empty( WPF()->current_object['topic'] ) ) {
494 $topic = WPF()->current_object['topic'];
495 }
496 if( ! empty( WPF()->current_object['user'] ) ) {
497 $user = WPF()->current_object['user'];
498 }
499 if( isset( WPF()->current_object ) ) {
500 if( wpfval( WPF()->current_object, 'forumid' ) && ! wpfval( WPF()->current_object, 'topicid' ) ) {
501 if( isset( $forum['title'] ) ) {
502 $title = $forum['title'];
503 }
504 if( isset( WPF()->current_object['forum_meta_desc'] ) && WPF()->current_object['forum_meta_desc'] != '' ) {
505 $description = $paged . WPF()->current_object['forum_meta_desc'];
506 } elseif( isset( WPF()->current_object['forum_desc'] ) && WPF()->current_object['forum_desc'] != '' ) {
507 $description = $paged . WPF()->current_object['forum_desc'];
508 }
509 } elseif( isset( WPF()->current_object['topicid'] ) && isset( $topic['first_postid'] ) ) {
510 $post = WPF()->post->get_post( $topic['first_postid'] );
511 $content = wpforo_content( $post, false );
512 $image = wpforo_find_image_urls( $content, true, 'og:image' );
513 if( isset( $post['title'] ) ) {
514 $title = wpforo_text( $paged . $post['title'], 60, false );
515 }
516 if( isset( $post['body'] ) ) {
517 $description = wpforo_text( $paged . $post['body'], 150, false );
518 }
519 if( isset( $post['body'] ) ) {
520 $schema = wpforo_schema( $forum, $topic, $post );
521 }
522 } elseif( wpforo_is_member_template( $template ) ) {
523 if( isset( WPF()->board->get_current( 'settings' )['title'] ) ) {
524 $title = $paged . WPF()->board->get_current( 'settings' )['title'];
525 }
526 $udata['name'] = ( isset( $user['display_name'] ) && $user['display_name'] ) ? wpforo_phrase( 'User', false ) . ': ' . $user['display_name'] : '';
527 $udata['title'] = ( isset( $user['rating']['title'] ) && $user['rating']['title'] ) ? wpforo_phrase( 'Title', false ) . ': ' . $user['rating']['title'] : '';
528 $udata['about'] = ( isset( $user['about'] ) && $user['about'] ) ? wpforo_phrase( 'About', false ) . ': ' . wpforo_text( $user['about'], 150, false ) : '';
529 $description = $title . ' - ' . wpforo_phrase( 'Member Profile', false ) . ' &gt; ' . wpforo_phrase( ucfirst( (string) $template ), false ) . ' ' . wpforo_phrase( 'Page', false ) . '. ' . implode( ', ', $udata );
530 if( ! wpforo_setting( 'seo', 'seo_profile' ) ) {
531 $noindex = "<meta name=\"robots\" content=\"noindex\">\r\n";
532 }
533 } elseif( isset( WPF()->current_object['template'] ) && WPF()->current_object['template'] === 'member' ) {
534 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? wpforo_phrase( 'Page', false ) . ' ' . $_GET['wpfpaged'] . ' | ' : '';
535 $description = $wpfpaged . wpforo_phrase( 'Forum Members List', false );
536 } elseif( isset( WPF()->current_object['template'] ) && WPF()->current_object['template'] === 'recent' ) {
537 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? wpforo_phrase( 'Page', false ) . ' ' . $_GET['wpfpaged'] . ' | ' : '';
538 $description = $wpfpaged . wpforo_phrase( 'Recent Posts', false );
539 } elseif( isset( WPF()->current_object['template'] ) && WPF()->current_object['template'] === 'tags' ) {
540 $wpfpaged = ( isset( $_GET['wpfpaged'] ) && $_GET['wpfpaged'] > 1 ) ? wpforo_phrase( 'Page', false ) . ' ' . $_GET['wpfpaged'] . ' | ' : '';
541 $description = $wpfpaged . wpforo_phrase( 'Tags', false );
542 } else {
543 if( isset( WPF()->board->get_current( 'settings' )['title'] ) ) {
544 $title = $paged . WPF()->board->get_current( 'settings' )['title'];
545 }
546 if( isset( WPF()->board->get_current( 'settings' )['desc'] ) ) {
547 $description = $paged . WPF()->board->get_current( 'settings' )['desc'];
548 }
549 if( isset( WPF()->current_object['template'] ) && ( WPF()->current_object['template'] == 'login' || WPF()->current_object['template'] == 'register' ) ) {
550 $noindex = "<meta name=\"robots\" content=\"noindex\">\r\n";
551 }
552 }
553 $description = strip_tags( str_replace( '>', '> ', $description ) );
554 $description = preg_replace( '#[\t\r\n]+#iu', ' ', $description );
555 if( $image ) {
556 $og_img = '<meta property="og:image" content="' . $image . '" />' . "\r\n";
557 $tw_img = '<meta property="twitter:image" content="' . $image . '" />' . "\r\n";
558 }
559 $meta_tags = "\r\n<!-- wpForo SEO -->\r\n" . $noindex . "<link rel=\"canonical\" href=\"" . $canonical . "\" />\r\n<meta name=\"description\" content=\"" . esc_html( $description ) . "\" />\r\n<meta property=\"og:title\" content=\"" . esc_html( $title ) . "\" />\r\n<meta property=\"og:description\" content=\"" . esc_html( $description ) . "\" />\r\n<meta property=\"og:url\" content=\"" . $canonical . "\" />\r\n<meta property=\"og:locale\" content=\"" . WPF()->locale . "\" />\r\n" . $og_img . "<meta property=\"og:site_name\" content=\"" . get_bloginfo(
560 'name'
561 ) . "\" />\r\n<meta property=\"og:type\" content=\"website\" />\r\n<meta name=\"twitter:description\" content=\"" . esc_html( $description ) . "\"/>\r\n<meta name=\"twitter:title\" content=\"" . esc_html( $title ) . "\" />\r\n<meta property=\"twitter:card\" content=\"summary_large_image\" />\r\n" . $tw_img . "<!-- wpForo SEO End -->\r\n\r\n";
562 $schema = "<!-- wpForo Schema -->" . $schema . "\r\n<!-- wpForo Schema End -->\r\n\r\n";
563 echo apply_filters( 'wpforo_seo_meta_tags', $meta_tags . $schema );
564 }
565 }
566 }
567
568 add_action( 'wp_head', 'wpforo_add_meta_tags', 1 );
569
570 add_action( 'wp_ajax_wpforo_answer_ajax', 'wpf_answer' );
571 function wpf_answer() {
572 wpforo_verify_nonce( 'wpforo_answer_ajax' );
573 $response = [ 'notice' => WPF()->notice->get_notices() ];
574 if( ! is_user_logged_in() ) {
575 WPF()->notice->add( wpforo_get_login_or_register_notice_text() );
576 $response['notice'] = WPF()->notice->get_notices();
577 wp_send_json_error( $response );
578 }
579 if( ! isset( $_POST['answerstatus'] ) || ! isset( $_POST['postid'] ) || ! $postid = intval( $_POST['postid'] ) ) {
580 WPF()->notice->add( 'action error', 'error' );
581 $response['notice'] = WPF()->notice->get_notices();
582 wp_send_json_error( $response );
583 }
584 if( ! $post = WPF()->post->get_post( $postid ) ) {
585 WPF()->notice->add( 'post not found', 'error' );
586 $response['notice'] = WPF()->notice->get_notices();
587 wp_send_json_error( $response );
588 }
589 if( ! $topic = WPF()->topic->get_topic( $post['topicid'] ) ) {
590 WPF()->notice->add( 'topic not found', 'error' );
591 $response['notice'] = WPF()->notice->get_notices();
592 wp_send_json_error( $response );
593 }
594 if( ! ( WPF()->perm->forum_can( 'at', $post['forumid'] ) || ( WPF()->perm->forum_can( 'oat', $post['forumid'] ) && WPF()->current_userid == $topic['userid'] ) ) ) {
595 WPF()->notice->add( 'You don\'t have permission to make topic answered', 'error' );
596 $response['notice'] = WPF()->notice->get_notices();
597 wp_send_json_error( $response );
598 }
599 if( intval( $_POST['answerstatus'] ) && WPF()->topic->has_is_answer_post( $topic['topicid'] ) ) {
600 WPF()->notice->add( 'You don\'t have permission to make two best answers for one topic', 'error' );
601 $response['notice'] = WPF()->notice->get_notices();
602 wp_send_json_error( $response );
603 }
604 if( false !== WPF()->db->query( "UPDATE " . WPF()->tables->posts . " SET is_answer = " . intval( $_POST['answerstatus'] ) . " WHERE postid = " . intval( $postid ) ) ) {
605 wpforo_clean_cache( 'post', $postid, $post );
606 WPF()->db->query( "UPDATE " . WPF()->tables->topics . " SET `solved` = " . intval( $_POST['answerstatus'] ) . " WHERE `topicid` = " . intval( $post['topicid'] ) );
607 do_action( 'wpforo_answer', intval( $_POST['answerstatus'] ), $post );
608 WPF()->notice->add( 'done', 'success' );
609 $response['notice'] = WPF()->notice->get_notices();
610 wp_send_json_success( $response );
611 }
612 wp_send_json_error( $response );
613 }
614
615 add_action( 'wp_ajax_wpforo_quote_ajax', 'wpf_quote' );
616 add_action( 'wp_ajax_nopriv_wpforo_quote_ajax', 'wpf_quote' );
617 function wpf_quote() {
618 wpforo_verify_nonce( 'wpforo_quote_ajax' );
619 if( ! $current_topicid = wpforo_bigintval( WPF()->current_object['topicid'] ) ) {
620 exit();
621 }
622 $post = WPF()->db->get_row( 'SELECT * FROM ' . WPF()->tables->posts . ' WHERE topicid = ' . $current_topicid . ' AND postid =' . wpforo_bigintval( $_POST['postid'] ), ARRAY_A );
623 if( ! ( WPF()->perm->forum_can( 'cr', $post['forumid'] ) || ( wpforo_is_owner( wpfval( WPF()->current_object['topic'], 'userid' ), wpfval( WPF()->current_object['topic'], 'email' ) ) && WPF()->perm->forum_can( 'ocr', $post['forumid'] ) ) ) ) {
624 return;
625 }
626 $post = apply_filters( 'wpforo_quote_post_ajax', $post );
627 $response = sprintf( '[quote data-userid="%1$d" data-postid="%2$d"]%3$s[/quote]<p></p>', $post['userid'], $post['postid'], wpautop( $post['body'] ) );
628 wp_send_json_success( $response );
629 }
630
631 add_action( 'wp_ajax_wpforo_report_ajax', 'wpf_report' );
632 function wpf_report() {
633 wpforo_verify_nonce( 'wpforo_report_ajax' );
634 if( ! is_user_logged_in() ) {
635 WPF()->notice->add( wpforo_get_login_or_register_notice_text() );
636 wp_send_json_error( WPF()->notice->get_notices() );
637 }
638
639 if( ! isset( $_POST['reportmsg'] ) || ! $_POST['reportmsg'] || ! isset( $_POST['postid'] ) || ! $_POST['postid'] ) {
640 WPF()->notice->add( 'Error: please insert some text to report.', 'error' );
641 wp_send_json_error( WPF()->notice->get_notices() );
642 }
643
644 ############### Sending Email ##################
645 $report_text = substr( strip_tags( (string) $_POST['reportmsg'] ), 0, 1000 );
646 $postid = intval( $_POST['postid'] );
647 $reporter = '<a href="' . WPF()->current_user['profile_url'] . '">' . ( WPF()->current_user['display_name'] ? WPF()->current_user['display_name'] : urldecode( (string) WPF()->current_user['user_nicename'] ) ) . '</a>';
648 $reportmsg = wpforo_kses( $report_text, 'email' );
649 $post_url = WPF()->post->get_url( $postid );
650
651 $subject = wpforo_setting( 'email', 'report_email_subject' );
652 $message = wpforo_setting( 'email', 'report_email_message' );
653
654 $from_tags = [ "[reporter]", "[message]", "[post_url]" ];
655 $to_words = [
656 sanitize_text_field( $reporter ),
657 $reportmsg,
658 '<a target="_blank" href="' . esc_url( (string) $post_url ) . '">' . esc_url( (string) $post_url ) . '</a>',
659 ];
660
661 $subject = stripslashes( strip_tags( str_replace( $from_tags, $to_words, (string) $subject ) ) );
662 $message = stripslashes( str_replace( $from_tags, $to_words, (string) $message ) );
663
664 $admin_emails = wpforo_setting( 'email', 'admin_emails' );
665 $admin_email = wpfval($admin_emails, 0);
666 $headers = wpforo_admin_mail_headers();
667
668 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type', 999 );
669 if( @wp_mail( $admin_email, $subject, $message, $headers ) ) {
670 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
671 } else {
672 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
673 WPF()->notice->add( 'Can\'t send report email', 'error' );
674 wp_send_json_error( WPF()->notice->get_notices() );
675 }
676
677 ############### Sending Email end ##############
678 WPF()->notice->add( 'Message has been sent', 'success' );
679 wp_send_json_success( WPF()->notice->get_notices() );
680 }
681
682 add_action( 'wp_ajax_wpforo_sticky_ajax', 'wpf_sticky' );
683 add_action( 'wp_ajax_nopriv_wpforo_sticky_ajax', 'wpf_sticky' );
684 function wpf_sticky() {
685 wpforo_verify_nonce( 'wpforo_sticky_ajax' );
686 WPF()->notice->add( 'wrong data', 'error' );
687 $response = [ 'notice' => WPF()->notice->get_notices() ];
688 if( ! $topicid = wpforo_bigintval( wpfval( $_POST, 'topicid' ) ) ) {
689 wp_send_json_error( $response );
690 }
691
692 $sql = "SELECT `forumid` FROM `" . WPF()->tables->topics . "` WHERE `topicid` = $topicid";
693 $forumid = WPF()->db->get_var( $sql );
694 if( ! WPF()->perm->forum_can( 's', $forumid ) ) {
695 WPF()->notice->add( 'You don\'t have permission to do this action from this forum', 'error' );
696 $response['notice'] = WPF()->notice->get_notices();
697 wp_send_json_error( $response );
698 }
699 $status = wpfval( $_POST, 'status' );
700 if( $status === 'sticky' ) {
701 $sql = "UPDATE `" . WPF()->tables->topics . "` SET `type` = 1 WHERE `topicid` = $topicid";
702 if( false !== WPF()->db->query( $sql ) ) {
703 wpforo_clean_cache( 'topic-first-post', $topicid );
704 WPF()->notice->add( 'Done!', 'success' );
705 $response['notice'] = WPF()->notice->get_notices();
706 wp_send_json_success( $response );
707 }
708 } elseif( $status === 'unsticky' ) {
709 $sql = "UPDATE `" . WPF()->tables->topics . "` SET `type` = 0 WHERE `topicid` = $topicid";
710 if( false !== WPF()->db->query( $sql ) ) {
711 wpforo_clean_cache( 'topic-first-post', $topicid );
712 WPF()->notice->add( 'Done!', 'success' );
713 $response['notice'] = WPF()->notice->get_notices();
714 wp_send_json_success( $response );
715 }
716 }
717 wp_send_json_error( $response );
718 }
719
720 add_action( 'wp_ajax_wpforo_private_ajax', 'wpf_private' );
721 function wpf_private() {
722 wpforo_verify_nonce( 'wpforo_private_ajax' );
723 if( ! WPF()->current_userid ) {
724 wp_send_json_error();
725 }
726 if( ! ( $topicid = wpforo_bigintval( wpfval( $_POST, 'topicid' ) ) ) ) {
727 wp_send_json_error();
728 }
729 if( ! ( $topic = WPF()->topic->get_topic( $topicid ) ) ){
730 wp_send_json_error();
731 }
732 if( ! ( WPF()->perm->forum_can( 'p', $topic['forumid'] ) || ( WPF()->current_userid == $topic['userid'] && WPF()->perm->forum_can( 'op', $topic['forumid'] ) ) ) ){
733 wp_send_json_error();
734 }
735 $status = wpfval( $_POST, 'status' );
736 if( $status === 'private' ) {
737 WPF()->topic->wprivate( $topicid, 1 );
738 wp_send_json_success();
739 } elseif( $status === 'public' ) {
740 WPF()->topic->wprivate( $topicid, 0 );
741 wp_send_json_success();
742 }
743 wp_send_json_error();
744 }
745
746 add_action( 'wp_ajax_wpforo_solved_ajax', 'wpf_solved' );
747 add_action( 'wp_ajax_nopriv_wpforo_solved_ajax', 'wpf_solved' );
748 function wpf_solved() {
749 wpforo_verify_nonce( 'wpforo_solved_ajax' );
750 if( ! WPF()->current_userid ){
751 wp_send_json_error();
752 }
753 if( ! $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ) {
754 wp_send_json_error();
755 }
756 if( $post = WPF()->post->get_post( $postid ) ) {
757 if( WPF()->perm->forum_can( 'sv', $post['forumid'] ) || ( WPF()->current_userid == $post['userid'] && WPF()->perm->forum_can( 'osv', $post['forumid'] ) ) ) {
758 $solved = ( wpfval( $_POST, 'status' ) === 'solved' ? 1 : 0 );
759 $sql = "UPDATE " . WPF()->tables->topics . " SET `solved` = %d WHERE `topicid` = %d";
760 WPF()->db->query( WPF()->db->prepare( $sql, $solved, $post['topicid'] ) );
761 wpforo_clean_cache( 'topic-first-post', $post['topicid'] );
762 wp_send_json_success();
763 }
764 }
765 wp_send_json_error();
766 }
767
768 add_action( 'wp_ajax_wpforo_approve_ajax', 'wpf_approve' );
769 function wpf_approve() {
770 wpforo_verify_nonce( 'wpforo_approve_ajax' );
771 if( ! WPF()->current_userid ) {
772 WPF()->notice->add( wpforo_get_login_or_register_notice_text() );
773 wp_send_json_error();
774 }
775 if( ! $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ) {
776 wp_send_json_error();
777 }
778 $status = wpfval( $_POST, 'status' );
779 if( $status === 'approve' ) {
780 WPF()->moderation->post_approve( $postid );
781 wp_send_json_success();
782 } elseif( $status === 'unapprove' ) {
783 WPF()->moderation->post_unapprove( $postid );
784 wp_send_json_success();
785 }
786 wp_send_json_error();
787 }
788
789 add_action( 'wp_ajax_wpforo_close_ajax', 'wpf_close' );
790 function wpf_close() {
791 wpforo_verify_nonce( 'wpforo_close_ajax' );
792 if( ! WPF()->current_userid ) {
793 wp_send_json_error();
794 }
795
796 if( ! $topicid = wpforo_bigintval( wpfval( $_POST, 'topicid' ) ) ) {
797 wp_send_json_error();
798 }
799 $status = wpfval( $_POST, 'status' );
800 if( $status === 'closed' ) {
801 $sql = "UPDATE " . WPF()->tables->topics . " SET closed = 0 WHERE topicid = " . $topicid;
802 WPF()->db->query( $sql );
803 wpforo_clean_cache( 'topic-first-post', $topicid );
804 wp_send_json_success();
805 } elseif( $status === 'close' ) {
806 $sql = "UPDATE " . WPF()->tables->topics . " SET closed = 1 WHERE topicid = " . $topicid;
807 WPF()->db->query( $sql );
808 wpforo_clean_cache( 'topic-first-post', $topicid );
809 wp_send_json_success();
810 }
811 wp_send_json_error();
812 }
813
814 add_action( 'wp_ajax_wpforo_post_edit', 'wpforo_post_edit' );
815 add_action( 'wp_ajax_nopriv_wpforo_post_edit', 'wpforo_post_edit' );
816 function wpforo_post_edit() {
817 wpforo_verify_nonce( 'wpforo_post_edit' );
818 $r = [ 'html' => '' ];
819 if( $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ) {
820 if( $post = WPF()->post->get_post( $postid, false ) ) {
821 if( WPF()->perm->forum_can( 'eor', $post['forumid'] ) || WPF()->perm->forum_can( 'eot', $post['forumid'] ) ) {
822 if( $topic = WPF()->topic->get_topic( $post['topicid'] ) ) {
823 $postmetas = (array) WPF()->postmeta->get_postmeta( $postid, '', true );
824 $post['body'] = htmlspecialchars( $post['body'], ENT_NOQUOTES );
825 $values = array_merge( $post, $topic, $postmetas );
826 $values = apply_filters( 'wpforo_edit_post_ajax', $values, $post, $topic, $postmetas );
827 ob_start();
828 if( intval( $post['is_first_post'] ) ) {
829 WPF()->form->current['varname'] = 'thread';
830 WPF()->tpl->topic_form( $post['forumid'], $values );
831 } else {
832 WPF()->form->current['varname'] = 'post';
833 if( trim( (string) $post['title'] ) ) {
834 $values['title'] = $post['title'];
835 }
836 WPF()->tpl->reply_form( $topic, $values );
837 }
838 $r['html'] = ob_get_clean();
839 wp_send_json_success( $r );
840 }
841 }
842 }
843 }
844 wp_send_json_error( $r );
845 }
846
847 add_action( 'wp_ajax_wpforo_delete_ajax', 'wpf_delete' );
848 function wpf_delete() {
849 wpforo_verify_nonce( 'wpforo_delete_ajax' );
850 $resp = [];
851 $status = (string) wpfval( $_POST, 'status' );
852 $postid = (int) wpfval( $_POST, 'postid' );
853 if( $status === 'topic' ) {
854 if( WPF()->topic->delete( $postid ) ) {
855 $forumid = (int) wpfval( $_POST, 'forumid' );
856 $resp = [
857 'postid' => $postid,
858 'location' => $forumid ? WPF()->forum->get_forum_url( $forumid ) : wpforo_home_url(),
859 ];
860 $resp['notice'] = WPF()->notice->get_notices();
861 wp_send_json_success( $resp );
862 }
863 } elseif( $status === 'reply' ) {
864 if( WPF()->post->delete( $postid ) ) {
865 $root = (int) WPF()->post->get_root( $postid );
866 $root_replies_count = (int) WPF()->post->get_root_replies_count( $root );
867 $resp = [
868 'postid' => $postid,
869 'root' => $root,
870 'root_count' => $root_replies_count,
871 ];
872 $resp['notice'] = WPF()->notice->get_notices();
873 wp_send_json_success( $resp );
874 }
875 }
876
877 $resp['notice'] = WPF()->notice->get_notices();
878 wp_send_json_error( $resp );
879 }
880
881 add_action( 'wp_ajax_wpforo_layout4_loadmore', 'wpfl4_loadmore' );
882 add_action( 'wp_ajax_nopriv_wpforo_layout4_loadmore', 'wpfl4_loadmore' );
883 function wpfl4_loadmore() {
884 wpforo_verify_nonce( 'wpforo_layout4_loadmore' );
885 $success = false;
886 WPF()->notice->add( 'wrong data', 'error' );
887 $response = [ 'no_more' => 0, 'output_html' => '', 'notice' => WPF()->notice->get_notices() ];
888 $request = [
889 'forumid' => 0,
890 'filter' => 'newest',
891 'paged' => 1,
892 ];
893 $request = array_merge( $request, $_POST );
894
895 if( $forumid = intval( $request['forumid'] ) ) {
896 $items_count = 0;
897 $childs = WPF()->forum->get_childs( $forumid );
898 $childs[] = $forumid;
899 $args = [
900 'offset' => ( $request['paged'] - 1 ) * wpforo_setting( 'forums', 'layout_threaded_intro_topics_count' ),
901 'row_count' => wpforo_setting( 'forums', 'layout_threaded_intro_topics_count' ),
902 'forumids' => $childs,
903 'orderby' => 'type, modified',
904 'order' => 'DESC',
905 ];
906
907 switch( $request['filter'] ) {
908 case 'solved':
909 $args['solved'] = 1;
910 $args['type'] = 0;
911 break;
912 case 'unsolved':
913 $args['solved'] = 0;
914 $args['type'] = 0;
915 $args['closed'] = 0;
916 break;
917 case 'hottest':
918 $args['orderby'] = 'posts';
919 break;
920 }
921
922 $topics = WPF()->topic->get_topics( $args, $items_count );
923 if( $topics ) {
924 ob_start();
925 if( function_exists( 'wpforo_thread_forum_template' ) ) {
926 foreach( $topics as $topic ) {
927 wpforo_thread_forum_template( $topic['topicid'] );
928 }
929 }
930 $response['output_html'] = ob_get_clean();
931 $success = true;
932 $response['notice'] = '';
933 if( count( $topics ) < wpforo_setting( 'forums', 'layout_threaded_intro_topics_count' ) ) {
934 $response['no_more'] = 1;
935 }
936 } else {
937 $response['no_more'] = 1;
938 }
939
940 if( $response['no_more'] ) {
941 WPF()->notice->add( 'all topics has been loaded in this list', 'success' );
942 $response['notice'] = WPF()->notice->get_notices();
943 }
944 }
945
946 if( $success ) {
947 wp_send_json_success( $response );
948 } else {
949 wp_send_json_error( $response );
950 }
951 }
952
953 add_action( 'wp_ajax_wpforo_topic_portable_form', 'wpforo_topic_portable_form' );
954 add_action( 'wp_ajax_nopriv_wpforo_topic_portable_form', 'wpforo_topic_portable_form' );
955 function wpforo_topic_portable_form() {
956 wpforo_verify_nonce( 'wpforo_topic_portable_form' );
957 $html = '';
958 if( $forumid = wpfval( $_POST, 'forumid' ) ) {
959 WPF()->form->current['varname'] = 'thread';
960 ob_start();
961 WPF()->tpl->topic_form( $forumid );
962 $html = trim( (string) ob_get_clean() );
963 }
964 if( $html ) {
965 wp_send_json_success( $html );
966 } else {
967 wp_send_json_error();
968 }
969 }
970
971 add_action( 'wp_ajax_wpforo_qa_comment_loadrest', 'wpforo_qa_comment_loadrest' );
972 add_action( 'wp_ajax_nopriv_wpforo_qa_comment_loadrest', 'wpforo_qa_comment_loadrest' );
973 function wpforo_qa_comment_loadrest() {
974 wpforo_verify_nonce( 'wpforo_qa_comment_loadrest' );
975 WPF()->notice->add( 'wrong data', 'error' );
976 $response = [ 'output_html' => '', 'notice' => WPF()->notice->get_notices() ];
977 if( $parentid = wpfval( $_POST, 'parentid' ) ) {
978 $args = [
979 'root' => $parentid,
980 'offset' => wpforo_setting( 'topics', 'layout_qa_comments_limit_count' ),
981 'row_count' => PHP_INT_MAX,
982 ];
983 if( ! wpforo_root_exist() ) {
984 unset( $args['root'] );
985 $args['parentid'] = $parentid;
986 }
987 if( $comments = WPF()->post->get_posts( $args ) ) {
988 ob_start();
989 include_once( wpftpl( 'layouts/3/comment.php' ) );
990 ob_clean();
991
992 foreach( $comments as $comment ) {
993 wpforo_qa_comment_template( $comment );
994 }
995
996 $response['output_html'] = ob_get_clean();
997 $response['notice'] = '';
998 wp_send_json_success( $response );
999 }
1000 }
1001 wp_send_json_error( $response );
1002 }
1003
1004 add_action( 'wp_ajax_wpforo_post_url_fixer', 'wpforo_post_url_fixer' );
1005 add_action( 'wp_ajax_nopriv_wpforo_post_url_fixer', 'wpforo_post_url_fixer' );
1006 function wpforo_post_url_fixer() {
1007 wpforo_verify_nonce( 'wpforo_post_url_fixer' );
1008 if( ( $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ) && ( $referer = wpfval( $_POST, 'referer' ) ) ) {
1009 if( is_wpforo_url( $referer ) ) {
1010 $diff = 100;
1011 $referer_hash = md5( $referer . $postid );
1012 $nowtime = time();
1013 if( $lasttime = (int) get_transient( 'wpforo_post_url_fixer' . $referer_hash ) ) {
1014 $diff = $nowtime - $lasttime;
1015 }
1016 if( $diff <= 8 ) {
1017 exit();
1018 }
1019 set_transient( 'wpforo_post_url_fixer' . $referer_hash, $nowtime, 1000 );
1020 if( $post = WPF()->post->get_post( $postid ) ) {
1021 echo WPF()->post->get_url( $post );
1022 }
1023 }
1024 }
1025 exit();
1026 }
1027
1028 add_action( 'wp_ajax_wpforo_update_database', 'wpforo_ajax_update_database' );
1029 function wpforo_ajax_update_database() {
1030 check_admin_referer( 'wpforo_update_database' );
1031 wpforo_set_max_execution_time();
1032 wpforo_update_db();
1033 exit();
1034 }
1035
1036 ############### Sending Email ##################
1037 function wpforo_set_html_content_type() {
1038 return apply_filters( 'wpforo_emails_content_type', 'text/html' );
1039 }
1040
1041 function __wpforo_set_html_content_type() {
1042 return 'text/html';
1043 }
1044
1045 function wpforo_mail_from_name() {
1046 return wpforo_setting( 'email', 'from_name' ) ?: get_option( 'blogname' );
1047 }
1048
1049 function wpforo_mail_from_email() {
1050 return wpforo_setting( 'email', 'from_email' ) ?: get_option( 'admin_email' );
1051 }
1052
1053 function wpforo_mail_headers( $from_name = '', $from_email = '', $cc = [], $bcc = [] ) {
1054 $H = [];
1055 if( ! $from_name ) {
1056 $from_name = wpforo_mail_from_name();
1057 }
1058 if( ! $from_email ) {
1059 $from_email = wpforo_mail_from_email();
1060 }
1061 $H[] = 'From: ' . $from_name . ' <' . $from_email . '>';
1062 if( ! empty( $cc ) ) {
1063 foreach( $cc as $c ) {
1064 $c = sanitize_email( $c );
1065 $H[] = 'CC: ' . $c;
1066 }
1067 }
1068 if( ! empty( $bcc ) ) {
1069 foreach( $bcc as $b ) {
1070 $b = sanitize_email( $b );
1071 $H[] = 'BCC: ' . $b;
1072 }
1073 }
1074
1075 return $H;
1076 }
1077
1078 function wpforo_admin_mail_headers( $from_name = '', $from_email = '', $cc = [], $bcc = [] ) {
1079 $H = [];
1080 if( ! $from_name ) {
1081 $from_name = wpforo_mail_from_name();
1082 }
1083 if( ! $from_email ) {
1084 $from_email = wpforo_mail_from_email();
1085 }
1086 $H[] = 'From: ' . $from_name . ' <' . $from_email . '>';
1087 if( empty( $cc ) ) $cc = wpforo_setting( 'email', 'admin_emails' );
1088 if( ! empty( $cc ) ) {
1089 foreach( $cc as $c ) {
1090 $c = sanitize_email( $c );
1091 $H[] = 'CC: ' . $c;
1092 }
1093 }
1094 if( ! empty( $bcc ) ) {
1095 foreach( $bcc as $b ) {
1096 $b = sanitize_email( $b );
1097 $H[] = 'BCC: ' . $b;
1098 }
1099 }
1100
1101 return $H;
1102 }
1103
1104 function wpforo_get_login_or_register_notice_text() {
1105 $popup_html = '';
1106 if( ! wpforo_is_bot() ) {
1107 $popup_html = sprintf( wpforo_phrase( 'Please %s or %s', false ), '<a href="' . wpforo_login_url() . '" rel="noindex,nofollow">' . wpforo_phrase( 'Login', false ) . '</a>', '<a href="' . wpforo_register_url() . '" rel="noindex,nofollow">' . wpforo_phrase( 'Register', false ) . '</a>' );
1108 }
1109
1110 return apply_filters( 'wpforo_login_or_register_popup_message', $popup_html );
1111 }
1112
1113 function wpforo_dynamic_phrases_register() {
1114 if( ! $js = WPF()->phrase->get_wpforo_phrases_inline_js() ) {
1115 return;
1116 }
1117 $md5_js = md5( $js );
1118
1119 $inline = false;
1120 $dynamic_js_file = WPF()->folders['assets']['dir'] . DIRECTORY_SEPARATOR . 'phrases.js';
1121 if( ! file_exists( $dynamic_js_file ) || $md5_js !== md5_file( $dynamic_js_file ) ) {
1122 $result = wpforo_write_file( $dynamic_js_file, $js );
1123 if( wpfval( $result, 'error' ) ) {
1124 $inline = true;
1125 }
1126 }
1127
1128 wp_register_script( 'wpforo-dynamic-phrases', WPF()->folders['assets']['url'] . '/phrases.js', false, WPFORO_VERSION . '.' . $md5_js );
1129 if( $inline ) {
1130 $js = preg_replace( '|[\r\n\t]+|', '', $js );
1131 wp_add_inline_script( 'wpforo-dynamic-phrases', $js );
1132 }
1133 }
1134
1135 function wpforo_dynamic_style_enqueue() {
1136 if( ! $css = WPF()->tpl->generate_dynamic_css() ) {
1137 return;
1138 }
1139 $md5_css = md5( $css );
1140
1141 $inline = false;
1142 $dynamic_css_file = WPF()->folders['assets']['dir'] . DIRECTORY_SEPARATOR . 'colors.css';
1143 if( ! file_exists( $dynamic_css_file ) || $md5_css !== md5_file( $dynamic_css_file ) ) {
1144 $result = wpforo_write_file( $dynamic_css_file, $css );
1145 if( wpfval( $result, 'error' ) ) {
1146 $inline = true;
1147 }
1148 }
1149
1150 wp_register_style( 'wpforo-dynamic-style', WPF()->folders['assets']['url'] . '/colors.css', false, WPFORO_VERSION . '.' . $md5_css );
1151 if( $inline ) {
1152 $css = preg_replace( '|[\r\n\t]+|', '', $css );
1153 wp_add_inline_style( 'wpforo-dynamic-style', $css );
1154 }
1155
1156 wp_enqueue_style( 'wpforo-dynamic-style' );
1157 }
1158
1159 add_action( 'wp_enqueue_scripts', 'wpforo_dynamic_style_enqueue', 999 );
1160
1161 function wpforo_frontend_register_scripts() {
1162 wp_register_style( 'wpforo-font-awesome', WPFORO_URL . '/assets/css/font-awesome/css/fontawesome-all.min.css', false, '6.1.1' );
1163 //wp_register_style( 'wpforo-font-awesome-rtl', WPFORO_URL . '/assets/css/font-awesome/css/font-awesome-rtl.css', [ 'wpforo-font-awesome' ], WPFORO_VERSION );
1164 wpforo_dynamic_phrases_register();
1165 wp_register_script( 'wpforo-frontend-js', WPFORO_URL . '/assets/js/frontend.js', [
1166 'jquery',
1167 'wpforo-dynamic-phrases',
1168 ], WPFORO_VERSION, true );
1169 wp_localize_script( 'wpforo-frontend-js', 'wpforo', [
1170 'ajax_url' => wpforo_get_ajax_url(),
1171 'nonces' => wpforo_generate_ajax_nonces(),
1172 'settings_slugs' => WPF()->settings->slugs,
1173 'editor_settings' => WPF()->tpl->editor_buttons( 'post' ),
1174 'revision_options' => WPF()->settings->posting,
1175 'notice' => [
1176 'login_or_register' => wpforo_get_login_or_register_notice_text(),
1177 'timeouts' => WPF()->notice->get_timeouts(),
1178 ],
1179 ] );
1180 wp_register_script( 'wpforo-ajax', WPFORO_URL . '/assets/js/ajax.js', [
1181 'suggest',
1182 'wpforo-frontend-js',
1183 ], WPFORO_VERSION, true );
1184 wp_register_style( 'wpforo-style', wpftpl_url( 'style.css' ), false, WPFORO_VERSION );
1185 wp_register_style( 'wpforo-style-rtl', wpftpl_url( 'style-rtl.css' ), false, WPFORO_VERSION );
1186 wp_register_style( 'wpforo-widgets', wpftpl_url( 'widgets.css' ), [], WPFORO_VERSION );
1187 wp_register_style( 'wpforo-widgets-rtl', wpftpl_url( 'widgets-rtl.css' ), [], WPFORO_VERSION );
1188 wp_register_script( 'wpforo-widgets-js', WPFORO_URL . '/assets/js/widgets.js', [ 'jquery' ], WPFORO_VERSION, true );
1189 $wpforo_widgets = [
1190 'ajax_url' => wpforo_get_ajax_url(),
1191 'is_live_notifications_on' => 0,
1192 'live_notifications_start' => 30000,
1193 'live_notifications_interval' => 60000,
1194 ];
1195 if( WPF()->current_userid && wpforo_setting( 'notifications', 'notifications' ) && wpforo_setting( 'notifications', 'notifications_live' ) ) {
1196 $start = apply_filters( 'wpforo_notifications_list', 30000 );
1197 $interval = apply_filters( 'wpforo_notifications_list', 60000 );
1198 if( $interval < 10000 ) {
1199 $interval = 10000;
1200 }
1201 $wpforo_widgets['is_live_notifications_on'] = 1;
1202 $wpforo_widgets['live_notifications_start'] = $start;
1203 $wpforo_widgets['live_notifications_interval'] = $interval;
1204 }
1205 wp_localize_script( 'wpforo-widgets-js', 'wpforo_widgets', $wpforo_widgets );
1206
1207 if( ! WPF()->perm->forum_can( 'va' ) || ! WPF()->usergroup->can( 'caa' ) ) {
1208 wp_add_inline_script(
1209 'wpforo-frontend-js',
1210 "jQuery(document).ready(function($){
1211 $('#wpforo-wrap').on('click', '.attach_cant_view', function(){
1212 wpforo_notice_show(
1213 '<p>" . addslashes( (string) ( is_user_logged_in() ? wpforo_phrase( 'You are not permitted to view this attachment', false ) : wpforo_get_login_or_register_notice_text() ) ) . "</p>'
1214 );
1215 });
1216 })"
1217 );
1218 }
1219
1220 do_action( 'wpforo_frontend_register_scripts' );
1221
1222 wpforo_frontend_enqueue_scripts();
1223 }
1224
1225 add_action( 'wp_enqueue_scripts', 'wpforo_frontend_register_scripts' );
1226
1227 function wpforo_frontend_enqueue_scripts() {
1228 $fontawesome = wpforo_setting( 'general', 'fontawesome' );
1229 if( $fontawesome === 'sitewide' || ( $fontawesome === 'forum' && is_wpforo_page() ) ) {
1230 wp_enqueue_style( 'wpforo-font-awesome' );
1231 //if( is_rtl() ) wp_enqueue_style( 'wpforo-font-awesome-rtl' );
1232 }
1233
1234 if( is_wpforo_page() ) {
1235 wp_enqueue_script( 'wpforo-dynamic-phrases' );
1236 wp_enqueue_script( 'wpforo-frontend-js' );
1237 wp_enqueue_script( 'wpforo-ajax' );
1238 if( is_rtl() ) {
1239 wp_enqueue_style( 'wpforo-style-rtl' );
1240 } else {
1241 wp_enqueue_style( 'wpforo-style' );
1242 }
1243 }
1244
1245 if( is_rtl() ) {
1246 wp_enqueue_style( 'wpforo-widgets-rtl' );
1247 } else {
1248 wp_enqueue_style( 'wpforo-widgets' );
1249 }
1250
1251 do_action( 'wpforo_frontend_enqueue_scripts' );
1252 }
1253
1254 function wpforo_style_options( $css ) {
1255 $css .= "\r\n#wpforo-wrap .wpforo-forum-title{font-size: " . wpforo_setting( 'styles', 'font_size_forum' ) . "px!important; line-height: " . ( wpforo_setting( 'styles', 'font_size_forum' ) + 1 ) . "px!important;}";
1256 $css .= "\r\n#wpforo-wrap .wpforo-topic-title a { font-size: " . wpforo_setting( 'styles', 'font_size_topic' ) . "px!important; }";
1257 $css .= "\r\n#wpforo-wrap .wpforo-post .wpf-right .wpforo-post-content {font-size: " . wpforo_setting( 'styles', 'font_size_post_content' ) . "px!important;}\r\n#wpforo-wrap .wpforo-post .wpf-right .wpforo-post-content p {font-size: " . wpforo_setting( 'styles', 'font_size_post_content' ) . "px;}";
1258
1259 if( 'bottom' === wpforo_setting( 'posting', 'topic_editor_toolbar_location' ) ) {
1260 $css .= "\r\n
1261 #wpforo #wpforo-wrap .wpf-topic-create .mce-container-body{display: flex; flex-direction: column;}
1262 #wpforo #wpforo-wrap .wpf-topic-create .mce-top-part{order: 1}
1263 #wpforo #wpforo-wrap .wpf-topic-create .wpf-field-wrap > .wpf-extra-fields,
1264 #wpforo #wpforo-wrap .wpforo-portable-form-wrap .wpf-extra-fields,
1265 #wpforo #wpforo-wrap .wpforo-messages-content .wpfpm-main .wpfpm-form-wrapper .wpf-extra-fields{ margin-top: 10px !important; }";
1266 }
1267 if( 'bottom' === wpforo_setting( 'posting', 'reply_editor_toolbar_location' ) ) {
1268 $css .= "\r\n
1269 #wpforo #wpforo-wrap .wpf-post-create .mce-container-body{display: flex; flex-direction: column;}
1270 #wpforo #wpforo-wrap .wpf-post-create .mce-top-part{order: 1}
1271 #wpforo #wpforo-wrap .wpf-post-create .wpf-field-wrap > .wpf-extra-fields,
1272 #wpforo #wpforo-wrap .wpforo-portable-form-wrap .wpf-extra-fields,
1273 #wpforo #wpforo-wrap .wpforo-messages-content .wpfpm-main .wpfpm-form-wrapper .wpf-extra-fields{ margin-top: 10px !important; }";
1274 }
1275 if( $ccss = wpforo_setting( 'styles', 'custom_css' ) ) $css .= "\r\n" . stripslashes( (string) $ccss );
1276
1277 return $css;
1278 }
1279
1280 add_filter( 'wpforo_dynamic_css_filter', 'wpforo_style_options' );
1281
1282 function wpforo_admin_enqueue() {
1283 wp_register_style( 'wpforo-font-awesome', WPFORO_URL . '/assets/css/font-awesome/css/fontawesome-all.min.css', false, '6.1.1' );
1284 wp_register_style( 'wpforo-iconpicker-css', WPFORO_URL . '/admin/assets/third-party/iconpicker/fontawesome-iconpicker.min.css', [ 'wpforo-font-awesome' ], '2.0.0' );
1285 wp_register_script( 'wpforo-iconpicker-js', WPFORO_URL . '/admin/assets/third-party/iconpicker/fontawesome-iconpicker.js', [ 'jquery' ], '2.0.0', true );
1286 wp_register_style( 'wpforo-admin', WPFORO_URL . '/admin/assets/css/admin.css', false, WPFORO_VERSION );
1287 wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', [
1288 'clear' => __( 'Clear' ),
1289 'defaultString' => __( 'Default' ),
1290 'pick' => __( 'Select Color' ),
1291 ] );
1292 wp_register_script( 'wpforo-contenthover-addons', WPFORO_URL . '/admin/assets/js/contenthover/jquery.contenthover.min.js', [ 'jquery' ], WPFORO_VERSION, false );
1293 wp_register_script( 'wpforo-backend-widgets-js', WPFORO_URL . '/admin/assets/js/widgets.js', [ 'jquery' ], WPFORO_VERSION, true );
1294 wp_register_script( 'wpforo-backend-js', WPFORO_URL . '/admin/assets/js/backend.js', [ 'jquery' ], WPFORO_VERSION, false );
1295 wp_localize_script( 'wpforo-backend-js', 'wpforo_admin', [
1296 'phrases' => [
1297 'move' => __( 'Move', 'wpforo' ),
1298 'delete' => __( 'Delete', 'wpforo' ),
1299 ],
1300 ] );
1301 WPF()->settings->init_info();
1302 wp_localize_script(
1303 'wpforo-backend-js',
1304 'wpforo',
1305 [
1306 'ajax_url' => wpforo_get_ajax_url(),
1307 'nonces' => wpforo_generate_ajax_nonces(),
1308 'board' => [ 'has_more_boards' => is_wpforo_multiboard() ],
1309 'settings' => [ 'info' => [ 'core' => WPF()->settings->info->core, 'addons' => WPF()->settings->info->addons ] ]
1310 ]
1311 );
1312 wp_register_style( 'wpforo-deactivation-css', WPFORO_URL . '/admin/assets/css/deactivation-dialog.css', [], WPFORO_VERSION );
1313 wp_register_script( 'wpforo-deactivation-js', WPFORO_URL . '/admin/assets/js/deactivation-dialog.js', [ 'jquery' ], WPFORO_VERSION );
1314 wp_localize_script( 'wpforo-deactivation-js', 'wpforo_deactivation_obj', [
1315 'msgReasonRequired' => __( 'Please choose one reasons before sending a feedback!', 'wpforo' ),
1316 'msgReasonDescRequired' => __( 'Please provide more information', 'wpforo' ),
1317 'msgFeedbackHasEmailNoCheckbox' => __( 'With the email address, please check the "I agree to receive email" checkbox to proceed.', 'wpforo' ),
1318 'msgFeedbackHasCheckboxNoEmail' => __( 'Please fill your email address for feedback', 'wpforo' ),
1319 'msgFeedbackNotValidEmail' => __( 'Your email address is not valid', 'wpforo' ),
1320 'adminUrl' => get_admin_url(),
1321 ] );
1322 wp_register_script( 'wpforo-iris', admin_url( 'js/iris.min.js' ), [
1323 'jquery-ui-draggable',
1324 'jquery-ui-slider',
1325 'jquery-touch-punch',
1326 ], false, true );
1327
1328 if( ! empty( $_GET['page'] ) && strpos( (string) $_GET['page'], 'wpforo' ) === 0 ) {
1329 wp_enqueue_style( 'wpforo-admin' );
1330 wp_enqueue_script( 'wpforo-backend-js' );
1331 wp_enqueue_style( 'wpforo-iconpicker-css' );
1332 wp_enqueue_script( 'wpforo-iconpicker-js' );
1333 wp_enqueue_style( 'wpforo-font-awesome' );
1334 wp_enqueue_script( 'jquery' );
1335 wp_enqueue_script( 'jquery-ui-core' );
1336 wp_enqueue_script( 'jquery-ui-widget' );
1337 wp_enqueue_script( 'jquery-ui-mouse' );
1338 wp_enqueue_script( 'jquery-ui-position' );
1339 wp_enqueue_script( 'jquery-ui-draggable' );
1340 wp_enqueue_script( 'jquery-ui-droppable' );
1341 wp_enqueue_script( 'jquery-ui-menu' );
1342 wp_enqueue_script( 'jquery-ui-sortable' );
1343 wp_enqueue_script( 'jquery-color' );
1344 wp_enqueue_script( 'wp-lists' );
1345 if( preg_match( '#^wpforo-(?:\d+-)?forums$#iu', (string) $_GET['page'] ) ) {
1346 if( ! empty( $_GET['action'] ) ) {
1347 //Just for excluding 'nav-menu' js loading//
1348 wp_enqueue_script( 'postbox' );
1349 wp_enqueue_script( 'link' );
1350 wp_enqueue_style( 'wp-color-picker' );
1351 wp_enqueue_script( 'wp-color-picker' );
1352 wp_enqueue_script( 'wp-color-picker-script-handle' );
1353 } else {
1354 wp_enqueue_script( 'nav-menu' );
1355 }
1356 } elseif( preg_match( '#^wpforo-(?:\d+-)?settings$#iu', (string) $_GET['page'] ) && ! empty( $_GET['wpf_tab'] ) && $_GET['wpf_tab'] === 'styles' ) {
1357 wp_enqueue_style( 'wp-color-picker' );
1358 wp_enqueue_script( 'wpforo-iris' );
1359 wp_enqueue_script( 'wp-color-picker' );
1360 } elseif( $_GET['page'] === wpforo_prefix_slug( 'dashboard' ) || $_GET['page'] === 'wpforo-overview' ) {
1361 wp_enqueue_script( 'postbox' );
1362 wp_enqueue_script( 'link' );
1363 } elseif( preg_match( '#^wpforo-(?:\d+-)?addons$#iu', (string) $_GET['page'] ) ) {
1364 wp_enqueue_script( 'wpforo-contenthover-addons' );
1365 }
1366 }
1367 if( ! wpforo_get_option( 'deactivation_dialog_never_show', false, false ) && ( strpos( wpforo_get_request_uri(), '/plugins.php' ) !== false ) ) {
1368 wp_enqueue_style( 'wpforo-deactivation-css' );
1369 wp_enqueue_script( 'wpforo-deactivation-js' );
1370 }
1371
1372 $screen = get_current_screen();
1373 if( ( 'user-edit' === $screen->id || 'profile' === $screen->id ) ) {
1374 wp_enqueue_style( 'wpforo-font-awesome' );
1375 }
1376
1377 if( $screen->id === 'widgets' ){
1378 wp_enqueue_script( 'wpforo-backend-widgets-js' );
1379 }
1380 }
1381
1382 add_action( 'admin_enqueue_scripts', 'wpforo_admin_enqueue' );
1383
1384 function wpforo_admin_permalink_notice() {
1385 $permalink_structure = get_option( 'permalink_structure' );
1386 if( ! $permalink_structure ) {
1387 $class = 'notice notice-warning';
1388 $message = __( 'IMPORTANT: wpForo can\'t work with default permalink, please change permalink structure', 'wpforo' );
1389 printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
1390 }
1391 }
1392
1393 add_action( 'admin_notices', 'wpforo_admin_permalink_notice' );
1394
1395 function wpforo_userform_to_wpuser_html_form( $wp_user ) {
1396 if( is_super_admin() ) {
1397 $userid = 0;
1398 $groupid = 0;
1399 $timezone = '';
1400 $secondary_groupids = [];
1401 if( is_object( $wp_user ) ) {
1402 $userid = $wp_user->ID;
1403 $user = WPF()->member->get_member( $wp_user->ID );
1404 $groupid = $user['groupid'];
1405 $timezone = sanitize_text_field( $user['timezone'] );
1406 $secondary_groupids = $user['secondary_groupids'];
1407 }
1408 ?>
1409 <style>
1410 #wpf-rating-table {
1411 width: 100%;
1412 font-size: 12px;
1413 }
1414
1415 #wpf-rating-table h4 {
1416 margin: 0;
1417 padding: 0;
1418 font-size: 14px;
1419 font-weight: bold;
1420 white-space: nowrap;
1421 }
1422
1423 #wpf-rating-table .wpf-badge-full {
1424 color: #FFFFFF;
1425 white-space: nowrap;
1426 font-size: 15px;
1427 line-height: 16px;
1428 font-weight: bold;
1429 text-align: center;
1430 display: inline-block;
1431 padding: 2px 8px;
1432 min-width: 30px;
1433 }
1434
1435 #wpf-rating-table .wpf-badge-full.wpf-badge-level-6, #wpf-rating-table .wpf-badge-full.wpf-badge-level-7, #wpf-rating-table .wpf-badge-full.wpf-badge-level-8 {
1436 font-size: 18px !important;
1437 }
1438
1439 #wpf-rating-table .wpf-badge-full.wpf-badge-level-9, #wpf-rating-table .wpf-badge-full.wpf-badge-level-10 {
1440 font-size: 22px !important;
1441 }
1442
1443 #wpf-rating-table th, #wpf-rating-table td {
1444 padding: 5px 10px;
1445 text-align: left;
1446 vertical-align: top;
1447 }
1448
1449 #wpf-rating-table tr:nth-child(odd) {
1450 background: #f5f5f5;
1451 }
1452
1453 #wpf-rating-table tr:nth-child(even) {
1454 background: #FFFFFF;
1455 }
1456
1457 #wpf-rating-table th {
1458 text-transform: uppercase;
1459 font-size: 12px;
1460 padding: 10px;
1461 }
1462
1463 .wpforo-profile-table input[type=checkbox] {
1464 width: auto !important;
1465 }
1466
1467 @media screen and (max-width: 700px) {
1468 #wpf-rating-table th, #wpf-rating-table td {
1469 display: table-cell !important;
1470 }
1471 }
1472 </style>
1473 <h2 style="margin-bottom: 30px; margin-top: 50px;"><?php _e( 'Forum Profile Fields - wpForo' ); ?></h2>
1474 <table class="form-table wpforo-profile-table"
1475 style="box-shadow: 1px 1px 6px #cccccc; background: #f7f7f7; margin-bottom: 30px; width: 97%;">
1476 <tr>
1477 <td colspan="2" style="padding: 5px;"></td>
1478 </tr>
1479 <tr class="form-field">
1480 <th scope="row" style="padding: 10px 20px 10px 20px; width: 30%;">
1481 <label for="wpforo_usergroup">
1482 <?php _e( 'Forum - Usergroup', 'wpforo' ); ?>
1483 </label>
1484 <?php if( wpforo_setting( 'authorization', 'role_synch' ) ): ?>
1485 <p class="description" style="font-weight: normal;">
1486 <?php $wpforo_synch_table = admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) ) ?>
1487 <?php echo sprintf( __( 'Forum Usergroups are synched with User Roles based on the %s. When you change this user Role the Usergroup is automatically changed according to that table.', 'wpforo' ), '<a href="' . $wpforo_synch_table . '" target="_blank">Role-Usergroup synchronization table</a>' ); ?>
1488 </p>
1489 <?php endif; ?>
1490 </th>
1491 <td style="padding: 15px 20px 10px 20px; vertical-align: top;">
1492 <?php if( wpforo_setting( 'authorization', 'role_synch' ) ): ?>
1493 <select id="wpforo_usergroup" disabled="disabled">
1494 <option value="0"><?php _e( 'Synced with user role', 'wpforo' ); ?></option>
1495 <?php WPF()->usergroup->show_selectbox( $groupid ); ?>
1496 </select>
1497 <input type="hidden" name="wpforo_usergroup" value="<?php echo $groupid; ?>">
1498 &nbsp; <span
1499 style="color: green"><?php _e( 'Role-Usergroup Synchronization is Turned ON!', 'wpforo' ); ?></span>
1500 <br/>
1501 <p class="description"
1502 style="font-weight: normal; font-size: 13px; line-height: 18px;"><?php _e( 'This user Usergroup is automatically changed according to current Role. If you want to disable Role-Usergroup synchronization and manage Usergroups and User Roles independently, please navigate to <b>Forums > Settings > Features</b> admin page and disable "Role-Usergroup Synchronization" option.', 'wpforo' ); ?></p>
1503 <?php else: ?>
1504 <select id="wpforo_usergroup"
1505 name="wpforo_usergroup"<?php if( wpforo_is_owner( $userid ) || ! current_user_can( 'administrator' ) ) {
1506 echo ' disabled="disabled"';
1507 } ?>>
1508 <?php WPF()->usergroup->show_selectbox( $groupid ?: WPF()->usergroup->default_groupid ); ?>
1509 </select>
1510 <?php endif; ?>
1511 </td>
1512 </tr>
1513 <tr class="form-field">
1514 <th scope="row" style="padding: 10px 20px 10px 20px;">
1515 <label for="wpforo_usergroup">
1516 <?php _e( 'Forum - Secondary Usergroups', 'wpforo' ); ?>
1517 </label>
1518 </th>
1519 <td style="padding: 15px 20px 10px 20px; vertical-align: top;">
1520 <?php $usergroups = WPF()->usergroup->get_secondary_groups(); ?>
1521 <?php if( ! empty( $usergroups ) ): ?>
1522 <?php foreach( $usergroups as $usergroup ): ?>
1523 <?php if( $usergroup['groupid'] == 1 || $usergroup['groupid'] == 4 ) {
1524 continue;
1525 } //|| $usergroup['groupid'] == $groupid ?>
1526 <label style="min-width: 20%; display: inline-block; padding-bottom: 5px;">
1527 <input type="checkbox"
1528 name="wpforo_secondary_groupids[]"
1529 value="<?php echo intval( $usergroup['groupid'] ) ?>"
1530 <?php checked( in_array( (int) $usergroup['groupid'], (array) $secondary_groupids, true ) ); ?>>&nbsp;
1531 <?php echo esc_html( $usergroup['name'] ); ?>
1532 </label>
1533 <?php endforeach; ?>
1534 <?php endif; ?>
1535 <input name="wpforo_secondary_groupids[]" value="0" type="hidden">
1536 </td>
1537 </tr>
1538 <tr class="form-field">
1539 <th scope="row" style="padding: 10px 20px 10px 20px;">
1540 <label for="wpforo_usertimezone"><?php _e( 'Forum - User Timezone', 'wpforo' ); ?></label>
1541 </th>
1542 <td style="padding: 15px 20px 10px 20px; vertical-align: top;">
1543 <select name="wpforo_usertimezone" id="wpforo_usertimezone">
1544 <?php echo wp_timezone_choice( $timezone ); ?>
1545 </select>
1546 </td>
1547 </tr>
1548 <?php if( ! empty( $user ) ) : ?>
1549 <tr class="form-field">
1550 <th scope="row" style="padding: 10px 20px 10px 20px;">
1551 <label><?php _e( 'User Reputation', 'wpforo' ); ?></label>
1552 <p class="description"
1553 style="font-weight: normal;"><?php _e( 'By default all members get rating badges and titles based on number of posts. However, using this option you can grant lower or higher rating to certain user (this user). The default member reputation badges, titles and points can be managed in Forums > Settings > Members Tab.', 'wpforo' ) ?></p>
1554 </th>
1555 <td style="padding: 15px 20px 10px 20px; vertical-align: top;">
1556 <div style="padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px dashed #cccccc;">
1557 <label><input type="radio" id="wpf-user-rating-default" name="wpforo_use_member_custom_points"
1558 value="0" <?php checked( ! $user['custom_points'] ) ?>> <?php _e( 'Default Rating', 'wpforo' ) ?></label>
1559 &nbsp;&nbsp;
1560 <label><input type="radio" id="wpf-user-rating-custom" name="wpforo_use_member_custom_points"
1561 value="1" <?php checked( $user['custom_points'] ) ?>> <?php _e( 'Custom Rating', 'wpforo' ) ?></label>
1562 </div>
1563
1564 <table id="wpf-rating-table" cellspacing="0" cellpadding="0" border="0"
1565 style="display: block; width: 100%; height: 150px; overflow-y: scroll; hidden; border: 1px solid #ccc; border-top: none; border-bottom: none; <?php if( ! $user['custom_points'] ) echo 'opacity:0.5;' ?>">
1566 <tr>
1567 <th style="text-align: center; width: 5%;">#</th>
1568 <th style="width: 30%"><?php _e( 'Rating Level', 'wpforo' ); ?></th>
1569 <th style="width: 35%"><?php _e( 'Rating Title', 'wpforo' ); ?></th>
1570 <th style="width: 30%;text-align:center;"><?php _e( 'Rating Badge', 'wpforo' ); ?></th>
1571 </tr>
1572 <?php $levels = WPF()->member->levels(); ?>
1573 <?php foreach( $levels as $level ): $points = WPF()->member->rating( $level, 'points' );
1574 $bgx = $level === $user['rating']['level'] ? 'background-color: #feff88' : ''; ?>
1575 <tr>
1576 <td style="text-align: center;<?php echo $bgx ?>"><input type="radio"
1577 name="wpforo_member_custom_points"
1578 id="wpf-user-rating-<?php echo intval( $points ) ?>"
1579 value="<?php echo intval( $points ) ?>" <?php checked( $level === $user['rating']['level'] ) ?>></td>
1580 <td style="<?php echo $bgx ?>"><h4><label
1581 for="wpf-user-rating-<?php echo intval( $points ) ?>"><?php _e( 'Level', 'wpforo' ); ?><?php echo esc_html( $level ) ?></label>
1582 </h4></td>
1583 <td style="<?php echo $bgx ?>"><?php echo WPF()->member->rating( $level, 'title' ) ?></td>
1584 <td style="text-align:center;<?php echo $bgx ?>">
1585 <div class="wpf-badge-full wpf-badge-level-<?php echo esc_attr( $level ) ?>"
1586 style="color:<?php echo WPF()->member->rating( $level, 'color' ) ?>;"><?php echo WPF()->member->rating_badge( $level, 'full' ); ?></div>
1587 </td>
1588 </tr>
1589 <?php endforeach; ?>
1590 </table>
1591 </td>
1592 </tr>
1593 <?php endif; ?>
1594 <tr>
1595 <td colspan="2" style="padding: 5px;"></td>
1596 </tr>
1597 </table>
1598 <script>
1599 jQuery(document).ready(function ($) {
1600 $('#wpf-user-rating-default').change(function () {if (this.checked) {$('#wpf-rating-table').css('opacity', 0.5)}})
1601 $('#wpf-user-rating-custom').change(function () {if (this.checked) { $('#wpf-rating-table').css('opacity', 1)}})
1602 })
1603 </script>
1604 <?php
1605 }
1606 }
1607
1608 add_action( 'user_new_form', 'wpforo_userform_to_wpuser_html_form' );
1609 add_action( 'show_user_profile', 'wpforo_userform_to_wpuser_html_form' );
1610 add_action( 'edit_user_profile', 'wpforo_userform_to_wpuser_html_form' );
1611
1612 add_action( 'register_form', function() {
1613 wp_nonce_field( 'wpforo_user_register', '_wpfnonce' );
1614 }, 21 );
1615
1616 function wpforo_do_hook_user_register( $userid ) {
1617 WPF()->member->synchronize_user( $userid );
1618 if( wpfval( $_POST, 'wpfreg' ) ) {
1619 $data = $_POST;
1620 $data['userid'] = $userid;
1621 $data['wpfreg'] = wpforo_clear_array( $data['wpfreg'], [
1622 'user_login',
1623 'user_email',
1624 'user_pass1',
1625 'user_pass2',
1626 ], 'key' );
1627 WPF()->member->update( $data, 'full', false );
1628 }
1629 }
1630
1631 add_action( 'user_register', 'wpforo_do_hook_user_register', 10, 1 );
1632
1633 function wpforo_do_hook_update_profile( $userid ) {
1634 if( $userid ) {
1635 if( current_user_can( 'create_users' ) || current_user_can( 'edit_user' ) ) {
1636 if( wpfval( $_POST, 'wpforo_usergroup' ) || wpfkey( $_POST, 'wpforo_usertimezone' ) ) {
1637 $member = wpforo_member( $userid );
1638 $can_change_own_rating = true;
1639 if( wpfval( $member, 'userid' ) ) {
1640 $groupid = $member['groupid'];
1641 $secondary_groupids = $member['secondary_groupids'];
1642 if( current_user_can( 'administrator' ) ) {
1643 if( wpfval( $_POST, 'wpforo_usergroup' ) ) {
1644 if( $userid != 1 && ! wpforo_is_owner( $userid ) && current_user_can( 'administrator' ) ) {
1645 $groupid = intval( $_POST['wpforo_usergroup'] );
1646 }
1647 }
1648 if( wpfval( $_POST, 'wpforo_secondary_groupids' ) ) {
1649 if( ! empty( $_POST['wpforo_secondary_groupids'] ) ) {
1650 $secondary_groupids = array_filter( array_map( 'intval', $_POST['wpforo_secondary_groupids'] ) );
1651 }
1652 }
1653 } else {
1654 if( wpforo_is_owner( $userid ) ) {
1655 $can_change_own_rating = false;
1656 }
1657 }
1658
1659 $custom_points = ( $can_change_own_rating && wpfval( $_POST, 'wpforo_use_member_custom_points' ) ) ? (int) wpfval( $_POST, 'wpforo_member_custom_points' ) : 0;
1660
1661 $args = [
1662 'groupid' => intval( $groupid ),
1663 'about' => wpforo_kses( $_POST['description'], 'user_description' ),
1664 'timezone' => ( isset( $_POST['wpforo_usertimezone'] ) ? sanitize_text_field( $_POST['wpforo_usertimezone'] ) : '' ),
1665 'secondary_groupids' => $secondary_groupids,
1666 'custom_points' => $custom_points,
1667 ];
1668 WPF()->member->update_profile_fields( $userid, $args, false );
1669
1670 if( ! wpforo_is_owner( $userid ) ) {
1671 WPF()->member->inactive_to_active( $userid );
1672 }
1673 }
1674 }
1675 }
1676 }
1677 }
1678
1679 add_action( 'personal_options_update', 'wpforo_do_hook_update_profile' );
1680 add_action( 'edit_user_profile_update', 'wpforo_do_hook_update_profile' );
1681
1682 function wpforo_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
1683 if( ! wpforo_setting( 'profiles', 'replace_avatar' ) ) {
1684 return $avatar;
1685 }
1686 $user = false;
1687 if( is_numeric( $id_or_email ) ) {
1688 $id = (int) $id_or_email;
1689 $user = get_user_by( 'id', $id );
1690 } elseif( is_object( $id_or_email ) ) {
1691 if( ! empty( $id_or_email->user_id ) ) {
1692 $id = (int) $id_or_email->user_id;
1693 $user = get_user_by( 'id', $id );
1694 } elseif( ! empty( $id_or_email->ID ) ) {
1695 $id = (int) $id_or_email->ID;
1696 $user = get_user_by( 'id', $id );
1697 }
1698 } else {
1699 $user = get_user_by( 'email', $id_or_email );
1700 }
1701
1702 if( $user && is_object( $user ) ) {
1703 if( $src = WPF()->member->get_avatar_url( $user->data->ID ) ) {
1704 $avatar = "<img alt='" . esc_attr( $alt ) . "' src='" . esc_url( (string) $src ) . "' class='avatar avatar-" . esc_attr( $size ) . " photo' height='" . esc_attr( $size ) . "' width='" . esc_attr( $size ) . "' />";
1705 }
1706 }
1707
1708 return $avatar;
1709 }
1710
1711 add_filter( 'get_avatar', 'wpforo_avatar', 10, 5 );
1712
1713 function wpforo_pre_get_avatar_data( $args, $id_or_email ) {
1714 if( wpforo_setting( 'profiles', 'replace_avatar' ) ) {
1715 $key = [ 'wpforo_pre_get_avatar_data', $id_or_email ];
1716 if( WPF()->ram_cache->exists( $key ) ) {
1717 $args['url'] = WPF()->ram_cache->get( $key );
1718 } else {
1719 $user = false;
1720 if( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
1721 $id_or_email = get_comment( $id_or_email );
1722 }
1723 // Process the user identifier.
1724 if( is_numeric( $id_or_email ) ) {
1725 $user = get_user_by( 'id', absint( $id_or_email ) );
1726 } elseif( is_string( $id_or_email ) ) {
1727 if( ! strpos( (string) $id_or_email, '@md5.gravatar.com' ) ) {
1728 $user = get_user_by( 'email', $id_or_email );
1729 }
1730 } elseif( $id_or_email instanceof WP_User ) {
1731 // User Object
1732 $user = $id_or_email;
1733 } elseif( $id_or_email instanceof WP_Post ) {
1734 // Post Object
1735 $user = get_user_by( 'id', (int) $id_or_email->post_author );
1736 } elseif( function_exists( 'is_avatar_comment_type' ) && $id_or_email instanceof WP_Comment ) {
1737 if( is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
1738 if( ! empty( $id_or_email->user_id ) ) {
1739 $user = get_user_by( 'id', (int) $id_or_email->user_id );
1740 }
1741 if( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) {
1742 $user = get_user_by( 'email', $id_or_email->comment_author_email );
1743 }
1744 }
1745 }
1746
1747 if( $user && is_object( $user ) ) {
1748 if( $avatar_url = WPF()->member->get_avatar_url( $user->data->ID ) ) {
1749 WPF()->ram_cache->set( $key, $avatar_url );
1750 $args['url'] = $avatar_url;
1751 }
1752 }
1753 }
1754 }
1755
1756 return $args;
1757 }
1758
1759 add_filter( 'pre_get_avatar_data', 'wpforo_pre_get_avatar_data', 10, 2 );
1760
1761 function wpforo_move_uploded_default_attach( $argname, $return = 'html' ) {
1762 if( ! empty( $_FILES[ $argname ] ) && ! empty( $_FILES[ $argname ]['name'] ) ) {
1763 $name = sanitize_file_name( $_FILES[ $argname ]['name'] ); //myimg.png
1764 $type = sanitize_mime_type( $_FILES[ $argname ]['type'] ); //image/png
1765 $tmp_name = sanitize_text_field( $_FILES[ $argname ]['tmp_name'] ); //D:\wamp\tmp\php986B.tmp
1766 $error = intval( $_FILES[ $argname ]['error'] ); //0
1767 $size = intval( $_FILES[ $argname ]['size'] ); //6112
1768
1769 $phpFileUploadErrors = [
1770 0 => 'There is no error, the file uploaded with success',
1771 1 => 'The uploaded file size is too big',
1772 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
1773 3 => 'The uploaded file was only partially uploaded',
1774 4 => 'No file was uploaded',
1775 6 => 'Missing a temporary folder',
1776 7 => 'Failed to write file to disk.',
1777 8 => 'A PHP extension stopped the file upload.',
1778 ];
1779
1780 if( $error ) {
1781 WPF()->notice->add( $phpFileUploadErrors[ $error ], 'error' );
1782
1783 return '';
1784 } elseif( $size > wpforo_setting( 'posting', 'max_upload_size' ) ) {
1785 WPF()->notice->add( 'The uploaded file size is too big', 'error' );
1786
1787 return '';
1788 }
1789
1790 if( function_exists( 'pathinfo' ) ) {
1791 $ext = pathinfo( $name, PATHINFO_EXTENSION );
1792 } else {
1793 $ext = substr( strrchr( (string) $name, '.' ), 1 );
1794 }
1795 $ext = strtolower( (string) $ext );
1796 $mime_types = get_allowed_mime_types();
1797 $mime_types = array_flip( $mime_types );
1798 if( ! empty( $mime_types ) ) {
1799 $allowed_types = implode( '|', $mime_types );
1800 $expld = explode( '|', $allowed_types );
1801 if( ! in_array( $ext, $expld ) ) {
1802 WPF()->notice->add( 'File type is not allowed', 'error' );
1803
1804 return '';
1805 }
1806 if( ! WPF()->perm->can_attach_file_type( $ext ) ) {
1807 WPF()->notice->add( 'You are not allowed to attach this file type', 'error' );
1808
1809 return '';
1810 }
1811 }
1812
1813 $attach_dir = WPF()->folders['default_attachments']['dir'];
1814 $attach_url = WPF()->folders['default_attachments']['url//'];
1815 if( ! is_dir( $attach_dir ) ) wp_mkdir_p( $attach_dir );
1816
1817 $fnm = pathinfo( $name, PATHINFO_FILENAME );
1818 $fnm = str_replace( ' ', '-', $fnm );
1819 while( strpos( (string) $fnm, '--' ) !== false ) {
1820 $fnm = str_replace( '--', '-', $fnm );
1821 }
1822 $fnm = preg_replace( "/[^-a-zA-Z0-9_]/", "", (string) $fnm );
1823 $fnm = trim( (string) $fnm, "-" );
1824 $fnm_empty = ! $fnm;
1825
1826 $file_name = $fnm . "." . $ext;
1827
1828 $attach_fname = time() . ( ! $fnm_empty ? '-' : '' ) . $file_name;
1829 $attach_path = $attach_dir . DIRECTORY_SEPARATOR . $attach_fname;
1830
1831 if( is_dir( $attach_dir ) && move_uploaded_file( $tmp_name, $attach_path ) ) {
1832 $attach_id = wpforo_insert_to_media_library( $attach_path, $fnm );
1833 if( $return === 'html' ) {
1834 return "\r\n" . '<div id="wpfa-' . $attach_id . '" class="wpforo-attached-file"><a class="wpforo-default-attachment" href="' . esc_url( (string) $attach_url . '/' . $attach_fname ) . '" target="_blank" title="' . esc_attr( basename( (string) $name ) ) . '"><i class="fas fa-paperclip"></i>&nbsp;' . esc_html( basename( (string) $name ) ) . '</a></div>';
1835 } else {
1836 return [
1837 'fileurl' => $attach_url . '/' . $attach_fname,
1838 'filename' => basename( (string) $name ),
1839 'mediaid' => $attach_id,
1840 ];
1841 }
1842 } else {
1843 WPF()->notice->add( 'Can\'t upload file', 'error' );
1844 }
1845 }
1846
1847 return '';
1848 }
1849
1850 function wpforo_add_default_attachment( $args ) {
1851 if( ! empty( $_FILES['attachfile'] ) && ! empty( $_FILES['attachfile']['name'] ) ) {
1852 if( WPF()->perm->can_attach( wpfval( $args, 'forumid' ) ) ) {
1853 if( $default_attach = wpforo_move_uploded_default_attach( 'attachfile' ) ) {
1854 $args['body'] .= $default_attach;
1855 $args['has_attach'] = 1;
1856 }
1857 }
1858 }
1859
1860 return $args;
1861 }
1862
1863 function wpforo_delete_attachment( $attach_post_id ) {
1864 if( ! $attach_post_id ) {
1865 return;
1866 }
1867 $posts = WPF()->db->get_results( "SELECT `postid`, `body` FROM `" . WPF()->tables->posts . "` WHERE `body` LIKE '%wpfa-" . intval( $attach_post_id ) . "%'", ARRAY_A );
1868 if( ! empty( $posts ) || is_array( $posts ) ) {
1869 foreach( $posts as $post ) {
1870 $body = preg_replace( '|<div[^><]*id=[\'\"]+wpfa-' . $attach_post_id . '[\'\"]+[^><]*>.+?</div>|is', '<div class="wpforo-attached-file wpfa-deleted">' . wpforo_phrase( 'Attachment removed', false ) . '</div>', (string) $post['body'] );
1871 if( $body ) {
1872 WPF()->db->query( "UPDATE `" . WPF()->tables->posts . "` SET `body` = '" . esc_sql( $body ) . "' WHERE `postid` = " . intval( $post['postid'] ) );
1873 }
1874 }
1875 }
1876 }
1877
1878 function wpforo_default_attachments_filter( $text ) {
1879 if( preg_match_all( '#<a[^<>]*class=[\'"]wpforo-default-attachment[\'"][^<>]*href=[\'"]([^\'"]+)[\'"][^<>]*>[\r\n\t\s\0]*(?:<i[^<>]*>[\r\n\t\s\0]*</i>[\r\n\t\s\0]*)?([^<>]*)</a>#iu', (string) $text, $matches, PREG_SET_ORDER ) ) {
1880 foreach( $matches as $match ) {
1881 $attach_html = '';
1882 if( file_exists( wpforo_fix_upload_dir( $match[1] ) ) ) {
1883 if( ! WPF()->perm->forum_can( 'va' ) || ! WPF()->usergroup->can( 'caa' ) ) {
1884 $attach_html .= '<br/><div class="wpfa-item wpfa-file"><a class="attach_cant_view" style="cursor: pointer;"><span style="color: #666;">' . wpforo_phrase( 'Attachment', false ) . ' : </span> ' . urldecode( basename( $match[2] ) ) . '</a></div>';
1885 }
1886 }
1887 if( $attach_html ) {
1888 $attach_html .= '<br/>';
1889 $text = str_replace( $match[0], $attach_html, $text );
1890 }
1891 }
1892 }
1893
1894 return $text;
1895 }
1896
1897 function wpforo_content_enable_do_shortcode() {
1898 if( wpforo_setting( 'posting', 'content_do_shortcode' ) ) {
1899 add_filter( 'wpforo_content_after', 'do_shortcode', 20 );
1900 }
1901 }
1902
1903 add_action( 'wpforo_after_init', 'wpforo_content_enable_do_shortcode' );
1904
1905 add_filter( 'wpforo_content_after', function( $text ) {
1906 return wpforo_strip_shortcodes( $text, true );
1907 }, 999 );
1908
1909 add_filter( 'wpforo_body_text_filter', function( $text ) {
1910 if( apply_filters( 'wpforo_allow_replace_3asterisk', true ) ) {
1911 $text = preg_replace( '#\*{3}([^*]+?)\*{3}#', '<span style="color: red; font-weight: bold;">$1</span>', (string) $text );
1912 }
1913
1914 return $text;
1915 } );
1916
1917 add_action( 'wp_footer', function() { WPF()->cache->create(); } );
1918
1919 add_filter( 'retrieve_password_message', function( $message, $key, $user_login, $user_data ) {
1920 $reset_password_url = '';
1921 if( preg_match( wpforo_get_wprp_url_pattern(), (string) $message, $match ) ) {
1922 if( wpforo_setting( 'authorization', 'use_our_lostpassword_url' ) ) {
1923 $reset_password_url = wpforo_resetpassword_url( $key, $user_login );
1924 $message = str_replace( $match[0], $reset_password_url, $message );
1925 } else {
1926 $reset_password_url = $match[0];
1927 }
1928 }
1929
1930 if( wpforo_setting( 'email', 'overwrite_reset_password_email' ) && $reset_password_url ) {
1931 $message = str_replace(
1932 [ '[user_login]', '[reset_password_url]' ],
1933 [ $user_login, $reset_password_url, ],
1934 wpforo_setting( 'email', 'reset_password_email_message' )
1935 );
1936 $message = _wpforo_apply_email_shortcodes( $message, [ 'user' => [ 'userid' => $user_data->ID ] ] );
1937 add_filter( 'wp_mail_content_type', '__wpforo_set_html_content_type', 999 );
1938 }
1939
1940 return $message;
1941 }, 999, 4 );
1942
1943 function wpforo_user_field_shortcode_to_value( $shortcode, $userid = null, $implode = true, $separator = ',' ) {
1944 $value = null;
1945
1946 if( $shortcode && ($field = preg_replace( '#^\s*\[?\s*(?:user_|owner_)?(?:fields_)?([^\[\]]+?)\s*]?\s*$#iu', '$1', (string) $shortcode )) ) {
1947 if( ! $userid ) $userid = WPF()->current_userid;
1948 if( in_array( $field, ['login','pass','nicename','email','url','registered','activation_key','status'], true ) ) $field = 'user_' . $field;
1949 $value = wpforo_member( $userid, $field );
1950 if( $implode && wpforo_is_array_of_scalars( $value ) ) $value = implode( $separator, $value );
1951 }
1952
1953 return $value;
1954 }
1955
1956 function wpforo_forum_field_shortcode_to_value( $shortcode, $forumid, $implode = true, $separator = ',' ) {
1957 $value = null;
1958
1959 if( $forumid ){
1960 if( $shortcode && ($field = preg_replace( '#^\s*\[?\s*(?:forum_)?(?:fields_)?([^\[\]]+?)\s*]?\s*$#iu', '$1', (string) $shortcode )) ) {
1961 if( $field === 'link' ){
1962 $value = sprintf( '<a target="_blank" href="%1$s">%2$s</a>', esc_url( (string) _wpforo_forum( $forumid, 'url' ) ), sanitize_text_field( _wpforo_forum( $forumid, 'title' ) ) );
1963 $value = stripslashes( (string) $value );
1964 }else{
1965 $value = _wpforo_forum( $forumid, $field );
1966 if( $implode && wpforo_is_array_of_scalars( $value ) ) $value = implode( $separator, $value );
1967 }
1968 }
1969 }
1970
1971 return $value;
1972 }
1973
1974 function wpforo_topic_field_shortcode_to_value( $shortcode, $topicid, $implode = true, $separator = ',' ) {
1975 $value = null;
1976
1977 if( $topicid ){
1978 if( $shortcode && ($field = preg_replace( '#^\s*\[?\s*(?:topic_)?(?:fields_)?([^\[\]]+?)\s*]?\s*$#iu', '$1', (string) $shortcode )) ) {
1979 if( $field === 'link' ){
1980 $value = sprintf( '<a target="_blank" href="%1$s">%2$s</a>', esc_url( (string) _wpforo_topic( $topicid, 'url' ) ), sanitize_text_field( _wpforo_topic( $topicid, 'title' ) ) );
1981 $value = stripslashes( $value );
1982 }else{
1983 $value = _wpforo_topic( $topicid, $field );
1984 if( $implode && wpforo_is_array_of_scalars( $value ) ) $value = implode( $separator, $value );
1985 }
1986 }
1987 }
1988
1989 return $value;
1990 }
1991
1992 function wpforo_post_field_shortcode_to_value( $shortcode, $postid, $implode = true, $separator = ',' ) {
1993 $value = null;
1994
1995 if($postid ){
1996 if( $shortcode && ($field = preg_replace( '#^\s*\[?\s*(?:post_)?(?:fields_)?([^\[\]]+?)\s*]?\s*$#iu', '$1', (string) $shortcode )) ) {
1997 if( $field === 'link' ){
1998 $value = sprintf( '<a target="_blank" href="%1$s">%2$s</a>', esc_url( (string) _wpforo_post( $postid, 'url' ) ), sanitize_text_field( _wpforo_post( $postid, 'title' ) ) );
1999 $value = stripslashes( $value );
2000 }else{
2001 $value = _wpforo_post( $postid, $field );
2002 if( $implode && wpforo_is_array_of_scalars( $value ) ) $value = implode( $separator, $value );
2003 }
2004 }
2005 }
2006
2007 return $value;
2008 }
2009
2010 function wpforo_new_user_notification_email_admin( $wp_new_user_notification_email_admin, $user, $blogname ) {
2011 if( wpforo_setting( 'email', 'overwrite_new_user_notification_admin' ) ) {
2012 $wp_new_user_notification_email_admin['subject'] = str_replace( '[blogname]', '[' . $blogname . ']', wpforo_setting( 'email', 'wp_new_user_notification_email_admin_subject' ) );
2013 $wp_new_user_notification_email_admin['message'] = str_replace( '[blogname]', $blogname, wpforo_setting( 'email', 'wp_new_user_notification_email_admin_message' ) );
2014 add_filter( 'wp_mail_content_type', '__wpforo_set_html_content_type', 999 );
2015 }
2016 $userid = $user->ID;
2017 $wp_new_user_notification_email_admin['message'] = preg_replace_callback( '#\[[^\[\]]+?]#isu', function( $match ) use ( $userid ) {
2018 $value = wpforo_user_field_shortcode_to_value( $match[0], $userid );
2019 if( ! $value || ! ( is_string( $value ) || is_numeric( $value ) ) ) $value = '';
2020 return $value;
2021 }, (string) $wp_new_user_notification_email_admin['message'] );
2022
2023 return $wp_new_user_notification_email_admin;
2024 }
2025
2026 add_filter( 'wp_new_user_notification_email_admin', 'wpforo_new_user_notification_email_admin', 999, 3 );
2027
2028 function wpforo_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
2029 $set_password_url = '';
2030 if( preg_match( wpforo_get_wprp_url_pattern(), (string) $wp_new_user_notification_email['message'], $match ) ) {
2031 if( wpforo_setting( 'authorization', 'use_our_lostpassword_url' ) ) {
2032 $set_password_url = wpforo_resetpassword_url( $match['key'], $user->user_login );
2033 $wp_new_user_notification_email['message'] = str_replace( $match[0], $set_password_url, $wp_new_user_notification_email['message'] );
2034 } else {
2035 $set_password_url = $match[0];
2036 }
2037 }
2038
2039 if( wpforo_setting( 'email', 'overwrite_new_user_notification' ) && $set_password_url ) {
2040 $wp_new_user_notification_email['subject'] = str_replace( '[blogname]', '[' . $blogname . ']', wpforo_setting( 'email', 'wp_new_user_notification_email_subject' ) );
2041 $wp_new_user_notification_email['message'] = str_replace(
2042 [ '[user_login]', '[set_password_url]' ],
2043 [ $user->user_login, $set_password_url ],
2044 wpforo_setting( 'email', 'wp_new_user_notification_email_message' )
2045 );
2046 add_filter( 'wp_mail_content_type', '__wpforo_set_html_content_type', 999 );
2047 }
2048
2049 return $wp_new_user_notification_email;
2050 }
2051
2052 add_filter( 'wp_new_user_notification_email', 'wpforo_new_user_notification_email', 999, 3 );
2053
2054 function wpforo_get_wprp_url_pattern() {
2055 return '#(?:<\s*)?https?://\S+?wp-login\.php\?action=rp&key=(?<key>[^?&=\s]+)\S+(?:\s*>)?#isu';
2056 }
2057
2058 function wpforo_synch_user_roles( $userid ) {
2059
2060 $user = get_userdata( $userid );
2061
2062 if( ! empty( $user ) && !empty( $user->roles ) ) {
2063 $role_usergroups = WPF()->usergroup->get_role_usergroup_relation();
2064
2065 if( !empty( $role_usergroups ) ){
2066 $append_second_groups = apply_filters( 'wpforo_synch_user_roles_append_secondary_groups', false );
2067 $ug_users_array = WPF()->usergroup->build_users_groupid_array( $role_usergroups, [ $user ] );
2068
2069 if( wpfval( $ug_users_array, 'user_prime_group' ) ) {
2070 $userid_groupids = current( $ug_users_array['user_prime_group'] );
2071 if( !empty( $userid_groupids ) ){
2072 $groupid = current( $userid_groupids );
2073 if( $groupid ) WPF()->member->set_groupid( $userid, $groupid );
2074 }
2075 }
2076
2077 if( wpfval( $ug_users_array, 'user_second_groups' ) ) {
2078 foreach ( $ug_users_array['user_second_groups'] as $userid => $secondary_usergroups ){
2079 if( !empty($secondary_usergroups) ){
2080 if( $append_second_groups ){
2081 // Merges current secondary groups with new secondary groups
2082 WPF()->member->append_secondary_groupids( $userid, $secondary_usergroups );
2083 } else {
2084 // Removes current secondary groups and sets new secondary groups
2085 WPF()->member->set_secondary_groupids( $userid, $secondary_usergroups );
2086 }
2087 }
2088 }
2089 } elseif( ! $append_second_groups && !wpfval( $ug_users_array, 'user_second_groups' ) ){
2090 WPF()->member->set_secondary_groupids( $userid, [] );
2091 }
2092
2093 delete_user_meta( intval( $userid ), '_wpf_member_obj' );
2094 }
2095 }
2096 }
2097
2098
2099 function wpforo_synch_roles() {
2100 $status = [
2101 'progress' => 0,
2102 'error' => 0,
2103 'start' => 0,
2104 'step' => 1,
2105 'left' => 0,
2106 'total' => 0,
2107 'id' => 0,
2108 ];
2109
2110 $wpforo_synch_roles_data = isset( $_POST['wpforo_synch_roles_data'] ) ? $_POST['wpforo_synch_roles_data'] : '';
2111
2112 if( $wpforo_synch_roles_data ) {
2113 parse_str( $wpforo_synch_roles_data, $data );
2114 check_ajax_referer( 'wpforo_synch_roles', 'checkthis' );
2115 $limit = apply_filters( 'wpforo_synch_roles_step_limit', 20 );
2116 $append_second_groups = apply_filters( 'wpforo_synch_roles_append_secondary_groups', true );
2117 $success = false;
2118 $group_users = [];
2119 $user_prime_group = [];
2120 $user_second_groups = [];
2121 $options = wpforo_get_option( 'synch_roles' );
2122 $step = isset( $data['wpf-step'] ) ? intval( $data['wpf-step'] ) : 1;
2123 $left = isset( $data['wpf-left-users'] ) ? intval( $data['wpf-left-users'] ) : 0;
2124 $id = isset( $data['wpf-start-id'] ) ? intval( $data['wpf-start-id'] ) : 0;
2125 $start = isset( $data['wpf-start'] ) ? intval( $data['wpf-start'] ) : 0;
2126 $ug_role = isset( $data['wpf_synch_roles'] ) ? $data['wpf_synch_roles'] : [];
2127 if( ! empty( $ug_role ) ) {
2128 /////////////////////////////////////////////////////
2129 /// Update Roles of Usergroups in usergroups table
2130 WPF()->usergroup->set_ug_roles( $ug_role );
2131 /////////////////////////////////////////////////////
2132 if( ! is_array( $options ) || $left > 0 ) {
2133 $args = [ 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $start, 'number' => $limit ];
2134 $users = get_users( $args );
2135 ////////////////////////////////////////////////////////////////////////////////////
2136 /// Builds associative array of Usergroup ID => Users ID array()
2137 $ug_users_array = WPF()->usergroup->build_users_groupid_array( $ug_role, $users );
2138 ////////////////////////////////////////////////////////////////////////////////////
2139 if( wpfval( $ug_users_array, 'group_users' ) ) {
2140 $group_users = $ug_users_array['group_users'];
2141 }
2142 if( wpfval( $ug_users_array, 'user_prime_group' ) ) {
2143 $user_prime_group = $ug_users_array['user_prime_group'];
2144 }
2145 if( wpfval( $ug_users_array, 'user_second_groups' ) ) {
2146 foreach ( $ug_users_array['user_second_groups'] as $userid => $secondary_usergroups ){
2147 if( !empty($secondary_usergroups) ){
2148 if( $append_second_groups ){
2149 // Merges current secondary groups with new secondary groups
2150 WPF()->member->append_secondary_groupids( $userid, $secondary_usergroups );
2151 } else {
2152 // Removes current secondary groups and sets new secondary groups
2153 WPF()->member->set_secondary_groupids( $userid, $secondary_usergroups );
2154 }
2155 }
2156 }
2157 }
2158 if( ! empty( $group_users ) ) {
2159 /////////////////////////////////////////////////////////////////
2160 /// Updates users Usergroup Ids in profiles table
2161 $return = WPF()->usergroup->set_users_groupid( $group_users );
2162 /////////////////////////////////////////////////////////////////
2163 $success = ( wpfval( $return, 'success' ) ) ? $return['success'] : $success;
2164 $status['error'] = ( wpfval( $return, 'error' ) ) ? $return['error'] : $status['error'];
2165 if( $success ) {
2166 end( $users );
2167 $key = key( $users );
2168 $status['id'] = $users[ $key ]->ID;
2169 $result = count_users();
2170 $status['total'] = ( wpfval( $result, 'total_users' ) ) ? intval( $result['total_users'] ) : 0;
2171 $status['start'] = $step * $limit;
2172 $status['left'] = ( $status['total'] > $status['start'] ) ? ( $status['total'] - $status['start'] ) : 0;
2173 $status['step'] = $step + 1;
2174 $progress = ( $status['total'] > $status['start'] ) ? ( $status['start'] * 100 ) / $status['total'] : 100;
2175 $status['progress'] = round( $progress );
2176 if( $progress == 100 ) {
2177 wpforo_delete_option( 'synch_roles' );
2178 } else {
2179 wpforo_update_option( 'synch_roles', $status );
2180 }
2181 }
2182 } else {
2183 $status['total'] = 0;
2184 $status['start'] = 0;
2185 $status['left'] = 0;
2186 $status['step'] = 1;
2187 $status['progress'] = 100;
2188 wpforo_delete_option( 'synch_roles' );
2189 }
2190 } else {
2191 $result = count_users();
2192 $status['total'] = ( wpfval( $result, 'total_users' ) ) ? intval( $result['total_users'] ) : 0;
2193 $status['start'] = $step * $limit;
2194 $status['left'] = 0;
2195 $status['step'] = 1;
2196 $status['progress'] = 100;
2197 wpforo_delete_option( 'synch_roles' );
2198 }
2199 }
2200 }
2201
2202 if( intval( wpfval( $status, 'progress' ) ) === 100 ) {
2203 WPF()->notice->add( 'Role-Usergroup synchronization is complete!', 'success' );
2204 }
2205
2206 wp_die( json_encode( $status ) );
2207 }
2208 add_action( 'wp_ajax_wpforo_synch_roles', 'wpforo_synch_roles' );
2209
2210
2211 function wpforo_update_usergroup_on_role_change( $userid, $new_role, $old_roles = [] ) {
2212 if( wpforo_setting( 'authorization', 'role_synch' ) ) {
2213 wpforo_synch_user_roles( $userid );
2214 }
2215 }
2216 add_action( 'add_user_role', 'wpforo_update_usergroup_on_role_change', 99, 2 );
2217 add_action( 'set_user_role', 'wpforo_update_usergroup_on_role_change', 99, 3 );
2218
2219
2220
2221 function wpforo_wp_admin_bar_red_circle_number( $number ){
2222 $number = intval( $number );
2223 if( $number ){
2224 return sprintf(
2225 '<div class="wp-core-ui wp-ui-notification wpforo-menu-notification-counter">%1$d</div>',
2226 $number
2227 );
2228 }
2229
2230 return '';
2231 }
2232
2233 function wpforo_get_memb_attention_count(): int {
2234 return WPF()->member->get_count( [ 'p.status' => ['banned','inactive'] ] );
2235 }
2236
2237 function wpforo_get_admin_bar_numbers(): array {
2238 $all_count = 0;
2239 $mod_count = WPF()->post->unapproved_count();
2240 $all_count += $mod_count;
2241
2242 return compact( 'all_count', 'mod_count' );
2243 }
2244
2245 function wpforo_admin_bar_menu( $wp_admin_bar ){
2246 $admin_bar_numbers = wpforo_get_admin_bar_numbers();
2247
2248 if( wpforo_current_user_is( 'admin' ) ) {
2249 $args = [
2250 'id' => 'new-forum',
2251 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Forum', 'wpforo' ),
2252 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) . '&action=add' ),
2253 'parent' => 'new-content',
2254 ];
2255 $wp_admin_bar->add_node( $args );
2256 $args = [
2257 'id' => 'new-ugroup',
2258 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New User Group', 'wpforo' ),
2259 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) . '&wpfaction=wpforo_usergroup_save_form' ),
2260 'parent' => 'new-content',
2261 ];
2262 $wp_admin_bar->add_node( $args );
2263 $args = [
2264 'id' => 'new-phrase',
2265 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Phrase', 'wpforo' ),
2266 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) . '&wpfaction=phrase_add_form' ),
2267 'parent' => 'new-content',
2268 ];
2269 $wp_admin_bar->add_node( $args );
2270 }
2271
2272 $args = [
2273 'id' => 'wpforo-home',
2274 'title' => __( 'Visit Forum', 'wpforo' ),
2275 'href' => wpforo_home_url(),
2276 'parent' => 'wpf-community',
2277 // 'meta' => [ 'target' => '_blank' ]
2278 ];
2279 $wp_admin_bar->add_node( $args );
2280
2281 if( wpforo_current_user_is( 'admin' ) || WPF()->usergroup->can( 'mf' ) || WPF()->usergroup->can( 'ms' ) || WPF()->usergroup->can( 'vm' ) || WPF()->usergroup->can( 'mp' ) || WPF()->usergroup->can( 'aum' ) || WPF()->usergroup->can( 'vmg' ) || WPF()->usergroup->can( 'mth' ) ) {
2282 $args = [
2283 'id' => 'wpf-community',
2284 'title' => __( 'Forum Dashboard', 'wpforo' ) . wpforo_wp_admin_bar_red_circle_number($admin_bar_numbers['all_count']),
2285 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ),
2286 ];
2287 $wp_admin_bar->add_node( $args );
2288 }
2289 if( WPF()->usergroup->can( 'mf' ) || wpforo_current_user_is( 'admin' ) ) {
2290 $args = [
2291 'id' => 'wpf-forums',
2292 'title' => '&#9776;&nbsp;&nbsp;' . __( 'Forums', 'wpforo' ),
2293 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) ),
2294 'parent' => 'wpf-community',
2295 ];
2296 $wp_admin_bar->add_node( $args );
2297 $args = [
2298 'id' => 'wpf-new-forum',
2299 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Forum', 'wpforo' ),
2300 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) . '&action=add' ),
2301 'parent' => 'wpf-forums',
2302 ];
2303 $wp_admin_bar->add_node( $args );
2304 }
2305 if( WPF()->usergroup->can( 'ms' ) || wpforo_current_user_is( 'admin' ) ) {
2306 $args = [
2307 'id' => 'wpf-settings',
2308 'title' => '&#9881;&nbsp;&nbsp;' . __( 'Settings', 'wpforo' ),
2309 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'settings' ) ),
2310 'parent' => 'wpf-community',
2311 ];
2312 $wp_admin_bar->add_node( $args );
2313 }
2314 if( WPF()->usergroup->can( 'mt' ) || wpforo_current_user_is( 'admin' ) ) {
2315 $args = [
2316 'id' => 'wpf-tools',
2317 'title' => '&#128295;&nbsp;&nbsp;' . __( 'Tools', 'wpforo' ),
2318 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) ),
2319 'parent' => 'wpf-community',
2320 ];
2321 $wp_admin_bar->add_node( $args );
2322 }
2323 if( WPF()->usergroup->can( 'aum' ) || wpforo_current_user_is( 'admin' ) ) {
2324 $args = [
2325 'id' => 'wpf-moderation',
2326 'title' => '&#128479;&nbsp;&nbsp;' . __( 'Moderation', 'wpforo' ) . wpforo_wp_admin_bar_red_circle_number($admin_bar_numbers['mod_count']),
2327 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'moderations' ) ),
2328 'parent' => 'wpf-community',
2329 ];
2330 $wp_admin_bar->add_node( $args );
2331 }
2332 if( WPF()->usergroup->can( 'ms' ) || wpforo_current_user_is( 'admin' ) ) {
2333 $args = [
2334 'id' => 'wpforo-accesses',
2335 'title' => '&#33;&nbsp;&nbsp;' . __( 'Accesses', 'wpforo' ),
2336 'href' => admin_url( 'admin.php?page=wpforo-accesses' ),
2337 'parent' => 'wpf-community',
2338 ];
2339 $wp_admin_bar->add_node( $args );
2340 $args = [
2341 'id' => 'wpforo-new-accesses',
2342 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Forum Access', 'wpforo' ),
2343 'href' => admin_url( 'admin.php?page=wpforo-accesses&wpfaction=wpforo_access_save_form' ),
2344 'parent' => 'wpforo-accesses',
2345 ];
2346 $wp_admin_bar->add_node( $args );
2347 }
2348 if( WPF()->usergroup->can( 'vm' ) || wpforo_current_user_is( 'admin' ) ) {
2349 $args = [
2350 'id' => 'wpf-members',
2351 'title' => '&#128100;&nbsp;&nbsp;' . __( 'Members', 'wpforo' ) . wpforo_wp_admin_bar_red_circle_number(wpforo_get_memb_attention_count()),
2352 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'members' ) ),
2353 'parent' => 'wpf-community',
2354 ];
2355 $wp_admin_bar->add_node( $args );
2356 }
2357 if( WPF()->usergroup->can( 'vmg' ) || wpforo_current_user_is( 'admin' ) ) {
2358 $args = [
2359 'id' => 'wpf-usergroups',
2360 'title' => '&#128101;&nbsp;&nbsp;' . __( 'Usergroups', 'wpforo' ),
2361 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) ),
2362 'parent' => 'wpf-community',
2363 ];
2364 $wp_admin_bar->add_node( $args );
2365 $args = [
2366 'id' => 'wpf-new-ugroup',
2367 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Usergroup', 'wpforo' ),
2368 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) . '&wpfaction=wpforo_usergroup_save_form' ),
2369 'parent' => 'wpf-usergroups',
2370 ];
2371 $wp_admin_bar->add_node( $args );
2372 }
2373 if( WPF()->usergroup->can( 'mp' ) || wpforo_current_user_is( 'admin' ) ) {
2374 $args = [
2375 'id' => 'wpf-phrases',
2376 'title' => '&#9873;&nbsp;&nbsp;' . __( 'Phrases', 'wpforo' ),
2377 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) ),
2378 'parent' => 'wpf-community',
2379 ];
2380 $wp_admin_bar->add_node( $args );
2381 $args = [
2382 'id' => 'wpf-new-phrase',
2383 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Phrase', 'wpforo' ),
2384 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) . '&wpfaction=phrase_add_form' ),
2385 'parent' => 'wpf-phrases',
2386 ];
2387 $wp_admin_bar->add_node( $args );
2388 }
2389 if( WPF()->usergroup->can( 'mth' ) || wpforo_current_user_is( 'admin' ) ) {
2390 $args = [
2391 'id' => 'wpf-themes',
2392 'title' => '&#127912;&nbsp;&nbsp;' . __( 'Themes', 'wpforo' ),
2393 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'themes' ) ),
2394 'parent' => 'wpf-community',
2395 ];
2396 $wp_admin_bar->add_node( $args );
2397 }
2398 if( wpforo_current_user_is( 'admin' ) ) {
2399 $args = [
2400 'id' => 'wpf-addons',
2401 'title' => '&#128268;&nbsp;&nbsp;' . __( 'Addons', 'wpforo' ),
2402 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'addons' ) ),
2403 'parent' => 'wpf-community',
2404 ];
2405 $wp_admin_bar->add_node( $args );
2406 }
2407 }
2408
2409 function wpforo_multiboard_admin_bar_menu( $wp_admin_bar ){
2410 $bds_bar_numbers = [];
2411 if( wpforo_current_user_is( 'admin' ) ) {
2412 $args = [
2413 'id' => 'wpforo-new-content',
2414 'title' => 'wpForo',
2415 'href' => admin_url( 'admin.php?page=wpforo-overview' ),
2416 'parent' => 'new-content',
2417 ];
2418 $wp_admin_bar->add_node( $args );
2419
2420 if( $boardids = WPF()->board->get_active_boardids() ){
2421 foreach( $boardids as $boardid ){
2422 WPF()->change_board( $boardid );
2423 $current = WPF()->board->get_current();
2424 $bds_bar_numbers[ $boardid ] = wpforo_get_admin_bar_numbers();
2425
2426 $menuid = 'wpforo-new-content-' . $current['slug'];
2427 $args = [
2428 'id' => $menuid,
2429 'title' => $current['title'],
2430 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ),
2431 'parent' => 'wpforo-new-content',
2432 ];
2433 $wp_admin_bar->add_node( $args );
2434 ## ---------------------------------------------------------------------------------- ####
2435 $args = [
2436 'id' => $menuid . 'new-forum',
2437 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Forum', 'wpforo' ),
2438 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) . '&action=add' ),
2439 'parent' => $menuid,
2440 ];
2441 $wp_admin_bar->add_node( $args );
2442 $args = [
2443 'id' => $menuid . 'new-ugroup',
2444 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New User Group', 'wpforo' ),
2445 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'usergroups' ) . '&wpfaction=wpforo_usergroup_save_form' ),
2446 'parent' => $menuid,
2447 ];
2448 $wp_admin_bar->add_node( $args );
2449 $args = [
2450 'id' => $menuid . 'new-phrase',
2451 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Phrase', 'wpforo' ),
2452 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) . '&wpfaction=phrase_add_form' ),
2453 'parent' => $menuid,
2454 ];
2455 $wp_admin_bar->add_node( $args );
2456
2457 }
2458 }
2459 }
2460
2461 if( wpforo_current_user_is( 'admin' ) || WPF()->usergroup->can( 'mf' ) || WPF()->usergroup->can( 'ms' ) || WPF()->usergroup->can( 'vm' ) || WPF()->usergroup->can( 'mp' ) || WPF()->usergroup->can( 'aum' ) || WPF()->usergroup->can( 'vmg' ) || WPF()->usergroup->can( 'mth' ) ) {
2462 $bds_bar_all = 0;
2463 foreach ( $bds_bar_numbers as $x ) $bds_bar_all += $x['all_count'];
2464 $args = [
2465 'id' => 'wpforo',
2466 'title' => 'wpForo' . wpforo_wp_admin_bar_red_circle_number( $bds_bar_all ),
2467 'href' => admin_url( 'admin.php?page=wpforo-overview' ),
2468 ];
2469 $wp_admin_bar->add_node( $args );
2470
2471
2472 if( $boardids = WPF()->board->get_active_boardids() ){
2473 foreach( $boardids as $boardid ){
2474 WPF()->change_board( $boardid );
2475 $current = WPF()->board->get_current();
2476
2477 $menuid = 'wpforo-' . $current['slug'];
2478 $args = [
2479 'id' => $menuid,
2480 'title' => '&#128489;&nbsp;&nbsp;' . $current['title'] . ' (' . strtok( $current['locale'], '_' ) . ')' . wpforo_wp_admin_bar_red_circle_number( $bds_bar_numbers[$boardid]['all_count'] ),
2481 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) ),
2482 'parent' => 'wpforo',
2483 ];
2484 $wp_admin_bar->add_node( $args );
2485
2486 ## ---------------------------------------------------------------------------------- ####
2487
2488 $args = [
2489 'id' => $menuid . '-home',
2490 'title' => '&#128279;&nbsp;' . __( 'Visit Forum', 'wpforo' ),
2491 'href' => wpforo_home_url(),
2492 'parent' => $menuid,
2493 // 'meta' => [ 'target' => '_blank' ]
2494 ];
2495 $wp_admin_bar->add_node( $args );
2496
2497 if( WPF()->usergroup->can( 'mf' ) || wpforo_current_user_is( 'admin' ) ) {
2498 $args = [
2499 'id' => $menuid . '-forums',
2500 'title' => '&#9776;&nbsp;&nbsp;' . __( 'Forums', 'wpforo' ),
2501 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) ),
2502 'parent' => $menuid,
2503 ];
2504 $wp_admin_bar->add_node( $args );
2505 $args = [
2506 'id' => $menuid . '-new-forum',
2507 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Forum', 'wpforo' ),
2508 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'forums' ) . '&action=add' ),
2509 'parent' => $menuid . '-forums',
2510 ];
2511 $wp_admin_bar->add_node( $args );
2512 }
2513 if( WPF()->usergroup->can( 'ms' ) || wpforo_current_user_is( 'admin' ) ) {
2514 $args = [
2515 'id' => $menuid . '-settings',
2516 'title' => '&#9881;&nbsp;&nbsp;' . __( 'Settings', 'wpforo' ),
2517 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'settings' ) ),
2518 'parent' => $menuid,
2519 ];
2520 $wp_admin_bar->add_node( $args );
2521 }
2522 if( WPF()->usergroup->can( 'mt' ) || wpforo_current_user_is( 'admin' ) ) {
2523 $args = [
2524 'id' => $menuid . '-tools',
2525 'title' => '&#128295;&nbsp;&nbsp;' . __( 'Tools', 'wpforo' ),
2526 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) ),
2527 'parent' => $menuid,
2528 ];
2529 $wp_admin_bar->add_node( $args );
2530 }
2531 if( WPF()->usergroup->can( 'aum' ) || wpforo_current_user_is( 'admin' ) ) {
2532 $args = [
2533 'id' => $menuid . '-moderation',
2534 'title' => '&#128479;&nbsp;&nbsp;' . __( 'Moderation', 'wpforo' ) . wpforo_wp_admin_bar_red_circle_number( $bds_bar_numbers[$boardid]['mod_count'] ),
2535 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'moderations' ) ),
2536 'parent' => $menuid,
2537 ];
2538 $wp_admin_bar->add_node( $args );
2539 }
2540 if( WPF()->usergroup->can( 'mp' ) || wpforo_current_user_is( 'admin' ) ) {
2541 $args = [
2542 'id' => $menuid . '-phrases',
2543 'title' => '&#9873;&nbsp;&nbsp;' . __( 'Phrases', 'wpforo' ),
2544 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) ),
2545 'parent' => $menuid,
2546 ];
2547 $wp_admin_bar->add_node( $args );
2548 $args = [
2549 'id' => $menuid . '-new-phrase',
2550 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Phrase', 'wpforo' ),
2551 'href' => admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'phrases' ) . '&wpfaction=phrase_add_form' ),
2552 'parent' => $menuid . '-phrases',
2553 ];
2554 $wp_admin_bar->add_node( $args );
2555 }
2556 }
2557 }
2558
2559 ##### -- ##### ----- $ ----- ###
2560
2561 if( WPF()->usergroup->can( 'ms' ) || wpforo_current_user_is( 'admin' ) ) {
2562 $args = [
2563 'id' => 'wpforo-boards',
2564 'title' => '&#9776;&nbsp;&nbsp;' . __( 'Boards', 'wpforo' ),
2565 'href' => admin_url( 'admin.php?page=wpforo-boards' ),
2566 'parent' => 'wpforo',
2567 ];
2568 $wp_admin_bar->add_node( $args );
2569 $args = [
2570 'id' => 'wpforo-new-board',
2571 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Board', 'wpforo' ),
2572 'href' => admin_url( 'admin.php?page=wpforo-boards&wpfaction=wpforo_board_save_form' ),
2573 'parent' => 'wpforo-boards',
2574 ];
2575 $wp_admin_bar->add_node( $args );
2576 }
2577 if( WPF()->usergroup->can( 'ms' ) || wpforo_current_user_is( 'admin' ) ) {
2578 $args = [
2579 'id' => 'wpforo-accesses',
2580 'title' => '&#33;&nbsp;&nbsp;' . __( 'Accesses', 'wpforo' ),
2581 'href' => admin_url( 'admin.php?page=wpforo-accesses' ),
2582 'parent' => 'wpforo',
2583 ];
2584 $wp_admin_bar->add_node( $args );
2585 $args = [
2586 'id' => 'wpforo-new-accesses',
2587 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Forum Access', 'wpforo' ),
2588 'href' => admin_url( 'admin.php?page=wpforo-accesses&wpfaction=wpforo_access_save_form' ),
2589 'parent' => 'wpforo-accesses',
2590 ];
2591 $wp_admin_bar->add_node( $args );
2592 }
2593 if( WPF()->usergroup->can( 'vmg' ) || wpforo_current_user_is( 'admin' ) ) {
2594 $args = [
2595 'id' => 'wpforo-usergroups',
2596 'title' => '&#128101;&nbsp;&nbsp;' . __( 'Usergroups', 'wpforo' ),
2597 'href' => admin_url( 'admin.php?page=wpforo-usergroups' ),
2598 'parent' => 'wpforo',
2599 ];
2600 $wp_admin_bar->add_node( $args );
2601 $args = [
2602 'id' => 'wpforo-new-ugroup',
2603 'title' => '&#43;&nbsp;&nbsp;' . __( 'Add New Usergroup', 'wpforo' ),
2604 'href' => admin_url( 'admin.php?page=wpforo-usergroups&wpfaction=wpforo_usergroup_save_form' ),
2605 'parent' => 'wpforo-usergroups',
2606 ];
2607 $wp_admin_bar->add_node( $args );
2608 }
2609 if( WPF()->usergroup->can( 'vm' ) || wpforo_current_user_is( 'admin' ) ) {
2610 $args = [
2611 'id' => 'wpforo-members',
2612 'title' => '&#128100;&nbsp;&nbsp;' . __( 'Members', 'wpforo' ) . wpforo_wp_admin_bar_red_circle_number( wpforo_get_memb_attention_count() ),
2613 'href' => admin_url( 'admin.php?page=wpforo-members' ),
2614 'parent' => 'wpforo',
2615 ];
2616 $wp_admin_bar->add_node( $args );
2617 }
2618 if( WPF()->usergroup->can( 'ms' ) || wpforo_current_user_is( 'admin' ) ) {
2619 $args = [
2620 'id' => 'wpforo-base-settings',
2621 'title' => '&#9881;&nbsp;&nbsp;' . __( 'Settings', 'wpforo' ),
2622 'href' => admin_url( 'admin.php?page=wpforo-base-settings' ),
2623 'parent' => 'wpforo',
2624 ];
2625 $wp_admin_bar->add_node( $args );
2626 }
2627 if( WPF()->usergroup->can( 'mth' ) || wpforo_current_user_is( 'admin' ) ) {
2628 $args = [
2629 'id' => 'wpforo-themes',
2630 'title' => '&#127912;&nbsp;&nbsp;' . __( 'Themes', 'wpforo' ),
2631 'href' => admin_url( 'admin.php?page=wpforo-themes' ),
2632 'parent' => 'wpforo',
2633 ];
2634 $wp_admin_bar->add_node( $args );
2635 }
2636 if( wpforo_current_user_is( 'admin' ) ) {
2637 $args = [
2638 'id' => 'wpforo-addons',
2639 'title' => '&#128268;&nbsp;&nbsp;' . __( 'Addons', 'wpforo' ),
2640 'href' => admin_url( 'admin.php?page=wpforo-addons' ),
2641 'parent' => 'wpforo',
2642 ];
2643 $wp_admin_bar->add_node( $args );
2644 }
2645
2646 }
2647 }
2648
2649 add_action( 'admin_bar_menu', function ( $wp_admin_bar ){
2650 if( is_wpforo_multiboard() ){
2651 wpforo_multiboard_admin_bar_menu( $wp_admin_bar );
2652 WPF()->change_board();
2653 }else{
2654 wpforo_admin_bar_menu( $wp_admin_bar );
2655 }
2656 echo '<style>
2657 #wpadminbar .wpforo-menu-notification-counter,
2658 #wpadminbar .wpforo-menu-notification-indicator{
2659 background-color: #d63638;
2660 color: #ffffff;
2661 }
2662
2663 #wpadminbar .wpforo-menu-notification-counter{
2664 display: inline-block;
2665 min-width: 18px;
2666 height: 18px;
2667 border-radius: 50%;
2668 margin: 5px 5px 0 5px;
2669 vertical-align: top;
2670 font-size: 11px;
2671 line-height: 1.6;
2672 text-align: center;
2673 }
2674 </style>';
2675 }, 999 );
2676
2677 function wpforo_tag_search() {
2678 $s = wp_unslash( $_GET['q'] );
2679 $tag_separator = ( strpos($s,'،') !== FALSE ) ? '،' : ',';
2680 $tag_separator = apply_filters( 'wpforo_tag_separator', $tag_separator );
2681 if( false !== strpos( (string) $s, $tag_separator ) ) {
2682 $s = str_replace($tag_separator, ',', $s);
2683 $s = explode( ',', $s );
2684 $s = $s[ count( $s ) - 1 ];
2685 }
2686 $s = trim( (string) $s );
2687 $tag_search_min_chars = apply_filters( 'wpforo_tag_search_min_chars', 2 );
2688 if( wpforo_strlen( $s ) >= $tag_search_min_chars ) {
2689 $limit = wpforo_setting( 'tags', 'suggest_limit' );
2690 $results = WPF()->db->get_col( "SELECT `tag` FROM `" . WPF()->tables->tags . "` WHERE `tag` LIKE '" . esc_sql( $s ) . "%' LIMIT " . $limit );
2691 if( ! empty( $results ) ) {
2692 echo implode( "\n", $results );
2693 }
2694 }
2695 wp_die();
2696 }
2697
2698 add_action( 'wp_ajax_wpforo_tag_search', 'wpforo_tag_search' );
2699 add_action( 'wp_ajax_nopriv_wpforo_tag_search', 'wpforo_tag_search' );
2700
2701 function wpforo_add_to_footer() {
2702 if( WPF()->current_object['load_tinymce'] ) {
2703 wp_enqueue_editor();
2704 }
2705 }
2706
2707 add_action( 'wpforo_bottom_hook', 'wpforo_add_to_footer' );
2708
2709 function wpforo_check_notifications() {
2710 $data = [ 'alerts' => 0, 'notifications' => '' ];
2711 if( is_user_logged_in() && wpforo_setting( 'notifications', 'notifications' ) ) {
2712 $data['alerts'] = count( WPF()->activity->notifications );
2713 if( wpfval( $_POST, 'getdata' ) ) {
2714 $data['notifications'] = WPF()->activity->notifications_list( false );
2715 }
2716 wp_send_json_success( $data );
2717 }
2718 wp_send_json_error( $data );
2719 }
2720
2721 add_action( 'wp_ajax_wpforo_notifications', 'wpforo_check_notifications' );
2722
2723 function wpforo_can_display_recaptcha_note() {
2724 $d = wpforo_is_admin() ? 'recaptcha_backend_note' : 'recaptcha_note';
2725
2726 return ! WPF()->dissmissed[ $d ] && current_user_can( 'administrator' ) && ! wp_is_mobile() && wpforo_setting( 'authorization', 'user_register' ) && ! wpforo_setting( 'authorization', 'register_url' ) && ! wpforo_is_recaptcha_configured();
2727 }
2728
2729 add_action( 'wpforo_header_hook', 'wpforo_recaptcha_note' );
2730 function wpforo_recaptcha_note() {
2731 if( wpforo_can_display_recaptcha_note() ) {
2732 ?>
2733 <div class="wpforo-rcn-wrap">
2734 <div class="wpforo-rcn-body">
2735 <span class="wpforo-rcn-head"><i
2736 class="fas fa-user-secret"></i> <?php wpforo_phrase( 'Protect your forum from spam user registration!' ); ?></span>
2737 <?php printf(
2738 wpforo_phrase( 'wpForo has not found any protection solution against spam user registration on the forum registration form. Please %1$s and enable the %2$s antibot protection in %3$s or install other alternative %4$s to avoid registration of spam users.', false, 'native' ),
2739 '<a class="wpf-rcnl" href="' . admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'base-settings' ) . '&wpf_tab=recaptcha#wpf-settings-tab' ) . '" target="_blank">' . wpforo_phrase( 'configure', false, 'lower' ) . '</a>',
2740 '<a class="wpf-rcngl" href="https://developers.google.com/recaptcha" target="_blank">Google reCAPTCHA</a>',
2741 '<a href="' . admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'base-settings' ) . '&wpf_tab=recaptcha#wpf-settings-tab' ) . '">' . wpforo_phrase( 'Tools &gt; Antispam Tab', false ) . '</a>',
2742 '<a class="wpf-rcnwl" href="https://wordpress.org/plugins/search/spam+users/" target="_blank">' . wpforo_phrase( 'WordPress plugin', false ) . '</a>'
2743 )
2744 ?>
2745 </div>
2746 <div class="wpforo-rcn-footer">
2747 <div class="wpforo-rcn-info">
2748 <?php wpforo_phrase( 'This notification is only visible for the website administrators. It will be automatically disabled once some antispam solution is enabled. If you don\'t use wpForo registration form or you\'re sure, that you have an antispam solution just click the [dismiss] button.' ); ?>
2749 </div>
2750 <div class="wpforo-rcn-dismiss">
2751 <span class="wpforo-rcn-dismiss-button"
2752 wpf-tooltip="<?php wpforo_phrase( 'I got it, please dismiss this message' ) ?>"
2753 wpf-tooltip-size="long"><?php wpforo_phrase( 'Dismiss' ) ?></span>
2754 </div>
2755 </div>
2756 </div>
2757 <?php
2758 }
2759 }
2760
2761 //add_action('admin_notices', 'wpforo_admin_notice_recaptcha');
2762 function wpforo_admin_notice_recaptcha() {
2763 if( wpforo_can_display_recaptcha_note() ) {
2764 wp_enqueue_script( 'wpforo-backend-js' );
2765 $class = 'notice notice-error is-dismissible';
2766 $message = __( 'IMPORTANT! The forum registration form is probably under risk of spam attacks. Please configure wpForo built-in %s antibot for registration form to avoid spam registrations. If you don\'t use the forum registration form or you are sure that your registration forms are secured, just click on (x) button to dismiss this message.', 'wpforo' );
2767 $message = sprintf( $message, '<a href="' . admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=antispam#wpf-recaptcha' ) . '" target="_blank" style="text-decoration:none;">' . __( 'Google reCAPTCHA', 'wpforo' ) . '</a>' );
2768 printf( '<div id="wpforo-admin-notice-recaptcha" class="%1$s"><p>%2$s</p></div>', $class, $message );
2769 }
2770 }
2771
2772 function wpforo_is_recaptcha_configured() {
2773 return wpforo_setting( 'recaptcha', 'wpf_reg_form' ) && wpforo_setting( 'recaptcha', 'site_key' ) && wpforo_setting( 'recaptcha', 'secret_key' );
2774 }
2775
2776
2777
2778 /*add_action( 'plugins_loaded', function() {
2779 if( ! (int) wpfval( WPF()->dissmissed, 'poll_version_is_old' ) && function_exists( 'WPF_POLL' ) ) {
2780 if( version_compare( WPFORO_VERSION, '1.7.7', '>' ) && version_compare( WPFOROPOLL_VERSION, '1.0.5', '<=' ) ) {
2781 remove_action( 'widgets_init', [ WPF_POLL(), 'init_widgets' ] );
2782 remove_action( 'wpforo_before_init', [ WPF_POLL(), 'init' ] );
2783
2784 WPF()->dissmissed['poll_version_is_old'] = 0;
2785 wpforo_update_option( 'dissmissed', WPF()->dissmissed );
2786 } else {
2787 WPF()->dissmissed['poll_version_is_old'] = 1;
2788 wpforo_update_option( 'dissmissed', WPF()->dissmissed );
2789 }
2790 }
2791 } );*/
2792
2793 add_action( 'admin_notices', function() {
2794 if( wpfkey( WPF()->dissmissed, 'poll_version_is_old' ) && ! (int) WPF()->dissmissed['poll_version_is_old'] ) {
2795 $class = 'notice notice-error';
2796 $message = '<div style="font-size: 16px; padding: 10px 0;"><strong>' . __( 'wpForo Polls addon is disabled!', 'wpforo' ) . '</strong><p style="font-size:15px; margin-bottom:0;">' . __( ' Your addon version is not compatible with the current version of wpForo. Please update the addon or downgrade wpForo to 1.7.7', 'wpforo' ) . '</p></div>';
2797 $message .= ' <a href="' . admin_url( wp_nonce_url( 'admin.php?page=' . wpforo_prefix_slug( 'dashboard' ) . '&wpfaction=dissmiss_poll_version_is_old', 'wpforo-dissmiss-poll-version-is-old' ) ) . '">[' . __( 'dismiss', 'wpforo' ) . ']</a>';
2798 printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
2799 }
2800 } );
2801
2802 add_action( 'wpforo_update_option', function() {
2803 wpforo_clean_folder( WPF()->folders['cache']['dir'] . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'option' );
2804 } );
2805
2806 add_action( 'wpforo_after_init', function() {
2807 add_action( 'wp_ajax_dismiss_wpforo_addon_note', [ WPF()->notice, 'dismissAddonNote' ] );
2808 add_action( 'admin_notices', [ WPF()->notice, 'addonNote' ] );
2809 } );
2810
2811 add_action( 'wpforo_after_init', function() {
2812 add_action( 'wp_ajax_dismiss_wpforo_cache_conflict_note', [ WPF()->notice, 'dismissCacheConflict' ] );
2813 } );
2814
2815 add_action( 'admin_enqueue_scripts', 'wpforo_cat_cover_js' );
2816
2817 function wpforo_cat_cover_js() {
2818 if ( wpfval($_GET, 'page') === wpforo_prefix_slug( 'forums' ) && !did_action( 'wp_enqueue_media' ) ) {
2819 wp_enqueue_media();
2820 }
2821 }
2822
2823 function wpforo_esc_html( $var ) {
2824 if ( is_scalar( $var ) ) {
2825 $var = esc_html( $var );
2826 } else {
2827 $var = wpforo_esc_html( $var );
2828 }
2829
2830 return $var;
2831 }
2832
2833 add_action( 'wpforo_bottom_hook', 'wpforo_debug' );
2834 function wpforo_debug() {
2835 if( wpforo_setting( 'general', 'debug_mode' ) ) : ?>
2836 <div id="wpforo-debug" style="display:none">
2837 <h4>Super Globals</h4>
2838 <textarea style="width:100%; height:300px;">
2839 Requests: <?php //print_r( array_map( 'wpforo_esc_html', $_REQUEST ) ); ?>
2840 Server: <?php //print_r( $_SERVER ); ?>
2841 </textarea>
2842 <h4>Options and Features</h4>
2843 <textarea style="width:100%; height:300px;">
2844 <?php echo @ 'route: ' . WPF()->board->route . "\r\n";
2845 echo @ 'use_home_url: ' . WPF()->board->get_current( 'is_standalone' ) . "\r\n";
2846 echo @ 'url: ' . wpforo_home_url() . "\r\n";
2847 echo @ 'pageid:' . WPF()->board->get_current( 'pageid' ) . "\r\n";
2848 echo @ 'default_groupid: ' . WPF()->usergroup->default_groupid . "\r\n";
2849 @print_r( WPF()->tpl->theme ) . "\r\n";
2850 ?>
2851 </textarea>
2852 </div>
2853 <?php
2854 endif;
2855 }
2856
2857 add_filter( 'wpforo_topic_list_args', function( $args ){
2858 if( wpforo_setting( 'topics', 'include_subforums_topics' ) ){
2859 $forumid = (int) $args['forumid'];
2860 $forumids = WPF()->forum->get_forumid_and_childids( $forumid );
2861 unset( $args['forumid'] );
2862 $args['forumids'] = $forumids;
2863 }
2864
2865 return $args;
2866 } );
2867
2868 function wpf_body_wp_encode_emoji( $post ){
2869 if( wpfkey( $post, 'title' ) ) $post['title'] = wp_encode_emoji( $post['title'] );
2870 if( wpfkey( $post, 'body' ) ) $post['body'] = wp_encode_emoji( $post['body'] );
2871 return $post;
2872 }
2873 add_filter( 'wpforo_add_post_data_filter', 'wpf_body_wp_encode_emoji' );
2874 add_filter( 'wpforo_edit_post_data_filter', 'wpf_body_wp_encode_emoji' );
2875 add_filter( 'wpforo_add_topic_data_filter', 'wpf_body_wp_encode_emoji' );
2876 add_filter( 'wpforo_edit_topic_data_filter', 'wpf_body_wp_encode_emoji' );
2877