1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Default Avatar Based on Link + Custom Field

Discussion in 'Styling and Customization Questions' started by Alpha52, Jun 18, 2012.

  1. Alpha52

    Alpha52 Member

    Ok, so here goes, I'll try to keep this brief:
    I run a Minecraft server.
    There's a website that, through a link, you can pull the user's in-game "head" image.
    Here's the site: http://minotar.net/

    What I want to do:
    I want to use a custom user registration field (In-game name) to set the default avatar to their in-game skin.
    BUT I also want this default avatar be be overwritten when the user decides he/she wants to upload a custom avatar.

    Example:
    User "Bobby" registers on my forums and fills in the custom name field with "Bobby123"
    That then sets the path for his avatar to:

    <img src="https://minotar.net/avatar/bobby123">

    Until he decides to upload a custom one.

    Does anyone know how to do this?
    Thanks in advance! :)
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Cogs are turning on this one.

    It may involve adding a conditional in the template that says in basic terms

    If user has their in-game name field filled in, load this image, else load avatar as normal...

    Let me play with an example.

    EDIT: The problem is, of course, the avatar is so prominent and used in so many places. I'm now beginning to think an add-on which handles this properly is more appropriate than hacking the templates.
     
  3. Alpha52

    Alpha52 Member

    Thanks! Ya, I figured this would be a slightly more mind boggling idea then most of the simple template modifications :p

    Yeah...I mean I've easy replaced all the default avatar images with my own which has worked easily, displaying them correctly everywhere that I can see.
    How different would it be to instead just take the image from an outside web server?
    Or, are you saying that each location for the avatars to be displayed are in their own unique files and that it would be a whole lot of editing to get the correct images displayed in every place? mmmm
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    There's loads of considerations.

    I'm currently editing the code in XenForo_Template_Helper_Core which is what the templates use to render a person's avatar in the correct size.

    In my initial test, I have been successfully been able to replace the avatar in posts with bobby123's from Minotar.

    But we have to consider, the wide range of sizes which is fine because Minotar does let you specify sizes, but XenForo thinks of sizes in s, m and l and translating that into the URL that Minotar understands is not impossible, but just another thing to add complexity.

    Also, in my initial tests, although everything displayed fine in posts, avatars disappeared from things like the forum index and Staff Online etc.

    Finally, another problem is despite what's in the Helper code, some avatars just didn't change at all, so they must be handled differently.

    I love the idea though, and it's definitely possible. Just going to take a lot of work to get it right!
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The problem is custom profile field values aren't available everywhere avatars are used so they can't be relied on to build the avatar location. If you modify the software to store your profile field in the xf_user table then it should be available for use in this function:

    XenForo_Template_Helper_Core::_getDefaultAvatarUrl

    This requires custom programming. You can post a request:

    http://xenforo.com/community/forums/resource-and-add-on-requests.68/
     
    Yorick likes this.
  6. Alpha52

    Alpha52 Member

    Will do. Thanks Jake :)
    And thanks Yorick for taking interest!
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    That's better than what I was thinking...
     

Share This Page