| 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-4 |
| 9 |
* Text Domain: wpforo |
| 10 |
* Domain Path: /wpf-languages |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly |
| 14 |
if( !defined( 'ABSPATH' ) ) exit; |
| 15 |
|
| 16 |
function wpforo_load_plugin_textdomain() { |
| 17 |
load_plugin_textdomain( 'wpforo', FALSE, basename( dirname( __FILE__ ) ) . '/wpf-languages/' ); |
| 18 |
} |
| 19 |
add_action( 'plugins_loaded', 'wpforo_load_plugin_textdomain' ); |
| 20 |
|
| 21 |
if( !class_exists( 'wpForo' ) ) { |
| 22 |
|
| 23 |
define('WPFORO_DIR', rtrim( plugin_dir_path( __FILE__ ), '/')); |
| 24 |
define('WPFORO_URL', rtrim( plugins_url( plugin_basename(dirname(__FILE__))), '/')); |
| 25 |
define('WPFORO_FOLDER', rtrim( plugin_basename(dirname(__FILE__)), '/')); |
| 26 |
define('WPFORO_BASENAME', plugin_basename(__FILE__)); //wpforo/wpforo.php |
| 27 |
|
| 28 |
define('WPFORO_THEME_DIR', WPFORO_DIR . '/wpf-themes' ); |
| 29 |
define('WPFORO_THEME_URL', WPFORO_URL . '/wpf-themes' ); |
| 30 |
|
| 31 |
include( WPFORO_DIR . '/wpf-includes/wpf-hooks.php' ); |
| 32 |
include( WPFORO_DIR . '/wpf-includes/wpf-actions.php'); |
| 33 |
include( WPFORO_DIR . '/wpf-includes/functions.php' ); |
| 34 |
if(is_admin()) { |
| 35 |
include( WPFORO_DIR . '/wpf-includes/functions-installation.php' ); |
| 36 |
} |
| 37 |
include( WPFORO_DIR . '/wpf-includes/functions-integration.php' ); |
| 38 |
include( WPFORO_DIR . '/wpf-includes/functions-template.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 |
|
| 51 |
class wpForo{ |
| 52 |
|
| 53 |
public $version = 'Beta-4'; |
| 54 |
public $options = array(); |
| 55 |
public $db; |
| 56 |
public $phrases; |
| 57 |
public $theme; |
| 58 |
public $current_object; |
| 59 |
public $menu = array(); |
| 60 |
|
| 61 |
public function __construct(){ |
| 62 |
$this->options(); |
| 63 |
$this->setup(); |
| 64 |
} |
| 65 |
|
| 66 |
public function init(){ |
| 67 |
$this->member->init_current_user(); |
| 68 |
$this->init_current_object(); |
| 69 |
$this->tpl->init_member_templates(); |
| 70 |
$this->tpl->init_nav_menu(); |
| 71 |
wpforo_actions(); |
| 72 |
} |
| 73 |
|
| 74 |
private function options(){ |
| 75 |
global $wpdb; |
| 76 |
$this->db = $wpdb; |
| 77 |
$this->file = __FILE__; |
| 78 |
$this->error = NULL; |
| 79 |
$this->basename = plugin_basename( $this->file ); |
| 80 |
|
| 81 |
//OPTIONS |
| 82 |
$this->url = trim( get_option('wpforo_url'), '/' ) . "/"; |
| 83 |
$this->general_options = get_option( 'wpforo_general_options'); |
| 84 |
$this->notices = get_option( 'wpforo_notices'); |
| 85 |
$this->pageid = get_option( 'wpforo_pageid'); |
| 86 |
$this->default_groupid = get_option('wpforo_default_groupid') ? get_option('wpforo_default_groupid') : 3; |
| 87 |
$this->usergroup_cans = get_option('wpforo_usergroup_cans'); |
| 88 |
$this->forum_options = get_option('wpforo_forum_options'); |
| 89 |
$this->forum_cans = get_option('wpforo_forum_cans'); |
| 90 |
$this->post_options = get_option('wpforo_post_options'); |
| 91 |
$this->member_options = get_option('wpforo_member_options'); |
| 92 |
$this->subscribe_options = get_option('wpforo_subscribe_options'); |
| 93 |
$this->countries = get_option('wpforo_countries'); |
| 94 |
$this->features = get_option('wpforo_features'); |
| 95 |
$this->style_options = get_option('wpforo_style_options'); |
| 96 |
$this->theme_options = get_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 |
add_action( 'activate_' . $this->basename, 'wpforo_activation' ); |
| 107 |
add_action( 'deactivate_' . $this->basename, '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'] : $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 |
private function init_current_object($url = ''){ |
| 149 |
$this->current_object = array('template' => '', 'paged' => 1); |
| 150 |
if(!$url) $url = wpforo_full_url(); |
| 151 |
|
| 152 |
$url = preg_replace('#https?://(www\.|)#isu', '', $url); |
| 153 |
$wpforo_base_url = preg_replace('#https?://(www\.|)#isu', '', WPFORO_BASE_URL); |
| 154 |
|
| 155 |
if( strpos($url, $wpforo_base_url) === FALSE || strpos($url, $wpforo_base_url) != 0 ) return; |
| 156 |
|
| 157 |
$current_object = array(); |
| 158 |
$current_object['template'] = ''; |
| 159 |
|
| 160 |
$wpf_url = str_replace( $wpforo_base_url, '' , $url ); |
| 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(in_array('paged', $wpf_url_parse)){ |
| 166 |
foreach($wpf_url_parse as $key => $value){ |
| 167 |
if( $value == 'paged'){ |
| 168 |
unset($wpf_url_parse[$key]); |
| 169 |
break; |
| 170 |
} |
| 171 |
if(is_numeric($value)) $paged = intval($value); |
| 172 |
|
| 173 |
unset($wpf_url_parse[$key]); |
| 174 |
} |
| 175 |
} |
| 176 |
if(isset($_GET['wpfpaged']) && intval($_GET['wpfpaged'])) $paged = intval($_GET['wpfpaged']); |
| 177 |
$current_object['paged'] = (isset($paged) && $paged) ? $paged : 1; |
| 178 |
|
| 179 |
$wpf_url_parse = array_values($wpf_url_parse); |
| 180 |
|
| 181 |
if(in_array('members', $wpf_url_parse) && $wpf_url_parse[0] == 'members'){ |
| 182 |
$current_object['template'] = 'members'; |
| 183 |
}elseif(in_array('profile', $wpf_url_parse)){ |
| 184 |
$current_object['template'] = 'profile'; |
| 185 |
foreach($wpf_url_parse as $value){ |
| 186 |
if( $value == 'profile') break; |
| 187 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value; |
| 188 |
} |
| 189 |
}elseif(in_array('messages', $wpf_url_parse)){ |
| 190 |
$current_object['template'] = 'messages'; |
| 191 |
foreach($wpf_url_parse as $value){ |
| 192 |
if( $value == 'messages') break; |
| 193 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value; |
| 194 |
} |
| 195 |
}elseif(in_array('account', $wpf_url_parse)){ |
| 196 |
$current_object['template'] = 'account'; |
| 197 |
foreach($wpf_url_parse as $value){ |
| 198 |
if( $value == 'account') break; |
| 199 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value; |
| 200 |
} |
| 201 |
}elseif(in_array('activity', $wpf_url_parse)){ |
| 202 |
$current_object['template'] = 'activity'; |
| 203 |
foreach($wpf_url_parse as $value){ |
| 204 |
if( $value == 'activity') break; |
| 205 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value; |
| 206 |
} |
| 207 |
}elseif(in_array('subscriptions', $wpf_url_parse)){ |
| 208 |
$current_object['template'] = 'subscriptions'; |
| 209 |
foreach($wpf_url_parse as $value){ |
| 210 |
if( $value == 'subscriptions') break; |
| 211 |
if(is_numeric($value)) $current_object['userid'] = $value; else $current_object['username'] = $value; |
| 212 |
} |
| 213 |
}else{ |
| 214 |
$current_object['template'] = 'forum'; |
| 215 |
if($wpf_url_parse[0] && $wpf_url_parse[0] != 'wpforo'){ |
| 216 |
|
| 217 |
if(isset($wpf_url_parse[1])){ |
| 218 |
$current_object['topic_slug'] = $wpf_url_parse[0]; |
| 219 |
$current_object['forum_slug'] = $wpf_url_parse[1]; |
| 220 |
$current_object['template'] = 'post'; |
| 221 |
}else{ |
| 222 |
$current_object['forum_slug'] = $wpf_url_parse[0]; |
| 223 |
$current_object['template'] = 'topic'; |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
if( isset($current_object['userid']) || isset($current_object['username']) ){ |
| 229 |
$args = array(); |
| 230 |
if(isset($current_object['userid'])) $args['userid'] = $current_object['userid']; |
| 231 |
if(isset($current_object['username'])) $args['username'] = $current_object['username']; |
| 232 |
$selected_user = $this->member->get_member($args); |
| 233 |
if(isset($current_object['userid']) && empty($selected_user)) $selected_user = $this->member->get_member(array('username' => $current_object['userid'])); |
| 234 |
if(!empty($selected_user)){ |
| 235 |
$current_object['user'] = $selected_user; |
| 236 |
$current_object['userid'] = $selected_user['ID']; |
| 237 |
$current_object['username'] = $selected_user['user_nicename']; |
| 238 |
|
| 239 |
switch($current_object['template']){ |
| 240 |
case 'activity': |
| 241 |
$args = array( |
| 242 |
'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'], |
| 243 |
'row_count' => $this->post_options['posts_per_page'], |
| 244 |
'userid' => $current_object['userid'], |
| 245 |
'order' => 'DESC' |
| 246 |
); |
| 247 |
$current_object['items_count'] = 0; |
| 248 |
$current_object['activities'] = $this->post->get_posts( $args, $current_object['items_count']); |
| 249 |
break; |
| 250 |
case 'subscriptions': |
| 251 |
$args = array( |
| 252 |
'offset' => ($current_object['paged'] - 1) * $this->post_options['posts_per_page'], |
| 253 |
'row_count' => $this->post_options['posts_per_page'], |
| 254 |
'userid' => $current_object['userid'], |
| 255 |
'order' => 'DESC' |
| 256 |
); |
| 257 |
$current_object['items_count'] = 0; |
| 258 |
$current_object['subscribes'] = $this->sbscrb->get_subscribes( $args, $current_object['items_count']); |
| 259 |
break; |
| 260 |
} |
| 261 |
|
| 262 |
}else{ |
| 263 |
$current_object['user'] = array(); |
| 264 |
$current_object['userid'] = 0; |
| 265 |
$current_object['username'] = ''; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
if(isset($current_object['forum_slug']) && $current_object['forum_slug']){ |
| 270 |
$forum = $this->forum->get_forum(array('slug' => $current_object['forum_slug'])); |
| 271 |
if(!empty($forum)){ |
| 272 |
$current_object['forum'] = $forum; |
| 273 |
$current_object['forumid'] = $forum['forumid']; |
| 274 |
$current_object['forum_desc'] = $forum['description']; |
| 275 |
$current_object['forum_meta_key'] = $forum['meta_key']; |
| 276 |
$current_object['forum_meta_desc'] = $forum['meta_desc']; |
| 277 |
}else{ |
| 278 |
$current_object['forum'] = array(); |
| 279 |
$current_object['forumid'] = 0; |
| 280 |
$current_object['forum_desc'] = ''; |
| 281 |
$current_object['forum_meta_key'] = ''; |
| 282 |
$current_object['forum_meta_desc'] = ''; |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
if(isset($current_object['topic_slug']) && $current_object['topic_slug']){ |
| 287 |
$topic = $this->topic->get_topic(array('slug' => $current_object['topic_slug'])); |
| 288 |
if(!empty($topic)){ |
| 289 |
$current_object['topic'] = $topic; |
| 290 |
$current_object['topicid'] = $topic['topicid']; |
| 291 |
}else{ |
| 292 |
$current_object['topic'] = array(); |
| 293 |
$current_object['topicid'] = 0; |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
$this->current_object = apply_filters('wpforo_current_object_filter', $current_object); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
$wpforo = new wpForo(); |
| 302 |
$wpforo->phrase = new wpForoPhrase( $wpforo ); |
| 303 |
$wpforo->phrases(); |
| 304 |
$wpforo->forum = new wpForoForum( $wpforo ); |
| 305 |
$wpforo->topic = new wpForoTopic( $wpforo ); |
| 306 |
$wpforo->post = new wpForoPost( $wpforo ); |
| 307 |
$wpforo->usergroup = new wpForoUsergroup( $wpforo ); |
| 308 |
$wpforo->member = new wpForoMember( $wpforo ); |
| 309 |
$wpforo->perm = new wpForoPermissions( $wpforo ); |
| 310 |
$wpforo->sbscrb = new wpForoSubscribe( $wpforo ); |
| 311 |
$wpforo->tpl = new wpForoTemplate( $wpforo ); |
| 312 |
$wpforo->notice = new wpForoNotices( $wpforo ); |
| 313 |
$wpforo->feed = new wpForoFeed( $wpforo ); |
| 314 |
if(is_admin()) include( WPFORO_DIR .'/wpf-admin/admin.php' ); |
| 315 |
$GLOBALS['wpforo'] = $wpforo; |
| 316 |
add_action('init', array($wpforo, 'init')); |
| 317 |
} |
| 318 |
?> |