- Status: Moved to Github
I have an application that sets a member’s profile photo to an image uploaded in a different FileStorage extension. I’m talking about this code in the \IPS\Member::photoUrl() function:
/* We have an uploaded or synced photo */
if ( $memberData['pp_main_photo'] and ( mb_substr( $memberData['pp_photo_type'], 0, 5 ) === 'sync-' or $memberData['pp_photo_type'] === 'custom' ) )
{
try
{
$photoUrl = File::get( 'core_Profile', ( $thumb and $memberData['pp_thumb_photo'] ) ? $memberData['pp_thumb_photo'] : $memberData['pp_main_photo'] )->url;
}
catch ( InvalidArgumentException $e ) { }
}
/* Letter photos are enabled and we do not have a photo set, but only if this isn't for email */
elseif( Settings::i()->letter_photos == 'letters' AND $email === FALSE and isset( $memberData['name'] ) )
{
if( $photo = static::generateLetterPhoto($memberData) )
{
$photoUrl = $photo;
}
}
/* Other - This allows an app (such as Gallery) to set the pp_photo_type to a storage container to support custom images without duplicating them */
elseif( $memberData['pp_photo_type'] and $memberData['pp_photo_type'] != 'none' and mb_strpos( $memberData['pp_photo_type'], '_' ) !== FALSE )
{
try
{
$photoUrl = File::get( $memberData['pp_photo_type'], $memberData['pp_main_photo'] )->url;
}
catch ( InvalidArgumentException $e )
{
/* If there was an exception, clear these values out - most likely the image or storage container is no longer valid */
$member = Member::load( $memberData['member_id'] );
$member->pp_photo_type = NULL;
$member->pp_main_photo = NULL;
$member->save();
}
}
I am talking about the second/last elseif check in the code above:
/* Other - This allows an app (such as Gallery) to set the pp_photo_type to a storage container to support custom images without duplicating them */
elseif( $memberData['pp_photo_type'] and $memberData['pp_photo_type'] != 'none' and mb_strpos( $memberData['pp_photo_type'], '_' ) !== FALSE )
{
try
{
$photoUrl = File::get( $memberData['pp_photo_type'], $memberData['pp_main_photo'] )->url;
}
catch ( InvalidArgumentException $e )
{
/* If there was an exception, clear these values out - most likely the image or storage container is no longer valid */
$member = Member::load( $memberData['member_id'] );
$member->pp_photo_type = NULL;
$member->pp_main_photo = NULL;
$member->save();
}
}
The problem is that when letter photos are enabled the first elseif check before this one takes precedence and overwrites the custom image.
The code must be changed to check/generate letter photos as the last step only if no custom image with a FileStorage container is specified.
Recommended Comments