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

408 lines 18.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Forums - wpForo
4 * Plugin URI: http://wpforo.com
5 * Description: Forums wpForo is a new generation of forum plugins. It's full-fledged forum solution for your community. Comes with multiple modern forum layouts.
6 * Author: gVectors Team (A. Chakhoyan, R. Hovhannisyan)
7 * Author URI: http://gvectors.com/
8 * Version: 1.3.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.3.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 define('WPFORO_THEME_DIR', WPFORO_DIR . '/wpf-themes' );
28 define('WPFORO_THEME_URL', WPFORO_URL . '/wpf-themes' );
29
30 include( WPFORO_DIR . '/wpf-includes/wpf-hooks.php' );
31 include( WPFORO_DIR . '/wpf-includes/wpf-actions.php');
32 include( WPFORO_DIR . '/wpf-includes/functions.php' );
33 if(wpforo_is_admin()) {
34 include( WPFORO_DIR . '/wpf-includes/functions-installation.php' );
35 }
36 include( WPFORO_DIR . '/wpf-includes/functions-integration.php' );
37 include( WPFORO_DIR . '/wpf-includes/functions-template.php' );
38 include( WPFORO_DIR . '/wpf-includes/class-cache.php' );
39 include( WPFORO_DIR . '/wpf-includes/class-forums.php' );
40 include( WPFORO_DIR . '/wpf-includes/class-topics.php' );
41 include( WPFORO_DIR . '/wpf-includes/class-posts.php' );
42 include( WPFORO_DIR . '/wpf-includes/class-usergroups.php' );
43 include( WPFORO_DIR . '/wpf-includes/class-members.php' );
44 include( WPFORO_DIR . '/wpf-includes/class-permissions.php' );
45 include( WPFORO_DIR . '/wpf-includes/class-phrases.php');
46 include( WPFORO_DIR . '/wpf-includes/class-subscribes.php' );
47 include( WPFORO_DIR . '/wpf-includes/class-template.php' );
48 include( WPFORO_DIR . '/wpf-includes/class-notices.php' );
49 include( WPFORO_DIR . '/wpf-includes/class-feed.php' );
50 include( WPFORO_DIR . '/wpf-includes/class-moderation.php' );
51
52 class wpForo{
53
54 public $options = array();
55 public $db;
56 public $phrases;
57 public $access;
58 public $usergroup;
59 public $theme;
60 public $addons = array();
61 public $current_object;
62 public $menu = array();
63
64 public function __construct(){
65 $this->options();
66 $this->setup();
67 }
68
69 public function init(){
70 $this->cache->init();
71 $this->member->init_current_user();
72 $this->init_current_object();
73 $this->moderation->init();
74 $this->tpl->init_member_templates();
75 $this->tpl->init_nav_menu();
76 add_action( 'wp_loaded', 'wpforo_actions');
77 }
78
79 private function options(){
80 global $wpdb;
81 $this->db = $wpdb;
82 $this->file = __FILE__;
83 $this->error = NULL;
84 $this->basename = plugin_basename( $this->file );
85
86 $permalink_structure = get_option('permalink_structure');
87
88 $this->use_trailing_slashes = ( '/' == substr($permalink_structure, -1, 1) );
89
90 //OPTIONS
91 $this->use_home_url = get_wpf_option('wpforo_use_home_url');
92 $this->excld_urls = get_wpf_option('wpforo_excld_urls');
93
94 $this->permastruct = trim( get_wpf_option('wpforo_permastruct'), '/' );
95 $this->permastruct = preg_replace('#^/?index\.php/?#isu', '', $this->permastruct);
96 $this->permastruct = trim($this->permastruct, '/');
97
98 $this->base_permastruct = (!$this->use_home_url ? $this->permastruct : '');
99 $this->base_permastruct = rtrim( ( strpos($permalink_structure, 'index.php') !== FALSE ? '/index.php/' . $this->base_permastruct : '/' . $this->base_permastruct ), '/\\' );
100 $this->url = esc_url( home_url( $this->user_trailingslashit($this->base_permastruct) ) );
101 $this->general_options = get_wpf_option( 'wpforo_general_options');
102 $this->pageid = get_wpf_option( 'wpforo_pageid');
103 $this->default_groupid = get_wpf_option('wpforo_default_groupid') ? get_option('wpforo_default_groupid') : 3;
104 $this->usergroup_cans = get_wpf_option('wpforo_usergroup_cans');
105 $this->forum_options = get_wpf_option('wpforo_forum_options');
106 $this->forum_cans = get_wpf_option('wpforo_forum_cans');
107 $this->post_options = get_wpf_option('wpforo_post_options');
108 $this->member_options = get_wpf_option('wpforo_member_options');
109 $this->subscribe_options = get_wpf_option('wpforo_subscribe_options');
110 $this->countries = get_wpf_option('wpforo_countries');
111 $this->features = get_wpf_option('wpforo_features');
112 $this->tools_antispam = get_wpf_option('wpforo_tools_antispam');
113 $this->tools_cleanup = get_wpf_option('wpforo_tools_cleanup');
114 $this->style_options = get_wpf_option('wpforo_style_options');
115 $this->theme_options = get_wpf_option('wpforo_theme_options');
116 $this->theme = $this->theme_options['folder'];
117 //CONSTANTS
118 define('WPFORO_BASE_PERMASTRUCT', $this->base_permastruct );
119 define('WPFORO_BASE_URL', $this->url );
120 define('WPFORO_THEME', $this->theme );
121 define('WPFORO_TEMPLATE_DIR', WPFORO_THEME_DIR . '/' . $this->theme );
122 define('WPFORO_TEMPLATE_URL', WPFORO_THEME_URL . '/' . $this->theme );
123 }
124
125 private function setup(){
126 if( wpforo_is_admin() ){
127 register_activation_hook($this->basename, 'do_wpforo_activation');
128 if( !wpforo_feature('user-synch') && get_option('wpforo_version') ){
129 $users = $this->db->get_var("SELECT COUNT(*) FROM `" . $this->db->prefix . "users`");
130 $profiles = $this->db->get_var("SELECT COUNT(*) FROM `" . $this->db->prefix . "wpforo_profiles`");
131 $delta = $users - $profiles;
132 if( $users > 100 && $delta > 2 ){ add_action( 'admin_notices', 'wpforo_profile_notice' ); }
133 }
134 register_deactivation_hook($this->basename, 'do_wpforo_deactivation');
135 }
136 }
137
138 public function phrases(){
139 if($this->general_options){
140 $phrases = $this->phrase->get_phrases( array( 'langid' => $this->general_options['lang'] ) );
141 foreach($phrases as $phrase){
142 $this->phrases[addslashes(strtolower($phrase['phrase_key']))] = $phrase['phrase_value'];
143 }
144 }
145 }
146
147 public function user_trailingslashit($url) {
148 $rtrimed_url = '';
149 $url_append_vars = '';
150 if( preg_match('#(^.+?)(/?\?.*$|$)#isu', $url, $match) ){
151 if(isset($match[1]) && $match[1]) $rtrimed_url = rtrim($match[1], '/\\');
152 if(isset($match[2]) && $match[2]) $url_append_vars = trim($match[2], '/\\');
153 if( $rtrimed_url ) {
154 $home_url = rtrim( preg_replace('#/?\?.*$#isu', '', home_url()), '/\\' );
155 if( $rtrimed_url == $home_url ){
156 $url = $rtrimed_url . '/';
157 }else{
158 $url = ( $this->use_trailing_slashes ? $rtrimed_url . '/' : $rtrimed_url );
159 }
160 }
161 }
162 return $url . $url_append_vars;
163 }
164
165 public function get_statistic(){
166 return $this->statistic();
167 }
168
169 public function statistic( $mode = 'get' ){
170
171 if( $mode == 'get' ){
172 $cached_stat = get_option( 'wpforo_stat' );
173 if( !empty($cached_stat) ){
174 if( isset($cached_stat['members']) && $cached_stat['members'] ) return $cached_stat;
175 }
176 }
177
178 $stats['forums'] = $this->forum->get_count();
179 $stats['topics'] = $this->topic->get_count();
180 $stats['posts'] = $this->post->get_count();
181 $stats['members'] = $this->member->get_count();
182 $stats['online_members_count'] = $this->member->online_members_count();
183 $stats['last_post_title'] = '';
184 $stats['last_post_url'] = '';
185 $posts = $this->topic->get_topics( array( 'orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1 ) );
186 if(isset($posts[0]) && !empty($posts[0])){
187 if( $this->perm->forum_can( 'vf', $posts[0]['forumid'] ) ){
188 $stats['last_post_title'] = $posts[0]['title'];
189 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
190 }
191 else{
192 $stats['last_post_title'] = '';
193 $stats['last_post_url'] = '';
194 }
195 }
196 $stats['newest_member_dname'] = '';
197 $stats['newest_member_profile_url'] = '';
198 $members = $this->member->get_members( array( 'orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1 ) );
199 if(isset($members[0]) && !empty($members[0])){
200 $stats['newest_member_dname'] = $members[0]['display_name'] ? $members[0]['display_name'] : urldecode($members[0]['user_nicename']);
201 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
202 }
203 if( !empty($stats) && $stats['members'] ) update_option( 'wpforo_stat', $stats );
204 return apply_filters('wpforo_get_statistic_array_filter', $stats);
205 }
206
207 public function init_current_object($url = ''){
208 $this->current_object = array('template' => '', 'paged' => 1, 'is_404' => false);
209 if(!$url) $url = wpforo_get_request_uri();
210
211 if( !is_wpforo_page($url) ) return;
212
213 $current_url = wpforo_get_url_query_vars_str($url);
214
215 if( $this->use_home_url ) $this->permastruct = '';
216
217 $current_object = array();
218 $current_object['template'] = '';
219 $current_object['is_404'] = false;
220
221 if(isset($_GET['wpfs'])) $current_object['template'] = 'search';
222 if( isset($_GET['wpforo']) ){
223 switch($_GET['wpforo']){
224 case 'signup':
225 if(!is_user_logged_in()) $current_object['template'] = 'register';
226 break;
227 case 'signin':
228 if(!is_user_logged_in()) $current_object['template'] = 'login';
229 break;
230 case 'logout':
231 wp_logout();
232 wp_redirect( wpforo_home_url( preg_replace('#\?.*$#is', '', wpforo_get_request_uri()) ) );
233 exit();
234 break;
235 }
236 }
237
238 $wpf_url = preg_replace( '#^/?'.preg_quote($this->permastruct).'#isu', '' , $current_url, 1 );
239 $wpf_url = preg_replace('#/?\?.*$#isu', '', $wpf_url);
240 $wpf_url_parse = array_filter( explode('/', trim($wpf_url, '/')) );
241 $wpf_url_parse = array_reverse($wpf_url_parse);
242
243 if(in_array('paged', $wpf_url_parse)){
244 foreach($wpf_url_parse as $key => $value){
245 if( $value == 'paged'){
246 unset($wpf_url_parse[$key]);
247 break;
248 }
249 if(is_numeric($value)) $paged = intval($value);
250
251 unset($wpf_url_parse[$key]);
252 }
253 }
254 if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']);
255 $current_object['paged'] = (isset($paged) && $paged) ? $paged : 1;
256
257 $wpf_url_parse = array_values($wpf_url_parse);
258
259 if( !isset($current_object['template']) || !$current_object['template'] )
260 $current_object = apply_filters('wpforo_before_init_current_object', $current_object, $wpf_url_parse);
261
262 if( !isset($current_object['template']) || !$current_object['template'] ) {
263 if(in_array('members', $wpf_url_parse) && $wpf_url_parse[0] == 'members'){
264 $current_object['template'] = 'members';
265 }elseif(in_array('profile', $wpf_url_parse)){
266 $current_object['template'] = 'profile';
267 foreach($wpf_url_parse as $value){
268 if( $value == 'profile') break;
269 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
270 }
271 }elseif(in_array('account', $wpf_url_parse)){
272 $current_object['template'] = 'account';
273 foreach($wpf_url_parse as $value){
274 if( $value == 'account') break;
275 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
276 }
277 }elseif(in_array('activity', $wpf_url_parse)){
278 $current_object['template'] = 'activity';
279 foreach($wpf_url_parse as $value){
280 if( $value == 'activity') break;
281 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
282 }
283 }elseif(in_array('subscriptions', $wpf_url_parse)){
284 $current_object['template'] = 'subscriptions';
285 foreach($wpf_url_parse as $value){
286 if( $value == 'subscriptions') break;
287 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
288 }
289 }else{
290 $current_object['template'] = 'forum';
291 if( isset($wpf_url_parse[0]) ){
292 if( isset($wpf_url_parse[1]) ){
293 $current_object['topic_slug'] = $wpf_url_parse[0];
294 $current_object['forum_slug'] = $wpf_url_parse[1];
295 $current_object['template'] = 'post';
296 }else{
297 $current_object['forum_slug'] = $wpf_url_parse[0];
298 $current_object['template'] = 'topic';
299 }
300 }
301 }
302 }
303
304 if( isset($current_object['userid']) || isset($current_object['username']) ){
305 $args = array();
306 if(isset($current_object['userid'])) $args['userid'] = $current_object['userid'];
307 if(isset($current_object['username'])) $args['username'] = $current_object['username'];
308 $selected_user = $this->member->get_member($args);
309 if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('username' => $current_object['userid']));
310 if(!empty($selected_user)){
311 $current_object['user'] = $selected_user;
312 $current_object['userid'] = $selected_user['ID'];
313 $current_object['username'] = $selected_user['user_nicename'];
314
315 switch($current_object['template']){
316 case 'activity':
317 $args = array(
318 'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'],
319 'row_count' => $this->post_options['posts_per_page'],
320 'userid' => $current_object['userid'],
321 'order' => 'DESC',
322 'check_private' => true
323 );
324 $current_object['items_count'] = 0;
325 $current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']);
326 break;
327 case 'subscriptions':
328 $args = array(
329 'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'],
330 'row_count' => $this->post_options['posts_per_page'],
331 'userid' => $current_object['userid'],
332 'order' => 'DESC'
333 );
334 $current_object['items_count'] = 0;
335 $current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']);
336 break;
337 }
338
339 }else{
340 $current_object['is_404'] = true;
341 $current_object['user'] = array();
342 $current_object['userid'] = 0;
343 $current_object['username'] = '';
344 }
345 }
346
347 if(isset($current_object['forum_slug']) && $current_object['forum_slug']){
348 $forum = $this->forum->get_forum(array('slug' => $current_object['forum_slug']), TRUE);
349 if(!empty($forum)){
350 $current_object['forum'] = $forum;
351 $current_object['forumid'] = $forum['forumid'];
352 $current_object['forum_desc'] = $forum['description'];
353 $current_object['forum_meta_key'] = $forum['meta_key'];
354 $current_object['forum_meta_desc'] = $forum['meta_desc'];
355 }else{
356 $current_object['is_404'] = true;
357 $current_object['forum'] = array();
358 $current_object['forumid'] = 0;
359 $current_object['forum_desc'] = '';
360 $current_object['forum_meta_key'] = '';
361 $current_object['forum_meta_desc'] = '';
362 }
363 }
364
365 if(isset($current_object['topic_slug']) && $current_object['topic_slug']){
366 $topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug']));
367 if(!empty($topic)){
368 $current_object['topic'] = $topic;
369 $current_object['topicid'] = $topic['topicid'];
370 }else{
371 $current_object['is_404'] = true;
372 $current_object['topic'] = array();
373 $current_object['topicid'] = 0;
374 }
375 }
376
377 $this->current_object = apply_filters('wpforo_after_init_current_object', $current_object, $wpf_url_parse);
378 }
379 }
380
381 $wpforo = new wpForo();
382 $wpforo->cache = new wpForoCache( $wpforo );
383 $wpforo->phrase = new wpForoPhrase( $wpforo ); $wpforo->phrases();
384 $wpforo->forum = new wpForoForum( $wpforo );
385 $wpforo->topic = new wpForoTopic( $wpforo );
386 $wpforo->post = new wpForoPost( $wpforo );
387 $wpforo->usergroup = new wpForoUsergroup( $wpforo );
388 $wpforo->member = new wpForoMember( $wpforo );
389 $wpforo->perm = new wpForoPermissions( $wpforo );
390 $wpforo->sbscrb = new wpForoSubscribe( $wpforo );
391 $wpforo->tpl = new wpForoTemplate( $wpforo );
392 $wpforo->notice = new wpForoNotices( $wpforo );
393 $wpforo->feed = new wpForoFeed( $wpforo );
394 $wpforo->moderation = new wpForoModeration( $wpforo );
395 if(wpforo_is_admin()) include( WPFORO_DIR .'/wpf-admin/admin.php' );
396 $GLOBALS['wpforo'] = $wpforo;
397 add_action('init', array($wpforo, 'init'));
398
399 //ADDONS/////////////////////////////////////////////////////
400 $wpforo->addons = array(
401 'pm' => array('version' => '1.0.0', 'requires' => '1.1.2', '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' => 'http://gvectors.com/product/wpforo-private-messages/'),
402 'attachments' => array('version' => '1.0.0', 'requires' => '1.1.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' => 'http://gvectors.com/product/wpforo-advanced-attachments/'),
403 'embeds' => array('version' => '1.0.2', 'requires' => '1.1.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' => 'http://gvectors.com/product/wpforo-embeds/'),
404 'ad-manager' => array('version' => '1.0.0', 'requires' => '1.2.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' => 'http://gvectors.com/product/wpforo-ad-manager/'),
405 );
406 $wp_version = get_bloginfo('version'); if (version_compare($wp_version, '4.2.0', '>=')) { add_action('wp_ajax_dismiss_wpforo_addon_note', array($wpforo->notice, 'dismissAddonNote')); add_action('admin_notices', array($wpforo->notice, 'addonNote'));}
407 /////////////////////////////////////////////////////////////
408 }