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