News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

SMF Quick Theme Changer

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

Previous topic - Next topic

Photoshocker


ladynada

just to let people know, that I needed to make a change in the code to get validation.

I had to use


? 'selected="selected"' :



I am using a modified version of this theme changer
thanks
nada
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

polaroidfuse

#22
This seems like a great mod, but it just doesnt make sense.

I installed it correctly on the default theme, and nothing happened.

It would also be nice if you could tell us exactly what code needs to be replaced in order for it to work in other themes in the index.template.php file.

Lady_Of_Chaos

heyas , I got this installed , I also did the edits to have it show on other themes , but when you choose to change theme , it says "error on page" at the bottom and doesnt change

ladynada

here is a copy I sent in PM to someone who asked the same thing

-- note: regarding the quick theme changer.  thanks go to Hambil who shared this mod with the SMF family
http://custom.simplemachines.org/mods/index.php?mod=746
I modified it.  To add it to your OTHER THEMES so you can switch between them and seemer based themes
or this custom theme:

in the index.php of your forum folder, look for:


// Start the session. (assuming it hasn't already been.)
loadSession();


then AFTER that insert this:


// -- 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


now for each theme

now, in the index.template.php that you wish to have a theme changer, look for the section where the
copyright is displayed at the bottom of the screen.  You should see above that part, where a script command
ends, and a new table begins.


// ]]></script>
      <table cellspacing="0" cellpadding="3" border="0" align="center" width="100%">
         <tr>


under the </script> insert this part


<!-- // Quick Theme Changer Script -->
   <script language="JavaScript" type="text/javascript">
      function quick_theme_changer(obj)
      {
      var id = obj.options[obj.selectedIndex].value;
      var url = new String(window.location);
      loc = \'index.php?theme=\' + id + \';saa=quick\' + \';url=\' + escape(url);
      window.location = loc;
      }
   </script>
<!-- // Quick Theme Changer End -->


if your theme has been altered, you are looking to insert the theme changer code BETWEEN the <table>
and the <tr>. so insert this:


<!-- // Quick Theme Changer Start -->
   <tr>
      <td colspan="3" style="text-align: center;">
      <select class="skin_changer" name="quick_theme_changer" onchange="quick_theme_changer(this)">
      <optgroup label="', $txt['quick_theme_changer'], '">';
         foreach ($context['themes'] as $theme)
            {
            echo '<option value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? 'selected="selected"' : ''), '>', $theme['name'], '</option>';
            }
      echo '</optgroup>
      </select>
      </td>
   </tr>
<!-- // Quick Theme Changer End -->

you know how to make sure you have an echo ' when needed?  or to shut off echo with a '; when needed?  in case of errors like that?

its easy, I added it to all my themes in a few minutes, always make backups first.
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

ladynada

I am working on a new theme and added the changer to it.  if you want to make the changer in its own table here is the code I am using in a left sidebar:



echo '


<script language="JavaScript" type="text/javascript">
function quick_theme_changer(obj)
{
var id = obj.options[obj.selectedIndex].value;
var url = new String(window.location);
loc = \'index.php?theme=\' + id + \';saa=quick\' + \';url=\' + escape(url);
window.location = loc;
}
</script>
<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center">
<tr>
<td class="sidebar_titles" align="center">';
echo , $txt['quick_theme_changer'], '<br />
</td></tr><tr>
<td>
<select class="skin_changer" name="quick_theme_changer" onchange="quick_theme_changer(this)">
<optgroup label="', $txt['quick_theme_changer'], '">';
foreach ($context['themes'] as $theme)
{
echo '<option style="text-align: left;" value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? 'selected="selected"' : ''), '>', $theme['name'], '</option>';
}
echo '</optgroup>
</select>
</td>
</tr>
</table>';




hope these help..
nada

WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

Iron IC

Hello there!

Great mod you made here. It works as it should, but unfortunately I get error messages in admin area under Maintainance -> Logged errors.

I run version 1.1.2. Any chance for at fix for this problem? That would be great. Thank you!

