Add custom user settings

Started by Gwenwyfar, November 28, 2014, 09:48:28 PM

Previous topic - Next topic

Gwenwyfar

I've not found anything similar to what I want looking around, so if anyone knows of any topic or mod that does this it could help too.

Basically, I want to add some custom user options. One of them (which I believe will be the most complex, so if I get that done the rest should be easy, just following the same thing) is to be similar to theme selection. It will be pretty much the same thing, but with banner selection instead.

I know there will be a lot of things to edit to do this, but I don't quite get all it involves, so this is the main question here. From what I know so far it would be like:

1 - Adding tables on database that contains member ID and the option number to save the info
2 - Edit profile.php (??)
3 - Edit profile-modify.php (??)
4 - ??
5 - Add the settings on admin template
6 - Add the "switchs" on index.tamplate.php

Is there something else I should be editing? And where are things loaded on the profile modify pages? I saw some arrays and functions that list each setting separately, but couldn't find where they're all linked together or called from. I tried to change the order of some things as well and it doesn't seem related to the array order.
"It is impossible to communicate with one that does not wish to communicate"

Arantor

How about we start with what settings you're trying to add, what types of values they are?

We'll worry about the 'how' once we know the 'what'. Especially since I can think of multiple approaches that affect all of the 'how' depending on the 'what'.

Gwenwyfar

Well, there will be mainly two types, one which I believe will be the most complex one would work in a very similar way to theme selection. You click on a change button, go to a page with a selection of banners and choose one. Then the options for these would be added through the admin panel, and would have a default one as well.

The others are simpler and for the most part wouldn't involve any editing around admin settings, or any extra pages, as they'd be simple fixed options. For instance, a select box with 2 or three choices of where the sidebar should be (left/right), and maybe one to disable it. The default would be one of those and the user could select a different one from there, too.

There will probably be others on the future, but they'd be all more similar to the second one.
"It is impossible to communicate with one that does not wish to communicate"

Arantor

Selection of banners... displayed where exactly?

Simple fixed options occur to me as being better served by custom profile fields (which for a user should be automatically loaded, IIRC into $options)

Gwenwyfar

In the look and layout section of profile settings, preferably in a page of its own, same as themes, so as to not load images without needing to.

Hmm, didn't think about that. That's a good idea. I saw it has checkboxes/lists but didn't quite understand how it worked when I saw it.
"It is impossible to communicate with one that does not wish to communicate"

Arantor

I didn't mean where the selection was displayed; I meant where the banners would be displayed. As in where the values need to be available.

As for custom profile fields, I'm not sure what's confusing about it?

Gwenwyfar

#6
Ah, sorry. Well, that's the easy part, that's why I didn't mention it :P (Or at least I think so) It'll be on the logo area, just a change in images there, same place as the default logo image goes, they'll all have the same size etc.

Well, I did see you can add checkboxes and option lists, but then where/how can those settings be used anywhere? Aren't those just to display more info on the profile?  ???
"It is impossible to communicate with one that does not wish to communicate"

Arantor

To your last point - yes, to a point. But like everything else, they're in the database, ready loaded for the user automatically. Why tangle with code to do all this stuff when it's already actually done for you?

Specifically, set up the custom field, set it to display only to owners and admins (with dropdown or whatever), and you will find the value ready loaded for you in $options. All the form handling, all the database handling is all handled automatically for you :) Why roll your own code when SMF can actually do it out of the box?

To your first point... easy? That depends on your perspective. I rather suspect my perspective is *very* different to most peoples' when it comes to doing things with SMF. And I much prefer giving out advice when I know what the details of the situation are. Unfortunately I have not yet perfected a mind reading mod for SMF ;)

Gwenwyfar

True, I just didn't remember about it at all when thinking about these new options, didn't think they could be that handy :P

But that will work nicely then, thanks! :)

Thinking about it, couldn't the same be done for the banner then? Adding it as a custom field, then just linking it on the profile options to a custom action where you can select it?

Well, trying to replicate the functioning of the theme settings seem way harder than just using the settings that are ready and working into something :laugh:
I try to explain things well but I guess sometimes I'm not as clear as I think I am about something :P
"It is impossible to communicate with one that does not wish to communicate"

Arantor

Depends if you want to show the banners themselves or not at point of selection really.

As for explaining, best way for that is to assume the other person knows absolutely nothing ;D

Gwenwyfar

I guess some thumbnails might work better on that anyways, so should be fine with just that, thanks again! :)

Now only need to find how to call those options :D

Good point. Will try to have that in mind in the future, I'm always making the mistake of assuming someone knows a certain point of my explanation because of something I said previously, though its more apparent with friends :-X
"It is impossible to communicate with one that does not wish to communicate"

Arantor

Well, $options will contain the fields. If you have a field called test, it will end up in the database as $options['cust_test']. The actual suffix that will be used can be observed in the custom_fields table by way of the col_name field.

Neither bbc nor raw HTML is supported when creating radio or select custom fields so that's not going to work for you without modification - but even then you're talking significantly less change than doing it all yourself. You *could* manually splice raw HTML into the database there but 1) you won't be able to edit it afterwards in the admin panel and 2) this is naturally *not recommended* but is a viable quick/dirty method for doing it in this case because the field is sufficiently big enough to hold it without risk of truncation or anything.

If you did go down this route, you'd have to use a radio button and splice the values into the field_options column in the custom_fields table. This is a comma separated value where it literally does an explode() on the value, so you would be doing:
<img src="http://domain.com/path/image1.jpg" alt="" />,<img src="http://domain.com/path/image2.jpg" alt="" />,<img src="http://domain.com/path/image3.jpg" alt="" />

This works because SMF sanitises this stuff on saving to the database, not on display.

My normal preference for such, though, would be a select with descriptive names which get translated into paths later (bearing in mind that the raw value of whatever you have as the options is what gets stored in the database for the user, and I think there might be a 255 character cap on that off hand, not sure)

Gwenwyfar

Ahh. Yeah, that's what I was looking for, what would be the suffixes :) Didn't know those were related to the database table fields.

Had another idea for adding the images in mind, still "hacky" though, just adding a sprite for it, as the labels and buttons have unique values that can be selected. But putting it on the database will be easier to edit later and have no delay to update for users (css being cached), so will probably go for that :)

Will take a look on that other option once I have a bit more knowledge of php for such, I still have a few things left to do on the forum before I go read an actual book/documentation/etc on the language (hands-on experience is always a great teacher to grasp the basics) :P

But thanks a lot! This is gonna be very handy :)
"It is impossible to communicate with one that does not wish to communicate"

Advertisement: