PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
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 beta-4, at wpf-includes/wpf-hooks.php

1,195 lines 46.9 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_full_url(), '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=register';
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=login';
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(is_admin()) return;
131 include_once( wpftpl('index.php') );
132 }
133
134 add_shortcode( 'wpforo-index', 'wpforo_load' );
135 function wpforo_load( $content ){
136 global $post;
137 if(is_admin()) return;
138 $wpforo_url = WPFORO_BASE_URL;
139 $wpforo_pageslug = basename($wpforo_url);
140 if( $post->post_name == $wpforo_pageslug ){
141 if(wpforo_feature('output-buffer') && function_exists('ob_start')){
142 ob_start();
143 wpforo_init_template();
144 return ob_get_clean();
145 }
146 else{
147 wpforo_init_template();
148 }
149 }else{
150 return false;
151 }
152 }
153
154 function wpforo_theme_functions(){
155 $path = wpftpl('functions.php');
156 if( file_exists($path) ){
157 include_once($path);
158 }
159 }
160 add_action('init', 'wpforo_theme_functions');
161
162 function wpforo_theme_functions_wp(){
163 $path = wpftpl('functions-wp.php');
164 if( file_exists($path) ){
165 include_once($path);
166 }
167 }
168 add_action('after_setup_theme', 'wpforo_theme_functions_wp');
169
170 function wpforo_do_rewrite(){
171 $wpforo_pageslug = basename(WPFORO_BASE_URL);
172 add_rewrite_rule($wpforo_pageslug.'/(.+)$', 'index.php?pagename='.$wpforo_pageslug, 'top');
173 flush_rewrite_rules();
174 }
175 add_action('init', 'wpforo_do_rewrite');
176
177 function wpforo_meta_title($title) {
178 global $wpforo;
179 $is404 = false;
180 $meta_title = array();
181
182 if(!wpforo_feature('seo-title', $wpforo)) return $title;
183
184 if(is_wpforo_page()){
185 $template = $wpforo->current_object['template'];
186 if( ($template == 'post' && $wpforo->current_object['topicid'] == 0) ||
187 ($template == 'topic' && $wpforo->current_object['forumid'] == 0) ||
188 ($template == 'profile' && $wpforo->current_object['userid'] == 0) ){
189 $is404 = true;
190 }
191 if(!$is404){
192 if(!empty($wpforo->current_object['forum'])) $forum = $wpforo->current_object['forum'];
193 if(!empty($wpforo->current_object['topic'])) $topic = $wpforo->current_object['topic'];
194 if(!empty($wpforo->current_object['user'])) $user = $wpforo->current_object['user'];
195 if(isset($topic['title']) && isset($forum['title']) && isset($wpforo->general_options['title'])){
196 $meta_title = array($topic['title'], $forum['title'], $wpforo->general_options['title']);
197 }
198 elseif(!isset($topic['title']) && isset($forum['title']) && isset($wpforo->general_options['title'])){
199 $meta_title = array($forum['title'], $wpforo->general_options['title']);
200 }
201 elseif( $template != 'forum' && $template != 'topic' && $template != 'post' ){
202 if( $template == 'profile' || $template == 'account' || $template == 'activity' || $template == 'subscriptions' ){
203 if(isset($user['display_name'])){
204 $meta_title = array($user['display_name'], wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
205 }
206 elseif(isset($wpforo->current_object['username'])){
207 $meta_title = array($wpforo->current_object['username'], wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
208 }
209 else{
210 $meta_title = array(wpforo_phrase( 'Member', false), wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
211 }
212 }
213 elseif($template){
214 $meta_title = array(wpforo_phrase( ucfirst($template), false), $wpforo->general_options['title']);
215 }
216 elseif($title){
217 $meta_title = (is_array($title)) ? $title : array($title);
218 }
219 else{
220 $meta_title = array(wpforo_phrase('Forum', false), get_bloginfo('name'));
221 }
222 }
223 elseif($title){
224 $meta_title = (is_array($title)) ? $title : array($title);
225 }
226 else{
227 $meta_title = array(wpforo_phrase('Forum', false), get_bloginfo('name'));
228 }
229 }
230 else{
231 $meta_title = array(wpforo_phrase( '404 - Page not found', false), $wpforo->general_options['title']);
232 }
233 }
234 if(!empty($meta_title)) {
235 return $meta_title;
236 }
237 else{
238 return $title;
239 }
240 }
241 add_filter('document_title_parts', 'wpforo_meta_title', 100);
242
243 function wpforo_meta_wp_title($title){
244 if(!wpforo_feature('seo-title')) return $title;
245 $meta_title = wpforo_meta_title($title);
246 if(is_array($meta_title) && !empty($meta_title)){
247 $title = implode(' &#8211; ', $meta_title);
248 }
249 return $title;
250 }
251 add_filter( 'wp_title', 'wpforo_meta_wp_title', 100);
252
253 function wpforo_add_meta_tags(){
254 global $wpforo;
255
256 if(!wpforo_feature('seo-meta', $wpforo)) return;
257
258 if(is_wpforo_page()){
259 $title = '';
260 $description = '';
261 $canonical = wpforo_full_url();
262 if(!empty($wpforo->current_object['forum'])) $forum = $wpforo->current_object['forum'];
263 if(!empty($wpforo->current_object['topic'])) $topic = $wpforo->current_object['topic'];
264 if(isset($wpforo->current_object)){
265 if( isset($wpforo->current_object['forumid']) && !isset($wpforo->current_object['topicid']) ){
266 if(isset($forum['title'])) $title = $forum['title'];
267 if(isset($wpforo->current_object['forum_meta_desc']) && $wpforo->current_object['forum_meta_desc'] !=''){
268 $description = $wpforo->current_object['forum_meta_desc'];
269 }
270 elseif(isset($wpforo->current_object['forum_desc']) && $wpforo->current_object['forum_desc'] !=''){
271 $description = $wpforo->current_object['forum_desc'];
272 }
273 }elseif( isset($wpforo->current_object['topicid']) && isset($topic['first_postid']) ){
274 $post = $wpforo->post->get_post($topic['first_postid']);
275 if(isset($post['title'])) $title = wpforo_text($post['title'], 60, false);
276 if(isset($post['body'])) $description = wpforo_text($post['body'], 155, false);
277 }else{
278 if( isset($wpforo->general_options['title']) ) $title = $wpforo->general_options['title'];
279 if( isset($wpforo->general_options['description']) ) $description = $wpforo->general_options['description'];
280 }
281 $description = preg_replace('#[\t\r\n]+#isu', ' ', $description);
282 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";
283 }
284 }
285 }
286 add_action('wp_head', 'wpforo_add_meta_tags', 1);
287
288
289 add_action('wp_ajax_wpforo_like_ajax', 'wpf_like');
290 add_action('wp_ajax_nopriv_wpforo_like_ajax', 'wpf_like');
291
292 function wpf_like(){
293 global $wpforo;
294 $response = array('stat' => 0, 'likers' => '', 'notice' => $wpforo->notice->get_notices());
295 if(!is_user_logged_in()){
296 $wpforo->notice->add( sprintf( wpforo_phrase('Please %s or %s', FALSE), '<a href="' . wpforo_login_url() . '">'.wpforo_phrase('Login', FALSE).'</a>', '<a href="' . wpforo_register_url() . '">'.wpforo_phrase('Register', FALSE).'</a>' ) );
297 $response['notice'] = $wpforo->notice->get_notices();
298 echo json_encode($response);
299 exit();
300 }
301 if( !isset($_POST['likestatus']) || !isset($_POST['postid']) || !($postid = intval($_POST['postid'])) ){
302 $wpforo->notice->add('action error', 'error');
303 $response['notice'] = $wpforo->notice->get_notices();
304 echo json_encode($response);
305 exit();
306 }
307 if( !$post = $wpforo->post->get_post( $postid ) ){
308 $wpforo->notice->add('post not found', 'error');
309 $response['notice'] = $wpforo->notice->get_notices();
310 echo json_encode($response);
311 exit();
312 }
313 if( !$wpforo->perm->forum_can( $post['forumid'], 'l') ){
314 $wpforo->notice->add('You haven\'t permission to like posts from this forum', 'error');
315 $response['notice'] = $wpforo->notice->get_notices();
316 echo json_encode($response);
317 exit();
318 }
319 if( $_POST['likestatus'] ){
320 if( $wpforo->db->insert(
321 $wpforo->db->prefix . 'wpforo_likes',
322 array(
323 'postid' => $postid,
324 'userid' => $wpforo->current_userid,
325 'post_userid' => $post['userid']
326 ),
327 array('%d','%d','%d')
328 ) ){
329 $wpforo->notice->add('done', 'success');
330 $response['stat'] = 1;
331 $response['notice'] = $wpforo->notice->get_notices();
332 }
333 }else{
334 if( $wpforo->db->delete(
335 $wpforo->db->prefix . 'wpforo_likes',
336 array(
337 'postid' => $postid,
338 'userid' => $wpforo->current_userid
339 ),
340 array('%d','%d')
341 ) ){
342 $wpforo->notice->add('done', 'success');
343 $response['stat'] = 1;
344 $response['notice'] = $wpforo->notice->get_notices();
345 }
346 }
347 if(!isset($post['userid'])) $wpforo->member->reset($post['userid']);
348 if(!isset($wpforo->current_userid)) $wpforo->member->reset($wpforo->current_userid);
349 $response['likers'] = $wpforo->tpl->likers($postid);
350 echo json_encode($response);
351 exit();
352 }
353
354
355 add_action('wp_ajax_wpforo_vote_ajax', 'wpf_vote');
356 add_action('wp_ajax_nopriv_wpforo_vote_ajax', 'wpf_vote');
357 function wpf_vote(){
358
359 if(!is_user_logged_in()) return;
360
361 global $wpforo;
362
363 if( !isset($_POST['postid']) || !$_POST['postid'] ){
364 $wpforo->notice->add('Wrong post data', 'error');
365 echo json_encode(array('stat' => 0, 'notice' => $wpforo->notice->get_notices()));
366 exit();
367 }
368 if( $wpforo->db->get_var( "SELECT `voteid` FROM `".$wpforo->db->prefix."wpforo_votes` WHERE `postid` = " . intval($_POST['postid']) . " AND `userid` = " . intval($wpforo->current_userid) )){
369 $wpforo->notice->add('You are already voted this post');
370 echo json_encode(array('stat' => 0, 'notice' => $wpforo->notice->get_notices()));
371 exit();
372 }
373
374 $reaction = 1;
375 if( $_POST['votestatus'] == 'down' ) $reaction = -1;
376 $post = $wpforo->post->get_post( intval($_POST['postid']) );
377
378 $voted = $wpforo->db->insert(
379 $wpforo->db->prefix . 'wpforo_votes',
380 array(
381 'postid' => intval($_POST['postid']),
382 'userid' => $wpforo->current_userid,
383 'reaction' => $reaction,
384 'post_userid' => $post['userid']
385 ),
386 array(
387 '%d',
388 '%d',
389 '%d',
390 '%d'
391 )
392 );
393
394 if(!isset($post['userid'])) $wpforo->member->reset($post['userid']);
395 if(!isset($wpforo->current_userid)) $wpforo->member->reset($wpforo->current_userid);
396
397 if( $voted !== FALSE ){
398 if( $_POST['itemtype'] == 'topic' ){
399 $incr = $wpforo->db->query( "UPDATE ".$wpforo->db->prefix . 'wpforo_topics'." SET `votes` = `votes` + $reaction WHERE topicid = " . intval($post['topicid']) );
400 $incr2 = $wpforo->db->query( "UPDATE ".$wpforo->db->prefix . 'wpforo_posts'." SET `votes` = `votes` + $reaction WHERE postid = " . intval($post['postid']) );
401 }else{
402 $incr = $wpforo->db->query( "UPDATE ".$wpforo->db->prefix . 'wpforo_posts'." SET `votes` = `votes` + $reaction WHERE postid = " . intval($post['postid']) );
403 $incr2 = TRUE;
404 }
405
406 if($incr !== FALSE && $incr2 !== FALSE){
407 $wpforo->notice->add('Successfully voted', 'success');
408 echo json_encode(array('stat' => 1, 'notice' => $wpforo->notice->get_notices()));
409 exit();
410 }
411 }
412
413 $wpforo->notice->add('Wrong post data', 'error');
414 echo json_encode(array('stat' => 0, 'notice' => $wpforo->notice->get_notices()));
415 exit();
416 }
417
418 add_action('wp_ajax_wpforo_answer_ajax', 'wpf_answer');
419 add_action('wp_ajax_nopriv_wpforo_answer_ajax', 'wpf_answer');
420 function wpf_answer(){
421 global $wpforo;
422 $response = array('stat' => 0, 'notice' => $wpforo->notice->get_notices());
423 if(!is_user_logged_in()){
424 $wpforo->notice->add( sprintf( wpforo_phrase('Please %s or %s', FALSE), '<a href="' . wpforo_login_url() . '">'.wpforo_phrase('Login', FALSE).'</a>', '<a href="' . wpforo_register_url() . '">'.wpforo_phrase('Register', FALSE).'</a>' ) );
425 $response['notice'] = $wpforo->notice->get_notices();
426 echo json_encode($response);
427 exit();
428 }
429 if( !isset($_POST['answerstatus']) || !isset($_POST['postid']) || !$postid = intval($_POST['postid']) ){
430 $wpforo->notice->add('action error', 'error');
431 $response['notice'] = $wpforo->notice->get_notices();
432 echo json_encode($response);
433 exit();
434 }
435 if( !$post = $wpforo->post->get_post( $postid ) ){
436 $wpforo->notice->add('post not found', 'error');
437 $response['notice'] = $wpforo->notice->get_notices();
438 echo json_encode($response);
439 exit();
440 }
441 if( !$topic = $wpforo->topic->get_topic( $post['topicid'] ) ){
442 $wpforo->notice->add('topic not found', 'error');
443 $response['notice'] = $wpforo->notice->get_notices();
444 echo json_encode($response);
445 exit();
446 }
447 if( !($wpforo->perm->forum_can( $post['forumid'], 'at') || ( $wpforo->perm->forum_can( $post['forumid'], 'oat') && $wpforo->current_userid == $topic['userid'] ) ) ){
448 $wpforo->notice->add('You haven\'t permission to make topic answered', 'error');
449 $response['notice'] = $wpforo->notice->get_notices();
450 echo json_encode($response);
451 exit();
452 }
453 if( FALSE !== $wpforo->db->query( "UPDATE ".$wpforo->db->prefix ."wpforo_posts SET is_answer = ".intval($_POST['answerstatus'])." WHERE postid = " . intval($postid) ) ){
454 $wpforo->notice->add('done', 'success');
455 $response['stat'] = 1;
456 $response['notice'] = $wpforo->notice->get_notices();
457 }
458 echo json_encode($response);
459 exit();
460 }
461
462 add_action('wp_ajax_wpforo_quote_ajax', 'wpf_quote');
463 add_action('wp_ajax_nopriv_wpforo_quote_ajax', 'wpf_quote');
464 function wpf_quote(){
465
466 if(!is_user_logged_in()) return;
467
468 global $wpforo;
469
470 $post = $wpforo->db->get_row('SELECT `userid`, `body` FROM '.$wpforo->db->prefix.'wpforo_posts WHERE postid =' . intval($_POST['postid']), ARRAY_A);
471 $poster = $wpforo->member->get_member(intval($post['userid']));
472 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 />';
473 exit();
474 }
475
476 add_action('wp_ajax_wpforo_report_ajax', 'wpf_report');
477 add_action('wp_ajax_nopriv_wpforo_report_ajax', 'wpf_report');
478 function wpf_report(){
479
480 if(!is_user_logged_in()) return;
481
482 global $wpforo;
483
484 if( !isset($_POST['reportmsg']) || !$_POST['reportmsg'] || !isset($_POST['postid']) || !$_POST['postid'] ){
485 $wpforo->notice->add('Error: please inset some text to report.', 'error');
486 echo json_encode( $wpforo->notice->get_notices() );
487 exit();
488 }
489
490 ############### Sending Email ##################
491 $report_text = substr($_POST['reportmsg'], 0, 1000);
492 $postid = intval($_POST['postid']);
493 $reporter = '<a href="'.$wpforo->current_user['profile_url'].'">'.($wpforo->current_user['display_name'] ? $wpforo->current_user['display_name'] : $wpforo->current_user['user_nicename']).'</a>';
494 $reportmsg = wpforo_kses($report_text, 'email');
495 $post_url = '<a target="_blank" href="'. esc_attr($wpforo->post->get_post_url($postid)).'">' . wpforo_phrase('Post link', false) . '&raquo;</a>';
496
497 $subject = $wpforo->subscribe_options['report_email_subject'];
498 $message = $wpforo->subscribe_options['report_email_message'];
499
500 $from_tags = array("[reporter]", "[message]", "[post_url]");
501 $to_words = array(sanitize_text_field($reporter), $reportmsg, $post_url);
502
503 $subject = str_replace($from_tags, $to_words, $subject);
504 $message = str_replace($from_tags, $to_words, $message);
505
506 $admin_email = get_option( 'admin_email' );
507 $admin_emails = $wpforo->subscribe_options['admin_emails'];
508 $admin_emails = trim($admin_emails);
509 $admin_emails = explode(',', $admin_emails);
510 $admin_emails = array_map('trim', $admin_emails);
511 $admin_email = (isset($admin_emails[0]) && $admin_emails[0]) ? $admin_emails[0] : $admin_email;
512 $headers = wpforo_admin_mail_headers();
513
514 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
515 if( wp_mail( $admin_email, $subject, $message, $headers ) ){
516 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
517 }else{
518 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
519 $wpforo->notice->add('Can\'t send report email', 'error');
520 echo json_encode( $wpforo->notice->get_notices() );
521 exit();
522 }
523
524 ############### Sending Email end ##############
525 $wpforo->notice->add('Message has been sent', 'success');
526 echo json_encode( $wpforo->notice->get_notices() );
527 exit();
528 }
529
530 add_action('wp_ajax_wpforo_sticky_ajax', 'wpf_sticky');
531 add_action('wp_ajax_nopriv_wpforo_sticky_ajax', 'wpf_sticky');
532 function wpf_sticky(){
533
534 if(!is_user_logged_in()) return;
535
536 if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); }
537 global $wpforo;
538 if( $_POST['status'] == 'sticky' ){
539 $sql = "UPDATE " . $wpforo->db->prefix . "wpforo_topics SET type = 1 WHERE topicid = " . intval($p_id);
540 $wpforo->db->query( $sql );
541 }elseif( $_POST['status'] == 'unsticky' ){
542 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET type = 0 WHERE topicid = " . intval($p_id);
543 $wpforo->db->query( $sql );
544 }
545 echo 1;
546 exit();
547 }
548
549 add_action('wp_ajax_wpforo_close_ajax', 'wpf_close');
550 add_action('wp_ajax_nopriv_wpforo_close_ajax', 'wpf_close');
551 function wpf_close(){
552
553 if(!is_user_logged_in()) return;
554
555 if( !isset($_POST['postid']) || !( $p_id = intval($_POST['postid']) ) ){ echo 0; exit(); }
556 global $wpforo;
557 if( $_POST['status'] == 'closed' ){
558 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET closed = 0 WHERE topicid = " . intval($p_id);
559 $wpforo->db->query( $sql );
560 }elseif( $_POST['status'] == 'close' ){
561 $sql = "UPDATE ".$wpforo->db->prefix ."wpforo_topics SET closed = 1 WHERE topicid = " . intval($p_id);
562 $wpforo->db->query( $sql );
563 echo 1;
564 exit();
565 }
566 echo $wpforo->topic->get_topic_url($p_id);
567 exit();
568 }
569
570 add_action('wp_ajax_wpforo_edit_ajax', 'wpf_edit');
571 add_action('wp_ajax_nopriv_wpforo_edit_ajax', 'wpf_edit');
572 function wpf_edit(){
573
574 if(!is_user_logged_in()) return;
575
576 if( !isset($_POST['postid']) || !$_POST['postid'] ){ echo 0; exit(); }
577 global $wpforo;
578 $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']);
579 if($post = $wpforo->db->get_row($sql, ARRAY_A) ){
580 $post['body'] = wpautop($post['body']);
581 echo json_encode($post);
582 exit();
583 }
584 echo 0;
585 exit();
586 }
587
588 add_action('wp_ajax_wpforo_move_ajax', 'wpf_move');
589 add_action('wp_ajax_nopriv_wpforo_move_ajax', 'wpf_move');
590 function wpf_move(){
591 exit();
592 }
593
594 add_action('wp_ajax_wpforo_delete_ajax', 'wpf_delete');
595 add_action('wp_ajax_nopriv_wpforo_delete_ajax', 'wpf_delete');
596 function wpf_delete(){
597
598 if(!is_user_logged_in()) return;
599
600 global $wpforo;
601
602 $resp = array();
603 if( $_POST['status'] == 'topic' ){
604 if( $wpforo->topic->delete(intval($_POST['postid'])) ){
605 $resp = array(
606 'postid' => intval($_POST['postid']),
607 'location' => $wpforo->forum->get_forum_url(intval($_POST['forumid']))
608 );
609 $return = 1;
610 }else{
611 $return = 0;
612 }
613 }elseif($_POST['status'] == 'reply'){
614 if( $wpforo->post->delete(intval($_POST['postid'])) ){
615 $resp = array(
616 'postid' => intval($_POST['postid'])
617 );
618 $return = 1;
619 }else{
620 $return = 0;
621 }
622 }
623
624 $resp['stat'] = $return;
625 $resp['notice'] = $wpforo->notice->get_notices();
626 echo json_encode( $resp );
627 exit();
628 }
629
630 add_action('wp_ajax_wpforo_subscribe_ajax', 'wpf_subscribe');
631 add_action('wp_ajax_nopriv_wpforo_subscribe_ajax', 'wpf_subscribe');
632 function wpf_subscribe(){
633
634 if(!is_user_logged_in()) return;
635
636 global $wpforo;
637
638 $args = array(
639 'itemid' => intval($_POST['itemid']),
640 'type' => sanitize_text_field($_POST['type']),
641 'userid' => intval($wpforo->current_userid)
642 );
643
644 if(isset($_POST['status']) && $_POST['status'] == 'subscribe'){
645 $args['confirmkey'] = $wpforo->sbscrb->get_confirm_key();
646 ############### Sending Email ##################
647 $confirmlink = $wpforo->sbscrb->get_confirm_link($args);
648 $member = $wpforo->current_user;
649 $member_name = (isset($wpforo->current_user_display_name) && $wpforo->current_user_display_name) ? $wpforo->current_user_display_name : $wpforo->current_user;
650 if($_POST['type'] == 'forum'){
651 $forum = $wpforo->forum->get_forum(intval($_POST['itemid']));
652 $item_title = $forum['title'];
653 }elseif($_POST['type'] == 'topic'){
654 $topic = $wpforo->topic->get_topic(intval($_POST['itemid']));
655 $item_title = $topic['title'];
656 }
657 $subject = $wpforo->subscribe_options['confirmation_email_subject'];
658 $message = $wpforo->subscribe_options['confirmation_email_message'];
659 $from_tags = array("[member_name]", "[entry_title]", "[confirm_link]");
660 $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>');
661 $subject = str_replace($from_tags, $to_words, $subject);
662 $message = str_replace($from_tags, $to_words, $message);
663 $message = wpforo_kses($message, 'email');
664
665 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
666 $headers = wpforo_mail_headers();
667
668 if( wp_mail( $wpforo->current_user_email , sanitize_text_field($subject), $message, $headers ) ){
669 if( $wpforo->sbscrb->add($args) ){
670 $return = 1;
671 }else{
672 $return = 0;
673 }
674 }else{
675 $wpforo->notice->add('Can\'t send confirmation email', 'error');
676 $return = 0;
677 }
678
679 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
680
681 ############### Sending Email end ##############
682 }elseif(isset($_POST['status']) && $_POST['status'] == 'unsubscribe'){
683 $subscribe = $wpforo->sbscrb->get_subscribe( $args );
684 $return = (int) $wpforo->sbscrb->delete( $subscribe['confirmkey'] );
685 }
686
687 $resp['stat'] = $return;
688 $resp['notice'] = $wpforo->notice->get_notices();
689 echo json_encode( $resp );
690 exit();
691 }
692
693 ############### Sending Email ##################
694 function wpforo_set_html_content_type(){
695 return 'text/html';
696 }
697
698 function wpforo_wp_mail_from_name($name){
699 global $wpforo;
700 if(isset($wpforo->subscribe_options['from_name']) && $wpforo->subscribe_options['from_name']){
701 return $wpforo->subscribe_options['from_name'];
702 }
703 else{
704 return $name;
705 }
706 }
707
708 function wpforo_wp_mail_from_email($email){
709 global $wpforo;
710 if(isset($wpforo->subscribe_options['from_email']) && $wpforo->subscribe_options['from_email']){
711 return $wpforo->subscribe_options['from_email'];
712 }
713 else{
714 return $email;
715 }
716 }
717
718 function wpforo_mail_from_name(){
719 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');}
720 }
721
722 function wpforo_mail_from_email(){
723 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' );}
724 }
725
726 function wpforo_mail_headers($from_name = '', $from_email = '', $cc = array(), $bcc = array()){
727 global $wpforo;
728 $H = array();
729 if(!$from_name) $from_name = wpforo_mail_from_name();
730 if(!$from_email) $from_email = wpforo_mail_from_email();
731 $H[] = 'From: ' . $from_name . ' <' . $from_email . '>';
732 if(!empty($cc)){
733 foreach($cc as $c){ $c = sanitize_email($c); $H[] = 'CC: ' . $c; }
734 }
735 if(!empty($bcc)){
736 foreach($bcc as $b){ $b = sanitize_email($b); $H[] = 'BCC: ' . $b; }
737 }
738 return $H;
739 }
740
741 function wpforo_admin_mail_headers($from_name = '', $from_email = '', $cc = array(), $bcc = array()){
742 global $wpforo;
743 $H = array();
744 if(!$from_name) $from_name = wpforo_mail_from_name();
745 if(!$from_email) $from_email = wpforo_mail_from_email();
746 $H[] = 'From: ' . $from_name . ' <' . $from_email . '>';
747 if(empty($cc)){
748 $cc = trim($wpforo->subscribe_options['admin_emails']);
749 $cc = explode(',', $cc);
750 $cc = array_map('trim', $cc);
751 }
752 if(!empty($cc)){
753 foreach($cc as $c){ $c = sanitize_email($c); $H[] = 'CC: ' . $c; }
754 }
755 if(!empty($bcc)){
756 foreach($bcc as $b){ $b = sanitize_email($b); $H[] = 'BCC: ' . $b; }
757 }
758 return $H;
759 }
760 ############### Sending Email end ##############
761
762 function wpforo_frontend_enqueue(){
763
764 global $wpforo;
765
766 if( is_wpforo_page() ){
767 wp_enqueue_script('jquery-ui-core');
768 wp_enqueue_script('jquery-ui-dialog');
769 wp_register_script( 'wpforo-frontend-js', WPFORO_URL . '/wpf-assets/js/frontend.js', array('jquery'), $wpforo->version, false );
770 wp_enqueue_script('wpforo-frontend-js');
771 if( wpforo_feature( 'font-awesome', $wpforo) ){
772 wp_register_style('wpforo-font-awesome', WPFORO_URL . '/wpf-assets/css/font-awesome/css/font-awesome.min.css', false, '4.6.3' );
773 wp_enqueue_style('wpforo-font-awesome');
774 }
775 if(is_user_logged_in()){
776 wp_register_script('wpforo-ajax', WPFORO_URL . '/wpf-assets/js/ajax.js', array('jquery'), $wpforo->version, false);
777 wp_enqueue_script('wpforo-ajax');
778 wp_localize_script('wpforo-ajax', 'wpf_ajax_obj', array( 'url' => admin_url('admin-ajax.php'), 'phrases' => $wpforo->phrases ));
779 }
780 }
781
782 if (is_rtl()) {
783 wp_register_style('wpforo-style-rtl', WPFORO_TEMPLATE_URL . '/style-rtl.css', false, $wpforo->version );
784 wp_enqueue_style('wpforo-style-rtl');
785 }
786 else{
787 wp_register_style('wpforo-style', WPFORO_TEMPLATE_URL . '/style.css', false, $wpforo->version );
788 wp_enqueue_style('wpforo-style');
789 }
790
791 if( file_exists(WPFORO_TEMPLATE_DIR . '/colors.css') ){
792 wp_register_style( 'wpforo-dynamic-style', WPFORO_TEMPLATE_URL . '/colors.css', false, $wpforo->version );
793 wp_enqueue_style('wpforo-dynamic-style');
794 }
795 }
796 add_action('wp_enqueue_scripts', 'wpforo_frontend_enqueue');
797
798 function wpforo_dynamic_style() {
799
800 if(!is_wpforo_page()) return;
801
802 global $wpforo;
803 $inline = false;
804 $dynamic_css_file = WPFORO_TEMPLATE_DIR . '/colors.css';
805 $dynamic_css_matrix = WPFORO_TEMPLATE_DIR . '/styles/css.php';
806 if( isset($wpforo->theme_options) ){
807 if( !isset($wpforo->theme_options['style']) || !isset($wpforo->theme_options['styles']) ) return false;
808 $style = $wpforo->theme_options['style'];
809 $styles = $wpforo->theme_options['styles'];
810 if( !empty($style) && !empty($styles) ){
811 foreach( $styles[$style] as $color_key => $color_value ){
812 if( $color_value ) {
813 $COLORS[ 'WPFCOLOR_' . $color_key ] = $color_value;
814 }
815 }
816 }
817 else{
818 return false;
819 }
820 }
821 else{
822 return false;
823 }
824 extract($COLORS, EXTR_OVERWRITE);
825 if( file_exists( $dynamic_css_matrix ) ){
826 require_once( $dynamic_css_matrix );
827 $css = apply_filters('wpforo_dynamic_css_filter', $css, $COLORS);
828 }
829 else{
830 return false;
831 }
832 $hach_new = md5($css);
833 if( file_exists( $dynamic_css_file ) && filesize($dynamic_css_file) ){
834 $css_current = wpforo_get_file_content( $dynamic_css_file );
835 if( $css_current ){
836 $hach_current = md5($css_current);
837 if( $hach_new == $hach_current ){
838 //CSS not changed
839 }
840 else{
841 $result = wpforo_write_file( $dynamic_css_file, $css );
842 if( isset($result['error']) && $result['error'] ){
843 $inline = true;
844 }
845 else{
846 //CSS updated
847 }
848 }
849 }
850 }
851 else{
852 $result = wpforo_write_file( $dynamic_css_file, $css );
853 if( isset($result['error']) && $result['error'] ){
854 $inline = true;
855 }
856 }
857 if( $inline ){
858 $css = preg_replace('|[\r\n\t]+|', '', $css );
859 wp_register_style( 'wpforo-dynamic-inline', WPFORO_TEMPLATE_URL . '/css/wpforo_dynamic-inline.css', false, $wpforo->version );
860 wp_enqueue_style( 'wpforo-dynamic-inline' );
861 wp_add_inline_style( 'wpforo-dynamic-inline', $css );
862 }
863 }
864 add_action( 'wp_enqueue_scripts', 'wpforo_dynamic_style' );
865
866 function wpforo_style_options($css, $COLORS){
867 global $wpforo;
868 if( !isset($css)) return;
869 if( isset($wpforo->style_options['font_size_forum']) && $wpforo->style_options['font_size_forum'] != 17 ){
870 $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;}";
871 }
872 if( isset($wpforo->style_options['font_size_topic']) && $wpforo->style_options['font_size_topic'] != 16 ){
873 $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; }";
874 }
875 if( isset($wpforo->style_options['font_size_post_content']) && $wpforo->style_options['font_size_post_content'] != 14 ){
876 $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;}";
877 }
878 if( isset($wpforo->style_options['custom_css']) ){
879 $css .= "\r\n" . $wpforo->style_options['custom_css'];
880 }
881 return $css;
882 }
883 add_filter( 'wpforo_dynamic_css_filter' , 'wpforo_style_options' , 10, 2 );
884
885 function wpforo_admin_enqueue(){
886 global $wpforo;
887 $phrases = array(
888 'move' => __('Move', 'wpforo'),
889 'delete' => __('Delete', 'wpforo')
890 );
891 if( strpos( wpforo_full_url(), '?page=wpforo' ) ){
892 if( wpforo_feature( 'font-awesome', $wpforo) ){
893 wp_register_style('wpforo-font-awesome', WPFORO_URL . '/wpf-assets/css/font-awesome/css/font-awesome.min.css', false, '4.6.3' );
894 wp_enqueue_style('wpforo-font-awesome');
895 }
896 wp_register_style('wpforo-admin', WPFORO_URL . '/wpf-admin/css/admin.css', false, $wpforo->version );
897 wp_enqueue_style('wpforo-admin');
898 wp_enqueue_script('jquery');
899 wp_enqueue_script('jquery-ui-core');
900 wp_enqueue_script('jquery-ui-widget');
901 wp_enqueue_script('jquery-ui-mouse');
902 wp_enqueue_script('jquery-ui-position');
903 wp_enqueue_script('jquery-ui-draggable');
904 wp_enqueue_script('jquery-ui-droppable');
905 wp_enqueue_script('jquery-ui-menu');
906 wp_enqueue_script('jquery-ui-sortable');
907 wp_enqueue_script('jquery-color');
908 wp_enqueue_script('wp-lists');
909 if( strpos( wpforo_full_url(), '?page=wpforo-forums&action' ) ){
910 //Just for excluding 'nav-menu' js loading//
911 }
912 elseif( strpos( wpforo_full_url(), '?page=wpforo-forums' ) ){
913 wp_enqueue_script('nav-menu');
914 }
915 elseif( strpos( wpforo_full_url(), '?page=wpforo-community' ) ){
916 wp_enqueue_script('postbox');
917 wp_enqueue_script('link');
918 }
919 wp_register_script( 'wpforo-basic_js', WPFORO_URL . '/wpf-admin/js/functions.js', array('jquery'), $wpforo->version, false );
920 wp_enqueue_script( 'wpforo-basic_js' );
921 wp_localize_script( 'wpforo-basic_js', 'wpforo_admin', array('phrases' => $phrases) );
922 wp_register_script( 'wpforo-admin_notice', WPFORO_URL . '/wpf-admin/js/admin_notice.js', array('jquery'), $wpforo->version, false );
923 wp_enqueue_script( 'wpforo-admin_notice' );
924 wp_localize_script('wpforo-admin_notice', 'wpf_admin_notice_obj', array('url' => admin_url('admin-ajax.php')));
925 }
926 }
927 add_action( 'admin_enqueue_scripts', 'wpforo_admin_enqueue' );
928
929 function wpforo_admin_display_notice() {
930 global $wpforo;
931 $wpforo_notices = $wpforo->notices;
932 if(is_array($wpforo_notices)){
933 foreach($wpforo_notices as $notice){
934 echo '<div id="' . esc_attr($notice) . '" class="update-nag">' . wpforo_phrase( $notice, FALSE ) . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a id="' . esc_attr($notice) . '" class="wpfadmin_notice">' . __( 'Dismiss', 'wpforo' ) . '</a></div>';
935 }
936 }
937 $permalink_structure = get_option( 'permalink_structure' );
938 if( $permalink_structure == '' ){
939 wpforo_add_notice( 'default_permalink_notice' );
940 }
941
942 }
943 add_action( 'admin_notices', 'wpforo_admin_display_notice' );
944
945 function wpforo_userform_to_wpuser_html_form($wp_user){
946 if( is_super_admin() ){
947 global $wpforo;
948
949 if( is_object($wp_user) ){
950 $user = $wpforo->member->get_member($wp_user->ID);
951 $groupid = $user['groupid'];
952 $timezone = $user['timezone'];
953 }
954 if( !isset($groupid) ) $groupid = 0;
955 if( !isset($timezone) ) $timezone = '';
956
957 echo '<table class="form-table">
958 <tr class="form-field">
959 <th scope="row"><label for="wpforo_usergroup">' . __('wpForo Usergroup', 'wpforo') . '</label></th>
960 <td>
961 <select name="wpforo_usergroup" id="wpforo_usergroup">';
962 $wpforo->usergroup->show_selectbox($groupid);
963 echo ' </select>
964 </td>
965 </tr>
966 <tr class="form-field">
967 <th scope="row"><label for="wpforo_usertimezone">' . __('wpForo User Timezone', 'wpforo') . '</label></th>
968 <td>
969 <select name="wpforo_usertimezone" id="wpforo_usertimezone">
970 ' . wp_timezone_choice($timezone) .
971 '</select>
972 </td>
973 </tr>
974 </table>';
975
976 }
977 }
978 add_action( 'user_new_form', 'wpforo_userform_to_wpuser_html_form' );
979 add_action( 'show_user_profile', 'wpforo_userform_to_wpuser_html_form' );
980 add_action( 'edit_user_profile', 'wpforo_userform_to_wpuser_html_form' );
981
982 function wpforo_do_hook_user_register($userid){
983 global $wpforo;
984 $wpforo->member->synchronize_user($userid);
985 }
986 add_action( 'user_register', 'wpforo_do_hook_user_register', 10, 1 );
987
988 function wpforo_do_hook_update_profile($userid){
989 if( isset($_POST['wpforo_usergroup']) && $_POST['wpforo_usergroup'] ){
990 global $wpforo;
991 $wpforo->member->edit_profile( array( 'userid' => intval($userid),
992 'groupid' => intval($_POST['wpforo_usergroup']),
993 'site' => esc_url($_POST['url']),
994 'about' => wpforo_kses($_POST['description'], 'user_description'),
995 'timezone' => ( isset($_POST['wpforo_usertimezone']) ? sanitize_text_field($_POST['wpforo_usertimezone']) : '' ) ) );
996 }
997 }
998 add_action('personal_options_update', 'wpforo_do_hook_update_profile');
999 add_action('edit_user_profile_update', 'wpforo_do_hook_update_profile');
1000
1001 function wpforo_update_last_login_date($user_login, $user){
1002 global $wpforo;
1003 $wpforo->member->edit_profile( array( 'userid' => intval($user->ID), 'last_login' => current_time( 'mysql', 1 ) ) );
1004 }
1005 add_action('wp_login', 'wpforo_update_last_login_date', 10, 2);
1006
1007 function wpforo_do_hook_deleted_user($userid){
1008 global $wpforo;
1009 $wpforo->member->delete( intval($userid), TRUE );
1010 }
1011 add_action( 'deleted_user', 'wpforo_do_hook_deleted_user' );
1012
1013 function wpforo_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
1014 global $wpforo;
1015 if(!wpforo_feature('replace-avatar', $wpforo)) return $avatar;
1016 $user = false;
1017 if ( is_numeric( $id_or_email ) ) {
1018 $id = (int) $id_or_email;
1019 $user = get_user_by( 'id' , $id );
1020 }elseif( is_object( $id_or_email ) ) {
1021 if ( ! empty( $id_or_email->user_id ) ) {
1022 $id = (int) $id_or_email->user_id;
1023 $user = get_user_by( 'id' , $id );
1024 }
1025 }else{
1026 $user = get_user_by( 'email', $id_or_email );
1027 }
1028
1029 if( $user && is_object( $user ) ){
1030 if( $src = $wpforo->member->get_avatar_url($user->data->ID) ){
1031 $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) . "' />";
1032 }
1033 }
1034 return $avatar;
1035 }
1036 add_filter( 'get_avatar' , 'wpforo_avatar' , 10, 5 );
1037
1038 function wpforo_forum_subscribers_mail_sender( $topic ){
1039 global $wpforo;
1040
1041 $subscribers = $wpforo->sbscrb->get_subscribes( array( 'itemid' => $topic['forumid'], 'type' => 'forum' ) );
1042 foreach($subscribers as $subscriber){
1043 $member = $wpforo->member->get_member( $subscriber['userid'] );
1044 $forum = $wpforo->forum->get_forum( $topic['forumid'] );
1045 $unsubscribe_link = $wpforo->sbscrb->get_unsubscribe_link($subscriber['confirmkey']);
1046
1047 ############### Sending Email ##################
1048
1049 $subject = $wpforo->subscribe_options['new_topic_notification_email_subject'];
1050 $message = $wpforo->subscribe_options['new_topic_notification_email_message'];
1051
1052 $from_tags = array( "[member_name]", "[forum]", "[unsubscribe_link]", "[topic_title]", "[topic_desc]");
1053 $to_words = array( sanitize_text_field($member['display_name']),
1054 '<a href="' . esc_url($forum['url']) . '">' . sanitize_text_field($forum['title']) . '</a>',
1055 '<br><a target="_blank" href="' . esc_url($unsubscribe_link) . '">' . wpforo_phrase('Unsubscribe', false) . '</a>' ,
1056 '<a target="_blank" href="' . esc_url($topic['topicurl']) . '">' . sanitize_text_field($topic['title']) . '</a>' ,
1057 wpforo_text( wpforo_kses( $topic['body'], 'email'), 70, FALSE ) );
1058
1059 $subject = str_replace($from_tags, $to_words, $subject);
1060 $message = str_replace($from_tags, $to_words, $message);
1061
1062 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1063 $headers = wpforo_mail_headers();
1064 $email_status = wp_mail( $member['user_email'] , $subject, $message, $headers );
1065 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1066
1067 ############### Sending Email end ##############
1068
1069 }
1070 }
1071 add_action( 'wpforo_after_add_topic', 'wpforo_forum_subscribers_mail_sender', 10, 1 );
1072
1073
1074
1075 function wpforo_topic_subscribers_mail_sender( $post ){
1076 global $wpforo;
1077
1078 $subscribers = $wpforo->sbscrb->get_subscribes( array( 'itemid' => $post['topicid'], 'type' => 'topic' ) );
1079 foreach($subscribers as $subscriber){
1080 $member = $wpforo->member->get_member( $subscriber['userid'] );
1081 $topic = $wpforo->topic->get_topic( $post['topicid'] );
1082 $unsubscribe_link = $wpforo->sbscrb->get_unsubscribe_link($subscriber['confirmkey']);
1083
1084
1085 ############### Sending Email ##################
1086
1087 $subject = $wpforo->subscribe_options['new_post_notification_email_subject'];
1088 $message = $wpforo->subscribe_options['new_post_notification_email_message'];
1089
1090 $from_tags = array( "[member_name]", "[topic]", "[unsubscribe_link]", "[reply_title]", "[reply_desc]");
1091 $to_words = array( sanitize_text_field($member['display_name']),
1092 '<a href="' . esc_url($post['posturl']) . '">' . sanitize_text_field($topic['title']) . '</a>',
1093 '<br><a target="_blank" href="' . esc_url($unsubscribe_link) . '">'.wpforo_phrase('Unsubscribe', false).'</a>' ,
1094 '<a target="_blank" href="' . esc_url($post['posturl']) . '">' . sanitize_text_field($post['title']) . '</a>' ,
1095 wpforo_text( wpforo_kses($post['body'], 'email'), 70, FALSE ) );
1096
1097 $subject = str_replace($from_tags, $to_words, $subject);
1098 $message = str_replace($from_tags, $to_words, $message);
1099
1100 add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1101 $headers = wpforo_mail_headers();
1102 $email_status = wp_mail( $member['user_email'] , $subject, $message, $headers );
1103 remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' );
1104
1105 ############### Sending Email end ##############
1106
1107 }
1108 }
1109 add_action( 'wpforo_after_add_post', 'wpforo_topic_subscribers_mail_sender', 11, 1 );
1110
1111
1112 function wpforo_add_default_attachment($args){
1113 if( !empty($_FILES['attachfile']) && !empty($_FILES['attachfile']['name']) ){
1114 global $wpforo;
1115
1116 $name = sanitize_file_name($_FILES['attachfile']['name']); //myimg.png
1117 $type = sanitize_mime_type($_FILES['attachfile']['type']); //image/png
1118 $tmp_name = sanitize_text_field($_FILES['attachfile']['tmp_name']); //D:\wamp\tmp\php986B.tmp
1119 $error = sanitize_text_field($_FILES['attachfile']['error']); //0
1120 $size = intval($_FILES['attachfile']['size']); //6112
1121
1122 $phpFileUploadErrors = array(
1123 0 => 'There is no error, the file uploaded with success',
1124 1 => 'The uploaded file size is too big',
1125 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
1126 3 => 'The uploaded file was only partially uploaded',
1127 4 => 'No file was uploaded',
1128 6 => 'Missing a temporary folder',
1129 7 => 'Failed to write file to disk.',
1130 8 => 'A PHP extension stopped the file upload.',
1131 );
1132
1133 if( $error ){
1134 $wpforo->notice->add($phpFileUploadErrors[$error], 'error');
1135 return FALSE;
1136 }elseif( $size > $wpforo->post_options['max_upload_size'] ){
1137 $wpforo->notice->add('The uploaded file size is too big', 'error');
1138 return FALSE;
1139 }
1140
1141 if(function_exists('pathinfo')){
1142 $ext = pathinfo($name, PATHINFO_EXTENSION);
1143 }
1144 else{
1145 $ext = substr(strrchr($name, '.'), 1);
1146 }
1147 $ext = strtolower($ext);
1148 $mime_types = get_allowed_mime_types();
1149 $mime_types = array_flip($mime_types);
1150 if(!empty($mime_types)){
1151 $allowed_types = implode('|', $mime_types);
1152 $expld = explode('|', $allowed_types);
1153 if( !in_array($ext, $expld) ){
1154 $wpforo->notice->add('File type is not allowed', 'error');
1155 return FALSE;
1156 }
1157 }
1158
1159 $wp_upload_dir = wp_upload_dir();
1160 $uplds_dir = $wp_upload_dir['basedir']."/wpforo";
1161 $attach_dir = $wp_upload_dir['basedir']."/wpforo/default_attachments";
1162 $attach_url = $wp_upload_dir['baseurl']."/wpforo/default_attachments";
1163 if(!is_dir($uplds_dir)) wp_mkdir_p($uplds_dir);
1164 if(!is_dir($attach_dir)) wp_mkdir_p($attach_dir);
1165
1166 $fnm = pathinfo($name, PATHINFO_FILENAME);
1167 $fnm = str_replace(' ', '-', $fnm);
1168 while(strpos($fnm, '--') !== FALSE) $fnm = str_replace('--', '-', $fnm);
1169 $fnm = preg_replace("/[^-a-zA-Z0-9]/", "", $fnm);
1170 $fnm = trim($fnm, "-");
1171 $fnm_empty = ( $fnm ? FALSE : TRUE );
1172
1173 $file_name = $fnm . "." . $ext;
1174
1175 $attach_fname = current_time( 'timestamp', 1 ).( !$fnm_empty ? '-' : '' ).$file_name;
1176 $attach_path = $attach_dir."/".$attach_fname;
1177
1178 if( is_dir($attach_dir) && move_uploaded_file($tmp_name, $attach_path) ){
1179 $args['body'] .= "\r\n" . '<div 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>';
1180 $args['has_attach'] = 1;
1181 }else{
1182 $wpforo->notice->add('Can`t upload file', 'error');
1183 return FALSE;
1184 }
1185 }
1186 return $args;
1187 }
1188 add_filter( 'wpforo_add_topic_data_filter', 'wpforo_add_default_attachment' );
1189 add_filter( 'wpforo_edit_topic_data_filter', 'wpforo_add_default_attachment' );
1190 add_filter( 'wpforo_add_post_data_filter', 'wpforo_add_default_attachment' );
1191 add_filter( 'wpforo_edit_post_data_filter', 'wpforo_add_default_attachment' );
1192
1193 add_filter('wpforo_body_text_filter', 'wp_encode_emoji', 9);
1194 add_filter('wpforo_body_text_filter', 'convert_smilies');
1195 ?>