WP Multisite and WP_w3all phpBB WordPress integration

User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

WP Multisite and WP_w3all phpBB WordPress integration

Post by axew3 »

This topic is for testing purpose about WorPress phpBB integration plugin into a WordPress Multisite installation.

Open class.wp.w3all-phpbb.php file
search for:

Code: Select all

//############################################
// END PHPBB TO WP FUNCTIONS
//############################################
immediately AFTER add the follow:

Code: Select all

//############################################
// START X WP MS MU
//############################################

public static function create_phpBB_user_wpms_res($username = '', $user_email = '', $key = '', $meta = ''){
	
      $r = self::create_phpBB_user_wpms($username, $user_email, $key, $meta);                                 
	   return $r; 
}

public static function wp_w3all_wp_after_pass_reset_msmu( $user ) { 
	
	 global $w3all_config,$wpdb;
	
	$w3db_conn = self::wp_w3all_phpbb_conn_init();
	$phpbb_config_file = $w3all_config;
 
		$user_email_hash = self::w3all_phpbb_email_hash($user->user_email);

			$res = $w3db_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."users SET user_password = '".$user->user_pass."' WHERE user_email_hash = '".$user_email_hash."'");
}

private static function create_phpBB_user_wpms($username = '', $user_email = '', $key = '', $meta = ''){
	
	global $w3all_config, $w3all_phpbb_lang_switch_yn;
   $phpbb_config_file = $w3all_config;
	 $w3phpbb_conn = self::w3all_db_connect();
   $phpbb_config = unserialize(W3PHPBBCONFIG);
   $wp_lang = get_option('WPLANG');

   		if(empty($wp_lang) OR $w3all_phpbb_lang_switch_yn == 0 ){ // wp lang for this user ISO 639-1 Code. en_EN // en = Lang code _ EN = Country code
   		   $wp_lang_x_phpbb = 'en'; // no lang setting, assume en by default
   			} else { 
   				 $wp_lang_x_phpbb = strtolower(substr($wp_lang, 0, strpos($wp_lang, '_'))); // should extract Lang code ISO Code that is phpBB suitable for this lang
   				}

    if( empty($username) OR empty($user_email) ){ return; }
     
     //maybe to be added as option
     // if you wish to setup gravatar by default into phpBB profile for the user when register in WP
     $uavatar = $avatype = ''; // this not will affect queries if the two here below are or not commented out 
     //$uavatar = get_option('show_avatars') == 1 ? $wpu->user_email : '';
     //$avatype = (empty($uavatar)) ? '' : 'avatar.driver.gravatar';
     
     $username = esc_sql($username);

            $u = $phpbb_config["cookie_name"].'_u';
            
            if ( preg_match('/[^0-9]/',$_COOKIE[$u]) ){
 	           	
                die( "Clean up cookie on your browser please!" );
 	            }
 	            
 	           $phpbb_u = $_COOKIE[$u];
 	        
 	    // only need to fire when user do not exist on phpBB already, and/or user is an admin that add an user manually 
   if ( $phpbb_u < 2 OR !empty($phpbb_u) && current_user_can( 'manage_options' ) === true ) {
      
      $phpbb_user_type = 1; //  set to 1 as deactivated on phpBB on WP MSMU
	    $user_email_hash = self::w3all_phpbb_email_hash($user_email);
	     
      $wpur = time();
      $wpul = $username;
      $wpup = md5(mt_rand(5,10) . microtime() . str_shuffle("ALEa0bc1AdeOf28P3ghEij4kRlm5nopqrD0Lst9uvwx9yzSSIO" . microtime()) . mt_rand(10,20)); // a temp pass to be updated after signup finished
      $wpup = self::phpBB_password_hash($wpup); // a temp pass, even not necessary as the user is not active at this point for wp msmu
      $wpue = $user_email;
      $time = time();
      
      $wpunn = esc_sql(utf8_encode(strtolower($wpul)));
      $wpul  = esc_sql($wpul);
      $w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."users (user_id, user_type, group_id, user_permissions, user_perm_from, user_ip, user_regdate, username, username_clean, user_password, user_passchg, user_email, user_email_hash, user_birthday, user_lastvisit, user_lastmark, user_lastpost_time, user_lastpage, user_last_confirm_key, user_last_search, user_warnings, user_last_warning, user_login_attempts, user_inactive_reason, user_inactive_time, user_posts, user_lang, user_timezone, user_dateformat, user_style, user_rank, user_colour, user_new_privmsg, user_unread_privmsg, user_last_privmsg, user_message_rules, user_full_folder, user_emailtime, user_topic_show_days, user_topic_sortby_type, user_topic_sortby_dir, user_post_show_days, user_post_sortby_type, user_post_sortby_dir, user_notify, user_notify_pm, user_notify_type, user_allow_pm, user_allow_viewonline, user_allow_viewemail, user_allow_massemail, user_options, user_avatar, user_avatar_type, user_avatar_width, user_avatar_height, user_sig, user_sig_bbcode_uid, user_sig_bbcode_bitfield, user_jabber, user_actkey, user_newpasswd, user_form_salt, user_new, user_reminded, user_reminded_time)
         VALUES ('','$phpbb_user_type','2','','0','', '$wpur', '$wpul', '$wpunn', '$wpup', '0', '$wpue', '$user_email_hash', '', '', '', '', '', '', '0', '0', '0', '0', '0', '0', '0', '$wp_lang_x_phpbb', 'Europe/Rome', 'D M d, Y g:i a', '1', '0', '', '0', '0', '0', '0', '-3', '0', '0', 't', 'd', 0, 't', 'a', '0', '1', '0', '1', '1', '1', '1', '230271', '$uavatar', '$avatype', '0', '0', '', '', '', '', '', '', '', '0', '0', '0')");
      
      $phpBBlid = $w3phpbb_conn->insert_id;
   
     $w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('2','$phpBBlid','0','0')");
     $w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('7','$phpBBlid','0','0')");

     $w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."acl_users (user_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ('$phpBBlid','0','0','6','0')");
    		
       $tot_users_count = $w3phpbb_conn->get_var("SELECT COUNT(*) FROM ".$phpbb_config_file["table_prefix"]."users WHERE group_id !='6' AND group_id !='1'");
 
     $w3phpbb_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."config SET config_value = '$tot_users_count' WHERE config_name = 'num_users'");

       $newest_member = $w3phpbb_conn->get_results("SELECT * FROM ".$phpbb_config_file["table_prefix"]."users WHERE user_id = (SELECT Max(user_id) FROM ".$phpbb_config_file["table_prefix"]."users) AND group_id != '6'");
       $uname = $newest_member[0]->username;
       $uid   = $newest_member[0]->user_id;
     
     $w3phpbb_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."config SET config_value = '$wpul' WHERE config_name = 'newest_username'");
     $w3phpbb_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."config SET config_value = '$uid' WHERE config_name = 'newest_user_id'");

 
 }// if cookie not set

}

