[Solved][XenForo] Minecraft Avatars

Discussion in 'Server & Community Management' started by LuisaDraws, Aug 11, 2016.

Thread Status:
Not open for further replies.
  1. Hello,

    I'm using the following code to get Minecraft Avatars to my XenForo:
    Code (Text):
    protected static function _getDefaultAvatarUrl(array $user, $size)
    {
    return "
    https://minotar.net/avatar/{$user['username']}/".XenForo_Model_Avatar::getSizeFromCode($size).".png";
    }
    But I'm having a problem that if the username is not the same as the minecraft name, the avatar it's just a blank picture.
    Is there a way to still keep a default avatar for those members?

    Thanks.
     
  2. Tux

    Tux

    Minotar should return a Steve avatar if it's a plausibly valid Minecraft username but no avatar was found, but returns a 404 if the name isn't valid. You'll have to filter the username beforehand and point it to https://minotar.net/avatar/char instead.
     
  3. How do I do that?
     
  4. Tux

    Tux

    Valid Minecraft usernames are 1-16 characters long and only allow alphanumeric characters and underscores. Based on this and a little bit of basic PHP and regex knowledge, you can change the URL for the avatar.
     
  5. I don't have any knowledge on those. Can you give me the code I need?
     
  6. Not that difficult, dude.
     
  7. Well "dude", I have 0 knowledge, ence why I'm asking for help.
     
  8. Does anyone know the placeholder for custom fields?
    I'm trying {$user['user.customFields.ID']} but doesn't seem to work.
    Also tried {$user.customFields.fieldId} but my forum goes blank.
    Thanks.
     
    #8 LuisaDraws, Aug 12, 2016
    Last edited: Aug 12, 2016
  9. JamesJ

    Supporter

    Learn PHP then? There are loads of basic tutorials which will teach you all you need for now..
     
    • Funny Funny x 1
  10. SeanMe

    Artist

    You can try this, it will just check if the users name is the same valid format as a Minecraft username, and if not, it will use a Steve face.

    PHP:
    protected static function _getDefaultAvatarUrl (array $user, $size) {
      $name = $user['username'];
      $size = XenForo_Model_Avatar::getSizeFromCode($size);
      // If username contains only numbers/letters/underscores and is 16 characters or less
      if(preg_match("/^[a-zA-Z]+[a-zA-Z0-9_]+$/", $user) && strlen($user) <= 16) {
        $avatar = "https://minotar.net/avatar/$user/$size.png";
      }
      // Else not valid minecraft username, so use steve avatar
      else $avatar = "https://minotar.net/avatar/char/$size.png";
      // Return the correct avatar
      return $avatar;
    }
     
  11. Thanks, but I actually want to use a custom field placeholder, because it's a required field to have the Minecraft Usernames in my forum. That would be better to use instead of the username. You know if it's possible?
     
    • Winner Winner x 1
Thread Status:
Not open for further replies.