PluginProbe
wpForo Forum / 1.5.2
wpForo Forum v1.5.2
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 / wpforo.php

wpforo.php in wpForo Forum 1.5.2, at wpforo.php

785 lines 37.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: wpForo
4 * Plugin URI: https://wpforo.com
5 * Description: WordPress Forum plugin. wpForo is a full-fledged forum solution for your community. Comes with multiple modern forum layouts.
6 * Author: gVectors Team (A. Chakhoyan, R. Hovhannisyan)
7 * Author URI: https://gvectors.com/
8 * Version: 1.5.2
9 * Text Domain: wpforo
10 * Domain Path: /wpf-languages
11 */
12
13 //Exit if accessed directly
14 if( !defined( 'ABSPATH' ) ) exit;
15 if( !defined( 'WPFORO_VERSION' ) ) define('WPFORO_VERSION', '1.5.2');
16
17 function wpforo_load_plugin_textdomain() { load_plugin_textdomain( 'wpforo', FALSE, basename( dirname( __FILE__ ) ) . '/wpf-languages/' ); }
18 add_action( 'plugins_loaded', 'wpforo_load_plugin_textdomain' );
19
20 if( !class_exists( 'wpForo' ) ) {
21
22 define('WPFORO_DIR', rtrim( plugin_dir_path( __FILE__ ), '/' ));
23 define('WPFORO_URL', rtrim( plugins_url( '', __FILE__ ), '/' ));
24 define('WPFORO_FOLDER', rtrim( plugin_basename(dirname(__FILE__)), '/'));
25 define('WPFORO_BASENAME', plugin_basename(__FILE__)); //wpforo/wpforo.php
26
27 final class wpForo{
28 private static $_instance = NULL;
29
30 public $file;
31 public $basename;
32 public $error;
33 public $locale;
34
35 public $tables;
36 public $blog_prefix;
37 private $prefix = "wpforo_";
38 private $_tables = array( 'accesses', 'activity', 'forums', 'languages', 'likes', 'phrases', 'posts', 'profiles',
39 'subscribes', 'topics', 'tags', 'usergroups', 'views', 'visits', 'votes' );
40
41 public $db;
42 public $addons = array();
43 public $current_url;
44 public $current_object;
45 public $menu = array();
46 public $data = array();
47 public $default;
48
49 public $wp_current_user = array();
50 public $current_user = array();
51 public $current_usermeta = array();
52 public $current_user_groupid = 4;
53 public $current_user_secondary_groupids = '';
54 public $current_userid = 0;
55 public $current_username = '';
56 public $current_user_email = '';
57 public $current_user_display_name = '';
58 public $current_user_status = '';
59
60 public $use_trailing_slashes;
61 public $use_home_url;
62 public $excld_urls;
63 public $base_permastruct;
64 public $permastruct;
65 public $url;
66 public $pageid;
67
68 public $general_options;
69 public $features;
70 public $tools_antispam;
71 public $tools_cleanup;
72 public $tools_misc;
73 public $tools_legal;
74
75 public $cache;
76 public $phrase;
77 public $forum;
78 public $topic;
79 public $post;
80 public $usergroup;
81 public $member;
82 public $perm;
83 public $sbscrb;
84 public $tpl;
85 public $notice;
86 public $api;
87 public $log;
88 public $feed;
89 public $form;
90 public $moderation;
91 public $activity;
92 public $seo;
93 public $add;
94
95 public $member_tpls;
96
97 public static function instance(){
98 if ( is_null(self::$_instance) ) self::$_instance = new self();
99 return self::$_instance;
100 }
101
102 private function __construct(){
103 global $wpdb;
104 $this->db = $wpdb;
105 $this->file = __FILE__;
106 $this->error = NULL;
107 $this->locale = get_locale();
108 $this->basename = plugin_basename($this->file);
109
110 $this->init_db_tables();
111 $this->includes();
112 $this->init_defaults();
113 $this->init_options();
114 $this->setup();
115 $this->init_hooks();
116
117 $this->cache = new wpForoCache();
118 $this->phrase = new wpForoPhrase();
119 $this->forum = new wpForoForum();
120 $this->topic = new wpForoTopic();
121 $this->post = new wpForoPost();
122 $this->usergroup = new wpForoUsergroup();
123 $this->member = new wpForoMember();
124 $this->perm = new wpForoPermissions();
125 $this->sbscrb = new wpForoSubscribe();
126 $this->tpl = new wpForoTemplate();
127 $this->notice = new wpForoNotices();
128 $this->api = new wpForoAPI();
129 $this->log = new wpForoLogs();
130 $this->feed = new wpForoFeed();
131 $this->form = new wpForoForm();
132 $this->moderation = new wpForoModeration();
133 $this->activity = new wpForoActivity();
134 $this->seo = new wpForoSEO();
135 $this->add = new stdClass(); // Integrations
136 }
137
138 private function init_hooks(){
139 add_action('admin_init', array($this, 'admin_init'));
140 add_action('init', array($this, 'init'));
141 add_action('wp_loaded', 'wpforo_actions');
142 add_action('wp', array($this, 'init_shortcode_page'));
143 }
144
145 private function init_db_tables($blog_id = 0){
146 $blog_id = apply_filters('wpforo_current_blog_id', $blog_id);
147 $this->tables = new stdClass;
148 if(!$blog_id) $blog_id = $this->db->blogid;
149 $this->blog_prefix = $this->db->get_blog_prefix( $blog_id );
150 $this->_tables = apply_filters('wpforo_init_db_tables', $this->_tables);
151 foreach ( $this->_tables as $table )
152 $this->tables->$table = $this->blog_prefix . $this->prefix . $table;
153 }
154
155 private function includes(){
156 include( WPFORO_DIR . '/wpf-includes/wpf-hooks.php' );
157 include( WPFORO_DIR . '/wpf-includes/wpf-actions.php');
158 include( WPFORO_DIR . '/wpf-includes/functions.php' );
159 include( WPFORO_DIR . '/wpf-includes/functions-integration.php' );
160 include( WPFORO_DIR . '/wpf-includes/functions-template.php' );
161 if(wpforo_is_admin()) {
162 include( WPFORO_DIR . '/wpf-includes/functions-installation.php' );
163 include( WPFORO_DIR .'/wpf-admin/admin.php' );
164 }
165
166 include( WPFORO_DIR . '/wpf-includes/class-cache.php' );
167 include( WPFORO_DIR . '/wpf-includes/class-forums.php' );
168 include( WPFORO_DIR . '/wpf-includes/class-topics.php' );
169 include( WPFORO_DIR . '/wpf-includes/class-posts.php' );
170 include( WPFORO_DIR . '/wpf-includes/class-usergroups.php' );
171 include( WPFORO_DIR . '/wpf-includes/class-members.php' );
172 include( WPFORO_DIR . '/wpf-includes/class-permissions.php' );
173 include( WPFORO_DIR . '/wpf-includes/class-phrases.php');
174 include( WPFORO_DIR . '/wpf-includes/class-subscribes.php' );
175 include( WPFORO_DIR . '/wpf-includes/class-template.php' );
176 include( WPFORO_DIR . '/wpf-includes/class-notices.php' );
177 include( WPFORO_DIR . '/wpf-includes/class-logs.php' );
178 include( WPFORO_DIR . '/wpf-includes/class-api.php' );
179 include( WPFORO_DIR . '/wpf-includes/class-feed.php' );
180 include( WPFORO_DIR . '/wpf-includes/class-forms.php' );
181 include( WPFORO_DIR . '/wpf-includes/class-moderation.php' );
182 include( WPFORO_DIR . '/wpf-includes/class-activity.php' );
183 include( WPFORO_DIR . '/wpf-includes/class-seo.php' );
184 }
185
186 public function admin_init(){
187 if( wpforo_is_admin() ){
188 if( !wpforo_feature('user-synch') && get_option('wpforo_version') ){
189 $users = $this->db->get_var("SELECT COUNT(*) FROM `".$this->db->users."`");
190 $profiles = $this->db->get_var("SELECT COUNT(*) FROM `" . $this->tables->profiles."`");
191 $delta = $users - $profiles;
192 if( $users > 100 && $delta > 2 ){ add_action( 'admin_notices', 'wpforo_profile_notice' ); }
193 }
194 $db_version = get_option('wpforo_version_db');
195 if( !$db_version || version_compare( $db_version, WPFORO_VERSION, '<') ){
196 add_action( 'admin_notices', 'wpforo_update_db_notice' );
197 }
198 if( !WPF()->forum->manage() && wpforo_current_user_is('admin') ){
199 WPF()->member->set_usergroup(WPF()->current_userid, 1);
200 wp_redirect( wpforo_get_request_uri() );
201 exit;
202 }
203 }
204 }
205
206 public function init(){
207 $this->phrase->init();
208 $this->member->init_current_user();
209 $this->perm->init();
210
211 $this->init_current_object();
212 $this->moderation->init();
213 $this->tpl->init();
214 $this->api->hooks();
215 add_action('wp_ajax_wpforo_deactivate', array($this, 'deactivate'));
216 }
217
218 public function init_shortcode_page(){
219 if(wpforo_is_admin()) return;
220
221 if( is_wpforo_shortcode_page() ){
222 $url = wpforo_home_url();
223
224 if( $atts = get_wpforo_shortcode_atts() ){
225 $args = shortcode_atts( array(
226 'item' => 'forum',
227 'id' => 0,
228 'slug' => '',
229 ), $atts );
230
231 if( $args['id'] || $args['slug'] ){
232 $getid = ( $args['slug'] ? $args['slug'] : $args['id'] );
233 if( $args['item'] == 'topic' ){
234 $url = $this->topic->get_topic_url($getid);
235 }elseif( $args['item'] == 'profile' ){
236 $url = $this->member->get_profile_url($getid);
237 }else{
238 $url = $this->forum->get_forum_url($getid);
239 }
240 }
241 }
242
243 $this->init_current_object($url);
244 $this->tpl->init_nav_menu();
245 }
246
247 }
248
249 private function init_defaults(){
250 $this->default = new stdClass;
251
252 $this->default->use_home_url = 0;
253 $this->default->excld_urls = '';
254 $this->default->permastruct = 'community';
255
256 $blogname = get_option('blogname', '');
257 $this->default->general_options = array(
258 'title' => $blogname . ' ' . __('Forum', 'wpforo'),
259 'description' => $blogname . ' ' . __('Discussion Board', 'wpforo'),
260 'lang' => 1
261 );
262
263 $this->default->features = array(
264 'user-admin-bar' => 0,
265 'page-title' => 1,
266 'top-bar' => 1,
267 'top-bar-search' => 1,
268 'breadcrumb' => 1,
269 'footer-stat' => 1,
270 'mention-nicknames' => 1,
271 'content-do_shortcode' => 0,
272 'view-logging' => 1,
273 'author-link' => 0,
274 'comment-author-link' => 0,
275 'user-register' => 1,
276 'user-register-email-confirm' => 1,
277 'register-url' => 0,
278 'login-url' => 0,
279 'resetpass-url' => 1, //In most cases incompatible with security and antispam plugins
280 'replace-avatar' => 1,
281 'avatars' => 1,
282 'custom-avatars' => 1,
283 'signature' => 1,
284 'rating' => 1,
285 'rating_title' => 1,
286 'member_cashe' => 1,
287 'object_cashe' => 1,
288 'html_cashe' => 0,
289 'memory_cashe' => 1,
290 'seo-title' => 1,
291 'seo-meta' => 1,
292 'seo-profile' => 1,
293 'rss-feed' => 1,
294 'font-awesome' => 1,
295 'bp_profile' => 0,
296 'bp_activity' => 1,
297 'bp_notification' => 1,
298 'bp_forum_tab' => 1,
299 'um_profile' => 0,
300 'um_forum_tab' => 1,
301 'um_notification' => 1,
302 'user-synch' => 0,
303 'role-synch' => 1,
304 'output-buffer' => 1,
305 'wp-date-format' => 0,
306 'subscribe_conf' => 1,
307 'subscribe_checkbox_on_post_editor' => 1,
308 'subscribe_checkbox_default_status' => 0,
309 'attach-media-lib' => 1,
310 'debug-mode' => 0,
311 'copyright' => 1
312 );
313
314 $this->default->tools_antispam = array(
315 'spam_filter' => 1,
316 'spam_filter_level_topic' => mt_rand(30, 60),
317 'spam_filter_level_post' => mt_rand(30, 60),
318 'spam_user_ban' => 0,
319 'new_user_max_posts' => 5,
320 'spam_user_ban_notification' => 1,
321 'min_number_post_to_attach' => 3,
322 'min_number_post_to_link' => 0,
323 'spam_file_scanner' => 1,
324 'limited_file_ext' => 'pdf|doc|docx|txt|htm|html|rtf|xml|xls|xlsx|zip|rar|tar|gz|bzip|7z',
325 'exclude_file_ext' => 'pdf|doc|docx|txt',
326 'rc_site_key' => '',
327 'rc_secret_key' => '',
328 'rc_theme' => 'light',
329 'rc_login_form' => 0,
330 'rc_reg_form' => 0,
331 'rc_lostpass_form' => 0,
332 'rc_wpf_login_form' => 1,
333 'rc_wpf_reg_form' => 1,
334 'rc_wpf_lostpass_form' => 1,
335 'rc_topic_editor' => 1,
336 'rc_post_editor' => 1,
337 'html' => 'embed(src width height name pluginspage type wmode allowFullScreen allowScriptAccess flashVars),',
338 );
339
340 $this->default->tools_cleanup = array(
341 'user_reg_days_ago' => 7,
342 'auto_cleanup_users' => 0,
343 'usergroup' => array ( 1 => '0', 5 => '0', 2 => '1', 3 => '0' )
344 );
345
346 $this->default->tools_misc = array(
347 'dofollow' => '',
348 'noindex' => '',
349 'admin_note' => '',
350 'admin_note_groups' => array( 1, 2, 3, 4, 5 ),
351 'admin_note_pages' => array('forum')
352 );
353
354 $this->default->tools_legal = array(
355 'rules_checkbox' => 0,
356 'rules_text' => NULL,
357 'page_terms' => '',
358 'page_privacy' => '',
359 'forum_privacy_text' => NULL,
360 'checkbox_terms_privacy' => 0,
361 'checkbox_email_password' => 1,
362 'checkbox_forum_privacy' => 0,
363 'checkbox_fb_login' => 1,
364 'contact_page_url' => NULL,
365 'cookies' => 1
366 );
367
368 $this->default->stats = array(
369 'forums' => 0,
370 'topics' => 0,
371 'posts' => 0,
372 'members' => 0,
373 'online_members_count' => 0,
374 'last_post_title' => '',
375 'last_post_url' => '',
376 'newest_member_dname' => '',
377 'newest_member_profile_url' => ''
378 );
379 }
380
381 private function init_options(){
382 $permalink_structure = get_option('permalink_structure');
383
384 $this->use_trailing_slashes = ( '/' == substr($permalink_structure, -1, 1) );
385
386 //OPTIONS
387 $this->use_home_url = get_wpf_option('wpforo_use_home_url', $this->default->use_home_url);
388 $this->excld_urls = get_wpf_option('wpforo_excld_urls', $this->default->excld_urls);
389
390 $this->permastruct = trim( get_wpf_option('wpforo_permastruct', $this->default->permastruct), '/' );
391 $this->permastruct = preg_replace('#^/?index\.php/?#isu', '', $this->permastruct);
392 $this->permastruct = trim($this->permastruct, '/');
393
394 $this->base_permastruct = (!$this->use_home_url ? $this->permastruct : '');
395 $this->base_permastruct = rtrim( ( strpos($permalink_structure, 'index.php') !== FALSE ? '/index.php/' . $this->base_permastruct : '/' . $this->base_permastruct ), '/\\' );
396 $this->url = esc_url( home_url( $this->user_trailingslashit($this->base_permastruct) ) );
397 $this->pageid = get_wpf_option( 'wpforo_pageid');
398
399 $this->general_options = get_wpf_option( 'wpforo_general_options', $this->default->general_options);
400 $this->features = get_wpf_option('wpforo_features', $this->default->features);
401 $this->tools_antispam = get_wpf_option('wpforo_tools_antispam', $this->default->tools_antispam);
402 $this->tools_cleanup = get_wpf_option('wpforo_tools_cleanup', $this->default->tools_cleanup);
403 $this->tools_misc = get_wpf_option('wpforo_tools_misc', $this->default->tools_misc);
404 $this->tools_legal = get_wpf_option('wpforo_tools_legal', $this->default->tools_legal);
405
406 //CONSTANTS
407 define('WPFORO_BASE_PERMASTRUCT', $this->base_permastruct );
408 define('WPFORO_BASE_URL', $this->url );
409 }
410
411 private function setup(){
412 if( wpforo_is_admin() ){
413 register_activation_hook($this->basename, 'do_wpforo_activation');
414 register_deactivation_hook($this->basename, 'do_wpforo_deactivation');
415 }
416 }
417
418 public function user_trailingslashit($url) {
419 $rtrimed_url = '';
420 $url_append_vars = '';
421 if( preg_match('#(^.+?)(/?\?.*$|$)#isu', $url, $match) ){
422 if(isset($match[1]) && $match[1]) $rtrimed_url = rtrim($match[1], '/\\');
423 if(isset($match[2]) && $match[2]) $url_append_vars = trim($match[2], '/\\');
424 if( $rtrimed_url ) {
425 $home_url = rtrim( preg_replace('#/?\?.*$#isu', '', home_url()), '/\\' );
426 if( $rtrimed_url == $home_url ){
427 $url = $rtrimed_url . '/';
428 }else{
429 $url = ( $this->use_trailing_slashes ? $rtrimed_url . '/' : $rtrimed_url );
430 }
431 }
432 }
433 return $url . $url_append_vars;
434 }
435
436 public function statistic( $mode = 'get', $template = 'all' ){
437
438 if( $mode == 'get' ){
439 if( $cached_stat = get_option('wpforo_stat' ) ){
440 $cached_stat['online_members_count'] = $this->member->online_members_count();
441 return $cached_stat;
442 }
443 }
444
445 if( $mode == 'get' || $template == 'all' ) {
446 $stats['forums'] = $this->forum->get_count( array('is_cat' => 0) );
447 $stats['topics'] = $this->topic->get_count();
448 $stats['posts'] = $this->post->get_count();
449 $stats['members'] = $this->member->get_count();
450 $stats['online_members_count'] = $this->member->online_members_count();
451 $row_count = apply_filters('wpforo_get_statistic_row_count', 20);
452
453 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => $row_count, 'private' => 0, 'status' => 0, 'permgroup' => 4 ));
454 $first = key($posts);
455 if ( isset($posts[$first]) && !empty($posts[$first]) && $this->perm->forum_can('vf', $posts[$first]['forumid'], 4) ) {
456 $stats['last_post_title'] = $posts[$first]['title'];
457 $stats['last_post_url'] = $this->post->get_post_url($posts[$first]['last_post']);
458 }
459
460 $members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1));
461 if (isset($members[0]) && !empty($members[0])) {
462 $stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']);
463 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
464 }
465 }else{
466 $stats = get_wpf_option('wpforo_stat', $this->default->stats);
467 switch ($template){
468 case 'forum':
469 $stats['forums'] = $this->forum->get_count( array('is_cat' => 0) );
470 break;
471 case 'topic':
472 $stats['topics'] = $this->topic->get_count();
473 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1));
474 if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) {
475 $stats['last_post_title'] = $posts[0]['title'];
476 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
477 }
478 break;
479 case 'post':
480 $stats['posts'] = $this->post->get_count();
481 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1));
482 if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) {
483 $stats['last_post_title'] = $posts[0]['title'];
484 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
485 }
486 break;
487 case 'user':
488 $stats['members'] = $this->member->get_count();
489 $stats['online_members_count'] = $this->member->online_members_count();
490
491 $members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1));
492 if (isset($members[0]) && !empty($members[0])) {
493 $stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']);
494 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
495 }
496 break;
497 }
498 }
499
500 $stats = array_merge($this->default->stats, $stats);
501 $stats = apply_filters('wpforo_get_statistic_array_filter', $stats);
502 update_option( 'wpforo_stat', $stats );
503 return $stats;
504 }
505
506 public function init_current_object($url = ''){
507 $this->current_object = array('template' => '', 'paged' => 1, 'is_404' => false, 'user_is_same_current_user' => false);
508 if(!$url) $url = wpforo_get_request_uri();
509
510 if( !is_wpforo_page($url) ) return;
511
512 $this->current_url = $url;
513 $current_url = wpforo_get_url_query_vars_str($url);
514
515 if( $this->use_home_url ) $this->permastruct = '';
516
517 $current_object = array();
518 $current_object['template'] = '';
519 $current_object['is_404'] = false;
520 $current_object['user_is_same_current_user'] = false;
521
522 if(isset($_GET['wpfs'])) $current_object['template'] = 'search';
523 if( isset($_GET['wpforo']) ){
524 switch($_GET['wpforo']){
525 case 'signup':
526 if(!is_user_logged_in()) $current_object['template'] = 'register';
527 break;
528 case 'signin':
529 if(!is_user_logged_in()) $current_object['template'] = 'login';
530 break;
531 case 'lostpassword':
532 if(!is_user_logged_in()) $current_object['template'] = 'lostpassword';
533 break;
534 case 'resetpassword':
535 $current_object['template'] = 'resetpassword';
536 break;
537 case 'page':
538 $current_object['template'] = 'page';
539 break;
540 case 'logout':
541 wp_logout();
542 wp_redirect( wpforo_home_url( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) ) );
543 exit();
544 break;
545 }
546 }
547
548 $wpf_url = preg_replace( '#^/?'.preg_quote($this->permastruct).'#isu', '' , $current_url, 1 );
549 $wpf_url = preg_replace('#/?\?.*$#isu', '', $wpf_url);
550 $wpf_url_parse = array_filter( explode('/', trim($wpf_url, '/')) );
551 $wpf_url_parse = array_reverse($wpf_url_parse);
552
553 if(in_array(WPF()->tpl->slugs['paged'], $wpf_url_parse)){
554 foreach($wpf_url_parse as $key => $value){
555 if( $value == WPF()->tpl->slugs['paged']){
556 unset($wpf_url_parse[$key]);
557 break;
558 }
559 if(is_numeric($value)) $paged = intval($value);
560
561 unset($wpf_url_parse[$key]);
562 }
563 }
564 if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']);
565 $current_object['paged'] = (isset($paged) && $paged) ? $paged : 1;
566
567 $wpf_url_parse = array_values($wpf_url_parse);
568
569 if( !isset($current_object['template']) || !$current_object['template'] )
570 $current_object = apply_filters('wpforo_before_init_current_object', $current_object, $wpf_url_parse);
571
572 if( !isset($current_object['template']) || !$current_object['template'] ) {
573 if(in_array(WPF()->tpl->slugs['members'], $wpf_url_parse) && $wpf_url_parse[0] == WPF()->tpl->slugs['members']){
574 $current_object['template'] = 'members';
575 }elseif(in_array(WPF()->tpl->slugs['recent'], $wpf_url_parse) && $wpf_url_parse[0] == WPF()->tpl->slugs['recent']){
576 $current_object['template'] = 'recent';
577 }elseif(in_array(WPF()->tpl->slugs['tags'], $wpf_url_parse) && $wpf_url_parse[0] == WPF()->tpl->slugs['tags']){
578 $current_object['template'] = 'tags';
579 }elseif(in_array(WPF()->tpl->slugs['profile'], $wpf_url_parse)){
580 $current_object['template'] = 'profile';
581 foreach($wpf_url_parse as $value){
582 if( $value == WPF()->tpl->slugs['profile']) break;
583 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
584 }
585 }elseif(in_array(WPF()->tpl->slugs['account'], $wpf_url_parse)){
586 $current_object['template'] = 'account';
587 foreach($wpf_url_parse as $value){
588 if( $value == WPF()->tpl->slugs['account']) break;
589 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
590 }
591 }elseif(in_array(WPF()->tpl->slugs['activity'], $wpf_url_parse)){
592 $current_object['template'] = 'activity';
593 foreach($wpf_url_parse as $value){
594 if( $value == WPF()->tpl->slugs['activity']) break;
595 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
596 }
597 }elseif(in_array(WPF()->tpl->slugs['subscriptions'], $wpf_url_parse)){
598 $current_object['template'] = 'subscriptions';
599 foreach($wpf_url_parse as $value){
600 if( $value == WPF()->tpl->slugs['subscriptions']) break;
601 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
602 }
603 }else{
604 $current_object['template'] = 'forum';
605 if( isset($wpf_url_parse[0]) ){
606 if( isset($wpf_url_parse[1]) ){
607 $current_object['topic_slug'] = $wpf_url_parse[0];
608 $current_object['forum_slug'] = $wpf_url_parse[1];
609 $current_object['template'] = 'post';
610 }else{
611 $current_object['forum_slug'] = $wpf_url_parse[0];
612 $current_object['template'] = 'topic';
613 }
614 }
615 }
616 }
617
618 if( in_array( $current_object['template'], array('profile', 'account', 'activity', 'subscriptions') )
619 && !isset($current_object['user_nicename']) && !isset($current_object['userid']) ){
620 $current_object = wpforo_find_current_user_data( $current_object );
621 }
622
623 if( isset($current_object['userid']) || isset($current_object['user_nicename']) ){
624 $args = array();
625 if(isset($current_object['userid'])) $args['userid'] = $current_object['userid'];
626 if(isset($current_object['user_nicename'])) $args['user_nicename'] = $current_object['user_nicename'];
627 $selected_user = $this->member->get_member($args);
628 if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('user_nicename' => $current_object['userid']));
629 if(!empty($selected_user)){
630 $current_object['user'] = $selected_user;
631 $current_object['userid'] = $selected_user['ID'];
632 $current_object['user_nicename'] = $selected_user['user_nicename'];
633 $current_object['user_is_same_current_user'] = !empty($this->current_userid) && $selected_user['ID'] == $this->current_userid;
634
635 switch($current_object['template']){
636 case 'activity':
637 $args = array(
638 'offset' => ($current_object['paged'] - 1) * $this->post->options['posts_per_page'],
639 'row_count' => $this->post->options['posts_per_page'],
640 'userid' => $current_object['userid'],
641 'orderby' => '`created` DESC, `postid` DESC',
642 'check_private' => true
643 );
644 $current_object['items_count'] = 0;
645 $current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']);
646 break;
647 case 'subscriptions':
648 $args = array(
649 'offset' => ($current_object['paged'] - 1) * $this->post->options['posts_per_page'],
650 'row_count' => $this->post->options['posts_per_page'],
651 'userid' => $current_object['userid'],
652 'order' => 'DESC'
653 );
654 $current_object['items_count'] = 0;
655 $current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']);
656 break;
657 }
658
659 }else{
660 $current_object['is_404'] = true;
661 $current_object['user'] = array();
662 $current_object['userid'] = 0;
663 $current_object['user_nicename'] = '';
664 }
665 }
666
667 if(isset($current_object['forum_slug']) && $current_object['forum_slug']){
668 $forum = $this->forum->get_forum( array('slug' => $current_object['forum_slug']) );
669 if(!empty($forum)){
670 $current_object['forum'] = $forum;
671 $current_object['forumid'] = $forum['forumid'];
672 $current_object['forum_desc'] = $forum['description'];
673 $current_object['forum_meta_key'] = $forum['meta_key'];
674 $current_object['forum_meta_desc'] = $forum['meta_desc'];
675 $current_object['og_text'] = $forum['title'];
676 }else{
677 $current_object['is_404'] = true;
678 $current_object['forum'] = array();
679 $current_object['forumid'] = 0;
680 $current_object['forum_desc'] = '';
681 $current_object['forum_meta_key'] = '';
682 $current_object['forum_meta_desc'] = '';
683 $current_object['og_text'] = '';
684 }
685 }
686
687 if(isset($current_object['topic_slug']) && $current_object['topic_slug']){
688 $topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug']));
689 if(!empty($topic)){
690 $current_object['topic'] = $topic;
691 $current_object['topicid'] = $topic['topicid'];
692 $current_object['og_text'] = ( wpfval($topic, 'title') ? $topic['title'] : '' );
693 }elseif( wpfkey($this->current_object, 'status') && $this->current_object['status'] == 'unapproved' && !is_user_logged_in() ){
694 wp_redirect( wpforo_login_url() );
695 exit();
696 }else{
697 $current_object['is_404'] = true;
698 $current_object['topic'] = array();
699 $current_object['topicid'] = 0;
700 }
701 }
702
703 $this->current_object = apply_filters('wpforo_after_init_current_object', $current_object, $wpf_url_parse);
704 }
705
706 public function is_installed(){
707 return (bool) get_option('wpforo_version');
708 }
709
710 public function deactivate(){
711 $response = array('code' => 0);
712 $json = filter_input(INPUT_POST, 'deactivateData');
713 if ($json) {
714 parse_str($json, $data);
715
716 $blogTitle = get_option('blogname');
717 $to = 'feedback@wpforo.com';
718 $subject = '[wpForo Feedback - ' . WPFORO_VERSION . ']';
719 $headers = array();
720 $contentType = 'text/html';
721 $fromName = apply_filters('wp_mail_from_name', $blogTitle);
722 $fromName = html_entity_decode($fromName, ENT_QUOTES);
723 $siteUrl = get_site_url();
724 $parsedUrl = parse_url($siteUrl);
725 $domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
726 $fromEmail = 'no-reply@' . $domain;
727 $headers[] = "Content-Type: $contentType; charset=UTF-8";
728 $headers[] = "From: " . $fromName . " <" . $fromEmail . "> \r\n";
729 $message = "Dismiss and never show again";
730
731 if(isset($data['never_show']) && ($v = intval($data['never_show']))){
732 update_option('wpforo_deactivation_dialog_never_show', $v);
733 $response['code'] = 'dismiss_and_deactivate';
734 }elseif(isset($data['deactivation_reason']) && ($reason = trim($data['deactivation_reason']))){
735 $subject .= ' - ' . $reason;
736 $message = "<strong>Deactivation reason:</strong> " . $reason . "\r\n" . "<br/>";
737 if (isset($data['deactivation_reason_desc']) && ($reasonDesc = trim($data['deactivation_reason_desc']))) {
738 $message .= "<strong>Deactivation reason description:</strong> " . $reasonDesc . "\r\n" . "<br/>";
739 }
740 if (isset($data['deactivation_feedback_email']) && ($feedback_email = trim($data['deactivation_feedback_email']))) {
741 $to = 'support@wpforo.com';
742 $message .= "<strong>Feedback Email:</strong> " . $feedback_email . "\r\n" . "<br/>";
743 }
744 $subject = html_entity_decode($subject, ENT_QUOTES);
745 $message = html_entity_decode($message, ENT_QUOTES);
746 $response['code'] = 'send_and_deactivate';
747 }
748
749 wp_mail($to, $subject, $message, $headers);
750 }
751 wp_die(json_encode($response));
752 }
753 }
754
755 /**
756 * Main instance of wpForo.
757 *
758 * Returns the main instance of WPF to prevent the need to use globals.
759 *
760 * @since 1.4.3
761 * @return wpForo
762 */
763 if ( !function_exists('WPF') ){
764 function WPF() {
765 return wpForo::instance();
766 }
767 }
768
769 // Global for backwards compatibility.
770 $GLOBALS['wpforo'] = WPF();
771
772 //ADDONS/////////////////////////////////////////////////////
773 WPF()->addons = array(
774 'embeds' => array('version' => '1.0.4', 'requires' => '1.4.0', 'class' => 'wpForoEmbeds', 'title' => 'Embeds', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'embeds' . '/header.png', 'desc' => __('Allows to embed hundreds of video, social network, audio and photo content providers in forum topics and posts.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-embeds/'),
775 'polls' => array('version' => '1.0.0', 'requires' => '1.4.3', 'class' => 'wpForoPoll', 'title' => 'Polls', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'polls' . '/header.png', 'desc' => __('wpForo Polls is a complete addon to help forum members create, vote and manage polls effectively. Comes with poll specific permissions and settings.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-polls/'),
776 'mycred' => array('version' => '1.0.0', 'requires' => '1.4.3', 'class' => 'myCRED_Hook_wpForo', 'title' => 'MyCRED Integration', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'mycred' . '/header.png', 'desc' => __('Awards myCRED points for forum activity. Integrates myCRED Badges and Ranks. Converts wpForo topic and posts, likes to myCRED points.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-mycred/'),
777 'ucf' => array('version' => '1.0.0', 'requires' => '1.4.0', 'class' => 'WpforoUcf', 'title' => 'User Custom Fields', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'ucf' . '/header.png', 'desc' => __('Advanced user profile builder system. Allows to add new fields and manage profile page. Creates custom Registration, Account, Member Search forms.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-user-custom-fields/'),
778 'attachments' => array('version' => '1.1.2', 'requires' => '1.4.0', 'class' => 'wpForoAttachments', 'title' => 'Advanced Attachments', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'attachments' . '/header.png', 'desc' => __('Adds an advanced file attachment system to forum topics and posts. AJAX powered media uploading and displaying system with user specific library.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-advanced-attachments/'),
779 'pm' => array('version' => '1.0.3', 'requires' => '1.4.0', 'class' => 'wpForoPMs', 'title' => 'Private Messages', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'pm' . '/header.png', 'desc' => __('Provides a safe way to communicate directly with other members. Messages are private and can only be viewed by conversation participants.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-private-messages/'),
780 'cross' => array('version' => '1.0.3', 'requires' => '1.4.0', 'class' => 'wpForoCrossPosting', 'title' => '"Forum - Blog" Cross Posting', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'cross' . '/header.png', 'desc' => __('Blog to Forum and Forum to Blog content synchronization. Blog posts with Forum topics and Blog comments with Forum replies.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-cross-posting/'),
781 'ad-manager' => array('version' => '1.0.0', 'requires' => '1.4.0', 'class' => 'wpForoAD', 'title' => 'Ads Manager', 'thumb' => WPFORO_URL . '/wpf-assets/addons/' . 'ad-manager' . '/header.png', 'desc' => __('Ads Manager is a powerful yet simple advertisement management system, that allows you to add adverting banners between forums, topics and posts.', 'wpforo'), 'url' => 'https://gvectors.com/product/wpforo-ad-manager/'),
782 );
783 $wp_version = get_bloginfo('version'); if (version_compare($wp_version, '4.2.0', '>=')) { add_action('wp_ajax_dismiss_wpforo_addon_note', array(WPF()->notice, 'dismissAddonNote')); add_action('admin_notices', array(WPF()->notice, 'addonNote'));}
784 /////////////////////////////////////////////////////////////
785 }