Here are some of the error messages I`ve gotten:

8: Undefined index: quick_theme_changer
Fil: /usr/home/web/webx/byggmuskler.no/forum/Themes/default/Admin.template.php (eval?)
Linje: 368

8: Undefined index: quick_theme_changer
Fil: /usr/home/web/webx/byggmuskler.no/forum/Themes/default/BoardIndex.template.php (eval?)
Linje: 368

8: Undefined index: quick_theme_changer
Fil: /usr/home/web/webx/byggmuskler.no/forum/Themes/default/Display.template.php (eval?)
Linje: 368

8: Undefined index: quick_theme_changer
Fil: /usr/home/web/webx/byggmuskler.no/forum/Themes/default/MessageIndex.template.php (eval?)
Linje: 368

8: Undefined index: quick_theme_changer
Fil: /usr/home/web/webx/byggmuskler.no/forum/Themes/default/Errors.template.php (eval?)
Linje: 368

Ladynada: How do I get the Theme Changer to appear if I install this mod manually after your example above? Do I have still have to import and activate the mod from inside admin first, and then apply the modifications? Excuse me, but I am not an expert on these sort of things.  :(


Regards Iron IC

ladynada

my reply crashed, good thing I copied and pasted it to a file before trying to save it. that can happen on any forum, so its a good habit to get into for long replies


Hi Iron IC,
I downloaded it again to refresh my memory.  To manually add this with my modifications, I did NOT change Themes.php at all in the sources folder.

next:  I DID add the code in the SMF folder's index.php and here is how mines looks after the edit.



// Start the session. (assuming it hasn't already been.)
loadSession();

// -- 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


// What function shall we execute? (done like this for memory's sake.)


That was an easy copy and paste

next:

there are two parts you need to add to the theme's Index.template.php.  I agree with the author that the best place is at the bottom (once you get the hang of it you could put it in a sidebar like I did with my elijah theme).

In the earthmom theme which you could download to look at the code, I put the java script part right after the script code for the footarea.  That spot starts where you will see:


// Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!


right after where their script ends, paste in the script section from this theme changer mod like this:



// ]]></script>

<!-- // Quick Theme Changer Script -->
<script language="JavaScript" type="text/javascript">
function quick_theme_changer(obj)
{
var id = obj.options[obj.selectedIndex].value;
var url = new String(window.location);
loc = \'index.php?theme=\' + id + \';saa=quick\' + \';url=\' + escape(url);
window.location = loc;
}
</script>
<!-- // Quick Theme Changer End -->



insert the code from the mod AFTER this:

// ]]></script>


Be sure to use my code, and by the way, my changes will not make the theme change 'permanent' for the user, but only for that session.

last:

you need to put the code for the changer itself. And in the earthmom theme I 'inserted' the code as a <tr> ....  </tr> section, inside the section before the SMF logos and stuff.



<tr>
<td colspan="3" style="text-align: center;">
<select class="skin_changer" name="quick_theme_changer" onchange="quick_theme_changer(this)">
<optgroup label="', $txt['quick_theme_changer'], '">';
foreach ($context['themes'] as $theme)
{
echo '<option value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? 'selected="selected"' : ''), '>', $theme['name'], '</option>';
}
echo '</optgroup>
</select>
</td>
</tr>




So.. if you want, you can simply make your own table and use that <tr> ....  </tr> section in it for the changer.  Just be sure you have the java script section before it to avoid those index errors where a variable name is being referenced without being declared beforehand.

It is very easy.  But I put the code in different places in my themes depending on how things changed as I made themes. So you could look at the code in any of my themes to get an idea.

So as not to confuse you, I will post in the next message, the code I used in my current elijah theme on my site, with the theme changer in the side bar.

nada


WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

ladynada

just another way to do it. all you need is the code from the mod entered into your SMF folder's index.php, like it says. Again, you do NOT need to change your Themes.php in the sources folder, as the theme change with my method will NOT be permanent for the user. Then for this example, here is the code I used in the sidebar on my current elijah theme at http://heartdaughter.com/



echo '


<script language="JavaScript" type="text/javascript">
function quick_theme_changer(obj)
{
var id = obj.options[obj.selectedIndex].value;
var url = new String(window.location);
loc = \'index.php?theme=\' + id + \';saa=quick\' + \';url=\' + escape(url);
window.location = loc;
}
</script>
<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center">
<tr>
<td class="sidebar_titles" align="center">';
echo , $txt['quick_theme_changer'], '<br />
</td></tr><tr>
<td>
<select class="skin_changer" name="quick_theme_changer" onchange="quick_theme_changer(this)">
<optgroup label="', $txt['quick_theme_changer'], '">';
foreach ($context['themes'] as $theme)
{
echo '<option style="text-align: left;" value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? 'selected="selected"' : ''), '>', $theme['name'], '</option>';
}
echo '</optgroup>
</select>
</td>
</tr>
</table>';



nada
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

Iron IC

#29
OMG, I will need some time to try and understand all this stuff :) I wish I was as good at this as you are, and that`s VERY GOOD, obviously! Thanks a million! I will chime in again if I have any questions. I guess the only way to learn is trial and error!

Oh, wait! You didn`t answer all my questions: I still wonder if I need to install the original theme changer mod from inside admin for this to work?

You are saying this mod does not change theme permanent for the user, but does it allow guests to change the theme as well? I do not want guests to be able to change the theme...

ladynada

Quote from: Iron IC on June 06, 2007, 06:15:33 PM
OMG, I will need some time to try and understand all this stuff :) I wish I was as good at this as you are, and that`s VERY GOOD, obviously! Thanks a million! I will chime in again if I have any questions. I guess the only way to learn is trial and error!

