PluginProbe
wpForo Forum / 1.0.1
wpForo Forum v1.0.1
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.0.1, at wpforo.php

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