PluginProbe
wpForo Forum / 1.6.3
wpForo Forum v1.6.3
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.3, at wpforo.php

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