Oh, wait! You didn`t answer all my questions: I still wonder if I need to install the original theme changer mod from inside admin for this to work?

You are saying this mod does not change theme permanent for the user, but does it allow guests to change the theme as well? I do not want guests to be able to change the theme...

yes it does let guests change the theme. and no you do not, and should not install it from admin, if you add it manually like this.

Someone else will have to give a code fragment to test if the user is a guest and not allow them to actually change the theme.  I am not as good at coding as you have said!  :)

nada
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

Iron IC

Hello again! Oh, don`t be shy, you are at least much better than me at this coding stuff, that`s for sure, lol.

I am afraid I do not quit understand everything you said here, I guess you will have to spoonfeed it to me. One thing I managed myself though, was to edit Themes.php, so that the changes to the theme is permanent. I only used the first piece of code (see page 1 in this thread), and not the one that allows guests to change the theme. This is actually working, but this is before I even have tried your manual approach. I still get all the annoying error messages inside admin.

Isn`t there a simple way to get rid of these errors , as the mod are working nicely as it is? (Even though the errors don`t actually affect the function of the mod.)

I tried to apply your mod to the index.template and that made the changer disappear from the forum (but this was done while the mod was installed from admin, so I guess that`s why it happened.)

If I where to give this manual editing a try with your modifications, do I have to edit something to the mod`s .xml file too? In that case, please show me exactly what and where to edit code. PS! If you think I am a complete idiot, just tell me to forget the whole thing and I won`t bother you anymore.  :-[

Thnx
Iron IC


ladynada

Hi Iron IC,

No I do not think you are an idiot.  I am wondering why you get those errors.  You might have part of the code in your Index.template.php more than once.

For you to use my manual edit, you would have uninstall the mod through the admin.  Also, I do not use the Themes.php  modification at all.  It is possible that the code there is causing your error, but I am not sure.

What I would do, is start all over and uninstall the mod, and check the files for any duplicate code from the mod and delete.  OR if you made backups, you could go back to your backups.

Let me know what happens,
nada
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

Iron IC

#33
You are to kind! Thank you very much. I`ll let you know what happens! (By the way, I get the errors with or without the themes.php modification so that`s not it) :)

Iron IC

#34
I guess maybe the problem has to do with me running norwegian-utf8. I got the same kind of errors with the Order News mod. I got rid of them after copying the contents from Themes/default/languages/modifications.english.php into modifications.norwegian-utf8.php.

Problem is, there`s no modifications in modifications.english.php that has to do with the Quick Theme Changer, so I have no text to paste into the norwegian modfile. Maybe this info can make you understand what the problem is?

I checked for duplicate code, but it seem to be correct the way it is.

Iron IC

ladynada

Quote from: Iron IC on June 07, 2007, 07:59:56 AM
You are to kind! Thank you very much. I`ll let you know what happens! (By the way, I get the errors with or without the themes.php modification so that`s not it) :)

basically that UNDEFINED error is due to some code trying to use a variable before the variable has been officially given a value.

It is like calling your 12 year old child by a name, when you never named him when he was born.

hope that helps you understand.  it means you have, possibly, some code that the program sees BEFORE the code that tells the program the value for the named-variable that the error complains about. 

by the way, PHP will sometimes still execute the program correctly!  So, just because you see an undefined error that does not mean the program will not still work right, however it does mean that you should fix it, because your log will fill up, and the code is not right.

Hey charlie!  dinner time!

charlie:  who is charlie?  everyone has called me junior ever since I was born, but I will come to dinner anyway!

nada
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

locomotion182

is there anyway to hide a particular theme? I dont want to show the SMF default theme to my usrs, is that possible?

ladynada

Quote from: locomotion182 on June 07, 2007, 08:47:28 PM
is there anyway to hide a particular theme? I dont want to show the SMF default theme to my usrs, is that possible?

Well, in the admin panel, under THEMES AND SETTINGS, you can click next to the default theme so that the red X goes away, and then that theme will not be available, but the files will still be on your system.

hope this helps
nada
WORK for Truth, Print it, Take Time to READ ALL LINKS NOTED  click here --> The TWO Witnesses are Mom and Dad and SMF Skins

locomotion182

hmm
one question though if i do this, next time i add a mod, it wont  be added to the SMF default theme right?
Im asking because as an Admin i want to keep it, to test the mods and everything.

Iron IC

Hello loco!

Yes, I think you are correct. The modifications are affecting the theme that is set to default.

Advertisement: