Avatars via phpBB group Avatar

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

If you wish to attach one or more files enter the details below.

Maximum filesize per attachment: 1 MiB.

Expand view Topic review: Avatars via phpBB group Avatar

Re: Avatars via phpBB group Avatar

by axew3 » Wed May 10, 2017 8:10 am

You have been added as committer for wp_w3all plugin at wp.org and editor/moderator here (in few minutes from this post).
Of course this not mean any obligation for you, but "whenever and if" you want so, you can add improving what you think better.
About commitments, i would like to maintain at moment the control over any new release. So before, for instance, we'll go to use the branches folder for testing purpose and pre release code:
https://plugins.trac.wordpress.org/brow ... n/branches

Thank you for appreciation about plugin on top of this topic: but i know the plugin could be write and be much more better.
Any aspect can be considered. Not only about code.

Re: Avatars via phpBB group Avatar

by Lepalose » Tue May 09, 2017 10:26 pm

I just registered an account,

https://wordpress.org/support/users/lepalose/

Glad to see that it is working for you as well.

Re: Avatars via phpBB group Avatar

by axew3 » Tue May 09, 2017 9:56 pm

so the file class.wp.w3all-phpbb.php has just been updated to apply your code.

Re: Avatars via phpBB group Avatar

by axew3 » Tue May 09, 2017 9:38 pm

Hey Lepalose, your code work like a charm, without any messy code around.
Are you registered at wp.org?

Re: Avatars via phpBB group Avatar

by axew3 » Tue May 09, 2017 9:24 pm

Code: Select all

preg_match('/^([g])([0-9]+).*/'
it grab any number after g with [0-9]+
and png are showed ok on test but
your code is more short, checking it right now

Re: Avatars via phpBB group Avatar

by Lepalose » Tue May 09, 2017 8:04 pm

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?

Top