PluginProbe
wpForo Forum / 1.2.0
wpForo Forum v1.2.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / wpf-hooks.php

wpf-hooks.php in wpForo Forum 1.2.0, at wpf-includes/wpf-hooks.php

1,547 lines 62.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
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() ) 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_edit_user_page( $url, $userid, $scheme ) {
96 global $wpforo;
97 return $wpforo->member->get_profile_url($userid);
98 }
99 add_filter( 'edit_profile_url', 'wpforo_change_default_edit_user_page', 10, 3 );
100
101 function wpforo_change_default_register_page( $register_url ) {
102 if(!wpforo_feature('register-url')) return $register_url;
103 return WPFORO_BASE_URL . '?wpforo=signup';
104 }
105 add_filter( 'register_url', 'wpforo_change_default_register_page' );
106
107 function wpforo_change_default_login_page( $login_url, $redirect ) {
108 if(!wpforo_feature('login-url')) return $login_url;
109 return WPFORO_BASE_URL . '?wpforo=signin';
110 }
111 add_filter( 'login_url', 'wpforo_change_default_login_page', 10, 2 );
112
113 function wpftpl( $filename ){
114 global $wpforo;
115 $find = array();
116 if ( $filename ) {
117 $find[] = 'wpforo/'. $filename;
118 $template = locate_template( array_unique( $find ) );
119 if ( $template ) {
120 return $template;
121 }
122 else{
123 return WPFORO_THEME_DIR . '/'. $wpforo->theme .'/' . $filename;
124 }
125 }
126 }
127
128 function wpforo_init_template(){
129 global $wpforo;
130 if(wpforo_is_admin()) return;
131 include_once( wpftpl('index.php') );
132 }
133
134 add_shortcode( 'wpforo', 'wpforo_load' );
135 function wpforo_load( $atts ){
136 if(wpforo_is_admin()) return;
137 global $wpforo, $post;
138
139 if( is_wpforo_shortcode_page() ){
140 $url = WPFORO_BASE_URL;
141
142 $args = shortcode_atts( array(
143 'item' => 'forum',
144 'id' => 0,
145 'slug' => '',
146 ), $atts );
147
148 if( $args['id'] || $args['slug'] ){
149 $getid = ( $args['slug'] ? $args['slug'] : $args['id'] );
150 if( $args['item'] == 'topic' ){
151 $url = $wpforo->topic->get_topic_url($getid);
152 }elseif( $args['item'] == 'profile' ){
153 $url = $wpforo->member->get_profile_url($getid);
154 }else{
155 $url = $wpforo->forum->get_forum_url($getid);
156 }
157 }
158
159 $wpforo->init_current_object($url);
160 $wpforo->tpl->init_nav_menu();
161 }
162
163 if(wpforo_feature('output-buffer') && function_exists('ob_start')){
164 ob_start();
165 wpforo_init_template();
166 return ob_get_clean();
167 }
168 else{
169 wpforo_init_template();
170 }
171
172 }
173
174
175 function wpforo_template_include($template){
176 if( is_wpforo_page() && !is_wpforo_shortcode_page() && ($wpforo_template = wpftpl('index.php')) ) return $wpforo_template;
177 return $template;
178 }
179
180 add_action('wp', 'wpforo_set_404_to_false');
181 function wpforo_set_404_to_false(){
182 if( is_wpforo_page() ){
183 global $wp_query;
184 $wp_query->is_404 = FALSE;
185 }
186 }
187
188 function wpforo_do_rewrite(){
189 if(!is_wpforo_page()){
190 flush_rewrite_rules();
191 nocache_headers();
192 return;
193 }
194
195 global $wpforo;
196 $pattern = ($wpforo->use_home_url ? '(.*)' : '('.preg_quote($wpforo->permastruct).'(?:/|$).*)$');
197 add_rewrite_rule($pattern, 'index.php?page_id=' . $wpforo->pageid, 'top');
198 flush_rewrite_rules();
199 nocache_headers();
200 if( $wpforo->use_home_url ) add_filter('template_include', 'wpforo_template_include');
201 }
202 add_action('init', 'wpforo_do_rewrite');
203
204 function wpforo_theme_functions(){
205 $path = wpftpl('functions.php');
206 if( file_exists($path) ){
207 include_once($path);
208 }
209 }
210 add_action('init', 'wpforo_theme_functions');
211
212 function wpforo_theme_functions_wp(){
213 $path = wpftpl('functions-wp.php');
214 if( file_exists($path) ){
215 include_once($path);
216 }
217 }
218 add_action('after_setup_theme', 'wpforo_theme_functions_wp');
219
220 function wpforo_meta_title($title) {
221 global $wpforo;
222 $is404 = false;
223 $meta_title = array();
224
225 if(!wpforo_feature('seo-title', $wpforo)) return $title;
226
227 if(is_wpforo_page()){
228 $template = $wpforo->current_object['template'];
229 if( ($template == 'post' && $wpforo->current_object['topicid'] == 0) ||
230 ($template == 'topic' && $wpforo->current_object['forumid'] == 0) ||
231 ($template == 'profile' && $wpforo->current_object['userid'] == 0) ){
232 $is404 = true;
233 }
234 if(!$is404){
235 $paged = ( $wpforo->current_object['paged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false) . ' ' . $wpforo->current_object['paged'] .' ' : '';
236 if(!empty($wpforo->current_object['forum'])) $forum = $wpforo->current_object['forum'];
237 if(!empty($wpforo->current_object['topic'])) $topic = $wpforo->current_object['topic'];
238 if(!empty($wpforo->current_object['user'])) $user = $wpforo->current_object['user'];
239 if(isset($topic['title']) && isset($forum['title']) && isset($wpforo->general_options['title'])){
240 $meta_title = array($topic['title'] . $paged, $forum['title'], $wpforo->general_options['title']);
241 }
242 elseif(!isset($topic['title']) && isset($forum['title']) && isset($wpforo->general_options['title'])){
243 $meta_title = array($forum['title'] . $paged, $wpforo->general_options['title']);
244 }
245 elseif( $template != 'forum' && $template != 'topic' && $template != 'post' ){
246 if( $template == 'profile' || $template == 'account' || $template == 'activity' || $template == 'subscriptions' ){
247 if(isset($user['display_name'])){
248 $meta_title = array($user['display_name'], wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
249 }
250 elseif(isset($wpforo->current_object['username'])){
251 $meta_title = array($wpforo->current_object['username'], wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
252 }
253 else{
254 $meta_title = array(wpforo_phrase( 'Member', false), wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
255 }
256 }
257 elseif($template){
258 $wpfpaged = ( isset($_GET['wpfpaged']) && $_GET['wpfpaged'] > 1 ) ? ' - ' . wpforo_phrase( 'page', false) . ' ' . $_GET['wpfpaged'] .' ' : '';
259 $meta_title = array(wpforo_phrase( ucfirst($template), false) . $wpfpaged, $wpforo->general_options['title']);
260 }
261 elseif($title){
262 $meta_title = (is_array($title)) ? $title : array($title);
263 }
264 else{
265 $meta_title = array(wpforo_phrase('Forum', false), get_bloginfo('name'));
266 }
267 }
268 elseif( isset($wpforo->general_options['title']) && $wpforo->general_options['title'] ){
269 $meta_title = array($wpforo->general_options['title'], get_bloginfo('name'));
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 else{
279 $meta_title = array(wpforo_phrase( '404 - Page not found', false), $wpforo->general_options['title']);
280 }
281 }
282 if(!empty($meta_title)) {
283 return $meta_title;
284 }
285 else{
286 return $title;
287 }
288 }
289 add_filter('document_title_parts', 'wpforo_meta_title', 100);
290
291 function wpforo_meta_wp_title($title){
292 if(!wpforo_feature('seo-title')) return $title;
293 $meta_title = wpforo_meta_title($title);
294 if(is_array($meta_title) && !empty($meta_title)){
295 $title = implode(' &#8211; ', $meta_title);
296 }
297 return $title;
298 }
299 add_filter( 'wp_title', 'wpforo_meta_wp_title', 100);
300
301 function wpforo_add_meta_tags(){
302 global $wpforo;
303
304 if(!wpforo_feature('seo-meta', $wpforo)) return;
305
306 if(is_wpforo_page()){
307 $title = '';
308 $template = '';
309 $description = '';
310 $udata = array();
311 $canonical = wpforo_get_request_uri();
312 $paged = ( $wpforo->current_object['paged'] > 1 ) ? wpforo_phrase( 'page', false) . ' ' . $wpforo->current_object['paged'] .' | ' : '';
313 if(isset($wpforo->current_object['template'])) $template = $wpforo->current_object['template'];
314 if(!empty($wpforo->current_object['forum'])) $forum = $wpforo->current_object['forum'];
315 if(!empty($wpforo->current_object['topic'])) $topic = $wpforo->current_object['topic'];
316 if(!empty($wpforo->current_object['user'])) $user = $wpforo->current_object['user'];
317 if(isset($wpforo->current_object)){
318 if( isset($wpforo->current_object['forumid']) && !isset($wpforo->current_object['topicid']) ){
319 if(isset($forum['title'])) $title = $forum['title'];
320 if(isset($wpforo->current_object['forum_meta_desc']) && $wpforo->current_object['forum_meta_desc'] !=''){
321 $description = $paged . $wpforo->current_object['forum_meta_desc'];
322 }
323 elseif(isset($wpforo->current_object['forum_desc']) && $wpforo->current_object['forum_desc'] !=''){
324 $description = $paged . $wpforo->current_object['forum_desc'];
325 }
326 }elseif( isset($wpforo->current_object['topicid']) && isset($topic['first_postid']) ){
327 $post = $wpforo->post->get_post($topic['first_postid']);
328 if(isset($post['title'])) $title = wpforo_text($paged . $post['title'], 60, false);
329 if(isset($post['body'])) $description = wpforo_text($paged . $post['body'], 150, false);
330 }elseif( $template == 'profile' || $template == 'account' || $template == 'activity' || $template == 'subscriptions' ){
331 if( isset($wpforo->general_options['title']) ) $title = $paged . $wpforo->general_options['title'];
332 $udata['name'] = (isset($user['display_name']) && $user['display_name']) ? wpforo_phrase( 'User', false ) . ': ' . $user['display_name'] : '';
333 $udata['title'] = (isset($user['stat']['title']) && $user['stat']['title']) ? wpforo_phrase( 'Title', false ) . ': ' . $user['stat']['title'] : '';
334 $udata['about'] = (isset($user['about']) && $user['about']) ? wpforo_phrase( 'About', false ) . ': ' . wpforo_text($user['about'], 150, false) : '';
335 $description = $title . ' - ' . wpforo_phrase('Member Profile', false) . ' &gt; ' . wpforo_phrase( ucfirst($template), false ) . ' ' . wpforo_phrase( 'Page', false ) . '. ' . implode(', ', $udata);
336 }elseif(isset($wpforo->current_object['template']) && $wpforo->current_object['template'] == 'member'){
337 $wpfpaged = ( isset($_GET['wpfpaged']) && $_GET['wpfpaged'] > 1 ) ? wpforo_phrase( 'Page', false) . ' ' . $_GET['wpfpaged'] .' | ' : '';
338 $description = $wpfpaged . wpforo_phrase( 'Forum Members List', false);
339 }
340 else{
341 if( isset($wpforo->general_options['title']) ) $title = $paged . $wpforo->general_options['title'];
342 if( isset($wpforo->general_options['description']) ) $description = $paged . $wpforo->general_options['description'];
343 }
344 $description = preg_replace('#[\t\r\n]+#isu', ' ', $description);
345 echo "\r\n<!-- wpForo SEO -->\r\n<link rel=\"canonical\" href=\"".$canonical."\" />\r\n<meta name=\"description\" content=\"" . esc_html($description) . "\" />\r\n<meta property=\"og:title\" content=\"" . esc_html($title) . "\" />\r\n<meta property=\"og:description\" content=\"" . esc_html($description) . "\" />\r\n<meta property=\"og:url\" content=\"" . $canonical . "\" />\r\n<meta property=\"og: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";
346 }
347 }
348 }
349 add_action('wp_head', 'wpforo_add_meta_tags', 1);
350
351
352 add_action('wp_ajax_wpforo_like_ajax', 'wpf_like');
353
354 function wpf_like(){
355 global $wpforo;
356 $response = array('stat' => 0, 'likers' => '', 'notice' => $wpforo->notice->get_notices());
357 if(!is_user_logged_in()){
358 $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>' ) );
359 $response['notice'] = $wpforo->notice->get_notices();
360 echo json_encode($response);
361 exit();
362 }
363 if( !isset($_POST['likestatus']) || !isset($_POST['postid']) || !($postid = intval($_POST['postid'])) ){
364 $wpforo->notice->add('action error', 'error');
365 $response['notice'] = $wpforo->notice->get_notices();
366 echo json_encode($response);
367 exit();
368 }
369 if( !$post = $wpforo->post->get_post( $postid ) ){
370 $wpforo->notice->add('post not found', 'error');
371 $response['notice'] = $wpforo->notice->get_notices();
372 echo json_encode($response);
373 exit();
374 }
375 if( !$wpforo->perm->forum_can( 'l', $post['forumid']) ){
376 $wpforo->notice->add('You haven\'t permission to like posts from this forum', 'error');
377 $response['notice'] = $wpforo->notice->get_notices();
378 echo json_encode($response);
379 exit();
380 }
381 if( $_POST['likestatus'] ){
382 if( $wpforo->db->insert(
383 $wpforo->db->prefix . 'wpforo_likes',
384 array(
385 'postid' => $postid,
386 'userid' => $wpforo->current_userid,
387 'post_userid' => $post['userid']
388 ),
389 array('%d','%d','%d')
390 ) ){
391 do_action('wpforo_like', $post, $wpforo->current_userid);
392 $wpforo->notice->add('done', 'success');
393 $response['stat'] = 1;
394 $response['notice'] = $wpforo->notice->get_notices();
395 }
396 }else{
397 if( $wpforo->db->delete(
398 $wpforo->db->prefix . 'wpforo_likes',
399 array(
400 'postid' => $postid,
401 'userid' => $wpforo->current_userid
402 ),
403 array('%d','%d')
404 ) ){
405 do_action('wpforo_dislike', $post, $wpforo->current_userid);
406 $wpforo->notice->add('done', 'success');
407 $response['stat'] = 1;
408 $response['notice'] = $wpforo->notice->get_notices();
409 }
410 }
411 if(!isset($post['userid'])) $wpforo->member->reset($post['userid']);
412 if(!isset($wpforo->current_userid)) $wpforo->member->reset($wpforo->current_userid);
413 $response['likers'] = $wpforo->tpl->likers($postid);
414 echo json_encode($response);
415 exit();
416 }
417
418
419 add_action('wp_ajax_wpforo_vote_ajax', 'wpf_vote');
420 function wpf_vote(){
421
422 if(!is_user_logged_in()) return;
423
424 global $wpforo;
425
426 if( !isset($_POST['postid']) || !$_POST['postid'] ){
427 $wpforo->notice->add('Wrong post data', 'error');
428 echo json_encode(array('stat' => 0, 'notice' => $wpforo->notice->get_notices()));
429 exit();
430 }
431 if( $wpforo->db->get_var( "SELECT `voteid` FROM `".$wpforo->db->prefix."wpforo_votes` WHERE `postid` = " . intval($_POST['postid']) . " AND `userid` = " . intval($wpforo->current_userid) )){
432 $wpforo->notice->add('You are already voted this post');
433 echo json_encode(array('stat' => 0, 'notice' => $wpforo->notice->get_notices()));
434 exit();
435 }
436
437 $reaction = 1;
438 if( $_POST['votestatus'] == 'down' ) $reaction = -1;
439 $post = $wpforo->post->get_post( intval($_POST['postid']) );
440
441 $voted = $wpforo->db->insert(
442 $wpforo->db->prefix . 'wpforo_votes',
443 array(
444 'postid' => intval($_POST['postid']),
445 'userid' => $wpforo->current_userid,
446 'reaction' => $reaction,
447 'post_userid' => $post['userid']
448 ),
449 array(
450 '%d',
451 '%d',
452 '%d',
453 '%d'
454 )
455 );
456
457 if(!isset($post['userid'])) $wpforo->member->reset($post['userid']);
458 if(!isset($wpforo->current_userid)) $wpforo->member->reset($wpforo->current_userid);
459
460 if( $voted !== FALSE ){
461 if( $_POST['itemtype'] == 'topic' ){
462 $incr = $wpforo->db->query( "UPDATE ".$wpforo->db->prefix . 'wpforo_topics'." SET `votes` = `votes` + $reaction WHERE topicid = " . intval($post['topicid']) );
463 $incr2 = $wpforo->db->query( "UPDATE ".$wpforo->db->prefix . 'wpforo_posts'." SET `votes` = `votes` + $reaction WHERE postid = " . intval($post['postid']) );
464 }else{
465 $incr = $wpforo->db->query( "UPDATE ".$wpforo->db->prefix . 'wpforo_posts'." SET `votes` = `votes` + $reaction WHERE postid = " . intval($post['postid']) );
466 $incr2 = TRUE;
467 }
468
469 if($incr !== FALSE && $incr2 !== FALSE){
470 do_action('wpforo_vote', $reaction, $post, $wpforo->current_userid );
471 $wpforo->notice->add('Successfully voted', 'success');
472 echo json_encode(array('stat' => 1, 'notice' => $wpforo->notice->get_notices()));
473 exit();
474 }
475 }
476
477 $wpforo->notice->add('Wrong post data', 'error');
478 echo json_encode(array('stat' => 0, 'notice' => $wpforo->notice->get_notices()));
479 exit();
480 }
481
482 add_action('wp_ajax_wpforo_answer_ajax', 'wpf_answer');
483 function wpf_answer(){
484 global $wpforo;
485 $response = array('stat' => 0, 'notice' => $wpforo->notice->get_notices());
486 if(!is_user_logged_in()){
487 $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>' ) );
488 $response['notice'] = $wpforo->notice->get_notices();
489 echo json_encode($response);
490 exit();
491 }
492 if( !isset($_POST['answerstatus']) || !isset($_POST['postid']) || !$postid = intval($_POST['postid']) ){
493 $wpforo->notice->add('action error', 'error');
494 $response['notice'] = $wpforo->notice->get_notices();
495 echo json_encode($response);
496 exit();
497 }
498 if( !$post = $wpforo->post->get_post( $postid ) ){
499 $wpforo->notice->add('post not found', 'error');
500 $response['notice'] = $wpforo->notice->get_notices();
501 echo json_encode($response);
502 exit();
503 }
504 if( !$topic = $wpforo->topic->get_topic( $post['topicid'] ) ){
505 $wpforo->notice->add('topic not found', 'error');
506 $response['notice'] = $wpforo->notice->get_notices();
507 echo json_encode($response);
508 exit();
509 }
510 if( !($wpforo->perm->forum_can( 'at', $post['forumid'] ) || ( $wpforo->perm->forum_can( 'oat', $post['forumid']) && $wpforo->current_userid == $topic['userid'] ) ) ){
511 $wpforo->notice->add('You haven\'t permission to make topic answered', 'error');
512 $response['notice'] = $wpforo->notice->get_notices();
513 echo json_encode($response);
514 exit();
515 }
516 if( FALSE !== $wpforo->db->query( "UPDATE ".$wpforo->db->prefix ."wpforo_posts SET is_answer = ".intval($_POST['answerstatus'])." WHERE postid = " . intval($postid) ) ){
517 do_action('wpforo_answer', intval($_POST['answerstatus']), $post);
518 $wpforo->notice->add('done', 'success');
519 $response['stat'] = 1;
520 $response['notice'] = $wpforo->notice->get_notices();
521 }
522 echo json_encode($response);
523 exit();
524 }
525
526 add_action('wp_ajax_wpforo_quote_ajax', 'wpf_quote');
527 function wpf_quote(){
528
529 if(!is_user_logged_in()) return;
530
531 global $wpforo;
532
533 $post = $wpforo->db->get_row('SELECT `userid`, `body` FROM '.$wpforo->db->prefix.'wpforo_posts WHERE postid =' . intval($_POST['postid']), ARRAY_A);
534 $poster = $wpforo->member->get_member(intval($post['userid']));
535 echo '<blockquote><div class="wpforo-post-quote-author">' . wpforo_phrase('Posted by', FALSE) . ': ' . ( $poster['display_name'] ? esc_textarea($poster['display_name']) : esc_textarea($poster['user_login']) ) . '</div><i class="fa fa-quote-left fa-0x wpfcl-0"></i> &nbsp; ' . wpautop($post['body']) . ' &nbsp; &#160;</blockquote><br /><br />';
536 exit();
537 }
538
539 add_action('wp_ajax_wpforo_report_ajax', 'wpf_report');
540 function wpf_report(){
541
542 if(!is_user_logged_in()) return;
543
544 global $wpforo;
545
546 if( !isset($_POST['reportmsg']) || !$_POST['reportmsg'] || !isset($_POST['postid']) || !$_POST['postid'] ){
547 $wpforo->notice->add('Error: please insert some text to report.', 'error');
548 echo json_encode( $wpforo->notice->get_notices() );
549 exit();
550 }
551
552 ############### Sending Email ##################
553 $report_text = substr($_POST['reportmsg'], 0, 1000);
554 $postid = intval($_POST['postid']);
555 $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>';
556 $reportmsg = wpforo_kses($report_text, 'email');
557 $post_url = '<a target="_blank" href="'. esc_attr($wpforo->post->get_post_url($postid)).'">' . wpforo_phrase('Post link', false) . '&raquo;</a>';
558
559 $subject = $wpforo->subscribe_options['report_email_subject'];
560 $message = $wpforo->subscribe_options['report_email_message'];
561
562 $from_tags = array("[reporter]", "[message]", "[post_url]");
563 $to_words = array(sanitize_text_field($reporter), $reportmsg, $post_url);
564
565 $subject = str_replace($from_tags, $to_words, $subject);
566 $message = str_replace($from_tags, $to_words, $message);
567
568 $admin_email = get_option( 'admin_email' );
569 $admin_emails = $wpforo->subscribe_options['admin_emails'];
570 $admin_emails = trim($admin_emails);
571 $admin_emails = explode(',', $admin_emails);
572 $admin_emails = array_map('sanitize_email', $admin_emails);
573 $admin_email = (isset($admin_emails[0]) && $admin_emails[0]) ? $admin_emails[0] : $admin_email;
574 $headers = wpforo_admin_mail_headers();
575
576 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
577 if( wp_mail( $admin_email, $subject, $message, $headers ) ){
578 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
579 }else{
580 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
581 $wpforo->notice->add('Can\'t send report email', 'error');
582 echo json_encode( $wpforo->notice->get_notices() );
583 exit();
584 }
585
586 ############### Sending Email end ##############
587 $wpforo->notice->add('Message has been sent', 'success');
588 echo json_encode( $wpforo->notice->get_notices() );
589 exit();
590 }
591
592 add_action('wp_ajax_wpforo_sticky_ajax', 'wpf_sticky');
593 function wpf_sticky(){
594 if(!is_user_logged_in()) return;
595
596 if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); }
597 global $wpforo;
598 if( $_POST['status'] == 'sticky' ){
599 $sql = "UPDATE " . $wpforo->db->prefix . "wpforo_topics SET type = 1 WHERE topicid = " . intval($p_id);
600 $wpforo->db->query( $sql );
601 }elseif( $_POST['status'] == 'unsticky' ){
602 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET type = 0 WHERE topicid = " . intval($p_id);
603 $wpforo->db->query( $sql );
604 }
605 echo 1;
606 exit();
607 }
608
609 add_action('wp_ajax_wpforo_private_ajax', 'wpf_private');
610 function wpf_private(){
611 if(!is_user_logged_in()) return;
612
613 if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); }
614 global $wpforo;
615 if( $_POST['status'] == 'private' ){
616 $sql = "UPDATE " . $wpforo->db->prefix . "wpforo_topics SET private = 1 WHERE topicid = " . intval($p_id);
617 $wpforo->db->query( $sql );
618 }elseif( $_POST['status'] == 'public' ){
619 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET private = 0 WHERE topicid = " . intval($p_id);
620 $wpforo->db->query( $sql );
621 }
622 echo 1;
623 exit();
624 }
625
626 add_action('wp_ajax_wpforo_solved_ajax', 'wpf_solved');
627 function wpf_solved(){
628 if(!is_user_logged_in()) return;
629
630 if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); }
631 global $wpforo;
632 if( $_POST['status'] == 'solved' ){
633 $sql = "UPDATE " . $wpforo->db->prefix . "wpforo_posts SET is_answer = 1 WHERE postid = " . intval($p_id);
634 $wpforo->db->query( $sql );
635 }elseif( $_POST['status'] == 'unsolved' ){
636 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_posts SET is_answer = 0 WHERE postid = " . intval($p_id);
637 $wpforo->db->query( $sql );
638 }
639 echo 1;
640 exit();
641 }
642
643 add_action('wp_ajax_wpforo_close_ajax', 'wpf_close');
644 function wpf_close(){
645 if(!is_user_logged_in()) return;
646
647 if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); }
648 global $wpforo;
649 if( $_POST['status'] == 'closed' ){
650 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET closed = 0 WHERE topicid = " . intval($p_id);
651 $wpforo->db->query( $sql );
652 }elseif( $_POST['status'] == 'close' ){
653 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET closed = 1 WHERE topicid = " . intval($p_id);
654 $wpforo->db->query( $sql );
655 echo 1;
656 exit();
657 }
658 echo $wpforo->topic->get_topic_url($p_id);
659 exit();
660 }
661
662 add_action('wp_ajax_wpforo_edit_ajax', 'wpf_edit');
663 function wpf_edit(){
664 if(!is_user_logged_in()) return;
665
666 if( !isset($_POST['postid']) || !$_POST['postid'] ){ echo 0; exit(); }
667 global $wpforo;
668 $sql = 'SELECT t.title AS topic_title, p.title AS post_title, p.`body` FROM '.$wpforo->db->prefix.'wpforo_posts p INNER JOIN '.$wpforo->db->prefix.'wpforo_topics t ON t.topicid = p.topicid WHERE p.postid =' . intval($_POST['postid']);
669 if($post = $wpforo->db->get_row($sql, ARRAY_A) ){
670 $post['body'] = wpautop($post['body']);
671 echo json_encode($post);
672 exit();
673 }
674 echo 0;
675 exit();
676 }
677
678 add_action('wp_ajax_wpforo_delete_ajax', 'wpf_delete');
679 function wpf_delete(){
680 if(!is_user_logged_in()) return;
681
682 global $wpforo;
683
684 $resp = array();
685 if( $_POST['status'] == 'topic' ){
686 if( $wpforo->topic->delete(intval($_POST['postid'])) ){
687 $resp = array(
688 'postid' => intval($_POST['postid']),
689 'location' => $wpforo->forum->get_forum_url(intval($_POST['forumid']))
690 );
691 $return = 1;
692 }else{
693 $return = 0;
694 }
695 }elseif($_POST['status'] == 'reply'){
696 if( $wpforo->post->delete(intval($_POST['postid'])) ){
697 $resp = array(
698 'postid' => intval($_POST['postid'])
699 );
700 $return = 1;
701 }else{
702 $return = 0;
703 }
704 }
705
706 $resp['stat'] = $return;
707 $resp['notice'] = $wpforo->notice->get_notices();
708 echo json_encode( $resp );
709 exit();
710 }
711
712 add_action('wp_ajax_wpforo_subscribe_ajax', 'wpf_subscribe');
713 function wpf_subscribe(){
714 if(!is_user_logged_in()) return FALSE;
715
716 global $wpforo;
717
718 $args = array(
719 'itemid' => intval($_POST['itemid']),
720 'type' => sanitize_text_field($_POST['type']),
721 'userid' => intval($wpforo->current_userid)
722 );
723
724 if(isset($_POST['status']) && $_POST['status'] == 'subscribe'){
725
726 if($_POST['type'] == 'forum'){
727 $forum = $wpforo->forum->get_forum(intval($_POST['itemid']));
728 if( isset($forum['forumid']) && $forum['forumid'] ){
729 if( !$wpforo->perm->forum_can('vf', $forum['forumid']) ){
730 $wpforo->notice->add('You are not permitted to subscribe here', 'error');
731 $return = 0;
732 }
733 }
734 }elseif($_POST['type'] == 'topic'){
735 $topic = $wpforo->topic->get_topic(intval($_POST['itemid']));
736 if( isset($topic['forumid']) && $topic['forumid'] ){
737 if( isset($topic['private']) && $topic['private'] && !wpforo_is_owner($topic['userid']) ){
738 if( !$wpforo->perm->forum_can('vp', $topic['forumid']) ){
739 $wpforo->notice->add('You are not permitted to subscribe here', 'error');
740 $return = 0;
741 }
742 }
743 }
744 }
745
746 $args['confirmkey'] = $wpforo->sbscrb->get_confirm_key();
747
748 if( wpforo_feature('subscribe_conf', $wpforo) ){
749 ############### Sending Email ##################
750 $confirmlink = $wpforo->sbscrb->get_confirm_link($args);
751 $member_name = (isset($wpforo->current_user_display_name) && $wpforo->current_user_display_name) ? $wpforo->current_user_display_name : urldecode($wpforo->current_user['user_nicename']);
752 if($_POST['type'] == 'forum'){
753 $item_title = $forum['title'];
754 }elseif($_POST['type'] == 'topic'){
755 $item_title = $topic['title'];
756 }
757 $subject = $wpforo->subscribe_options['confirmation_email_subject'];
758 $message = $wpforo->subscribe_options['confirmation_email_message'];
759 $from_tags = array("[member_name]", "[entry_title]", "[confirm_link]");
760 $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>');
761 $subject = str_replace($from_tags, $to_words, $subject);
762 $message = str_replace($from_tags, $to_words, $message);
763 $message = wpforo_kses($message, 'email');
764
765 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
766 $headers = wpforo_mail_headers();
767
768 if( wp_mail( $wpforo->current_user_email , sanitize_text_field($subject), $message, $headers ) ){
769 if( $wpforo->sbscrb->add($args) ){
770 $return = 1;
771 }else{
772 $return = 0;
773 }
774 }else{
775 $wpforo->notice->add('Can\'t send confirmation email', 'error');
776 $return = 0;
777 }
778 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
779 ############### Sending Email end ##############
780 }
781 else{
782 $args['active'] = 1;
783 if( $wpforo->sbscrb->add($args) ){
784 $return = 1;
785 }else{
786 $return = 0;
787 }
788 }
789
790 }elseif(isset($_POST['status']) && $_POST['status'] == 'unsubscribe'){
791 $subscribe = $wpforo->sbscrb->get_subscribe( $args );
792 $return = (int) $wpforo->sbscrb->delete( $subscribe['confirmkey'] );
793 }
794
795 $resp['stat'] = $return;
796 $resp['notice'] = $wpforo->notice->get_notices();
797 echo json_encode( $resp );
798 exit();
799 }
800
801 ############### Sending Email ##################
802 function wpforo_set_html_content_type(){
803 return 'text/html';
804 }
805
806 function wpforo_wp_mail_from_name($name){
807 global $wpforo;
808 if(isset($wpforo->subscribe_options['from_name']) && $wpforo->subscribe_options['from_name']){
809 return $wpforo->subscribe_options['from_name'];
810 }
811 else{
812 return $name;
813 }
814 }
815
816 function wpforo_wp_mail_from_email($email){
817 global $wpforo;
818 if(isset($wpforo->subscribe_options['from_email']) && $wpforo->subscribe_options['from_email']){
819 return $wpforo->subscribe_options['from_email'];
820 }
821 else{
822 return $email;
823 }
824 }
825
826 function wpforo_mail_from_name(){
827 global $wpforo; if(isset($wpforo->subscribe_options['from_name']) && $wpforo->subscribe_options['from_name']){ return $wpforo->subscribe_options['from_name']; } else {return get_option('blogname');}
828 }
829
830 function wpforo_mail_from_email(){
831 global $wpforo; if(isset($wpforo->subscribe_options['from_email']) && $wpforo->subscribe_options['from_email']){return $wpforo->subscribe_options['from_email'];} else {return get_option( 'admin_email' );}
832 }
833
834 function wpforo_mail_headers($from_name = '', $from_email = '', $cc = array(), $bcc = array()){
835 global $wpforo;
836 $H = array();
837 if(!$from_name) $from_name = wpforo_mail_from_name();
838 if(!$from_email) $from_email = wpforo_mail_from_email();
839 $H[] = 'From: ' . $from_name . ' <' . $from_email . '>';
840 if(!empty($cc)){
841 foreach($cc as $c){ $c = sanitize_email($c); $H[] = 'CC: ' . $c; }
842 }
843 if(!empty($bcc)){
844 foreach($bcc as $b){ $b = sanitize_email($b); $H[] = 'BCC: ' . $b; }
845 }
846 return $H;
847 }
848
849 function wpforo_admin_mail_headers($from_name = '', $from_email = '', $cc = array(), $bcc = array()){
850 global $wpforo;
851 $H = array();
852 if(!$from_name) $from_name = wpforo_mail_from_name();
853 if(!$from_email) $from_email = wpforo_mail_from_email();
854 $H[] = 'From: ' . $from_name . ' <' . $from_email . '>';
855 if(empty($cc)){
856 $cc = trim($wpforo->subscribe_options['admin_emails']);
857 $cc = explode(',', $cc);
858 $cc = array_map('trim', $cc);
859 }
860 if(!empty($cc)){
861 foreach($cc as $c){ $c = sanitize_email($c); $H[] = 'CC: ' . $c; }
862 }
863 if(!empty($bcc)){
864 foreach($bcc as $b){ $b = sanitize_email($b); $H[] = 'BCC: ' . $b; }
865 }
866 return $H;
867 }
868
869 ############### Sending Email end ##############
870
871 function wpforo_frontend_enqueue(){
872
873 global $wpforo;
874
875 if( is_wpforo_page() ){
876 wp_enqueue_script('jquery-ui-core');
877 wp_enqueue_script('jquery-ui-dialog');
878 wp_register_script( 'wpforo-frontend-js', WPFORO_URL . '/wpf-assets/js/frontend.js', array('jquery'), WPFORO_VERSION, false );
879 wp_enqueue_script('wpforo-frontend-js');
880 if( wpforo_feature( 'font-awesome', $wpforo) ){
881 wp_register_style('wpforo-font-awesome', WPFORO_URL . '/wpf-assets/css/font-awesome/css/font-awesome.min.css', false, '4.7' );
882 wp_enqueue_style('wpforo-font-awesome');
883 if (is_rtl()) {
884 wp_register_style('wpforo-font-awesome-rtl', WPFORO_URL . '/wpf-assets/css/font-awesome/font-awesome-rtl.css', false, WPFORO_VERSION );
885 wp_enqueue_style('wpforo-font-awesome-rtl');
886 }
887 }
888 if(is_user_logged_in()){
889 wp_register_script('wpforo-ajax', WPFORO_URL . '/wpf-assets/js/ajax.js', array('jquery'), WPFORO_VERSION, false);
890 wp_enqueue_script('wpforo-ajax');
891 wp_localize_script('wpforo-ajax', 'wpf_ajax_obj', array( 'url' => admin_url('admin-ajax.php'), 'phrases' => $wpforo->phrases ));
892 }
893 if (is_rtl()) {
894 wp_register_style('wpforo-style-rtl', WPFORO_TEMPLATE_URL . '/style-rtl.css', false, WPFORO_VERSION );
895 wp_enqueue_style('wpforo-style-rtl');
896 }
897 else{
898 wp_register_style('wpforo-style', WPFORO_TEMPLATE_URL . '/style.css', false, WPFORO_VERSION );
899 wp_enqueue_style('wpforo-style');
900 }
901 }
902
903 if (is_rtl()) {
904 wp_register_style('wpforo-widgets-rtl', WPFORO_TEMPLATE_URL . '/widgets-rtl.css', false, WPFORO_VERSION );
905 wp_enqueue_style('wpforo-widgets-rtl');
906 }
907 else{
908 wp_register_style('wpforo-widgets', WPFORO_TEMPLATE_URL . '/widgets.css', false, WPFORO_VERSION );
909 wp_enqueue_style('wpforo-widgets');
910 }
911 }
912 add_action('wp_enqueue_scripts', 'wpforo_frontend_enqueue');
913
914 function wpforo_add_into_wp_head(){
915 global $wpforo;
916
917 if(!$wpforo->perm->forum_can('va')){
918 ?>
919 <script type="text/javascript">
920 jQuery(document).ready(function($){
921 $(document).on('click','.attach_cant_view', function(){
922 $("#wpf-msg-box").hide();
923 $('#wpforo-load').visible();
924 $("#wpf-msg-box p.wpf-msg-box-triangle-right").removeClass("error").removeClass("success");
925 $("#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>");
926 $("#wpf-msg-box").show(150).delay(1000);
927 $('#wpforo-load').invisible();
928 });
929 });
930 </script>
931 <?php
932 }
933 }
934 add_action('wp_head', 'wpforo_add_into_wp_head');
935
936 function wpforo_dynamic_style() {
937
938 if(!is_wpforo_page()) return;
939
940 global $wpforo;
941 $inline = false;
942 $dynamic_css_file = WPFORO_TEMPLATE_DIR . '/colors.css';
943 $dynamic_css_matrix = WPFORO_TEMPLATE_DIR . '/styles/css.php';
944 if( isset($wpforo->theme_options) ){
945 if( !isset($wpforo->theme_options['style']) || !isset($wpforo->theme_options['styles']) ) return false;
946 $style = $wpforo->theme_options['style'];
947 $styles = $wpforo->theme_options['styles'];
948 if( !empty($style) && !empty($styles) ){
949 foreach( $styles[$style] as $color_key => $color_value ){
950 if( $color_value ) {
951 $COLORS[ 'WPFCOLOR_' . $color_key ] = $color_value;
952 }
953 }
954 }
955 else{
956 return false;
957 }
958 }
959 else{
960 return false;
961 }
962 extract($COLORS, EXTR_OVERWRITE);
963 if( file_exists( $dynamic_css_matrix ) ){
964 require_once( $dynamic_css_matrix );
965 $css = apply_filters('wpforo_dynamic_css_filter', $css, $COLORS);
966 }
967 else{
968 return false;
969 }
970 $hach_new = md5($css);
971 if( file_exists( $dynamic_css_file ) && filesize($dynamic_css_file) ){
972 $css_current = wpforo_get_file_content( $dynamic_css_file );
973 if( $css_current ){
974 $hach_current = md5($css_current);
975 if( $hach_new == $hach_current ){
976 //CSS not changed
977 }
978 else{
979 $result = wpforo_write_file( $dynamic_css_file, $css );
980 if( isset($result['error']) && $result['error'] ){
981 $inline = true;
982 }
983 else{
984 //CSS updated
985 }
986 }
987 }
988 }
989 else{
990 $result = wpforo_write_file( $dynamic_css_file, $css );
991 if( isset($result['error']) && $result['error'] ){
992 $inline = true;
993 }
994 }
995 if( $inline ){
996 $css = preg_replace('|[\r\n\t]+|', '', $css );
997 wp_register_style( 'wpforo-dynamic-inline', WPFORO_TEMPLATE_URL . '/css/wpforo_dynamic-inline.css', false, WPFORO_VERSION );
998 wp_enqueue_style( 'wpforo-dynamic-inline' );
999 wp_add_inline_style( 'wpforo-dynamic-inline', $css );
1000 }
1001 }
1002 add_action( 'wp_enqueue_scripts', 'wpforo_dynamic_style' );
1003
1004 function wpforo_style_options($css, $COLORS){
1005 global $wpforo;
1006 if( !isset($css)) return;
1007 if( isset($wpforo->style_options['font_size_forum']) && $wpforo->style_options['font_size_forum'] != 17 ){
1008 $css .= "\r\n#wpforo-wrap .wpforo-forum-title{font-size: " . intval($wpforo->style_options['font_size_forum']) . "px!important; line-height: " . (intval($wpforo->style_options['font_size_forum']) + 1) . "px!important;}";
1009 }
1010 if( isset($wpforo->style_options['font_size_topic']) && $wpforo->style_options['font_size_topic'] != 16 ){
1011 $css .= "\r\n#wpforo-wrap .wpforo-topic-title a { font-size: " . intval($wpforo->style_options['font_size_topic']) . "px!important; line-height: " . (intval($wpforo->style_options['font_size_topic']) + 4) . "px!important; }";
1012 }
1013 if( isset($wpforo->style_options['font_size_post_content']) && $wpforo->style_options['font_size_post_content'] != 14 ){
1014 $css .= "\r\n#wpforo-wrap .wpforo-post .wpf-right .wpforo-post-content {font-size: " . intval($wpforo->style_options['font_size_post_content']) . "px!important; line-height: " . (intval($wpforo->style_options['font_size_post_content']) + 4) . "px!important;}\r\n#wpforo-wrap .wpforo-post .wpf-right .wpforo-post-content p {font-size: " . intval($wpforo->style_options['font_size_post_content']) . "px;}";
1015 }
1016 if( isset($wpforo->style_options['custom_css']) ){
1017 $css .= "\r\n" . stripslashes($wpforo->style_options['custom_css']);
1018 }
1019 return $css;
1020 }
1021 add_filter( 'wpforo_dynamic_css_filter' , 'wpforo_style_options' , 10, 2 );
1022
1023 function wpforo_admin_enqueue(){
1024 global $wpforo;
1025 $phrases = array(
1026 'move' => __('Move', 'wpforo'),
1027 'delete' => __('Delete', 'wpforo')
1028 );
1029 if( !empty($_GET['page']) && FALSE !== strpos( $_GET['page'], 'wpforo' ) ){
1030 if( wpforo_feature( 'font-awesome', $wpforo) ){
1031 wp_register_style('wpforo-font-awesome', WPFORO_URL . '/wpf-assets/css/font-awesome/css/font-awesome.min.css', false, '4.6.3' );
1032 wp_enqueue_style('wpforo-font-awesome');
1033 }
1034 wp_register_style('wpforo-admin', WPFORO_URL . '/wpf-admin/css/admin.css', false, WPFORO_VERSION );
1035 wp_enqueue_style('wpforo-admin');
1036 wp_enqueue_script('jquery');
1037 wp_enqueue_script('jquery-ui-core');
1038 wp_enqueue_script('jquery-ui-widget');
1039 wp_enqueue_script('jquery-ui-mouse');
1040 wp_enqueue_script('jquery-ui-position');
1041 wp_enqueue_script('jquery-ui-draggable');
1042 wp_enqueue_script('jquery-ui-droppable');
1043 wp_enqueue_script('jquery-ui-menu');
1044 wp_enqueue_script('jquery-ui-sortable');
1045 wp_enqueue_script('jquery-color');
1046 wp_enqueue_script('wp-lists');
1047 if( $_GET['page'] == 'wpforo-forums' ){
1048 if( !empty($_GET['action']) ){
1049 //Just for excluding 'nav-menu' js loading//
1050 wp_enqueue_script('postbox');
1051 wp_enqueue_script('link');
1052 }
1053 else{
1054 wp_enqueue_script('nav-menu');
1055 }
1056 }
1057 elseif( $_GET['page'] == 'wpforo-settings' && !empty($_GET['tab']) && $_GET['tab'] == 'styles' ){
1058 wp_enqueue_style('wp-color-picker');
1059 wp_enqueue_script('iris', admin_url('js/iris.min.js'),array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), false, 1);
1060 wp_enqueue_script('wp-color-picker', admin_url('js/color-picker.min.js'), array('iris'), false,1);
1061 $colorpicker_l10n = array('clear' => __('Clear'), 'defaultString' => __('Default'), 'pick' => __('Select Color'));
1062 wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', $colorpicker_l10n );
1063 }
1064 elseif( $_GET['page'] == 'wpforo-community' ){
1065 wp_enqueue_script('postbox');
1066 wp_enqueue_script('link');
1067 }
1068 elseif( $_GET['page'] == 'wpforo-addons' ){
1069 wp_register_script( 'wpforo-contenthover', WPFORO_URL . '/wpf-admin/js/contenthover/jquery.contenthover.min.js', array('jquery'), WPFORO_VERSION, false );
1070 wp_enqueue_script( 'wpforo-contenthover' );
1071 }
1072 wp_localize_script( 'wpforo-basic_js', 'wpforo_admin', array('phrases' => $phrases) );
1073 wp_register_script( 'wpforo-contenthover', WPFORO_URL . '/wpf-admin/js/functions.js', array('jquery'), WPFORO_VERSION, false );
1074 wp_enqueue_script( 'wpforo-contenthover' );
1075
1076 }
1077 }
1078 add_action( 'admin_enqueue_scripts', 'wpforo_admin_enqueue' );
1079
1080 function wpforo_admin_permalink_notice() {
1081 $permalink_structure = get_option( 'permalink_structure' );
1082 if( !$permalink_structure ){
1083 $class = 'notice notice-warning';
1084 $message = __( 'IMPORTANT: wpForo can\'t work with default permalink, please change permalink structure', 'wpforo' );
1085 printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
1086 }
1087
1088 }
1089 add_action( 'admin_notices', 'wpforo_admin_permalink_notice' );
1090
1091 function wpforo_userform_to_wpuser_html_form($wp_user){
1092 if( is_super_admin() ){
1093 global $wpforo;
1094
1095 if( is_object($wp_user) ){
1096 $user = $wpforo->member->get_member($wp_user->ID);
1097 $groupid = $user['groupid'];
1098 $timezone = $user['timezone'];
1099 }
1100 if( !isset($groupid) ) $groupid = 0;
1101 if( !isset($timezone) ) $timezone = '';
1102
1103 echo '<table class="form-table">
1104 <tr class="form-field">
1105 <th scope="row"><label for="wpforo_usergroup">' . __('wpForo Usergroup', 'wpforo') . '</label></th>
1106 <td>
1107 <select name="wpforo_usergroup" id="wpforo_usergroup">';
1108 $wpforo->usergroup->show_selectbox($groupid);
1109 echo ' </select>
1110 </td>
1111 </tr>
1112 <tr class="form-field">
1113 <th scope="row"><label for="wpforo_usertimezone">' . __('wpForo User Timezone', 'wpforo') . '</label></th>
1114 <td>
1115 <select name="wpforo_usertimezone" id="wpforo_usertimezone">
1116 ' . wp_timezone_choice($timezone) .
1117 '</select>
1118 </td>
1119 </tr>
1120 </table>';
1121
1122 }
1123 }
1124 add_action( 'user_new_form', 'wpforo_userform_to_wpuser_html_form' );
1125 add_action( 'show_user_profile', 'wpforo_userform_to_wpuser_html_form' );
1126 add_action( 'edit_user_profile', 'wpforo_userform_to_wpuser_html_form' );
1127
1128 function wpforo_do_hook_user_register($userid){
1129 global $wpforo;
1130 $wpforo->member->synchronize_user($userid);
1131 }
1132 add_action( 'user_register', 'wpforo_do_hook_user_register', 10, 1 );
1133
1134 function wpforo_do_hook_update_profile($userid){
1135 global $wpforo;
1136 if( isset($_POST['wpforo_usergroup']) && $_POST['wpforo_usergroup'] ){
1137 $wpforo->member->edit_profile( array( 'userid' => intval($userid),
1138 'groupid' => intval($_POST['wpforo_usergroup']),
1139 'site' => esc_url($_POST['url']),
1140 'about' => wpforo_kses($_POST['description'], 'user_description'),
1141 'timezone' => ( isset($_POST['wpforo_usertimezone']) ? sanitize_text_field($_POST['wpforo_usertimezone']) : '' ) ) );
1142 }
1143 $wpforo->member->reset($userid);
1144 }
1145 add_action('personal_options_update', 'wpforo_do_hook_update_profile');
1146 add_action('edit_user_profile_update', 'wpforo_do_hook_update_profile');
1147
1148 function wpforo_update_last_login_date($user_login, $user = array()){
1149 if(empty($user)) return;
1150 global $wpforo;
1151 $wpforo->member->edit_profile( array( 'userid' => intval($user->ID), 'last_login' => current_time( 'mysql', 1 ) ) );
1152 }
1153 add_action('wp_login', 'wpforo_update_last_login_date', 10, 2);
1154
1155 function wpforo_do_hook_deleted_user($userid){
1156 global $wpforo;
1157 if( !empty($_REQUEST['wpforo_user_delete_option']) && $_REQUEST['wpforo_user_delete_option'] == 'reassign' && !empty($_REQUEST['wpforo_reassign_user']) ){
1158 $wpforo->member->delete( $userid, $_REQUEST['wpforo_reassign_user'] );
1159 }else{
1160 $wpforo->member->delete( $userid );
1161 }
1162 $wpforo->notice->clear();
1163 }
1164 add_action( 'deleted_user', 'wpforo_do_hook_deleted_user' );
1165
1166 function wpforo_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
1167 global $wpforo;
1168 if(!wpforo_feature('replace-avatar', $wpforo)) return $avatar;
1169 $user = false;
1170 if ( is_numeric( $id_or_email ) ) {
1171 $id = (int) $id_or_email;
1172 $user = get_user_by( 'id' , $id );
1173 }elseif( is_object( $id_or_email ) ) {
1174 if ( ! empty( $id_or_email->user_id ) ) {
1175 $id = (int) $id_or_email->user_id;
1176 $user = get_user_by( 'id' , $id );
1177 }
1178 }else{
1179 $user = get_user_by( 'email', $id_or_email );
1180 }
1181
1182 if( $user && is_object( $user ) ){
1183 if( $src = $wpforo->member->get_avatar_url($user->data->ID) ){
1184 $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) . "' />";
1185 }
1186 }
1187 return $avatar;
1188 }
1189 add_filter( 'get_avatar' , 'wpforo_avatar' , 10, 5 );
1190
1191 function wpforo_topic_auto_subscribe($item){
1192 if(!is_user_logged_in()) return FALSE;
1193 if(!isset($_POST['wpforo_topic_subs']) || !$_POST['wpforo_topic_subs'] ) return FALSE;
1194
1195 global $wpforo;
1196
1197 if( isset($item['forumid']) && $item['forumid'] ){
1198 if( isset($item['private']) && $item['private'] && !wpforo_is_owner($item['userid']) ){
1199 if( !$wpforo->perm->forum_can('vp', $item['forumid']) ){
1200 $wpforo->notice->add('You are not permitted to subscribe here', 'error');
1201 return FALSE;
1202 }
1203 }
1204 else{
1205 //This is not a Private Topic or Current User is the owner.
1206 }
1207 }
1208 else{
1209 $wpforo->notice->add('Forum ID is not detected', 'error');
1210 return FALSE;
1211 }
1212
1213 $args = array(
1214 'itemid' => intval($item['topicid']),
1215 'type' => 'topic',
1216 'userid' => intval($wpforo->current_userid)
1217 );
1218
1219 $args['confirmkey'] = $wpforo->sbscrb->get_confirm_key();
1220
1221 if( wpforo_feature('subscribe_conf', $wpforo) ){
1222 ############### Sending Email ##################
1223 $confirmlink = $wpforo->sbscrb->get_confirm_link($args);
1224 $member_name = (isset($wpforo->current_user_display_name) && $wpforo->current_user_display_name) ? $wpforo->current_user_display_name : urldecode($wpforo->current_user['user_nicename']);
1225 $subject = $wpforo->subscribe_options['confirmation_email_subject'];
1226 $message = $wpforo->subscribe_options['confirmation_email_message'];
1227 $topic = $wpforo->topic->get_topic( $item['topicid'] );
1228 $from_tags = array("[member_name]", "[entry_title]", "[confirm_link]");
1229 $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>');
1230 $subject = str_replace($from_tags, $to_words, $subject);
1231 $message = str_replace($from_tags, $to_words, $message);
1232 $message = wpforo_kses($message, 'email');
1233
1234 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1235 $headers = wpforo_mail_headers();
1236
1237 if( wp_mail( $wpforo->current_user_email , sanitize_text_field($subject), $message, $headers ) ){
1238 if( $response = $wpforo->sbscrb->add($args) ) return $response;
1239 }else{
1240 $wpforo->notice->add('Can\'t send confirmation email', 'error');
1241 return FALSE;
1242 }
1243 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1244 ############### Sending Email end ##############
1245 }else{
1246 $args['active'] = 1;
1247 if( $response = $wpforo->sbscrb->add($args) ) return $response;
1248 }
1249 return FALSE;
1250 }
1251 add_action( 'wpforo_after_add_topic', 'wpforo_topic_auto_subscribe', 10, 1 );
1252 add_action( 'wpforo_after_add_post', 'wpforo_topic_auto_subscribe', 10, 1 );
1253
1254 function wpforo_forum_subscribers_mail_sender( $topic ){
1255
1256 global $wpforo;
1257
1258 $subscribers = $wpforo->sbscrb->get_subscribes( array( 'itemid' => $topic['forumid'], 'type' => 'forum' ) );
1259 if( $wpforo->subscribe_options['new_topic_notify'] ){
1260 $admin_emails = explode(',', $wpforo->subscribe_options['admin_emails']);
1261 foreach( $admin_emails as $admin_email ) $subscribers[] = sanitize_email( $admin_email );
1262 }
1263 foreach($subscribers as $subscriber){
1264
1265 if( is_array($subscriber) ){
1266 $member = $wpforo->member->get_member( $subscriber['userid'] );
1267 $unsubscribe_link = $wpforo->sbscrb->get_unsubscribe_link($subscriber['confirmkey']);
1268 }else{
1269 $member = array('display_name' => $subscriber, 'user_email' => $subscriber);
1270 $unsubscribe_link = '#';
1271 }
1272
1273 if( isset($topic['forumid']) && $topic['forumid'] ){
1274 if( isset($topic['private']) && $topic['private'] && $topic['userid'] != $subscriber['userid'] ){
1275 $subscriber_goupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : $wpforo->usergroup->get_groupid_by_userid($subscriber['userid']);
1276 if( !$wpforo->perm->forum_can('vp', $topic['forumid'], $subscriber_goupid) ){
1277 continue;
1278 }
1279 }
1280 if( isset($topic['status']) && $topic['status'] == 1 ){
1281 $subscriber_goupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : $wpforo->usergroup->get_groupid_by_userid($subscriber['userid']);
1282 if( !$wpforo->perm->forum_can('au', $topic['forumid'], $subscriber_goupid) ){
1283 continue;
1284 }
1285 }
1286 }
1287
1288 $owner = $wpforo->member->get_member( $topic['userid'] );
1289
1290 if($owner['user_email'] == $member['user_email']) continue;
1291
1292 $forum = $wpforo->forum->get_forum( $topic['forumid'] );
1293
1294 ############### Sending Email ##################
1295
1296 if( isset($topic['status']) && $topic['status'] ){
1297 $subject_prefix = __('Please Moderate: ', 'wpforo');
1298 $mod_text = '<br /><br /><p style="color:#DD0000">' . __('This topic is currently unapproved. You can approve topics in Dashboard &raquo; Forums &raquo; Moderation admin page.', 'wpforo') . '</p>';
1299 }
1300 else{
1301 $subject_prefix = '';
1302 $mod_text = '';
1303 }
1304
1305 $subject = $wpforo->subscribe_options['new_topic_notification_email_subject'];
1306 $message = $wpforo->subscribe_options['new_topic_notification_email_message'];
1307
1308 $from_tags = array( "[member_name]", "[forum]", "[unsubscribe_link]", "[topic_title]", "[topic_desc]");
1309 $to_words = array( sanitize_text_field($member['display_name']),
1310 '<a href="' . esc_url($forum['url']) . '">' . sanitize_text_field($forum['title']) . '</a>',
1311 '<br><a target="_blank" href="' . esc_url($unsubscribe_link) . '">' . wpforo_phrase('Unsubscribe', false) . '</a>' ,
1312 '<a target="_blank" href="' . esc_url($topic['topicurl']) . '">' . sanitize_text_field($topic['title']) . '</a>' ,
1313 wpforo_text( wpforo_kses( $topic['body'], 'email'), 70, FALSE ) );
1314
1315 $subject = str_replace($from_tags, $to_words, $subject);
1316 $message = str_replace($from_tags, $to_words, $message);
1317
1318 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1319 $headers = wpforo_mail_headers();
1320 $subject = $subject_prefix . $subject;
1321 $message = $message . $mod_text;
1322 $email_status = wp_mail( $member['user_email'] , $subject, $message, $headers );
1323 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1324
1325 ############### Sending Email end ##############
1326
1327 }
1328 }
1329 add_action( 'wpforo_after_add_topic', 'wpforo_forum_subscribers_mail_sender', 12, 1 );
1330
1331
1332
1333 function wpforo_topic_subscribers_mail_sender( $post ){
1334 global $wpforo;
1335
1336 $subscribers = $wpforo->sbscrb->get_subscribes( array( 'itemid' => $post['topicid'], 'type' => 'topic' ) );
1337 if( $wpforo->subscribe_options['new_reply_notify'] ){
1338 $admin_emails = explode(',', $wpforo->subscribe_options['admin_emails']);
1339 foreach( $admin_emails as $admin_email ) $subscribers[] = sanitize_email( $admin_email );
1340 }
1341
1342 $topic = $wpforo->topic->get_topic( $post['topicid'] );
1343
1344 foreach($subscribers as $subscriber){
1345
1346 if( is_array($subscriber) ){
1347 $member = $wpforo->member->get_member( $subscriber['userid'] );
1348 $unsubscribe_link = $wpforo->sbscrb->get_unsubscribe_link($subscriber['confirmkey']);
1349 }else{
1350 $member = array('display_name' => $subscriber, 'user_email' => $subscriber);
1351 $unsubscribe_link = '#';
1352 }
1353
1354 $owner = $wpforo->member->get_member( $post['userid'] );
1355 if($owner['user_email'] == $member['user_email']) continue;
1356
1357
1358 if( isset($topic['forumid']) && $topic['forumid'] ){
1359 if( isset($topic['private']) && $topic['private'] && $topic['userid'] != $subscriber['userid'] ){
1360 $subscriber_goupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : $wpforo->usergroup->get_groupid_by_userid($subscriber['userid']);
1361 if( !$wpforo->perm->forum_can('vp', $topic['forumid'], $subscriber_goupid) ){
1362 continue;
1363 }
1364 }
1365 if( isset($topic['status']) && $topic['status'] == 1 ){
1366 $subscriber_goupid = ( isset($member['groupid']) && $member['groupid'] ) ? $member['groupid'] : $wpforo->usergroup->get_groupid_by_userid($subscriber['userid']);
1367 if( !$wpforo->perm->forum_can('au', $topic['forumid'], $subscriber_goupid) ){
1368 continue;
1369 }
1370 }
1371 }
1372
1373 ############### Sending Email ##################
1374
1375 if( isset($post['status']) && $post['status'] ){
1376 $subject_prefix = __('Please Moderate: ', 'wpforo');
1377 $mod_text = '<br /><br /><p style="color:#DD0000">' . __('This post is currently unapproved. You can approve posts in Dashboard &raquo; Forums &raquo; Moderation admin page.', 'wpforo') . '</p>';
1378 }
1379 else{
1380 $subject_prefix = '';
1381 $mod_text = '';
1382 }
1383
1384 $subject = $wpforo->subscribe_options['new_post_notification_email_subject'];
1385 $message = $wpforo->subscribe_options['new_post_notification_email_message'];
1386
1387 $from_tags = array( "[member_name]", "[topic]", "[unsubscribe_link]", "[reply_title]", "[reply_desc]");
1388 $to_words = array( sanitize_text_field($member['display_name']),
1389 '<a href="' . esc_url($post['posturl']) . '">' . sanitize_text_field($topic['title']) . '</a>',
1390 '<br><a target="_blank" href="' . esc_url($unsubscribe_link) . '">'.wpforo_phrase('Unsubscribe', false).'</a>' ,
1391 '<a target="_blank" href="' . esc_url($post['posturl']) . '">' . sanitize_text_field($post['title']) . '</a>' ,
1392 wpforo_text( wpforo_kses($post['body'], 'email'), 70, FALSE ) );
1393
1394 $subject = str_replace($from_tags, $to_words, $subject);
1395 $message = str_replace($from_tags, $to_words, $message);
1396
1397 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1398 $headers = wpforo_mail_headers();
1399 $subject = $subject_prefix . $subject;
1400 $message = $message . $mod_text;
1401 $email_status = wp_mail( $member['user_email'] , $subject, $message, $headers );
1402 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1403
1404 ############### Sending Email end ##############
1405
1406 }
1407 }
1408 add_action( 'wpforo_after_add_post', 'wpforo_topic_subscribers_mail_sender', 13, 1 );
1409
1410
1411 function wpforo_add_default_attachment($args){
1412 if( !empty($_FILES['attachfile']) && !empty($_FILES['attachfile']['name']) ){
1413 global $wpforo;
1414 if( $wpforo->perm->can_attach() ){
1415 $name = sanitize_file_name($_FILES['attachfile']['name']); //myimg.png
1416 $type = sanitize_mime_type($_FILES['attachfile']['type']); //image/png
1417 $tmp_name = sanitize_text_field($_FILES['attachfile']['tmp_name']); //D:\wamp\tmp\php986B.tmp
1418 $error = intval($_FILES['attachfile']['error']); //0
1419 $size = intval($_FILES['attachfile']['size']); //6112
1420
1421 $phpFileUploadErrors = array(
1422 0 => 'There is no error, the file uploaded with success',
1423 1 => 'The uploaded file size is too big',
1424 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
1425 3 => 'The uploaded file was only partially uploaded',
1426 4 => 'No file was uploaded',
1427 6 => 'Missing a temporary folder',
1428 7 => 'Failed to write file to disk.',
1429 8 => 'A PHP extension stopped the file upload.',
1430 );
1431
1432 if( $error ){
1433 $wpforo->notice->add($phpFileUploadErrors[$error], 'error');
1434 return $args;
1435 }elseif( $size > $wpforo->post_options['max_upload_size'] ){
1436 $wpforo->notice->add('The uploaded file size is too big', 'error');
1437 return $args;
1438 }
1439
1440 if(function_exists('pathinfo')){
1441 $ext = pathinfo($name, PATHINFO_EXTENSION);
1442 }
1443 else{
1444 $ext = substr(strrchr($name, '.'), 1);
1445 }
1446 $ext = strtolower($ext);
1447 $mime_types = get_allowed_mime_types();
1448 $mime_types = array_flip($mime_types);
1449 if(!empty($mime_types)){
1450 $allowed_types = implode('|', $mime_types);
1451 $expld = explode('|', $allowed_types);
1452 if( !in_array($ext, $expld) ){
1453 $wpforo->notice->add('File type is not allowed', 'error');
1454 return $args;
1455 }
1456 if( !$wpforo->perm->can_attach_file_type($ext) ){
1457 $wpforo->notice->add('You are not allowed to attach this file type', 'error');
1458 return $args;
1459 }
1460 }
1461
1462 $wp_upload_dir = wp_upload_dir();
1463 $uplds_dir = $wp_upload_dir['basedir']."/wpforo";
1464 $attach_dir = $wp_upload_dir['basedir']."/wpforo/default_attachments";
1465 $attach_url = preg_replace('#^https?\:#is', '', $wp_upload_dir['baseurl'])."/wpforo/default_attachments";
1466 if(!is_dir($uplds_dir)) wp_mkdir_p($uplds_dir);
1467 if(!is_dir($attach_dir)) wp_mkdir_p($attach_dir);
1468
1469 $fnm = pathinfo($name, PATHINFO_FILENAME);
1470 $fnm = str_replace(' ', '-', $fnm);
1471 while(strpos($fnm, '--') !== FALSE) $fnm = str_replace('--', '-', $fnm);
1472 $fnm = preg_replace("/[^-a-zA-Z0-9]/", "", $fnm);
1473 $fnm = trim($fnm, "-");
1474 $fnm_empty = ( $fnm ? FALSE : TRUE );
1475
1476 $file_name = $fnm . "." . $ext;
1477
1478 $attach_fname = current_time( 'timestamp', 1 ).( !$fnm_empty ? '-' : '' ) . $file_name;
1479 $attach_path = $attach_dir . "/" . $attach_fname;
1480
1481 if( is_dir($attach_dir) && move_uploaded_file($tmp_name, $attach_path) ){
1482 $attach_id = wpforo_insert_to_media_library( $attach_path, $fnm );
1483 $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>';
1484 $args['has_attach'] = 1;
1485 }else{
1486 $wpforo->notice->add('Can`t upload file', 'error');
1487 return $args;
1488 }
1489 }
1490 }
1491 return $args;
1492 }
1493
1494 function wpforo_delete_attachment( $attach_post_id ){
1495 global $wpdb;
1496 if(!$attach_post_id) return;
1497 $posts = $wpdb->get_results("SELECT `postid`, `body` FROM `" . $wpdb->prefix . "wpforo_posts` WHERE `body` LIKE '%wpfa-" . intval( $attach_post_id ) . "%'", ARRAY_A );
1498 if(!empty($posts) || is_array($posts)){
1499 foreach( $posts as $post ){
1500 $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'] );
1501 if( $body ) $wpdb->query("UPDATE `" . $wpdb->prefix . "wpforo_posts` SET `body` = '" . esc_sql( $body ) . "' WHERE `postid` = " . intval($post['postid']));
1502 }
1503 }
1504 }
1505
1506 function wpforo_default_attachments_filter($text){
1507 global $wpforo;
1508
1509 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) ){
1510 foreach( $matches as $match ){
1511 $attach_html = '';
1512 $fileurl = preg_replace('#^https?\:#is', '', $match[1]);
1513 $filename = $match[2];
1514
1515 $upload_array = wp_upload_dir();
1516 $filedir = preg_replace('#^https?\:#is', '', str_replace( preg_replace('#^https?\:#is', '', $upload_array['baseurl']), $upload_array['basedir'], $fileurl ) );
1517 $filedir = str_replace( basename($filedir), urldecode( basename($filedir) ), $filedir );
1518
1519 if(file_exists($filedir)){
1520 if(!$wpforo->perm->forum_can('va')){
1521 $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>';
1522 }
1523 }
1524
1525 if($attach_html){
1526 $attach_html .= '<br/>';
1527 $text = str_replace($match[0], $attach_html, $text);
1528 }
1529 }
1530 }
1531
1532 return $text;
1533 }
1534
1535 add_action( 'delete_attachment', 'wpforo_delete_attachment', 10 );
1536 if( !defined('WPFOROATTACH_BASENAME') ){
1537 add_filter( 'wpforo_add_topic_data_filter', 'wpforo_add_default_attachment' );
1538 add_filter( 'wpforo_edit_topic_data_filter', 'wpforo_add_default_attachment' );
1539 add_filter( 'wpforo_add_post_data_filter', 'wpforo_add_default_attachment' );
1540 add_filter( 'wpforo_edit_post_data_filter', 'wpforo_add_default_attachment' );
1541 add_filter('wpforo_body_text_filter', 'wpforo_default_attachments_filter');
1542 }
1543
1544 if( !class_exists('wpForoSmiles') ){
1545 add_filter('wpforo_body_text_filter', 'wp_encode_emoji', 9);
1546 add_filter('wpforo_body_text_filter', 'convert_smilies');
1547 }