| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( !defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
function do_wpforo_activation($network_wide){ |
| 6 |
if ( is_multisite() && $network_wide ) { |
| 7 |
global $wpdb; |
| 8 |
|
| 9 |
$old_blogid = $wpdb->blogid; |
| 10 |
$blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); |
| 11 |
foreach ($blogids as $blogid){ |
| 12 |
switch_to_blog($blogid); |
| 13 |
wpforo_activation(); |
| 14 |
} |
| 15 |
switch_to_blog($old_blogid); |
| 16 |
}else{ |
| 17 |
wpforo_activation(); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
function do_wpforo_deactivation($network_wide){ |
| 22 |
if ( is_multisite() && $network_wide ) { |
| 23 |
global $wpdb; |
| 24 |
|
| 25 |
$old_blogid = $wpdb->blogid; |
| 26 |
$blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); |
| 27 |
foreach ($blogids as $blogid){ |
| 28 |
switch_to_blog($blogid); |
| 29 |
wpforo_deactivation(); |
| 30 |
} |
| 31 |
switch_to_blog($old_blogid); |
| 32 |
}else{ |
| 33 |
wpforo_deactivation(); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
function wpforo_activation(){ |
| 38 |
if( ! wpforo_is_admin() ) return; |
| 39 |
if( ! current_user_can( 'activate_plugins' ) ) return; |
| 40 |
|
| 41 |
add_option('wpforo_default_groupid', WPF()->usergroup->default->default_groupid); |
| 42 |
|
| 43 |
require( WPFORO_DIR . '/wpf-includes/install-sql.php' ); |
| 44 |
foreach( $wpforo_sql as $sql ) if( FALSE === @WPF()->db->query($sql) ) @WPF()->db->query( preg_replace('#)[\r\n\t\s]*ENGINE.*$#isu', ')', $sql) ); |
| 45 |
|
| 46 |
$users = WPF()->db->get_var("SELECT COUNT(*) FROM `".WPF()->db->users."`"); |
| 47 |
if( $users <= 100 ) WPF()->member->synchronize_users(); |
| 48 |
WPF()->member->init_current_user(); |
| 49 |
|
| 50 |
add_option( 'wpforo_count_per_page', 10 ); |
| 51 |
|
| 52 |
################################################################### |
| 53 |
// General Options //////////////////////////////////////////////// |
| 54 |
wpforo_update_options( 'wpforo_general_options', WPF()->default->general_options ); |
| 55 |
|
| 56 |
################################################################### |
| 57 |
// Forums ///////////////////////////////////////////////////////// |
| 58 |
wpforo_update_options( 'wpforo_forum_options', WPF()->forum->default->options ); |
| 59 |
|
| 60 |
################################################################## |
| 61 |
// Topics & Posts //////////////////////////////////////////////// |
| 62 |
wpforo_update_options( 'wpforo_post_options', WPF()->post->default->options ); |
| 63 |
|
| 64 |
################################################################# |
| 65 |
// Features ///////////////////////////////////////////////////// |
| 66 |
wpforo_update_options( 'wpforo_features', WPF()->default->features ); |
| 67 |
|
| 68 |
################################################################# |
| 69 |
// API ////////////////////////////////////////////////////////// |
| 70 |
wpforo_update_options( 'wpforo_api_options', WPF()->default->features ); |
| 71 |
|
| 72 |
################################################################# |
| 73 |
// Theme & Style //////////////////////////////////////////////// |
| 74 |
wpforo_update_options( 'wpforo_style_options', WPF()->tpl->default->style ); |
| 75 |
wpforo_update_options( 'wpforo_theme_options', WPF()->tpl->default->options ); |
| 76 |
|
| 77 |
################################################################# |
| 78 |
// Members ////////////////////////////////////////////////////// |
| 79 |
$exlude = array('rating_title_ug', 'rating_badge_ug'); |
| 80 |
wpforo_update_options( 'wpforo_member_options', WPF()->member->default->options, $exlude); |
| 81 |
|
| 82 |
################################################################# |
| 83 |
// Subscribe Options //////////////////////////////////////////// |
| 84 |
wpforo_update_options( 'wpforo_subscribe_options', WPF()->sbscrb->default->options ); |
| 85 |
|
| 86 |
################################################################# |
| 87 |
// Tool Options - Antispam /////////////////////////////////////// |
| 88 |
wpforo_update_options( 'wpforo_tools_antispam', WPF()->default->tools_antispam); |
| 89 |
|
| 90 |
################################################################# |
| 91 |
// Tool Options - Cleanup /////////////////////////////////////// |
| 92 |
wpforo_update_options( 'wpforo_tools_cleanup', WPF()->default->tools_cleanup); |
| 93 |
|
| 94 |
################################################################# |
| 95 |
// Tool Options - Misc /////////////////////////////////////// |
| 96 |
wpforo_update_options( 'wpforo_tools_misc', WPF()->default->tools_misc); |
| 97 |
|
| 98 |
################################################################# |
| 99 |
// Forum Navigation and Menu //////////////////////////////////// |
| 100 |
$menu_name = wpforo_phrase('wpForo Navigation', false, 'orig'); |
| 101 |
$menu_location = 'wpforo-menu'; |
| 102 |
$menu_exists = wp_get_nav_menu_object( $menu_name ); |
| 103 |
if(!$menu_exists){ |
| 104 |
$id = array(); |
| 105 |
$menu_id = wp_create_nav_menu($menu_name); |
| 106 |
$id['wpforo-home'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 107 |
'menu-item-title' => wpforo_phrase('Forums', false), |
| 108 |
'menu-item-classes' => 'wpforo-home', |
| 109 |
'menu-item-url' => '/%wpforo-home%/', |
| 110 |
'menu-item-status' => 'publish', |
| 111 |
'menu-item-parent-id' => 0, |
| 112 |
'menu-item-position' => 0)); |
| 113 |
|
| 114 |
$id['wpforo-members'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 115 |
'menu-item-title' => wpforo_phrase('Members', false), |
| 116 |
'menu-item-classes' => 'wpforo-members', |
| 117 |
'menu-item-url' => '/%wpforo-members%/', |
| 118 |
'menu-item-status' => 'publish', |
| 119 |
'menu-item-parent-id' => 0, |
| 120 |
'menu-item-position' => 0)); |
| 121 |
|
| 122 |
$id['wpforo-recent'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 123 |
'menu-item-title' => wpforo_phrase('Recent Posts', false), |
| 124 |
'menu-item-classes' => 'wpforo-recent', |
| 125 |
'menu-item-url' => '/%wpforo-recent%/', |
| 126 |
'menu-item-status' => 'publish', |
| 127 |
'menu-item-parent-id' => 0, |
| 128 |
'menu-item-position' => 0)); |
| 129 |
|
| 130 |
$id['wpforo-profile'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 131 |
'menu-item-title' => wpforo_phrase('My Profile', false), |
| 132 |
'menu-item-classes' => 'wpforo-profile', |
| 133 |
'menu-item-url' => '/%wpforo-profile-home%/', |
| 134 |
'menu-item-status' => 'publish', |
| 135 |
'menu-item-parent-id' => 0, |
| 136 |
'menu-item-position' => 0)); |
| 137 |
|
| 138 |
if(isset($id['wpforo-profile']) && $id['wpforo-profile']){ |
| 139 |
$id['wpforo-profile-account'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 140 |
'menu-item-title' => wpforo_phrase('Account', false), |
| 141 |
'menu-item-classes' => 'wpforo-profile-account', |
| 142 |
'menu-item-url' => '/%wpforo-profile-account%/', |
| 143 |
'menu-item-status' => 'publish', |
| 144 |
'menu-item-parent-id' => $id['wpforo-profile'], |
| 145 |
'menu-item-position' => 1) |
| 146 |
); |
| 147 |
$id['wpforo-profile-activity'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 148 |
'menu-item-title' => wpforo_phrase('Activity', false), |
| 149 |
'menu-item-classes' => 'wpforo-profile-activity', |
| 150 |
'menu-item-url' => '/%wpforo-profile-activity%/', |
| 151 |
'menu-item-status' => 'publish', |
| 152 |
'menu-item-parent-id' => $id['wpforo-profile'], |
| 153 |
'menu-item-position' => 1) |
| 154 |
); |
| 155 |
$id['wpforo-profile-subscriptions'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 156 |
'menu-item-title' => wpforo_phrase('Subscriptions', false), |
| 157 |
'menu-item-classes' => 'wpforo-profile-subscriptions', |
| 158 |
'menu-item-url' => '/%wpforo-profile-subscriptions%/', |
| 159 |
'menu-item-status' => 'publish', |
| 160 |
'menu-item-parent-id' => $id['wpforo-profile'], |
| 161 |
'menu-item-position' => 2) |
| 162 |
); |
| 163 |
} |
| 164 |
|
| 165 |
$id['wpforo-register'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 166 |
'menu-item-title' => wpforo_phrase('Register', false), |
| 167 |
'menu-item-classes' => 'wpforo-register', |
| 168 |
'menu-item-url' => '/%wpforo-register%/', |
| 169 |
'menu-item-status' => 'publish', |
| 170 |
'menu-item-parent-id' => 0, |
| 171 |
'menu-item-position' => 0)); |
| 172 |
|
| 173 |
$id['wpforo-login'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 174 |
'menu-item-title' => wpforo_phrase('Login', false), |
| 175 |
'menu-item-classes' => 'wpforo-login', |
| 176 |
'menu-item-url' => '/%wpforo-login%/', |
| 177 |
'menu-item-status' => 'publish', |
| 178 |
'menu-item-parent-id' => 0, |
| 179 |
'menu-item-position' => 0)); |
| 180 |
|
| 181 |
$id['wpforo-logout'] = wp_update_nav_menu_item($menu_id, 0, array( |
| 182 |
'menu-item-title' => wpforo_phrase('Logout', false), |
| 183 |
'menu-item-classes' => 'wpforo-logout', |
| 184 |
'menu-item-url' => '/%wpforo-logout%/', |
| 185 |
'menu-item-status' => 'publish', |
| 186 |
'menu-item-parent-id' => 0, |
| 187 |
'menu-item-position' => 0)); |
| 188 |
|
| 189 |
if( !has_nav_menu( $menu_location ) ){ |
| 190 |
$locations = get_theme_mod('nav_menu_locations'); |
| 191 |
if(empty($locations)) $locations = array(); |
| 192 |
$locations[$menu_location] = $menu_id; |
| 193 |
set_theme_mod( 'nav_menu_locations', $locations ); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
################################################################# |
| 198 |
// Access Sets ////////////////////////////////////////////////// |
| 199 |
$cans_n = array('vf' => 0, 'ct' => 0, 'vt' => 0, 'et' => 0, 'dt' => 0, |
| 200 |
'cr' => 0, 'vr' => 0, 'er' => 0, 'dr' => 0, |
| 201 |
'eot' => 0, 'eor' => 0, 'dot' => 0, 'dor' => 0, |
| 202 |
'l' => 0, 'r' => 0, 's' => 0, 'au' => 0, |
| 203 |
'p' => 0, 'op' => 0, 'vp' => 0, 'sv' => 0, |
| 204 |
'osv' => 0, 'v' => 0, 'a' => 0, 'va' => 0, |
| 205 |
'at' => 0, 'oat' => 0, 'cot' => 0, 'mt' => 0, 'ccp' => 0, 'cvp' => 0, 'cvpr' => 0 ); |
| 206 |
$cans_r = array('vf' => 1, 'ct' => 0, 'vt' => 1, 'et' => 0, 'dt' => 0, |
| 207 |
'cr' => 0, 'vr' => 1, 'er' => 0, 'dr' => 0, |
| 208 |
'eot' => 0, 'eor' => 0, 'dot' => 0, 'dor' => 0, |
| 209 |
'l' => 0, 'r' => 0, 's' => 0, 'au' => 0, |
| 210 |
'p' => 0, 'op' => 0, 'vp' => 0, 'sv' => 0, |
| 211 |
'osv' => 0, 'v' => 0, 'a' => 0, 'va' => 1, |
| 212 |
'at' => 0, 'oat' => 0, 'cot' => 0, 'mt' => 0, 'ccp' => 0, 'cvp' => 0, 'cvpr' => 1 ); |
| 213 |
$cans_s = array('vf' => 1, 'ct' => 1, 'vt' => 1, 'et' => 0, 'dt' => 0, |
| 214 |
'cr' => 1, 'vr' => 1, 'er' => 0, 'dr' => 0, |
| 215 |
'eot' => 1, 'eor' => 1, 'dot' => 1, 'dor' => 1, |
| 216 |
'l' => 1, 'r' => 1, 's' => 0, 'au' => 0, |
| 217 |
'p' => 0, 'op' => 1, 'vp' => 0, 'sv' => 0, |
| 218 |
'osv' => 1, 'v' => 1, 'a' => 1, 'va' => 1, |
| 219 |
'at' => 0, 'oat' => 1, 'cot' => 0, 'mt' => 0, 'ccp' => 1, 'cvp' => 1, 'cvpr' => 1 ); |
| 220 |
$cans_m = array('vf' => 1, 'ct' => 1, 'vt' => 1, 'et' => 1, 'dt' => 1, |
| 221 |
'cr' => 1, 'vr' => 1, 'er' => 1, 'dr' => 1, |
| 222 |
'eot' => 1, 'eor' => 1, 'dot' => 1, 'dor' => 1, |
| 223 |
'l' => 1, 'r' => 1, 's' => 1, 'au' => 1, |
| 224 |
'p' => 1, 'op' => 1, 'vp' => 1, 'sv' => 1, |
| 225 |
'osv' => 1, 'v' => 1, 'a' => 1, 'va' => 1, |
| 226 |
'at' => 1, 'oat' => 1, 'cot' => 1, 'mt' => 1, 'ccp' => 1, 'cvp' => 1, 'cvpr' => 1 ); |
| 227 |
$cans_a = array('vf' => 1, 'ct' => 1, 'vt' => 1, 'et' => 1, 'dt' => 1, |
| 228 |
'cr' => 1, 'vr' => 1, 'er' => 1, 'dr' => 1, |
| 229 |
'eot' => 1, 'eor' => 1, 'dot' => 1, 'dor' => 1, |
| 230 |
'l' => 1, 'r' => 1, 's' => 1, 'au' => 1, |
| 231 |
'p' => 1, 'op' => 1, 'vp' => 1, 'sv' => 1, |
| 232 |
'osv' => 1, 'v' => 1, 'a' => 1, 'va' => 1, |
| 233 |
'at' => 1, 'oat' => 1, 'cot' => 1, 'mt' => 1, 'ccp' => 1, 'cvp' => 1, 'cvpr' => 1 ); |
| 234 |
|
| 235 |
$sql = "SELECT * FROM `".WPF()->tables->accesses."`"; |
| 236 |
$accesses = WPF()->db->get_results($sql, ARRAY_A); |
| 237 |
if( empty($accesses) ){ |
| 238 |
|
| 239 |
$cans_n = serialize($cans_n); |
| 240 |
$cans_r = serialize($cans_r); |
| 241 |
$cans_s = serialize($cans_s); |
| 242 |
$cans_m = serialize($cans_m); |
| 243 |
$cans_a = serialize($cans_a); |
| 244 |
|
| 245 |
$sql = "INSERT IGNORE INTO `".WPF()->tables->accesses."` |
| 246 |
(`access`, `title`, cans) VALUES |
| 247 |
('no_access', 'No access', '". $cans_n ."'), |
| 248 |
('read_only', 'Read only access', '". $cans_r ."'), |
| 249 |
('standard', 'Standard access', '". $cans_s ."'), |
| 250 |
('moderator', 'Moderator access', '".$cans_m."'), |
| 251 |
('full', 'Full access', '".$cans_a."')"; |
| 252 |
|
| 253 |
WPF()->db->query( $sql ); |
| 254 |
}else{ |
| 255 |
foreach($accesses as $access){ |
| 256 |
$default = array(); |
| 257 |
$current = unserialize($access['cans']); |
| 258 |
if( strtolower($access['access']) == 'no_access' ) $default = $cans_n; |
| 259 |
elseif( strtolower($access['access']) == 'read_only' ) $default = $cans_r; |
| 260 |
elseif( strtolower($access['access']) == 'standard' ) $default = $cans_s; |
| 261 |
elseif( strtolower($access['access']) == 'moderator' ) $default = $cans_m; |
| 262 |
elseif( strtolower($access['access']) == 'full' ) $default = $cans_a; |
| 263 |
if( !empty($default) ){ |
| 264 |
$data_update = array_merge($default, $current); |
| 265 |
if( !empty($data_update) ){ |
| 266 |
$data_update = serialize($data_update); |
| 267 |
WPF()->db->query("UPDATE `".WPF()->tables->accesses."` SET `cans` = '" . WPF()->db->_real_escape($data_update) . "' WHERE `accessid` = " . intval($access['accessid']) ); |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
################################################################# |
| 275 |
// Usergroup //////////////////////////////////////////////////// |
| 276 |
$cans_admin = array('cf' => '1', 'ef' => '1', 'df' => '1', 'vm' => '1', 'aum' => '1', 'em' => '1', 'vmg' => '1', 'aup' => '1', 'vmem' => '1', 'vprf' => '1', 'vpra' => '1', 'vprs' => '1', |
| 277 |
'bm' => '1', 'dm' => '1', 'upa' => '1', 'ups' => '1', 'va' => '1', |
| 278 |
'vmu' => '1', 'vmm' => '1', 'vmt' => '1', 'vmct' => '1', |
| 279 |
'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1', |
| 280 |
'vmlad' => '1', 'vip' => '1', 'vml' => '1', 'vmo' => '1', |
| 281 |
'vms' => '1', 'vmam' => '1', 'vmpn' => '1', 'vwpm' => '1'); |
| 282 |
$cans_moder = array('cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '1', 'em' => '0', 'vmg' => '0', 'aup' => '1', 'vmem' => '1', 'vprf' => '1', 'vpra' => '1', 'vprs' => '1', |
| 283 |
'bm' => '1', 'dm' => '1', 'upa' => '1', 'ups' => '1', 'va' => '1', |
| 284 |
'vmu' => '0', 'vmm' => '1', 'vmt' => '1', 'vmct' => '1', |
| 285 |
'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1', |
| 286 |
'vmlad' => '1', 'vip' => '1', 'vml' => '1', 'vmo' => '1', |
| 287 |
'vms' => '1', 'vmam' => '1', 'vmpn' => '1', 'vwpm' => '1'); |
| 288 |
$cans_reg = array( 'cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '0', 'em' => '0', 'vmg' => '0', 'aup' => '1', 'vmem' => '1', 'vprf' => '1', 'vpra' => '1', 'vprs' => '0', |
| 289 |
'bm' => '0', 'dm' => '0', 'upa' => '1', 'ups' => '1', 'va' => '1', |
| 290 |
'vmu' => '0', 'vmm' => '0', 'vmt' => '1', 'vmct' => '1', |
| 291 |
'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1', |
| 292 |
'vmlad' => '1', 'vip' => '0', 'vml' => '1', 'vmo' => '1', |
| 293 |
'vms' => '1', 'vmam' => '1', 'vmpn' => '0', 'vwpm' => '1'); |
| 294 |
$cans_guest = array('cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '0', 'em' => '0', 'vmg' => '0', 'aup' => '0', 'vmem' => '1', 'vprf' => '1', 'vpra' => '1', 'vprs' => '0', |
| 295 |
'bm' => '0', 'dm' => '0', 'upa' => '0', 'ups' => '0', 'va' => '1', |
| 296 |
'vmu' => '0', 'vmm' => '0', 'vmt' => '1', 'vmct' => '1', |
| 297 |
'vmr' => '1', 'vmw' => '0', 'vmsn' => '1', 'vmrd' => '1', |
| 298 |
'vmlad' => '1', 'vip' => '0', 'vml' => '1', 'vmo' => '1', |
| 299 |
'vms' => '1', 'vmam' => '1', 'vmpn' => '0', 'vwpm' => '0'); |
| 300 |
$cans_customer = array('cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '0', 'em' => '0', 'vmg' => '0', 'aup' => '0', 'vmem' => '1', 'vprf' => '1', 'vpra' => '1', 'vprs' => '0', |
| 301 |
'bm' => '0', 'dm' => '0', 'upa' => '1', 'ups' => '1', 'va' => '1', |
| 302 |
'vmu' => '0', 'vmm' => '0', 'vmt' => '1', 'vmct' => '1', |
| 303 |
'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1', |
| 304 |
'vmlad' => '1', 'vip' => '0', 'vml' => '1', 'vmo' => '1', |
| 305 |
'vms' => '1', 'vmam' => '1', 'vmpn' => '0', 'vwpm' => '1'); |
| 306 |
|
| 307 |
|
| 308 |
$sql = "SELECT * FROM `".WPF()->tables->usergroups."`"; |
| 309 |
if( !$usergroups = WPF()->db->get_results($sql, ARRAY_A) ){ |
| 310 |
WPF()->usergroup->add('Admin', $cans_admin, '', 'administrator', 'full', '#FF3333'); |
| 311 |
WPF()->usergroup->add('Moderator', $cans_moder, '', 'editor', 'moderator', '#0066FF'); |
| 312 |
WPF()->usergroup->add('Registered', $cans_reg, '', 'subscriber', 'standard', ''); |
| 313 |
WPF()->usergroup->add('Guest', $cans_guest, '', '', 'read_only', '#222222'); |
| 314 |
WPF()->usergroup->add('Customer', $cans_customer, '', 'subscriber', 'standard', '#993366'); |
| 315 |
} |
| 316 |
else{ |
| 317 |
foreach($usergroups as $usergroup){ |
| 318 |
$default = array(); |
| 319 |
$current = unserialize($usergroup['cans']); |
| 320 |
if( strtolower($usergroup['name']) == 'admin' ) $default = $cans_admin; |
| 321 |
elseif( strtolower($usergroup['name']) == 'moderator' ) $default = $cans_moder; |
| 322 |
elseif( strtolower($usergroup['name']) == 'registered' ) $default = $cans_reg; |
| 323 |
elseif( strtolower($usergroup['name']) == 'guest' ) $default = $cans_guest; |
| 324 |
elseif( strtolower($usergroup['name']) == 'customer' ) $default = $cans_customer; |
| 325 |
if( !empty($default) ){ |
| 326 |
$data_update = array_merge($default, $current); |
| 327 |
if( !empty($data_update) ){ |
| 328 |
$data_update = serialize($data_update); |
| 329 |
WPF()->db->query("UPDATE `".WPF()->tables->usergroups."` SET `cans` = '" . WPF()->db->_real_escape($data_update) . "' WHERE `groupid` = " . intval($usergroup['groupid']) ); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
$sql = "SELECT COUNT(*) FROM `".WPF()->tables->forums."`"; |
| 335 |
$count = WPF()->db->get_var($sql); |
| 336 |
if(!$count){ |
| 337 |
if( $parentid = WPF()->forum->add( array( 'title' => 'Main Category', 'description' => 'This is a simple category / section' ), FALSE ) ){ |
| 338 |
WPF()->forum->add( array( 'title' => 'Main Forum', 'description' => 'This is a simple parent forum', 'parentid' => $parentid, 'icon' => 'fa-comments' ), FALSE ); |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
################################################################# |
| 343 |
// Permalink Settings /////////////////////////////////////////// |
| 344 |
$permalink_structure = get_option( 'permalink_structure' ); |
| 345 |
if( !$permalink_structure ){ |
| 346 |
global $wp_rewrite; |
| 347 |
$wp_rewrite->set_permalink_structure( '/%postname%/' ); |
| 348 |
} |
| 349 |
|
| 350 |
################################################################# |
| 351 |
// Creating Forum Page ////////////////////////////////////////// |
| 352 |
wpforo_create_forum_page(); |
| 353 |
|
| 354 |
################################################################# |
| 355 |
// Importing Language Packs and Phrases ///////////////////////// |
| 356 |
WPF()->phrase->xml_import('english.xml', 'install'); |
| 357 |
|
| 358 |
################################################################# |
| 359 |
// Creating wpforo folders ////////////////////////////////////// |
| 360 |
$upload_array = wp_upload_dir(); |
| 361 |
$wpforo_upload_dir = $upload_array['basedir'].'/wpforo/'; |
| 362 |
if (!is_dir($wpforo_upload_dir)) { |
| 363 |
wp_mkdir_p($wpforo_upload_dir); |
| 364 |
} |
| 365 |
$avatars_upload_dir=$upload_array['basedir'].'/wpforo/avatars/'; |
| 366 |
if (!is_dir($avatars_upload_dir)) { |
| 367 |
wp_mkdir_p($avatars_upload_dir); |
| 368 |
} |
| 369 |
|
| 370 |
################################################################# |
| 371 |
// RESET USER CACHE ///////////////////////////////////////////// |
| 372 |
WPF()->member->clear_db_cache(); |
| 373 |
|
| 374 |
################################################################# |
| 375 |
// RESET FUNCTIONS ////////////////////////////////////////////// |
| 376 |
$sql = "SHOW COLUMNS FROM `".WPF()->tables->phrases."` WHERE `Field` LIKE 'package'"; |
| 377 |
if( !WPF()->db->get_row($sql, ARRAY_A) ){ |
| 378 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->phrases."` ADD COLUMN `package` VARCHAR(255) NOT NULL DEFAULT 'wpforo'" ); |
| 379 |
} |
| 380 |
WPF()->phrase->clear_cache(); |
| 381 |
|
| 382 |
################################################################# |
| 383 |
// ADD `private` field in TOPIC TABLE /////////////////////////// |
| 384 |
$args = array( 'table' => WPF()->tables->topics, 'col' => 'private', 'check' => 'col_exists' ); |
| 385 |
if( !wpforo_db_check( $args ) ){ |
| 386 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD `private` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX `is_private` (`private`);" ); |
| 387 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD INDEX `own_private` ( `userid`, `private`);" ); |
| 388 |
} |
| 389 |
// ADD INDEXES in wpforo_views TABLE/////////////////////////// |
| 390 |
$args = array( 'table' => WPF()->tables->views, 'col' => 'topicid', 'check' => 'key_exists' ); |
| 391 |
if( !wpforo_db_check( $args ) ){ |
| 392 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` ADD INDEX(`userid`);" ); |
| 393 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` ADD INDEX(`topicid`);" ); |
| 394 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` ADD UNIQUE( `userid`, `topicid`);" ); |
| 395 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->likes."` ADD UNIQUE( `userid`, `postid`);" ); |
| 396 |
} |
| 397 |
$args = array( 'table' => WPF()->tables->views, 'col' => 'created', 'check' => 'col_type' ); |
| 398 |
$col_type = wpforo_db_check( $args ); |
| 399 |
if( $col_type != 'int(11)' ){ |
| 400 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` MODIFY `created` INT(11) NOT NULL;" ); |
| 401 |
} |
| 402 |
// ADD `status` field in TOPICS & POSTS TABLE /////////////////////////// |
| 403 |
$args = array( 'table' => WPF()->tables->topics, 'col' => 'status', 'check' => 'col_exists' ); |
| 404 |
if( !wpforo_db_check( $args ) ){ |
| 405 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD `status` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX `status` (`status`);" ); |
| 406 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD INDEX `forumid_status` ( `forumid`, `status`);" ); |
| 407 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD `status` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX `status` (`status`);" ); |
| 408 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD INDEX `topicid_status` ( `topicid`, `status`);" ); |
| 409 |
} |
| 410 |
// ADD `name` and `email` field in TOPIC TABLE /////////////////////////// |
| 411 |
$args = array( 'table' => WPF()->tables->topics, 'col' => 'name', 'check' => 'col_exists' ); |
| 412 |
if( !wpforo_db_check( $args ) ){ |
| 413 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD `name` VARCHAR(50) NOT NULL, ADD `email` VARCHAR(50) NOT NULL" ); |
| 414 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD `name` VARCHAR(50) NOT NULL, ADD `email` VARCHAR(50) NOT NULL" ); |
| 415 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD KEY `email` (`email`)" ); |
| 416 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD KEY `email` (`email`)" ); |
| 417 |
} |
| 418 |
// ADD `utitle`, `role` and `access` to USERGROUP TABLE ///////// |
| 419 |
$args = array( 'table' => WPF()->tables->usergroups, 'col' => 'utitle', 'check' => 'col_exists' ); |
| 420 |
if( !wpforo_db_check( $args ) ){ |
| 421 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->usergroups."` ADD `utitle` VARCHAR(100), ADD `role` VARCHAR(50), ADD `access` VARCHAR(50)" ); |
| 422 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `utitle` = 'Admin', `role` = 'administrator', `access` = 'full' WHERE `groupid` = 1"); |
| 423 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `utitle` = 'Moderator', `role` = 'editor', `access` = 'moderator' WHERE `groupid` = 2"); |
| 424 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `utitle` = 'Registered', `role` = 'subscriber', `access` = 'standard' WHERE `groupid` = 3"); |
| 425 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `utitle` = 'Guest', `role` = '', `access` = 'read_only' WHERE `groupid` = 4"); |
| 426 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `utitle` = 'Customer', `role` = 'customer', `access` = 'standard' WHERE `groupid` = 5"); |
| 427 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `utitle` = 'name', `role` = 'subscriber', `access` = 'standard' WHERE `utitle` IS NULL OR `utitle` = ''"); |
| 428 |
} |
| 429 |
################################################################# |
| 430 |
// ADD `color` field in usergroups TABLE /////////////////////////// |
| 431 |
$args = array( 'table' => WPF()->tables->usergroups, 'col' => 'color', 'check' => 'col_exists' ); |
| 432 |
if( !wpforo_db_check( $args ) ){ |
| 433 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->usergroups."` ADD `color` varchar(7) NOT NULL DEFAULT ''" ); |
| 434 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `color` = '#FF3333' WHERE `groupid` = 1"); |
| 435 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `color` = '#0066FF' WHERE `groupid` = 2"); |
| 436 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `color` = '#222222' WHERE `groupid` = 4"); |
| 437 |
@WPF()->db->query( "UPDATE `".WPF()->tables->usergroups."` SET `color` = '#993366' WHERE `groupid` = 5"); |
| 438 |
} |
| 439 |
################################################################# |
| 440 |
// ADD `visible` field in usergroups TABLE /////////////////////////// |
| 441 |
$args = array( 'table' => WPF()->tables->usergroups, 'col' => 'visible', 'check' => 'col_exists' ); |
| 442 |
if( !wpforo_db_check( $args ) ){ |
| 443 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->usergroups."` ADD `visible` TINYINT(1) NOT NULL DEFAULT 1;" ); |
| 444 |
} |
| 445 |
################################################################# |
| 446 |
// ADD `online_time` field in profiles TABLE /////////////////////////// |
| 447 |
$args = array( 'table' => WPF()->tables->profiles, 'col' => 'online_time', 'check' => 'col_exists' ); |
| 448 |
if( !wpforo_db_check( $args ) ){ |
| 449 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->profiles."` ADD `online_time` INT UNSIGNED NOT NULL DEFAULT 0 AFTER `last_login`, ADD KEY (`online_time`)" ); |
| 450 |
} |
| 451 |
// ADD `is_email_confirmed` field in profiles TABLE /////////////////////////// |
| 452 |
$args = array( 'table' => WPF()->tables->profiles, 'col' => 'is_email_confirmed', 'check' => 'col_exists' ); |
| 453 |
if( !wpforo_db_check( $args ) ){ |
| 454 |
WPF()->db->query( "ALTER TABLE `".WPF()->tables->profiles."` ADD `is_email_confirmed` TINYINT(1) NOT NULL DEFAULT 0, ADD KEY (`is_email_confirmed`)" ); |
| 455 |
WPF()->db->query( "UPDATE `".WPF()->tables->profiles."` |
| 456 |
JOIN `".WPF()->tables->subscribes."` |
| 457 |
ON `".WPF()->tables->subscribes."`.`userid` = `".WPF()->tables->profiles."`.`userid` |
| 458 |
SET `".WPF()->tables->profiles."`.`is_email_confirmed` = 1 |
| 459 |
WHERE `".WPF()->tables->subscribes."`.`active` = 1"); |
| 460 |
WPF()->db->query("UPDATE `".WPF()->tables->profiles."` SET `is_email_confirmed` = 1 WHERE `groupid` = 1"); |
| 461 |
} |
| 462 |
################################################################# |
| 463 |
// DROP uname unique key from profiles TABLE /////////////////////////// |
| 464 |
$args = array( 'table' => WPF()->tables->profiles, 'col' => 'UNIQUE USERNAME', 'check' => 'key_exists' ); |
| 465 |
if( wpforo_db_check( $args ) ){ |
| 466 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->profiles."` DROP KEY `UNIQUE USERNAME`" ); |
| 467 |
} |
| 468 |
$args = array( 'table' => WPF()->tables->profiles, 'col' => 'UNIQUE ID', 'check' => 'key_exists' ); |
| 469 |
if( wpforo_db_check( $args ) ){ |
| 470 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->profiles."` DROP KEY `UNIQUE ID`" ); |
| 471 |
} |
| 472 |
################################################################# |
| 473 |
// ADD `private` field in post TABLE /////////////////////////// |
| 474 |
$args = array( 'table' => WPF()->tables->posts, 'col' => 'private', 'check' => 'col_exists' ); |
| 475 |
if( !wpforo_db_check( $args ) ){ |
| 476 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD `private` TINYINT(1) NOT NULL DEFAULT 0, ADD INDEX `is_private` (`private`)" ); |
| 477 |
} |
| 478 |
################################################################# |
| 479 |
// ADD `unique_vote` KEY in post Votes /////////////////////////// |
| 480 |
$args = array( 'table' => WPF()->tables->votes, 'col' => 'unique_vote', 'check' => 'key_exists' ); |
| 481 |
if( !wpforo_db_check( $args ) ){ |
| 482 |
$args = array( 'table' => WPF()->tables->votes, 'col' => 'userid', 'check' => 'key_exists' ); |
| 483 |
if( wpforo_db_check( $args ) ) @WPF()->db->query( "ALTER TABLE `".WPF()->tables->votes."` DROP KEY `userid`" ); |
| 484 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->votes."` ADD UNIQUE KEY `unique_vote` (`userid`, `postid`, `reaction`)" ); |
| 485 |
} |
| 486 |
################################################################# |
| 487 |
//Add user_name col in subsciption table/////////////////////////// |
| 488 |
$args = array( 'table' => WPF()->tables->subscribes, 'col' => 'user_name', 'check' => 'col_exists' ); |
| 489 |
if( !wpforo_db_check( $args ) ){ |
| 490 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->subscribes."` ADD `user_name` VARCHAR(60) NOT NULL DEFAULT ''" ); |
| 491 |
} |
| 492 |
//Add user_email col in subsciption table |
| 493 |
$args = array( 'table' => WPF()->tables->subscribes, 'col' => 'user_email', 'check' => 'col_exists' ); |
| 494 |
if( !wpforo_db_check( $args ) ){ |
| 495 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->subscribes."` ADD `user_email` VARCHAR(60) NOT NULL DEFAULT ''" ); |
| 496 |
} |
| 497 |
//Add indexes for subscribe new fields |
| 498 |
$args = array( 'table' => WPF()->tables->subscribes, 'col' => 'fld_group_unq', 'check' => 'key_exists' ); |
| 499 |
if( !wpforo_db_check( $args ) ){ |
| 500 |
$args = array( 'table' => WPF()->tables->subscribes, 'col' => 'itemid', 'check' => 'key_exists' ); |
| 501 |
if( wpforo_db_check( $args ) ) @WPF()->db->query( "ALTER TABLE `".WPF()->tables->subscribes."` DROP KEY `itemid`" ); |
| 502 |
wpforo_add_unique_key( WPF()->tables->subscribes, 'subid', 'fld_group_unq', '`itemid`, `type`, `userid`, `user_email`(60)'); |
| 503 |
} |
| 504 |
$args = array( 'table' => WPF()->tables->subscribes, 'col' => 'type', 'check' => 'col_type' ); |
| 505 |
$col_type = wpforo_db_check( $args ); |
| 506 |
if( $col_type != 'varchar(50)' ){ |
| 507 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->subscribes."` MODIFY `type` VARCHAR(50) NOT NULL" ); |
| 508 |
} |
| 509 |
|
| 510 |
//Add index for double condition queries to avoid SQl caching |
| 511 |
$args = array( 'table' => WPF()->tables->posts, 'col' => 'forumid_status', 'check' => 'key_exists' ); |
| 512 |
if( !wpforo_db_check( $args ) ) { |
| 513 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD KEY `forumid_status` (`forumid`,`status`)" ); |
| 514 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD KEY `topicid_status` (`topicid`,`status`)" ); |
| 515 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->posts."` ADD KEY `topicid_solved` (`topicid`,`is_answer`)" ); |
| 516 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->topics."` ADD KEY `forumid_status` (`forumid`,`status`)" ); |
| 517 |
} |
| 518 |
################################################################# |
| 519 |
// CHECK Addon Notice ///////////////////////////////////////// |
| 520 |
$lastHash = get_option('wpforo-addon-note-dismissed'); |
| 521 |
$first = get_option('wpforo-addon-note-first'); |
| 522 |
if( $lastHash && $first == 'true' ) { |
| 523 |
update_option('wpforo-addon-note-first', 'false'); |
| 524 |
} |
| 525 |
|
| 526 |
################################################################# |
| 527 |
// UPDATE VERSION - END ///////////////////////////////////////// |
| 528 |
update_option('wpforo_version', WPFORO_VERSION); |
| 529 |
WPF()->notice->clear(); |
| 530 |
wpforo_clean_cache(); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
function wpforo_update() { |
| 535 |
if ( get_option('wpforo_version') && WPFORO_VERSION !== get_option('wpforo_version') ) wpforo_activation(); |
| 536 |
} |
| 537 |
add_action('wp_loaded', 'wpforo_update'); |
| 538 |
|
| 539 |
|
| 540 |
function wpforo_update_options( $option_key, $default, $exlude = array() ) { |
| 541 |
|
| 542 |
$option = get_option( $option_key, array() ); |
| 543 |
|
| 544 |
if( !empty($option) ){ |
| 545 |
if( !empty($exlude) ){ |
| 546 |
foreach( $exlude as $key ){ |
| 547 |
if( isset($default[$key]) ) unset($default[$key]); |
| 548 |
} |
| 549 |
} |
| 550 |
$option_update = array_merge($default, $option); |
| 551 |
} |
| 552 |
else{ |
| 553 |
$option_update = $default; |
| 554 |
} |
| 555 |
|
| 556 |
update_option( $option_key, $option_update ); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
function wpforo_deactivation() {} |
| 561 |
|
| 562 |
|
| 563 |
function wpforo_uninstall() { |
| 564 |
if( ! wpforo_is_admin() ) return; |
| 565 |
if( ! current_user_can( 'activate_plugins' ) ) return; |
| 566 |
$QUERY_STRING = trim(preg_replace('|_wpnonce=[^\&\?\=]*|is', '', $_SERVER['QUERY_STRING']), '&'); |
| 567 |
|
| 568 |
if( 'action=wpforo-uninstall' == trim($QUERY_STRING) ){ |
| 569 |
|
| 570 |
foreach(WPF()->tables as $table){ |
| 571 |
$sql = "DROP TABLE IF EXISTS `$table`;"; |
| 572 |
WPF()->db->query( $sql ); |
| 573 |
} |
| 574 |
|
| 575 |
if( isset(WPF()->pageid) && WPF()->pageid ){ |
| 576 |
wp_delete_post( WPF()->pageid, true ); |
| 577 |
} |
| 578 |
|
| 579 |
$options = array( 'wpforo_version', |
| 580 |
'wpforo_url', |
| 581 |
'wpforo_stat', |
| 582 |
'wpforo_general_options', |
| 583 |
'wpforo_pageid', |
| 584 |
'wpforo_count_per_page', |
| 585 |
'wpforo_default_groupid', |
| 586 |
'wpforo_forum_options', |
| 587 |
'wpforo_post_options', |
| 588 |
'wpforo_member_options', |
| 589 |
'wpforo_subscribe_options', |
| 590 |
'wpforo_theme_options', |
| 591 |
'wpforo_features', |
| 592 |
'wpforo_style_options', |
| 593 |
'wpforo_permastruct', |
| 594 |
'wpforo_use_home_url', |
| 595 |
'wpforo_excld_urls', |
| 596 |
'wpforo_tools_antispam', |
| 597 |
'wpforo_tools_cleanup', |
| 598 |
'wpforo_tools_misc' |
| 599 |
); |
| 600 |
|
| 601 |
foreach($options as $option){ |
| 602 |
if( strpos( $option, 'wpforo_' ) !== FALSE){ |
| 603 |
delete_option( $option ); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
WPF()->db->query( "DELETE FROM `" . WPF()->db->usermeta."` WHERE `meta_key` = '_wpf_member_obj'" ); |
| 608 |
WPF()->db->query( "DELETE FROM `" . WPF()->db->options."` WHERE option_name LIKE 'wpforo_stat%'" ); |
| 609 |
WPF()->db->query( "DELETE FROM `" . WPF()->db->options."` WHERE option_name LIKE 'widget_wpforo_widget_%'" ); |
| 610 |
|
| 611 |
$menu = wp_get_nav_menu_object( 'wpforo-navigation' ); |
| 612 |
wp_delete_nav_menu( $menu->term_id ); |
| 613 |
wp_delete_post(WPF()->pageid, TRUE); |
| 614 |
|
| 615 |
deactivate_plugins( WPFORO_BASENAME ); |
| 616 |
|
| 617 |
} |
| 618 |
else{ |
| 619 |
return; |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
function wpforo_profile_notice(){ |
| 624 |
if( is_multisite() ){ |
| 625 |
$users = WPF()->db->get_var("SELECT COUNT(*) FROM `".WPF()->db->usermeta."` WHERE `meta_key` LIKE '".WPF()->blog_prefix."capabilities'"); |
| 626 |
} else { |
| 627 |
$users = WPF()->db->get_var("SELECT COUNT(*) FROM `".WPF()->db->users."`"); |
| 628 |
} |
| 629 |
$profiles = WPF()->db->get_var("SELECT COUNT(*) FROM `".WPF()->tables->profiles."`"); |
| 630 |
$delta = $users - $profiles; |
| 631 |
$status = ( $delta > 2 ) ? round((( $profiles * 100 ) / $users ), 1) . '% (' . $profiles . ' / ' . $users . ') ' : '100%'; |
| 632 |
$btext = ( $profiles == 0 ) ? __( 'Start Profile Synchronization', 'wpforo') : __( 'Continue Synchronization', 'wpforo'); |
| 633 |
$url = admin_url('admin.php?page=wpforo-community&action=synch'); |
| 634 |
$class = 'wpforo-mnote notice notice-warning is-dismissible'; |
| 635 |
$note = __( 'This process may take a few seconds or dozens of minutes, please be patient and don\'t close this page.', 'wpforo'); |
| 636 |
$info = __( 'You can permanently disable this message in Dashboard > Forums > Features admin page.', 'wpforo'); |
| 637 |
$button = '<a href="' . $url . '" class="button button-primary button-large" style="font-size:14px;">' . $btext . ' >></a>'; |
| 638 |
$header = __( 'wpForo Forum Installation | ', 'wpforo' ); |
| 639 |
$message = __( 'Forum users\' profile data are not synchronized yet, this step is required! Please click the button below to complete installation.', 'wpforo' ); |
| 640 |
echo '<div class="' . $class . '" style="padding:15px 20px;"><h2 style="margin:0px;">' . esc_html($header) . $status . ' </h2><p style="font-size:15px;margin:5px 0px;">' . $message . '</p><p style="margin:0px 0px 10px 0px;">' . $button . '</p><hr /><p style="margin:0px;color:#dd0000;">' . $note . '</p><p style="margin:0px;color:#999; font-size:12px;">' . $info . '</p></div>'; |
| 641 |
} |
| 642 |
|
| 643 |
function wpforo_update_db_notice(){ |
| 644 |
$private_topics = WPF()->db->get_var("SELECT `topicid` FROM `".WPF()->tables->topics."` WHERE `private` = 1 LIMIT 1"); |
| 645 |
if( $private_topics ){ |
| 646 |
$private_posts = WPF()->db->get_var("SELECT `postid` FROM `".WPF()->tables->posts."` WHERE `private` = 1 LIMIT 1"); |
| 647 |
if( !$private_posts ){ |
| 648 |
$url = admin_url('admin.php?page=wpforo-community&action=wpfdb&wpfv=142'); |
| 649 |
$class = 'wpforo-mnote notice notice-warning is-dismissible'; |
| 650 |
$note = __( 'This process may take a few seconds or dozens of minutes, please be patient and don\'t close this page. Database backup is not required. If you got 500 Server Error please don\'t worry, the data updating process is still working in MySQL server.', 'wpforo'); |
| 651 |
$button = '<a href="' . $url . '" class="button button-primary button-large" style="font-size:14px;">' . __( 'Updater Database', 'wpforo') . ' >></a>'; |
| 652 |
$header = __( 'wpForo - Update Database ', 'wpforo' ); |
| 653 |
$message = __( 'Please click the button below to complete wpForo update.', 'wpforo' ); |
| 654 |
echo '<div class="' . $class . '" style="padding:15px 20px;"><h2 style="margin:0px;">' . esc_html($header) . ' </h2><p style="font-size:15px;margin:5px 0px;">' . $message . '</p><p style="margin:0px 0px 10px 0px;">' . $button . '</p><hr /><p style="margin:0px;color:#ed7600;">' . $note . '</p></div>'; |
| 655 |
|
| 656 |
} |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
function wpforo_get_shortcode_pageid( $exclude = array() ){ |
| 661 |
$exclude = array_filter( array_map('wpforo_bigintval', (array) $exclude) ); |
| 662 |
$sql = "SELECT `ID` FROM `".WPF()->db->posts."` |
| 663 |
WHERE `post_content` LIKE '%[wpforo]%' |
| 664 |
AND `post_status` LIKE 'publish' |
| 665 |
AND `post_type` IN('post', 'page')"; |
| 666 |
if( $exclude ) $sql .= " AND `ID` NOT IN(". implode(',', $exclude) .")"; |
| 667 |
return WPF()->db->get_var($sql); |
| 668 |
} |
| 669 |
|
| 670 |
function wpforo_create_forum_page(){ |
| 671 |
if( !WPF()->pageid || |
| 672 |
!WPF()->db->get_var("SELECT `ID` FROM `".WPF()->db->posts."` WHERE `ID` = '".intval(WPF()->pageid)."' AND ( `post_content` LIKE '%[wpforo]%' OR `post_content` LIKE '%[wpforo-index]%' ) AND `post_status` LIKE 'publish' AND `post_type` IN('post', 'page')") ){ |
| 673 |
if( !$page_id = wpforo_get_shortcode_pageid( get_option('page_on_front') ) ){ |
| 674 |
$wpforo_page = array( |
| 675 |
'post_date' => current_time( 'mysql', 1 ), |
| 676 |
'post_date_gmt' => current_time( 'mysql', 1 ), |
| 677 |
'post_content' => '[wpforo]', |
| 678 |
'post_title' => 'Forum', |
| 679 |
'post_status' => 'publish', |
| 680 |
'comment_status' => 'close', |
| 681 |
'ping_status' => 'close', |
| 682 |
'post_name' => 'community', |
| 683 |
'post_modified' => current_time( 'mysql', 1 ), |
| 684 |
'post_modified_gmt' => current_time( 'mysql', 1 ), |
| 685 |
'post_parent' => 0, |
| 686 |
'menu_order' => 0, |
| 687 |
'post_type' => 'page' |
| 688 |
); |
| 689 |
$page_id = wp_insert_post( $wpforo_page ); |
| 690 |
} |
| 691 |
if( $page_id && !is_wp_error($page_id) ){ |
| 692 |
update_option( 'wpforo_pageid', $page_id ); |
| 693 |
update_option( 'wpforo_use_home_url', '0' ); |
| 694 |
$wpforo_url = get_wpf_option('wpforo_url'); |
| 695 |
if( !$wpforo_url ){ |
| 696 |
update_option( 'wpforo_permastruct', 'community' ); |
| 697 |
update_option( 'wpforo_url', esc_url( home_url('/') ) . "community/" ); |
| 698 |
}else{ |
| 699 |
if( !WPF()->permastruct ){ |
| 700 |
update_option( 'wpforo_permastruct', basename($wpforo_url) ); |
| 701 |
update_option( 'wpforo_url', esc_url( home_url('/') ) . basename($wpforo_url) . "/" ); |
| 702 |
}else{ |
| 703 |
update_option( 'wpforo_url', esc_url( home_url('/') ) . WPF()->permastruct . "/" ); |
| 704 |
} |
| 705 |
} |
| 706 |
} |
| 707 |
}else{ |
| 708 |
if( !WPF()->use_home_url ) update_option( 'wpforo_use_home_url', '0' ); |
| 709 |
if( !WPF()->permastruct ) update_option( 'wpforo_permastruct', basename( get_wpf_option('wpforo_url') ) ); |
| 710 |
WPF()->db->query("UPDATE `".WPF()->db->posts."` SET `post_content` = REPLACE(`post_content`, '[wpforo-index]', '[wpforo]') WHERE `ID` = '".WPF()->pageid."'"); |
| 711 |
} |
| 712 |
|
| 713 |
WPF()->pageid = get_wpf_option( 'wpforo_pageid'); |
| 714 |
WPF()->permastruct = trim( get_wpf_option('wpforo_permastruct'), '/' ); |
| 715 |
flush_rewrite_rules(FALSE); |
| 716 |
nocache_headers(); |
| 717 |
} |
| 718 |
|
| 719 |
function wpforo_update_db(){ |
| 720 |
// ADD posts' private values from TOPICS table /////////////////////////// |
| 721 |
@WPF()->db->query( "UPDATE `".WPF()->tables->posts."`, `".WPF()->tables->topics."` SET `".WPF()->tables->posts."`.`private` = `".WPF()->tables->topics."`.`private` WHERE `".WPF()->tables->posts."`.`topicid` = `".WPF()->tables->topics."`.`topicid`"); |
| 722 |
// ADD INDEXES in wpforo_views TABLE/////////////////////////// |
| 723 |
$args = array( 'table' => WPF()->tables->views, 'col' => 'topicid', 'check' => 'key_exists' ); |
| 724 |
if( !wpforo_db_check( $args ) ){ |
| 725 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` ADD INDEX(`userid`);" ); |
| 726 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` ADD INDEX(`topicid`);" ); |
| 727 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->views."` ADD UNIQUE( `userid`, `topicid`);" ); |
| 728 |
@WPF()->db->query( "ALTER TABLE `".WPF()->tables->likes."` ADD UNIQUE( `userid`, `postid`);" ); |
| 729 |
} |
| 730 |
update_option('wpforo_version_db', WPFORO_VERSION); |
| 731 |
} |