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:
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;
}
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?