//############################################
// END X WP MS MU
//############################################
Save. Now open: wp_w3all.php file
search for:

Code: Select all

} // END   if ( defined('PHPBB_INSTALLED') ){ // 2nd not in admin
immediately BEFORE add the follow:

Code: Select all

/////////////////////////   
// W3ALL WPMS MU START
/////////////////////////

function wpmu_activate_user_phpbb( $user_id, $password, $meta ) { 
  	 global $w3all_config,$w3all_phpbb_user_deactivated_yn;

	$w3db_conn = WP_w3all_phpbb::wp_w3all_phpbb_conn_init();
	$phpbb_config_file = $w3all_config;
  $user = get_user_by('id', $user_id);
  $user_info = get_userdata($user->ID);
  $wp_user_role = implode(', ', $user_info->roles);

		$phpbb_user_data = WP_w3all_phpbb::wp_w3all_get_phpbb_user_info($user->user_email);
     $password = WP_w3all_phpbb::phpBB_password_hash($password);
		if ( $phpbb_user_data[0]->user_type == 1 ) {
		 	$res = $w3db_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."users SET user_type = '0', user_password = '".$password."' WHERE user_email_hash = '".$phpbb_user_data[0]->user_email_hash."'");

     }
}
  
function w3all_wpmu_new_user_up_pass( $user_id ) { 

    $wpu  = get_user_by('id', $user_id);
    
    $phpBB_user_activate = WP_w3all_phpbb::wp_w3all_wp_after_pass_reset_msmu($wpu); // msmu: the pass updated is the one of WP
} 
         
function w3all_wpmu_new_user_signup( $user, $user_email, $key, $meta ) { 
	
    $phpBB_user_add = WP_w3all_phpbb::create_phpBB_user_wpms_res( $user, $user_email, $key, $meta );
}

  
function w3all_wpmu_validate_user_signup( $result ){
  	
           $wp_w3_ck_phpbb_ue_exist = WP_w3all_phpbb::phpBB_user_check($result['user_name'], $result['user_email'], 0);

         if($wp_w3_ck_phpbb_ue_exist === true){
            temp_wp_w3_error_on_update();
          exit;
         } 
         
    return $result; 
}

add_filter( 'wpmu_validate_user_signup', 'w3all_wpmu_validate_user_signup', 10, 1 );    
add_action( 'after_signup_user', 'w3all_wpmu_new_user_signup', 10, 4 );
add_action( 'wpmu_activate_user', 'wpmu_activate_user_phpbb', 10, 3 ); 
add_action( 'wpmu_new_user', 'w3all_wpmu_new_user_up_pass', 10, 1 ); 
 

/////////////////////////   
// W3ALL WPMS MU END
/////////////////////////
i can provide files instead of code if more comfortable. The code need some little adjustment more, but is working fine on my test at moment.
pennymachines
User www
User www
Posts: 78
Joined: Mon Feb 06, 2017 9:51 pm

