PluginProbe
wpForo Forum / 1.6.2
wpForo Forum v1.6.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.6.2, at wpforo.php

969 lines 44.8 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.6.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.6.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 public $current_user_accesses = array();
60
61 public $use_trailing_slashes;
62 public $use_home_url;
63 public $excld_urls;
64 public $base_permastruct;
65 public $permastruct;
66 public $url;
67 public $pageid;
68
69 public $general_options;
70 public $features;
71 public $tools_antispam;
72 public $tools_cleanup;
73 public $tools_misc;
74 public $tools_legal;
75
76 public $cache;
77 public $phrase;
78 public $forum;
79 public $topic;
80 public $post;
81 public $usergroup;
82 public $member;
83 public $perm;
84 public $sbscrb;
85 public $tpl;
86 public $notice;
87 public $api;
88 public $log;
89 public $feed;
90 public $form;
91 public $moderation;
92 public $activity;
93 public $seo;
94 public $add;
95
96 public $member_tpls;
97
98 public static function instance(){
99 if ( is_null(self::$_instance) ) self::$_instance = new self();
100 return self::$_instance;
101 }
102
103 private function __construct(){
104 global $wpdb;
105 $this->db = $wpdb;
106 $this->file = __FILE__;
107 $this->error = NULL;
108 $this->locale = get_locale();
109 $this->basename = plugin_basename($this->file);
110
111 $this->init_db_tables();
112 $this->includes();
113 $this->init_defaults();
114 $this->init_options();
115 $this->setup();
116 $this->init_hooks();
117
118 $this->cache = new wpForoCache();
119 $this->phrase = new wpForoPhrase();
120 $this->forum = new wpForoForum();
121 $this->topic = new wpForoTopic();
122 $this->post = new wpForoPost();
123 $this->usergroup = new wpForoUsergroup();
124 $this->member = new wpForoMember();
125 $this->perm = new wpForoPermissions();
126 $this->sbscrb = new wpForoSubscribe();
127 $this->tpl = new wpForoTemplate();
128 $this->notice = new wpForoNotices();
129 $this->api = new wpForoAPI();
130 $this->log = new wpForoLogs();
131 $this->feed = new wpForoFeed();
132 $this->form = new wpForoForm();
133 $this->moderation = new wpForoModeration();
134 $this->activity = new wpForoActivity();
135 $this->seo = new wpForoSEO();
136 $this->add = new stdClass(); // Integrations
137 }
138
139 private function init_hooks(){
140 add_action('admin_init', array($this, 'admin_init'));
141 add_action('init', array($this, 'init'));
142 add_action('wp_loaded', 'wpforo_actions');
143 add_action('wp', array($this, 'init_shortcode_page'));
144 }
145
146 private function init_db_tables($blog_id = 0){
147 $this->db->query("SET SESSION group_concat_max_len = 1000000");
148 $blog_id = apply_filters('wpforo_current_blog_id', $blog_id);
149 $this->tables = new stdClass;
150 if(!$blog_id) $blog_id = $this->db->blogid;
151 $this->blog_prefix = $this->db->get_blog_prefix( $blog_id );
152 $this->_tables = apply_filters('wpforo_init_db_tables', $this->_tables);
153 foreach ( $this->_tables as $table )
154 $this->tables->$table = $this->blog_prefix . $this->prefix . $table;
155 }
156
157 private function includes(){
158 include( WPFORO_DIR . '/wpf-includes/wpf-hooks.php' );
159 include( WPFORO_DIR . '/wpf-includes/wpf-actions.php');
160 include( WPFORO_DIR . '/wpf-includes/functions.php' );
161 include( WPFORO_DIR . '/wpf-includes/functions-integration.php' );
162 include( WPFORO_DIR . '/wpf-includes/functions-template.php' );
163 if(wpforo_is_admin()) {
164 include( WPFORO_DIR . '/wpf-includes/functions-installation.php' );
165 include( WPFORO_DIR .'/wpf-admin/admin.php' );
166 }
167
168 include( WPFORO_DIR . '/wpf-includes/class-cache.php' );
169 include( WPFORO_DIR . '/wpf-includes/class-forums.php' );
170 include( WPFORO_DIR . '/wpf-includes/class-topics.php' );
171 include( WPFORO_DIR . '/wpf-includes/class-posts.php' );
172 include( WPFORO_DIR . '/wpf-includes/class-usergroups.php' );
173 include( WPFORO_DIR . '/wpf-includes/class-members.php' );
174 include( WPFORO_DIR . '/wpf-includes/class-permissions.php' );
175 include( WPFORO_DIR . '/wpf-includes/class-phrases.php');
176 include( WPFORO_DIR . '/wpf-includes/class-subscribes.php' );
177 include( WPFORO_DIR . '/wpf-includes/class-template.php' );
178 include( WPFORO_DIR . '/wpf-includes/class-notices.php' );
179 include( WPFORO_DIR . '/wpf-includes/class-logs.php' );
180 include( WPFORO_DIR . '/wpf-includes/class-api.php' );
181 include( WPFORO_DIR . '/wpf-includes/class-feed.php' );
182 include( WPFORO_DIR . '/wpf-includes/class-forms.php' );
183 include( WPFORO_DIR . '/wpf-includes/class-moderation.php' );
184 include( WPFORO_DIR . '/wpf-includes/class-activity.php' );
185 include( WPFORO_DIR . '/wpf-includes/class-seo.php' );
186 }
187
188 public function admin_init(){
189 if( wpforo_is_admin() ){
190
191 $this->check_database();
192
193 if( strpos( wpforo_get_request_uri(), 'user-new.php' ) === false ){
194 $sql = "SELECT `groupid` FROM ". $this->tables->profiles ." WHERE `userid` = " . wpforo_bigintval($this->current_userid);
195 if( !$current_groupid = $this->db->get_var($sql) ){
196 $this->member->synchronize_user($this->current_userid);
197 }
198 }
199
200 if( !$this->forum->manage() && wpforo_current_user_is('admin') ){
201 $this->member->set_usergroup($this->current_userid, 1);
202 }
203 }
204 }
205
206 public function check_database(){
207
208 //Make sure all users profiles are created
209 if( !wpforo_feature('user-synch') && get_option('wpforo_version') ){
210 $users = $this->db->get_var("SELECT COUNT(*) FROM `".$this->db->users."`");
211 $profiles = $this->db->get_var("SELECT COUNT(*) FROM `" . $this->tables->profiles."`");
212 $delta = $users - $profiles;
213 if( $users > 100 && $delta > 2 ){ add_action( 'admin_notices', 'wpforo_profile_notice', 10 ); }
214 }
215 //Make sure tables structures are correct for current version
216 $wpforo_version_db = get_option('wpforo_version_db');
217 if( !$wpforo_version_db || version_compare( $wpforo_version_db, WPFORO_VERSION, '<') ){
218 if( 'tables' != wpfval($_GET, 'view') ){
219 $db_note = false;
220 $problems = wpforo_database_check();
221 if( !empty($problems) ) {
222 foreach( $problems as $table_name => $problem ){
223 if( wpfval($problem, 'fields') ) $db_note = true;
224 if( wpfval($problem, 'exists') ) $db_note = true;
225 }
226 if( $db_note ) {
227 add_action( 'admin_notices', 'wpforo_database_notice', 10 );
228 }
229 } else {
230 update_option('wpforo_version_db', WPFORO_VERSION );
231 }
232 }
233 }
234 }
235
236 public function init(){
237 do_action( 'wpforo_before_init' );
238 $this->phrase->init();
239 $this->perm->init();
240 $this->member->init_current_user();
241
242 $this->init_current_object();
243 $this->moderation->init();
244 $this->tpl->init();
245 $this->api->hooks();
246 add_action('wp_ajax_wpforo_deactivate', array($this, 'deactivate'));
247 do_action( 'wpforo_after_init' );
248 }
249
250 public function init_shortcode_page(){
251 if(wpforo_is_admin()) return;
252
253 if( is_wpforo_shortcode_page() ){
254 $url = wpforo_home_url();
255
256 if( $atts = get_wpforo_shortcode_atts() ){
257 $args = shortcode_atts( array(
258 'item' => 'forum',
259 'id' => 0,
260 'slug' => '',
261 ), $atts );
262
263 if( $args['id'] || $args['slug'] ){
264 $getid = ( $args['slug'] ? $args['slug'] : $args['id'] );
265 if( $args['item'] == 'topic' ){
266 $url = $this->topic->get_topic_url($getid);
267 }elseif( $args['item'] == 'profile' ){
268 $url = $this->member->get_profile_url($getid);
269 }else{
270 $url = $this->forum->get_forum_url($getid);
271 }
272 }
273 }
274
275 $this->init_current_object($url);
276 $this->tpl->init_nav_menu();
277 }
278
279 }
280
281 private function init_defaults(){
282 date_default_timezone_set('UTC');
283
284 $this->default = new stdClass;
285
286 $this->default->use_home_url = 0;
287 $this->default->excld_urls = '';
288 $this->default->permastruct = 'community';
289
290 $blogname = get_option('blogname', '');
291 $this->default->general_options = array(
292 'title' => $blogname . ' ' . __('Forum', 'wpforo'),
293 'description' => $blogname . ' ' . __('Discussion Board', 'wpforo'),
294 'lang' => 1
295 );
296
297 $this->default->features = array(
298 'user-admin-bar' => 0,
299 'page-title' => 1,
300 'top-bar' => 1,
301 'top-bar-search' => 1,
302 'breadcrumb' => 1,
303 'footer-stat' => 1,
304 'mention-nicknames' => 1,
305 'content-do_shortcode' => 0,
306 'view-logging' => 1,
307 'track-logging' => 1,
308 'author-link' => 0,
309 'comment-author-link' => 0,
310 'user-register' => 1,
311 'user-register-email-confirm' => 1,
312 'register-url' => 0,
313 'login-url' => 0,
314 'resetpass-url' => 1, //In most cases incompatible with security and antispam plugins
315 'replace-avatar' => 1,
316 'avatars' => 1,
317 'custom-avatars' => 1,
318 'signature' => 1,
319 'rating' => 1,
320 'rating_title' => 1,
321 'member_cashe' => 1,
322 'object_cashe' => 1,
323 'html_cashe' => 0,
324 'memory_cashe' => 1,
325 'seo-title' => 1,
326 'seo-meta' => 1,
327 'seo-profile' => 1,
328 'rss-feed' => 1,
329 'font-awesome' => 1,
330 'bp_profile' => 0,
331 'bp_activity' => 1,
332 'bp_notification' => 1,
333 'bp_forum_tab' => 1,
334 'um_profile' => 0,
335 'um_forum_tab' => 1,
336 'um_notification' => 1,
337 'user-synch' => 0,
338 'role-synch' => 1,
339 'output-buffer' => 1,
340 'wp-date-format' => 0,
341 'subscribe_conf' => 1,
342 'subscribe_checkbox_on_post_editor' => 1,
343 'subscribe_checkbox_default_status' => 0,
344 'attach-media-lib' => 1,
345 'debug-mode' => 0,
346 'copyright' => 1
347 );
348
349 $this->default->tools_antispam = array(
350 'spam_filter' => 1,
351 'spam_filter_level_topic' => mt_rand(30, 60),
352 'spam_filter_level_post' => mt_rand(30, 60),
353 'spam_user_ban' => 0,
354 'new_user_max_posts' => 5,
355 'unapprove_post_if_user_is_new' => 0,
356 'spam_user_ban_notification' => 1,
357 'min_number_post_to_attach' => 3,
358 'min_number_post_to_link' => 0,
359 'spam_file_scanner' => 1,
360 'limited_file_ext' => 'pdf|doc|docx|txt|htm|html|rtf|xml|xls|xlsx|zip|rar|tar|gz|bzip|7z',
361 'exclude_file_ext' => 'pdf|doc|docx|txt',
362 'rc_site_key' => '',
363 'rc_secret_key' => '',
364 'rc_theme' => 'light',
365 'rc_login_form' => 0,
366 'rc_reg_form' => 0,
367 'rc_lostpass_form' => 0,
368 'rc_wpf_login_form' => 1,
369 'rc_wpf_reg_form' => 1,
370 'rc_wpf_lostpass_form' => 1,
371 'rc_topic_editor' => 1,
372 'rc_post_editor' => 1,
373 'html' => 'embed(src width height name pluginspage type wmode allowFullScreen allowScriptAccess flashVars),',
374 );
375
376 $this->default->tools_cleanup = array(
377 'user_reg_days_ago' => 7,
378 'auto_cleanup_users' => 0,
379 'usergroup' => array ( 1 => '0', 5 => '0', 2 => '1', 3 => '0' )
380 );
381
382 $this->default->tools_misc = array(
383 'dofollow' => '',
384 'noindex' => '',
385 'admin_note' => '',
386 'admin_note_groups' => array( 1, 2, 3, 4, 5 ),
387 'admin_note_pages' => array('forum')
388 );
389
390 $this->default->tools_legal = array(
391 'rules_checkbox' => 0,
392 'rules_text' => NULL,
393 'page_terms' => '',
394 'page_privacy' => '',
395 'forum_privacy_text' => NULL,
396 'checkbox_terms_privacy' => 0,
397 'checkbox_email_password' => 1,
398 'checkbox_forum_privacy' => 0,
399 'checkbox_fb_login' => 1,
400 'contact_page_url' => NULL,
401 'cookies' => 1
402 );
403
404 $this->default->stats = array(
405 'forums' => 0,
406 'topics' => 0,
407 'posts' => 0,
408 'members' => 0,
409 'online_members_count' => 0,
410 'last_post_title' => '',
411 'last_post_url' => '',
412 'newest_member_dname' => '',
413 'newest_member_profile_url' => ''
414 );
415 }
416
417 private function init_options(){
418 $permalink_structure = get_option('permalink_structure');
419
420 $this->use_trailing_slashes = ( '/' == substr($permalink_structure, -1, 1) );
421
422 //OPTIONS
423 $this->use_home_url = get_wpf_option('wpforo_use_home_url', $this->default->use_home_url);
424 $this->excld_urls = get_wpf_option('wpforo_excld_urls', $this->default->excld_urls);
425
426 $this->permastruct = trim( get_wpf_option('wpforo_permastruct', $this->default->permastruct), '/' );
427 $this->permastruct = preg_replace('#^/?index\.php/?#isu', '', $this->permastruct);
428 $this->permastruct = trim($this->permastruct, '/');
429
430 $this->base_permastruct = (!$this->use_home_url ? $this->permastruct : '');
431 $this->base_permastruct = rtrim( ( strpos($permalink_structure, 'index.php') !== FALSE ? '/index.php/' . $this->base_permastruct : '/' . $this->base_permastruct ), '/\\' );
432 $this->url = esc_url( home_url( $this->user_trailingslashit($this->base_permastruct) ) );
433 $this->pageid = get_wpf_option( 'wpforo_pageid');
434
435 $this->general_options = get_wpf_option( 'wpforo_general_options', $this->default->general_options);
436 $this->features = get_wpf_option('wpforo_features', $this->default->features);
437 $this->tools_antispam = get_wpf_option('wpforo_tools_antispam', $this->default->tools_antispam);
438 $this->tools_cleanup = get_wpf_option('wpforo_tools_cleanup', $this->default->tools_cleanup);
439 $this->tools_misc = get_wpf_option('wpforo_tools_misc', $this->default->tools_misc);
440 $this->tools_legal = get_wpf_option('wpforo_tools_legal', $this->default->tools_legal);
441
442 //CONSTANTS
443 define('WPFORO_BASE_PERMASTRUCT', $this->base_permastruct );
444 define('WPFORO_BASE_URL', $this->url );
445 }
446
447 private function setup(){
448 if( wpforo_is_admin() ){
449 register_activation_hook($this->basename, 'do_wpforo_activation');
450 register_deactivation_hook($this->basename, 'do_wpforo_deactivation');
451 }
452 }
453
454 public function user_trailingslashit($url) {
455 $rtrimed_url = '';
456 $url_append_vars = '';
457 if( preg_match('#^(.+?)(/?[\?\&].*)?$#isu', $url, $match) ){
458 if( wpfval($match, 1) ) $rtrimed_url = rtrim($match[1], '/\\');
459 if( wpfval($match, 2) ) $url_append_vars = '?' . trim($match[2], '?&/\\');
460 if( $rtrimed_url ) {
461 $home_url = rtrim( preg_replace('#/?\?.*$#isu', '', home_url()), '/\\' );
462 if( $rtrimed_url == $home_url ){
463 $url = $rtrimed_url . '/';
464 }else{
465 $url = ( $this->use_trailing_slashes ? $rtrimed_url . '/' : $rtrimed_url );
466 }
467 }
468 }
469 return $url . $url_append_vars;
470 }
471
472 public function strip_url_paged_var($url){
473 $patterns = array(
474 '#/'. preg_quote( $this->tpl->slugs['paged'] ) .'/?\d*/?#isu',
475 '#[\&\?]wpfpaged=\d*#isu'
476 );
477 $url = preg_replace($patterns, '', $url);
478 $url = $this->user_trailingslashit($url);
479 return $url;
480 }
481
482 public function statistic( $mode = 'get', $template = 'all' ){
483
484 if( $mode == 'get' ){
485 if( $cached_stat = get_option('wpforo_stat' ) ){
486 $cached_stat['online_members_count'] = $this->member->online_members_count();
487 if( wpfval($cached_stat, 'forums') && wpfval($cached_stat, 'topics') && wpfval($cached_stat, 'posts') ){
488 return $cached_stat;
489 }
490 }
491 }
492
493 if( $mode == 'get' || $template == 'all' ) {
494 $stats['forums'] = $this->forum->get_count( array('is_cat' => 0) );
495 $stats['topics'] = $this->topic->get_count();
496 $stats['posts'] = $this->post->get_count();
497 $stats['members'] = $this->member->get_count();
498 $stats['online_members_count'] = $this->member->online_members_count();
499 $row_count = apply_filters('wpforo_get_statistic_row_count', 20);
500
501 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => $row_count, 'private' => 0, 'status' => 0, 'permgroup' => 4 ));
502 $first = key($posts);
503 if ( isset($posts[$first]) && !empty($posts[$first]) && $this->perm->forum_can('vf', $posts[$first]['forumid'], 4) ) {
504 $stats['last_post_title'] = $posts[$first]['title'];
505 $stats['last_post_url'] = $this->post->get_post_url($posts[$first]['last_post']);
506 }
507
508 $members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1));
509 if (isset($members[0]) && !empty($members[0])) {
510 $stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']);
511 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
512 }
513 }else{
514 $stats = get_wpf_option('wpforo_stat', $this->default->stats);
515 switch ($template){
516 case 'forum':
517 $stats['forums'] = $this->forum->get_count( array('is_cat' => 0) );
518 break;
519 case 'topic':
520 $stats['topics'] = $this->topic->get_count();
521 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1));
522 if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) {
523 $stats['last_post_title'] = $posts[0]['title'];
524 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
525 }
526 break;
527 case 'post':
528 $stats['posts'] = $this->post->get_count();
529 $posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1));
530 if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) {
531 $stats['last_post_title'] = $posts[0]['title'];
532 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
533 }
534 break;
535 case 'user':
536 $stats['members'] = $this->member->get_count();
537 $stats['online_members_count'] = $this->member->online_members_count();
538
539 $members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1));
540 if (isset($members[0]) && !empty($members[0])) {
541 $stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']);
542 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
543 }
544 break;
545 }
546 }
547
548 $stats = array_merge($this->default->stats, $stats);
549 $stats = apply_filters('wpforo_get_statistic_array_filter', $stats);
550 update_option( 'wpforo_stat', $stats );
551 return $stats;
552 }
553
554 public function init_current_object($url = ''){
555 $this->current_object = array(
556 'template' => '',
557 'layout' => 1,
558 'og_text' => '',
559 'paged' => 1,
560 'items_count' => 0,
561 'items_per_page' => $this->post->get_option_items_per_page(),
562 'is_404' => false,
563 'user_is_same_current_user' => false,
564 'orderby' => null,
565 'members' => array(),
566 'categories' => array(),
567 'topics' => array(),
568 'posts' => array(),
569 'user' => array(),
570 'userid' => 0,
571 'user_nicename' => '',
572 'forum' => array(),
573 'forumid' => 0,
574 'forum_slug' => '',
575 'forum_desc' => '',
576 'forum_meta_key' => '',
577 'forum_meta_desc' => '',
578 'topic' => array(),
579 'topicid' => 0,
580 'topic_slug' => '',
581 'tags' => array()
582 );
583
584 if(!$url) $url = wpforo_get_request_uri();
585 $url = wpforo_fix_url($url);
586 $url = preg_replace('#\#[^\/\?\&]*$#isu', '', $url);
587 parse_str( parse_url($url, PHP_URL_QUERY), $get );
588
589 if( !is_wpforo_page($url) ) return;
590
591 $this->current_url = $url;
592 $current_url = wpforo_get_url_query_vars_str($url);
593
594 if( $this->use_home_url ) $this->permastruct = '';
595
596 $current_object = array();
597 if(isset($get['wpfs'])) $current_object['template'] = 'search';
598 if( isset($get['wpforo']) ){
599 switch($get['wpforo']){
600 case 'signup':
601 if(!is_user_logged_in()) $current_object['template'] = 'register';
602 break;
603 case 'signin':
604 if(!is_user_logged_in()) $current_object['template'] = 'login';
605 break;
606 case 'lostpassword':
607 if(!is_user_logged_in()) $current_object['template'] = 'lostpassword';
608 break;
609 case 'resetpassword':
610 $current_object['template'] = 'resetpassword';
611 break;
612 case 'page':
613 $current_object['template'] = 'page';
614 break;
615 case 'logout':
616 wp_logout();
617 wp_redirect( wpforo_home_url( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) ) );
618 exit();
619 break;
620 }
621 }
622
623 $wpf_url = preg_replace( '#^/?'.preg_quote($this->permastruct).'#isu', '' , $current_url, 1 );
624 $wpf_url = preg_replace('#/?\?.*$#isu', '', $wpf_url);
625 $wpf_url_parse = array_filter( explode('/', trim($wpf_url, '/')) );
626 $wpf_url_parse = array_reverse($wpf_url_parse);
627
628 if(in_array($this->tpl->slugs['paged'], $wpf_url_parse)){
629 foreach($wpf_url_parse as $key => $value){
630 if( $value == $this->tpl->slugs['paged']){
631 unset($wpf_url_parse[$key]);
632 break;
633 }
634 if(is_numeric($value)) $paged = intval($value);
635
636 unset($wpf_url_parse[$key]);
637 }
638 }
639 if( $_paged = intval( wpfval($get, 'wpfpaged') ) ) $paged = $_paged;
640 $current_object['paged'] = (isset($paged) && $paged > 0) ? $paged : 1;
641 $current_object['orderby'] = wpfval($get, 'orderby');
642
643 $wpf_url_parse = array_values($wpf_url_parse);
644
645 if( !isset($current_object['template']) || !$current_object['template'] )
646 $current_object = apply_filters('wpforo_before_init_current_object', $current_object, $wpf_url_parse);
647
648 if( !isset($current_object['template']) || !$current_object['template'] ) {
649 if(in_array($this->tpl->slugs['members'], $wpf_url_parse) && $wpf_url_parse[0] == $this->tpl->slugs['members']){
650 $current_object['template'] = 'members';
651 $current_object['items_per_page'] = $this->member->options['members_per_page'];
652
653 if( !empty($_GET['_wpfms']) ){
654 $users_include = array();
655 $search_fields_names = $this->member->get_search_fields_names(false);
656
657 $wpfms = (isset($_GET['wpfms'])) ? sanitize_text_field($_GET['wpfms']) : '';
658 if($wpfms){
659 $users_include = $this->member->search($wpfms, $search_fields_names);
660 }else{
661 if( $filters = array_filter($_GET) ){
662 $args = array();
663 foreach ($filters as $filter_key => $filter){
664 if( in_array($filter_key, (array) $search_fields_names) && !is_array($filter) ){
665 $args[$filter_key] = $filter;
666 }
667 }
668 $users_include = $this->member->filter($args);
669 }
670 }
671
672 $users_include = apply_filters('wpforo_member_search_users_include', $users_include);
673 }
674 $args = array(
675 'offset' => ($current_object['paged'] - 1) * $current_object['items_per_page'],
676 'row_count' => $current_object['items_per_page'],
677 'orderby' => 'posts',
678 'order' => 'DESC',
679 'groupids' => $this->usergroup->get_visible_usergroup_ids()
680 );
681 if(!empty($users_include)) $args['include'] = $users_include;
682 $current_object['members'] = $this->member->get_members($args, $current_object['items_count']);
683 if(isset($users_include) && empty($users_include)){ $current_object['members'] = array(); $current_object['items_count'] = 0; }
684
685 }elseif(in_array($this->tpl->slugs['recent'], $wpf_url_parse) && $wpf_url_parse[0] == $this->tpl->slugs['recent']){
686 $current_object['template'] = 'recent';
687 $current_object['items_per_page'] = $this->post->options['topics_per_page'];
688 }elseif(in_array($this->tpl->slugs['tags'], $wpf_url_parse) && $wpf_url_parse[0] == $this->tpl->slugs['tags']){
689 $current_object['template'] = 'tags';
690 $current_object['items_per_page'] = $this->post->options['tags_per_page'];
691
692 $args = array(
693 'offset' => ($current_object['paged'] - 1) * $current_object['items_per_page'],
694 'row_count' => $current_object['items_per_page']
695 );
696 $current_object['tags'] = $this->topic->get_tags($args, $current_object['items_count']);
697 }elseif(in_array($this->tpl->slugs['profile'], $wpf_url_parse)){
698 $current_object['template'] = 'profile';
699 foreach($wpf_url_parse as $value){
700 if( $value == $this->tpl->slugs['profile']) break;
701 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
702 }
703 }elseif(in_array($this->tpl->slugs['account'], $wpf_url_parse)){
704 $current_object['template'] = 'account';
705 foreach($wpf_url_parse as $value){
706 if( $value == $this->tpl->slugs['account']) break;
707 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
708 }
709 }elseif(in_array($this->tpl->slugs['activity'], $wpf_url_parse)){
710 $current_object['template'] = 'activity';
711 foreach($wpf_url_parse as $value){
712 if( $value == $this->tpl->slugs['activity']) break;
713 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
714 }
715 }elseif(in_array($this->tpl->slugs['subscriptions'], $wpf_url_parse)){
716 $current_object['template'] = 'subscriptions';
717 foreach($wpf_url_parse as $value){
718 if( $value == $this->tpl->slugs['subscriptions']) break;
719 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value;
720 }
721 }else{
722 $current_object['template'] = 'forum';
723 if( isset($wpf_url_parse[0]) ){
724 if( isset($wpf_url_parse[1]) ){
725 $current_object['topic_slug'] = $wpf_url_parse[0];
726 $current_object['forum_slug'] = $wpf_url_parse[1];
727 $current_object['template'] = 'post';
728 }else{
729 $current_object['forum_slug'] = $wpf_url_parse[0];
730 $current_object['template'] = 'topic';
731 }
732 }
733 }
734 }
735
736 if( in_array( $current_object['template'], array('profile', 'account', 'activity', 'subscriptions') )
737 && !isset($current_object['user_nicename']) && !isset($current_object['userid']) ){
738 $current_object['userid'] = $this->current_userid;
739 }
740
741 if( isset($current_object['userid']) || isset($current_object['user_nicename']) ){
742 $args = array();
743 if(isset($current_object['userid'])) $args['userid'] = $current_object['userid'];
744 if(isset($current_object['user_nicename'])) $args['user_nicename'] = $current_object['user_nicename'];
745 $selected_user = $this->member->get_member($args);
746 if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('user_nicename' => $current_object['userid']));
747 if(!empty($selected_user)){
748 $current_object['user'] = $selected_user;
749 $current_object['userid'] = $selected_user['ID'];
750 $current_object['user_nicename'] = $selected_user['user_nicename'];
751 $current_object['user_is_same_current_user'] = !empty($this->current_userid) && $selected_user['ID'] == $this->current_userid;
752
753 switch($current_object['template']){
754 case 'activity':
755 $args = array(
756 'offset' => ($current_object['paged'] - 1) * $this->current_object['items_per_page'],
757 'row_count' => $this->current_object['items_per_page'],
758 'userid' => $current_object['userid'],
759 'orderby' => '`created` DESC, `postid` DESC',
760 'check_private' => true
761 );
762 $current_object['items_count'] = 0;
763 $current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']);
764 break;
765 case 'subscriptions':
766 $args = array(
767 'offset' => ($current_object['paged'] - 1) * $this->current_object['items_per_page'],
768 'row_count' => $this->current_object['items_per_page'],
769 'userid' => $current_object['userid'],
770 'order' => 'DESC'
771 );
772 $current_object['items_count'] = 0;
773 $current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']);
774 break;
775 }
776
777 }else{
778 $current_object['is_404'] = true;
779 }
780 }
781
782 if(isset($current_object['topic_slug']) && $current_object['topic_slug']){
783 $topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug']), false);
784 if(!empty($topic)){
785
786 $topic_forumid = intval( wpfval($topic, 'forumid') );
787 $is_owner = wpforo_is_owner($topic['userid'], $topic['email']);
788
789 if( $topic_forumid && (
790 !WPF()->perm->forum_can('vf', $topic_forumid) ||
791 ( !$is_owner && !WPF()->perm->forum_can('vt', $topic_forumid) ) ||
792 ( wpfval($topic, 'private') && !$is_owner && !WPF()->perm->forum_can('vp', $topic_forumid) ) ||
793 ( wpfval($topic, 'status') && !$is_owner && !WPF()->perm->forum_can('au', $topic_forumid) )
794 ) ){
795 if( is_user_logged_in() ){
796 $current_object['is_404'] = true;
797 }else{
798 wp_redirect( wpforo_login_url() );
799 exit();
800 }
801 }else{
802 $current_object['topic'] = $topic;
803 $current_object['topicid'] = $topic['topicid'];
804 $current_object['og_text'] = (string) wpfval($topic, 'title');
805 }
806
807 }else{
808 $current_object['is_404'] = true;
809 }
810 }
811
812 if(isset($current_object['forum_slug']) && $current_object['forum_slug']){
813 $args = ( empty($topic) ? array('slug' => $current_object['forum_slug']) : $topic['forumid'] );
814 if( $forum = $this->forum->get_forum( $args ) ){
815 if( $forum['is_cat'] ) $current_object['template'] = 'forum';
816 $current_object['forum'] = $forum;
817 $current_object['forumid'] = $forum['forumid'];
818 $current_object['forum_desc'] = $forum['description'];
819 $current_object['forum_meta_key'] = $forum['meta_key'];
820 $current_object['forum_meta_desc'] = $forum['meta_desc'];
821 $current_object['og_text'] = $forum['title'];
822 $current_object['layout'] = $this->forum->get_layout( $forum );
823
824 if( $current_object['template'] == 'topic' ){
825 $current_object['items_per_page'] = $this->post->options['topics_per_page'];
826 $args = array(
827 'offset' => ($current_object['paged'] - 1) * $current_object['items_per_page'],
828 'row_count' => $current_object['items_per_page'],
829 'forumid' => $current_object['forumid'],
830 'orderby' => 'type, modified',
831 'order' => 'DESC'
832 );
833 $current_object['topics'] = $this->topic->get_topics( $args, $current_object['items_count'] );
834 }
835 }else{
836 $current_object['is_404'] = true;
837 }
838 }
839
840 if( in_array($current_object['template'], array('forum', 'topic')) ){
841 if( !empty($forum) ){
842 $current_object['categories'] = array( $forum );
843 }else{
844 $current_object['categories'] = $this->forum->get_forums( array( "type" => 'category' ) );
845 }
846 }
847
848 if ( $current_object['template'] == 'post' && ! empty( $forum ) && ! empty( $topic ) ) {
849 $current_object['items_per_page'] = $this->post->get_option_items_per_page($current_object['layout']);
850
851 $args = array(
852 'forumid' => $forum['forumid'],
853 'topicid' => $topic['topicid'],
854 'offset' => ( $current_object['paged'] - 1 ) * $current_object['items_per_page'],
855 'row_count' => $current_object['items_per_page']
856 );
857 if( $current_object['layout'] == 4 ){
858 $args['parentid'] = 0;
859 }elseif( $current_object['layout'] == 3 ){
860 $args['parentid'] = 0;
861 switch ( $current_object['orderby'] ) {
862 case 'oldest':
863 $args['orderby'] = '`is_first_post` DESC, `is_answer` DESC, `created` ASC, `postid` ASC';
864 break;
865 case 'newest':
866 $args['orderby'] = '`is_first_post` DESC, `is_answer` DESC, `modified` DESC, `postid` DESC';
867 break;
868 default:
869 $args['orderby'] = '`is_first_post` DESC, `is_answer` DESC, `votes` DESC, `created` ASC, `postid` ASC';
870 break;
871 }
872 }
873 if( $this->post->get_option_union_first_post($current_object['layout']) ) $args['union_first_post'] = true;
874 $current_object['posts'] = $this->post->get_posts( $args, $current_object['items_count']);
875 }
876
877 $this->current_object = wpforo_parse_args($current_object, $this->current_object);
878
879 $this->current_object = apply_filters('wpforo_after_init_current_object', $this->current_object, $wpf_url_parse);
880
881 if( $this->current_object['items_count']
882 && $this->current_object['paged'] > 1
883 && (($this->current_object['paged'] - 1) * $this->current_object['items_per_page']) >= $this->current_object['items_count']
884 ){
885 wp_redirect( $this->strip_url_paged_var( $this->current_url ) );
886 exit();
887 }
888 }
889
890 public function is_installed(){
891 return (bool) get_option('wpforo_version');
892 }
893
894 public function deactivate(){
895 $response = array('code' => 0);
896 $json = filter_input(INPUT_POST, 'deactivateData');
897 if ($json) {
898 parse_str($json, $data);
899
900 $blogTitle = get_option('blogname');
901 $to = 'feedback@wpforo.com';
902 $subject = '[wpForo Feedback - ' . WPFORO_VERSION . ']';
903 $headers = array();
904 $contentType = 'text/html';
905 $fromName = apply_filters('wp_mail_from_name', $blogTitle);
906 $fromName = html_entity_decode($fromName, ENT_QUOTES);
907 $siteUrl = get_site_url();
908 $parsedUrl = parse_url($siteUrl);
909 $domain = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
910 $fromEmail = 'no-reply@' . $domain;
911 $headers[] = "Content-Type: $contentType; charset=UTF-8";
912 $headers[] = "From: " . $fromName . " <" . $fromEmail . "> \r\n";
913 $message = "Dismiss and never show again";
914
915 if(isset($data['never_show']) && ($v = intval($data['never_show']))){
916 update_option('wpforo_deactivation_dialog_never_show', $v);
917 $response['code'] = 'dismiss_and_deactivate';
918 }elseif(isset($data['deactivation_reason']) && ($reason = trim($data['deactivation_reason']))){
919 $subject .= ' - ' . $reason;
920 $message = "<strong>Deactivation reason:</strong> " . $reason . "\r\n" . "<br/>";
921 if (isset($data['deactivation_reason_desc']) && ($reasonDesc = trim($data['deactivation_reason_desc']))) {
922 $message .= "<strong>Deactivation reason description:</strong> " . $reasonDesc . "\r\n" . "<br/>";
923 }
924 if (isset($data['deactivation_feedback_email']) && ($feedback_email = trim($data['deactivation_feedback_email']))) {
925 $to = 'support@wpforo.com';
926 $message .= "<strong>Feedback Email:</strong> " . $feedback_email . "\r\n" . "<br/>";
927 }
928 $subject = html_entity_decode($subject, ENT_QUOTES);
929 $message = html_entity_decode($message, ENT_QUOTES);
930 $response['code'] = 'send_and_deactivate';
931 }
932
933 wp_mail($to, $subject, $message, $headers);
934 }
935 wp_die(json_encode($response));
936 }
937 }
938
939 /**
940 * Main instance of wpForo.
941 *
942 * Returns the main instance of WPF to prevent the need to use globals.
943 *
944 * @since 1.4.3
945 * @return wpForo
946 */
947 if ( !function_exists('WPF') ){
948 function WPF() {
949 return wpForo::instance();
950 }
951 }
952
953 // Global for backwards compatibility.
954 $GLOBALS['wpforo'] = WPF();
955
956 //ADDONS/////////////////////////////////////////////////////
957 WPF()->addons = array(
958 '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/'),
959 '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/'),
960 '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/'),
961 '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/'),
962 '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/'),
963 '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/'),
964 '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/'),
965 '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/'),
966 );
967 $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'));}
968 /////////////////////////////////////////////////////////////
969 }