PluginProbe
wpForo Forum / 1.1.0
wpForo Forum v1.1.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.1.0, at wpforo.php

341 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Forum - wpForo
4 * Plugin URI: http://wpforo.com
5 * Description: Next Generation of WordPress Forum Softwares. Everything you need to run an efficient and professional community. Powerful and beautiful bulletin board with unique features.
6 * Author: gVectors Team (A. Chakhoyan, R. Hovhannisyan)
7 * Author URI: http://gvectors.com/
8 * Version: 1.1.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.1.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( plugin_basename(dirname(__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(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-forums.php' );
39 include( WPFORO_DIR . '/wpf-includes/class-topics.php' );
40 include( WPFORO_DIR . '/wpf-includes/class-posts.php' );
41 include( WPFORO_DIR . '/wpf-includes/class-usergroups.php' );
42 include( WPFORO_DIR . '/wpf-includes/class-members.php' );
43 include( WPFORO_DIR . '/wpf-includes/class-permissions.php' );
44 include( WPFORO_DIR . '/wpf-includes/class-phrases.php');
45 include( WPFORO_DIR . '/wpf-includes/class-subscribes.php' );
46 include( WPFORO_DIR . '/wpf-includes/class-template.php' );
47 include( WPFORO_DIR . '/wpf-includes/class-notices.php' );
48 include( WPFORO_DIR . '/wpf-includes/class-feed.php' );
49
50 class wpForo{
51
52 public $options = array();
53 public $db;
54 public $phrases;
55 public $theme;
56 public $current_object;
57 public $menu = array();
58
59 public function __construct(){
60 $this->options();
61 $this->setup();
62 }
63
64 public function init(){
65 $this->member->init_current_user();
66 $this->init_current_object();
67 $this->tpl->init_member_templates();
68 $this->tpl->init_nav_menu();
69 wpforo_actions();
70 }
71
72 private function options(){
73 global $wpdb;
74 $this->db = $wpdb;
75 $this->file = __FILE__;
76 $this->error = NULL;
77 $this->basename = plugin_basename( $this->file );
78
79 //OPTIONS
80 $this->permastruct = trim( get_wpf_option('wpforo_permastruct'), '/' );
81 $this->use_home_url = get_wpf_option('wpforo_use_home_url');
82 $this->excld_urls = get_wpf_option('wpforo_excld_urls');
83 $this->url = ( $this->use_home_url ? esc_url( home_url('/') ) : esc_url( home_url('/') ) . $this->permastruct . "/" );
84 $this->general_options = get_wpf_option( 'wpforo_general_options');
85 $this->pageid = get_wpf_option( 'wpforo_pageid');
86 $this->default_groupid = get_wpf_option('wpforo_default_groupid') ? get_option('wpforo_default_groupid') : 3;
87 $this->usergroup_cans = get_wpf_option('wpforo_usergroup_cans');
88 $this->forum_options = get_wpf_option('wpforo_forum_options');
89 $this->forum_cans = get_wpf_option('wpforo_forum_cans');
90 $this->post_options = get_wpf_option('wpforo_post_options');
91 $this->member_options = get_wpf_option('wpforo_member_options');
92 $this->subscribe_options = get_wpf_option('wpforo_subscribe_options');
93 $this->countries = get_wpf_option('wpforo_countries');
94 $this->features = get_wpf_option('wpforo_features');
95 $this->style_options = get_wpf_option('wpforo_style_options');
96 $this->theme_options = get_wpf_option('wpforo_theme_options');
97 $this->theme = $this->theme_options['folder'];
98 //CONSTANTS
99 define('WPFORO_BASE_URL', $this->url );
100 define('WPFORO_THEME', $this->theme );
101 define('WPFORO_TEMPLATE_DIR', WPFORO_THEME_DIR . '/' . $this->theme );
102 define('WPFORO_TEMPLATE_URL', WPFORO_THEME_URL . '/' . $this->theme );
103 }
104
105 private function setup(){
106 register_activation_hook($this->basename, 'do_wpforo_activation');
107 register_deactivation_hook($this->basename, 'do_wpforo_deactivation');
108 }
109
110 public function phrases(){
111 if($this->general_options){
112 $phrases = $this->phrase->get_phrases( array( 'langid' => $this->general_options['lang'] ) );
113 foreach($phrases as $phrase){
114 $this->phrases[addslashes(strtolower($phrase['phrase_key']))] = $phrase['phrase_value'];
115 }
116 }
117 }
118
119 public function get_statistic(){
120 $stats = array();
121 $stats['forums'] = $this->forum->get_count();
122 $stats['topics'] = $this->topic->get_count();
123 $stats['posts'] = $this->post->get_count();
124 $stats['members'] = $this->member->get_count();
125 $stats['online_members_count'] = $this->member->online_members_count();
126
127 $stats['last_post_title'] = '';
128 $stats['last_post_url'] = '';
129
130 $posts = $this->topic->get_topics( array( 'orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1 ) );
131 if(isset($posts[0]) && !empty($posts[0])){
132 $stats['last_post_title'] = $posts[0]['title'];
133 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
134 }
135
136 $stats['newest_member_dname'] = '';
137 $stats['newest_member_profile_url'] = '';
138
139 $members = $this->member->get_members( array( 'orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1 ) );
140 if(isset($members[0]) && !empty($members[0])){
141 $stats['newest_member_dname'] = $members[0]['display_name'] ? $members[0]['display_name'] : urldecode($members[0]['user_nicename']);
142 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
143 }
144
145 return apply_filters('wpforo_get_statistic_array_filter', $stats);
146 }
147
148 public function init_current_object($url = ''){
149 $this->current_object = array('template' => '', 'paged' => 1);
150 if( !is_wpforo_page($url) ) return;
151
152 if(!$url) $url = wpforo_full_url();
153
154 $current_url = wpforo_get_url_query_vars_str($url);
155
156 if( $this->use_home_url ) $this->permastruct = '';
157
158 $current_object = array();
159 $current_object['template'] = '';
160
161 $wpf_url = preg_replace( '#^/?'.preg_quote($this->permastruct).'#isu', '' , $current_url, 1 );
162 $wpf_url = preg_replace('#\/?\?.*$#is', '', $wpf_url);
163 $wpf_url_parse = explode('/', trim($wpf_url, '/'));
164 $wpf_url_parse = array_reverse($wpf_url_parse);
165
166 if(isset($_GET['wpfs'])){
167 $current_object['template'] = 'search';
168 }
169
170 if( isset($_GET['wpforo']) ){
171 switch($_GET['wpforo']){
172 case 'signup':
173 if(!is_user_logged_in()) $current_object['template'] = 'register';
174 break;
175 case 'signin':
176 if(!is_user_logged_in()) $current_object['template'] = 'login';
177 break;
178 case 'logout':
179 wp_logout();
180 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_full_url()) );
181 exit();
182 break;
183 }
184 }
185
186 if(in_array('paged', $wpf_url_parse)){
187 foreach($wpf_url_parse as $key => $value){
188 if( $value == 'paged'){
189 unset($wpf_url_parse[$key]);
190 break;
191 }
192 if(is_numeric($value)) $paged = intval($value);
193
194 unset($wpf_url_parse[$key]);
195 }
196 }
197 if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']);
198 $current_object['paged'] = (isset($paged) && $paged) ? $paged : 1;
199
200 $wpf_url_parse = array_values($wpf_url_parse);
201
202 if( !isset($current_object['template']) || !$current_object['template'] ) {
203 if(in_array('members', $wpf_url_parse) && $wpf_url_parse[0] == 'members'){
204 $current_object['template'] = 'members';
205 }elseif(in_array('profile', $wpf_url_parse)){
206 $current_object['template'] = 'profile';
207 foreach($wpf_url_parse as $value){
208 if( $value == 'profile') break;
209 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
210 }
211 }elseif(in_array('messages', $wpf_url_parse)){
212 $current_object['template'] = 'messages';
213 foreach($wpf_url_parse as $value){
214 if( $value == 'messages') break;
215 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
216 }
217 }elseif(in_array('account', $wpf_url_parse)){
218 $current_object['template'] = 'account';
219 foreach($wpf_url_parse as $value){
220 if( $value == 'account') break;
221 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
222 }
223 }elseif(in_array('activity', $wpf_url_parse)){
224 $current_object['template'] = 'activity';
225 foreach($wpf_url_parse as $value){
226 if( $value == 'activity') break;
227 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
228 }
229 }elseif(in_array('subscriptions', $wpf_url_parse)){
230 $current_object['template'] = 'subscriptions';
231 foreach($wpf_url_parse as $value){
232 if( $value == 'subscriptions') break;
233 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
234 }
235 }else{
236 $current_object['template'] = 'forum';
237 if($wpf_url_parse[0] && $wpf_url_parse[0] != 'wpforo'){
238
239 if(isset($wpf_url_parse[1])){
240 $current_object['topic_slug'] = $wpf_url_parse[0];
241 $current_object['forum_slug'] = $wpf_url_parse[1];
242 $current_object['template'] = 'post';
243 }else{
244 $current_object['forum_slug'] = $wpf_url_parse[0];
245 $current_object['template'] = 'topic';
246 }
247 }
248 }
249 }
250
251 if( isset($current_object['userid']) || isset($current_object['username']) ){
252 $args = array();
253 if(isset($current_object['userid'])) $args['userid'] = $current_object['userid'];
254 if(isset($current_object['username'])) $args['username'] = $current_object['username'];
255 $selected_user = $this->member->get_member($args);
256 if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('username' => $current_object['userid']));
257 if(!empty($selected_user)){
258 $current_object['user'] = $selected_user;
259 $current_object['userid'] = $selected_user['ID'];
260 $current_object['username'] = $selected_user['user_nicename'];
261
262 switch($current_object['template']){
263 case 'activity':
264 $args = array(
265 'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'],
266 'row_count' => $this->post_options['posts_per_page'],
267 'userid' => $current_object['userid'],
268 'order' => 'DESC'
269 );
270 $current_object['items_count'] = 0;
271 $current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']);
272 break;
273 case 'subscriptions':
274 $args = array(
275 'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'],
276 'row_count' => $this->post_options['posts_per_page'],
277 'userid' => $current_object['userid'],
278 'order' => 'DESC'
279 );
280 $current_object['items_count'] = 0;
281 $current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']);
282 break;
283 }
284
285 }else{
286 $current_object['user'] = array();
287 $current_object['userid'] = 0;
288 $current_object['username'] = '';
289 }
290 }
291
292 if(isset($current_object['forum_slug']) && $current_object['forum_slug']){
293 $forum = $this->forum->get_forum(array('slug' => $current_object['forum_slug']), TRUE);
294 if(!empty($forum)){
295 $current_object['forum'] = $forum;
296 $current_object['forumid'] = $forum['forumid'];
297 $current_object['forum_desc'] = $forum['description'];
298 $current_object['forum_meta_key'] = $forum['meta_key'];
299 $current_object['forum_meta_desc'] = $forum['meta_desc'];
300 }else{
301 $current_object['forum'] = array();
302 $current_object['forumid'] = 0;
303 $current_object['forum_desc'] = '';
304 $current_object['forum_meta_key'] = '';
305 $current_object['forum_meta_desc'] = '';
306 }
307 }
308
309 if(isset($current_object['topic_slug']) && $current_object['topic_slug']){
310 $topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug']), TRUE);
311 if(!empty($topic)){
312 $current_object['topic'] = $topic;
313 $current_object['topicid'] = $topic['topicid'];
314 }else{
315 $current_object['topic'] = array();
316 $current_object['topicid'] = 0;
317 }
318 }
319
320 $this->current_object = apply_filters('wpforo_current_object_filter', $current_object);
321 }
322 }
323
324 $wpforo = new wpForo();
325 $wpforo->phrase = new wpForoPhrase( $wpforo );
326 $wpforo->phrases();
327 $wpforo->forum = new wpForoForum( $wpforo );
328 $wpforo->topic = new wpForoTopic( $wpforo );
329 $wpforo->post = new wpForoPost( $wpforo );
330 $wpforo->usergroup = new wpForoUsergroup( $wpforo );
331 $wpforo->member = new wpForoMember( $wpforo );
332 $wpforo->perm = new wpForoPermissions( $wpforo );
333 $wpforo->sbscrb = new wpForoSubscribe( $wpforo );
334 $wpforo->tpl = new wpForoTemplate( $wpforo );
335 $wpforo->notice = new wpForoNotices( $wpforo );
336 $wpforo->feed = new wpForoFeed( $wpforo );
337 if(is_admin()) include( WPFORO_DIR .'/wpf-admin/admin.php' );
338 $GLOBALS['wpforo'] = $wpforo;
339 add_action('init', array($wpforo, 'init'));
340 }
341 ?>