Re: WP Multisite and WP_w3all phpBB WordPress integration

Post by pennymachines »

I think perhaps I should have posted this reply here - not in the original thread. sorry for the repeat post.

I cut and pasted the code into the two files as instructed.
When I activate the plugin in one of the subsites, I am immediately logged out of admin and sent to the front page (index.php).
I can only get back into that subsite admin by removing or renaming the plugin.
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: WP Multisite and WP_w3all phpBB WordPress integration

Post by axew3 »

ok yes!
Look, i will prepare in short a MU clean to test out and resolve definitively this issue.
As soon i can i will post in reply here changes, logs and going-on steps ... try to have all fixed about this for 1.6.9 release.

(as well all issue about iframe resolved once for all)
pennymachines
User www
User www
Posts: 78
Joined: Mon Feb 06, 2017 9:51 pm

Re: WP Multisite and WP_w3all phpBB WordPress integration

Post by pennymachines »

That's fantastic - I will eagerly await 1.6.9!

In the meantime, I have suggested a new English (UK) translation of the latest stable release (based upon my currently limited understanding of the plugin). Having done so, it occurs to me that all instances of 'Last Topic Posts' might be better rendered as 'Latest Forum Posts'.
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: WP Multisite and WP_w3all phpBB WordPress integration

Post by axew3 »

Here we should go.
Adding the entire going on 1.6.9 that include all buddypress fixes (we'll add all profile fields for buddypress on next, like google, twitter, fb etc) and WP Multisite fixes.
On my test, for what i've try, all is working.
The user is added as deactivated in phpBB when register WP multisite (to get a site or as single user) and so activated when activate the account.
The registration flow change in MU install: the user is temporary added into a signup table: the signup table leave for the deleted user in WP the gost account in this table, that remain for some day until expire.
To avoid problems with integration, in the case it is integrate with a phpBB where users can register phpBB side, when an user is deleted in WP, also the signup user will be cleaned about this user, to avoid problems about duplicated email-
SO a deleted user in WP is deactivated in phpBB, and removed from signup: the username become so immediately available.
Hope the explanation is clear (i do not think ... just trust me).
Please give when you can, a try/test, so we can follow releasing new version
going on coming WP_w3all 1.6.9 suitable for WP MU - Woocommerce and Buddypress
wp-w3all-phpbb-integration.zip
(134.9 KiB) Downloaded 207 times
p.s it is intended that here we cannot leave install plugin into a subsite, giving possibility to the owner to add his own different phpBB.
It is IMPOSSIBLE: to better say, is not impossible, but WP store users into a single table, and for each site divide into sub tables that i should see how are done to understand in case where to change things to get for each subsite, a different linked phpBB. And it should not be an easy job i imagine.

p.s oh god ... i see that the page leap/scroll to top when inserting a post ... what bad!
User avatar
kaspir
Moderator
Moderator
Posts: 88
Joined: Mon Mar 20, 2017 2:38 pm
Location: USA
Contact:

Re: WP Multisite and WP_w3all phpBB WordPress integration

Post by kaspir »

I don't use Multi-Site, and don't use BuddyPress. Hell, I don't even use the iframe you provide, which is sweet but just not for me. HOWEVER, I do use Woocommerce, and there is still a huge problem with widget logins after the 3.0 Woocommerce update. Still occurring after this update as well.

Code: Select all

Warning: Missing argument 2 for wc_maybe_store_user_agent(), called in /wp-includes/class-wp-hook.php on line 298 and defined in /wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 1516

Warning: Cannot modify header information - headers already sent by (output started at /wp-content/plugins/woocommerce/includes/wc-core-functions.php:1516) in /wp-includes/pluggable.php on line 1195
If I disable the w3all plugin, this error no longer occurs.

I did find that woocommerce added a new function in 3.0, residing on that line# 1516, here it is (having to do with $user, which it's claiming to be a missing argument.. $var is blank?!?!):

Code: Select all

/**
 * Store user agents. Used for tracker.
 * @since 3.0.0
 */
function wc_maybe_store_user_agent( $user_login, $user ) {
	if ( 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) && user_can( $user, 'manage_woocommerce' ) ) {
		$admin_user_agents   = array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) );
		$admin_user_agents[] = wc_get_user_agent();
		update_option( 'woocommerce_tracker_ua', array_unique( $admin_user_agents ) );
	}
}
add_action( 'wp_login', 'wc_maybe_store_user_agent', 10, 2 );
So if I'm correct, the problem resides here, in woocommerce? Can it even be fixed thru w3all by any chance?
Is there a woocommerce option I am missing? (I tried turning off woocommerce->geolocate->option but till get the error...)
Does any use Woocommerce and have this problem like me?
Image
World of Phaos RPG online is making it's come back! Play free now!
Check out phpBB contributions & extension downloads. :P
Post Reply