SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: KahneFan on March 02, 2009, 12:27:48 AM

Title: Theme Change Block
Post by: KahneFan on March 02, 2009, 12:27:48 AM
Is there a way to create a block with the ability to change themes from a drop down?

I've installed the Simple Theme Changer (http://custom.simplemachines.org/mods/index.php?mod=1342) mod, and it has a code that I can insert wherever I'd like the drop down to appear. I tried placing the code in a SP PHP block and it displayed the drop down, but no theme names appeared for some reason.
Title: Re: Theme Change Block
Post by: Robbo on March 02, 2009, 12:44:28 AM
Show me the code you tried to insert. There is a possibility you just made a small mistake.
Title: Re: Theme Change Block
Post by: KahneFan on March 02, 2009, 12:52:41 AM
Per STC mod:

Code: [Select]
echo '
<select id="simple_theme_changer" onchange="switch_theme();">
   <optgroup label="', $txt['simple_theme_changer_name'], '">';

foreach ($context['themes'] as $id => $theme)
   echo '
      <option value="', $id, '"', (($settings['theme_id'] == $id) ? ' selected="selected"' : ''), '>', $theme, '</option>';

echo '
   </optgroup>
</select>

<script language="JavaScript" type="text/javascript">
   <!--
   function switch_theme(){
   theme_changer = document.getElementById("simple_theme_changer");
      var id = theme_changer.options[theme_changer.selectedIndex].value;
      var page = new String(window.location);

      window.location = "index.php?action=theme;sa=pick;type=quick;u=', $context['user']['id'] ,';th=" + id + ";sesc=', $context['session_id'], ';page=" + escape(page);
      return false;
   }
   -->
</script>';
Title: Re: Theme Change Block
Post by: Yağız... on March 02, 2009, 01:16:00 PM
Try this:

2.0 RC1:
Code: [Select]
global $smcFunc, $context, $txt;
// Simple Theme Changer
$request = $smcFunc['db_query']('', '
SELECT *
FROM {db_prefix}themes
WHERE variable = {string:name}
AND id_member = 0',
array('name' => 'name')
);
$context['themes'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['themes'][$row['id_theme']] = $row['value'];
$smcFunc['db_free_result']($request);
echo '
<select id="simple_theme_changer" onchange="switch_theme();">
<optgroup label="', $txt['simple_theme_changer_name'], '">';

foreach ($context['themes'] as $id => $theme)
echo '
<option value="', $id, '"', (($settings['theme_id'] == $id) ? ' selected="selected"' : ''), '>', $theme, '</option>';
echo '
</optgroup>
</select>
<script language="JavaScript" type="text/javascript">
<!--
function switch_theme(){
theme_changer = document.getElementById("simple_theme_changer");
var id = theme_changer.options[theme_changer.selectedIndex].value;
var page = new String(window.location);
window.location = "index.php?action=theme;sa=pick;type=quick;u=', $context['user']['id'] ,';th=" + id + ";sesc=', $context['session_id'], ';page=" + escape(page);
return false;
}
-->
</script>';
1.1.8:
Code: [Select]
global $db_prefix, $context, $txt;
// Simple Theme Changer
$request = db_query("
SELECT *
FROM {$db_prefix}themes
WHERE variable = 'name'
AND ID_MEMBER = 0", __FILE__, __LINE__);
$context['themes'] = array();
while($row = mysql_fetch_assoc($request))
$context['themes'][$row['ID_THEME']] = $row['value'];

mysql_free_result($request);
// End Simple Theme Changer
echo '
<select id="simple_theme_changer" onchange="switch_theme();">
<optgroup label="', $txt['simple_theme_changer_name'], '">';
foreach ($context['themes'] as $id => $theme)
echo '
<option value="', $id, '"', (($settings['theme_id'] == $id) ? ' selected="selected"' : ''), '>', $theme, '</option>';
echo '
</optgroup>
</select>
<script language="JavaScript" type="text/javascript">
<!--
function switch_theme(){
theme_changer = document.getElementById("simple_theme_changer");
var id = theme_changer.options[theme_changer.selectedIndex].value;
var page = new String(window.location);
window.location = "index.php?action=theme;sa=pick;type=quick;u=', $context['user']['id'] ,';th=" + id + ";sesc=', $context['session_id'], ';page=" + escape(page);
return false;
}
-->
</script>';
Title: Re: Theme Change Block
Post by: KahneFan on March 02, 2009, 08:00:01 PM
Perfect, thanks!
Title: Re: Theme Change Block
Post by: Dream12 on April 01, 2009, 08:50:22 AM
Hi i have installed and used the code you have provided but when i go to change themes it just chucks me to a link

"that doest extince and get page cannot be found on sever"

any ideas.

thanks.

Have attached a link taht shows the screen after changing the theme
Title: Re: Theme Change Block
Post by: Number7 on April 04, 2009, 12:01:05 AM

Yağız, your code works fine at switching the theme, but i end up at the profile / look & layout page instead of the page i was originated.

Any way to change that?  (smf 2.0rc1)
Title: Re: Theme Change Block
Post by: KahneFan on April 04, 2009, 01:04:11 AM
Since the code above only works for members, I hand wrote a BBC block and manually added links, so that guests could use it as well. You can see the block on my forum, not my portal:

http://ipostyoupost.com/index.php?action=forum

And, since I like to show what the theme looks like on the forum and not the portal, I used the link below with the corresponding theme # at the end...

http://ipostyoupost.com/index.php?action=forum;theme=22

If you just use:

http://ipostyoupost.com/index.php?theme=22

It will "refresh" people to your portal page if you prefer.
SimplePortal 2.3.8 © 2008-2024, SimplePortal