PluginProbe
wpForo Forum / beta-6
wpForo Forum vbeta-6
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 beta-6, at wpforo.php

339 lines 13.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: 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: beta-6
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', 'Beta-6');
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->url = trim( get_option('wpforo_url'), '/' ) . "/";
81 $this->general_options = get_option( 'wpforo_general_options');
82 $this->notices = get_option( 'wpforo_notices');
83 $this->pageid = get_option( 'wpforo_pageid');
84 $this->default_groupid = get_option('wpforo_default_groupid') ? get_option('wpforo_default_groupid') : 3;
85 $this->usergroup_cans = get_option('wpforo_usergroup_cans');
86 $this->forum_options = get_option('wpforo_forum_options');
87 $this->forum_cans = get_option('wpforo_forum_cans');
88 $this->post_options = get_option('wpforo_post_options');
89 $this->member_options = get_option('wpforo_member_options');
90 $this->subscribe_options = get_option('wpforo_subscribe_options');
91 $this->countries = get_option('wpforo_countries');
92 $this->features = get_option('wpforo_features');
93 $this->style_options = get_option('wpforo_style_options');
94 $this->theme_options = get_option('wpforo_theme_options');
95 $this->theme = $this->theme_options['folder'];
96 //CONSTANTS
97 define('WPFORO_BASE_URL', $this->url );
98 define('WPFORO_THEME', $this->theme );
99 define('WPFORO_TEMPLATE_DIR', WPFORO_THEME_DIR . '/' . $this->theme );
100 define('WPFORO_TEMPLATE_URL', WPFORO_THEME_URL . '/' . $this->theme );
101 }
102
103 private function setup(){
104 add_action( 'activate_' . $this->basename, 'wpforo_activation' );
105 add_action( 'deactivate_' . $this->basename, 'wpforo_deactivation' );
106 }
107
108 public function phrases(){
109 if($this->general_options){
110 $phrases = $this->phrase->get_phrases( array( 'langid' => $this->general_options['lang'] ) );
111 foreach($phrases as $phrase){
112 $this->phrases[addslashes(strtolower($phrase['phrase_key']))] = $phrase['phrase_value'];
113 }
114 }
115 }
116
117 public function get_statistic(){
118 $stats = array();
119 $stats['forums'] = $this->forum->get_count();
120 $stats['topics'] = $this->topic->get_count();
121 $stats['posts'] = $this->post->get_count();
122 $stats['members'] = $this->member->get_count();
123 $stats['online_members_count'] = $this->member->online_members_count();
124
125 $stats['last_post_title'] = '';
126 $stats['last_post_url'] = '';
127
128 $posts = $this->topic->get_topics( array( 'orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1 ) );
129 if(isset($posts[0]) && !empty($posts[0])){
130 $stats['last_post_title'] = $posts[0]['title'];
131 $stats['last_post_url'] = $this->post->get_post_url($posts[0]['last_post']);
132 }
133
134 $stats['newest_member_dname'] = '';
135 $stats['newest_member_profile_url'] = '';
136
137 $members = $this->member->get_members( array( 'orderby' => 'userid', 'order' => 'DESC', 'row_count' => 1 ) );
138 if(isset($members[0]) && !empty($members[0])){
139 $stats['newest_member_dname'] = $members[0]['display_name'] ? $members[0]['display_name'] : $members[0]['user_nicename'];
140 $stats['newest_member_profile_url'] = $this->member->get_profile_url($members[0]['ID']);
141 }
142
143 return apply_filters('wpforo_get_statistic_array_filter', $stats);
144 }
145
146 private function init_current_object($url = ''){
147 $this->current_object = array('template' => '', 'paged' => 1);
148 if(!$url) $url = wpforo_full_url();
149
150 $url = rtrim($url, '/') . '/';
151 $url = preg_replace('#https?://[^/\?]+\.[^/\?]+/?#isu', '', $url);
152 $wpforo_base_url = preg_replace('#https?://[^/\?]+\.[^/\?]+/?#isu', '', WPFORO_BASE_URL);
153
154 if( strpos($url, $wpforo_base_url) === FALSE || strpos($url, $wpforo_base_url) != 0 ) return;
155
156 $current_object = array();
157 $current_object['template'] = '';
158
159 $wpf_url = preg_replace( '#^/?'.preg_quote($wpforo_base_url).'#isu', '' , $url, 1 );
160 $wpf_url = preg_replace('#\/?\?.*$#is', '', $wpf_url);
161 $wpf_url_parse = explode('/', trim($wpf_url, '/'));
162 $wpf_url_parse = array_reverse($wpf_url_parse);
163
164 if(isset($_GET['wpfs'])){
165 $current_object['template'] = 'search';
166 }
167
168 if( isset($_GET['wpforo']) ){
169 switch($_GET['wpforo']){
170 case 'signup':
171 if(!is_user_logged_in()) $current_object['template'] = 'register';
172 break;
173 case 'signin':
174 if(!is_user_logged_in()) $current_object['template'] = 'login';
175 break;
176 case 'logout':
177 wp_logout();
178 wp_redirect( preg_replace('#\?.*$#is', '', wpforo_full_url()) );
179 exit();
180 break;
181 }
182 }
183
184 if(in_array('paged', $wpf_url_parse)){
185 foreach($wpf_url_parse as $key => $value){
186 if( $value == 'paged'){
187 unset($wpf_url_parse[$key]);
188 break;
189 }
190 if(is_numeric($value)) $paged = intval($value);
191
192 unset($wpf_url_parse[$key]);
193 }
194 }
195 if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']);
196 $current_object['paged'] = (isset($paged) && $paged) ? $paged : 1;
197
198 $wpf_url_parse = array_values($wpf_url_parse);
199
200 if( !isset($current_object['template']) || !$current_object['template'] ) {
201 if(in_array('members', $wpf_url_parse) && $wpf_url_parse[0] == 'members'){
202 $current_object['template'] = 'members';
203 }elseif(in_array('profile', $wpf_url_parse)){
204 $current_object['template'] = 'profile';
205 foreach($wpf_url_parse as $value){
206 if( $value == 'profile') break;
207 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
208 }
209 }elseif(in_array('messages', $wpf_url_parse)){
210 $current_object['template'] = 'messages';
211 foreach($wpf_url_parse as $value){
212 if( $value == 'messages') break;
213 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
214 }
215 }elseif(in_array('account', $wpf_url_parse)){
216 $current_object['template'] = 'account';
217 foreach($wpf_url_parse as $value){
218 if( $value == 'account') break;
219 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
220 }
221 }elseif(in_array('activity', $wpf_url_parse)){
222 $current_object['template'] = 'activity';
223 foreach($wpf_url_parse as $value){
224 if( $value == 'activity') break;
225 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
226 }
227 }elseif(in_array('subscriptions', $wpf_url_parse)){
228 $current_object['template'] = 'subscriptions';
229 foreach($wpf_url_parse as $value){
230 if( $value == 'subscriptions') break;
231 if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value;
232 }
233 }else{
234 $current_object['template'] = 'forum';
235 if($wpf_url_parse[0] && $wpf_url_parse[0] != 'wpforo'){
236
237 if(isset($wpf_url_parse[1])){
238 $current_object['topic_slug'] = $wpf_url_parse[0];
239 $current_object['forum_slug'] = $wpf_url_parse[1];
240 $current_object['template'] = 'post';
241 }else{
242 $current_object['forum_slug'] = $wpf_url_parse[0];
243 $current_object['template'] = 'topic';
244 }
245 }
246 }
247 }
248
249 if( isset($current_object['userid']) || isset($current_object['username']) ){
250 $args = array();
251 if(isset($current_object['userid'])) $args['userid'] = $current_object['userid'];
252 if(isset($current_object['username'])) $args['username'] = $current_object['username'];
253 $selected_user = $this->member->get_member($args);
254 if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('username' => $current_object['userid']));
255 if(!empty($selected_user)){
256 $current_object['user'] = $selected_user;
257 $current_object['userid'] = $selected_user['ID'];
258 $current_object['username'] = $selected_user['user_nicename'];
259
260 switch($current_object['template']){
261 case 'activity':
262 $args = array(
263 'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'],
264 'row_count' => $this->post_options['posts_per_page'],
265 'userid' => $current_object['userid'],
266 'order' => 'DESC'
267 );
268 $current_object['items_count'] = 0;
269 $current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']);
270 break;
271 case 'subscriptions':
272 $args = array(
273 'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'],
274 'row_count' => $this->post_options['posts_per_page'],
275 'userid' => $current_object['userid'],
276 'order' => 'DESC'
277 );
278 $current_object['items_count'] = 0;
279 $current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']);
280 break;
281 }
282
283 }else{
284 $current_object['user'] = array();
285 $current_object['userid'] = 0;
286 $current_object['username'] = '';
287 }
288 }
289
290 if(isset($current_object['forum_slug']) && $current_object['forum_slug']){
291 $forum = $this->forum->get_forum(array('slug' => $current_object['forum_slug']));
292 if(!empty($forum)){
293 $current_object['forum'] = $forum;
294 $current_object['forumid'] = $forum['forumid'];
295 $current_object['forum_desc'] = $forum['description'];
296 $current_object['forum_meta_key'] = $forum['meta_key'];
297 $current_object['forum_meta_desc'] = $forum['meta_desc'];
298 }else{
299 $current_object['forum'] = array();
300 $current_object['forumid'] = 0;
301 $current_object['forum_desc'] = '';
302 $current_object['forum_meta_key'] = '';
303 $current_object['forum_meta_desc'] = '';
304 }
305 }
306
307 if(isset($current_object['topic_slug']) && $current_object['topic_slug']){
308 $topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug']));
309 if(!empty($topic)){
310 $current_object['topic'] = $topic;
311 $current_object['topicid'] = $topic['topicid'];
312 }else{
313 $current_object['topic'] = array();
314 $current_object['topicid'] = 0;
315 }
316 }
317
318 $this->current_object = apply_filters('wpforo_current_object_filter', $current_object);
319 }
320 }
321
322 $wpforo = new wpForo();
323 $wpforo->phrase = new wpForoPhrase( $wpforo );
324 $wpforo->phrases();
325 $wpforo->forum = new wpForoForum( $wpforo );
326 $wpforo->topic = new wpForoTopic( $wpforo );
327 $wpforo->post = new wpForoPost( $wpforo );
328 $wpforo->usergroup = new wpForoUsergroup( $wpforo );
329 $wpforo->member = new wpForoMember( $wpforo );
330 $wpforo->perm = new wpForoPermissions( $wpforo );
331 $wpforo->sbscrb = new wpForoSubscribe( $wpforo );
332 $wpforo->tpl = new wpForoTemplate( $wpforo );
333 $wpforo->notice = new wpForoNotices( $wpforo );
334 $wpforo->feed = new wpForoFeed( $wpforo );
335 if(is_admin()) include( WPFORO_DIR .'/wpf-admin/admin.php' );
336 $GLOBALS['wpforo'] = $wpforo;
337 add_action('init', array($wpforo, 'init'));
338 }
339 ?>