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

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

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