| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( !defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
|
| 6 |
add_action( 'admin_init', 'wpforo_do_uninstall', 10); |
| 7 |
function wpforo_do_uninstall(){ |
| 8 |
if( isset($_GET['action']) && $_GET['action'] == 'wpforo-uninstall' ){ |
| 9 |
if( check_admin_referer( 'wpforo_uninstall' ) && current_user_can('administrator') ) wpforo_uninstall(); |
| 10 |
wp_redirect( admin_url( 'plugins.php' ) ); |
| 11 |
exit(); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
add_filter( 'plugin_action_links_' . WPFORO_BASENAME, 'wpforo_action_link', 10, 2 ); |
| 16 |
function wpforo_action_link( $links, $file ) { |
| 17 |
|
| 18 |
$uninstall_url = wp_nonce_url( admin_url( 'plugins.php?action=wpforo-uninstall' ), 'wpforo_uninstall' ); |
| 19 |
|
| 20 |
$links[] = '<a href="'.esc_url( $uninstall_url ).'" 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>'; |
| 21 |
|
| 22 |
$settings_link = '<a href="'.esc_url( admin_url( 'admin.php?page=wpforo-community' ) ).'">' . __( 'Settings', 'wpforo' ) . '</a>'; |
| 23 |
array_unshift( $links, $settings_link ); |
| 24 |
|
| 25 |
return $links; |
| 26 |
} |
| 27 |
|
| 28 |
function wpforo_notice_show(){ |
| 29 |
WPF()->notice->show(); |
| 30 |
} |
| 31 |
add_action( 'wpforo_top_hook', 'wpforo_notice_show', 10, 0 ); |
| 32 |
|
| 33 |
function wpforo_user_admin_bar(){ |
| 34 |
if( !is_super_admin() && is_user_logged_in() ) show_admin_bar( wpforo_feature('user-admin-bar') ); |
| 35 |
} |
| 36 |
add_action('init', 'wpforo_user_admin_bar'); |
| 37 |
|
| 38 |
function wpforo_admin_notice__menu_help(){ |
| 39 |
if(strpos(wpforo_get_request_uri(), 'nav-menus.php') !== FALSE){ |
| 40 |
|
| 41 |
$message = 'wpForo Menu Shortcodes<hr/><table>'; |
| 42 |
foreach( WPF()->menu as $key => $value ){ |
| 43 |
$message .= "<tr><td> " . $value['label'] . ": </td><td> /%$key%/ </td></tr>"; |
| 44 |
} |
| 45 |
$message .= "<tr><td> " . wpforo_phrase('register', FALSE) . ": </td><td> /%wpforo-register%/ </td></tr> |
| 46 |
<tr><td> " . wpforo_phrase('login', FALSE) . ": </td><td> /%wpforo-login%/ </td></tr> |
| 47 |
</table>"; |
| 48 |
|
| 49 |
$class = 'notice notice-warning'; |
| 50 |
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); |
| 51 |
} |
| 52 |
} |
| 53 |
//add_action( 'admin_notices', 'wpforo_admin_notice__menu_help' ); |
| 54 |
|
| 55 |
function wpforo_disable_comments( $open, $post_id ) { |
| 56 |
if(is_wpforo_page()) return FALSE; |
| 57 |
return $open; |
| 58 |
} |
| 59 |
add_filter( 'comments_open', 'wpforo_disable_comments', 10, 2 ); |
| 60 |
|
| 61 |
function wpforo_disable_comments_hide_existing_comments($comments) { |
| 62 |
if(is_wpforo_page()) return array(); |
| 63 |
return $comments; |
| 64 |
} |
| 65 |
add_filter('comments_array', 'wpforo_disable_comments_hide_existing_comments', 10, 2); |
| 66 |
|
| 67 |
function wpforo_remove_comment_support() { |
| 68 |
if(is_wpforo_page()){ |
| 69 |
remove_post_type_support( 'post', 'comments' ); |
| 70 |
remove_post_type_support( 'page', 'comments' ); |
| 71 |
} |
| 72 |
} |
| 73 |
add_action('init', 'wpforo_remove_comment_support', 100); |
| 74 |
|
| 75 |
function wpforo_change_author_default_page( $link ){ |
| 76 |
if(!wpforo_feature('author-link')) return $link; |
| 77 |
return WPF()->member->get_profile_url($link); |
| 78 |
} |
| 79 |
function wpforo_change_comment_author_default_page( $link, $ID = 0, $object = NULL ){ |
| 80 |
if(!wpforo_feature('comment-author-link')) return $link; |
| 81 |
if(!isset($link) || !$link){ |
| 82 |
if(isset($object->user_id) && $object->user_id){ |
| 83 |
return WPF()->member->get_profile_url($object->user_id); |
| 84 |
} |
| 85 |
} |
| 86 |
return $link; |
| 87 |
} |
| 88 |
add_filter( 'author_link', 'wpforo_change_author_default_page', 10, 1 ); |
| 89 |
add_filter( 'get_comment_author_url', 'wpforo_change_comment_author_default_page', 10, 3 ); |
| 90 |
|
| 91 |
function wpforo_change_default_register_page( $register_url ) { |
| 92 |
if(!wpforo_feature('register-url')) return $register_url; |
| 93 |
return wpforo_home_url('?wpforo=signup'); |
| 94 |
} |
| 95 |
add_filter( 'register_url', 'wpforo_change_default_register_page' ); |
| 96 |
|
| 97 |
function wpforo_change_default_login_page( $login_url, $redirect ) { |
| 98 |
if(!wpforo_feature('login-url')) return $login_url; |
| 99 |
return wpforo_home_url('?wpforo=signin'); |
| 100 |
} |
| 101 |
add_filter( 'login_url', 'wpforo_change_default_login_page', 10, 2 ); |
| 102 |
|
| 103 |
function wpforo_restrict_trash_shortcode_page($check, $post){ |
| 104 |
if( $post->ID == WPF()->pageid ) { |
| 105 |
$check = false; |
| 106 |
WPF()->notice->add('DO NOT DELETE WPFORO PAGE!!!', 'error'); |
| 107 |
} |
| 108 |
return $check; |
| 109 |
} |
| 110 |
add_filter('pre_trash_post', 'wpforo_restrict_trash_shortcode_page', 10, 2); |
| 111 |
|
| 112 |
function wpforo_restrict_front_page_dropdown($output, $r){ |
| 113 |
if( $r['name'] == 'page_for_posts' || ($r['name'] == 'page_on_front' && wpforo_get_shortcode_pageid( WPF()->pageid )) ){ |
| 114 |
$pattern = '#[\r\n\t\s]*<option[^<>]*?value=[\'"]'.wpforo_bigintval(WPF()->pageid).'[\'"][^<>]*?>[^<>]*?</option>#isu'; |
| 115 |
$output = preg_replace($pattern, '', $output); |
| 116 |
} |
| 117 |
return $output; |
| 118 |
} |
| 119 |
add_filter('wp_dropdown_pages', 'wpforo_restrict_front_page_dropdown', 10, 2); |
| 120 |
|
| 121 |
function wpforo_page_on_front_manager($value, $option, $old_value){ |
| 122 |
if( $option == 'page_on_front' && $value == WPF()->pageid ){ |
| 123 |
if( !$page_id = wpforo_get_shortcode_pageid( WPF()->pageid ) ){ |
| 124 |
$wpforo_page = array( |
| 125 |
'post_date' => current_time( 'mysql', 1 ), |
| 126 |
'post_date_gmt' => current_time( 'mysql', 1 ), |
| 127 |
'post_content' => '[wpforo]', |
| 128 |
'post_title' => 'Forum page_on_front', |
| 129 |
'post_status' => 'publish', |
| 130 |
'comment_status' => 'close', |
| 131 |
'ping_status' => 'close', |
| 132 |
'post_name' => 'front-community', |
| 133 |
'post_modified' => current_time( 'mysql', 1 ), |
| 134 |
'post_modified_gmt' => current_time( 'mysql', 1 ), |
| 135 |
'post_parent' => 0, |
| 136 |
'menu_order' => 0, |
| 137 |
'post_type' => 'page' |
| 138 |
); |
| 139 |
$page_id = wp_insert_post( $wpforo_page ); |
| 140 |
} |
| 141 |
$value = ( $page_id && !is_wp_error($page_id) ? $page_id : $old_value); |
| 142 |
} |
| 143 |
return $value; |
| 144 |
} |
| 145 |
add_filter('pre_update_option', 'wpforo_page_on_front_manager', 10, 3); |
| 146 |
|
| 147 |
function wpftpl( $filename ){ |
| 148 |
$find = array(); |
| 149 |
if ( $filename ) { |
| 150 |
$find[] = 'wpforo/'. $filename; |
| 151 |
$template = locate_template( array_unique( $find ) ); |
| 152 |
if ( !$template ) $template = WPFORO_THEME_DIR . '/'. WPF()->tpl->theme .'/' . $filename; |
| 153 |
|
| 154 |
return apply_filters('wpforo_wpftpl', $template); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
function wpforo_init_template(){ |
| 159 |
if(wpforo_is_admin()) return; |
| 160 |
include_once( wpftpl('index.php') ); |
| 161 |
} |
| 162 |
|
| 163 |
add_shortcode( 'wpforo', 'wpforo_load' ); |
| 164 |
function wpforo_load( $atts ){ |
| 165 |
if(wpforo_is_admin()) return ''; |
| 166 |
|
| 167 |
if(wpforo_feature('output-buffer') && function_exists('ob_start')){ |
| 168 |
if( wpforo_feature('html_cashe') ){ |
| 169 |
if( $html = WPF()->cache->get_html() ) return $html; |
| 170 |
} |
| 171 |
ob_start(); |
| 172 |
wpforo_init_template(); |
| 173 |
$output = ob_get_clean(); |
| 174 |
WPF()->cache->html($output); |
| 175 |
return $output; |
| 176 |
} |
| 177 |
else{ |
| 178 |
wpforo_init_template(); |
| 179 |
} |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
function wpforo_template_include($template){ |
| 184 |
if( is_wpforo_page() && !is_wpforo_shortcode_page() && ($wpforo_template = wpftpl('index.php')) ){ |
| 185 |
return $wpforo_template; |
| 186 |
} |
| 187 |
return $template; |
| 188 |
} |
| 189 |
|
| 190 |
add_action('wp', 'wpforo_set_header_status'); |
| 191 |
function wpforo_set_header_status(){ |
| 192 |
if( is_wpforo_page() ){ |
| 193 |
global $wp_query; |
| 194 |
|
| 195 |
$status = ( WPF()->current_object['is_404'] ? 404 : 200 ); |
| 196 |
status_header( $status ); |
| 197 |
$wp_query->is_404 = FALSE; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
function wpforo_do_rewrite(){ |
| 202 |
if( is_wpforo_page() ){ |
| 203 |
if( WPF()->use_home_url ){ |
| 204 |
add_rewrite_rule( '(.*)', 'index.php?page_id=' . WPF()->pageid, 'top'); |
| 205 |
add_filter('template_include', 'wpforo_template_include'); |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
add_action('setup_theme', 'wpforo_do_rewrite'); |
| 210 |
|
| 211 |
function wpforo_rewrite_rules_array($rules){ |
| 212 |
$permastruct = utf8_uri_encode( WPF()->permastruct ); |
| 213 |
$permastruct = preg_replace('#^/?index\.php/?#isu', '', $permastruct); |
| 214 |
$permastruct = trim($permastruct, '/'); |
| 215 |
$pattern = '('.preg_quote($permastruct).'(?:/|$).*)$'; |
| 216 |
$to_url = 'index.php?page_id=' . WPF()->pageid; |
| 217 |
if( !WPF()->use_home_url && !in_array($to_url, $rules) ) $rules = array_merge( array($pattern => $to_url), $rules ); |
| 218 |
|
| 219 |
return $rules; |
| 220 |
} |
| 221 |
add_filter( 'rewrite_rules_array', 'wpforo_rewrite_rules_array' ); |
| 222 |
|
| 223 |
function wpforo_theme_functions(){ |
| 224 |
$path = wpftpl('functions.php'); |
| 225 |
if( file_exists($path) ){ |
| 226 |
include_once($path); |
| 227 |
} |
| 228 |
} |
| 229 |
add_action('init', 'wpforo_theme_functions'); |
| 230 |
|
| 231 |
function wpforo_theme_functions_wp(){ |
| 232 |
$path = wpftpl('functions-wp.php'); |
| 233 |
if( file_exists($path) ){ |
| 234 |
include_once($path); |
| 235 |
} |
| 236 |
} |
| 237 |
add_action('after_setup_theme', 'wpforo_theme_functions_wp'); |
| 238 |
|
| 239 |
function wpforo_meta_title($title) { |
| 240 |
$is404 = false; |
| 241 |
$meta_title = array(); |
| 242 |
|
| 243 |
if(!wpforo_feature('seo-title')) return $title; |
| 244 |
|
| 245 |
if(is_wpforo_page()){ |
| 246 |
$template = WPF()->current_object['template']; |
| 247 |
if( ($template == 'post' && WPF()->current_object['topicid'] == 0) || |
| 248 |
($template == 'topic' && WPF()->current_object['forumid'] == 0) || |
| 249 |
($template == 'profile' && WPF()->current_object['userid'] == 0) ){ |
| 250 |
$is404 = true; |
| 251 |
} |
| 252 |
if(!$is404){ |
| 253 |
$paged = ( WPF()->current_object['paged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false) . ' ' . WPF()->current_object['paged'] .' ' : ''; |
| 254 |
if(!empty(WPF()->current_object['forum'])) $forum = WPF()->current_object['forum']; |
| 255 |
if(!empty(WPF()->current_object['topic'])) $topic = WPF()->current_object['topic']; |
| 256 |
if(!empty(WPF()->current_object['user'])) $user = WPF()->current_object['user']; |
| 257 |
if(isset($topic['title']) && isset($forum['title']) && isset(WPF()->general_options['title'])){ |
| 258 |
$meta_title = array($topic['title'] . $paged, $forum['title'], WPF()->general_options['title']); |
| 259 |
} |
| 260 |
elseif(!isset($topic['title']) && isset($forum['title']) && isset(WPF()->general_options['title'])){ |
| 261 |
$meta_title = array($forum['title'] . $paged, WPF()->general_options['title']); |
| 262 |
} |
| 263 |
elseif( $template != 'forum' && $template != 'topic' && $template != 'post' ){ |
| 264 |
if( $template == 'profile' || $template == 'account' || $template == 'activity' || $template == 'subscriptions' ){ |
| 265 |
if(isset($user['display_name'])){ |
| 266 |
$meta_title = array($user['display_name'], wpforo_phrase( ucfirst($template), false), WPF()->general_options['title']); |
| 267 |
} |
| 268 |
elseif(isset(WPF()->current_object['user_nicename'])){ |
| 269 |
$meta_title = array(WPF()->current_object['user_nicename'], wpforo_phrase( ucfirst($template), false), WPF()->general_options['title']); |
| 270 |
} |
| 271 |
else{ |
| 272 |
$meta_title = array(wpforo_phrase( 'Member', false), wpforo_phrase( ucfirst($template), false), WPF()->general_options['title']); |
| 273 |
} |
| 274 |
} |
| 275 |
elseif( $template == 'recent' ){ |
| 276 |
$wpfpaged = ( isset($_GET['wpfpaged']) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false) . ' ' . $_GET['wpfpaged'] .' ' : ''; |
| 277 |
$meta_title = array( wpforo_phrase( 'Recent Posts', false) . $wpfpaged, WPF()->general_options['title']); |
| 278 |
} |
| 279 |
elseif($template){ |
| 280 |
$wpfpaged = ( isset($_GET['wpfpaged']) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false) . ' ' . $_GET['wpfpaged'] .' ' : ''; |
| 281 |
$meta_title = array(wpforo_phrase( ucfirst($template), false) . $wpfpaged, WPF()->general_options['title']); |
| 282 |
} |
| 283 |
elseif($title){ |
| 284 |
$meta_title = (is_array($title)) ? $title : array($title); |
| 285 |
} |
| 286 |
else{ |
| 287 |
$meta_title = array(wpforo_phrase('Forum', false), get_bloginfo('name')); |
| 288 |
} |
| 289 |
} |
| 290 |
elseif( isset(WPF()->general_options['title']) && WPF()->general_options['title'] ){ |
| 291 |
$meta_title = array(WPF()->general_options['title'], get_bloginfo('name')); |
| 292 |
} |
| 293 |
elseif($title){ |
| 294 |
$meta_title = (is_array($title)) ? $title : array($title); |
| 295 |
} |
| 296 |
else{ |
| 297 |
$meta_title = array(wpforo_phrase('Forum', false), get_bloginfo('name')); |
| 298 |
} |
| 299 |
} |
| 300 |
else{ |
| 301 |
$meta_title = array(wpforo_phrase( '404 - Page not found', false), WPF()->general_options['title']); |
| 302 |
} |
| 303 |
} |
| 304 |
if(!empty($meta_title)) { |
| 305 |
return $meta_title; |
| 306 |
} |
| 307 |
else{ |
| 308 |
return $title; |
| 309 |
} |
| 310 |
} |
| 311 |
add_filter('document_title_parts', 'wpforo_meta_title', 100); |
| 312 |
|
| 313 |
function wpforo_meta_wp_title($title){ |
| 314 |
if(!wpforo_feature('seo-title')) return $title; |
| 315 |
$meta_title = wpforo_meta_title($title); |
| 316 |
if(is_array($meta_title) && !empty($meta_title)){ |
| 317 |
$title = implode(' – ', $meta_title); |
| 318 |
} |
| 319 |
return $title; |
| 320 |
} |
| 321 |
add_filter( 'wp_title', 'wpforo_meta_wp_title', 100); |
| 322 |
|
| 323 |
function wpforo_add_meta_tags(){ |
| 324 |
if(!wpforo_feature('seo-meta')) return; |
| 325 |
|
| 326 |
if(is_wpforo_page()){ |
| 327 |
$title = ''; |
| 328 |
$og_img = ''; |
| 329 |
$noindex = ''; |
| 330 |
$template = ''; |
| 331 |
$description = ''; |
| 332 |
$udata = array(); |
| 333 |
$canonical = wpforo_get_request_uri(); |
| 334 |
$noindex_urls = WPF()->tools_misc['noindex']; |
| 335 |
$image = wpforo_get_image_url(false, true, 'og:image'); |
| 336 |
if(!empty($noindex_urls)){ |
| 337 |
$noindex_urls = explode("\n", $noindex_urls); |
| 338 |
if(!empty($noindex_urls)){ |
| 339 |
$noindex_urls = array_map("trim", $noindex_urls); |
| 340 |
foreach( $noindex_urls as $noindex_url){ |
| 341 |
$noindex_url = strtok($noindex_url, "#"); |
| 342 |
if( strpos( $noindex_url, '*' ) !== false ){ |
| 343 |
$noindex_url = strtok($noindex_url, "*"); |
| 344 |
if( preg_match('|^' . preg_quote($noindex_url) . '|is', $canonical) ){ |
| 345 |
$noindex = "<meta name=\"robots\" content=\"noindex\">\r\n"; break; |
| 346 |
} |
| 347 |
} |
| 348 |
elseif( $canonical == $noindex_url ) { |
| 349 |
$noindex = "<meta name=\"robots\" content=\"noindex\">\r\n"; break; |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
$paged = ( WPF()->current_object['paged'] > 1 ) ? wpforo_phrase( 'page', false) . ' ' . WPF()->current_object['paged'] .' | ' : ''; |
| 355 |
if(isset(WPF()->current_object['template'])) $template = WPF()->current_object['template']; |
| 356 |
if(!empty(WPF()->current_object['forum'])) $forum = WPF()->current_object['forum']; |
| 357 |
if(!empty(WPF()->current_object['topic'])) $topic = WPF()->current_object['topic']; |
| 358 |
if(!empty(WPF()->current_object['user'])) $user = WPF()->current_object['user']; |
| 359 |
if(isset(WPF()->current_object)){ |
| 360 |
if( isset(WPF()->current_object['forumid']) && !isset(WPF()->current_object['topicid']) ){ |
| 361 |
if(isset($forum['title'])) $title = $forum['title']; |
| 362 |
if(isset(WPF()->current_object['forum_meta_desc']) && WPF()->current_object['forum_meta_desc'] !=''){ |
| 363 |
$description = $paged . WPF()->current_object['forum_meta_desc']; |
| 364 |
} |
| 365 |
elseif(isset(WPF()->current_object['forum_desc']) && WPF()->current_object['forum_desc'] !=''){ |
| 366 |
$description = $paged . WPF()->current_object['forum_desc']; |
| 367 |
} |
| 368 |
}elseif( isset(WPF()->current_object['topicid']) && isset($topic['first_postid']) ){ |
| 369 |
$post = WPF()->post->get_post($topic['first_postid']); |
| 370 |
$image = wpforo_get_image_url($post['body'], true, 'og:image'); |
| 371 |
if(isset($post['title'])) $title = wpforo_text($paged . $post['title'], 60, false); |
| 372 |
if(isset($post['body'])) $description = wpforo_text($paged . $post['body'], 150, false); |
| 373 |
}elseif( $template == 'profile' || $template == 'account' || $template == 'activity' || $template == 'subscriptions' ){ |
| 374 |
if( isset(WPF()->general_options['title']) ) $title = $paged . WPF()->general_options['title']; |
| 375 |
$udata['name'] = (isset($user['display_name']) && $user['display_name']) ? wpforo_phrase( 'User', false ) . ': ' . $user['display_name'] : ''; |
| 376 |
$udata['title'] = (isset($user['stat']['title']) && $user['stat']['title']) ? wpforo_phrase( 'Title', false ) . ': ' . $user['stat']['title'] : ''; |
| 377 |
$udata['about'] = (isset($user['about']) && $user['about']) ? wpforo_phrase( 'About', false ) . ': ' . wpforo_text($user['about'], 150, false) : ''; |
| 378 |
$description = $title . ' - ' . wpforo_phrase('Member Profile', false) . ' > ' . wpforo_phrase( ucfirst($template), false ) . ' ' . wpforo_phrase( 'Page', false ) . '. ' . implode(', ', $udata); |
| 379 |
if(!wpforo_feature('seo-profile')){ $noindex = "<meta name=\"robots\" content=\"noindex\">\r\n"; } |
| 380 |
}elseif(isset(WPF()->current_object['template']) && WPF()->current_object['template'] == 'member'){ |
| 381 |
$wpfpaged = ( isset($_GET['wpfpaged']) && $_GET['wpfpaged'] > 1 ) ? wpforo_phrase( 'Page', false) . ' ' . $_GET['wpfpaged'] .' | ' : ''; |
| 382 |
$description = $wpfpaged . wpforo_phrase( 'Forum Members List', false); |
| 383 |
}elseif(isset(WPF()->current_object['template']) && WPF()->current_object['template'] == 'recent'){ |
| 384 |
$wpfpaged = ( isset($_GET['wpfpaged']) && $_GET['wpfpaged'] > 1 ) ? wpforo_phrase( 'Page', false) . ' ' . $_GET['wpfpaged'] .' | ' : ''; |
| 385 |
$description = $wpfpaged . wpforo_phrase( 'Recent Posts', false); |
| 386 |
} |
| 387 |
else{ |
| 388 |
if( isset(WPF()->general_options['title']) ) $title = $paged . WPF()->general_options['title']; |
| 389 |
if( isset(WPF()->general_options['description']) ) $description = $paged . WPF()->general_options['description']; |
| 390 |
if(isset(WPF()->current_object['template']) && ( WPF()->current_object['template'] == 'login' || WPF()->current_object['template'] == 'register' ) ){ |
| 391 |
$noindex = "<meta name=\"robots\" content=\"noindex\">\r\n"; |
| 392 |
} |
| 393 |
} |
| 394 |
$description = preg_replace('#[\t\r\n]+#isu', ' ', $description); |
| 395 |
if($image) $og_img = '<meta property="og:image" content="' . $image . '" />' . "\r\n"; |
| 396 |
echo "\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". $og_img . "<meta property=\"og:site_name\" content=\"" . get_bloginfo('name') . "\" />\r\n<meta name=\"twitter:description\" content=\"" . esc_html($description) . "\"/>\r\n<meta name=\"twitter:title\" content=\"" . esc_html($title) . "\" />\r\n<!-- wpForo SEO End -->\r\n\r\n"; |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
add_action('wp_head', 'wpforo_add_meta_tags', 1); |
| 401 |
|
| 402 |
|
| 403 |
add_action('wp_ajax_wpforo_like_ajax', 'wpf_like'); |
| 404 |
function wpf_like(){ |
| 405 |
$response = array('stat' => 0, 'likers' => '', 'notice' => WPF()->notice->get_notices()); |
| 406 |
if( !is_user_logged_in() ){ |
| 407 |
WPF()->notice->add( sprintf( wpforo_phrase('Please %s or %s', FALSE), '<a href="' . wpforo_login_url() . '">'.wpforo_phrase('Login', FALSE).'</a>', '<a href="' . wpforo_register_url() . '">'.wpforo_phrase('Register', FALSE).'</a>' ) ); |
| 408 |
$response['notice'] = WPF()->notice->get_notices(); |
| 409 |
echo json_encode($response); |
| 410 |
exit(); |
| 411 |
} |
| 412 |
if( !isset($_POST['likestatus']) || !isset($_POST['postid']) || !($postid = intval($_POST['postid'])) ){ |
| 413 |
WPF()->notice->add('action error', 'error'); |
| 414 |
$response['notice'] = WPF()->notice->get_notices(); |
| 415 |
echo json_encode($response); |
| 416 |
exit(); |
| 417 |
} |
| 418 |
if( !$post = WPF()->post->get_post( $postid ) ){ |
| 419 |
WPF()->notice->add('post not found', 'error'); |
| 420 |
$response['notice'] = WPF()->notice->get_notices(); |
| 421 |
echo json_encode($response); |
| 422 |
exit(); |
| 423 |
} |
| 424 |
if( !WPF()->perm->forum_can( 'l', $post['forumid']) ){ |
| 425 |
WPF()->notice->add('You don\'t have permission to like posts from this forum', 'error'); |
| 426 |
$response['notice'] = WPF()->notice->get_notices(); |
| 427 |
echo json_encode($response); |
| 428 |
exit(); |
| 429 |
} |
| 430 |
if( $_POST['likestatus'] ){ |
| 431 |
if( WPF()->db->insert( |
| 432 |
WPF()->tables->likes, |
| 433 |
array( |
| 434 |
'postid' => $postid, |
| 435 |
'userid' => WPF()->current_userid, |
| 436 |
'post_userid' => $post['userid'] |
| 437 |
), |
| 438 |
array('%d','%d','%d') |
| 439 |
) ){ |
| 440 |
wpforo_clean_cache('post-soft', $postid); |
| 441 |
do_action('wpforo_like', $post, WPF()->current_userid); |
| 442 |
WPF()->notice->add('done', 'success'); |
| 443 |
$response['stat'] = 1; |
| 444 |
$response['notice'] = WPF()->notice->get_notices(); |
| 445 |
} |
| 446 |
}else{ |
| 447 |
if( WPF()->db->delete( |
| 448 |
WPF()->tables->likes, |
| 449 |
array( |
| 450 |
'postid' => $postid, |
| 451 |
'userid' => WPF()->current_userid |
| 452 |
), |
| 453 |
array('%d','%d') |
| 454 |
) ){ |
| 455 |
wpforo_clean_cache('post-soft', $postid); |
| 456 |
do_action('wpforo_dislike', $post, WPF()->current_userid); |
| 457 |
WPF()->notice->add('done', 'success'); |
| 458 |
$response['stat'] = 1; |
| 459 |
$response['notice'] = WPF()->notice->get_notices(); |
| 460 |
} |
| 461 |
} |
| 462 |
if(!isset($post['userid'])) WPF()->member->reset($post['userid']); |
| 463 |
if(!isset(WPF()->current_userid)) WPF()->member->reset(WPF()->current_userid); |
| 464 |
$response['likers'] = WPF()->tpl->likers($postid); |
| 465 |
echo json_encode($response); |
| 466 |
exit(); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
add_action('wp_ajax_wpforo_vote_ajax', 'wpf_vote'); |
| 471 |
function wpf_vote(){ |
| 472 |
|
| 473 |
if(!is_user_logged_in()) return; |
| 474 |
|
| 475 |
if( !isset($_POST['postid']) || !$_POST['postid'] ){ |
| 476 |
WPF()->notice->add('Wrong post data', 'error'); |
| 477 |
echo json_encode(array('stat' => 0, 'notice' => WPF()->notice->get_notices())); |
| 478 |
exit(); |
| 479 |
} |
| 480 |
|
| 481 |
$reaction = 1; |
| 482 |
if( $_POST['votestatus'] == 'down' ) $reaction = -1; |
| 483 |
|
| 484 |
if( WPF()->db->get_var( "SELECT `voteid` FROM `".WPF()->tables->votes."` WHERE `postid` = " . wpforo_bigintval($_POST['postid']) . " AND `userid` = " . wpforo_bigintval(WPF()->current_userid) . " AND `reaction` = '" . $reaction . "'" )){ |
| 485 |
WPF()->notice->add('You are already voted this post'); |
| 486 |
echo json_encode(array('stat' => 0, 'notice' => WPF()->notice->get_notices())); |
| 487 |
exit(); |
| 488 |
}else{ |
| 489 |
WPF()->db->delete( |
| 490 |
WPF()->tables->votes, |
| 491 |
array( 'postid' => $_POST['postid'], 'userid' => WPF()->current_userid ), |
| 492 |
array('%d', '%d') |
| 493 |
); |
| 494 |
} |
| 495 |
|
| 496 |
$postid = wpforo_bigintval($_POST['postid']); |
| 497 |
$post = WPF()->post->get_post( $postid ); |
| 498 |
|
| 499 |
$voted = WPF()->db->insert( |
| 500 |
WPF()->tables->votes, |
| 501 |
array( |
| 502 |
'postid' => $postid, |
| 503 |
'userid' => WPF()->current_userid, |
| 504 |
'reaction' => $reaction, |
| 505 |
'post_userid' => $post['userid'] |
| 506 |
), |
| 507 |
array( |
| 508 |
'%d', |
| 509 |
'%d', |
| 510 |
'%d', |
| 511 |
'%d' |
| 512 |
) |
| 513 |
); |
| 514 |
|
| 515 |
if(!isset($post['userid'])) WPF()->member->reset($post['userid']); |
| 516 |
if(!isset(WPF()->current_userid)) WPF()->member->reset(WPF()->current_userid); |
| 517 |
|
| 518 |
if( $voted !== FALSE ){ |
| 519 |
$incr = $incr2 = true; |
| 520 |
|
| 521 |
if( $_POST['itemtype'] == 'topic' ){ |
| 522 |
$incr = WPF()->db->query( "UPDATE ".WPF()->tables->topics." SET `votes` = `votes` + $reaction WHERE topicid = " . wpforo_bigintval($post['topicid']) ); |
| 523 |
} |
| 524 |
$incr2 = WPF()->db->query( "UPDATE ".WPF()->tables->posts." SET `votes` = `votes` + $reaction WHERE postid = " . wpforo_bigintval($post['postid']) ); |
| 525 |
|
| 526 |
if($incr !== FALSE && $incr2 !== FALSE){ |
| 527 |
wpforo_clean_cache('post', $postid, $post); |
| 528 |
do_action('wpforo_vote', $reaction, $post, WPF()->current_userid ); |
| 529 |
WPF()->notice->add('Successfully voted', 'success'); |
| 530 |
echo json_encode(array('stat' => 1, 'notice' => WPF()->notice->get_notices())); |
| 531 |
exit(); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
WPF()->notice->add('Wrong post data', 'error'); |
| 536 |
echo json_encode(array('stat' => 0, 'notice' => WPF()->notice->get_notices())); |
| 537 |
exit(); |
| 538 |
} |
| 539 |
|
| 540 |
add_action('wp_ajax_wpforo_answer_ajax', 'wpf_answer'); |
| 541 |
function wpf_answer(){ |
| 542 |
$response = array('stat' => 0, 'notice' => WPF()->notice->get_notices()); |
| 543 |
if(!is_user_logged_in()){ |
| 544 |
WPF()->notice->add( sprintf( wpforo_phrase('Please %s or %s', FALSE), '<a href="' . wpforo_login_url() . '">'.wpforo_phrase('Login', FALSE).'</a>', '<a href="' . wpforo_register_url() . '">'.wpforo_phrase('Register', FALSE).'</a>' ) ); |
| 545 |
$response['notice'] = WPF()->notice->get_notices(); |
| 546 |
echo json_encode($response); |
| 547 |
exit(); |
| 548 |
} |
| 549 |
if( !isset($_POST['answerstatus']) || !isset($_POST['postid']) || !$postid = intval($_POST['postid']) ){ |
| 550 |
WPF()->notice->add('action error', 'error'); |
| 551 |
$response['notice'] = WPF()->notice->get_notices(); |
| 552 |
echo json_encode($response); |
| 553 |
exit(); |
| 554 |
} |
| 555 |
if( !$post = WPF()->post->get_post( $postid ) ){ |
| 556 |
WPF()->notice->add('post not found', 'error'); |
| 557 |
$response['notice'] = WPF()->notice->get_notices(); |
| 558 |
echo json_encode($response); |
| 559 |
exit(); |
| 560 |
} |
| 561 |
if( !$topic = WPF()->topic->get_topic( $post['topicid'] ) ){ |
| 562 |
WPF()->notice->add('topic not found', 'error'); |
| 563 |
$response['notice'] = WPF()->notice->get_notices(); |
| 564 |
echo json_encode($response); |
| 565 |
exit(); |
| 566 |
} |
| 567 |
if( !(WPF()->perm->forum_can( 'at', $post['forumid'] ) || ( WPF()->perm->forum_can( 'oat', $post['forumid']) && WPF()->current_userid == $topic['userid'] ) ) ){ |
| 568 |
WPF()->notice->add('You don\'t have permission to make topic answered', 'error'); |
| 569 |
$response['notice'] = WPF()->notice->get_notices(); |
| 570 |
echo json_encode($response); |
| 571 |
exit(); |
| 572 |
} |
| 573 |
if( FALSE !== WPF()->db->query( "UPDATE ".WPF()->tables->posts." SET is_answer = ".intval($_POST['answerstatus'])." WHERE postid = " . intval($postid) ) ){ |
| 574 |
wpforo_clean_cache('post', $postid, $post); |
| 575 |
do_action('wpforo_answer', intval($_POST['answerstatus']), $post); |
| 576 |
WPF()->notice->add('done', 'success'); |
| 577 |
$response['stat'] = 1; |
| 578 |
$response['notice'] = WPF()->notice->get_notices(); |
| 579 |
} |
| 580 |
echo json_encode($response); |
| 581 |
exit(); |
| 582 |
} |
| 583 |
|
| 584 |
add_action('wp_ajax_wpforo_quote_ajax', 'wpf_quote'); |
| 585 |
add_action('wp_ajax_nopriv_wpforo_quote_ajax', 'wpf_quote' ); |
| 586 |
function wpf_quote(){ |
| 587 |
$post = WPF()->db->get_row('SELECT `userid`, `name`, `email`, `body` FROM '.WPF()->tables->posts.' WHERE postid =' . intval($_POST['postid']), ARRAY_A); |
| 588 |
if( !WPF()->perm->forum_can( 'cr', $post['forumid']) ) return; |
| 589 |
$post = apply_filters('wpforo_quote_post_ajax', $post); |
| 590 |
$poster = wpforo_member( $post ); |
| 591 |
echo '<blockquote><div class="wpforo-post-quote-author"><strong>' . wpforo_phrase('Posted by', FALSE) . ': ' . ( $poster['display_name'] ? esc_textarea($poster['display_name']) : esc_textarea($poster['user_login']) ) . '</strong></div>' . wpautop($post['body']) . '</blockquote><br />'; |
| 592 |
exit(); |
| 593 |
} |
| 594 |
|
| 595 |
add_action('wp_ajax_wpforo_report_ajax', 'wpf_report'); |
| 596 |
function wpf_report(){ |
| 597 |
|
| 598 |
if(!is_user_logged_in()) return; |
| 599 |
|
| 600 |
if( !isset($_POST['reportmsg']) || !$_POST['reportmsg'] || !isset($_POST['postid']) || !$_POST['postid'] ){ |
| 601 |
WPF()->notice->add('Error: please insert some text to report.', 'error'); |
| 602 |
echo json_encode( WPF()->notice->get_notices() ); |
| 603 |
exit(); |
| 604 |
} |
| 605 |
|
| 606 |
############### Sending Email ################## |
| 607 |
$report_text = substr($_POST['reportmsg'], 0, 1000); |
| 608 |
$postid = intval($_POST['postid']); |
| 609 |
$reporter = '<a href="'.WPF()->current_user['profile_url'].'">'.(WPF()->current_user['display_name'] ? WPF()->current_user['display_name'] : urldecode(WPF()->current_user['user_nicename'])).'</a>'; |
| 610 |
$reportmsg = wpforo_kses($report_text, 'email'); |
| 611 |
$post_url = '<a target="_blank" href="'. esc_attr(WPF()->post->get_post_url($postid)).'">' . wpforo_phrase('Post link', false) . '»</a>'; |
| 612 |
|
| 613 |
$subject = WPF()->sbscrb->options['report_email_subject']; |
| 614 |
$message = WPF()->sbscrb->options['report_email_message']; |
| 615 |
|
| 616 |
$from_tags = array("[reporter]", "[message]", "[post_url]"); |
| 617 |
$to_words = array(sanitize_text_field($reporter), $reportmsg, $post_url); |
| 618 |
|
| 619 |
$subject = stripslashes(strip_tags(str_replace($from_tags, $to_words, $subject))); |
| 620 |
$message = stripslashes(str_replace($from_tags, $to_words, $message)); |
| 621 |
|
| 622 |
$admin_email = get_option( 'admin_email' ); |
| 623 |
$admin_emails = WPF()->sbscrb->options['admin_emails']; |
| 624 |
$admin_emails = trim($admin_emails); |
| 625 |
$admin_emails = explode(',', $admin_emails); |
| 626 |
$admin_emails = array_map('sanitize_email', $admin_emails); |
| 627 |
$admin_email = (isset($admin_emails[0]) && $admin_emails[0]) ? $admin_emails[0] : $admin_email; |
| 628 |
$headers = wpforo_admin_mail_headers(); |
| 629 |
|
| 630 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 631 |
if( wp_mail( $admin_email, $subject, $message, $headers ) ){ |
| 632 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 633 |
}else{ |
| 634 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 635 |
WPF()->notice->add('Can\'t send report email', 'error'); |
| 636 |
echo json_encode( WPF()->notice->get_notices() ); |
| 637 |
exit(); |
| 638 |
} |
| 639 |
|
| 640 |
############### Sending Email end ############## |
| 641 |
WPF()->notice->add('Message has been sent', 'success'); |
| 642 |
echo json_encode( WPF()->notice->get_notices() ); |
| 643 |
exit(); |
| 644 |
} |
| 645 |
|
| 646 |
add_action('wp_ajax_wpforo_sticky_ajax', 'wpf_sticky'); |
| 647 |
add_action('wp_ajax_nopriv_wpforo_sticky_ajax', 'wpf_sticky' ); |
| 648 |
function wpf_sticky(){ |
| 649 |
WPF()->notice->add('wrong data', 'error'); |
| 650 |
$response = array('stat' => 0, 'notice' => WPF()->notice->get_notices()); |
| 651 |
if( !isset($_POST['topicid']) || !( $topicid = wpforo_bigintval($_POST['topicid']) ) ){ |
| 652 |
echo json_encode($response); |
| 653 |
exit(); |
| 654 |
} |
| 655 |
$sql = "SELECT `forumid` FROM `".WPF()->tables->topics."` WHERE `topicid` = $topicid"; |
| 656 |
$forumid = WPF()->db->get_var($sql); |
| 657 |
if( !WPF()->perm->forum_can( 's', $forumid) ){ |
| 658 |
WPF()->notice->add('You don\'t have permission to do this action from this forum', 'error'); |
| 659 |
$response['notice'] = WPF()->notice->get_notices(); |
| 660 |
echo json_encode($response); |
| 661 |
exit(); |
| 662 |
} |
| 663 |
if( $_POST['status'] == 'sticky' ){ |
| 664 |
$sql = "UPDATE `".WPF()->tables->topics."` SET `type` = 1 WHERE `topicid` = $topicid"; |
| 665 |
if( false !== WPF()->db->query($sql) ){ |
| 666 |
WPF()->notice->add('Done!', 'success'); |
| 667 |
$response['notice'] = WPF()->notice->get_notices(); |
| 668 |
$response['stat'] = 1; |
| 669 |
} |
| 670 |
}elseif( $_POST['status'] == 'unsticky' ){ |
| 671 |
$sql = "UPDATE `".WPF()->tables->topics."` SET `type` = 0 WHERE `topicid` = $topicid"; |
| 672 |
if( false !== WPF()->db->query($sql) ){ |
| 673 |
WPF()->notice->add('Done!', 'success'); |
| 674 |
$response['notice'] = WPF()->notice->get_notices(); |
| 675 |
$response['stat'] = 1; |
| 676 |
} |
| 677 |
} |
| 678 |
wpforo_clean_cache('topic', $topicid); |
| 679 |
echo json_encode($response); |
| 680 |
exit(); |
| 681 |
} |
| 682 |
|
| 683 |
add_action('wp_ajax_wpforo_private_ajax', 'wpf_private'); |
| 684 |
function wpf_private(){ |
| 685 |
if(!is_user_logged_in()) return; |
| 686 |
if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); } |
| 687 |
$topic = wpforo_topic($p_id); |
| 688 |
if( $_POST['status'] == 'private' ){ |
| 689 |
$sql = "UPDATE ".WPF()->tables->topics." SET private = 1 WHERE topicid = " . intval($p_id); |
| 690 |
WPF()->db->query( $sql ); |
| 691 |
$sql = "UPDATE ".WPF()->tables->posts." SET private = 1 WHERE topicid = " . intval($p_id); |
| 692 |
WPF()->db->query( $sql ); |
| 693 |
WPF()->topic->last_topic($topic, 'remove'); |
| 694 |
}elseif( $_POST['status'] == 'public' ){ |
| 695 |
$sql = "UPDATE ".WPF()->tables->topics." SET private = 0 WHERE topicid = " . intval($p_id); |
| 696 |
WPF()->db->query( $sql ); |
| 697 |
$sql = "UPDATE ".WPF()->tables->posts." SET private = 0 WHERE topicid = " . intval($p_id); |
| 698 |
WPF()->db->query( $sql ); |
| 699 |
WPF()->topic->last_topic($topic, 'add'); |
| 700 |
} |
| 701 |
wpforo_clean_cache(); |
| 702 |
echo 1; |
| 703 |
exit(); |
| 704 |
} |
| 705 |
|
| 706 |
add_action('wp_ajax_wpforo_solved_ajax', 'wpf_solved'); |
| 707 |
add_action('wp_ajax_nopriv_wpforo_solved_ajax', 'wpf_solved' ); |
| 708 |
function wpf_solved(){ |
| 709 |
if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); } |
| 710 |
$post = WPF()->post->get_post($_POST['postid']); |
| 711 |
if( WPF()->perm->forum_can( 'sv', $post['forumid']) || WPF()->perm->forum_can( 'osv', $post['forumid']) ){ |
| 712 |
if( $_POST['status'] == 'solved' ){ |
| 713 |
$sql = "UPDATE ".WPF()->tables->posts." SET is_answer = 1 WHERE postid = " . intval($p_id); |
| 714 |
WPF()->db->query( $sql ); |
| 715 |
}elseif( $_POST['status'] == 'unsolved' ){ |
| 716 |
$sql = "UPDATE ".WPF()->tables->posts." SET is_answer = 0 WHERE postid = " . intval($p_id); |
| 717 |
WPF()->db->query( $sql ); |
| 718 |
} |
| 719 |
if( isset($post['topicid']) && $post['topicid'] ) wpforo_clean_cache('topic', $post['topicid']); |
| 720 |
echo 1; |
| 721 |
exit(); |
| 722 |
}else{ |
| 723 |
return; |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
add_action('wp_ajax_wpforo_approve_ajax', 'wpf_approved'); |
| 728 |
function wpf_approved(){ |
| 729 |
if(!is_user_logged_in()) return; |
| 730 |
if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); } |
| 731 |
$post = wpforo_post($p_id); |
| 732 |
if( $_POST['status'] == 'approve' ){ |
| 733 |
WPF()->post->status($p_id, 0); |
| 734 |
}elseif( $_POST['status'] == 'unapprove' ){ |
| 735 |
WPF()->post->status($p_id, 1); |
| 736 |
} |
| 737 |
wpforo_clean_cache('post', $p_id); |
| 738 |
echo 1; |
| 739 |
exit(); |
| 740 |
} |
| 741 |
|
| 742 |
add_action('wp_ajax_wpforo_close_ajax', 'wpf_close'); |
| 743 |
function wpf_close(){ |
| 744 |
if(!is_user_logged_in()) return; |
| 745 |
|
| 746 |
if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); } |
| 747 |
if( $_POST['status'] == 'closed' ){ |
| 748 |
$sql = "UPDATE ".WPF()->tables->topics." SET closed = 0 WHERE topicid = " . intval($p_id); |
| 749 |
WPF()->db->query( $sql ); |
| 750 |
wpforo_clean_cache('topic', $p_id); |
| 751 |
}elseif( $_POST['status'] == 'close' ){ |
| 752 |
$sql = "UPDATE ".WPF()->tables->topics." SET closed = 1 WHERE topicid = " . intval($p_id); |
| 753 |
WPF()->db->query( $sql ); |
| 754 |
wpforo_clean_cache('topic', $p_id); |
| 755 |
echo 1; |
| 756 |
exit(); |
| 757 |
} |
| 758 |
echo WPF()->topic->get_topic_url($p_id); |
| 759 |
exit(); |
| 760 |
} |
| 761 |
|
| 762 |
add_action('wp_ajax_wpforo_edit_ajax', 'wpf_edit'); |
| 763 |
add_action('wp_ajax_nopriv_wpforo_edit_ajax', 'wpf_edit' ); |
| 764 |
function wpf_edit(){ |
| 765 |
|
| 766 |
if( !isset($_POST['postid']) || !$_POST['postid'] ){ echo 0; exit(); } |
| 767 |
$sql = 'SELECT t.forumid AS forumid, t.title AS topic_title, p.title AS post_title, p.`body` |
| 768 |
FROM '.WPF()->tables->posts.' p |
| 769 |
INNER JOIN '.WPF()->tables->topics.' t ON t.topicid = p.topicid |
| 770 |
WHERE p.postid =' . intval($_POST['postid']); |
| 771 |
if($post = WPF()->db->get_row($sql, ARRAY_A) ){ |
| 772 |
if( WPF()->perm->forum_can('eor', $post['forumid']) || WPF()->perm->forum_can('eot', $post['forumid']) ){ |
| 773 |
$post = apply_filters('wpforo_edit_post_ajax', $post); |
| 774 |
$post['body'] = wpautop($post['body']); |
| 775 |
echo json_encode($post); |
| 776 |
exit(); |
| 777 |
} |
| 778 |
} |
| 779 |
echo 0; |
| 780 |
exit(); |
| 781 |
} |
| 782 |
|
| 783 |
add_action('wp_ajax_wpforo_delete_ajax', 'wpf_delete'); |
| 784 |
function wpf_delete(){ |
| 785 |
if(!is_user_logged_in()) return; |
| 786 |
|
| 787 |
$resp = array(); |
| 788 |
if( $_POST['status'] == 'topic' ){ |
| 789 |
if( WPF()->topic->delete(intval($_POST['postid'])) ){ |
| 790 |
$resp = array( |
| 791 |
'postid' => intval($_POST['postid']), |
| 792 |
'location' => WPF()->forum->get_forum_url(intval($_POST['forumid'])) |
| 793 |
); |
| 794 |
$return = 1; |
| 795 |
}else{ |
| 796 |
$return = 0; |
| 797 |
} |
| 798 |
}elseif($_POST['status'] == 'reply'){ |
| 799 |
if( WPF()->post->delete(intval($_POST['postid'])) ){ |
| 800 |
$resp = array( |
| 801 |
'postid' => intval($_POST['postid']) |
| 802 |
); |
| 803 |
$return = 1; |
| 804 |
}else{ |
| 805 |
$return = 0; |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
$resp['stat'] = $return; |
| 810 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 811 |
echo json_encode( $resp ); |
| 812 |
exit(); |
| 813 |
} |
| 814 |
|
| 815 |
add_action('wp_ajax_wpforo_subscribe_ajax', 'wpf_subscribe'); |
| 816 |
add_action('wp_ajax_nopriv_wpforo_subscribe_ajax', 'wpf_subscribe'); |
| 817 |
function wpf_subscribe(){ |
| 818 |
$resp = array('stat' => 0, 'notice' => WPF()->notice->get_notices()); |
| 819 |
$args = array( |
| 820 |
'itemid' => wpforo_bigintval($_POST['itemid']), |
| 821 |
'type' => sanitize_text_field($_POST['type']), |
| 822 |
'userid' => WPF()->current_userid, |
| 823 |
'active' => 0, |
| 824 |
'user_name' => '', |
| 825 |
'user_email' => '' |
| 826 |
); |
| 827 |
|
| 828 |
if( !WPF()->current_userid ){ |
| 829 |
if( WPF()->current_user_email ) $args['user_email'] = WPF()->current_user_email; |
| 830 |
if( WPF()->current_user_display_name ) $args['user_name'] = WPF()->current_user_display_name; |
| 831 |
} |
| 832 |
if( !$args['userid'] && !$args['user_email'] ) wp_send_json($resp); |
| 833 |
|
| 834 |
if(isset($_POST['status']) && $_POST['status'] == 'subscribe'){ |
| 835 |
|
| 836 |
if($_POST['type'] == 'forum'){ |
| 837 |
$forum = WPF()->forum->get_forum(wpforo_bigintval($_POST['itemid'])); |
| 838 |
if( isset($forum['forumid']) && $forum['forumid'] ){ |
| 839 |
if( !WPF()->perm->forum_can('vf', $forum['forumid']) ){ |
| 840 |
WPF()->notice->add('You are not permitted to subscribe here', 'error'); |
| 841 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 842 |
wp_send_json($resp); |
| 843 |
} |
| 844 |
} |
| 845 |
}elseif($_POST['type'] == 'topic'){ |
| 846 |
$topic = WPF()->db->get_row("SELECT * FROM `".WPF()->tables->topics."` WHERE `topicid` = " . intval($_POST['itemid']), ARRAY_A); |
| 847 |
if( isset($topic['forumid']) && $topic['forumid'] ){ |
| 848 |
if( isset($topic['private']) && $topic['private'] && !wpforo_is_owner($topic['userid'], $topic['email']) ){ |
| 849 |
if( !WPF()->perm->forum_can('vp', $topic['forumid']) ){ |
| 850 |
WPF()->notice->add('You are not permitted to subscribe here', 'error'); |
| 851 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 852 |
wp_send_json($resp); |
| 853 |
} |
| 854 |
} |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
$args['confirmkey'] = WPF()->sbscrb->get_confirm_key(); |
| 859 |
|
| 860 |
if( wpforo_feature('subscribe_conf') ){ |
| 861 |
############### Sending Email ################## |
| 862 |
$confirmlink = WPF()->sbscrb->get_confirm_link($args); |
| 863 |
$member_name = ( WPF()->current_userid ? wpforo_make_dname( WPF()->current_user['display_name'], WPF()->current_user['user_nicename'] ) : ( $args['user_name'] ? $args['user_name'] : $args['user_email'] ) ); |
| 864 |
if($_POST['type'] == 'forum'){ |
| 865 |
$item_title = $forum['title']; |
| 866 |
}elseif($_POST['type'] == 'topic'){ |
| 867 |
$item_title = $topic['title']; |
| 868 |
} |
| 869 |
$subject = WPF()->sbscrb->options['confirmation_email_subject']; |
| 870 |
$message = WPF()->sbscrb->options['confirmation_email_message']; |
| 871 |
$from_tags = array("[member_name]", "[entry_title]", "[confirm_link]"); |
| 872 |
$to_words = array(sanitize_text_field($member_name), '<strong>' . sanitize_text_field($item_title) . '</strong>', '<br><br><a href="' . esc_url($confirmlink) . '"> ' . wpforo_phrase('Confirm my subscription', false) . ' </a>'); |
| 873 |
$subject = stripslashes(strip_tags(str_replace($from_tags, $to_words, $subject))); |
| 874 |
$message = stripslashes(str_replace($from_tags, $to_words, $message)); |
| 875 |
$message = wpforo_kses($message, 'email'); |
| 876 |
|
| 877 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 878 |
$headers = wpforo_mail_headers(); |
| 879 |
|
| 880 |
if( wp_mail( WPF()->current_user_email , sanitize_text_field($subject), $message, $headers ) ){ |
| 881 |
if( WPF()->sbscrb->add($args) ){ |
| 882 |
$return = 1; |
| 883 |
}else{ |
| 884 |
$return = 0; |
| 885 |
} |
| 886 |
}else{ |
| 887 |
WPF()->notice->add('Can\'t send confirmation email', 'error'); |
| 888 |
$return = 0; |
| 889 |
} |
| 890 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 891 |
############### Sending Email end ############## |
| 892 |
} |
| 893 |
else{ |
| 894 |
$args['active'] = 1; |
| 895 |
if( WPF()->sbscrb->add($args) ){ |
| 896 |
$return = 1; |
| 897 |
}else{ |
| 898 |
$return = 0; |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
}elseif(isset($_POST['status']) && $_POST['status'] == 'unsubscribe'){ |
| 903 |
$subscribe = WPF()->sbscrb->get_subscribe( $args ); |
| 904 |
$return = (int) WPF()->sbscrb->delete( $subscribe['confirmkey'] ); |
| 905 |
} |
| 906 |
|
| 907 |
$resp['stat'] = $return; |
| 908 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 909 |
wp_send_json($resp); |
| 910 |
} |
| 911 |
|
| 912 |
############### Sending Email ################## |
| 913 |
function wpforo_set_html_content_type(){ |
| 914 |
return 'text/html'; |
| 915 |
} |
| 916 |
|
| 917 |
function wpforo_wp_mail_from_name($name){ |
| 918 |
if(isset(WPF()->sbscrb->options['from_name']) && WPF()->sbscrb->options['from_name']){ |
| 919 |
return WPF()->sbscrb->options['from_name']; |
| 920 |
} |
| 921 |
else{ |
| 922 |
return $name; |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
function wpforo_wp_mail_from_email($email){ |
| 927 |
if(isset(WPF()->sbscrb->options['from_email']) && WPF()->sbscrb->options['from_email']){ |
| 928 |
return WPF()->sbscrb->options['from_email']; |
| 929 |
} |
| 930 |
else{ |
| 931 |
return $email; |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
function wpforo_mail_from_name(){ |
| 936 |
if(isset(WPF()->sbscrb->options['from_name']) && WPF()->sbscrb->options['from_name']){ return WPF()->sbscrb->options['from_name']; } else {return get_option('blogname');} |
| 937 |
} |
| 938 |
|
| 939 |
function wpforo_mail_from_email(){ |
| 940 |
if(isset(WPF()->sbscrb->options['from_email']) && WPF()->sbscrb->options['from_email']){return WPF()->sbscrb->options['from_email'];} else {return get_option( 'admin_email' );} |
| 941 |
} |
| 942 |
|
| 943 |
function wpforo_mail_headers($from_name = '', $from_email = '', $cc = array(), $bcc = array()){ |
| 944 |
$H = array(); |
| 945 |
if(!$from_name) $from_name = wpforo_mail_from_name(); |
| 946 |
if(!$from_email) $from_email = wpforo_mail_from_email(); |
| 947 |
$H[] = 'From: ' . $from_name . ' <' . $from_email . '>'; |
| 948 |
if(!empty($cc)){ |
| 949 |
foreach($cc as $c){ $c = sanitize_email($c); $H[] = 'CC: ' . $c; } |
| 950 |
} |
| 951 |
if(!empty($bcc)){ |
| 952 |
foreach($bcc as $b){ $b = sanitize_email($b); $H[] = 'BCC: ' . $b; } |
| 953 |
} |
| 954 |
return $H; |
| 955 |
} |
| 956 |
|
| 957 |
function wpforo_admin_mail_headers($from_name = '', $from_email = '', $cc = array(), $bcc = array()){ |
| 958 |
$H = array(); |
| 959 |
if(!$from_name) $from_name = wpforo_mail_from_name(); |
| 960 |
if(!$from_email) $from_email = wpforo_mail_from_email(); |
| 961 |
$H[] = 'From: ' . $from_name . ' <' . $from_email . '>'; |
| 962 |
if(empty($cc)){ |
| 963 |
$cc = trim(WPF()->sbscrb->options['admin_emails']); |
| 964 |
$cc = explode(',', $cc); |
| 965 |
$cc = array_map('trim', $cc); |
| 966 |
} |
| 967 |
if(!empty($cc)){ |
| 968 |
foreach($cc as $c){ $c = sanitize_email($c); $H[] = 'CC: ' . $c; } |
| 969 |
} |
| 970 |
if(!empty($bcc)){ |
| 971 |
foreach($bcc as $b){ $b = sanitize_email($b); $H[] = 'BCC: ' . $b; } |
| 972 |
} |
| 973 |
return $H; |
| 974 |
} |
| 975 |
|
| 976 |
############### Sending Email end ############## |
| 977 |
|
| 978 |
function wpforo_frontend_enqueue(){ |
| 979 |
if( (is_wpforo_page() && wpforo_feature('font-awesome') == 1) || wpforo_feature('font-awesome') == 2 ){ |
| 980 |
wp_register_style('wpforo-font-awesome', WPFORO_URL . '/wpf-assets/css/font-awesome/css/fontawesome-all.min.css', false, '5.0.6' ); |
| 981 |
wp_enqueue_style('wpforo-font-awesome'); |
| 982 |
if (is_rtl()) { |
| 983 |
wp_register_style('wpforo-font-awesome-rtl', WPFORO_URL . '/wpf-assets/css/font-awesome/css/font-awesome-rtl.css', false, WPFORO_VERSION ); |
| 984 |
wp_enqueue_style('wpforo-font-awesome-rtl'); |
| 985 |
} |
| 986 |
} |
| 987 |
if( is_wpforo_page() ){ |
| 988 |
wp_enqueue_script('jquery-ui-core'); |
| 989 |
wp_enqueue_script('jquery-ui-dialog'); |
| 990 |
wp_register_script( 'wpforo-frontend-js', WPFORO_URL . '/wpf-assets/js/frontend.js', array('jquery'), WPFORO_VERSION, false ); |
| 991 |
wp_enqueue_script('wpforo-frontend-js'); |
| 992 |
wp_localize_script('wpforo-frontend-js', 'wpforo_phrases', WPF()->phrase->__phrases); |
| 993 |
wp_register_script('wpforo-ajax', WPFORO_URL . '/wpf-assets/js/ajax.js', array('jquery'), WPFORO_VERSION, false); |
| 994 |
wp_enqueue_script('wpforo-ajax'); |
| 995 |
wp_localize_script('wpforo-ajax', 'wpf_ajax_obj', array( 'url' => admin_url('admin-ajax.php') )); |
| 996 |
if (is_rtl()) { |
| 997 |
wp_register_style('wpforo-style-rtl', WPFORO_TEMPLATE_URL . '/style-rtl.css', false, WPFORO_VERSION ); |
| 998 |
wp_enqueue_style('wpforo-style-rtl'); |
| 999 |
} |
| 1000 |
else{ |
| 1001 |
wp_register_style('wpforo-style', WPFORO_TEMPLATE_URL . '/style.css', false, WPFORO_VERSION ); |
| 1002 |
wp_enqueue_style('wpforo-style'); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
if (is_rtl()) { |
| 1007 |
wp_register_style('wpforo-widgets-rtl', WPFORO_TEMPLATE_URL . '/widgets-rtl.css', false, WPFORO_VERSION ); |
| 1008 |
wp_enqueue_style('wpforo-widgets-rtl'); |
| 1009 |
} |
| 1010 |
else{ |
| 1011 |
wp_register_style('wpforo-widgets', WPFORO_TEMPLATE_URL . '/widgets.css', false, WPFORO_VERSION ); |
| 1012 |
wp_enqueue_style('wpforo-widgets'); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
add_action('wp_enqueue_scripts', 'wpforo_frontend_enqueue'); |
| 1016 |
|
| 1017 |
function wpforo_add_into_wp_head(){ |
| 1018 |
if(!WPF()->perm->forum_can('va')){ |
| 1019 |
?> |
| 1020 |
<script type="text/javascript"> |
| 1021 |
jQuery(document).ready(function($){ |
| 1022 |
var wpforo_wrap = $('#wpforo-wrap'); |
| 1023 |
$(wpforo_wrap).on('click','.attach_cant_view', function(){ |
| 1024 |
wpforo_notice_show("<p><?php echo addslashes( ( is_user_logged_in() ? WPF()->post->options['attach_cant_view_msg'] : sprintf( wpforo_phrase('Please %s or %s', FALSE), '<a href="' . wpforo_login_url() . '">'.wpforo_phrase('Login', FALSE).'</a>', '<a href="' . wpforo_register_url() . '">'.wpforo_phrase('Register', FALSE).'</a>' ) ) ) ?></p>"); |
| 1025 |
}); |
| 1026 |
}); |
| 1027 |
</script> |
| 1028 |
<?php |
| 1029 |
} |
| 1030 |
} |
| 1031 |
add_action('wp_head', 'wpforo_add_into_wp_head'); |
| 1032 |
|
| 1033 |
function wpforo_dynamic_style() { |
| 1034 |
|
| 1035 |
if(!is_wpforo_page()) return false; |
| 1036 |
|
| 1037 |
$inline = false; |
| 1038 |
$dynamic_css_file = WPFORO_TEMPLATE_DIR . '/colors.css'; |
| 1039 |
$dynamic_css_matrix = WPFORO_TEMPLATE_DIR . '/styles/css.php'; |
| 1040 |
if( isset(WPF()->tpl->options) ){ |
| 1041 |
if( !isset(WPF()->tpl->options['style']) || !isset(WPF()->tpl->options['styles']) ) return false; |
| 1042 |
$style = WPF()->tpl->options['style']; |
| 1043 |
$styles = WPF()->tpl->options['styles']; |
| 1044 |
if( !empty($style) && !empty($styles) ){ |
| 1045 |
foreach( $styles[$style] as $color_key => $color_value ){ |
| 1046 |
if( $color_value ) { |
| 1047 |
$COLORS[ 'WPFCOLOR_' . $color_key ] = $color_value; |
| 1048 |
} |
| 1049 |
} |
| 1050 |
} |
| 1051 |
else{ |
| 1052 |
return false; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
else{ |
| 1056 |
return false; |
| 1057 |
} |
| 1058 |
extract($COLORS, EXTR_OVERWRITE); |
| 1059 |
if( file_exists( $dynamic_css_matrix ) ){ |
| 1060 |
require_once( $dynamic_css_matrix ); |
| 1061 |
$css = apply_filters('wpforo_dynamic_css_filter', $css, $COLORS); |
| 1062 |
} |
| 1063 |
else{ |
| 1064 |
return false; |
| 1065 |
} |
| 1066 |
$hach_new = md5($css); |
| 1067 |
if( file_exists( $dynamic_css_file ) && filesize($dynamic_css_file) ){ |
| 1068 |
$css_current = wpforo_get_file_content( $dynamic_css_file ); |
| 1069 |
if( $css_current ){ |
| 1070 |
$hach_current = md5($css_current); |
| 1071 |
if( $hach_new == $hach_current ){ |
| 1072 |
//CSS not changed |
| 1073 |
} |
| 1074 |
else{ |
| 1075 |
$result = wpforo_write_file( $dynamic_css_file, $css ); |
| 1076 |
if( isset($result['error']) && $result['error'] ){ |
| 1077 |
$inline = true; |
| 1078 |
} |
| 1079 |
else{ |
| 1080 |
//CSS updated |
| 1081 |
} |
| 1082 |
} |
| 1083 |
} |
| 1084 |
} |
| 1085 |
else{ |
| 1086 |
$result = wpforo_write_file( $dynamic_css_file, $css ); |
| 1087 |
if( isset($result['error']) && $result['error'] ){ |
| 1088 |
$inline = true; |
| 1089 |
} |
| 1090 |
} |
| 1091 |
if( $inline ){ |
| 1092 |
$css = preg_replace('|[\r\n\t]+|', '', $css ); |
| 1093 |
wp_add_inline_style( 'wpforo-dynamic-style', $css ); |
| 1094 |
} |
| 1095 |
} |
| 1096 |
add_action( 'wp_enqueue_scripts', 'wpforo_dynamic_style', 12 ); |
| 1097 |
|
| 1098 |
function wpforo_style_options($css, $COLORS){ |
| 1099 |
if( !isset($css)) return ''; |
| 1100 |
if( isset(WPF()->tpl->style['font_size_forum']) && WPF()->tpl->style['font_size_forum'] != 17 ){ |
| 1101 |
$css .= "\r\n#wpforo-wrap .wpforo-forum-title{font-size: " . intval(WPF()->tpl->style['font_size_forum']) . "px!important; line-height: " . (intval(WPF()->tpl->style['font_size_forum']) + 1) . "px!important;}"; |
| 1102 |
} |
| 1103 |
if( isset(WPF()->tpl->style['font_size_topic']) && WPF()->tpl->style['font_size_topic'] != 16 ){ |
| 1104 |
$css .= "\r\n#wpforo-wrap .wpforo-topic-title a { font-size: " . intval(WPF()->tpl->style['font_size_topic']) . "px!important; line-height: " . (intval(WPF()->tpl->style['font_size_topic']) + 4) . "px!important; }"; |
| 1105 |
} |
| 1106 |
if( isset(WPF()->tpl->style['font_size_post_content']) && WPF()->tpl->style['font_size_post_content'] != 14 ){ |
| 1107 |
$css .= "\r\n#wpforo-wrap .wpforo-post .wpf-right .wpforo-post-content {font-size: " . intval(WPF()->tpl->style['font_size_post_content']) . "px!important; line-height: " . (intval(WPF()->tpl->style['font_size_post_content']) + 4) . "px!important;}\r\n#wpforo-wrap .wpforo-post .wpf-right .wpforo-post-content p {font-size: " . intval(WPF()->tpl->style['font_size_post_content']) . "px;}"; |
| 1108 |
} |
| 1109 |
if( isset(WPF()->tpl->style['custom_css']) ){ |
| 1110 |
$css .= "\r\n" . stripslashes(WPF()->tpl->style['custom_css']); |
| 1111 |
} |
| 1112 |
return $css; |
| 1113 |
} |
| 1114 |
add_filter( 'wpforo_dynamic_css_filter' , 'wpforo_style_options' , 10, 2 ); |
| 1115 |
|
| 1116 |
function wpforo_admin_enqueue(){ |
| 1117 |
$phrases = array( |
| 1118 |
'move' => __('Move', 'wpforo'), |
| 1119 |
'delete' => __('Delete', 'wpforo') |
| 1120 |
); |
| 1121 |
if( !empty($_GET['page']) && FALSE !== strpos( $_GET['page'], 'wpforo' ) ){ |
| 1122 |
if( wpforo_feature( 'font-awesome') ){ |
| 1123 |
wp_register_style('wpforo-font-awesome', WPFORO_URL . '/wpf-assets/css/font-awesome/css/fontawesome-all.min.css', false, '5.0.6' ); |
| 1124 |
wp_enqueue_style('wpforo-font-awesome'); |
| 1125 |
} |
| 1126 |
wp_register_style('wpforo-admin', WPFORO_URL . '/wpf-admin/css/admin.css', false, WPFORO_VERSION ); |
| 1127 |
wp_enqueue_style('wpforo-admin'); |
| 1128 |
wp_enqueue_script('jquery'); |
| 1129 |
wp_enqueue_script('jquery-ui-core'); |
| 1130 |
wp_enqueue_script('jquery-ui-widget'); |
| 1131 |
wp_enqueue_script('jquery-ui-mouse'); |
| 1132 |
wp_enqueue_script('jquery-ui-position'); |
| 1133 |
wp_enqueue_script('jquery-ui-draggable'); |
| 1134 |
wp_enqueue_script('jquery-ui-droppable'); |
| 1135 |
wp_enqueue_script('jquery-ui-menu'); |
| 1136 |
wp_enqueue_script('jquery-ui-sortable'); |
| 1137 |
wp_enqueue_script('jquery-color'); |
| 1138 |
wp_enqueue_script('wp-lists'); |
| 1139 |
if( $_GET['page'] == 'wpforo-forums' ){ |
| 1140 |
if( !empty($_GET['action']) ){ |
| 1141 |
//Just for excluding 'nav-menu' js loading// |
| 1142 |
wp_enqueue_script('postbox'); |
| 1143 |
wp_enqueue_script('link'); |
| 1144 |
} |
| 1145 |
else{ |
| 1146 |
wp_enqueue_script('nav-menu'); |
| 1147 |
} |
| 1148 |
} |
| 1149 |
elseif( $_GET['page'] == 'wpforo-settings' && !empty($_GET['tab']) && $_GET['tab'] == 'styles' ){ |
| 1150 |
wp_enqueue_style('wp-color-picker'); |
| 1151 |
wp_enqueue_script('iris', admin_url('js/iris.min.js'),array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), false, 1); |
| 1152 |
wp_enqueue_script('wp-color-picker', admin_url('js/color-picker.min.js'), array('iris'), false,1); |
| 1153 |
$colorpicker_l10n = array('clear' => __('Clear'), 'defaultString' => __('Default'), 'pick' => __('Select Color')); |
| 1154 |
wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', $colorpicker_l10n ); |
| 1155 |
} |
| 1156 |
elseif( $_GET['page'] == 'wpforo-community' ){ |
| 1157 |
wp_enqueue_script('postbox'); |
| 1158 |
wp_enqueue_script('link'); |
| 1159 |
} |
| 1160 |
elseif( $_GET['page'] == 'wpforo-addons' ){ |
| 1161 |
wp_register_script( 'wpforo-contenthover', WPFORO_URL . '/wpf-admin/js/contenthover/jquery.contenthover.min.js', array('jquery'), WPFORO_VERSION, false ); |
| 1162 |
wp_enqueue_script( 'wpforo-contenthover' ); |
| 1163 |
} |
| 1164 |
wp_register_script( 'wpforo-contenthover', WPFORO_URL . '/wpf-admin/js/functions.js', array('jquery'), WPFORO_VERSION, false ); |
| 1165 |
wp_enqueue_script( 'wpforo-contenthover' ); |
| 1166 |
wp_localize_script( 'wpforo-contenthover', 'wpforo_admin', array('phrases' => $phrases) ); |
| 1167 |
|
| 1168 |
} |
| 1169 |
} |
| 1170 |
add_action( 'admin_enqueue_scripts', 'wpforo_admin_enqueue' ); |
| 1171 |
|
| 1172 |
function wpforo_admin_permalink_notice() { |
| 1173 |
$permalink_structure = get_option( 'permalink_structure' ); |
| 1174 |
if( !$permalink_structure ){ |
| 1175 |
$class = 'notice notice-warning'; |
| 1176 |
$message = __( 'IMPORTANT: wpForo can\'t work with default permalink, please change permalink structure', 'wpforo' ); |
| 1177 |
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); |
| 1178 |
} |
| 1179 |
|
| 1180 |
} |
| 1181 |
add_action( 'admin_notices', 'wpforo_admin_permalink_notice' ); |
| 1182 |
|
| 1183 |
function wpforo_userform_to_wpuser_html_form($wp_user){ |
| 1184 |
if( is_super_admin() ){ |
| 1185 |
if( is_object($wp_user) ){ |
| 1186 |
$user = WPF()->member->get_member($wp_user->ID); |
| 1187 |
$groupid = $user['groupid']; |
| 1188 |
$timezone = $user['timezone']; |
| 1189 |
} |
| 1190 |
if( !isset($groupid) ) $groupid = 0; |
| 1191 |
if( !isset($timezone) ) $timezone = ''; |
| 1192 |
|
| 1193 |
echo '<table class="form-table"> |
| 1194 |
<tr class="form-field"> |
| 1195 |
<th scope="row"><label for="wpforo_usergroup">' . __('wpForo Usergroup', 'wpforo') . '</label></th> |
| 1196 |
<td> |
| 1197 |
<select name="wpforo_usergroup" id="wpforo_usergroup">'; |
| 1198 |
WPF()->usergroup->show_selectbox($groupid); |
| 1199 |
echo ' </select> |
| 1200 |
</td> |
| 1201 |
</tr> |
| 1202 |
<tr class="form-field"> |
| 1203 |
<th scope="row"><label for="wpforo_usertimezone">' . __('wpForo User Timezone', 'wpforo') . '</label></th> |
| 1204 |
<td> |
| 1205 |
<select name="wpforo_usertimezone" id="wpforo_usertimezone"> |
| 1206 |
' . wp_timezone_choice($timezone) . |
| 1207 |
'</select> |
| 1208 |
</td> |
| 1209 |
</tr> |
| 1210 |
</table>'; |
| 1211 |
|
| 1212 |
} |
| 1213 |
} |
| 1214 |
add_action( 'user_new_form', 'wpforo_userform_to_wpuser_html_form' ); |
| 1215 |
add_action( 'show_user_profile', 'wpforo_userform_to_wpuser_html_form' ); |
| 1216 |
add_action( 'edit_user_profile', 'wpforo_userform_to_wpuser_html_form' ); |
| 1217 |
|
| 1218 |
function wpforo_do_hook_user_register($userid){ |
| 1219 |
WPF()->member->synchronize_user($userid); |
| 1220 |
} |
| 1221 |
add_action( 'user_register', 'wpforo_do_hook_user_register', 10, 1 ); |
| 1222 |
|
| 1223 |
function wpforo_do_hook_update_profile($userid){ |
| 1224 |
if( isset($_POST['wpforo_usergroup']) && $_POST['wpforo_usergroup'] ){ |
| 1225 |
WPF()->member->edit_profile( array( 'userid' => intval($userid), |
| 1226 |
'groupid' => intval($_POST['wpforo_usergroup']), |
| 1227 |
'site' => esc_url($_POST['url']), |
| 1228 |
'about' => wpforo_kses($_POST['description'], 'user_description'), |
| 1229 |
'timezone' => ( isset($_POST['wpforo_usertimezone']) ? sanitize_text_field($_POST['wpforo_usertimezone']) : '' ) ) ); |
| 1230 |
} |
| 1231 |
WPF()->member->reset($userid); |
| 1232 |
} |
| 1233 |
add_action('personal_options_update', 'wpforo_do_hook_update_profile'); |
| 1234 |
add_action('edit_user_profile_update', 'wpforo_do_hook_update_profile'); |
| 1235 |
|
| 1236 |
function wpforo_update_last_login_date($user_login, $user = array()){ |
| 1237 |
if(empty($user)) return; |
| 1238 |
WPF()->member->edit_profile( array( 'userid' => intval($user->ID), 'last_login' => current_time( 'mysql', 1 ) ) ); |
| 1239 |
} |
| 1240 |
add_action('wp_login', 'wpforo_update_last_login_date', 10, 2); |
| 1241 |
|
| 1242 |
function wpforo_do_hook_deleted_user($userid){ |
| 1243 |
if( !empty($_REQUEST['wpforo_user_delete_option']) && $_REQUEST['wpforo_user_delete_option'] == 'reassign' && !empty($_REQUEST['wpforo_reassign_user']) ){ |
| 1244 |
WPF()->member->delete( $userid, $_REQUEST['wpforo_reassign_user'] ); |
| 1245 |
}else{ |
| 1246 |
WPF()->member->delete( $userid ); |
| 1247 |
} |
| 1248 |
WPF()->notice->clear(); |
| 1249 |
} |
| 1250 |
add_action( 'deleted_user', 'wpforo_do_hook_deleted_user' ); |
| 1251 |
|
| 1252 |
function wpforo_avatar( $avatar, $id_or_email, $size, $default, $alt ) { |
| 1253 |
if(!wpforo_feature('replace-avatar')) return $avatar; |
| 1254 |
$user = false; |
| 1255 |
if ( is_numeric( $id_or_email ) ) { |
| 1256 |
$id = (int) $id_or_email; |
| 1257 |
$user = get_user_by( 'id' , $id ); |
| 1258 |
}elseif( is_object( $id_or_email ) ) { |
| 1259 |
if ( ! empty( $id_or_email->user_id ) ) { |
| 1260 |
$id = (int) $id_or_email->user_id; |
| 1261 |
$user = get_user_by( 'id' , $id ); |
| 1262 |
} |
| 1263 |
elseif ( ! empty( $id_or_email->ID ) ) { |
| 1264 |
$id = (int) $id_or_email->ID; |
| 1265 |
$user = get_user_by( 'id' , $id ); |
| 1266 |
} |
| 1267 |
}else{ |
| 1268 |
$user = get_user_by( 'email', $id_or_email ); |
| 1269 |
} |
| 1270 |
|
| 1271 |
if( $user && is_object( $user ) ){ |
| 1272 |
if( $src = WPF()->member->get_avatar_url($user->data->ID) ){ |
| 1273 |
$avatar = "<img alt='" . esc_attr($alt) . "' src='" . esc_url($src) . "' class='avatar avatar-" . esc_attr($size) . " photo' height='" . esc_attr($size) . "' width='" . esc_attr($size) . "' />"; |
| 1274 |
} |
| 1275 |
} |
| 1276 |
return $avatar; |
| 1277 |
} |
| 1278 |
add_filter( 'get_avatar' , 'wpforo_avatar' , 10, 5 ); |
| 1279 |
|
| 1280 |
function wpforo_mention_nickname_to_link($match){ |
| 1281 |
$return = $match[0]; |
| 1282 |
if( $member = WPF()->member->get_member($match[1]) ){ |
| 1283 |
$href = WPF()->member->profile_url($member); |
| 1284 |
$dname = wpforo_make_dname($member['display_name'], $member['user_nicename']); |
| 1285 |
$return = sprintf('<a href="%s" title="%s">@%s</a>%s', $href, $dname, $match[1], $match[2]); |
| 1286 |
} |
| 1287 |
|
| 1288 |
return $return; |
| 1289 |
} |
| 1290 |
|
| 1291 |
function wpforo_mentioned_code_to_link($text){ |
| 1292 |
//$text = htmlspecialchars_decode($text); |
| 1293 |
$text = preg_replace_callback('#@([^\r\n\t\s\0<>\[\]!,\.\(\)\'\"\|\?\@]+)($|[\r\n\t\s\0<>\[\]!,\.\(\)\'\"\|\?\@])#isu', 'wpforo_mention_nickname_to_link', $text); |
| 1294 |
return $text; |
| 1295 |
} |
| 1296 |
add_filter('wpforo_body_text_filter', 'wpforo_mentioned_code_to_link'); |
| 1297 |
|
| 1298 |
function wpforo_send_mail_to_mentioned_users($item){ |
| 1299 |
if( !WPF()->sbscrb->options['user_mention_notify'] ) return false; |
| 1300 |
$return = false; |
| 1301 |
$body = strip_tags($item['body']); |
| 1302 |
if( preg_match_all('#@([^\r\n\t\s\0<>\[\]!,\.\(\)\'\"\|\?\@]+)(?:$|[\r\n\t\s\0<>\[\]!,\.\(\)\'\"\|\?\@])#isu', $body, $matches, PREG_SET_ORDER) ){ |
| 1303 |
|
| 1304 |
$dname = wpforo_make_dname( WPF()->current_user['display_name'], WPF()->current_user['user_nicename'] ); |
| 1305 |
$_to_words = array($dname); |
| 1306 |
if( array_key_exists('first_postid', $item) ){ |
| 1307 |
$_to_words[] = $item['title']; |
| 1308 |
$_to_words[] = $item['topicurl']; |
| 1309 |
}else{ |
| 1310 |
$_to_words[] = wpforo_topic($item['topicid'], 'title'); |
| 1311 |
$_to_words[] = $item['posturl']; |
| 1312 |
} |
| 1313 |
|
| 1314 |
$_subject = WPF()->sbscrb->options['user_mention_email_subject']; |
| 1315 |
$_message = WPF()->sbscrb->options['user_mention_email_message']; |
| 1316 |
$_from_tags = array("[author-user-name]", "[topic-title]", "[post-url]"); |
| 1317 |
$_subject = str_replace($_from_tags, $_to_words, $_subject); |
| 1318 |
$_message = str_replace($_from_tags, $_to_words, $_message); |
| 1319 |
|
| 1320 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1321 |
$headers = wpforo_mail_headers(); |
| 1322 |
|
| 1323 |
foreach ( $matches as $match ){ |
| 1324 |
$member = WPF()->member->get_member($match[1]); |
| 1325 |
if( !empty($member['user_email']) ){ |
| 1326 |
|
| 1327 |
if( WPF()->current_userid == $member['userid'] ) continue; |
| 1328 |
|
| 1329 |
if( in_array($member['user_email'], WPF()->sbscrb->already_sent_emails) ) continue; |
| 1330 |
|
| 1331 |
if( isset($item['private']) && $item['private'] ){ |
| 1332 |
if( !WPF()->perm->forum_can('vp', $item['forumid'], $member['groupid']) ) continue; |
| 1333 |
} |
| 1334 |
if( isset($item['status']) && $item['status'] ){ |
| 1335 |
if( !WPF()->perm->forum_can('au', $item['forumid'], $member['groupid']) ) continue; |
| 1336 |
} |
| 1337 |
|
| 1338 |
$dname = wpforo_make_dname($member['display_name'], $member['user_nicename']); |
| 1339 |
$subject = stripslashes(str_replace('[mentioned-user-name]', $dname, $_subject)); |
| 1340 |
$message = stripslashes(str_replace('[mentioned-user-name]', $dname, $_message)); |
| 1341 |
$message = wpforo_kses($message, 'email'); |
| 1342 |
|
| 1343 |
if( $return = wp_mail( $member['user_email'], sanitize_text_field($subject), $message, $headers ) ){ |
| 1344 |
WPF()->sbscrb->already_sent_emails[] = $member['user_email']; |
| 1345 |
} |
| 1346 |
} |
| 1347 |
} |
| 1348 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1349 |
|
| 1350 |
} |
| 1351 |
|
| 1352 |
return $return; |
| 1353 |
} |
| 1354 |
add_action( 'wpforo_after_add_topic', 'wpforo_send_mail_to_mentioned_users' ); |
| 1355 |
add_action( 'wpforo_after_add_post', 'wpforo_send_mail_to_mentioned_users' ); |
| 1356 |
|
| 1357 |
function wpforo_topic_auto_subscribe($item){ |
| 1358 |
if(!isset($_POST['wpforo_topic_subs']) || !$_POST['wpforo_topic_subs'] ) return FALSE; |
| 1359 |
|
| 1360 |
if( isset($item['forumid']) && $item['forumid'] ){ |
| 1361 |
if( isset($item['private']) && $item['private'] && !wpforo_is_owner($item['userid']) ){ |
| 1362 |
if( !WPF()->perm->forum_can('vp', $item['forumid']) ){ |
| 1363 |
WPF()->notice->add('You are not permitted to subscribe here', 'error'); |
| 1364 |
return FALSE; |
| 1365 |
} |
| 1366 |
} |
| 1367 |
else{ |
| 1368 |
//This is not a Private Topic or Current User is the owner. |
| 1369 |
} |
| 1370 |
} |
| 1371 |
else{ |
| 1372 |
WPF()->notice->add('Forum ID is not detected', 'error'); |
| 1373 |
return FALSE; |
| 1374 |
} |
| 1375 |
|
| 1376 |
$args = array( |
| 1377 |
'itemid' => wpforo_bigintval($item['topicid']), |
| 1378 |
'type' => 'topic', |
| 1379 |
'userid' => WPF()->current_userid, |
| 1380 |
'user_name' => '', |
| 1381 |
'user_email' => '' |
| 1382 |
); |
| 1383 |
|
| 1384 |
if( !WPF()->current_userid ){ |
| 1385 |
if( WPF()->current_user_email ) $args['user_email'] = WPF()->current_user_email; |
| 1386 |
if( WPF()->current_user_display_name ) $args['user_name'] = WPF()->current_user_display_name; |
| 1387 |
} |
| 1388 |
if( !$args['userid'] && !$args['user_email'] ) return false; |
| 1389 |
|
| 1390 |
$args['confirmkey'] = WPF()->sbscrb->get_confirm_key(); |
| 1391 |
|
| 1392 |
if( wpforo_feature('subscribe_conf') ){ |
| 1393 |
############### Sending Email ################## |
| 1394 |
$confirmlink = WPF()->sbscrb->get_confirm_link($args); |
| 1395 |
$member_name = ( WPF()->current_userid ? wpforo_make_dname( WPF()->current_user['display_name'], WPF()->current_user['user_nicename'] ) : ( $args['user_name'] ? $args['user_name'] : $args['user_email'] ) ); |
| 1396 |
$subject = WPF()->sbscrb->options['confirmation_email_subject']; |
| 1397 |
$message = WPF()->sbscrb->options['confirmation_email_message']; |
| 1398 |
$topic = WPF()->db->get_row("SELECT * FROM `".WPF()->tables->topics."` WHERE `topicid` = " . intval($item['topicid']), ARRAY_A); |
| 1399 |
$from_tags = array("[member_name]", "[entry_title]", "[confirm_link]"); |
| 1400 |
$to_words = array(sanitize_text_field($member_name), '<strong>' . sanitize_text_field($topic['title']) . '</strong>', '<br><br><a href="' . esc_url($confirmlink) . '"> ' . wpforo_phrase('Confirm my subscription', false) . ' </a>'); |
| 1401 |
$subject = stripslashes(str_replace($from_tags, $to_words, $subject)); |
| 1402 |
$message = stripslashes(str_replace($from_tags, $to_words, $message)); |
| 1403 |
$message = wpforo_kses($message, 'email'); |
| 1404 |
|
| 1405 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1406 |
$headers = wpforo_mail_headers(); |
| 1407 |
|
| 1408 |
if( wp_mail( WPF()->current_user_email, sanitize_text_field($subject), $message, $headers ) ){ |
| 1409 |
if( $response = WPF()->sbscrb->add($args) ) return $response; |
| 1410 |
}else{ |
| 1411 |
WPF()->notice->add('Can\'t send confirmation email', 'error'); |
| 1412 |
return FALSE; |
| 1413 |
} |
| 1414 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1415 |
############### Sending Email end ############## |
| 1416 |
}else{ |
| 1417 |
$args['active'] = 1; |
| 1418 |
if( $response = WPF()->sbscrb->add($args) ) return $response; |
| 1419 |
} |
| 1420 |
return FALSE; |
| 1421 |
} |
| 1422 |
add_action( 'wpforo_after_add_topic', 'wpforo_topic_auto_subscribe' ); |
| 1423 |
add_action( 'wpforo_after_add_post', 'wpforo_topic_auto_subscribe' ); |
| 1424 |
|
| 1425 |
function wpforo_forum_subscribers_mail_sender( $topic ){ |
| 1426 |
|
| 1427 |
if( defined('IS_GO2WPFORO') && IS_GO2WPFORO ) return; |
| 1428 |
|
| 1429 |
$forums_sbs = WPF()->sbscrb->get_subscribes( array( 'itemid' => 0, 'type' => array('forums', 'forums-topics') ) ); |
| 1430 |
$forum_sbs = WPF()->sbscrb->get_subscribes( array( 'itemid' => $topic['forumid'], 'type' => array('forum', 'forum-topic') ) ); |
| 1431 |
$subscribers = array_merge($forums_sbs, $forum_sbs); |
| 1432 |
if( WPF()->sbscrb->options['new_topic_notify'] ){ |
| 1433 |
$admin_emails = explode(',', WPF()->sbscrb->options['admin_emails']); |
| 1434 |
foreach( $admin_emails as $admin_email ) $subscribers[] = sanitize_email( $admin_email ); |
| 1435 |
} |
| 1436 |
|
| 1437 |
$subscribers = apply_filters('wpforo_forum_subscribers', $subscribers); |
| 1438 |
|
| 1439 |
foreach($subscribers as $subscriber){ |
| 1440 |
|
| 1441 |
if( is_array($subscriber) ){ |
| 1442 |
if( $subscriber['userid'] ){ |
| 1443 |
$member = WPF()->member->get_member( $subscriber['userid'] ); |
| 1444 |
}elseif( $subscriber['user_email'] ){ |
| 1445 |
$member = array('groupid' => 4, 'display_name' => ($subscriber['user_name'] ? $subscriber['user_name'] : $subscriber['user_email']), 'user_email' => $subscriber['user_email']); |
| 1446 |
}else{ |
| 1447 |
continue; |
| 1448 |
} |
| 1449 |
$unsubscribe_link = WPF()->sbscrb->get_unsubscribe_link($subscriber['confirmkey']); |
| 1450 |
}else{ |
| 1451 |
$member = array('display_name' => $subscriber, 'user_email' => $subscriber); |
| 1452 |
$unsubscribe_link = '#'; |
| 1453 |
} |
| 1454 |
|
| 1455 |
if( isset($topic['forumid']) && $topic['forumid'] ){ |
| 1456 |
if( isset($topic['private']) && $topic['private'] && isset($subscriber['userid']) |
| 1457 |
&& ( ( $topic['userid'] && $subscriber['userid'] && $topic['userid'] != $subscriber['userid'] ) |
| 1458 |
|| ( $topic['email'] && $subscriber['user_email'] && $topic['email'] != $subscriber['user_email'] ) ) ){ |
| 1459 |
$subscriber_groupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : WPF()->usergroup->get_groupid_by_userid($subscriber['userid']); |
| 1460 |
if( !WPF()->perm->forum_can('vp', $topic['forumid'], $subscriber_groupid) ){ |
| 1461 |
continue; |
| 1462 |
} |
| 1463 |
} |
| 1464 |
if( isset($topic['status']) && $topic['status'] == 1 && isset($subscriber['userid']) ){ |
| 1465 |
$subscriber_groupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : WPF()->usergroup->get_groupid_by_userid($subscriber['userid']); |
| 1466 |
if( !WPF()->perm->forum_can('au', $topic['forumid'], $subscriber_groupid) ){ |
| 1467 |
continue; |
| 1468 |
} |
| 1469 |
} |
| 1470 |
} |
| 1471 |
|
| 1472 |
$owner = wpforo_member( $topic ); |
| 1473 |
|
| 1474 |
if($owner['user_email'] == $member['user_email']) continue; |
| 1475 |
if( in_array($member['user_email'], WPF()->sbscrb->already_sent_emails) ) continue; |
| 1476 |
|
| 1477 |
$forum = WPF()->forum->get_forum( $topic['forumid'] ); |
| 1478 |
|
| 1479 |
############### Sending Email ################## |
| 1480 |
|
| 1481 |
if( isset($topic['status']) && $topic['status'] ){ |
| 1482 |
$subject_prefix = __('Please Moderate: ', 'wpforo'); |
| 1483 |
$mod_text = '<br /><br /><p style="color:#DD0000">' . __('This topic is currently unapproved. You can approve topics in Dashboard » Forums » Moderation admin page.', 'wpforo') . '</p>'; |
| 1484 |
} |
| 1485 |
else{ |
| 1486 |
$subject_prefix = ''; |
| 1487 |
$mod_text = ''; |
| 1488 |
} |
| 1489 |
|
| 1490 |
$subject = WPF()->sbscrb->options['new_topic_notification_email_subject']; |
| 1491 |
$message = WPF()->sbscrb->options['new_topic_notification_email_message']; |
| 1492 |
|
| 1493 |
$from_tags = array( "[member_name]", "[forum]", "[unsubscribe_link]", "[topic_title]", "[topic_desc]"); |
| 1494 |
$to_words = array( sanitize_text_field($member['display_name']), |
| 1495 |
'<a href="' . esc_url($forum['url']) . '">' . sanitize_text_field($forum['title']) . '</a>', |
| 1496 |
'<br><a target="_blank" href="' . esc_url($unsubscribe_link) . '">' . wpforo_phrase('Unsubscribe', false) . '</a>' , |
| 1497 |
'<a target="_blank" href="' . esc_url($topic['topicurl']) . '">' . sanitize_text_field($topic['title']) . '</a>' , |
| 1498 |
wpforo_text( wpforo_kses( $topic['body'], 'email'), 70, FALSE ) ); |
| 1499 |
|
| 1500 |
$subject = stripslashes(strip_tags(str_replace($from_tags, $to_words, $subject))); |
| 1501 |
$message = stripslashes(str_replace($from_tags, $to_words, $message)); |
| 1502 |
|
| 1503 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1504 |
$headers = wpforo_mail_headers(); |
| 1505 |
$subject = $subject_prefix . $subject; |
| 1506 |
$message = $message . $mod_text; |
| 1507 |
if( $email_status = wp_mail( $member['user_email'], $subject, $message, $headers ) ){ |
| 1508 |
WPF()->sbscrb->already_sent_emails[] = $member['user_email']; |
| 1509 |
} |
| 1510 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1511 |
|
| 1512 |
############### Sending Email end ############## |
| 1513 |
|
| 1514 |
} |
| 1515 |
} |
| 1516 |
add_action( 'wpforo_after_add_topic', 'wpforo_forum_subscribers_mail_sender', 12); |
| 1517 |
|
| 1518 |
function wpforo_topic_subscribers_mail_sender( $post ){ |
| 1519 |
|
| 1520 |
if( defined('IS_GO2WPFORO') && IS_GO2WPFORO ) return; |
| 1521 |
|
| 1522 |
$forums_sbs = WPF()->sbscrb->get_subscribes( array( 'itemid' => 0, 'type' => 'forums-topics' ) ); |
| 1523 |
$forum_sbs = WPF()->sbscrb->get_subscribes( array( 'itemid' => $post['forumid'], 'type' => 'forum-topic' ) ); |
| 1524 |
$topic_sbs = WPF()->sbscrb->get_subscribes( array( 'itemid' => $post['topicid'], 'type' => 'topic' ) ); |
| 1525 |
$subscribers = array_merge($forums_sbs, $forum_sbs, $topic_sbs); |
| 1526 |
|
| 1527 |
if( WPF()->sbscrb->options['new_reply_notify'] ){ |
| 1528 |
$admin_emails = explode(',', WPF()->sbscrb->options['admin_emails']); |
| 1529 |
foreach( $admin_emails as $admin_email ) $subscribers[] = sanitize_email( $admin_email ); |
| 1530 |
} |
| 1531 |
$topic = WPF()->db->get_row("SELECT * FROM `".WPF()->tables->topics."` WHERE `topicid` = " . intval($post['topicid']), ARRAY_A); |
| 1532 |
$subscribers = apply_filters('wpforo_topic_subscribers', $subscribers); |
| 1533 |
|
| 1534 |
foreach($subscribers as $subscriber){ |
| 1535 |
|
| 1536 |
if( is_array($subscriber) ){ |
| 1537 |
if( $subscriber['userid'] ){ |
| 1538 |
$member = WPF()->member->get_member( $subscriber['userid'] ); |
| 1539 |
}elseif( $subscriber['user_email'] ){ |
| 1540 |
$member = array('groupid' => 4, 'display_name' => ($subscriber['user_name'] ? $subscriber['user_name'] : $subscriber['user_email']), 'user_email' => $subscriber['user_email']); |
| 1541 |
}else{ |
| 1542 |
continue; |
| 1543 |
} |
| 1544 |
$unsubscribe_link = WPF()->sbscrb->get_unsubscribe_link($subscriber['confirmkey']); |
| 1545 |
}else{ |
| 1546 |
$member = array('display_name' => $subscriber, 'user_email' => $subscriber); |
| 1547 |
$unsubscribe_link = '#'; |
| 1548 |
} |
| 1549 |
|
| 1550 |
$owner = wpforo_member( $post ); |
| 1551 |
if($owner['user_email'] == $member['user_email']) continue; |
| 1552 |
if( in_array($member['user_email'], WPF()->sbscrb->already_sent_emails) ) continue; |
| 1553 |
|
| 1554 |
if( isset($topic['forumid']) && $topic['forumid'] && isset($subscriber['userid']) ){ |
| 1555 |
|
| 1556 |
$subscriber_groupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : WPF()->usergroup->get_groupid_by_userid($subscriber['userid']); |
| 1557 |
|
| 1558 |
if( isset($topic['private']) && $topic['private'] |
| 1559 |
&& ( ( $topic['userid'] && $subscriber['userid'] && $topic['userid'] != $subscriber['userid'] ) |
| 1560 |
|| ( $topic['email'] && $subscriber['user_email'] && $topic['email'] != $subscriber['user_email'] ) ) ){ |
| 1561 |
if( !WPF()->perm->forum_can('vp', $topic['forumid'], $subscriber_groupid) ){ |
| 1562 |
continue; |
| 1563 |
} |
| 1564 |
} |
| 1565 |
if( (isset($topic['status']) && $topic['status'] == 1) || (isset($post['status']) && $post['status'] == 1) ){ |
| 1566 |
if( !WPF()->perm->forum_can('au', $topic['forumid'], $subscriber_groupid) ){ |
| 1567 |
continue; |
| 1568 |
} |
| 1569 |
} |
| 1570 |
} |
| 1571 |
|
| 1572 |
############### Sending Email ################## |
| 1573 |
|
| 1574 |
if( isset($post['status']) && $post['status'] ){ |
| 1575 |
$subject_prefix = __('Please Moderate: ', 'wpforo'); |
| 1576 |
$mod_text = '<br /><br /><p style="color:#DD0000">' . __('This post is currently unapproved. You can approve posts in Dashboard » Forums » Moderation admin page.', 'wpforo') . '</p>'; |
| 1577 |
} |
| 1578 |
else{ |
| 1579 |
$subject_prefix = ''; |
| 1580 |
$mod_text = ''; |
| 1581 |
} |
| 1582 |
|
| 1583 |
$subject = WPF()->sbscrb->options['new_post_notification_email_subject']; |
| 1584 |
$message = WPF()->sbscrb->options['new_post_notification_email_message']; |
| 1585 |
|
| 1586 |
$from_tags = array( "[member_name]", "[topic]", "[unsubscribe_link]", "[reply_title]", "[reply_desc]"); |
| 1587 |
$to_words = array( sanitize_text_field($member['display_name']), |
| 1588 |
'<a href="' . esc_url($post['posturl']) . '">' . sanitize_text_field($topic['title']) . '</a>', |
| 1589 |
'<br><a target="_blank" href="' . esc_url($unsubscribe_link) . '">'.wpforo_phrase('Unsubscribe', false).'</a>' , |
| 1590 |
'<a target="_blank" href="' . esc_url($post['posturl']) . '">' . sanitize_text_field($post['title']) . '</a>' , |
| 1591 |
wpforo_text( wpforo_kses($post['body'], 'email'), 70, FALSE ) ); |
| 1592 |
|
| 1593 |
$subject = stripslashes(strip_tags(str_replace($from_tags, $to_words, $subject))); |
| 1594 |
$message = stripslashes(str_replace($from_tags, $to_words, $message)); |
| 1595 |
|
| 1596 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1597 |
$headers = wpforo_mail_headers(); |
| 1598 |
$subject = $subject_prefix . $subject; |
| 1599 |
$message = $message . $mod_text; |
| 1600 |
if( $email_status = wp_mail( $member['user_email'], $subject, $message, $headers ) ){ |
| 1601 |
WPF()->sbscrb->already_sent_emails[] = $member['user_email']; |
| 1602 |
} |
| 1603 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 1604 |
|
| 1605 |
############### Sending Email end ############## |
| 1606 |
|
| 1607 |
} |
| 1608 |
} |
| 1609 |
add_action( 'wpforo_after_add_post', 'wpforo_topic_subscribers_mail_sender', 13, 1 ); |
| 1610 |
|
| 1611 |
function wpforo_add_default_attachment($args){ |
| 1612 |
if( !empty($_FILES['attachfile']) && !empty($_FILES['attachfile']['name']) ){ |
| 1613 |
if( WPF()->perm->can_attach() ){ |
| 1614 |
$name = sanitize_file_name($_FILES['attachfile']['name']); //myimg.png |
| 1615 |
$type = sanitize_mime_type($_FILES['attachfile']['type']); //image/png |
| 1616 |
$tmp_name = sanitize_text_field($_FILES['attachfile']['tmp_name']); //D:\wamp\tmp\php986B.tmp |
| 1617 |
$error = intval($_FILES['attachfile']['error']); //0 |
| 1618 |
$size = intval($_FILES['attachfile']['size']); //6112 |
| 1619 |
|
| 1620 |
$phpFileUploadErrors = array( |
| 1621 |
0 => 'There is no error, the file uploaded with success', |
| 1622 |
1 => 'The uploaded file size is too big', |
| 1623 |
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', |
| 1624 |
3 => 'The uploaded file was only partially uploaded', |
| 1625 |
4 => 'No file was uploaded', |
| 1626 |
6 => 'Missing a temporary folder', |
| 1627 |
7 => 'Failed to write file to disk.', |
| 1628 |
8 => 'A PHP extension stopped the file upload.', |
| 1629 |
); |
| 1630 |
|
| 1631 |
if( $error ){ |
| 1632 |
WPF()->notice->add($phpFileUploadErrors[$error], 'error'); |
| 1633 |
return $args; |
| 1634 |
}elseif( $size > WPF()->post->options['max_upload_size'] ){ |
| 1635 |
WPF()->notice->add('The uploaded file size is too big', 'error'); |
| 1636 |
return $args; |
| 1637 |
} |
| 1638 |
|
| 1639 |
if(function_exists('pathinfo')){ |
| 1640 |
$ext = pathinfo($name, PATHINFO_EXTENSION); |
| 1641 |
} |
| 1642 |
else{ |
| 1643 |
$ext = substr(strrchr($name, '.'), 1); |
| 1644 |
} |
| 1645 |
$ext = strtolower($ext); |
| 1646 |
$mime_types = get_allowed_mime_types(); |
| 1647 |
$mime_types = array_flip($mime_types); |
| 1648 |
if(!empty($mime_types)){ |
| 1649 |
$allowed_types = implode('|', $mime_types); |
| 1650 |
$expld = explode('|', $allowed_types); |
| 1651 |
if( !in_array($ext, $expld) ){ |
| 1652 |
WPF()->notice->add('File type is not allowed', 'error'); |
| 1653 |
return $args; |
| 1654 |
} |
| 1655 |
if( !WPF()->perm->can_attach_file_type($ext) ){ |
| 1656 |
WPF()->notice->add('You are not allowed to attach this file type', 'error'); |
| 1657 |
return $args; |
| 1658 |
} |
| 1659 |
} |
| 1660 |
|
| 1661 |
$wp_upload_dir = wp_upload_dir(); |
| 1662 |
$uplds_dir = $wp_upload_dir['basedir']."/wpforo"; |
| 1663 |
$attach_dir = $wp_upload_dir['basedir']."/wpforo/default_attachments"; |
| 1664 |
$attach_url = preg_replace('#^https?\:#is', '', $wp_upload_dir['baseurl'])."/wpforo/default_attachments"; |
| 1665 |
if(!is_dir($uplds_dir)) wp_mkdir_p($uplds_dir); |
| 1666 |
if(!is_dir($attach_dir)) wp_mkdir_p($attach_dir); |
| 1667 |
|
| 1668 |
$fnm = pathinfo($name, PATHINFO_FILENAME); |
| 1669 |
$fnm = str_replace(' ', '-', $fnm); |
| 1670 |
while(strpos($fnm, '--') !== FALSE) $fnm = str_replace('--', '-', $fnm); |
| 1671 |
$fnm = preg_replace("/[^-a-zA-Z0-9]/", "", $fnm); |
| 1672 |
$fnm = trim($fnm, "-"); |
| 1673 |
$fnm_empty = ( $fnm ? FALSE : TRUE ); |
| 1674 |
|
| 1675 |
$file_name = $fnm . "." . $ext; |
| 1676 |
|
| 1677 |
$attach_fname = current_time( 'timestamp', 1 ).( !$fnm_empty ? '-' : '' ) . $file_name; |
| 1678 |
$attach_path = $attach_dir . "/" . $attach_fname; |
| 1679 |
|
| 1680 |
if( is_dir($attach_dir) && move_uploaded_file($tmp_name, $attach_path) ){ |
| 1681 |
$attach_id = wpforo_insert_to_media_library( $attach_path, $fnm ); |
| 1682 |
$args['body'] .= "\r\n" . '<div id="wpfa-' . $attach_id . '" class="wpforo-attached-file"><a class="wpforo-default-attachment" href="' . esc_url($attach_url.'/'.$attach_fname) . '" target="_blank"><i class="fas fa-paperclip"></i>' . esc_html(basename($name)) . '</a></div>'; |
| 1683 |
$args['has_attach'] = 1; |
| 1684 |
}else{ |
| 1685 |
WPF()->notice->add('Can`t upload file', 'error'); |
| 1686 |
return $args; |
| 1687 |
} |
| 1688 |
} |
| 1689 |
} |
| 1690 |
return $args; |
| 1691 |
} |
| 1692 |
|
| 1693 |
function wpforo_delete_attachment( $attach_post_id ){ |
| 1694 |
if(!$attach_post_id) return; |
| 1695 |
$posts = WPF()->db->get_results("SELECT `postid`, `body` FROM `" . WPF()->tables->posts . "` WHERE `body` LIKE '%wpfa-" . intval( $attach_post_id ) . "%'", ARRAY_A ); |
| 1696 |
if(!empty($posts) || is_array($posts)){ |
| 1697 |
foreach( $posts as $post ){ |
| 1698 |
$body = preg_replace('|<div[^><]*id=[\'\"]+wpfa-' . $attach_post_id . '[\'\"]+[^><]*>.+?</div>|is', '<div class="wpforo-attached-file wpfa-deleted">' . wpforo_phrase('Attachment removed', FALSE) . '</div>', $post['body'] ); |
| 1699 |
if( $body ) WPF()->db->query("UPDATE `" . WPF()->tables->posts . "` SET `body` = '" . esc_sql( $body ) . "' WHERE `postid` = " . intval($post['postid'])); |
| 1700 |
} |
| 1701 |
} |
| 1702 |
} |
| 1703 |
|
| 1704 |
function wpforo_default_attachments_filter($text){ |
| 1705 |
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>#isu', $text, $matches, PREG_SET_ORDER) ){ |
| 1706 |
foreach( $matches as $match ){ |
| 1707 |
$attach_html = ''; |
| 1708 |
$fileurl = preg_replace('#^https?\:#is', '', $match[1]); |
| 1709 |
$filename = $match[2]; |
| 1710 |
|
| 1711 |
$upload_array = wp_upload_dir(); |
| 1712 |
$filedir = preg_replace('#^https?\:#is', '', str_replace( preg_replace('#^https?\:#is', '', $upload_array['baseurl']), $upload_array['basedir'], $fileurl ) ); |
| 1713 |
$filedir = str_replace( basename($filedir), urldecode( basename($filedir) ), $filedir ); |
| 1714 |
|
| 1715 |
if(file_exists($filedir)){ |
| 1716 |
if(!WPF()->perm->forum_can('va')){ |
| 1717 |
$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($filename) ) . '</a></div>'; |
| 1718 |
} |
| 1719 |
} |
| 1720 |
|
| 1721 |
if($attach_html){ |
| 1722 |
$attach_html .= '<br/>'; |
| 1723 |
$text = str_replace($match[0], $attach_html, $text); |
| 1724 |
} |
| 1725 |
} |
| 1726 |
} |
| 1727 |
|
| 1728 |
return $text; |
| 1729 |
} |
| 1730 |
|
| 1731 |
add_action( 'delete_attachment', 'wpforo_delete_attachment', 10 ); |
| 1732 |
if( !defined('WPFOROATTACH_BASENAME') ){ |
| 1733 |
add_filter( 'wpforo_add_topic_data_filter', 'wpforo_add_default_attachment' ); |
| 1734 |
add_filter( 'wpforo_edit_topic_data_filter', 'wpforo_add_default_attachment' ); |
| 1735 |
add_filter( 'wpforo_add_post_data_filter', 'wpforo_add_default_attachment' ); |
| 1736 |
add_filter( 'wpforo_edit_post_data_filter', 'wpforo_add_default_attachment' ); |
| 1737 |
add_filter('wpforo_body_text_filter', 'wpforo_default_attachments_filter'); |
| 1738 |
} |
| 1739 |
|
| 1740 |
if( !class_exists('wpForoSmiles') ){ |
| 1741 |
add_filter('wpforo_body_text_filter', 'wp_encode_emoji', 9); |
| 1742 |
add_filter('wpforo_body_text_filter', 'convert_smilies'); |
| 1743 |
} |
| 1744 |
|
| 1745 |
function wpforo_content_enable_do_shortcode(){ |
| 1746 |
if (wpforo_feature('content-do_shortcode')) { |
| 1747 |
add_filter('wpforo_content_after', 'do_shortcode', 20); |
| 1748 |
} |
| 1749 |
} |
| 1750 |
add_action('init', 'wpforo_content_enable_do_shortcode'); |
| 1751 |
|
| 1752 |
|
| 1753 |
function wpforo_add_adminbar_links( $wp_admin_bar ) { |
| 1754 |
$args = array( |
| 1755 |
'id' => 'new-forum', |
| 1756 |
'title' => __('New Forum', 'wpforo'), |
| 1757 |
'href' => admin_url('admin.php?page=wpforo-forums&action=add'), |
| 1758 |
'parent' => 'new-content' |
| 1759 |
); |
| 1760 |
$wp_admin_bar->add_node( $args ); |
| 1761 |
|
| 1762 |
$args = array( |
| 1763 |
'id' => 'new-ugroup', |
| 1764 |
'title' => __('New User Group', 'wpforo'), |
| 1765 |
'href' => admin_url('admin.php?page=wpforo-usergroups&action=add'), |
| 1766 |
'parent' => 'new-content' |
| 1767 |
); |
| 1768 |
$wp_admin_bar->add_node( $args ); |
| 1769 |
|
| 1770 |
$args = array( |
| 1771 |
'id' => 'new-phrase', |
| 1772 |
'title' => __('New Phrase', 'wpforo'), |
| 1773 |
'href' => admin_url('admin.php?page=wpforo-phrases&action=add'), |
| 1774 |
'parent' => 'new-content' |
| 1775 |
); |
| 1776 |
$wp_admin_bar->add_node( $args ); |
| 1777 |
|
| 1778 |
if( WPF()->current_user_groupid == 1 || |
| 1779 |
WPF()->current_user_groupid == 2 || |
| 1780 |
WPF()->perm->usergroup_can('vm') || |
| 1781 |
( WPF()->perm->usergroup_can('cf') && |
| 1782 |
WPF()->perm->usergroup_can('ef') && |
| 1783 |
WPF()->perm->usergroup_can('df') ) |
| 1784 |
){ |
| 1785 |
$args = array( |
| 1786 |
'id' => 'wpf-community', |
| 1787 |
'title' => __('Community', 'wpforo'), |
| 1788 |
'href' => admin_url('admin.php?page=wpforo-community') |
| 1789 |
); |
| 1790 |
$wp_admin_bar->add_node( $args ); |
| 1791 |
} |
| 1792 |
if( WPF()->perm->usergroup_can('cf') && WPF()->perm->usergroup_can('ef') && WPF()->perm->usergroup_can('df') ){ |
| 1793 |
$args = array( |
| 1794 |
'id' => 'wpf-forums', |
| 1795 |
'title' => __('Forums', 'wpforo'), |
| 1796 |
'href' => admin_url('admin.php?page=wpforo-forums'), |
| 1797 |
'parent' => 'wpf-community' |
| 1798 |
); |
| 1799 |
$wp_admin_bar->add_node( $args ); |
| 1800 |
$args = array( |
| 1801 |
'id' => 'wpf-new-forum', |
| 1802 |
'title' => __('New Forum', 'wpforo'), |
| 1803 |
'href' => admin_url('admin.php?page=wpforo-forums&action=add'), |
| 1804 |
'parent' => 'wpf-forums' |
| 1805 |
); |
| 1806 |
$wp_admin_bar->add_node( $args ); |
| 1807 |
} |
| 1808 |
if( WPF()->current_user_groupid == 1 ){ |
| 1809 |
$args = array( |
| 1810 |
'id' => 'wpf-settings', |
| 1811 |
'title' => __('Settings', 'wpforo'), |
| 1812 |
'href' => admin_url('admin.php?page=wpforo-settings'), |
| 1813 |
'parent' => 'wpf-community' |
| 1814 |
); |
| 1815 |
$wp_admin_bar->add_node( $args ); |
| 1816 |
} |
| 1817 |
if( WPF()->current_user_groupid == 1 ){ |
| 1818 |
$args = array( |
| 1819 |
'id' => 'wpf-tools', |
| 1820 |
'title' => __('Tools', 'wpforo'), |
| 1821 |
'href' => admin_url('admin.php?page=wpforo-tools'), |
| 1822 |
'parent' => 'wpf-community' |
| 1823 |
); |
| 1824 |
$wp_admin_bar->add_node( $args ); |
| 1825 |
} |
| 1826 |
if( WPF()->perm->usergroup_can('aum') ){ |
| 1827 |
$args = array( |
| 1828 |
'id' => 'wpf-moderation', |
| 1829 |
'title' => __('Moderation', 'wpforo'), |
| 1830 |
'href' => admin_url('admin.php?page=wpforo-moderations'), |
| 1831 |
'parent' => 'wpf-community' |
| 1832 |
); |
| 1833 |
$wp_admin_bar->add_node( $args ); |
| 1834 |
} |
| 1835 |
if( WPF()->perm->usergroup_can('vm') ){ |
| 1836 |
$args = array( |
| 1837 |
'id' => 'wpf-members', |
| 1838 |
'title' => __('Members', 'wpforo'), |
| 1839 |
'href' => admin_url('admin.php?page=wpforo-members'), |
| 1840 |
'parent' => 'wpf-community' |
| 1841 |
); |
| 1842 |
$wp_admin_bar->add_node( $args ); |
| 1843 |
} |
| 1844 |
if( WPF()->current_user_groupid == 1 ){ |
| 1845 |
$args = array( |
| 1846 |
'id' => 'wpf-usergroups', |
| 1847 |
'title' => __('Usergroups', 'wpforo'), |
| 1848 |
'href' => admin_url('admin.php?page=wpforo-usergroups'), |
| 1849 |
'parent' => 'wpf-community' |
| 1850 |
); |
| 1851 |
$wp_admin_bar->add_node( $args ); |
| 1852 |
$args = array( |
| 1853 |
'id' => 'wpf-new-ugroup', |
| 1854 |
'title' => __('New Usergroup', 'wpforo'), |
| 1855 |
'href' => admin_url('admin.php?page=wpforo-usergroups&action=add'), |
| 1856 |
'parent' => 'wpf-usergroups' |
| 1857 |
); |
| 1858 |
$wp_admin_bar->add_node( $args ); |
| 1859 |
} |
| 1860 |
if( WPF()->current_user_groupid == 1 ){ |
| 1861 |
$args = array( |
| 1862 |
'id' => 'wpf-phrases', |
| 1863 |
'title' => __('Phrases', 'wpforo'), |
| 1864 |
'href' => admin_url('admin.php?page=wpforo-phrases'), |
| 1865 |
'parent' => 'wpf-community' |
| 1866 |
); |
| 1867 |
$wp_admin_bar->add_node( $args ); |
| 1868 |
$args = array( |
| 1869 |
'id' => 'wpf-new-phrase', |
| 1870 |
'title' => __('New Phrase', 'wpforo'), |
| 1871 |
'href' => admin_url('admin.php?page=wpforo-phrases&action=add'), |
| 1872 |
'parent' => 'wpf-phrases' |
| 1873 |
); |
| 1874 |
$wp_admin_bar->add_node( $args ); |
| 1875 |
} |
| 1876 |
if( WPF()->current_user_groupid == 1 ){ |
| 1877 |
$args = array( |
| 1878 |
'id' => 'wpf-themes', |
| 1879 |
'title' => __('Themes', 'wpforo'), |
| 1880 |
'href' => admin_url('admin.php?page=wpforo-themes'), |
| 1881 |
'parent' => 'wpf-community' |
| 1882 |
); |
| 1883 |
$wp_admin_bar->add_node( $args ); |
| 1884 |
} |
| 1885 |
if( WPF()->current_user_groupid == 1 ){ |
| 1886 |
$args = array( |
| 1887 |
'id' => 'wpf-addons', |
| 1888 |
'title' => __('Addons', 'wpforo'), |
| 1889 |
'href' => admin_url('admin.php?page=wpforo-addons'), |
| 1890 |
'parent' => 'wpf-community' |
| 1891 |
); |
| 1892 |
$wp_admin_bar->add_node( $args ); |
| 1893 |
} |
| 1894 |
|
| 1895 |
} |
| 1896 |
add_action( 'admin_bar_menu', 'wpforo_add_adminbar_links', 999 ); |
| 1897 |
|
| 1898 |
function wpforo_create_cache(){ |
| 1899 |
WPF()->cache->create(); |
| 1900 |
} |
| 1901 |
add_action( 'wp_footer', 'wpforo_create_cache', 10 ); |
| 1902 |
|
| 1903 |
function wpforo_redirect_to_custom_lostpassword() { |
| 1904 |
if( !wpforo_feature('resetpass-url') ) return; |
| 1905 |
|
| 1906 |
if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) { |
| 1907 |
if ( is_user_logged_in() ) { |
| 1908 |
wp_redirect( wpforo_home_url() ); |
| 1909 |
exit; |
| 1910 |
} |
| 1911 |
|
| 1912 |
wp_redirect( wpforo_home_url( '?wpforo=lostpassword' ) ); |
| 1913 |
exit; |
| 1914 |
} |
| 1915 |
} |
| 1916 |
add_action('login_form_lostpassword', 'wpforo_redirect_to_custom_lostpassword'); |
| 1917 |
|
| 1918 |
function wpforo_redirect_to_custom_password_reset(){ |
| 1919 |
if( !wpforo_feature('resetpass-url') ) return; |
| 1920 |
|
| 1921 |
if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) { |
| 1922 |
// Verify key / login combo |
| 1923 |
$_REQUEST['key'] = sanitize_textarea_field($_REQUEST['key']); |
| 1924 |
$_REQUEST['key'] = sanitize_textarea_field($_REQUEST['login']); |
| 1925 |
$user = check_password_reset_key( $_REQUEST['key'], $_REQUEST['login'] ); |
| 1926 |
if ( ! $user || is_wp_error( $user ) ) { |
| 1927 |
if ( $user && $user->get_error_code() === 'expired_key' ) { |
| 1928 |
WPF()->notice->add('The key is expired', 'error'); |
| 1929 |
} else { |
| 1930 |
WPF()->notice->add('The key is invalid', 'error'); |
| 1931 |
} |
| 1932 |
wp_redirect( wpforo_login_url() ); |
| 1933 |
exit; |
| 1934 |
} |
| 1935 |
|
| 1936 |
$redirect_url = wpforo_home_url( '?wpforo=resetpassword&rp_key='.esc_attr( urlencode($_REQUEST['key']) ).'&rp_login='.esc_attr( urlencode($_REQUEST['login']) ) ); |
| 1937 |
|
| 1938 |
wp_redirect( $redirect_url ); |
| 1939 |
exit; |
| 1940 |
} |
| 1941 |
} |
| 1942 |
add_action( 'login_form_rp', 'wpforo_redirect_to_custom_password_reset' ); |
| 1943 |
add_action( 'login_form_resetpass', 'wpforo_redirect_to_custom_password_reset' ); |
| 1944 |
|
| 1945 |
function wpforo_do_lostpass(){ |
| 1946 |
if( !wpforo_feature('resetpass-url') ) return; |
| 1947 |
|
| 1948 |
if( isset($_POST['user_login']) && $_POST['user_login'] ){ |
| 1949 |
$errors = retrieve_password(); |
| 1950 |
if ( is_wp_error( $errors ) ) { |
| 1951 |
// Errors found |
| 1952 |
$redirect_url = wpforo_home_url( '?wpforo=lostpassword' ); |
| 1953 |
WPF()->notice->add(join( ',', $errors->get_error_codes()), 'error'); |
| 1954 |
} else { |
| 1955 |
// Email sent |
| 1956 |
$redirect_url = wpforo_login_url(); |
| 1957 |
WPF()->notice->add('Email has been sent', 'success'); |
| 1958 |
} |
| 1959 |
|
| 1960 |
wp_safe_redirect( $redirect_url ); |
| 1961 |
exit(); |
| 1962 |
} |
| 1963 |
} |
| 1964 |
add_action('login_form_lostpassword', 'wpforo_do_lostpass'); |
| 1965 |
|
| 1966 |
function wpforo_do_password_reset() { |
| 1967 |
if( !wpforo_feature('resetpass-url') ) return; |
| 1968 |
|
| 1969 |
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) { |
| 1970 |
$rp_key = sanitize_textarea_field($_REQUEST['rp_key']); |
| 1971 |
$rp_login = sanitize_textarea_field($_REQUEST['rp_login']); |
| 1972 |
|
| 1973 |
$user = check_password_reset_key( $rp_key, $rp_login ); |
| 1974 |
|
| 1975 |
if ( ! $user || is_wp_error( $user ) ) { |
| 1976 |
if ( $user && $user->get_error_code() === 'expired_key' ) { |
| 1977 |
WPF()->notice->add('The key is expired', 'error'); |
| 1978 |
} else { |
| 1979 |
WPF()->notice->add('The key is invalid', 'error'); |
| 1980 |
} |
| 1981 |
wp_redirect( wpforo_login_url() ); |
| 1982 |
exit(); |
| 1983 |
} |
| 1984 |
|
| 1985 |
if ( isset( $_POST['pass1'] ) ) { |
| 1986 |
if ( $_POST['pass1'] != $_POST['pass2'] ) { |
| 1987 |
// Passwords don't match |
| 1988 |
WPF()->notice->add('The password reset mismatch', 'error'); |
| 1989 |
$redirect_url = wpforo_home_url( '?wpforo=resetpassword&rp_key='.esc_attr( $rp_key ).'&rp_login='.esc_attr( $rp_login ) );; |
| 1990 |
|
| 1991 |
wp_redirect( $redirect_url ); |
| 1992 |
exit(); |
| 1993 |
} |
| 1994 |
|
| 1995 |
if ( empty( $_POST['pass1'] ) ) { |
| 1996 |
// Password is empty |
| 1997 |
WPF()->notice->add('The password reset empty', 'error'); |
| 1998 |
$redirect_url = wpforo_home_url( '?wpforo=resetpassword&rp_key='.esc_attr( $rp_key ).'&rp_login='.esc_attr( $rp_login ) ); |
| 1999 |
|
| 2000 |
wp_redirect( $redirect_url ); |
| 2001 |
exit(); |
| 2002 |
} |
| 2003 |
|
| 2004 |
// Parameter checks OK, reset password |
| 2005 |
reset_password( $user, $_POST['pass1'] ); |
| 2006 |
|
| 2007 |
$creds = array('user_login' => sanitize_user($rp_login), 'user_password' => $_POST['pass1'] ); |
| 2008 |
wp_signon($creds); |
| 2009 |
|
| 2010 |
WPF()->notice->add('The password has been changed', 'success'); |
| 2011 |
wp_redirect( wpforo_login_url() ); |
| 2012 |
exit(); |
| 2013 |
} |
| 2014 |
|
| 2015 |
WPF()->notice->add('Invalid request.', 'error'); |
| 2016 |
wp_redirect( wpforo_login_url() ); |
| 2017 |
exit(); |
| 2018 |
|
| 2019 |
} |
| 2020 |
} |
| 2021 |
add_action( 'login_form_rp', 'wpforo_do_password_reset' ); |
| 2022 |
add_action( 'login_form_resetpass', 'wpforo_do_password_reset' ); |
| 2023 |
|
| 2024 |
function wpforo_replace_retrieve_password_message( $message, $key, $user_login, $user_data ) { |
| 2025 |
if( wpforo_feature('resetpass-url') ){ |
| 2026 |
$reset_password_url = wpforo_home_url( '?wpforo=resetpassword&rp_key='.esc_attr( $key ).'&rp_login='.rawurlencode( $user_login ) ); |
| 2027 |
if( empty(WPF()->sbscrb->options['reset_password_email_message']) ){ |
| 2028 |
$message = preg_replace('#<?http[^\r\n\t\s]+wp-login\.php[^\r\n\t\s]+#isu', "<$reset_password_url>", $message); |
| 2029 |
}else{ |
| 2030 |
$message = str_replace(array('[user_login]', '[reset_password_url]'), array($user_login, "<$reset_password_url>"), strip_tags(WPF()->sbscrb->options['reset_password_email_message'])); |
| 2031 |
} |
| 2032 |
} |
| 2033 |
return $message; |
| 2034 |
} |
| 2035 |
add_filter( 'retrieve_password_message', 'wpforo_replace_retrieve_password_message', 10, 4 ); |