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

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

793 lines 37.7 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.4
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.4');
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
199 if( strpos( wpforo_get_request_uri(), 'user-new.php' ) === false ){
200 $sql = "SELECT `groupid` FROM ". WPF()->tables->profiles ." WHERE `userid` = " . wpforo_bigintval(WPF()->current_userid);
201 if( !$current_groupid = WPF()->db->get_var($sql) ){
202 WPF()->member->synchronize_user(WPF()->current_userid);
203 }
204 }
205
206 if( !WPF()->forum->manage() && wpforo_current_user_is('admin') ){
207 WPF()->member->set_usergroup(WPF()->current_userid, 1);
208 }
209 }
210 }
211
212 public function init(){
213 $this->phrase->init();
214 $this->member->init_current_user();
215 $this->perm->init();
216
217 $this->init_current_object();
218 $this->moderation->init();
219 $this->tpl->init();
220 $this->api->hooks();
221 add_action('wp_ajax_wpforo_deactivate', array($this, 'deactivate'));
222 }
223
224 public function init_shortcode_page(){
225 if(wpforo_is_admin()) return;
226
227 if( is_wpforo_shortcode_page() ){
228 $url = wpforo_home_url();
229
230 if( $atts = get_wpforo_shortcode_atts() ){
231 $args = shortcode_atts( array(
232 'item' => 'forum',
233 'id' => 0,
234 'slug' => '',
235 ), $atts );
236
237 if( $args['id'] || $args['slug'] ){
238 $getid = ( $args['slug'] ? $args['slug'] : $args['id'] );
239 if( $args['item'] == 'topic' ){
240 $url = $this->topic->get_topic_url($getid);
241 }elseif( $args['item'] == 'profile' ){
242 $url = $this->member->get_profile_url($getid);
243 }else{
244 $url = $this->forum->get_forum_url($getid);
245 }
246 }
247 }
248
249 $this->init_current_object($url);
250 $this->tpl->init_nav_menu();
251 }
252
253 }
254
255 private function init_defaults(){
256 $this->default = new stdClass;
257
258 $this->default->use_home_url = 0;
259 $this->default->excld_urls = '';
260 $this->default->permastruct = 'community';
261
262 $blogname = get_option('blogname', '');
263 $this->default->general_options = array(
264 'title' => $blogname . ' ' . __('Forum', 'wpforo'),
265 'description' => $blogname . ' ' . __('Discussion Board', 'wpforo'),
266 'lang' => 1
267 );
268
269 $this->default->features = array(
270 'user-admin-bar' => 0,
271 'page-title' => 1,
272 'top-bar' => 1,
273 'top-bar-search' => 1,
274 'breadcrumb' => 1,
275 'footer-stat' => 1,
276 'mention-nicknames' => 1,
277 'content-do_shortcode' => 0,
278 'view-logging' => 1,
279 'track-logging' => 1,
280 'author-link' => 0,
281 'comment-author-link' => 0,
282 'user-register' => 1,
283 'user-register-email-confirm' => 1,
284 'register-url' => 0,
285 'login-url' => 0,
286 'resetpass-url' => 1, //In most cases incompatible with security and antispam plugins
287 'replace-avatar' => 1,
288 'avatars' => 1,
289 'custom-avatars' => 1,
290 'signature' => 1,
291 'rating' => 1,
292 'rating_title' => 1,
293 'member_cashe' => 1,
294 'object_cashe' => 1,
295 'html_cashe' => 0,
296 'memory_cashe' => 1,
297 'seo-title' => 1,
298 'seo-meta' => 1,
299 'seo-profile' => 1,
300 'rss-feed' => 1,
301 'font-awesome' => 1,
302 'bp_profile' => 0,
303 'bp_activity' => 1,
304 'bp_notification' => 1,
305 'bp_forum_tab' => 1,
306 'um_profile' => 0,
307 'um_forum_tab' => 1,
308 'um_notification' => 1,
309 'user-synch' => 0,
310 'role-synch' => 1,
311 'output-buffer' => 1,
312 'wp-date-format' => 0,
313 'subscribe_conf' => 1,
314 'subscribe_checkbox_on_post_editor' => 1,
315 'subscribe_checkbox_default_status' => 0,
316 'attach-media-lib' => 1,
317 'debug-mode' => 0,
318 'copyright' => 1
319 );
320
321 $this->default->tools_antispam = array(
322 'spam_filter' => 1,
323 'spam_filter_level_topic' => mt_rand(30, 60),
324 'spam_filter_level_post' => mt_rand(30, 60),
325 'spam_user_ban' => 0,
326 'new_user_max_posts' => 5,
327 'spam_user_ban_notification' => 1,
328 'min_number_post_to_attach' => 3,
329 'min_number_post_to_link' => 0,
330 'spam_file_scanner' => 1,
331 'limited_file_ext' => 'pdf|doc|docx|txt|htm|html|rtf|xml|xls|xlsx|zip|rar|tar|gz|bzip|7z',
332 'exclude_file_ext' => 'pdf|doc|docx|txt',
333 'rc_site_key' => '',
334 'rc_secret_key' => '',
335 'rc_theme' => 'light',
336 'rc_login_form' => 0,
337 'rc_reg_form' => 0,
338 'rc_lostpass_form' => 0,
339 'rc_wpf_login_form' => 1,
340 'rc_wpf_reg_form' => 1,
341 'rc_wpf_lostpass_form' => 1,
342 'rc_topic_editor' => 1,
343 'rc_post_editor' => 1,
344 'html' => 'embed(src width height name pluginspage type wmode allowFullScreen allowScriptAccess flashVars),',
345 );
346
347 $this->default->tools_cleanup = array(
348 'user_reg_days_ago' => 7,
349 'auto_cleanup_users' => 0,
350 'usergroup' => array ( 1 => '0', 5 => '0', 2 => '1', 3 => '0' )
351 );
352
353 $this->default->tools_misc = array(
354 'dofollow' => '',
355 'noindex' => '',
356 'admin_note' => '',
357 'admin_note_groups' => array( 1, 2, 3, 4, 5 ),
358 'admin_note_pages' => array('forum')
359 );
360
361 $this->default->tools_legal = array(
362 'rules_checkbox' => 0,
363 'rules_text' => NULL,
364 'page_terms' => '',
365 'page_privacy' => '',
366 'forum_privacy_text' => NULL,
367 'checkbox_terms_privacy' => 0,
368 'checkbox_email_password' => 1,
369 'checkbox_forum_privacy' => 0,
370 'checkbox_fb_login' => 1,
371 'contact_page_url' => NULL,
372 'cookies' => 1
373 );
374
375 $this->default->stats = array(
376 'forums' => 0,
377 'topics' => 0,
378 'posts' => 0,
379 'members' => 0,
380 'online_members_count' => 0,
381 'last_post_title' => '',
382 'last_post_url' => '',
383 'newest_member_dname' => '',
384 'newest_member_profile_url' => ''
385 );
386 }
387
388 private function init_options(){
389 $permalink_structure = get_option('permalink_structure');
390
391 $this->use_trailing_slashes = ( '/' == substr($permalink_structure, -1, 1) );
392
393 //OPTIONS
394 $this->use_home_url = get_wpf_option('wpforo_use_home_url', $this->default->use_home_url);
395 $this->excld_urls = get_wpf_option('wpforo_excld_urls', $this->default->excld_urls);
396
397 $this->permastruct = trim( get_wpf_option('wpforo_permastruct', $this->default->permastruct), '/' );
398 $this->permastruct = preg_replace('#^/?index\.php/?#isu', '', $this->permastruct);
399 $this->permastruct = trim($this->permastruct, '/');
400
401 $this->base_permastruct = (!$this->use_home_url ? $this->permastruct : '');
402 $this->base_permastruct = rtrim( ( strpos($permalink_structure, 'index.php') !== FALSE ? '/index.php/' . $this->base_permastruct : '/' . $this->base_permastruct ), '/\\' );
403 $this->url = esc_url( home_url( $this->user_trailingslashit($this->base_permastruct) ) );
404 $this->pageid = get_wpf_option( 'wpforo_pageid');
405
406 $this->general_options = get_wpf_option( 'wpforo_general_options', $this->default->general_options);
407 $this->features = get_wpf_option('wpforo_features', $this->default->features);
408 $this->tools_antispam = get_wpf_option('wpforo_tools_antispam', $this->default->tools_antispam);
409 $this->tools_cleanup = get_wpf_option('wpforo_tools_cleanup', $this->default->tools_cleanup);
410 $this->tools_misc = get_wpf_option('wpforo_tools_misc', $this->default->tools_misc);
411 $this->tools_legal = get_wpf_option('wpforo_tools_legal', $this->default->tools_legal);
412
413 //CONSTANTS
414 define('WPFORO_BASE_PERMASTRUCT', $this->base_permastruct );
415 define('WPFORO_BASE_URL', $this->url );
416 }
417
418 private function setup(){
419 if( wpforo_is_admin() ){
420 register_activation_hook($this->basename, 'do_wpforo_activation');
421 register_deactivation_hook($this->basename, 'do_wpforo_deactivation');
422 }
423 }
424
425 public function user_trailingslashit($url) {
426 $rtrimed_url = '';
427 $url_append_vars = '';
428 if( preg_match('#(^.+?)(/?\?.*$|$)#isu', $url, $match) ){
429 if(isset($match[1]) && $match[1]) $rtrimed_url = rtrim($match[1], '/\\');
430 if(isset($match[2]) && $match[2]) $url_append_vars = trim($match[2], '/\\');
431 if( $rtrimed_url ) {
432 $home_url = rtrim( preg_replace('#/?\?.*$#isu', '', home_url()), '/\\' );
433 if( $rtrimed_url == $home_url ){
434 $url = $rtrimed_url . '/';
435 }else{
436 $url = ( $this->use_trailing_slashes ? $rtrimed_url . '/' : $rtrimed_url );
437 }
438 }
439 }
440 return $url . $url_append_vars;
441 }
442
443 public function statistic( $mode = 'get', $template = 'all' ){
444
445 if( $mode == 'get' ){
446 if( $cached_stat = get_option('wpforo_stat' ) ){
447 $cached_stat['online_members_count'] = $this->member->online_members_count();
448 return $cached_stat;
449 }
450 }
451
452 if( $mode == 'get' || $template == 'all' ) {
453 $stats['forums'] = $this->forum->get_count( array('is_cat' => 0) );
454 $stats['topics'] = $this->topic->get_count();
455 $stats['posts'] = $this->post->get_count();
456 $stats['members'] = $this->member->get_count();
457 $stats['online_members_count'] = $this->member->online_members_count();
458 $row_count = apply_filters('wpforo_get_statistic_row_count', 20);
459
460 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => $row_count, 'private' => 0, 'status' => 0, 'permgroup' => 4 ));
461 $first = key($posts);
462 if ( isset($posts[$first]) && !empty($posts[$first]) && $this->perm->forum_can('vf', $posts[$first]['forumid'], 4) ) {
463 $stats['last_post_title'] = $posts[$first]['title'];
464 $stats['last_post_url'] = $this->post->get_post_url($posts[$first]['last_post']);
465 }
466
467 $members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1));
468 if (isset($members[0]) && !empty($members[0])) {
469 $stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']);
470 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
471 }
472 }else{
473 $stats = get_wpf_option('wpforo_stat', $this->default->stats);
474 switch ($template){
475 case 'forum':
476 $stats['forums'] = $this->forum->get_count( array('is_cat' => 0) );
477 break;
478 case 'topic':
479 $stats['topics'] = $this->topic->get_count();
480 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1));
481 if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) {
482 $stats['last_post_title'] = $posts[0]['title'];
483 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
484 }
485 break;
486 case 'post':
487 $stats['posts'] = $this->post->get_count();
488 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1));
489 if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) {
490 $stats['last_post_title'] = $posts[0]['title'];
491 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
492 }
493 break;
494 case 'user':
495 $stats['members'] = $this->member->get_count();
496 $stats['online_members_count'] = $this->member->online_members_count();
497
498 $members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1));
499 if (isset($members[0]) && !empty($members[0])) {
500 $stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']);
501 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
502 }
503 break;
504 }
505 }
506
507 $stats = array_merge($this->default->stats, $stats);
508 $stats = apply_filters('wpforo_get_statistic_array_filter', $stats);
509 update_option( 'wpforo_stat', $stats );
510 return $stats;
511 }
512
513 public function init_current_object($url = ''){
514 $this->current_object = array('template' => '', 'paged' => 1, 'is_404' => false, 'user_is_same_current_user' => false);
515 if(!$url) $url = wpforo_get_request_uri();
516 $url = preg_replace('#\#[^\/\?\&]*$#isu', '', $url);
517
518 if( !is_wpforo_page($url) ) return;
519
520 $this->current_url = $url;
521 $current_url = wpforo_get_url_query_vars_str($url);
522
523 if( $this->use_home_url ) $this->permastruct = '';
524
525 $current_object = array();
526 $current_object['template'] = '';
527 $current_object['is_404'] = false;
528 $current_object['user_is_same_current_user'] = false;
529
530 if(isset($_GET['wpfs'])) $current_object['template'] = 'search';
531 if( isset($_GET['wpforo']) ){
532 switch($_GET['wpforo']){
533 case 'signup':
534 if(!is_user_logged_in()) $current_object['template'] = 'register';
535 break;
536 case 'signin':
537 if(!is_user_logged_in()) $current_object['template'] = 'login';
538 break;
539 case 'lostpassword':
540 if(!is_user_logged_in()) $current_object['template'] = 'lostpassword';
541 break;
542 case 'resetpassword':
543 $current_object['template'] = 'resetpassword';
544 break;
545 case 'page':
546 $current_object['template'] = 'page';
547 break;
548 case 'logout':
549 wp_logout();
550 wp_redirect( wpforo_home_url( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) ) );
551 exit();
552 break;
553 }
554 }
555
556 $wpf_url = preg_replace( '#^/?'.preg_quote($this->permastruct).'#isu', '' , $current_url, 1 );
557 $wpf_url = preg_replace('#/?\?.*$#isu', '', $wpf_url);
558 $wpf_url_parse = array_filter( explode('/', trim($wpf_url, '/')) );
559 $wpf_url_parse = array_reverse($wpf_url_parse);
560
561 if(in_array(WPF()->tpl->slugs['paged'], $wpf_url_parse)){
562 foreach($wpf_url_parse as $key => $value){
563 if( $value == WPF()->tpl->slugs['paged']){
564 unset($wpf_url_parse[$key]);
565 break;
566 }
567 if(is_numeric($value)) $paged = intval($value);
568
569 unset($wpf_url_parse[$key]);
570 }
571 }
572 if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']);
573 $current_object['paged'] = (isset($paged) && $paged) ? $paged : 1;
574
575 $wpf_url_parse = array_values($wpf_url_parse);
576
577 if( !isset($current_object['template']) || !$current_object['template'] )
578 $current_object = apply_filters('wpforo_before_init_current_object', $current_object, $wpf_url_parse);
579
580 if( !isset($current_object['template']) || !$current_object['template'] ) {
581 if(in_array(WPF()->tpl->slugs['members'], $wpf_url_parse) && $wpf_url_parse[0] == WPF()->tpl->slugs['members']){
582 $current_object['template'] = 'members';
583 }elseif(in_array(WPF()->tpl->slugs['recent'], $wpf_url_parse) && $wpf_url_parse[0] == WPF()->tpl->slugs['recent']){
584 $current_object['template'] = 'recent';
585 }elseif(in_array(WPF()->tpl->slugs['tags'], $wpf_url_parse) && $wpf_url_parse[0] == WPF()->tpl->slugs['tags']){
586 $current_object['template'] = 'tags';
587 }elseif(in_array(WPF()->tpl->slugs['profile'], $wpf_url_parse)){
588 $current_object['template'] = 'profile';
589 foreach($wpf_url_parse as $value){
590 if( $value == WPF()->tpl->slugs['profile']) break;
591 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
592 }
593 }elseif(in_array(WPF()->tpl->slugs['account'], $wpf_url_parse)){
594 $current_object['template'] = 'account';
595 foreach($wpf_url_parse as $value){
596 if( $value == WPF()->tpl->slugs['account']) break;
597 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
598 }
599 }elseif(in_array(WPF()->tpl->slugs['activity'], $wpf_url_parse)){
600 $current_object['template'] = 'activity';
601 foreach($wpf_url_parse as $value){
602 if( $value == WPF()->tpl->slugs['activity']) break;
603 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
604 }
605 }elseif(in_array(WPF()->tpl->slugs['subscriptions'], $wpf_url_parse)){
606 $current_object['template'] = 'subscriptions';
607 foreach($wpf_url_parse as $value){
608 if( $value == WPF()->tpl->slugs['subscriptions']) break;
609 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
610 }
611 }else{
612 $current_object['template'] = 'forum';
613 if( isset($wpf_url_parse[0]) ){
614 if( isset($wpf_url_parse[1]) ){
615 $current_object['topic_slug'] = $wpf_url_parse[0];
616 $current_object['forum_slug'] = $wpf_url_parse[1];
617 $current_object['template'] = 'post';
618 }else{
619 $current_object['forum_slug'] = $wpf_url_parse[0];
620 $current_object['template'] = 'topic';
621 }
622 }
623 }
624 }
625
626 if( in_array( $current_object['template'], array('profile', 'account', 'activity', 'subscriptions') )
627 && !isset($current_object['user_nicename']) && !isset($current_object['userid']) ){
628 $current_object = wpforo_find_current_user_data( $current_object );
629 }
630
631 if( isset($current_object['userid']) || isset($current_object['user_nicename']) ){
632 $args = array();
633 if(isset($current_object['userid'])) $args['userid'] = $current_object['userid'];
634 if(isset($current_object['user_nicename'])) $args['user_nicename'] = $current_object['user_nicename'];
635 $selected_user = $this->member->get_member($args);
636 if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('user_nicename' => $current_object['userid']));
637 if(!empty($selected_user)){
638 $current_object['user'] = $selected_user;
639 $current_object['userid'] = $selected_user['ID'];
640 $current_object['user_nicename'] = $selected_user['user_nicename'];
641 $current_object['user_is_same_current_user'] = !empty($this->current_userid) && $selected_user['ID'] == $this->current_userid;
642
643 switch($current_object['template']){
644 case 'activity':
645 $args = array(
646 'offset' => ($current_object['paged'] - 1) * $this->post->options['posts_per_page'],
647 'row_count' => $this->post->options['posts_per_page'],
648 'userid' => $current_object['userid'],
649 'orderby' => '`created` DESC, `postid` DESC',
650 'check_private' => true
651 );
652 $current_object['items_count'] = 0;
653 $current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']);
654 break;
655 case 'subscriptions':
656 $args = array(
657 'offset' => ($current_object['paged'] - 1) * $this->post->options['posts_per_page'],
658 'row_count' => $this->post->options['posts_per_page'],
659 'userid' => $current_object['userid'],
660 'order' => 'DESC'
661 );
662 $current_object['items_count'] = 0;
663 $current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']);
664 break;
665 }
666
667 }else{
668 $current_object['is_404'] = true;
669 $current_object['user'] = array();
670 $current_object['userid'] = 0;
671 $current_object['user_nicename'] = '';
672 }
673 }
674
675 if(isset($current_object['forum_slug']) && $current_object['forum_slug']){
676 $forum = $this->forum->get_forum( array('slug' => $current_object['forum_slug']) );
677 if(!empty($forum)){
678 $current_object['forum'] = $forum;
679 $current_object['forumid'] = $forum['forumid'];
680 $current_object['forum_desc'] = $forum['description'];
681 $current_object['forum_meta_key'] = $forum['meta_key'];
682 $current_object['forum_meta_desc'] = $forum['meta_desc'];
683 $current_object['og_text'] = $forum['title'];
684 }else{
685 $current_object['is_404'] = true;
686 $current_object['forum'] = array();
687 $current_object['forumid'] = 0;
688 $current_object['forum_desc'] = '';
689 $current_object['forum_meta_key'] = '';
690 $current_object['forum_meta_desc'] = '';
691 $current_object['og_text'] = '';
692 }
693 }
694
695 if(isset($current_object['topic_slug']) && $current_object['topic_slug']){
696 $topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug']));
697 if(!empty($topic)){
698 $current_object['topic'] = $topic;
699 $current_object['topicid'] = $topic['topicid'];
700 $current_object['og_text'] = ( wpfval($topic, 'title') ? $topic['title'] : '' );
701 }elseif( wpfkey($this->current_object, 'status') && $this->current_object['status'] == 'unapproved' && !is_user_logged_in() ){
702 wp_redirect( wpforo_login_url() );
703 exit();
704 }else{
705 $current_object['is_404'] = false;
706 $current_object['topic'] = array();
707 $current_object['topicid'] = 0;
708 }
709 }
710
711 $this->current_object = apply_filters('wpforo_after_init_current_object', $current_object, $wpf_url_parse);
712 }
713
714 public function is_installed(){
715 return (bool) get_option('wpforo_version');
716 }
717
718 public function deactivate(){
719 $response = array('code' => 0);
720 $json = filter_input(INPUT_POST, 'deactivateData');
721 if ($json) {
722 parse_str($json, $data);
723
724 $blogTitle = get_option('blogname');
725 $to = 'feedback@wpforo.com';
726 $subject = '[wpForo Feedback - ' . WPFORO_VERSION . ']';
727 $headers = array();
728 $contentType = 'text/html';
729 $fromName = apply_filters('wp_mail_from_name', $blogTitle);
730 $fromName = html_entity_decode($fromName, ENT_QUOTES);
731 $siteUrl = get_site_url();
732 $parsedUrl = parse_url($siteUrl);
733 $domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
734 $fromEmail = 'no-reply@' . $domain;
735 $headers[] = "Content-Type: $contentType; charset=UTF-8";
736 $headers[] = "From: " . $fromName . " <" . $fromEmail . "> \r\n";
737 $message = "Dismiss and never show again";
738
739 if(isset($data['never_show']) && ($v = intval($data['never_show']))){
740 update_option('wpforo_deactivation_dialog_never_show', $v);
741 $response['code'] = 'dismiss_and_deactivate';
742 }elseif(isset($data['deactivation_reason']) && ($reason = trim($data['deactivation_reason']))){
743 $subject .= ' - ' . $reason;
744 $message = "<strong>Deactivation reason:</strong> " . $reason . "\r\n" . "<br/>";
745 if (isset($data['deactivation_reason_desc']) && ($reasonDesc = trim($data['deactivation_reason_desc']))) {
746 $message .= "<strong>Deactivation reason description:</strong> " . $reasonDesc . "\r\n" . "<br/>";
747 }
748 if (isset($data['deactivation_feedback_email']) && ($feedback_email = trim($data['deactivation_feedback_email']))) {
749 $to = 'support@wpforo.com';
750 $message .= "<strong>Feedback Email:</strong> " . $feedback_email . "\r\n" . "<br/>";
751 }
752 $subject = html_entity_decode($subject, ENT_QUOTES);
753 $message = html_entity_decode($message, ENT_QUOTES);
754 $response['code'] = 'send_and_deactivate';
755 }
756
757 wp_mail($to, $subject, $message, $headers);
758 }
759 wp_die(json_encode($response));
760 }
761 }
762
763 /**
764 * Main instance of wpForo.
765 *
766 * Returns the main instance of WPF to prevent the need to use globals.
767 *
768 * @since 1.4.3
769 * @return wpForo
770 */
771 if ( !function_exists('WPF') ){
772 function WPF() {
773 return wpForo::instance();
774 }
775 }
776
777 // Global for backwards compatibility.
778 $GLOBALS['wpforo'] = WPF();
779
780 //ADDONS/////////////////////////////////////////////////////
781 WPF()->addons = array(
782 '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/'),
783 '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/'),
784 '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/'),
785 '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/'),
786 '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/'),
787 '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/'),
788 '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/'),
789 '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/'),
790 );
791 $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'));}
792 /////////////////////////////////////////////////////////////
793 }