UBB.Dev
Posted By: White Gold Wielder Unique Avatars? - 06/08/2004 6:20 PM
I have my own custom avatar solution that prevents two people from having the same avatar, but there is too much manual intervention on my part. I have an idea to cut this down quite a bit, but I need some help.

I have already modified the avatar selection popup supplied by Infopop to only be an avatar gallery of sorts, but I plan to modify it further to once again make it select and assign your avatar. The trouble is, I won’t allow two people to have the same avatar. I need to create some sort of flat file that holds the names of the avatars that are taken and have it check this file before allowing an avatar to be assigned. This is the hard part.

What would be the best format or organization for the file? Are there more efficient ways to search a file like this? Do I have to use some file locking method to prevent people from reading/writing to the file at the same time?

Or is there a better and entirely different way to solve the problem of unique avatars?
Posted By: Ron M Re: Unique Avatars? - 06/08/2004 8:54 PM
What about forcing all users accounts to have a custom avatar URL such as http://www.domain.com/avatars/00000000.cgi where 00000000 is the member number of the user. Then don't allow users to change the avatars. Then you just drop in the avatar in the directory.
Posted By: White Gold Wielder Re: Unique Avatars? - 06/08/2004 9:42 PM
I'm not sure what 00000000.cgi would do, but it seems like there would still be a lot of manual intervention on my part. I don't want to have to do anything except put approved images in the avatar directory.

Here is my modified avatar selection page . It only displays every image in the avatar directory and displays that person's profile when you click it.

What I would like to do is keep this functionality, but add to it to allow you to change your own avatar. I see a set of buttons/links that allow you to filter the display to show either taken avatars, not taken, or both. There might be a colored border around each image that signified whether the image was taken or not. If you clicked on a taken image, it would still display that person's profile. If you clicked on one that was not taken, it might pop up and ask you if you are sure and then change your avatar to that image.

An image is either taken or it is not, so there would be no duplicate avatars.

BTW, I use Custom Field #1 for my avatar field. I had my own custom solution in place before avatars were available and I stuck with it once I saw that I couldn't use Infopop's feature in the way I wanted.
Posted By: Ron M Re: Unique Avatars? - 06/08/2004 10:03 PM
I was using 00000000 as an example. Replace with your member number.

Hmmm...that would be a serious hack to do what you are looking for.
Posted By: White Gold Wielder Re: Unique Avatars? - 06/08/2004 10:36 PM
I know 00000000.cgi was an example! OMG! But what does it do? Your first post wasn't exactly clear on exactly what you propose.

I was hoping that someone with some experience with hacks that read and write to external files would give me some advice. For instance, LK has to read and write to a file with his Calendar. I have yet to examine his code, but I imagine he somehow locks the file so only one person can write to it at once.

That's probably the only serious part. Setting your avatar by clicking it is not a big deal and the rest is a cakewalk.
Posted By: Ron M Re: Unique Avatars? - 06/08/2004 11:52 PM
I mistakenly put .cgi instead of .jpg/.gif, etc.

Old habit.
Posted By: White Gold Wielder Re: Unique Avatars? - 06/09/2004 12:08 AM
Ahh, actually, that is similar to what I do now, although the filename I use is avatar00000.gif. The big problem is that I have to rename and move each file whenever they want to add / change their avatar. If this is their first avatar, I also have to edit their profile manually through the CP.

Needless to say, the job has gotten increasingly more labor intensive and frankly I'm so behind that I don't want to do it anymore.

If I get some schooling on files, I could whip this mod into shape and get this monkey off my back.

Oh, another addition to the mod would be to not allow avatars to people who haven't passed the "new user" posting threshold (100 posts on my site). Don't want to see people who don't plan on sticking around hogging all the good avatars.
Posted By: AllenAyres Re: Unique Avatars? - 06/09/2004 1:56 AM
You woudn't consider them linking to their own from somewhere else?
Posted By: White Gold Wielder Re: Unique Avatars? - 06/09/2004 4:54 AM
I care enough about the look and feel of my site to not allow the chaos of linked avatars.

I also have two members who have dedicated themselves over the years to creating hundreds of avatars choices within the required theme and size restrictions. If anyone has a custom request, they work with them to create one to their liking. This hoard of avatars should be more than enough choice for any serious member of the site.
Posted By: White Gold Wielder Re: Unique Avatars? - 06/10/2004 6:59 PM
I no one has any advice for reading and writing to a flat file, perhaps those more familiar with the mods here can suggest a few besides LK's Calendar that use these files.

I'll just have to learn what I can from those.
Posted By: White Gold Wielder Re: Unique Avatars? - 06/18/2004 7:10 PM
I really need some advice on how to read and write to a file. I don't know where to begin.
Posted By: Ian Spence Re: Unique Avatars? - 06/18/2004 7:32 PM
$ted = &OpenFileAsString("file_path/file_name");

&WriteFileAsString("file_path/file_name", $ted);
Posted By: White Gold Wielder Re: Unique Avatars? - 06/19/2004 12:38 AM
Is that the best way to accomplish what I want to do?
Code
$ted = &OpenFileAsString("file_path/file_name");
That would put the entire contents of the file into $ted, right? This seems like it would be unwieldly to try to search.

And when writing, I have to modify $ted and then overwrite the entire file each time?

I guess I expected to read and write only the line of the file I needed. As far as making sure that no one takes the same avatar, I'll have to search the file again right before I write to it to make sure no one else has written to it in the mean time.

I thought it would be more complicated, with having to lock the file, having to search the file for a particular line and then writing to a specific line of that file. I guess I could just keep it simple and see how it goes.
Posted By: Ian Spence Re: Unique Avatars? - 06/19/2004 3:46 AM
@ted = &OpenFileAsArray("file_path/file_name");
Posted By: White Gold Wielder Re: Unique Avatars? - 06/23/2004 6:01 AM
Since the file is very simple (consisting of only the filename and the user #), I was thinking of using a hash with the filename as the key and the user # as the value.

I could find, add and remove items fairly easily, from what I'm learning about PERL.

Am I barking up the wrong tree?
© UBB.Developers