News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Theme picker at top

Started by Miraenda, April 27, 2005, 08:14:06 PM

Previous topic - Next topic

bloc

Nice, Ohms. :) Easier to see which theme you are watching, with current auto-selected.

Ohms

#21
I just decided to add the Theme in Profile Mod and discovered that if they use the Quick Theme Changer to pick their theme, it did not get changed in their profile (e.g. the database), so I did some more tweaking with this.

The section in Load.php now looks like this:// Quick theme changer
function theme_name(){
  global $settings,$db_prefix,$context,$scripturl;
  $context['theme_options'] = "";
$resultaa=db_query("
        SELECT * from {$db_prefix}themes WHERE `variable` = 'name' ORDER by `value`", __FILE__, __LINE__);
while($rowaa=mysql_fetch_array($resultaa)){
$theme_rowa=$rowaa['ID_THEME'];
$theme_row_namea=$rowaa['value'];
$selected = "";
if ($settings['theme_id'] == $theme_rowa){
   $selected = "selected";
   }

$blech = $context['user']['id'];
$blech2 = $context['session_id'];
// $context['theme_options']="".$context['theme_options']."<option value=\"$scripturl?theme=$theme_rowa\" $selected>$theme_row_namea</option>";
$context['theme_options']="".$context['theme_options']."<option value=\"$scripturl?action=theme;sa=quickpick;u=$blech;id=$theme_rowa;sesc=$blech2\" $selected>$theme_row_namea</option>";
}
}


In Themes.php, near the top I changed:
$subActions = array(
'admin' => 'ThemeAdmin',
'settings' => 'SetThemeSettings',
'options' => 'SetThemeOptions',
'remove' => 'RemoveTheme',
'pick' => 'PickTheme',
'install' => 'ThemeInstall',
'edit' => 'EditTheme'
);

to:$subActions = array(
'admin' => 'ThemeAdmin',
'settings' => 'SetThemeSettings',
'options' => 'SetThemeOptions',
'remove' => 'RemoveTheme',
'pick' => 'PickTheme',
'quickpick' => 'QuickPick',
'install' => 'ThemeInstall',
'edit' => 'EditTheme'
);


Then I made a copy of the function PickTheme, calling it instead QuickPick and made some changes in the function [just replaced the 'redirectexit('blahblah')' code where you see my comments in two places with a javascript back() function]:
function QuickPick()
{
global $txt, $db_prefix, $sc, $context, $modSettings, $user_info, $ID_MEMBER, $language;

checkSession('get');

loadTemplate('Themes');
loadLanguage('Profile');

$_SESSION['ID_THEME'] = 0;

// Have we made a desicion, or are we just browsing?
if (isset($_GET['id']))
{
// Save for this user.
if (!isset($_REQUEST['u']) || !allowedTo('admin_forum'))
{
updateMemberData($ID_MEMBER, array('ID_THEME' => (int) $_GET['id']));
   // I changed redirectexit to this.
                   ?><script>
                       back()
                   </script><?php
                  
// End of this change. One more.
}
// For everyone.
elseif ($_REQUEST['u'] == '0')
{
updateMemberData(null, array('ID_THEME' => (int) $_GET['id']));

redirectexit('');
}
// Change the default/guest theme.
elseif ($_REQUEST['u'] == '-1')
{
updateSettings(array('theme_guests' => (int) $_GET['id']));

redirectexit('');
}
// Change a specific member's theme.
else
{
updateMemberData((int) $_REQUEST['u'], array('ID_THEME' => (int) $_GET['id']));
                   
// I changed redirectexit to this, too.      
                  
?>
<script>
                       back()
                   </script><?php
                  
// End of my change.
}
}

// Figure out who the member of the minute is, and what theme they've chosen.
if (!isset($_REQUEST['u']) || !allowedTo('admin_forum'))
{
$context['current_member'] = $ID_MEMBER;
$context['current_theme'] = $user_info['theme'];
}
// Everyone can't chose just one.
elseif ($_REQUEST['u'] == '0')
{
$context['current_member'] = 0;
$context['current_theme'] = 0;
}
// Guests and such...
elseif ($_REQUEST['u'] == '-1')
{
$context['current_member'] = -1;
$context['current_theme'] = $modSettings['theme_guests'];
}
// Someones else :P.
else
{
$context['current_member'] = (int) $_REQUEST['u'];

$request db_query("
SELECT ID_THEME
FROM 
{$db_prefix}members
WHERE ID_MEMBER = 
$context[current_member]
LIMIT 1"
__FILE____LINE__);
list ($context['current_theme']) = mysql_fetch_row($request);
mysql_free_result($request);
}
// Get the theme name and descriptions.
$context['available_themes'] = array();
if (!empty($modSettings['knownThemes']))
{
$knownThemes implode("', '"explode(','$modSettings['knownThemes']));

$request db_query("
SELECT ID_THEME, variable, value
FROM 
{$db_prefix}themes
WHERE variable IN ('name', 'theme_url', 'theme_dir', 'images_url')" 
. (empty($modSettings['theme_default']) && !allowedTo('admin_forum') ? "
AND ID_THEME IN ('
$knownThemes')
AND ID_THEME != 1" 
'') . "
AND ID_THEME != 0
LIMIT " 
count(explode(','$modSettings['knownThemes'])) * 4__FILE____LINE__);
while ($row mysql_fetch_assoc($request))
{
if (!isset($context['available_themes'][$row['ID_THEME']]))
$context['available_themes'][$row['ID_THEME']] = array(
'id' => $row['ID_THEME'],
'selected' => $context['current_theme'] == $row['ID_THEME'],
'num_users' => 0
);
$context['available_themes'][$row['ID_THEME']][$row['variable']] = $row['value'];
}
mysql_free_result($request);
}

// Okay, this is a complicated problem: the default theme is 1, but they aren't allowed to access 1!
if (!isset($context['available_themes'][$modSettings['theme_guests']]))
{
$context['available_themes'][0] = array(
'num_users' => 0
);
$guest_theme 0;
}
else
$guest_theme $modSettings['theme_guests'];

$request db_query("
SELECT COUNT(ID_MEMBER) AS theCount, ID_THEME
FROM 
{$db_prefix}members
GROUP BY ID_THEME DESC"
__FILE____LINE__);
while ($row mysql_fetch_assoc($request))
{
// Figure out which theme it is they are REALLY using.
if ($row['ID_THEME'] == && empty($modSettings['theme_default']))
$row['ID_THEME'] = $guest_theme;
elseif (empty($modSettings['theme_allow']))
$row['ID_THEME'] = $guest_theme;

if (isset($context['available_themes'][$row['ID_THEME']]))
$context['available_themes'][$row['ID_THEME']]['num_users'] += $row['theCount'];
else
$context['available_themes'][$guest_theme]['num_users'] += $row['theCount'];
}

foreach ($context['available_themes'] as $ID_THEME => $theme_data)
{
// Don't try to load the forum or board default theme's data... it doesn't have any!
if ($ID_THEME == 0)
continue;

$settings $theme_data;
$settings['theme_id'] = $ID_THEME;

if (file_exists($settings['theme_dir'] . '/languages/Settings.' $user_info['language'] . '.php'))
include($settings['theme_dir'] . '/languages/Settings.' $user_info['language'] . '.php');
elseif (file_exists($settings['theme_dir'] . '/languages/Settings.' $language '.php'))
include($settings['theme_dir'] . '/languages/Settings.' $language '.php');
else
{
$txt['theme_thumbnail_href'] = $settings['images_url'] . '/thumbnail.gif';
$txt['theme_description'] = '';
}

$context['available_themes'][$ID_THEME]['thumbnail_href'] = $txt['theme_thumbnail_href'];
$context['available_themes'][$ID_THEME]['description'] = $txt['theme_description'];
}

// As long as we're not doing the default theme...
if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
{
if ($guest_theme != 0)
$context['available_themes'][0] = $context['available_themes'][$guest_theme];
$context['available_themes'][0]['id'] = 0;
$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
$context['available_themes'][0]['selected'] = $context['current_theme'] == 0;
$context['available_themes'][0]['description'] = $txt['theme_global_description'];
}

ksort($context['available_themes']);

$context['page_title'] = &$txt['theme_pick'];
$context['sub_template'] = 'pick';
}


The entire function probably didn't need to remain intact, but I figured I would err on the side of security and leave it in. If any PHP gurus out there can tell me what I can leave out, that would be awesome.

Doing it this way, the theme they are using gets updated in the database (e.g. their profile) and then they are redirected back to wherever they were when they changed the theme.

So, now the Theme in Profile Mod works with this as well.

This probably slows this down quite a bit.

LostProphecy

hmmm nice :)

i'll have to remember to try this out when i get home tonight :D
Angelus Ex Quo Nox

LostProphecy

looking at this it's quite massive... has anyone thought of making it a mod??
Angelus Ex Quo Nox

Terroriste

Thank you. You're best coder :)

IamV

I just tried Kirby's theme changer & it is the best I've tried so far!

It should be renamed 'The Ultimate Theme Changer/Selector'

Thank you so much for sharing this with us  ;D

LostProphecy

i'm generating this error all the time from the themechanger thingy...

8: Undefined index: theme_options
File: /home/kodee/public_html/forums/Themes/themechanger.php
Line: 5

can anyone help me in how you define "theme_options"
Angelus Ex Quo Nox

Escobar

#27
Problem:
I have smf 1.05.
I tried this code.
I placed the second part in various places...but it doesn't show up.  :(
Any help?

EDIT (SOLUTION FOUND AFTER TINKERING):
I put it above
// Show the menu up top.  Something like [home] [help] [profile] [logout]...function template_menu()
and it showed up.

Next problem is having the change show up in the users profile...
I can't locate load.php and the other files ohms is talking about...



I chose SMF because you get your questions answered.

DemonicInfluence

Quote from: ashoka1 on September 13, 2005, 05:44:22 PM
Problem:
I have smf 1.05.
I tried this code.
I placed the second part in various places...but it doesn't show up.  :(
Any help?

EDIT (SOLUTION FOUND AFTER TINKERING):
I put it above
// Show the menu up top.  Something like [home] [help] [profile] [logout]...function template_menu()
and it showed up.

Next problem is having the change show up in the users profile...
I can't locate load.php and the other files ohms is talking about...




It is in the Sources folder..

barnjo

So where do I put the code that starts function QuickPick ()?

DemonicInfluence


berserk87

how do i put the theme chooser at the bottom of the page next to the xhtml, and css and myslq buttons and such?

were are they?
smf and php n00b

bloc

In index.template.php..look for <img id="powered-mysql"....etc. In default theme there is 3 <td>'s there.

Xarcell

I'm lost.
-------------------------------------------------------------
Instructions:
------------------------------------------------------------
Then, add in the index.php file:

theme_name();

right after:

loadTheme();

--------------------------------------------------------------

The Index file in the main smf directory right? I can't seem to find "theme_name();". My dropdown is blank.



-Xarcell, using 1.1rc1

bloc

No, find the second ("loadTheme") first and put the first("theme_name") after it...

Xarcell

#35
I already tried adding "theme_name();" before the theme_load but all I got was an error.

<-- Session verification failed. Please try logging out and back in again, and then try again.-->

I did, but it still kept doing the same thing. Now I tried moving the "theme_name();" around a bit and can't egt it to do anything.

BTW, I must be blind, because I only see one "theme_load()" in the file. Thanx for your help though. I got frustrated and had to take a break. Now I'm back on it again, lol...

-Xarcell

Xarcell

#36
Ok, I've tinkered with it a little more and it works now. However, after I select a theme, I have to refresh to get it to work. Or view the theme I picked.

Also, is there anyway to get the thumbnails of the theme to appear?

Thanx again,

EDIT: I thougt it would help to mention this, but I didn't use the global file/code for layout reasons, although the themechanger.php is in place. I used this



echo '<center><form name="jumpurl1" onSubmit="return jumpit()">
                <select size="1" name="jumpurl2">
                      '.$context['theme_options'].'
                </select>
                <input type="button" value="Change it!" onClick="jumpit()"></form></center>
                   <script>
                       function jumpit(){
                          window.location=document.jumpurl1.jumpurl2.value
                          return false
                       }
                   </script>';



I also used Ohms code suggestion for the load.php. theme.php, etc.

-Xarcell

bloc

In fact, my latest version of TinyPortal have a theme-chooser that show thumbnails of the themes... ;)

The code is tailored for TP though, with options to choose which themes should show in the chooser - so its not instantly appliable for "normal" themes/SMF.

DemonicInfluence

Could u show. So that we could try to modify it so it works normally?

Xarcell

Your a good man bloc.

I applied for beta testing TP.

-Xarcell

Advertisement: