SMF Quick Theme Changer

Started by Hambil, April 04, 2007, 01:46:44 PM

Previous topic - Next topic

I AM Legend

#60
Awesome, That worked perfect.
Thanks for the help and assistance.

The Cadet

So... This mod works on the 1.1.6 board Default Style. However, I tried to add it to the other styles, and I couldn't for the life of me figure it out. Could you help me out? File is attached. Also, would I need to modify any other files in this style?

The Cadet


cleanfiles

Works great on 1.1.7, working on 4 themes :)

fuddes

#64
I found a fix for keeping non-admin users on the same page!

Open /Sources/Themes.php

Find:
// Save for this user.
if (!isset($_REQUEST['u']) || !allowedTo('admin_forum'))
{
updateMemberData($ID_MEMBER, array('ID_THEME' => (int) $_GET['th']));

redirectexit('action=profile;sa=theme');


Replace with:
// Save for this user.
if (!isset($_REQUEST['u']) || !allowedTo('admin_forum'))
{
updateMemberData($ID_MEMBER, array('ID_THEME' => (int) $_GET['th']));

            redirectexit($_REQUEST['url']);


I'm not sure why or how it works, but it does. I was just tinkering around and trying anything. I have been using it for a few days now and haven't found any problems.

Gitominoti

I'm seeming to have trouble with this mod. Whenever I try to edit the index.template.php on some skins, some or all of the code is missing that is needed to be changed. Whenever I edit what is there, the skin breaks, and if I leave it the mod doesn't work on the skin. How do I make it work on the skins?

sixthofmay

Quote from: fuddes on June 21, 2007, 02:04:34 PM
Anyone know how to sort the themes in alphabetical order on the pulldown menu?

I was wondering the same.
And also there is no option to go back to the forum or board default. If you want to do that you have to go into your profile "Look and Layout Preferences" and change to the default from there. I'm running SMF 1.1.8.

I'll take a look a the code and see if I can figure out a mod.

Fustrate

Since development on this modification stopped quite a while ago, I'll go ahead and post that there's been a new mod put out that does the same thing and also supports 2.0 (and 1.1.8 )... http://custom.simplemachines.org/mods/index.php?mod=1342
Steven Hoffman
Former Team Member, 2009-2012

sixthofmay

#68
Quote from: Fustrate on April 25, 2009, 07:00:19 PM
Since development on this modification stopped quite a while ago, I'll go ahead and post that there's been a new mod put out that does the same thing and also supports 2.0 (and 1.1.8 )... http://custom.simplemachines.org/mods/index.php?mod=1342

I tried that one, and it added the field, but it didn't work at all. Don't know why, so I tried the SMF Quick Theme Changer which works fine for me.

I solved the alpha sort and the board default mod, and am writing up the mod now.

edit:
I'm going to test for a few days before posting the mod, but you can preview it on my site [nofollow]. It doesn't allow you to actually change the theme unless you are registered, but you can see the Default option and alpha sort in the dropdown.

sixthofmay

#69
If you install Pretty URLs, it breaks the SMF Quick Theme Changer when trying to change themes when in a forum (404 error).

edit:
ahhh.. the fix is not working right when a regular user..

edit2:
Ok got it working hopefully..
The admin vs. regular user issue was relatively easy to fix. The redirect code in themes.php just needs to be in two places now. Not sure if that's a SMF 1.1.8 thing or Pretty URLs caused it.

While testing some more, a real bugger popped up when one of my topics had the word "they've" in it. More 404 errors when changing a theme while viewing the topic.
The cause was the redirect code in themes.php- the $_REQUEST['url'] function was not properly decoding single quote characters in the Pretty URLs url passed by the javascript function. It was decoding it as \\'
Bizarre...
I tried the other javascript url encode functions besides escape(url), but the single quote char always got mangled by $_REQUEST.
I finally figured out to use the str_replace function in the redirect, and to get that working took some head scratching:
redirectexit(str_replace('\\\\'',chr(39),$_REQUEST['url']));
Heh.

I'll post the full mod after a few more days of testing.

sixthofmay

#70
Ok it's been running fine with no issues, so here's the alpha sort, default theme at top of dropdown mod (plus fixes for non pretty and Pretty URLs):
Note I run SMF v1.1.8, so I have no idea if this will work on 2.X.
I also run Pretty URLs v0.9.2 (see notes below):

Find in /index.php:

// -- QUICK THEME CHANGER START
// Load the themes for the Quick Theme Changer downdown
$request = db_query("
SELECT ID_THEME, variable, value
FROM {$db_prefix}themes
WHERE variable IN ('name', 'theme_dir', 'theme_url', 'images_url')
AND ID_MEMBER = 0", __FILE__, __LINE__);
$context['themes'] = array();
while ($row = mysql_fetch_assoc($request))
{
if (!isset($context['themes'][$row['ID_THEME']]))
$context['themes'][$row['ID_THEME']] = array(
'id' => $row['ID_THEME'],
);
$context['themes'][$row['ID_THEME']][$row['variable']] = $row['value'];
}
mysql_free_result($request);
// -- QUICK THEME CHANGER END


Replace with:
This code I found in one of the other SMF php files. The ORDER BY value does the alpha sort. Note the original query code seems to be loading extra stuff into the array, that as far as I can tell, is never used.

// -- QUICK THEME CHANGER START modified
// Load all the theme IDs and names in alphabetical order
$request = db_query("
SELECT ID_THEME, value AS name
FROM {$db_prefix}themes
WHERE variable = 'name'
AND ID_MEMBER = 0
ORDER BY value", __FILE__, __LINE__);
$context['themes'] = array();

// add option for Forum or Board Default (at the top of the dropdown list)
$context['themes'][] = array(
'id' => 0,
'name' => 'Reset to Defaults'
);
while ($row = mysql_fetch_assoc($request))
{
$context['themes'][] = array(
'id' => $row['ID_THEME'],
'name' => $row['name']
);
}
mysql_free_result($request);
// -- QUICK THEME CHANGER END




Non Pretty URLs code fixes (note I didn't test this, as I run only Pretty URLs, post if it doesn't work):

If you get an odd page redirect as a non admin user (to the profile I think) when changing themes you may need this (note that fuddes mentioned this fix in a previous post above, and may only be needed with later SMF versions, like 1.1.8 ) :

Find in /Sources/Themes.php:

redirectexit('action=profile;sa=theme');


Replace with:

if (isset($_REQUEST['saa']) && $_REQUEST['saa'] == 'quick')
redirectexit($_REQUEST['url']);
else
redirectexit('action=profile;sa=theme');




Pretty URLs v0.9.2 code fixes (may not be needed with v0.9.3):

If you get an odd page redirect as a non admin user (to the profile I think) when changing themes or a 404 error if a single quote char is in the topic title you may need this:
Find in /Sources/Themes.php:

redirectexit('action=profile;sa=theme');


Replace with:

//odd str_replace code is to handle single quote chars in url not being properly decoded by $_REQUEST....
if (isset($_REQUEST['saa']) && $_REQUEST['saa'] == 'quick')
redirectexit(str_replace('\\\\'',chr(39),$_REQUEST['url']));
else
redirectexit('action=profile;sa=theme');


Find in /Sources/Themes.php:

redirectexit($_REQUEST['url']);


Replace with:

redirectexit(str_replace('\\\\'',chr(39),$_REQUEST['url']));


404 error fix:
Find in /Themes/default/index.template.php (or wherever yours is):

loc = \'index.php?action=theme;sa=pick;saa=quick;u=', $context['user']['id'] ,';th=\' + id + \';sesc=', $context['session_id'], ';url=\' + escape(url);


Replace with:

  loc = \'', $scripturl, '?action=theme;sa=pick;saa=quick;u=', $context['user']['id'] ,';th=\' + id + \';sesc=', $context['session_id'], ';url=\' + escape(url);


Post if it does or doesn't work!

Advertisement: