Edit profile picture based on JSON data

theBdoom

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?

tl;dr
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:
I want to know if it's possible?
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.
 
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.

So where exactly do I access these variables though?
 
So where exactly do I access these variables though?
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.
 
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.
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.
 
Top Bottom