I have implemented a way to change the header color for the members, though I have completely no idea of how to save the color value to the specified member.
The value is stored inside of the variable 'hex' which is created by a jQuery plugin.
'hex' consists of values such as 'rgb(170, 255, 0)'
I've done something similar to that using Custom Profile Fields. Have you looked at that mod yet? It'll certainly do what you want, including associating/storing the members specific requirement with their ID details.
Thanks, I'll have a look. Though if possible, I'd like to stay away from mods.
No problem.
Lainaus käyttäjältä: xpopy
... I'd like to stay away from mods.
Lainaus käyttäjältä: xpopy
I have implemented a way to change the header color ...
Maybe I should rephrase that; saving a value to a database shouldn't be so hard that I would need a mod for it.
I am no professional and I didn't make SMF. I have honestly no idea how they save their own settings or where they do it.
Though saving just a value such as 'rgb(170, 255, 0)' to a database shouldn't need a whole new mod.
Well, your change has already implied that you've used a "mod", albeit of your own design :P
You could download and analyse the Custom Profile mod to see how it implements database queries and associates member-specific data with their member ID. Even installing that officially supported mod doesn't mean you have to use all its features, though.
Custom profile fields is built into 2.0...
Ah yeah, just saw that. Though how would I integrate this, and call it back later?
This is how I would like it to look like:
http://i.imgur.com/oQyvlgx.png
Would I have to create a new field type for it?
Yeah, that isn't going to work with it.
You'd be better manually adding it to the great and exciting list of fields in the start of Profile-Modify.php.
Oh interesting, I think I can get that to work..
Though how would I call it for the specific user? Is it $context['callback_func'], while callback_func would be whatever I set it in this huge list?
Um, sorry, what?
Uhm, to set the color of the header I would have to load the value somehow. Looking in the huge list inside of Profile-Modify.php,
'callback_func' => 'theme_color',
looks like the funcion name, or so.
But how would I 'extract' the value from it?
The callback function isn't for storing values or anything, it's a function that will be called for displaying things.
For example, if you define that, when it comes to showing it in the profile area, template_profile_theme_color() gets called to output the code to the user for their selection.
The id of the item you add is in almost every case going to be the column in smf_members where the data will be stored, and ultimately what I think you're going to end up doing is defining an input_validate function to validate what is provided by the user and you might end up updating $cur_profile['theme_color'] inside it. Really depends on exactly how you store it vs displaying it. (Note, storing an RGB triplet in hex format is much, much easier than storing an rgb() triplet, it's smaller and also easier to sanitise)
Ah, sorry. I'm still a newbie regarding PHP, and I'm really sorry for the amount of questions..
I have decided to make use of a dropdown list including a couple preset colors, instead of the old way. I think this will be way easier to add...
The dropdown is basicly the same as Time Format uses, just edited.
'theme_color' => array(
'type' => 'callback',
'callback_func' => 'theme_color',
'permission' => 'profile_extra',
'preload' => create_function('', '
global $context, $user_info, $txt, $cur_profile, $modSettings;
$context[\'color_list\'] = array(
array(\'format\' => \'blue\', \'title\' => \'Blue\'),
array(\'format\' => \'green\', \'title\' => \'Green\'),
array(\'format\' => \'orange\', \'title\' => \'Orange\')
);
$context[\'member\'][\'theme_color\'] = $cur_profile[\'theme_color\'];
return true;
'),
),
Now, to display this I have to place template_profile_theme_color() somewhere, right? Where would that be?
And finaly, would I have to save this to the databse somehow, or does SMF do that for me?
If you're going with a simple dropdown, use the best facilities for a simple dropdown, like the gender option is:
'gender' => array(
'type' => 'select',
'cast_type' => 'int',
'options' => 'return array(0 => \'\', 1 => $txt[\'male\'], 2 => $txt[\'female\']);',
'label' => $txt['gender'],
'permission' => 'profile_extra',
),
I think what you're looking for:
'theme_color' => array(
'type' => 'select',
'options' => 'return array(\'blue\' => \'Blue\', \'green\' => \'Green\', \'orange\' => \'Orange\');',
'label' => 'Theme Color',
'permission' => 'profile_extra',
),
Oh, yeah that does indeed look better.
Now to display it?
Where do you want to display it?
The setting should probably by within the Look and Layout tab.
And to use it, I've added
<style type="text/css">
#header{background-color:*variable here*;}
</style>
inside of index.template.php
You can add it to Look and Layout Preferences by editing the 'theme' function in Profile-Modify.php, which pulls L&L. The relevant part:
setupProfileContext(
array(
'id_theme', 'smiley_set', 'hr',
'time_format', 'time_offset', 'hr',
'theme_settings',
)
);
id_theme corresponds to the theme changer, smiley_set to the smiley set selector if enabled, hr is a line, time_format and time_offset tie into the time format and offset options, and theme_settings is everything else.
You could add it as such:
setupProfileContext(
array(
'id_theme', 'smiley_set', 'theme_color', 'hr',
'time_format', 'time_offset', 'hr',
'theme_settings',
)
);
As far as getting it, you have options. By now you should have the column theme_color in the smf_members table which is where this will be stored. The simplest method of retrieving this will be to add $user_settings to the list of global variables in the template_html_above function, and then using:
<style type="text/css">
#header{background-color:', !empty($user_settings['theme_color']) ? $user_settings['theme_color']) : 'blue', ';}
</style>
The blue is given as a default for guests etc. and folks who don't have a value currently set. This should be added directly into the echo statements in template_html_above().
Hmm, everything seems to work except
$user_settings['theme_color']
When a user have set a color in their settings, the code above returns nothing.
Did you add $user_settings to the list of global variables in the function where you're using it?
Yeah I did.
I also noticed that if $user_settings['theme_color'] is empty, the default kicks in and sets the header to blue, otherwise if it's not empty its not putting out anything.
That's clever, I managed to make a typo in that code ;)
<style type="text/css">
#header{background-color:', !empty($user_settings['theme_color']) ? $user_settings['theme_color'] : 'blue', ';}
</style>
Thing is, if it's not empty it should be outputting a value...
Haha nice!
Works perfectly now, thanks a lot for the help! ^^