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

Edit profile picture based on JSON data

Discussion in 'XenForo Development Discussions' started by theBdoom, Nov 4, 2015.

  1. theBdoom

    theBdoom New Member

    So I want to make a script which can automatically change my users profile picture based on a profileID which I grab from an API. The API gives a large amount of information and I want to grab the "profileID" which will correspond to a list of profile icons that I have. I want to disable the ability for users to upload an image and make it grab the profileID from he API I am using. Does anyone know if this is possible?

    Step 1. Grab profileID from database
    Step 2. Set userProfileImage to an image based on the profileID

    I want to know if it's possible? I already know how to use PHP to grab the data from my server. I am unsure what XenForo file can make it check the API for the imageID and automatically update the users profile every hour or once a day, or a week. Also, what file would I have to edit in order to disable profileImage uploads? Is there a documentation for XenForo?
    Last edited: Nov 4, 2015
  2. Robust

    Robust Well-Known Member

    Everything is possible.

    So you know how to select the profile ID, you can also use the predefined variables in that method if there is one in the one you're accessing (the profile of the user you're viewing) and save a query on page load. Get the data and unserialise it. Use the XF DataWriter (XenForo_DataWriter_User), setExistingData to the user id, and then set whatever data you want to override.

    Combine this with a cron and you can have a task running every so often to be updating user profiles. Though, updating 1 million profiles via cron every hour is not nice. I think what you're probably going to want instead is when the user accesses the site, check if their profile has been updated in the last week, if it has then set the check time for another 3 days and check again for this then, if it hasn't go ahead with the update explained above.

    Right now that's the best method I got, but there's probably better.
  3. theBdoom

    theBdoom New Member

    So where exactly do I access these variables though?
  4. Robust

    Robust Well-Known Member

    The user ID? Where are you hooking into? Or do you mean for the cron? For the cron you will want to get users active since the cron was last ran and process them.
  5. theBdoom

    theBdoom New Member

    Well I have this API which I can grab data from and one of the variables I want to grab is "userProfileIconID." On xenforo where would I be able to set the userprofile based on that ID?

    I think it's better as an example:

    Imagine if you have 3 users, user 1 has iconID 35, user 2 has iconID 36 and user 3 has iconID 37. Each iconID corresponds to a profile image.
    So if user 1 has iconID 35 I want his profile picture on the site to correspond to "iconImage35.jpg" and so forth.

    Basically whatever iconID number they have decided what their profile image is. Does this make any sense? Basically, change the profile image based on a number and that number corresponds to a image. Each image has a number.

Share This Page