PluginProbe
wpForo Forum / 1.2.0
wpForo Forum v1.2.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 / wpf-includes / functions-installation.php

functions-installation.php in wpForo Forum 1.2.0, at wpf-includes/functions-installation.php

783 lines 36.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 global $wpforo, $wpdb;
39 if( ! wpforo_is_admin() ) return;
40 if( ! current_user_can( 'activate_plugins' ) ) return;
41 add_option('wpforo_default_groupid', 3);
42 require( WPFORO_DIR . '/wpf-includes/install-sql.php' );
43 foreach( $wpforo_sql as $sql ) if( FALSE === @$wpforo->db->query($sql) ) @$wpforo->db->query( preg_replace('#)[\r\n\t\s]*ENGINE.*$#isu', ')', $sql) );
44 $wpforo->member->synchronize_users();
45 $wpforo->member->init_current_user();
46 $blogname = get_option('blogname');
47 $adminemail = get_option('admin_email');
48 add_option( 'wpforo_count_per_page', 10 );
49
50 ###################################################################
51 // General Options ////////////////////////////////////////////////
52 $general_options = array(
53 'title' => $blogname . ' ' . __('Forum', 'wpforo'),
54 'description' => $blogname . ' ' . __('Discussion Board', 'wpforo'),
55 'lang' => 1,
56 );
57 wpforo_update_options( 'wpforo_general_options', $general_options );
58
59 ###################################################################
60 // Forums /////////////////////////////////////////////////////////
61 $wpforo_forum = array(
62 'layout_qa_intro_topics_toggle' => 1,
63 'layout_extended_intro_topics_toggle' => 1,
64 'layout_qa_intro_topics_count' => 3,
65 'layout_extended_intro_topics_count' => 5,
66 );
67 wpforo_update_options( 'wpforo_forum_options', $wpforo_forum );
68
69 ##################################################################
70 // Topics & Posts ////////////////////////////////////////////////
71 $upload_max_filesize = @ini_get('upload_max_filesize');
72 $upload_max_filesize = wpforo_human_size_to_bytes($upload_max_filesize);
73 if( !$upload_max_filesize || $upload_max_filesize > 10485760 ) $upload_max_filesize = 10485760;
74 $wpforo_post = array(
75 'layout_extended_intro_posts_toggle' => 1,
76 'layout_extended_intro_posts_count' => 4,
77 'topics_per_page' => 10,
78 'eot_durr' => 300,
79 'dot_durr' => 300,
80 'posts_per_page' => 15,
81 'eor_durr' => 300,
82 'dor_durr' => 300,
83 'max_upload_size' => $upload_max_filesize,
84 'attach_cant_view_msg' => __("You are not permitted to view this attachment", 'wpforo')
85 );
86 wpforo_update_options( 'wpforo_post_options', $wpforo_post );
87
88 #################################################################
89 // Features /////////////////////////////////////////////////////
90 $wpforo_features = array(
91 'user-admin-bar' => 0,
92 'page-title' => 1,
93 'top-bar' => 1,
94 'top-bar-search' => 1,
95 'breadcrumb' => 1,
96 'footer-stat' => 1,
97 'author-link' => 0,
98 'comment-author-link' => 0,
99 'user-register' => 1,
100 'user-register-email-confirm' => 0,
101 'register-url' => 0,
102 'login-url' => 0,
103 'replace-avatar' => 1,
104 'avatars' => 1,
105 'custom-avatars' => 1,
106 'signature' => 1,
107 'rating' => 1,
108 'rating_title' => 1,
109 'member_cashe' => 1,
110 'seo-title' => 1,
111 'seo-meta' => 1,
112 'font-awesome' => 1,
113 'output-buffer' => 1,
114 'wp-date-format' => 0,
115 'subscribe_conf' => 1,
116 'subscribe_checkbox_on_post_editor' => 1,
117 'subscribe_checkbox_default_status' => 0,
118 'attach-media-lib' => 1,
119 'debug-mode' => 0,
120 'copyright' => 1
121 );
122 wpforo_update_options( 'wpforo_features', $wpforo_features );
123
124 #################################################################
125 // Theme & Style ////////////////////////////////////////////////
126 $wpforo_style = array(
127 'font_size_forum' => 17,
128 'font_size_topic' => 16,
129 'font_size_post_content' => 14,
130 'custom_css' => "#wpforo-wrap {\r\n font-size: 13px; width: 100%; padding:10px 20px; margin:0px;\r\n}\r\n",
131 );
132 wpforo_update_options( 'wpforo_style_options', $wpforo_style );
133
134 $defaut_theme = 'classic';
135 $theme = $wpforo->tpl->find_theme( $defaut_theme );
136 $current_theme = get_option( 'wpforo_theme_options' );
137 if(!empty($current_theme)) {
138 $theme = wpforo_deep_merge($theme, $current_theme);
139 update_option( 'wpforo_theme_options', $theme );
140 }
141 add_option( 'wpforo_theme_options', $theme );
142
143 #################################################################
144 // Members //////////////////////////////////////////////////////
145 $wpforo_member = array(
146 'online_status_timeout' => 240,
147 'url_structure' => 'nicename',
148 'login_url' => '',
149 'register_url' => '',
150 'lost_password_url' => '',
151 'rating_title_ug' => array ( 1 => '1', 5 => '1', 4 => '1', 2 => '1', 3 => '1' ),
152 'rating_badge_ug' => array ( 1 => '1', 5 => '1', 4 => '1', 2 => '1', 3 => '1' ),
153 );
154 $exlude = array('rating_title_ug', 'rating_badge_ug');
155 wpforo_update_options( 'wpforo_member_options', $wpforo_member, $exlude);
156
157 #################################################################
158 // Subscribe Options ////////////////////////////////////////////
159 $subscriptions_options = array (
160 'from_name' => $blogname . ' - Forum',
161 'from_email' => $adminemail,
162 'admin_emails' => $adminemail,
163 'new_topic_notify' => 1,
164 'new_reply_notify' => 0,
165 'confirmation_email_subject' => "Please confirm subscription to [entry_title]",
166 'confirmation_email_message' => "Hello [member_name]!<br>\r\n Thank you for subscribing.<br>\r\n This is an automated response.<br>\r\n We are glad to inform you that after confirmation you will get updates from - [entry_title].<br>\r\n Please click on link below to complete this step.<br>\r\n [confirm_link]" ,
167 'new_topic_notification_email_subject' => "New Topic" ,
168 'new_topic_notification_email_message' => "Hello [member_name]!<br>\r\n New topic has been created on your subscribed forum - [forum].\r\n <br><br>\r\n <strong>[topic_title]</strong>\r\n <blockquote>\r\n [topic_desc]\r\n </blockquote>\r\n <br><hr>\r\n If you want to unsubscribe from this forum please use the link below.<br>\r\n [unsubscribe_link]" ,
169 'new_post_notification_email_subject' => "New Reply" ,
170 'new_post_notification_email_message' => "Hello [member_name]!<br>\r\n New reply has been posted on your subscribed topic - [topic].\r\n <br><br>\r\n <strong>[reply_title]</strong>\r\n <blockquote >\r\n [reply_desc]\r\n </blockquote>\r\n <br><hr>\r\n If you want to unsubscribe from this topic please use the link below.<br>\r\n [unsubscribe_link]" ,
171 'report_email_subject' => "Forum Post Report",
172 'report_email_message' => "<strong>Report details:</strong>\r\n Reporter: [reporter], <br>\r\n Message: [message],<br>\r\n <br>\r\n [post_url]",
173 //'spam_notification_email_subject' => 'New Banned User',
174 //'spam_notification_email_message' => "Hello [member_name]!<br>\r\n Please check this user's topics/posts and consider to Delete or Unban.<br>\r\n User Activity: [profile_activity_url]",
175 'update' => '1'
176 );
177 wpforo_update_options( 'wpforo_subscribe_options', $subscriptions_options );
178
179
180
181 #################################################################
182 // Tool Options - Antispam ///////////////////////////////////////
183 $topic_level = mt_rand(60, 80);
184 $post_level = mt_rand(70, 80);
185 $wpforo_tools_antispam = array(
186 'spam_filter' => 1,
187 'spam_filter_level_topic' => $topic_level,
188 'spam_filter_level_post' => $post_level,
189 'spam_user_ban' => 0,
190 'new_user_max_posts' => 5,
191 'spam_user_ban_notification' => 1,
192 'min_number_post_to_attach' => 3,
193 'min_number_post_to_link' => 0,
194 'limited_file_ext' => 'pdf|doc|docx|txt|htm|html|rtf|xml|xls|xlsx|zip|rar|tar|gz|bzip|7z',
195 );
196 wpforo_update_options( 'wpforo_tools_antispam', $wpforo_tools_antispam);
197
198
199
200 #################################################################
201 // Countries ////////////////////////////////////////////////////
202 $countries = array( "Afghanistan","�
203 land Islands","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica",
204 "Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain",
205 "Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina",
206 "Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso",
207 "Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile",
208 "China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Congo, The Democratic Republic of The",
209 "Cook Islands","Costa Rica","Cote D'ivoire","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica",
210 "Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands (Malvinas)",
211 "Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon",
212 "Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala",
213 "Guernsey","Guinea","Guinea-bissau","Guyana","Haiti","Heard Island and Mcdonald Islands","Holy See (Vatican City State)",
214 "Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran, Islamic Republic of","Iraq","Ireland",
215 "Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kiribati","Korea, Democratic People's Republic of",
216 "Korea, Republic of","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia",
217 "Libyan Arab Jamahiriya","Liechtenstein","Lithuania","Luxembourg","Macao","Macedonia, The Former Yugoslav Republic of",
218 "Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius",
219 "Mayotte","Mexico","Micronesia, Federated States of","Moldova, Republic of","Monaco","Mongolia","Montenegro","Montserrat",
220 "Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","Netherlands Antilles","New Caledonia",
221 "New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Northern Mariana Islands","Norway","Oman",
222 "Pakistan","Palau","Palestinian Territory, Occupied","Panama","Papua New Guinea","Paraguay","Peru","Philippines",
223 "Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saint Helena",
224 "Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and The Grenadines","Samoa",
225 "San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore",
226 "Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Georgia and The South Sandwich Islands",
227 "Spain","Sri Lanka","Sudan","Suriname","Svalbard and Jan Mayen","Swaziland","Sweden","Switzerland","Syrian Arab Republic",
228 "Taiwan, Province of China","Tajikistan","Tanzania, United Republic of","Thailand","Timor-leste","Togo","Tokelau",
229 "Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine",
230 "United Arab Emirates","United Kingdom","United States","United States Minor Outlying Islands","Uruguay","Uzbekistan",
231 "Vanuatu","Venezuela","Viet Nam","Virgin Islands, British","Virgin Islands, U.S.","Wallis and Futuna","Western Sahara",
232 "Yemen","Zambia","Zimbabwe" );
233
234 add_option( 'wpforo_countries', $countries );
235
236 #################################################################
237 // Forum Navigation and Menu ////////////////////////////////////
238 $menu_name = wpforo_phrase('wpForo Navigation', false, 'orig');
239 $menu_location = 'wpforo-menu';
240 $menu_exists = wp_get_nav_menu_object( $menu_name );
241 if(!$menu_exists){
242 $id = array();
243 $menu_id = wp_create_nav_menu($menu_name);
244 $id['wpforo-home'] = wp_update_nav_menu_item($menu_id, 0, array(
245 'menu-item-title' => wpforo_phrase('Forums', false),
246 'menu-item-classes' => 'wpforo-home',
247 'menu-item-url' => '/%wpforo-home%/',
248 'menu-item-status' => 'publish',
249 'menu-item-parent-id' => 0,
250 'menu-item-position' => 0));
251
252 $id['wpforo-members'] = wp_update_nav_menu_item($menu_id, 0, array(
253 'menu-item-title' => wpforo_phrase('Members', false),
254 'menu-item-classes' => 'wpforo-members',
255 'menu-item-url' => '/%wpforo-members%/',
256 'menu-item-status' => 'publish',
257 'menu-item-parent-id' => 0,
258 'menu-item-position' => 0));
259
260 $id['wpforo-profile'] = wp_update_nav_menu_item($menu_id, 0, array(
261 'menu-item-title' => wpforo_phrase('My Profile', false),
262 'menu-item-classes' => 'wpforo-profile',
263 'menu-item-url' => '/%wpforo-profile-home%/',
264 'menu-item-status' => 'publish',
265 'menu-item-parent-id' => 0,
266 'menu-item-position' => 0));
267
268 if(isset($id['wpforo-profile']) && $id['wpforo-profile']){
269 $id['wpforo-profile-account'] = wp_update_nav_menu_item($menu_id, 0, array(
270 'menu-item-title' => wpforo_phrase('Account', false),
271 'menu-item-classes' => 'wpforo-profile-account',
272 'menu-item-url' => '/%wpforo-profile-account%/',
273 'menu-item-status' => 'publish',
274 'menu-item-parent-id' => $id['wpforo-profile'],
275 'menu-item-position' => 1)
276 );
277 $id['wpforo-profile-activity'] = wp_update_nav_menu_item($menu_id, 0, array(
278 'menu-item-title' => wpforo_phrase('Activity', false),
279 'menu-item-classes' => 'wpforo-profile-activity',
280 'menu-item-url' => '/%wpforo-profile-activity%/',
281 'menu-item-status' => 'publish',
282 'menu-item-parent-id' => $id['wpforo-profile'],
283 'menu-item-position' => 1)
284 );
285 $id['wpforo-profile-subscriptions'] = wp_update_nav_menu_item($menu_id, 0, array(
286 'menu-item-title' => wpforo_phrase('Subscriptions', false),
287 'menu-item-classes' => 'wpforo-profile-subscriptions',
288 'menu-item-url' => '/%wpforo-profile-subscriptions%/',
289 'menu-item-status' => 'publish',
290 'menu-item-parent-id' => $id['wpforo-profile'],
291 'menu-item-position' => 2)
292 );
293 }
294
295 $id['wpforo-register'] = wp_update_nav_menu_item($menu_id, 0, array(
296 'menu-item-title' => wpforo_phrase('Register', false),
297 'menu-item-classes' => 'wpforo-register',
298 'menu-item-url' => '/%wpforo-register%/',
299 'menu-item-status' => 'publish',
300 'menu-item-parent-id' => 0,
301 'menu-item-position' => 0));
302
303 $id['wpforo-login'] = wp_update_nav_menu_item($menu_id, 0, array(
304 'menu-item-title' => wpforo_phrase('Login', false),
305 'menu-item-classes' => 'wpforo-login',
306 'menu-item-url' => '/%wpforo-login%/',
307 'menu-item-status' => 'publish',
308 'menu-item-parent-id' => 0,
309 'menu-item-position' => 0));
310
311 $id['wpforo-logout'] = wp_update_nav_menu_item($menu_id, 0, array(
312 'menu-item-title' => wpforo_phrase('Logout', false),
313 'menu-item-classes' => 'wpforo-logout',
314 'menu-item-url' => '/%wpforo-logout%/',
315 'menu-item-status' => 'publish',
316 'menu-item-parent-id' => 0,
317 'menu-item-position' => 0));
318
319 if( !has_nav_menu( $menu_location ) ){
320 $locations = get_theme_mod('nav_menu_locations');
321 if(empty($locations)) $locations = array();
322 $locations[$menu_location] = $menu_id;
323 set_theme_mod( 'nav_menu_locations', $locations );
324 }
325 }
326
327 #################################################################
328 // Forum Access Array ///////////////////////////////////////////
329 $forum_cans = array (
330 'vf' => 'Can view forum',
331 'ct' => 'Can create topic',
332 'vt' => 'Can view topic',
333 'et' => 'Can edit topic',
334 'dt' => 'Can delete topic',
335 'cr' => 'Can post reply',
336 'vr' => 'Can view replies',
337 'er' => 'Can edit replies',
338 'dr' => 'Can delete replies',
339 'eot' => 'Can edit own topic',
340 'eor' => 'Can edit own reply',
341 'dot' => 'Can delete own topic',
342 'dor' => 'Can delete own reply',
343 'l' => 'Can like',
344 'r' => 'Can report',
345 's' => 'Can set topic sticky',
346 'p' => 'Can set topic private',
347 'op' => 'Can set own topic private',
348 'vp' => 'Can view private topic',
349 'au' => 'Can approve/unapprove content',
350 'sv' => 'Can set topic solved',
351 'osv' => 'Can set own topic solved',
352 'v' => 'Can vote',
353 'a' => 'Can attach file',
354 'va' => 'Can view attached files',
355 'at' => 'Can set topic answered',
356 'oat' => 'Can set own topic answered',
357 'cot' => 'Can close topic',
358 'mt' => 'Can move topic'
359 );
360 wpforo_update_options( 'wpforo_forum_cans', $forum_cans);
361
362 #################################################################
363 // Access Sets //////////////////////////////////////////////////
364 $cans_n = array('vf' => 0, 'ct' => 0, 'vt' => 0, 'et' => 0, 'dt' => 0,
365 'cr' => 0, 'vr' => 0, 'er' => 0, 'dr' => 0,
366 'eot' => 0, 'eor' => 0, 'dot' => 0, 'dor' => 0,
367 'l' => 0, 'r' => 0, 's' => 0, 'au' => 0, 'p' => 0, 'op' => 0, 'vp' => 0, 'sv' => 0, 'osv' => 0, 'v' => 0, 'a' => 0, 'va' => 0,
368 'at' => 0, 'oat' => 0, 'cot' => 0, 'mt' => 0);
369 $cans_r = array('vf' => 1, 'ct' => 0, 'vt' => 1, 'et' => 0, 'dt' => 0,
370 'cr' => 0, 'vr' => 1, 'er' => 0, 'dr' => 0,
371 'eot' => 0, 'eor' => 0, 'dot' => 0, 'dor' => 0,
372 'l' => 0, 'r' => 0, 's' => 0, 'au' => 0, 'p' => 0, 'op' => 0, 'vp' => 0, 'sv' => 0, 'osv' => 0, 'v' => 0, 'a' => 0, 'va' => 1,
373 'at' => 0, 'oat' => 0, 'cot' => 0, 'mt' => 0);
374 $cans_s = array('vf' => 1, 'ct' => 1, 'vt' => 1, 'et' => 0, 'dt' => 0,
375 'cr' => 1, 'vr' => 1, 'er' => 0, 'dr' => 0,
376 'eot' => 1, 'eor' => 1, 'dot' => 1, 'dor' => 1,
377 'l' => 1, 'r' => 1, 's' => 0, 'au' => 0, 'p' => 0, 'op' => 1, 'vp' => 0, 'sv' => 0, 'osv' => 1, 'v' => 1, 'a' => 1, 'va' => 1,
378 'at' => 0, 'oat' => 1, 'cot' => 0, 'mt' => 0);
379 $cans_m = array('vf' => 1, 'ct' => 1, 'vt' => 1, 'et' => 1, 'dt' => 1,
380 'cr' => 1, 'vr' => 1, 'er' => 1, 'dr' => 1,
381 'eot' => 1, 'eor' => 1, 'dot' => 1, 'dor' => 1,
382 'l' => 1, 'r' => 1, 's' => 1, 'au' => 1, 'p' => 1, 'op' => 1, 'vp' => 1, 'sv' => 1, 'osv' => 1, 'v' => 1, 'a' => 1, 'va' => 1,
383 'at' => 1, 'oat' => 1, 'cot' => 1, 'mt' => 1);
384 $cans_a = array('vf' => 1, 'ct' => 1, 'vt' => 1, 'et' => 1, 'dt' => 1,
385 'cr' => 1, 'vr' => 1, 'er' => 1, 'dr' => 1,
386 'eot' => 1, 'eor' => 1, 'dot' => 1, 'dor' => 1,
387 'l' => 1, 'r' => 1, 's' => 1, 'au' => 1, 'p' => 1, 'op' => 1, 'vp' => 1, 'sv' => 1, 'osv' => 1, 'v' => 1, 'a' => 1, 'va' => 1,
388 'at' => 1, 'oat' => 1, 'cot' => 1, 'mt' => 1);
389
390 $sql = "SELECT * FROM `".$wpforo->db->prefix."wpforo_accesses`";
391 $accesses = $wpforo->db->get_results($sql, ARRAY_A);
392 if( empty($accesses) ){
393
394 $cans_n = serialize($cans_n);
395 $cans_r = serialize($cans_r);
396 $cans_s = serialize($cans_s);
397 $cans_m = serialize($cans_m);
398 $cans_a = serialize($cans_a);
399
400 $sql = "INSERT IGNORE INTO `".$wpforo->db->prefix."wpforo_accesses`
401 (`access`, `title`, cans) VALUES
402 ('no_access', 'No access', '". $cans_n ."'),
403 ('read_only', 'Read only access', '". $cans_r ."'),
404 ('standard', 'Standard access', '". $cans_s ."'),
405 ('moderator', 'Moderator access', '".$cans_m."'),
406 ('full', 'Full access', '".$cans_a."')";
407
408 $wpforo->db->query( $sql );
409 }
410 else{
411 foreach($accesses as $access){
412 $default = array();
413 $data_update = array();
414 $current = unserialize($access['cans']);
415 if( strtolower($access['access']) == 'no_access' ) $default = $cans_n;
416 elseif( strtolower($access['access']) == 'read_only' ) $default = $cans_r;
417 elseif( strtolower($access['access']) == 'standard' ) $default = $cans_s;
418 elseif( strtolower($access['access']) == 'moderator' ) $default = $cans_m;
419 elseif( strtolower($access['access']) == 'full' ) $default = $cans_a;
420 if( !empty($default) ){
421 $data_update = array_merge($default, $current);
422 if( !empty($data_update) ){
423 $data_update = serialize($data_update);
424 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_accesses` SET `cans` = '" . $wpforo->db->_real_escape($data_update) . "' WHERE `accessid` = " . intval($access['accessid']) );
425 }
426 }
427 }
428 }
429
430
431 #################################################################
432 // Usergroup Cans ///////////////////////////////////////////////
433 $usergroup_cans = array (
434 'cf' => 'Dashboard - Can create forum',
435 'ef' => 'Dashboard - Can edit forum',
436 'df' => 'Dashboard - Can delete forum',
437 'vm' => 'Dashboard - Members Menu',
438 'aum' => 'Dashboard - Moderation Menu',
439 'em' => 'Dashboard - Can edit member',
440 'bm' => 'Dashboard - Can ban member',
441 'dm' => 'Dashboard - Can delete member',
442 'vmg' => 'Dashboard - Usergroup Menu',
443 'aup' => 'Front - Can pass moderation',
444 'vmem' => 'Front - Can view members',
445 'vprf' => 'Front - Can view profiles',
446 'upa' => 'Front - Can upload avatar',
447 'ups' => 'Front - Can have signature',
448 'va' => 'Front - Can view avatars',
449 'vmu' => 'Front - Can view member username',
450 'vmm' => 'Front - Can view member email',
451 'vmt' => 'Front - Can view member title',
452 'vmct' => 'Front - Can view member custom title',
453 'vmr' => 'Front - Can view member reputation',
454 'vmw' => 'Front - Can view member website',
455 'vmsn' => 'Front - Can view member social networks',
456 'vmrd' => 'Front - Can view member reg. date',
457 'vmlad'=> 'Front - Can view member last active date',
458 'vip' => 'Front - Can view member ip address',
459 'vml' => 'Front - Can view member location',
460 'vmo' => 'Front - Can view member occupation',
461 'vms' => 'Front - Can view member signature',
462 'vmam' => 'Front - Can view member about me',
463 'vmpn' => 'Front - Can view member phone number',
464 'vwpm' => 'Front - Can write PM'
465 );
466 wpforo_update_options( 'wpforo_usergroup_cans', $usergroup_cans );
467
468 #################################################################
469 // Usergroup ////////////////////////////////////////////////////
470 $cans_admin = array('cf' => '1', 'ef' => '1', 'df' => '1', 'vm' => '1', 'aum' => '1', 'em' => '1', 'vmg' => '1', 'aup' => '1', 'vmem' => '1', 'vprf' => '1',
471 'bm' => '1', 'dm' => '1', 'upa' => '1', 'ups' => '1', 'va' => '1',
472 'vmu' => '1', 'vmm' => '1', 'vmt' => '1', 'vmct' => '1',
473 'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1',
474 'vmlad' => '1', 'vip' => '1', 'vml' => '1', 'vmo' => '1',
475 'vms' => '1', 'vmam' => '1', 'vmpn' => '1', 'vwpm' => '1');
476 $cans_moder = array('cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '1', 'em' => '0', 'vmg' => '0', 'aup' => '1', 'vmem' => '1', 'vprf' => '1',
477 'bm' => '1', 'dm' => '1', 'upa' => '1', 'ups' => '1', 'va' => '1',
478 'vmu' => '1', 'vmm' => '1', 'vmt' => '1', 'vmct' => '1',
479 'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1',
480 'vmlad' => '1', 'vip' => '1', 'vml' => '1', 'vmo' => '1',
481 'vms' => '1', 'vmam' => '1', 'vmpn' => '1', 'vwpm' => '1');
482 $cans_reg = array( 'cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '0', 'em' => '0', 'vmg' => '0', 'aup' => '1', 'vmem' => '1', 'vprf' => '1',
483 'bm' => '0', 'dm' => '0', 'upa' => '1', 'ups' => '1', 'va' => '1',
484 'vmu' => '1', 'vmm' => '0', 'vmt' => '1', 'vmct' => '1',
485 'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1',
486 'vmlad' => '1', 'vip' => '0', 'vml' => '1', 'vmo' => '1',
487 'vms' => '1', 'vmam' => '1', 'vmpn' => '0', 'vwpm' => '1');
488 $cans_guest = array('cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '0', 'em' => '0', 'vmg' => '0', 'aup' => '0', 'vmem' => '1', 'vprf' => '1',
489 'bm' => '0', 'dm' => '0', 'upa' => '0', 'ups' => '0', 'va' => '0',
490 'vmu' => '0', 'vmm' => '0', 'vmt' => '0', 'vmct' => '0',
491 'vmr' => '1', 'vmw' => '0', 'vmsn' => '1', 'vmrd' => '0',
492 'vmlad' => '1', 'vip' => '0', 'vml' => '1', 'vmo' => '1',
493 'vms' => '0', 'vmam' => '1', 'vmpn' => '0', 'vwpm' => '0');
494 $cans_customer = array( 'cf' => '0', 'ef' => '0', 'df' => '0', 'vm' => '0', 'aum' => '0', 'em' => '0', 'vmg' => '0', 'aup' => '0', 'vmem' => '1', 'vprf' => '1',
495 'bm' => '0', 'dm' => '0', 'upa' => '1', 'ups' => '1', 'va' => '1',
496 'vmu' => '1', 'vmm' => '0', 'vmt' => '1', 'vmct' => '1',
497 'vmr' => '1', 'vmw' => '1', 'vmsn' => '1', 'vmrd' => '1',
498 'vmlad' => '1', 'vip' => '0', 'vml' => '1', 'vmo' => '1',
499 'vms' => '1', 'vmam' => '1', 'vmpn' => '0', 'vwpm' => '1');
500
501
502 $sql = "SELECT * FROM `".$wpforo->db->prefix."wpforo_usergroups`";
503 $usergroups = $wpforo->db->get_results($sql, ARRAY_A);
504 if( empty($usergroups) ){
505 $cans_admin = serialize( $cans_admin );
506 $cans_moder = serialize( $cans_moder );
507 $cans_reg = serialize( $cans_reg );
508 $cans_guest = serialize( $cans_guest );
509 $cans_customer = serialize( $cans_customer );
510 $sql = "INSERT IGNORE INTO `".$wpforo->db->prefix."wpforo_usergroups`
511 (`name`, `cans`) VALUES ('Admin', '$cans_admin'),('Moderator', '$cans_moder'),('Registered', '$cans_reg'),('Guest', '$cans_guest'),('Customer', '$cans_customer')";
512 $wpforo->db->query($sql);
513 }
514 else{
515 foreach($usergroups as $usergroup){
516 $default = array();
517 $data_update = array();
518 $current = unserialize($usergroup['cans']);
519 if( strtolower($usergroup['name']) == 'admin' ) $default = $cans_admin;
520 elseif( strtolower($usergroup['name']) == 'moderator' ) $default = $cans_moder;
521 elseif( strtolower($usergroup['name']) == 'registered' ) $default = $cans_reg;
522 elseif( strtolower($usergroup['name']) == 'guest' ) $default = $cans_guest;
523 elseif( strtolower($usergroup['name']) == 'customer' ) $default = $cans_customer;
524 if( !empty($default) ){
525 $data_update = array_merge($default, $current);
526 if( !empty($data_update) ){
527 $data_update = serialize($data_update);
528 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_usergroups` SET `cans` = '" . $wpforo->db->_real_escape($data_update) . "' WHERE `groupid` = " . intval($usergroup['groupid']) );
529 }
530 }
531 }
532 }
533 $sql = "SELECT COUNT(*) FROM `".$wpforo->db->prefix."wpforo_forums`";
534 $count = $wpforo->db->get_var($sql);
535 if(!$count){
536 if( $parentid = $wpforo->forum->add( array( 'title' => 'Main Category', 'description' => 'This is a simple category / section' ), FALSE ) ){
537 $wpforo->forum->add( array( 'title' => 'Main Forum', 'description' => 'This is a simple parent forum', 'parentid' => $parentid, 'icon' => 'fa-comments' ), FALSE );
538 }
539 }
540
541 #################################################################
542 // Permalink Settings ///////////////////////////////////////////
543 $permalink_structure = get_option( 'permalink_structure' );
544 if( !$permalink_structure ){
545 global $wp_rewrite;
546 $wp_rewrite->set_permalink_structure( '/%postname%/' );
547 }
548
549 #################################################################
550 // Creating Forum Page //////////////////////////////////////////
551 if( !$wpforo->pageid ||
552 !$wpforo->db->get_var("SELECT `ID` FROM `{$wpforo->db->prefix}posts` WHERE `ID` = '".intval($wpforo->pageid)."' AND ( `post_content` LIKE '%[wpforo]%' OR `post_content` LIKE '%[wpforo-index]%' ) AND `post_status` LIKE 'publish' AND `post_type` IN('post', 'page')") ){
553 if( !$page_id = $wpforo->db->get_var("SELECT `ID` FROM `{$wpforo->db->prefix}posts` WHERE `post_content` LIKE '%[wpforo]%' AND `post_status` LIKE 'publish' AND `post_type` IN('post', 'page')") ){
554 $wpforo_page = array(
555 'post_date' => current_time( 'mysql', 1 ),
556 'post_date_gmt' => current_time( 'mysql', 1 ),
557 'post_content' => '[wpforo]',
558 'post_title' => 'Forum',
559 'post_status' => 'publish',
560 'comment_status' => 'close',
561 'ping_status' => 'close',
562 'post_name' => 'community',
563 'post_modified' => current_time( 'mysql', 1 ),
564 'post_modified_gmt' => current_time( 'mysql', 1 ),
565 'post_parent' => 0,
566 'menu_order' => 0,
567 'post_type' => 'page'
568 );
569 $page_id = wp_insert_post( $wpforo_page );
570 }
571 if( $page_id && !is_wp_error($page_id) ){
572 update_option( 'wpforo_pageid', $page_id );
573 update_option( 'wpforo_use_home_url', '0' );
574 $wpforo_url = get_wpf_option('wpforo_url');
575 if( !$wpforo_url ){
576 update_option( 'wpforo_permastruct', 'community' );
577 update_option( 'wpforo_url', esc_url( home_url('/') ) . "community/" );
578 }else{
579 if( !$wpforo->permastruct ){
580 update_option( 'wpforo_permastruct', basename($wpforo_url) );
581 update_option( 'wpforo_url', esc_url( home_url('/') ) . basename($wpforo_url) . "/" );
582 }else{
583 update_option( 'wpforo_url', esc_url( home_url('/') ) . $wpforo->permastruct . "/" );
584 }
585 }
586 }
587 }else{
588 if( !$wpforo->use_home_url ) update_option( 'wpforo_use_home_url', '0' );
589 if( !$wpforo->permastruct ) update_option( 'wpforo_permastruct', basename( get_wpf_option('wpforo_url') ) );
590 $wpforo->db->query("UPDATE `{$wpforo->db->prefix}posts` SET `post_content` = REPLACE(`post_content`, '[wpforo-index]', '[wpforo]') WHERE `ID` = '{$wpforo->pageid}'");
591 }
592
593
594 #################################################################
595 // Importing Language Packs and Phrases /////////////////////////
596 $wpforo->phrase->xml_import('english.xml', 'install');
597
598 #################################################################
599 // Creating wpforo folders //////////////////////////////////////
600 $upload_array = wp_upload_dir();
601 $wpforo_upload_dir = $upload_array['basedir'].'/wpforo/';
602 if (!is_dir($wpforo_upload_dir)) {
603 wp_mkdir_p($wpforo_upload_dir);
604 }
605 $avatars_upload_dir=$upload_array['basedir'].'/wpforo/avatars/';
606 if (!is_dir($avatars_upload_dir)) {
607 wp_mkdir_p($avatars_upload_dir);
608 }
609
610 #################################################################
611 // RESET USER CACHE /////////////////////////////////////////////
612 $wpforo->member->clear_db_cache();
613
614 #################################################################
615 // RESET FUNCTIONS //////////////////////////////////////////////
616 $sql = "SHOW COLUMNS FROM `".$wpdb->prefix."wpforo_phrases` WHERE `Field` LIKE 'package'";
617 if( !$wpdb->get_row($sql, ARRAY_A) ){
618 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_phrases` ADD COLUMN `package` VARCHAR(255) NOT NULL DEFAULT 'wpforo'";
619 @$wpdb->query( $sql );
620 }
621 $wpforo->phrase->clear_cache();
622
623 #################################################################
624 // FIX TOPIC TABLE DATE DEFAULT VALUE | ADD PRIVATE COL//////////
625 $args = array( 'table' => $wpdb->prefix . 'wpforo_topics', 'col' => 'created', 'check' => 'default_value' );
626 $value = wpforo_db_check( $args );
627 if( $value == '0000-00-00 00:00:00' ){
628 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_topics` CHANGE `created` `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `modified` `modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;";
629 @$wpdb->query( $sql );
630 }
631 // ADD `private` field in TOPIC TABLE ///////////////////////////
632 $args = array( 'table' => $wpdb->prefix . 'wpforo_topics', 'col' => 'private', 'check' => 'col_exists' );
633 if( !wpforo_db_check( $args ) ){
634 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_topics` ADD `private` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX `is_private` (`private`);";
635 @$wpdb->query( $sql );
636 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_topics` ADD INDEX `own_private` ( `userid`, `private`);";
637 @$wpdb->query( $sql );
638 }
639 // ADD INDEXES in wpforo_views TABLE///////////////////////////
640 $args = array( 'table' => $wpdb->prefix . 'wpforo_views', 'col' => 'topicid', 'check' => 'key_exists' );
641 if( !wpforo_db_check( $args ) ){
642 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_views` ADD INDEX(`userid`);";
643 @$wpdb->query( $sql );
644 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_views` ADD INDEX(`topicid`);";
645 @$wpdb->query( $sql );
646 }
647 $args = array( 'table' => $wpdb->prefix . 'wpforo_views', 'col' => 'created', 'check' => 'col_type' );
648 $col_type = wpforo_db_check( $args );
649 if( $col_type != 'int(11)' ){
650 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_views` CHANGE `created` `created` INT(11) NOT NULL;";
651 @$wpdb->query( $sql );
652 }
653
654 // ADD `status` field in TOPICS & POSTS TABLE ///////////////////////////
655 $args = array( 'table' => $wpdb->prefix . 'wpforo_topics', 'col' => 'status', 'check' => 'col_exists' );
656 if( !wpforo_db_check( $args ) ){
657 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_topics` ADD `status` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX `status` (`status`);";
658 @$wpdb->query( $sql );
659 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_topics` ADD INDEX `forumid_status` ( `forumid`, `status`);";
660 @$wpdb->query( $sql );
661 }
662 $args = array( 'table' => $wpdb->prefix . 'wpforo_posts', 'col' => 'status', 'check' => 'col_exists' );
663 if( !wpforo_db_check( $args ) ){
664 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_posts` ADD `status` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX `status` (`status`);";
665 @$wpdb->query( $sql );
666 $sql = "ALTER TABLE `".$wpdb->prefix."wpforo_posts` ADD INDEX `topicid_status` ( `topicid`, `status`);";
667 @$wpdb->query( $sql );
668 }
669
670 #################################################################
671 // UPDATE VERSION - END /////////////////////////////////////////
672 update_option('wpforo_version', WPFORO_VERSION);
673 $wpforo->notice->clear();
674 }
675
676
677 function wpforo_update() {
678 if ( get_option('wpforo_version') && WPFORO_VERSION !== get_option('wpforo_version') ) wpforo_activation();
679 }
680 add_action('plugins_loaded', 'wpforo_update');
681
682
683 function wpforo_update_options( $option_key, $default, $exlude = array() ) {
684
685 $option = get_option( $option_key, array() );
686
687 if( !empty($option) ){
688 if( !empty($exlude) ){
689 foreach( $exlude as $key ){
690 if( isset($default[$key]) ) unset($default[$key]);
691 }
692 }
693 $option_update = array_merge($default, $option);
694 }
695 else{
696 $option_update = $default;
697 }
698
699 update_option( $option_key, $option_update );
700 }
701
702
703 function wpforo_deactivation() {}
704
705
706 function wpforo_uninstall() {
707
708 global $wpforo, $wpdb;
709
710 if( ! wpforo_is_admin() ) return;
711 if( ! current_user_can( 'activate_plugins' ) ) return;
712 $QUERY_STRING = trim(preg_replace('|_wpnonce=[^\&\?\=]*|is', '', $_SERVER['QUERY_STRING']), '&');
713
714 if( 'action=wpforo-uninstall' == trim($QUERY_STRING) ){
715
716 $tables = array( $wpdb->prefix . 'wpforo_accesses',
717 $wpdb->prefix . 'wpforo_forums',
718 $wpdb->prefix . 'wpforo_languages',
719 $wpdb->prefix . 'wpforo_likes',
720 $wpdb->prefix . 'wpforo_phrases',
721 $wpdb->prefix . 'wpforo_profiles',
722 $wpdb->prefix . 'wpforo_posts',
723 $wpdb->prefix . 'wpforo_subscribes',
724 $wpdb->prefix . 'wpforo_topics',
725 $wpdb->prefix . 'wpforo_usergroups',
726 $wpdb->prefix . 'wpforo_views',
727 $wpdb->prefix . 'wpforo_votes');
728
729 foreach($tables as $table){
730 if( strpos( $table, '_wpforo_' ) !== FALSE){
731 $sql = "DROP TABLE IF EXISTS `$table`;";
732 $wpdb->query( $sql );
733 }
734 }
735
736 if( isset($wpforo->pageid) && $wpforo->pageid ){
737 wp_delete_post( $wpforo->pageid, true );
738 }
739
740 $options = array( 'wpforo_version',
741 'wpforo_url',
742 'wpforo_general_options',
743 'wpforo_pageid',
744 'wpforo_count_per_page',
745 'wpforo_default_groupid',
746 'wpforo_usergroup_cans',
747 'wpforo_forum_options',
748 'wpforo_forum_cans',
749 'wpforo_post_options',
750 'wpforo_member_options',
751 'wpforo_subscribe_options',
752 'wpforo_countries',
753 'wpforo_theme_options',
754 'wpforo_features',
755 'wpforo_style_options',
756 'wpforo_permastruct',
757 'wpforo_use_home_url',
758 'wpforo_excld_urls',
759 'wpforo_tools_antispam'
760 );
761
762 foreach($options as $option){
763 if( strpos( $option, 'wpforo_' ) !== FALSE){
764 delete_option( $option );
765 }
766 }
767
768 $wpdb->query( "DELETE FROM `" . $wpdb->base_prefix ."usermeta` WHERE `meta_key` = '_wpf_member_obj'" );
769 $wpdb->query( "DELETE FROM `" . $wpdb->prefix ."options` WHERE option_name LIKE 'widget_wpforo_widget_%'" );
770
771 $menu = wp_get_nav_menu_object( 'wpforo-navigation' );
772 wp_delete_nav_menu( $menu->term_id );
773 wp_delete_post($wpforo->pageid, TRUE);
774
775 deactivate_plugins( WPFORO_BASENAME );
776
777 }
778 else{
779 return;
780 }
781 }
782
783 ?>