PluginProbe
wpForo Forum / 1.6.0
wpForo Forum v1.6.0
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.0, at wpforo.php

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