News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Username Variable in URL Profile Pic

Started by Dan Rodgers, October 23, 2013, 01:32:23 AM

Previous topic - Next topic

Dan Rodgers

First post, sorry if this is the wrong place ;)

Basically, I want to set the users profile pic to be "site.com/avatars/[usernamehere].png
I don't have to worry about illegal characters as I only allow letters and numbers via my way of adding users.
Thanks in advance

margarett

Some questions:
-do you have pictures for all your users?
-should they be able to change it again if they want to?

This can be achieved with a more-or-less simple SQL query in the members table, provided that the images are already in place...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Dan Rodgers

Quote from: margarett on October 23, 2013, 05:09:20 AM
Some questions:
-do you have pictures for all your users?
-should they be able to change it again if they want to?

This can be achieved with a more-or-less simple SQL query in the members table, provided that the images are already in place...

Yes, I should have an avatar for every user, this is using a server which is running a custom dungeon game similar to nethack, but users have their own profiles and it is much more fun. My goal is to get the images from the mini apache server running on that server and use it for the forums. As for changing their avatar, I would prefer they not be able to, as I have limited disk space.

Kindred

in which case, you are porbably going to want to change the code rather than just inject the filename directly into the DB
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Dan Rodgers

Quote from: Kindred on October 23, 2013, 05:01:43 PM
in which case, you are porbably going to want to change the code rather than just inject the filename directly into the DB
The game code? If you mean SMF code, if I can get snippets and instruction to where they go, I could do it, but I know little php and I never looked into it as it was always very confusing  to me :P

Dan Rodgers


Arantor

You will want to be changing the way avatars are defined in loadMemberContext in Load.php.

Actually, might I suggest you take a look at the default avatar mod? It's doing something fairly similar, in that it's replacing the avatar handling but only for undefined avatars... should not be a huge job to replace it for all avatars.

Dan Rodgers

Quote from: Arantor on October 24, 2013, 09:31:34 PM
You will want to be changing the way avatars are defined in loadMemberContext in Load.php.

Actually, might I suggest you take a look at the default avatar mod? It's doing something fairly similar, in that it's replacing the avatar handling but only for undefined avatars... should not be a huge job to replace it for all avatars.
Yea, that is kind of what I want, but I need that avatar to point to a URL with the posting persons username in it.

Arantor

Yes, yes, I realise that. The whole point of directing you to it was because it's practically a blueprint for the changes you need to make.

Dan Rodgers

Quote from: Arantor on October 24, 2013, 10:46:10 PM
Yes, yes, I realise that. The whole point of directing you to it was because it's practically a blueprint for the changes you need to make.
Well, as I said, I no nothing about PHP, so it really doesn't help much :P but thanks for the answer

margarett

I was doing a quick test here in my test forum.

First question:
Quote from: mesome32 on October 23, 2013, 04:29:14 PM
As for changing their avatar, I would prefer they not be able to
You need to edit Profile.template.php so that the user does not delete the avatar you give him. Even if you go to Permissions and remove all the options to configure avatar (choose from server/upload to server/external link), an option "No avatar" is still displayed. If the user chooses to save, then the chosen avatar is removed. Check first attachment.

Quote from: Arantor on October 24, 2013, 09:31:34 PM
You will want to be changing the way avatars are defined in loadMemberContext in Load.php.
I could be wrong (and is a serious risk, questioning you :P ) but in this case you still present all options to the user, he can still choose an avatar but, regardless, SMF will use whatever you change in loadMemberContext (disregarding user option). No? :)

So, from my point of view, it should be easier/most adequate to:
1 - edit Profile.template.php to hide the avatar selection
2 - run a SQL query, like:

UPDATE smf_members SET avatar = CONCAT( member_name, '.png' )

Each user is now expected to have a file "user_name.png" inside the folder "avatars". Which is the user's original requirement...
Note: this *MIGHT* leave some orphan rows in "attachments" table (if there were users with uploaded attachments), but that can also be addressed ;)

This keeps pretty much everything as clean as possible, no big coding changes except hiding the avatar selection, easy "revertible".
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

this assumes that all members who have joined are the only members to ever exist. Your SQL method does not address the issue when a new user joins.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

You are right, didn't consider that :P But, it can also be addressed with a small change in Subs-Members.php ;)

But it heavily depends on how the registrations are processed...
Quote from: mesome32 on October 23, 2013, 01:32:23 AM
...via my way of adding users.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Dan Rodgers

Quote from: margarett on October 25, 2013, 07:57:35 AM
You are right, didn't consider that :P But, it can also be addressed with a small change in Subs-Members.php ;)

But it heavily depends on how the registrations are processed...
Quote from: mesome32 on October 23, 2013, 01:32:23 AM
...via my way of adding users.
I manually inject them into the database.

Kindred

That is the ****WRONG**** way to add users.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

Can you elaborate how you do that? There is already a way for you, as admin to manually register members via ACP.
How do you do it?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Dan Rodgers

Quote from: Kindred on October 25, 2013, 10:37:11 AM
That is the ****WRONG**** way to add users.
Yes, I am aware that is not the best way to add them, but the way users register is by executing the command /reg in the game, this is to make sure users use the name they have in the game and to make sure they paid for the game.

margarett

But will this lead to an automated script that registers new users
OR
Do you pick and add them manually
?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

So modify your registration script to force a value into the relevant column of the database.

I find it very curious that you're able to get a game set up that can manually register in the forum database (which is no small feat) but can't make changes even when given a blueprint for doing it without giving you step by step instructions.

Dan Rodgers

Quote from: margarett on October 25, 2013, 10:48:38 AM
But will this lead to an automated script that registers new users
OR
Do you pick and add them manually
?
It's a script, users type /reg myPassword myEmail and then they sign in.

Quote from: Arantor on October 25, 2013, 10:54:09 AM
So modify your registration script to force a value into the relevant column of the database.

I find it very curious that you're able to get a game set up that can manually register in the forum database (which is no small feat) but can't make changes even when given a blueprint for doing it without giving you step by step instructions.

I did not make the registration add on, my dev did and I have asked him if it would be possible to do it automatically and hes has yet to reply after a month, no AFK notice or anything :I

margarett

Well, that should be easy then.

Your script fetches the user avatar, copies it to the "avatars" folder with "user_name.png" schema and, when it enters the database information for the user, just write to the "avatar" column that file name.
This solves the issue with new registrations, my previous trick should take care of the existing ones. It still requires the small modification to Profile.template.php ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: