PluginProbe
wpForo Forum / 1.3.1
wpForo Forum v1.3.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.3.1, at wpf-includes/wpf-hooks.php

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