PluginProbe
wpForo Forum / 1.0.0
wpForo Forum v1.0.0
3.1.6 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 All 138 releases
wpforo / wpf-includes / wpf-hooks.php

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

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