| 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.4.13 |
| 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.4.13'); |
| 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', 'forums', 'languages', 'likes', 'phrases', 'posts', 'profiles', |
| 39 |
'subscribes', 'topics', '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 $form = array(); |
| 47 |
public $default; |
| 48 |
|
| 49 |
public $current_user = array(); |
| 50 |
public $current_user_groupid = 4; |
| 51 |
public $current_userid = 0; |
| 52 |
public $current_username = ''; |
| 53 |
public $current_user_email = ''; |
| 54 |
public $current_user_display_name = ''; |
| 55 |
public $current_user_status = ''; |
| 56 |
|
| 57 |
public $use_trailing_slashes; |
| 58 |
public $use_home_url; |
| 59 |
public $excld_urls; |
| 60 |
public $base_permastruct; |
| 61 |
public $permastruct; |
| 62 |
public $url; |
| 63 |
public $pageid; |
| 64 |
|
| 65 |
public $general_options; |
| 66 |
public $features; |
| 67 |
public $tools_antispam; |
| 68 |
public $tools_cleanup; |
| 69 |
public $tools_misc; |
| 70 |
public $tools_legal; |
| 71 |
|
| 72 |
public $cache; |
| 73 |
public $phrase; |
| 74 |
public $forum; |
| 75 |
public $topic; |
| 76 |
public $post; |
| 77 |
public $usergroup; |
| 78 |
public $member; |
| 79 |
public $perm; |
| 80 |
public $sbscrb; |
| 81 |
public $tpl; |
| 82 |
public $notice; |
| 83 |
public $api; |
| 84 |
public $feed; |
| 85 |
public $moderation; |
| 86 |
public $add; |
| 87 |
|
| 88 |
public $member_tpls; |
| 89 |
|
| 90 |
public static function instance(){ |
| 91 |
if ( is_null(self::$_instance) ) self::$_instance = new self(); |
| 92 |
return self::$_instance; |
| 93 |
} |
| 94 |
|
| 95 |
private function __construct(){ |
| 96 |
global $wpdb; |
| 97 |
$this->db = $wpdb; |
| 98 |
$this->file = __FILE__; |
| 99 |
$this->error = NULL; |
| 100 |
$this->locale = get_locale(); |
| 101 |
$this->basename = plugin_basename($this->file); |
| 102 |
|
| 103 |
$this->init_db_tables(); |
| 104 |
$this->includes(); |
| 105 |
$this->init_defaults(); |
| 106 |
$this->init_options(); |
| 107 |
$this->setup(); |
| 108 |
$this->init_hooks(); |
| 109 |
|
| 110 |
$this->cache = new wpForoCache(); |
| 111 |
$this->phrase = new wpForoPhrase(); |
| 112 |
$this->forum = new wpForoForum(); |
| 113 |
$this->topic = new wpForoTopic(); |
| 114 |
$this->post = new wpForoPost(); |
| 115 |
$this->usergroup = new wpForoUsergroup(); |
| 116 |
$this->member = new wpForoMember(); |
| 117 |
$this->perm = new wpForoPermissions(); |
| 118 |
$this->sbscrb = new wpForoSubscribe(); |
| 119 |
$this->tpl = new wpForoTemplate(); |
| 120 |
$this->notice = new wpForoNotices(); |
| 121 |
$this->api = new wpForoAPI(); |
| 122 |
$this->feed = new wpForoFeed(); |
| 123 |
$this->moderation = new wpForoModeration(); |
| 124 |
$this->add = new stdClass(); // Integrations |
| 125 |
} |
| 126 |
|
| 127 |
private function init_hooks(){ |
| 128 |
add_action('admin_init', array($this, 'admin_init')); |
| 129 |
add_action('init', array($this, 'init')); |
| 130 |
add_action('wp_loaded', 'wpforo_actions'); |
| 131 |
add_action('wp', array($this, 'init_shortcode_page')); |
| 132 |
} |
| 133 |
|
| 134 |
private function init_db_tables($blog_id = 0){ |
| 135 |
$blog_id = apply_filters('wpforo_current_blog_id', $blog_id); |
| 136 |
$this->tables = new stdClass; |
| 137 |
if(!$blog_id) $blog_id = $this->db->blogid; |
| 138 |
$this->blog_prefix = $this->db->get_blog_prefix( $blog_id ); |
| 139 |
$this->_tables = apply_filters('wpforo_init_db_tables', $this->_tables); |
| 140 |
foreach ( $this->_tables as $table ) |
| 141 |
$this->tables->$table = $this->blog_prefix . $this->prefix . $table; |
| 142 |
} |
| 143 |
|
| 144 |
private function includes(){ |
| 145 |
include( WPFORO_DIR . '/wpf-includes/wpf-hooks.php' ); |
| 146 |
include( WPFORO_DIR . '/wpf-includes/wpf-actions.php'); |
| 147 |
include( WPFORO_DIR . '/wpf-includes/functions.php' ); |
| 148 |
include( WPFORO_DIR . '/wpf-includes/functions-integration.php' ); |
| 149 |
include( WPFORO_DIR . '/wpf-includes/functions-template.php' ); |
| 150 |
if(wpforo_is_admin()) { |
| 151 |
include( WPFORO_DIR . '/wpf-includes/functions-installation.php' ); |
| 152 |
include( WPFORO_DIR .'/wpf-admin/admin.php' ); |
| 153 |
} |
| 154 |
|
| 155 |
include( WPFORO_DIR . '/wpf-includes/class-cache.php' ); |
| 156 |
include( WPFORO_DIR . '/wpf-includes/class-forums.php' ); |
| 157 |
include( WPFORO_DIR . '/wpf-includes/class-topics.php' ); |
| 158 |
include( WPFORO_DIR . '/wpf-includes/class-posts.php' ); |
| 159 |
include( WPFORO_DIR . '/wpf-includes/class-usergroups.php' ); |
| 160 |
include( WPFORO_DIR . '/wpf-includes/class-members.php' ); |
| 161 |
include( WPFORO_DIR . '/wpf-includes/class-permissions.php' ); |
| 162 |
include( WPFORO_DIR . '/wpf-includes/class-phrases.php'); |
| 163 |
include( WPFORO_DIR . '/wpf-includes/class-subscribes.php' ); |
| 164 |
include( WPFORO_DIR . '/wpf-includes/class-template.php' ); |
| 165 |
include( WPFORO_DIR . '/wpf-includes/class-notices.php' ); |
| 166 |
include( WPFORO_DIR . '/wpf-includes/class-api.php' ); |
| 167 |
include( WPFORO_DIR . '/wpf-includes/class-feed.php' ); |
| 168 |
include( WPFORO_DIR . '/wpf-includes/class-moderation.php' ); |
| 169 |
} |
| 170 |
|
| 171 |
public function admin_init(){ |
| 172 |
if( wpforo_is_admin() ){ |
| 173 |
if( !wpforo_feature('user-synch') && get_option('wpforo_version') ){ |
| 174 |
$users = $this->db->get_var("SELECT COUNT(*) FROM `".$this->db->users."`"); |
| 175 |
$profiles = $this->db->get_var("SELECT COUNT(*) FROM `" . $this->tables->profiles."`"); |
| 176 |
$delta = $users - $profiles; |
| 177 |
if( $users > 100 && $delta > 2 ){ add_action( 'admin_notices', 'wpforo_profile_notice' ); } |
| 178 |
} |
| 179 |
$db_version = get_option('wpforo_version_db'); |
| 180 |
if( !$db_version || version_compare( $db_version, WPFORO_VERSION, '<') ){ |
| 181 |
add_action( 'admin_notices', 'wpforo_update_db_notice' ); |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
public function init(){ |
| 187 |
$this->phrase->init(); |
| 188 |
$this->member->init_current_user(); |
| 189 |
$this->perm->init(); |
| 190 |
|
| 191 |
$this->init_current_object(); |
| 192 |
$this->moderation->init(); |
| 193 |
$this->tpl->init(); |
| 194 |
$this->api->hooks(); |
| 195 |
} |
| 196 |
|
| 197 |
public function init_shortcode_page(){ |
| 198 |
if(wpforo_is_admin()) return; |
| 199 |
|
| 200 |
if( is_wpforo_shortcode_page() ){ |
| 201 |
$url = wpforo_home_url(); |
| 202 |
|
| 203 |
if( $atts = get_wpforo_shortcode_atts() ){ |
| 204 |
$args = shortcode_atts( array( |
| 205 |
'item' => 'forum', |
| 206 |
'id' => 0, |
| 207 |
'slug' => '', |
| 208 |
), $atts ); |
| 209 |
|
| 210 |
if( $args['id'] || $args['slug'] ){ |
| 211 |
$getid = ( $args['slug'] ? $args['slug'] : $args['id'] ); |
| 212 |
if( $args['item'] == 'topic' ){ |
| 213 |
$url = $this->topic->get_topic_url($getid); |
| 214 |
}elseif( $args['item'] == 'profile' ){ |
| 215 |
$url = $this->member->get_profile_url($getid); |
| 216 |
}else{ |
| 217 |
$url = $this->forum->get_forum_url($getid); |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
$this->init_current_object($url); |
| 223 |
$this->tpl->init_nav_menu(); |
| 224 |
} |
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
private function init_defaults(){ |
| 229 |
$this->default = new stdClass; |
| 230 |
|
| 231 |
$this->default->use_home_url = 0; |
| 232 |
$this->default->excld_urls = ''; |
| 233 |
$this->default->permastruct = 'community'; |
| 234 |
|
| 235 |
$blogname = get_option('blogname', ''); |
| 236 |
$this->default->general_options = array( |
| 237 |
'title' => $blogname . ' ' . __('Forum', 'wpforo'), |
| 238 |
'description' => $blogname . ' ' . __('Discussion Board', 'wpforo'), |
| 239 |
'lang' => 1 |
| 240 |
); |
| 241 |
|
| 242 |
$this->default->features = array( |
| 243 |
'user-admin-bar' => 0, |
| 244 |
'page-title' => 1, |
| 245 |
'top-bar' => 1, |
| 246 |
'top-bar-search' => 1, |
| 247 |
'breadcrumb' => 1, |
| 248 |
'footer-stat' => 1, |
| 249 |
'mention-nicknames' => 1, |
| 250 |
'content-do_shortcode' => 0, |
| 251 |
'view-logging' => 1, |
| 252 |
'author-link' => 0, |
| 253 |
'comment-author-link' => 0, |
| 254 |
'user-register' => 1, |
| 255 |
'user-register-email-confirm' => 1, |
| 256 |
'register-url' => 0, |
| 257 |
'login-url' => 0, |
| 258 |
'resetpass-url' => 0, //In most cases incompatible with security and antispam plugins |
| 259 |
'replace-avatar' => 1, |
| 260 |
'avatars' => 1, |
| 261 |
'custom-avatars' => 1, |
| 262 |
'signature' => 1, |
| 263 |
'rating' => 1, |
| 264 |
'rating_title' => 1, |
| 265 |
'member_cashe' => 1, |
| 266 |
'object_cashe' => 1, |
| 267 |
'html_cashe' => 0, |
| 268 |
'memory_cashe' => 1, |
| 269 |
'seo-title' => 1, |
| 270 |
'seo-meta' => 1, |
| 271 |
'seo-profile' => 1, |
| 272 |
'rss-feed' => 1, |
| 273 |
'font-awesome' => 1, |
| 274 |
'user-synch' => 0, |
| 275 |
'bp_profile' => 0, |
| 276 |
'bp_activity' => 1, |
| 277 |
'bp_notification' => 1, |
| 278 |
'bp_forum_tab' => 1, |
| 279 |
'output-buffer' => 1, |
| 280 |
'wp-date-format' => 0, |
| 281 |
'subscribe_conf' => 1, |
| 282 |
'subscribe_checkbox_on_post_editor' => 1, |
| 283 |
'subscribe_checkbox_default_status' => 0, |
| 284 |
'attach-media-lib' => 1, |
| 285 |
'debug-mode' => 0, |
| 286 |
'copyright' => 1 |
| 287 |
); |
| 288 |
|
| 289 |
$this->default->tools_antispam = array( |
| 290 |
'spam_filter' => 1, |
| 291 |
'spam_filter_level_topic' => mt_rand(30, 60), |
| 292 |
'spam_filter_level_post' => mt_rand(30, 60), |
| 293 |
'spam_user_ban' => 0, |
| 294 |
'new_user_max_posts' => 5, |
| 295 |
'spam_user_ban_notification' => 1, |
| 296 |
'min_number_post_to_attach' => 3, |
| 297 |
'min_number_post_to_link' => 0, |
| 298 |
'spam_file_scanner' => 1, |
| 299 |
'limited_file_ext' => 'pdf|doc|docx|txt|htm|html|rtf|xml|xls|xlsx|zip|rar|tar|gz|bzip|7z', |
| 300 |
'exclude_file_ext' => 'pdf|doc|docx|txt', |
| 301 |
'rc_site_key' => '', |
| 302 |
'rc_secret_key' => '', |
| 303 |
'rc_theme' => 'light', |
| 304 |
'rc_login_form' => 0, |
| 305 |
'rc_reg_form' => 0, |
| 306 |
'rc_lostpass_form' => 0, |
| 307 |
'rc_wpf_login_form' => 1, |
| 308 |
'rc_wpf_reg_form' => 1, |
| 309 |
'rc_wpf_lostpass_form' => 1, |
| 310 |
'rc_topic_editor' => 1, |
| 311 |
'rc_post_editor' => 1, |
| 312 |
'html' => 'embed(src width height name pluginspage type wmode allowFullScreen allowScriptAccess flashVars),', |
| 313 |
); |
| 314 |
|
| 315 |
$this->default->tools_cleanup = array( |
| 316 |
'user_reg_days_ago' => 7, |
| 317 |
'auto_cleanup_users' => 0, |
| 318 |
'usergroup' => array ( 1 => '0', 5 => '0', 2 => '1', 3 => '0' ) |
| 319 |
); |
| 320 |
|
| 321 |
$this->default->tools_misc = array( |
| 322 |
'dofollow' => '', |
| 323 |
'noindex' => '' |
| 324 |
); |
| 325 |
|
| 326 |
$this->default->tools_legal = array( |
| 327 |
'rules_checkbox' => 0, |
| 328 |
'rules_text' => NULL, |
| 329 |
'page_terms' => '', |
| 330 |
'page_privacy' => '', |
| 331 |
'forum_privacy_text' => NULL, |
| 332 |
'checkbox_terms_privacy' => 0, |
| 333 |
'checkbox_email_password' => 1, |
| 334 |
'checkbox_forum_privacy' => 0, |
| 335 |
'checkbox_fb_login' => 1, |
| 336 |
'contact_page_url' => NULL, |
| 337 |
'cookies' => 1 |
| 338 |
); |
| 339 |
|
| 340 |
$this->default->stats = array( |
| 341 |
'forums' => 0, |
| 342 |
'topics' => 0, |
| 343 |
'posts' => 0, |
| 344 |
'members' => 0, |
| 345 |
'online_members_count' => 0, |
| 346 |
'last_post_title' => '', |
| 347 |
'last_post_url' => '', |
| 348 |
'newest_member_dname' => '', |
| 349 |
'newest_member_profile_url' => '' |
| 350 |
); |
| 351 |
} |
| 352 |
|
| 353 |
private function init_options(){ |
| 354 |
$permalink_structure = get_option('permalink_structure'); |
| 355 |
|
| 356 |
$this->use_trailing_slashes = ( '/' == substr($permalink_structure, -1, 1) ); |
| 357 |
|
| 358 |
//OPTIONS |
| 359 |
$this->use_home_url = get_wpf_option('wpforo_use_home_url', $this->default->use_home_url); |
| 360 |
$this->excld_urls = get_wpf_option('wpforo_excld_urls', $this->default->excld_urls); |
| 361 |
|
| 362 |
$this->permastruct = trim( get_wpf_option('wpforo_permastruct', $this->default->permastruct), '/' ); |
| 363 |
$this->permastruct = preg_replace('#^/?index\.php/?#isu', '', $this->permastruct); |
| 364 |
$this->permastruct = trim($this->permastruct, '/'); |
| 365 |
|
| 366 |
$this->base_permastruct = (!$this->use_home_url ? $this->permastruct : ''); |
| 367 |
$this->base_permastruct = rtrim( ( strpos($permalink_structure, 'index.php') !== FALSE ? '/index.php/' . $this->base_permastruct : '/' . $this->base_permastruct ), '/\\' ); |
| 368 |
$this->url = esc_url( home_url( $this->user_trailingslashit($this->base_permastruct) ) ); |
| 369 |
$this->pageid = get_wpf_option( 'wpforo_pageid'); |
| 370 |
|
| 371 |
$this->general_options = get_wpf_option( 'wpforo_general_options', $this->default->general_options); |
| 372 |
$this->features = get_wpf_option('wpforo_features', $this->default->features); |
| 373 |
$this->tools_antispam = get_wpf_option('wpforo_tools_antispam', $this->default->tools_antispam); |
| 374 |
$this->tools_cleanup = get_wpf_option('wpforo_tools_cleanup', $this->default->tools_cleanup); |
| 375 |
$this->tools_misc = get_wpf_option('wpforo_tools_misc', $this->default->tools_misc); |
| 376 |
$this->tools_legal = get_wpf_option('wpforo_tools_legal', $this->default->tools_legal); |
| 377 |
|
| 378 |
//CONSTANTS |
| 379 |
define('WPFORO_BASE_PERMASTRUCT', $this->base_permastruct ); |
| 380 |
define('WPFORO_BASE_URL', $this->url ); |
| 381 |
} |
| 382 |
|
| 383 |
private function setup(){ |
| 384 |
if( wpforo_is_admin() ){ |
| 385 |
register_activation_hook($this->basename, 'do_wpforo_activation'); |
| 386 |
register_deactivation_hook($this->basename, 'do_wpforo_deactivation'); |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
public function user_trailingslashit($url) { |
| 391 |
$rtrimed_url = ''; |
| 392 |
$url_append_vars = ''; |
| 393 |
if( preg_match('#(^.+?)(/?\?.*$|$)#isu', $url, $match) ){ |
| 394 |
if(isset($match[1]) && $match[1]) $rtrimed_url = rtrim($match[1], '/\\'); |
| 395 |
if(isset($match[2]) && $match[2]) $url_append_vars = trim($match[2], '/\\'); |
| 396 |
if( $rtrimed_url ) { |
| 397 |
$home_url = rtrim( preg_replace('#/?\?.*$#isu', '', home_url()), '/\\' ); |
| 398 |
if( $rtrimed_url == $home_url ){ |
| 399 |
$url = $rtrimed_url . '/'; |
| 400 |
}else{ |
| 401 |
$url = ( $this->use_trailing_slashes ? $rtrimed_url . '/' : $rtrimed_url ); |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
return $url . $url_append_vars; |
| 406 |
} |
| 407 |
|
| 408 |
public function statistic( $mode = 'get', $template = 'all' ){ |
| 409 |
|
| 410 |
if( $mode == 'get' ){ |
| 411 |
if( $cached_stat = get_option('wpforo_stat' ) ){ |
| 412 |
$cached_stat['online_members_count'] = $this->member->online_members_count(); |
| 413 |
return $cached_stat; |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
if( $mode == 'get' || $template == 'all' ) { |
| 418 |
$stats['forums'] = $this->forum->get_count( array('is_cat' => 0) ); |
| 419 |
$stats['topics'] = $this->topic->get_count(); |
| 420 |
$stats['posts'] = $this->post->get_count(); |
| 421 |
$stats['members'] = $this->member->get_count(); |
| 422 |
$stats['online_members_count'] = $this->member->online_members_count(); |
| 423 |
|
| 424 |
$posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 20, 'private' => 0, 'status' => 0, 'permgroup' => 4 )); |
| 425 |
$first = key($posts); |
| 426 |
if ( isset($posts[$first]) && !empty($posts[$first]) && $this->perm->forum_can('vf', $posts[$first]['forumid'], 4) ) { |
| 427 |
$stats['last_post_title'] = $posts[$first]['title']; |
| 428 |
$stats['last_post_url'] = $this->post->get_post_url($posts[$first]['last_post']); |
| 429 |
} |
| 430 |
|
| 431 |
$members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1)); |
| 432 |
if (isset($members[0]) && !empty($members[0])) { |
| 433 |
$stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']); |
| 434 |
$stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']); |
| 435 |
} |
| 436 |
}else{ |
| 437 |
$stats = get_wpf_option('wpforo_stat', $this->default->stats); |
| 438 |
switch ($template){ |
| 439 |
case 'forum': |
| 440 |
$stats['forums'] = $this->forum->get_count( array('is_cat' => 0) ); |
| 441 |
break; |
| 442 |
case 'topic': |
| 443 |
$stats['topics'] = $this->topic->get_count(); |
| 444 |
$posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1)); |
| 445 |
if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) { |
| 446 |
$stats['last_post_title'] = $posts[0]['title']; |
| 447 |
$stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']); |
| 448 |
} |
| 449 |
break; |
| 450 |
case 'post': |
| 451 |
$stats['posts'] = $this->post->get_count(); |
| 452 |
$posts = $this->topic->get_topics(array('orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1)); |
| 453 |
if ( isset($posts[0]) && !empty($posts[0]) && $this->perm->forum_can('vf', $posts[0]['forumid']) ) { |
| 454 |
$stats['last_post_title'] = $posts[0]['title']; |
| 455 |
$stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']); |
| 456 |
} |
| 457 |
break; |
| 458 |
case 'user': |
| 459 |
$stats['members'] = $this->member->get_count(); |
| 460 |
$stats['online_members_count'] = $this->member->online_members_count(); |
| 461 |
|
| 462 |
$members = $this->member->get_members(array('orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1)); |
| 463 |
if (isset($members[0]) && !empty($members[0])) { |
| 464 |
$stats['newest_member_dname'] = wpforo_make_dname($members[0]['display_name'], $members[0]['user_nicename']); |
| 465 |
$stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']); |
| 466 |
} |
| 467 |
break; |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
$stats = array_merge($this->default->stats, $stats); |
| 472 |
$stats = apply_filters('wpforo_get_statistic_array_filter', $stats); |
| 473 |
update_option( 'wpforo_stat', $stats ); |
| 474 |
return $stats; |
| 475 |
} |
| 476 |
|
| 477 |
public function init_current_object($url = ''){ |
| 478 |
$this->current_object = array('template' => '', 'paged' => 1, 'is_404' => false, 'user_is_same_current_user' => false); |
| 479 |
if(!$url) $url = wpforo_get_request_uri(); |
| 480 |
|
| 481 |
if( !is_wpforo_page($url) ) return; |
| 482 |
|
| 483 |
$this->current_url = $url; |
| 484 |
$current_url = wpforo_get_url_query_vars_str($url); |
| 485 |
|
| 486 |
if( $this->use_home_url ) $this->permastruct = ''; |
| 487 |
|
| 488 |
$current_object = array(); |
| 489 |
$current_object['template'] = ''; |
| 490 |
$current_object['is_404'] = false; |
| 491 |
$current_object['user_is_same_current_user'] = false; |
| 492 |
|
| 493 |
if(isset($_GET['wpfs'])) $current_object['template'] = 'search'; |
| 494 |
if( isset($_GET['wpforo']) ){ |
| 495 |
switch($_GET['wpforo']){ |
| 496 |
case 'signup': |
| 497 |
if(!is_user_logged_in()) $current_object['template'] = 'register'; |
| 498 |
break; |
| 499 |
case 'signin': |
| 500 |
if(!is_user_logged_in()) $current_object['template'] = 'login'; |
| 501 |
break; |
| 502 |
case 'lostpassword': |
| 503 |
if(!is_user_logged_in()) $current_object['template'] = 'lostpassword'; |
| 504 |
break; |
| 505 |
case 'resetpassword': |
| 506 |
$current_object['template'] = 'resetpassword'; |
| 507 |
break; |
| 508 |
case 'page': |
| 509 |
$current_object['template'] = 'page'; |
| 510 |
break; |
| 511 |
case 'logout': |
| 512 |
wp_logout(); |
| 513 |
wp_redirect( wpforo_home_url( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) ) ); |
| 514 |
exit(); |
| 515 |
break; |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
$wpf_url = preg_replace( '#^/?'.preg_quote($this->permastruct).'#isu', '' , $current_url, 1 ); |
| 520 |
$wpf_url = preg_replace('#/?\?.*$#isu', '', $wpf_url); |
| 521 |
$wpf_url_parse = array_filter( explode('/', trim($wpf_url, '/')) ); |
| 522 |
$wpf_url_parse = array_reverse($wpf_url_parse); |
| 523 |
|
| 524 |
if(in_array('paged', $wpf_url_parse)){ |
| 525 |
foreach($wpf_url_parse as $key => $value){ |
| 526 |
if( $value == 'paged'){ |
| 527 |
unset($wpf_url_parse[$key]); |
| 528 |
break; |
| 529 |
} |
| 530 |
if(is_numeric($value)) $paged = intval($value); |
| 531 |
|
| 532 |
unset($wpf_url_parse[$key]); |
| 533 |
} |
| 534 |
} |
| 535 |
if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']); |
| 536 |
$current_object['paged'] = (isset($paged) && $paged) ? $paged : 1; |
| 537 |
|
| 538 |
$wpf_url_parse = array_values($wpf_url_parse); |
| 539 |
|
| 540 |
if( !isset($current_object['template']) || !$current_object['template'] ) |
| 541 |
$current_object = apply_filters('wpforo_before_init_current_object', $current_object, $wpf_url_parse); |
| 542 |
|
| 543 |
if( !isset($current_object['template']) || !$current_object['template'] ) { |
| 544 |
if(in_array('members', $wpf_url_parse) && $wpf_url_parse[0] == 'members'){ |
| 545 |
$current_object['template'] = 'members'; |
| 546 |
}elseif(in_array('recent', $wpf_url_parse) && $wpf_url_parse[0] == 'recent'){ |
| 547 |
$current_object['template'] = 'recent'; |
| 548 |
}elseif(in_array('profile', $wpf_url_parse)){ |
| 549 |
$current_object['template'] = 'profile'; |
| 550 |
foreach($wpf_url_parse as $value){ |
| 551 |
if( $value == 'profile') break; |
| 552 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value; |
| 553 |
} |
| 554 |
}elseif(in_array('account', $wpf_url_parse)){ |
| 555 |
$current_object['template'] = 'account'; |
| 556 |
foreach($wpf_url_parse as $value){ |
| 557 |
if( $value == 'account') break; |
| 558 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value; |
| 559 |
} |
| 560 |
}elseif(in_array('activity', $wpf_url_parse)){ |
| 561 |
$current_object['template'] = 'activity'; |
| 562 |
foreach($wpf_url_parse as $value){ |
| 563 |
if( $value == 'activity') break; |
| 564 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value; |
| 565 |
} |
| 566 |
}elseif(in_array('subscriptions', $wpf_url_parse)){ |
| 567 |
$current_object['template'] = 'subscriptions'; |
| 568 |
foreach($wpf_url_parse as $value){ |
| 569 |
if( $value == 'subscriptions') break; |
| 570 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['user_nicename'] = $value; |
| 571 |
} |
| 572 |
}else{ |
| 573 |
$current_object['template'] = 'forum'; |
| 574 |
if( isset($wpf_url_parse[0]) ){ |
| 575 |
if( isset($wpf_url_parse[1]) ){ |
| 576 |
$current_object['topic_slug'] = $wpf_url_parse[0]; |
| 577 |
$current_object['forum_slug'] = $wpf_url_parse[1]; |
| 578 |
$current_object['template'] = 'post'; |
| 579 |
}else{ |
| 580 |
$current_object['forum_slug'] = $wpf_url_parse[0]; |
| 581 |
$current_object['template'] = 'topic'; |
| 582 |
} |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
if( in_array( $current_object['template'], array('profile', 'account', 'activity', 'subscriptions') ) |
| 588 |
&& !isset($current_object['user_nicename']) && !isset($current_object['userid']) ){ |
| 589 |
$current_object = wpforo_find_current_user_data( $current_object ); |
| 590 |
} |
| 591 |
|
| 592 |
if( isset($current_object['userid']) || isset($current_object['user_nicename']) ){ |
| 593 |
$args = array(); |
| 594 |
if(isset($current_object['userid'])) $args['userid'] = $current_object['userid']; |
| 595 |
if(isset($current_object['user_nicename'])) $args['user_nicename'] = $current_object['user_nicename']; |
| 596 |
$selected_user = $this->member->get_member($args); |
| 597 |
if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('user_nicename' => $current_object['userid'])); |
| 598 |
if(!empty($selected_user)){ |
| 599 |
$current_object['user'] = $selected_user; |
| 600 |
$current_object['userid'] = $selected_user['ID']; |
| 601 |
$current_object['user_nicename'] = $selected_user['user_nicename']; |
| 602 |
$current_object['user_is_same_current_user'] = !empty($this->current_userid) && $selected_user['ID'] == $this->current_userid; |
| 603 |
|
| 604 |
switch($current_object['template']){ |
| 605 |
case 'activity': |
| 606 |
$args = array( |
| 607 |
'offset' => ($current_object['paged'] - 1) * $this->post->options['posts_per_page'], |
| 608 |
'row_count' => $this->post->options['posts_per_page'], |
| 609 |
'userid' => $current_object['userid'], |
| 610 |
'orderby' => '`created` DESC, `postid` DESC', |
| 611 |
'check_private' => true |
| 612 |
); |
| 613 |
$current_object['items_count'] = 0; |
| 614 |
$current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']); |
| 615 |
break; |
| 616 |
case 'subscriptions': |
| 617 |
$args = array( |
| 618 |
'offset' => ($current_object['paged'] - 1) * $this->post->options['posts_per_page'], |
| 619 |
'row_count' => $this->post->options['posts_per_page'], |
| 620 |
'userid' => $current_object['userid'], |
| 621 |
'order' => 'DESC' |
| 622 |
); |
| 623 |
$current_object['items_count'] = 0; |
| 624 |
$current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']); |
| 625 |
break; |
| 626 |
} |
| 627 |
|
| 628 |
}else{ |
| 629 |
$current_object['is_404'] = true; |
| 630 |
$current_object['user'] = array(); |
| 631 |
$current_object['userid'] = 0; |
| 632 |
$current_object['user_nicename'] = ''; |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
if(isset($current_object['forum_slug']) && $current_object['forum_slug']){ |
| 637 |
$forum = $this->forum->get_forum( array('slug' => $current_object['forum_slug']) ); |
| 638 |
if(!empty($forum)){ |
| 639 |
$current_object['forum'] = $forum; |
| 640 |
$current_object['forumid'] = $forum['forumid']; |
| 641 |
$current_object['forum_desc'] = $forum['description']; |
| 642 |
$current_object['forum_meta_key'] = $forum['meta_key']; |
| 643 |
$current_object['forum_meta_desc'] = $forum['meta_desc']; |
| 644 |
$current_object['og_text'] = $forum['title']; |
| 645 |
}else{ |
| 646 |
$current_object['is_404'] = true; |
| 647 |
$current_object['forum'] = array(); |
| 648 |
$current_object['forumid'] = 0; |
| 649 |
$current_object['forum_desc'] = ''; |
| 650 |
$current_object['forum_meta_key'] = ''; |
| 651 |
$current_object['forum_meta_desc'] = ''; |
| 652 |
$current_object['og_text'] = ''; |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
if(isset($current_object['topic_slug']) && $current_object['topic_slug']){ |
| 657 |
$topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug'])); |
| 658 |
if(!empty($topic)){ |
| 659 |
$current_object['topic'] = $topic; |
| 660 |
$current_object['topicid'] = $topic['topicid']; |
| 661 |
$current_object['og_text'] = ( wpfval($topic, 'title') ? $topic['title'] : '' ); |
| 662 |
}elseif( $this->current_object['status'] == 'unapproved' && !is_user_logged_in() ){ |
| 663 |
wp_redirect( wpforo_login_url() ); |
| 664 |
exit(); |
| 665 |
}else{ |
| 666 |
$current_object['is_404'] = true; |
| 667 |
$current_object['topic'] = array(); |
| 668 |
$current_object['topicid'] = 0; |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
$this->current_object = apply_filters('wpforo_after_init_current_object', $current_object, $wpf_url_parse); |
| 673 |
} |
| 674 |
|
| 675 |
public function is_installed(){ |
| 676 |
return (bool) get_option('wpforo_version'); |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
/** |
| 681 |
* Main instance of wpForo. |
| 682 |
* |
| 683 |
* Returns the main instance of WPF to prevent the need to use globals. |
| 684 |
* |
| 685 |
* @since 1.4.3 |
| 686 |
* @return wpForo |
| 687 |
*/ |
| 688 |
if ( !function_exists('WPF') ){ |
| 689 |
function WPF() { |
| 690 |
return wpForo::instance(); |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
// Global for backwards compatibility. |
| 695 |
$GLOBALS['wpforo'] = WPF(); |
| 696 |
|
| 697 |
//ADDONS///////////////////////////////////////////////////// |
| 698 |
WPF()->addons = array( |
| 699 |
'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/'), |
| 700 |
'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/'), |
| 701 |
'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/'), |
| 702 |
'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/'), |
| 703 |
'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/'), |
| 704 |
'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/'), |
| 705 |
'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/'), |
| 706 |
'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/'), |
| 707 |
); |
| 708 |
$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'));} |
| 709 |
///////////////////////////////////////////////////////////// |
| 710 |
} |