SMF Theme Changer

Started by SMFHacks.com Team, April 23, 2012, 06:38:02 PM

Previous topic - Next topic

Antechinus

#60
Ah. I see the problem. It's not doing anything with user settings or cookies. It's just appending the selected theme id to the current url. That's not persistent, ergo the problem.

What you're after is one that a/ sets a cookie, or a browser local storage value, for guests and b/ sets a proper user setting for logged in members.

I suppose you could even go belt and braces, and do both for logged in members. That way if they visit the site again without bothering to log in their selected theme would stay the same.

But OTOH you have to wonder if there's much point having a theme changer for logged in members, since they can always go into the profile and change their selected theme anyway. Theme changers are really more useful for guests.

Sir Osis of Liver

Odd thing is, it was working when I first installed yesterday, then tested it on my 7" tab last night and it wasn't keeping the setting, same thing on pc today.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Antechinus

Makes perfect sense. It depends on sessions, and each session is tied to the device you logged in with.

Sir Osis of Liver

Well, yes, if that's how it's supposed to work, but I'm pretty sure that it updated profile setting first time I tested it, now it doesn't.  Looking at the code, I see it reads the database for available themes, but don't see it updating member setting -



// ClickSafe Read database
function cls_read_db()
{
  global $context, $settings, $txt, $modSettings, $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT id_theme, variable, value
FROM {db_prefix}themes
WHERE variable IN ({string:name}, {string:theme_dir}, {string:theme_url}, {string:images_url})
AND id_member = {int:no_member}
      AND id_theme IN ({array_string:known_themes})',
array(
'no_member' => 0,
'name' => 'name',
'theme_dir' => 'theme_dir',
'theme_url' => 'theme_url',
'images_url' => 'images_url',
      'known_themes' => explode(',', $modSettings['knownThemes']),
)
);
$context['cls_themes'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!isset($context['cls_themes'][$row['id_theme']]))
$context['cls_themes'][$row['id_theme']] = array(
'id' => $row['id_theme'],
);
$context['cls_themes'][$row['id_theme']][$row['variable']] = $row['value'];
}
$smcFunc['db_free_result']($request);
}


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Antechinus

No, it doesn't touch member settings or cookies. All it does is a session-dependent change of url, so if you thought it was holding across sessions/login/logout you must have been hallucinating.

Sir Osis of Liver

Well, that's always a possibilty.  Don't see any easy way to make it do what I want.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Antechinus

Exactly* what do you want it to do?

*This word is important.

Sir Osis of Liver

Same thing as changing theme in Profile -> Look and Layout.  Think I'll try adding button in header that does this -



https://www.simplemachines.org/community/index.php?action=theme;sa=pick


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Antechinus

Ok, if that's the only functionality you want then it makes sense to use the default functionality. But, obviously that's not available for guests, so they will be stuck with whatever is the site default. Which is why people invented theme changers.

Sir Osis of Liver

I'm not concerned about guests, just need a simple way for members to change their theme.  Stuck a button in header here, looks kind of crappy but it works.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Antechinus

if ($context['user']['is_logged'])
{
echo '


Will save a lot of error messages from guests and spiders. ;)

Sir Osis of Liver

Good idea. 

Also did a crappy hack in Themes.template.php to remove 'Forum or Board Default' so each theme is listed only once -



// Just go through each theme and show its information - thumbnail, etc.

foreach ($context['available_themes'] as $theme)
{
if($loop == null) {
$loop = 1;
continue;
}
echo '
<div class="cat_bar">
<h3 class="catbg">
<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $theme['name'], (!empty($theme['variants']) ? ';vrt=' . $theme['selected_variant'] : ''), '</a>
</h3>



Got a feeling it's not a great idea, but makes things less confusing for dopey users (it's always confused me :P).
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Deaks

Any plans to make this work for 2.1?? :D
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Shades.

@vbgamer45 I could really use this mod for SMF 2.1.2! Any chance you can update it? O:)  8)
ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

vbgamer45

Updated for SMF 2.1.x!
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Shades.

Thank you for updating! :)

I'm getting the same error as I was getting when I tried to use the old version. But it only happens when I put the theme changer up top. If I move it down to the bottom, no errors.

QuoteError
Type of error
Undefined_vars
Error message
8: Undefined index: forum_width
File
/home/******/public_html/******/Sources/cls.php
Line
97
URL of page causing the error
https://******.com/index.php?action=admin;area=modsettings;sa=cls;

Backtrace information
#0: smf_error_handler()
Called from /home/******/public_html/******/Sources/cls.php on line 97
#1: cls_change_theme_top()
Called from /home/******/public_html/******/Sources/Subs.php on line 4546
#2: template_header()
Called from /home/******/public_html/******/Sources/Subs.php on line 4150
#3: obExit()
Called from /home/******/public_html/******/index.php on line 194

SMF 2.1.2 Fresh install, No mods other than this one. ;)
ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

vbgamer45

Fixed above error^

2.0 Added caching support less db queries per page load.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Shades.

Quote from: vbgamer45 on October 12, 2022, 08:27:10 PMFixed above error^

2.0 Added caching support less db queries per page load.
Works great now thank you! :)  8)
ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

Shades.

I moved the Theme Changer over to the top left. Just wondering if this was the correct way to do it? It works and I'm not seeing any errors.

In cls.php around lines 109 & 133 I changed:
               <!-- START ClickSafe SMF Change Theme TOP -->                     
              <div style="margin: auto; text-align:right; width:'.$settings['forum_width'].'; font-size:12px;">

To:
               <!-- START ClickSafe SMF Change Theme TOP -->                     
              <div style="margin: auto; text-align:left; margin: 5px 100px 0; width:'.$settings['forum_width'].'; font-size:12px;">

Does that look correct? Not sure if I need that zero at the end of "margin: 5px 100px 0;" or even if this is the correct way to do it. I was just playing around with it and it worked. :o  ;D

You can check it out on my site. ;)

You cannot view this attachment.
ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: