I confirmed this for another Test user.
Making a topic/post/reply in the phpBB forum somehow makes the avatar work.
Having a user logged in/created/previously existing on both PhpBB and Wordpress, and posting on Wordpress, does not make the connection to get the avatar working at all times.
Avatars via phpBB group Avatar
-
- Moderator
- Posts: 15
- Joined: Mon May 08, 2017 4:15 am
- axew3
- w3all User
- Posts: 2883
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: Avatars via phpBB group Avatar
the problem is maybe what you have before note, about the (example) _g2.jpg
if the user have not an avatar, and group is the avatar, but upload is the way in phpBB, the code fail.
while work if gallery. taking a dive in as soon
if the user have not an avatar, and group is the avatar, but upload is the way in phpBB, the code fail.
while work if gallery. taking a dive in as soon
- axew3
- w3all User
- Posts: 2883
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: Avatars via phpBB group Avatar
to resolve the above, this is the on fly pseudo code that work, function
public static function w3all_get_phpbb_avatars_url( $w3unames ) {
on class.wp.w3all-phpbb.php now should look like this, but i think there is one more to add, the remote image, i need to test this more
public static function w3all_get_phpbb_avatars_url( $w3unames ) {
on class.wp.w3all-phpbb.php now should look like this, but i think there is one more to add, the remote image, i need to test this more
Code: Select all
public static function w3all_get_phpbb_avatars_url( $w3unames ) {
global $w3all_config;
$config = $w3all_config;
$w3db_conn = self::w3all_db_connect();
//$phpbb_config = self::get_phpbb_config();
$phpbb_config = unserialize(W3PHPBBCONFIG);
// this not work by user_email_hash, but were necessary by username
// $uavatars = $w3db_conn->get_results( $w3db_conn->prepare("SELECT username, user_avatar, user_avatar_type FROM ".$config["table_prefix"]."users WHERE user_email_hash IN(%d) ORDER BY user_id DESC", $w3unames ));
$uavatars = $w3db_conn->get_results( "SELECT username, user_avatar, user_avatar_type FROM ".$config["table_prefix"]."users WHERE user_email_hash IN(".$w3unames.") ORDER BY user_id DESC" );
if(!empty($uavatars)){
foreach($uavatars as $user_ava) {
if(!empty($user_ava->user_avatar)){ // has been selected above by the way, check it need to be added
if ( $user_ava->user_avatar_type == 'avatar.driver.local' ){
$phpbb_avatar_url = get_option( 'w3all_url_to_cms' ) . '/' . $phpbb_config["avatar_gallery_path"] . '/' . $user_ava->user_avatar;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
} elseif ( $user_ava->user_avatar_type == 'avatar.driver.remote' ){
$phpbb_avatar_url = $user_ava->user_avatar;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
} else {
$avatar_entry = $user_ava->user_avatar;
$ext = substr(strrchr($avatar_entry, '.'), 1);
$avatar_entry = intval($avatar_entry);
if ( $user_ava->user_avatar_type == 'avatar.driver.upload' && preg_match('/^([g])([0-9]).*/', $user_ava->user_avatar, $w3m, PREG_OFFSET_CAPTURE) )
{
if($w3m[1][0] && $w3m[2][0]){
$gprefix = '_' . $w3m[1][0] . $w3m[2][0];
}
}
if ( $user_ava->user_avatar_type == 'avatar.driver.upload' ){
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . $gprefix . '.' . $ext;
} else {
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . '_' . $avatar_entry . '.' . $ext;
}
$phpbb_avatar_url = get_option( 'w3all_url_to_cms' ).'/'.$phpbb_config["avatar_path"].'/'.$phpbb_avatar_filename;
// in phpBB there is Gravatar as option available as profile image
// so if it is the case, the user at this point can have an email address, instead than an image url as value
// $pemail = '/^.*@[-a-z0-9]+\.+[-a-z0-9]+[\.[a-z0-9]+]?/';
// preg_match($pemail, $user_ava->user_avatar, $url_email);
// $phpbb_avatar_url = (empty($url_email)) ? $phpbb_avatar_url : $user_ava->user_avatar;
$phpbb_avatar_url = ( is_email( $user_ava->user_avatar ) !== false ) ? $user_ava->user_avatar : $phpbb_avatar_url;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
}
}
}
} else { $u_a = ''; }
$u_a = (empty($u_a)) ? '' : $u_a;
return $u_a;
}
- axew3
- w3all User
- Posts: 2883
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: Avatars via phpBB group Avatar
Thank you @Lepalose for your presence and hints ... ok, i've return over just now, and the definitive code, with little adjustments, that work with all is like that (so applied as patch into 1.7.1)
into file class.wp.w3all-phpbb.php, the function function w3all_get_phpbb_avatars_url() will be maybe:
into file class.wp.w3all-phpbb.php, the function function w3all_get_phpbb_avatars_url() will be maybe:
Code: Select all
public static function w3all_get_phpbb_avatars_url( $w3unames ) {
global $w3all_config;
$config = $w3all_config;
$w3db_conn = self::w3all_db_connect();
//$phpbb_config = self::get_phpbb_config();
$phpbb_config = unserialize(W3PHPBBCONFIG);
// this not work by user_email_hash, but were necessary by username
// $uavatars = $w3db_conn->get_results( $w3db_conn->prepare("SELECT username, user_avatar, user_avatar_type FROM ".$config["table_prefix"]."users WHERE user_email_hash IN(%d) ORDER BY user_id DESC", $w3unames ));
$uavatars = $w3db_conn->get_results( "SELECT username, user_avatar, user_avatar_type FROM ".$config["table_prefix"]."users WHERE user_email_hash IN(".$w3unames.") ORDER BY user_id DESC" );
if(!empty($uavatars)){
foreach($uavatars as $user_ava) {
if(!empty($user_ava->user_avatar)){ // has been selected above by the way, check it need to be added
if ( $user_ava->user_avatar_type == 'avatar.driver.local' ){
$phpbb_avatar_url = get_option( 'w3all_url_to_cms' ) . '/' . $phpbb_config["avatar_gallery_path"] . '/' . $user_ava->user_avatar;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
} elseif ( $user_ava->user_avatar_type == 'avatar.driver.remote' ){
$phpbb_avatar_url = $user_ava->user_avatar;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
} else {
$avatar_entry = $user_ava->user_avatar;
$ext = substr(strrchr($avatar_entry, '.'), 1);
$avatar_entry = intval($avatar_entry);
if ( $user_ava->user_avatar_type == 'avatar.driver.upload' && preg_match('/^([g])([0-9]+).*/', $user_ava->user_avatar, $w3m, PREG_OFFSET_CAPTURE) )
{
if($w3m[1][0] && $w3m[2][0]){
$gprefix = '_' . $w3m[1][0] . $w3m[2][0];
}
}
if ( $user_ava->user_avatar_type == 'avatar.driver.upload' && isset($gprefix) ){
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . $gprefix . '.' . $ext;
} else {
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . '_' . $avatar_entry . '.' . $ext;
}
$phpbb_avatar_url = get_option( 'w3all_url_to_cms' ).'/'.$phpbb_config["avatar_path"].'/'.$phpbb_avatar_filename;
// in phpBB there is Gravatar as option available as profile image
// so if it is the case, the user at this point can have an email address, instead than an image url as value
// $pemail = '/^.*@[-a-z0-9]+\.+[-a-z0-9]+[\.[a-z0-9]+]?/';
// preg_match($pemail, $user_ava->user_avatar, $url_email);
// $phpbb_avatar_url = (empty($url_email)) ? $phpbb_avatar_url : $user_ava->user_avatar;
$phpbb_avatar_url = ( is_email( $user_ava->user_avatar ) !== false ) ? $user_ava->user_avatar : $phpbb_avatar_url;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
}
}
}
} else { $u_a = ''; }
$u_a = (empty($u_a)) ? '' : $u_a;
return $u_a;
}
- axew3
- w3all User
- Posts: 2883
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: Avatars via phpBB group Avatar
class.wp.w3all-phpbb.php has been updated on repository to fix this bug:
https://plugins.trac.wordpress.org/brow ... tion/trunk
Now all should work fine on any possible avatar configuration.
Please, follow with hints and hits when possible and let know if still any problem!
https://plugins.trac.wordpress.org/brow ... tion/trunk
Now all should work fine on any possible avatar configuration.
Please, follow with hints and hits when possible and let know if still any problem!
-
- Moderator
- Posts: 15
- Joined: Mon May 08, 2017 4:15 am
Re: Avatars via phpBB group Avatar
Okay, so I put in that code, and it has a different issue.
For a user with a Personal Avatar uploaded as a .png with the 'avatar.driver.upload' this is not working correctly. It returns a 'g' even though the identity does not have one.
Honestly, the code I suggested is working fine for this issue in grabbing avatars - note that the avatar.driver.upload does not need a specific statement, as it works with this code:
Note: I commented out the new code, and just went back to the str_tok to grab the correct avatar id value without the additional checks.
This solves finding the correct avatar regardless if there is a string in the prefix or not. That is it will find a group avatar, or a user's personal avatar correctly.
I am not exactly sure what happened with your code, but I ended up with an $avatar_entry of 'g8' instead of the correct $avatar_entry '48' for that user who had their own avatar uploaded. I think it may be possible that 'preg_match' is catching the 'g' in the .png of the user_avatar.
Thinking about your code further, does this only give one digit for group avatars? Would this fail if the group id is > 10?
For a user with a Personal Avatar uploaded as a .png with the 'avatar.driver.upload' this is not working correctly. It returns a 'g' even though the identity does not have one.
Honestly, the code I suggested is working fine for this issue in grabbing avatars - note that the avatar.driver.upload does not need a specific statement, as it works with this code:
Code: Select all
public static function w3all_get_phpbb_avatars_url( $w3unames ) {
global $w3all_config;
$config = $w3all_config;
$w3db_conn = self::w3all_db_connect();
//$phpbb_config = self::get_phpbb_config();
$phpbb_config = unserialize(W3PHPBBCONFIG);
// this not work by user_email_hash, but were necessary by username
// $uavatars = $w3db_conn->get_results( $w3db_conn->prepare("SELECT username, user_avatar, user_avatar_type FROM ".$config["table_prefix"]."users WHERE user_email_hash IN(%d) ORDER BY user_id DESC", $w3unames ));
$uavatars = $w3db_conn->get_results( "SELECT username, user_avatar, user_avatar_type FROM ".$config["table_prefix"]."users WHERE user_email_hash IN(".$w3unames.") ORDER BY user_id DESC" );
if(!empty($uavatars)){
foreach($uavatars as $user_ava) {
if(!empty($user_ava->user_avatar)){ // has been selected above by the way, check it need to be added
if ( $user_ava->user_avatar_type == 'avatar.driver.local' ){
$phpbb_avatar_url = get_option( 'w3all_url_to_cms' ) . '/' . $phpbb_config["avatar_gallery_path"] . '/' . $user_ava->user_avatar;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
} elseif ( $user_ava->user_avatar_type == 'avatar.driver.remote' ){
$phpbb_avatar_url = $user_ava->user_avatar;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
} else {
$avatar_entry = $user_ava->user_avatar;
$ext = substr(strrchr($avatar_entry, '.'), 1);
// $avatar_entry = intval($avatar_entry);
// LEPALOSE MODIFIED ABOVE LINE TO BELOW
$avatar_entry = strtok($avatar_entry, '_');
// LEPALOSE COMMENT OUT BELOW
// if ( $user_ava->user_avatar_type == 'avatar.driver.upload' && preg_match('/^([g])([0-9]+).*/', $user_ava->user_avatar, $w3m, PREG_OFFSET_CAPTURE) )
/* {
if($w3m[1][0] && $w3m[2][0]){ // this is a group avatar
$gprefix = '_' . $w3m[1][0] . $w3m[2][0]; // switch
}
}
if ( $user_ava->user_avatar_type == 'avatar.driver.upload' && isset($gprefix) ){ // switch
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . $gprefix . '.' . $ext;
} else {
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . '_' . $avatar_entry . '.' . $ext;
}
LEPALOSE END OF COMMENT OUT */
// LEPALOSE COPY ELSE LINE ABOVE TO THE LINE BELOW
$phpbb_avatar_filename = $phpbb_config["avatar_salt"] . '_' . $avatar_entry . '.' . $ext;
$phpbb_avatar_url = get_option( 'w3all_url_to_cms' ).'/'.$phpbb_config["avatar_path"].'/'.$phpbb_avatar_filename;
// in phpBB there is Gravatar as option available as profile image
// so if it is the case, the user at this point can have an email address, instead than an image url as value
// $pemail = '/^.*@[-a-z0-9]+\.+[-a-z0-9]+[\.[a-z0-9]+]?/';
// preg_match($pemail, $user_ava->user_avatar, $url_email);
// $phpbb_avatar_url = (empty($url_email)) ? $phpbb_avatar_url : $user_ava->user_avatar;
$phpbb_avatar_url = ( is_email( $user_ava->user_avatar ) !== false ) ? $user_ava->user_avatar : $phpbb_avatar_url;
$u_a[] = array("uname" => $user_ava->username, "uavaurl" => $phpbb_avatar_url);
}
}
}
} else { $u_a = ''; }
$u_a = (empty($u_a)) ? '' : $u_a;
return $u_a;
}
This solves finding the correct avatar regardless if there is a string in the prefix or not. That is it will find a group avatar, or a user's personal avatar correctly.
I am not exactly sure what happened with your code, but I ended up with an $avatar_entry of 'g8' instead of the correct $avatar_entry '48' for that user who had their own avatar uploaded. I think it may be possible that 'preg_match' is catching the 'g' in the .png of the user_avatar.
Thinking about your code further, does this only give one digit for group avatars? Would this fail if the group id is > 10?