SimplePortal

Customization => Custom Coding => Topic started by: Kosedragen on November 18, 2008, 02:52:00 AM

Title: Themes block? O:
Post by: Kosedragen on November 18, 2008, 02:52:00 AM
I was wondering how one could make a custom block where one easily could change from one theme to another. I remember there being such a block in TinyPortal, and I thought it to be rather practical ^^
Title: Re: Themes block? O:
Post by: ???1031 on November 18, 2008, 06:03:28 AM
Hmm this is a very good idea and normal easy to made. (Because SMF give the ability to do it in an easy way).

I will look into it, because i think it can be easy created. :)

Bye
DIN1031
Title: Re: Themes block? O:
Post by: ???1031 on November 18, 2008, 06:37:57 AM
So here is a php block which can do that ;).

Code: [Select]
/*
This is a small Theme Picker.
Version 1.0.0 (18.11.08)
Tested only on SMF 1.1.x
*/

//This will show the Submit button, this is only for user who disable the Javascript, if you don't like it you can remove it by set it to 0
$showSubmitButton = 1;

//Here start the script :D and you know if you not know what you do do nothing after this ;)
global $modSettings, $context, $db_prefix, $settings;

$context['themes'] = array();

// Load the themes for pull down list
$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);

//The Java Script
echo '
<script language="JavaScript" type="text/javascript">
function sportal_theme_change(obj)
{
var id = obj.options[obj.selectedIndex].value;
var url = new String(window.location);
loc = \'index.php?theme=\' + id + \';sesc=', $context['session_id'], '\';
window.location = loc;
}
</script>';

//And the pulldown
echo '
<form>
<div style="text-align: center; witdh:99%;">
<select name="theme" onchange="sportal_theme_change(this)" style="width:95%;">';
foreach ($context['themes'] as $theme)
{
echo '
<option value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? ' selected' : ''), '>', $theme['name'], '</option>';
}
echo '
</select>' . (!empty($showSubmitButton) ? '
<input type="hidden" name="sesc" value="' . $context['session_id'] . '" />
<input type="submit" value="Submit" name="Submit" />
' : '') . '
</div>
</form>';
Title: Re: Themes block? O:
Post by: Kosedragen on November 18, 2008, 08:12:40 AM
That's neat! :D Maybe you could implement this as a future request?

Also; when you click the theme in the drop down-box it instantly switches. Maybe you could change it so that it does not switch at once, but you have to click "change" or "submit" firstl. And maybe it could show the thumbnail of the theme underneath? ^^
Title: Re: Themes block? O:
Post by: ???1031 on November 19, 2008, 10:17:23 AM
That's neat! :D Maybe you could implement this as a future request?

Also; when you click the theme in the drop down-box it instantly switches. Maybe you could change it so that it does not switch at once, but you have to click "change" or "submit" firstl. And maybe it could show the thumbnail of the theme underneath? ^^
Possible is everything ;).
This was only a first idea.
And the Submit button is normal only for user who disable the Javascirpt :).

Bye
DIN1031
Title: Re: Themes block? O:
Post by: Kosedragen on November 19, 2008, 11:21:09 AM
Oh, I meant that I'd actually prefer to click the "submit"-button before it changes ^^ That way one can view the thumbnail if it is added. Still I find this absolutely great : D
Title: Re: Themes block? O:
Post by: Costa on November 19, 2008, 12:09:36 PM
and where i can change the name of the "SUBMIT" button?
Title: Re: Themes block? O:
Post by: Nathaniel on November 19, 2008, 03:12:11 PM
Find this code:
Code: [Select]
<input type="submit" value="Submit" name="Submit" />
Change the 'value' attribute, to the title that you want.
Title: Re: Themes block? O:
Post by: ???1031 on November 19, 2008, 03:32:47 PM
So here is a little bit overworked version ;)
Follow things Added:
+ Image Preview of the Theme
+ Theme change is now permanent stored
+ Settings added (with automatic fix for not logical choices)
+ $txt['sp_ThemeChange_submit'] = 'Change Theme'; change the text of the button. (You can outcomment it and add it to an language file to make it mui compatible)

Code: [Select]
/*
This is a small Theme Picker.
Version 1.1.0 (19.11.08)
Tested only on SMF 1.1.x
*/

//Settings Start here, they are all checked, and disable itself it it not usefull to disable it ;P

//This will show the Submit button, this is only for user who disable the Javascript, if you don't like it you can remove it by set it to 0
$showSubmitButton = 1;
//Auto Remove the button if Java Script avaible and enabled and the button is shown
$autoRemoveButton = 1;
//Disable the Java Script? 0 = No, 1 = Yes!
$autoSubmitThemeChange = 0;
//Enable the Images? Disable the autoSubmitThemeChange for this! Only one of them will work ;)
$showPreviewImages = 1;
//Change Theme Text for the Button
$txt['sp_ThemeChange_submit'] = 'Change Theme';

//Here start the script :D and you know if you not know what you do do nothing after this ;)
global $modSettings, $context, $db_prefix, $settings, $txt, $ID_MEMBER, $scripturl, $user_info;

//Checkup Settings :) Fix them so that it work ;)
$autoSubmitThemeChange = !empty($autoSubmitThemeChange);
$showPreviewImages = !empty($showPreviewImages);
$showSubmitButton = $showPreviewImages || !empty($showSubmitButton) || !$autoSubmitThemeChange;
$autoRemoveButton = $showSubmitButton && $autoSubmitThemeChange && !empty($autoRemoveButton);
$txt['sp_ThemeChange_submit'] = empty($txt['sp_ThemeChange_submit']) ? 'Change Theme' : $txt['sp_ThemeChange_submit'];

//Load the Themerelated Language Things :)
loadLanguage('Profile');

// Load the themes for pull down list
$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__);

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);

//Let's see if i should update the theme on the userdata?
if(isset($_REQUEST['th']) && is_numeric($_REQUEST['th'])) {
checkSession('get');
$_REQUEST['th'] = (int) $_REQUEST['th'];
//Fall back to default?
if(empty($context['themes'][$_REQUEST['th']]))
$_REQUEST['th'] = -1;
if(!$context['user']['is_guest'])
updateMemberData($ID_MEMBER, array('ID_THEME' => ($_REQUEST['th'] == -1 ? 0 : $_REQUEST['th'])));
redirectexit('theme='.$_REQUEST['th']);
}

//Load the current user theme, could be possible updated ;)
if(!$context['user']['is_guest']) {
$request = db_query("
SELECT ID_THEME
FROM {$db_prefix}members
WHERE ID_MEMBER = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
list ($context['current_theme']) = mysql_fetch_row($request);
mysql_free_result($request);
}
else
$context['current_theme'] = 0; //Only for guest ;)

//Enable the Image Thumbnails?
$context['current_theme_thumb'] = '';
if($showPreviewImages) {
foreach ($context['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['themes'][$ID_THEME]['thumbnail_href'] = $txt['theme_thumbnail_href'];
$context['themes'][$ID_THEME]['description'] = $txt['theme_description'];
}

//Default Theme need an thumnail :D (Hope this work :X)
$context['themes'][0]['thumbnail_href'] = !empty($context['themes'][$modSettings['theme_default']]['thumbnail_href']) ? $context['themes'][$modSettings['theme_default']]['thumbnail_href'] : $context['themes'][1]['thumbnail_href'];
//Standardthumb :x
$context['current_theme_thumb'] = $context['themes'][0]['thumbnail_href'];
}

//Default Theme :)
$context['themes'][0]['id'] = 0;
$context['themes'][0]['name'] = $txt['theme_forum_default'];
$context['themes'][0]['description'] = $txt['theme_global_description'];

//Sort it ;)
ksort($context['themes']);

//The Java Script Parts :) Only this or the other not both :O
if($autoSubmitThemeChange)
{
echo '
<script language="JavaScript" type="text/javascript">
function sportal_theme_change(obj)
{
var id = obj.options[obj.selectedIndex].value;
var url = new String(window.location);
loc = \'index.php?th=\' + id + \';sesc=', $context['session_id'], '\';
window.location = loc;
}
</script>';
}
elseif($showPreviewImages)
{
echo '
<script language="JavaScript" type="text/javascript">
var sp_smf_thumb_link_array = new Array();';
foreach($context['themes'] as $key => $item)
echo '
sp_smf_thumb_link_array['.$key.'] = "' . $item['thumbnail_href'] . '";';
echo '
function sportal_theme_change(obj)
{
var id = obj.options[obj.selectedIndex].value;
document.getElementById("sp_theme_thumbnail").src = sp_smf_thumb_link_array[id];
}
</script>';
}


//And the pulldown
echo '
<form>
<div style="text-align: center; width:99%;">
<select name="th"' . ($autoSubmitThemeChange || $showPreviewImages ? ' onchange="sportal_theme_change(this)"' : '') . ' style="width:95%;">';
foreach ($context['themes'] as $theme)
{
if($showPreviewImages && $context['current_theme'] == $theme['id'])
$context['current_theme_thumb'] = $theme['thumbnail_href'];
echo '
<option value="', $theme['id'], '"', ($context['current_theme'] == $theme['id'] ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';
}
echo '
</select>' . ($showPreviewImages ? '
<img style="padding:5px 5px 5px 5px" id="sp_theme_thumbnail" src="'.$context['current_theme_thumb'].'" />' : '') . ($showSubmitButton ? '
<input type="hidden" name="sesc" value="' . $context['session_id'] . '" />
<input style="display:inline;" id="sp_theme_changer_submitt_button" type="submit" value="' . $txt['sp_ThemeChange_submit'] . '" name="submit" />
' : '') . '
</div>
</form>';

//Autoremove the Button?
if($autoRemoveButton)
{
echo '
<script language="JavaScript" type="text/javascript">
document.getElementById("sp_theme_changer_submitt_button").style.display = "none";
</script>';
}

Bye
DIN1031
Title: Re: Themes block? O:
Post by: Costa on November 19, 2008, 04:10:48 PM
Thank you all
Title: Re: Themes block? O:
Post by: Kosedragen on November 20, 2008, 03:34:14 PM
Thank you very much, mate ^^ Appreciate it!
Title: Re: Themes block? O:
Post by: Sudhakar on December 03, 2008, 08:14:37 AM
Tried Using this code written by bluebdream.

Re: Themes block? O: (http://simpleportal.net/index.php?topic=901.msg5874#msg5874)

Error Message :

Fatal error: Call to undefined function db_query() in /home/itacumen/public_html/discuss/Sources/SPortal2.php(1863) : eval()'d code on line 16

 :bandaged:------------------------- * -------------------------------------- :bandaged:

Tried Using this code written by ???1031 .

Re: Themes block? O: (http://simpleportal.net/index.php?topic=901.msg5962#msg5962)

Error Message :

Fatal error: Call to undefined function db_query() in /home/itacumen/public_html/discuss/Sources/SPortal2.php(1863) : eval()'d code on line 34
Title: Re: Themes block? O:
Post by: ???1031 on December 03, 2008, 08:31:03 AM
Tried Using this code written by bluebdream.

Re: Themes block? O: (http://simpleportal.net/index.php?topic=901.msg5874#msg5874)

Error Message :

Fatal error: Call to undefined function db_query() in /home/itacumen/public_html/discuss/Sources/SPortal2.php(1863) : eval()'d code on line 16

 :bandaged:------------------------- * -------------------------------------- :bandaged:

Tried Using this code written by ???1031 .

Re: Themes block? O: (http://simpleportal.net/index.php?topic=901.msg5962#msg5962)

Error Message :

Fatal error: Call to undefined function db_query() in /home/itacumen/public_html/discuss/Sources/SPortal2.php(1863) : eval()'d code on line 34
The block is only for SMF 1.1.x it will not work in SMF 2.0.x like it stand in the header of the block... (in future i insert a smf version checkup in all of my blocks...)
Title: Re: Themes block? O:
Post by: Sudhakar on December 03, 2008, 12:40:36 PM

The block is only for SMF 1.1.x it will not work in SMF 2.0.x like it stand in the header of the block... (in future i insert a smf version checkup in all of my blocks...)

Ok Many Thanks for the information.
Hope you will do as early.
Title: Re: Themes block? O:
Post by: Saga on December 30, 2008, 08:59:59 PM
i've got an error in using this block on smf 1.1.7

Undefined index: csect_cookie
Fichier: /home/***/Sources/Load.php(1743) : eval()'d code
Ligne: 157

The blocks after theme block don't use the good themes but the last i've installed
could you help me ?
Title: Re: Themes block? O:
Post by: [SiNaN] on February 02, 2009, 04:48:07 PM
I've fixed some bugs, use these codes:

Code: [Select]
/*
This is a small Theme Picker.
Version 1.1.0 (19.11.08)
Tested only on SMF 1.1.x
*/

//Settings Start here, they are all checked, and disable itself it it not usefull to disable it ;P

//This will show the Submit button, this is only for user who disable the Javascript, if you don't like it you can remove it by set it to 0
$showSubmitButton = 1;
//Auto Remove the button if Java Script avaible and enabled and the button is shown
$autoRemoveButton = 1;
//Disable the Java Script? 0 = No, 1 = Yes!
$autoSubmitThemeChange = 0;
//Enable the Images? Disable the autoSubmitThemeChange for this! Only one of them will work ;)
$showPreviewImages = 1;
//Change Theme Text for the Button
$txt['sp_ThemeChange_submit'] = 'Change Theme';

//Here start the script :D and you know if you not know what you do do nothing after this ;)
global $modSettings, $context, $db_prefix, $settings, $txt, $ID_MEMBER, $scripturl, $user_info;

//Checkup Settings :) Fix them so that it work ;)
$autoSubmitThemeChange = !empty($autoSubmitThemeChange);
$showPreviewImages = !empty($showPreviewImages);
$showSubmitButton = $showPreviewImages || !empty($showSubmitButton) || !$autoSubmitThemeChange;
$autoRemoveButton = $showSubmitButton && $autoSubmitThemeChange && !empty($autoRemoveButton);
$txt['sp_ThemeChange_submit'] = empty($txt['sp_ThemeChange_submit']) ? 'Change Theme' : $txt['sp_ThemeChange_submit'];

//Load the Themerelated Language Things :)
loadLanguage('Profile');
loadLanguage('Themes');

// Load the themes for pull down list
$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__);

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);

//Let's see if i should update the theme on the userdata?
if(isset($_REQUEST['th']) && is_numeric($_REQUEST['th'])) {
   checkSession('get');
   $_REQUEST['th'] = (int) $_REQUEST['th'];
   //Fall back to default?
   if(empty($context['themes'][$_REQUEST['th']]))
      $_REQUEST['th'] = -1;
   if(!$context['user']['is_guest'])
      updateMemberData($ID_MEMBER, array('ID_THEME' => ($_REQUEST['th'] == -1 ? 0 : $_REQUEST['th'])));
   redirectexit('theme=' . $_REQUEST['th']);
}

//Load the current user theme, could be possible updated ;)
if(!$context['user']['is_guest']) {
      $request = db_query("
         SELECT ID_THEME
         FROM {$db_prefix}members
         WHERE ID_MEMBER = $ID_MEMBER
         LIMIT 1", __FILE__, __LINE__);
      list ($context['current_theme']) = mysql_fetch_row($request);
      mysql_free_result($request);
}
else
   $context['current_theme'] = 0; //Only for guest ;)

//Enable the Image Thumbnails?
$context['current_theme_thumb'] = '';
if($showPreviewImages) {
   foreach ($context['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;
 
      $temp_settings = $theme_data;
      $temp_settings['theme_id'] = $ID_THEME;
 
      if (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
      elseif (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php');
      else
         $txt['theme_description'] = '';
 
      $context['themes'][$ID_THEME]['thumbnail_href'] = $temp_settings['images_url'] . '/thumbnail.gif';
      $context['themes'][$ID_THEME]['description'] = $txt['theme_description'];
   }
 
   //Default Theme need an thumnail :D (Hope this work :X)
   $context['themes'][0]['thumbnail_href'] = !empty($context['themes'][$modSettings['theme_guests']]['thumbnail_href']) ? $context['themes'][$modSettings['theme_guests']]['thumbnail_href'] : $context['themes'][1]['thumbnail_href'];
   //Standardthumb :x
   $context['current_theme_thumb'] = $context['themes'][0]['thumbnail_href'];
}

//Default Theme :)
$context['themes'][0]['id'] = 0;
$context['themes'][0]['name'] = $txt['theme_forum_default'];
$context['themes'][0]['description'] = $txt['theme_global_description'];

//Sort it ;)
ksort($context['themes']);

//The Java Script Parts :) Only this or the other not both :O
if($autoSubmitThemeChange)
{
   echo '
<script language="JavaScript" type="text/javascript">
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      var url = new String(window.location);
      loc = \'index.php?th=\' + id + \';sesc=', $context['session_id'], '\';
      window.location = loc;
   }
</script>';
}
elseif($showPreviewImages)
{
   echo '
<script language="JavaScript" type="text/javascript">
   var sp_smf_thumb_link_array = new Array();';
   foreach($context['themes'] as $key => $item)
      echo '
   sp_smf_thumb_link_array['.$key.'] = "' . $item['thumbnail_href'] . '";';
   echo '
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      document.getElementById("sp_theme_thumbnail").src = sp_smf_thumb_link_array[id];
   }
</script>';
}


//And the pulldown
echo '
<form>
   <div style="text-align: center; width:99%;">
      <select name="th"' . ($autoSubmitThemeChange || $showPreviewImages ? ' onchange="sportal_theme_change(this)"' : '') . ' style="width:95%;">';
         foreach ($context['themes'] as $theme)
         {
            if($showPreviewImages && $context['current_theme'] == $theme['id'])
               $context['current_theme_thumb'] = $theme['thumbnail_href'];
            echo '
         <option value="', $theme['id'], '"', ($context['current_theme'] == $theme['id'] ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';
         }
   echo '
      </select>' . ($showPreviewImages ? '
      <img style="padding:5px 5px 5px 5px" id="sp_theme_thumbnail" src="'.$context['current_theme_thumb'].'" />' : '') . ($showSubmitButton ? '
      <input type="hidden" name="sesc" value="' . $context['session_id'] . '" />
      <input style="display:inline;" id="sp_theme_changer_submitt_button" type="submit" value="' . $txt['sp_ThemeChange_submit'] . '" name="submit" />
   ' : '') . '
   </div>
</form>';

//Autoremove the Button?
if($autoRemoveButton)
{
   echo '
<script language="JavaScript" type="text/javascript">
   document.getElementById("sp_theme_changer_submitt_button").style.display = "none";
</script>';
}

http://simpleportal.net/index.php?issue=126.0
Title: Re: Themes block? O:
Post by: [SiNaN] on February 02, 2009, 05:08:11 PM
Here is the one for SMF 2.0:

Code: [Select]
/*
This is a small Theme Picker.
Version 1.1.0 (19.11.08)
DIN1031
*/

//This will show the Submit button, this is only for user who disable the Javascript, if you don't like it you can remove it by set it to 0
$showSubmitButton = 1;
//Auto Remove the button if Java Script avaible and enabled and the button is shown
$autoRemoveButton = 1;
//Disable the Java Script? 0 = No, 1 = Yes!
$autoSubmitThemeChange = 0;
//Enable the Images? Disable the autoSubmitThemeChange for this! Only one of them will work ;)
$showPreviewImages = 1;
//Change Theme Text for the Button
$txt['sp_ThemeChange_submit'] = 'Change Theme';

//Here start the script :D and you know if you not know what you do do nothing after this ;)
global $modSettings, $context, $db_prefix, $settings, $txt, $smcFunc, $scripturl, $user_info;

$autoSubmitThemeChange = !empty($autoSubmitThemeChange);
$showPreviewImages = !empty($showPreviewImages);
$showSubmitButton = $showPreviewImages || !empty($showSubmitButton) || !$autoSubmitThemeChange;
$autoRemoveButton = $showSubmitButton && $autoSubmitThemeChange && !empty($autoRemoveButton);
$txt['sp_ThemeChange_submit'] = empty($txt['sp_ThemeChange_submit']) ? 'Change Theme' : $txt['sp_ThemeChange_submit'];

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

$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}' . (!empty($modSettings['knownThemes']) ? '
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['themes'] = array();
while ($row = $smcFunc['db_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'];
}
$smcFunc['db_free_result']($request);

if (isset($_REQUEST['th']) && is_numeric($_REQUEST['th']))
{
   checkSession('get');

   $_REQUEST['th'] = (int) $_REQUEST['th'];

   if (empty($context['themes'][$_REQUEST['th']]))
      $_REQUEST['th'] = -1;

   if (!$context['user']['is_guest'])
      updateMemberData($user_info['id'], array('id_theme' => ($_REQUEST['th'] == -1 ? 0 : $_REQUEST['th'])));

   redirectexit('theme=' . $_REQUEST['th']);
}

if (!$context['user']['is_guest'])
{
   $request = $smcFunc['db_query']('', '
      SELECT id_theme
      FROM {db_prefix}members
      WHERE id_member = {int:current_member}
      LIMIT 1',
      array(
         'current_member' => $user_info['id'],
      )
   );
   list ($context['current_theme']) = $smcFunc['db_fetch_row']($request);
   $smcFunc['db_free_result']($request);
}
else
   $context['current_theme'] = 0;

$context['current_theme_thumb'] = '';

if($showPreviewImages)
{
   foreach ($context['themes'] as $ID_THEME => $theme_data)
   {
      if ($ID_THEME == 0)
         continue;

      $temp_settings = $theme_data;
      $temp_settings['theme_id'] = $ID_THEME;
   
      if (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
      elseif (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php');
      else
         $txt['theme_description'] = '';
 
      $context['themes'][$ID_THEME]['thumbnail_href'] = $temp_settings['images_url'] . '/thumbnail.gif';
      $context['themes'][$ID_THEME]['description'] = $txt['theme_description'];
   }
   
   $context['themes'][0]['thumbnail_href'] = !empty($context['themes'][$modSettings['theme_guests']]['thumbnail_href']) ? $context['themes'][$modSettings['theme_guests']]['thumbnail_href'] : $context['themes'][1]['thumbnail_href'];
   $context['current_theme_thumb'] = $context['themes'][0]['thumbnail_href'];
}

$context['themes'][0]['id'] = 0;
$context['themes'][0]['name'] = $txt['theme_forum_default'];
$context['themes'][0]['description'] = $txt['theme_global_description'];

ksort($context['themes']);

if ($autoSubmitThemeChange)
{
echo '
<script language="JavaScript" type="text/javascript">
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      var url = new String(window.location);
      loc = \'index.php?th=\' + id + \';sesc=', $context['session_id'], '\';
      window.location = loc;
   }
</script>';
}
elseif ($showPreviewImages)
{
   echo '
<script language="JavaScript" type="text/javascript">
   var sp_smf_thumb_link_array = new Array();';

   foreach($context['themes'] as $key => $item)
      echo '
   sp_smf_thumb_link_array['.$key.'] = "' . $item['thumbnail_href'] . '";';

   echo '
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      document.getElementById("sp_theme_thumbnail").src = sp_smf_thumb_link_array[id];
   }
</script>';
}

echo '
<form>
   <div style="text-align: center; width:99%;">
      <select name="th"' . ($autoSubmitThemeChange || $showPreviewImages ? ' onchange="sportal_theme_change(this)"' : '') . ' style="width: 95%;">';

foreach ($context['themes'] as $theme)
{
   if ($showPreviewImages && $context['current_theme'] == $theme['id'])
      $context['current_theme_thumb'] = $theme['thumbnail_href'];

   echo '
         <option value="', $theme['id'], '"', ($context['current_theme'] == $theme['id'] ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';
}

echo '
      </select>' . ($showPreviewImages ? '
      <img style="padding:5px 5px 5px 5px" id="sp_theme_thumbnail" src="'.$context['current_theme_thumb'].'" />' : '') . ($showSubmitButton ? '
      <input type="hidden" name="sesc" value="' . $context['session_id'] . '" />
      <input style="display:inline;" id="sp_theme_changer_submitt_button" type="submit" value="' . $txt['sp_ThemeChange_submit'] . '" name="submit" />' : '') . '
   </div>
</form>';

if ($autoRemoveButton)
   echo '
<script language="JavaScript" type="text/javascript">
   document.getElementById("sp_theme_changer_submitt_button").style.display = "none";
</script>';

Credits goes to ???1031, original coder of the block. I just fixed a few bugs and cleaned codes.
Title: Re: Themes block? O:
Post by: siath on February 02, 2009, 05:57:32 PM
Couple Questions.

When I change themes the picture doesn't change, even though it is set to preview. I didn't change anything from the cut and paste to the block...

The other question I had was is there a way to stop them from being able to choose themes you don't want them to. Like the Default SMF theme (the original theme that comes with SMF)?

I have only two themes check in SMF for them to select yet it shows Form Default, SMF default and then my two themes.

Anyway Nice job and thans for the replies in other thread.
Title: Re: Themes block? O:
Post by: [SiNaN] on February 02, 2009, 06:22:28 PM
Updated the post above yours, it should now be okay.
Title: Re: Themes block? O:
Post by: siath on February 02, 2009, 06:41:44 PM
I just wanted to say a BIG THANK YOU. For takeing the time to help and reply to my posts.
Title: Re: Themes block? O:
Post by: [SiNaN] on February 03, 2009, 03:15:44 AM
I just wanted to say a BIG THANK YOU. For takeing the time to help and reply to my posts.

Thanks for you too, for using SimplePortal.

----

Note: You can find the updated block codes in the last posts of first page.
Title: Re: Themes block? O:
Post by: Smoky Blue on February 12, 2009, 03:55:00 AM
Perfect Blue..

theme changer is exactly what i was looking for tonight..

thanks!  :P
Title: Re: Themes block? O:
Post by: Smoky Blue on February 18, 2009, 04:42:36 AM
issue:

theme block is up, when changing themes, it takes you to the "portal" page, but yet doesnt change a theme.  :0
Title: Re: Themes block? O:
Post by: Smoky Blue on February 18, 2009, 09:46:12 PM
**BUMP**
Title: Re: Themes block? O:
Post by: [SiNaN] on February 19, 2009, 03:18:05 AM
Probably because of the session id handling changes in 1.1.8. A quick patched one:

Code: [Select]
/*
This is a small Theme Picker.
Version 1.1.0 (19.11.08)
Tested only on SMF 1.1.x
*/

//Settings Start here, they are all checked, and disable itself it it not usefull to disable it ;P

//This will show the Submit button, this is only for user who disable the Javascript, if you don't like it you can remove it by set it to 0
$showSubmitButton = 1;
//Auto Remove the button if Java Script avaible and enabled and the button is shown
$autoRemoveButton = 1;
//Disable the Java Script? 0 = No, 1 = Yes!
$autoSubmitThemeChange = 0;
//Enable the Images? Disable the autoSubmitThemeChange for this! Only one of them will work ;)
$showPreviewImages = 1;
//Change Theme Text for the Button
$txt['sp_ThemeChange_submit'] = 'Change Theme';

//Here start the script :D and you know if you not know what you do do nothing after this ;)
global $modSettings, $context, $db_prefix, $settings, $txt, $ID_MEMBER, $scripturl, $user_info;

//Checkup Settings :) Fix them so that it work ;)
$autoSubmitThemeChange = !empty($autoSubmitThemeChange);
$showPreviewImages = !empty($showPreviewImages);
$showSubmitButton = $showPreviewImages || !empty($showSubmitButton) || !$autoSubmitThemeChange;
$autoRemoveButton = $showSubmitButton && $autoSubmitThemeChange && !empty($autoRemoveButton);
$txt['sp_ThemeChange_submit'] = empty($txt['sp_ThemeChange_submit']) ? 'Change Theme' : $txt['sp_ThemeChange_submit'];

//Load the Themerelated Language Things :)
loadLanguage('Profile');
loadLanguage('Themes');

// Load the themes for pull down list
$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__);

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);

//Let's see if i should update the theme on the userdata?
if(isset($_REQUEST['th']) && is_numeric($_REQUEST['th'])) {
   checkSession('post');
   $_REQUEST['th'] = (int) $_REQUEST['th'];
   //Fall back to default?
   if(empty($context['themes'][$_REQUEST['th']]))
      $_REQUEST['th'] = -1;
   if(!$context['user']['is_guest'])
      updateMemberData($ID_MEMBER, array('ID_THEME' => ($_REQUEST['th'] == -1 ? 0 : $_REQUEST['th'])));
   redirectexit('theme=' . $_REQUEST['th']);
}

//Load the current user theme, could be possible updated ;)
if(!$context['user']['is_guest']) {
      $request = db_query("
         SELECT ID_THEME
         FROM {$db_prefix}members
         WHERE ID_MEMBER = $ID_MEMBER
         LIMIT 1", __FILE__, __LINE__);
      list ($context['current_theme']) = mysql_fetch_row($request);
      mysql_free_result($request);
}
else
   $context['current_theme'] = 0; //Only for guest ;)

//Enable the Image Thumbnails?
$context['current_theme_thumb'] = '';
if($showPreviewImages) {
   foreach ($context['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;
 
      $temp_settings = $theme_data;
      $temp_settings['theme_id'] = $ID_THEME;
 
      if (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
      elseif (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php');
      else
         $txt['theme_description'] = '';
 
      $context['themes'][$ID_THEME]['thumbnail_href'] = $temp_settings['images_url'] . '/thumbnail.gif';
      $context['themes'][$ID_THEME]['description'] = $txt['theme_description'];
   }
 
   //Default Theme need an thumnail :D (Hope this work :X)
   $context['themes'][0]['thumbnail_href'] = !empty($context['themes'][$modSettings['theme_guests']]['thumbnail_href']) ? $context['themes'][$modSettings['theme_guests']]['thumbnail_href'] : $context['themes'][1]['thumbnail_href'];
   //Standardthumb :x
   $context['current_theme_thumb'] = $context['themes'][0]['thumbnail_href'];
}

//Default Theme :)
$context['themes'][0]['id'] = 0;
$context['themes'][0]['name'] = $txt['theme_forum_default'];
$context['themes'][0]['description'] = $txt['theme_global_description'];

//Sort it ;)
ksort($context['themes']);

//The Java Script Parts :) Only this or the other not both :O
if($autoSubmitThemeChange)
{
   echo '
<script language="JavaScript" type="text/javascript">
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      var url = new String(window.location);
      loc = \'index.php?th=\' + id + \';sesc=', $context['session_id'], '\';
      window.location = loc;
   }
</script>';
}
elseif($showPreviewImages)
{
   echo '
<script language="JavaScript" type="text/javascript">
   var sp_smf_thumb_link_array = new Array();';
   foreach($context['themes'] as $key => $item)
      echo '
   sp_smf_thumb_link_array['.$key.'] = "' . $item['thumbnail_href'] . '";';
   echo '
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      document.getElementById("sp_theme_thumbnail").src = sp_smf_thumb_link_array[id];
   }
</script>';
}


//And the pulldown
echo '
<form method="post">
   <div style="text-align: center; width:99%;">
      <select name="th"' . ($autoSubmitThemeChange || $showPreviewImages ? ' onchange="sportal_theme_change(this)"' : '') . ' style="width:95%;">';
         foreach ($context['themes'] as $theme)
         {
            if($showPreviewImages && $context['current_theme'] == $theme['id'])
               $context['current_theme_thumb'] = $theme['thumbnail_href'];
            echo '
         <option value="', $theme['id'], '"', ($context['current_theme'] == $theme['id'] ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';
         }
   echo '
      </select>' . ($showPreviewImages ? '
      <img style="padding:5px 5px 5px 5px" id="sp_theme_thumbnail" src="'.$context['current_theme_thumb'].'" />' : '') . ($showSubmitButton ? '
      <input type="hidden" name="sc" value="' . $context['session_id'] . '" />
      <input style="display:inline;" id="sp_theme_changer_submitt_button" type="submit" value="' . $txt['sp_ThemeChange_submit'] . '" name="submit" />
   ' : '') . '
   </div>
</form>';

//Autoremove the Button?
if($autoRemoveButton)
{
   echo '
<script language="JavaScript" type="text/javascript">
   document.getElementById("sp_theme_changer_submitt_button").style.display = "none";
</script>';
}
Title: Re: Themes block? O:
Post by: Smoky Blue on February 20, 2009, 08:58:39 AM
umm running the rc Blue  :0
Title: Re: Themes block? O:
Post by: neuikc on July 19, 2009, 12:22:53 AM
Sorry to bring this back after so long, but any chance the code for the 2.0 block could get *updated* for SMF 2.0 RC1.2. When I choose the theme I wish to switch to, it goes to a blank page, with the theme I currently am using. Not switching.

TIA
Title: Re: Themes block? O:
Post by: neuikc on July 20, 2009, 01:18:16 PM
Here is the one for SMF 2.0:

Code: [Select]
/*
This is a small Theme Picker.
Version 1.1.0 (19.11.08)
DIN1031
*/

//This will show the Submit button, this is only for user who disable the Javascript, if you don't like it you can remove it by set it to 0
$showSubmitButton = 1;
//Auto Remove the button if Java Script avaible and enabled and the button is shown
$autoRemoveButton = 1;
//Disable the Java Script? 0 = No, 1 = Yes!
$autoSubmitThemeChange = 0;
//Enable the Images? Disable the autoSubmitThemeChange for this! Only one of them will work ;)
$showPreviewImages = 1;
//Change Theme Text for the Button
$txt['sp_ThemeChange_submit'] = 'Change Theme';

//Here start the script :D and you know if you not know what you do do nothing after this ;)
global $modSettings, $context, $db_prefix, $settings, $txt, $smcFunc, $scripturl, $user_info;

$autoSubmitThemeChange = !empty($autoSubmitThemeChange);
$showPreviewImages = !empty($showPreviewImages);
$showSubmitButton = $showPreviewImages || !empty($showSubmitButton) || !$autoSubmitThemeChange;
$autoRemoveButton = $showSubmitButton && $autoSubmitThemeChange && !empty($autoRemoveButton);
$txt['sp_ThemeChange_submit'] = empty($txt['sp_ThemeChange_submit']) ? 'Change Theme' : $txt['sp_ThemeChange_submit'];

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

$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}' . (!empty($modSettings['knownThemes']) ? '
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['themes'] = array();
while ($row = $smcFunc['db_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'];
}
$smcFunc['db_free_result']($request);

if (isset($_REQUEST['th']) && is_numeric($_REQUEST['th']))
{
   checkSession('get');

   $_REQUEST['th'] = (int) $_REQUEST['th'];

   if (empty($context['themes'][$_REQUEST['th']]))
      $_REQUEST['th'] = -1;

   if (!$context['user']['is_guest'])
      updateMemberData($user_info['id'], array('id_theme' => ($_REQUEST['th'] == -1 ? 0 : $_REQUEST['th'])));

   redirectexit('theme=' . $_REQUEST['th']);
}

if (!$context['user']['is_guest'])
{
   $request = $smcFunc['db_query']('', '
      SELECT id_theme
      FROM {db_prefix}members
      WHERE id_member = {int:current_member}
      LIMIT 1',
      array(
         'current_member' => $user_info['id'],
      )
   );
   list ($context['current_theme']) = $smcFunc['db_fetch_row']($request);
   $smcFunc['db_free_result']($request);
}
else
   $context['current_theme'] = 0;

$context['current_theme_thumb'] = '';

if($showPreviewImages)
{
   foreach ($context['themes'] as $ID_THEME => $theme_data)
   {
      if ($ID_THEME == 0)
         continue;

      $temp_settings = $theme_data;
      $temp_settings['theme_id'] = $ID_THEME;
   
      if (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
      elseif (file_exists($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php'))
         include($temp_settings['theme_dir'] . '/languages/Settings.' . $language . '.php');
      else
         $txt['theme_description'] = '';
 
      $context['themes'][$ID_THEME]['thumbnail_href'] = $temp_settings['images_url'] . '/thumbnail.gif';
      $context['themes'][$ID_THEME]['description'] = $txt['theme_description'];
   }
   
   $context['themes'][0]['thumbnail_href'] = !empty($context['themes'][$modSettings['theme_guests']]['thumbnail_href']) ? $context['themes'][$modSettings['theme_guests']]['thumbnail_href'] : $context['themes'][1]['thumbnail_href'];
   $context['current_theme_thumb'] = $context['themes'][0]['thumbnail_href'];
}

$context['themes'][0]['id'] = 0;
$context['themes'][0]['name'] = $txt['theme_forum_default'];
$context['themes'][0]['description'] = $txt['theme_global_description'];

ksort($context['themes']);

if ($autoSubmitThemeChange)
{
echo '
<script language="JavaScript" type="text/javascript">
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      var url = new String(window.location);
      loc = \'index.php?th=\' + id + \';sesc=', $context['session_id'], '\';
      window.location = loc;
   }
</script>';
}
elseif ($showPreviewImages)
{
   echo '
<script language="JavaScript" type="text/javascript">
   var sp_smf_thumb_link_array = new Array();';

   foreach($context['themes'] as $key => $item)
      echo '
   sp_smf_thumb_link_array['.$key.'] = "' . $item['thumbnail_href'] . '";';

   echo '
   function sportal_theme_change(obj)
   {
      var id = obj.options[obj.selectedIndex].value;
      document.getElementById("sp_theme_thumbnail").src = sp_smf_thumb_link_array[id];
   }
</script>';
}

echo '
<form>
   <div style="text-align: center; width:99%;">
      <select name="th"' . ($autoSubmitThemeChange || $showPreviewImages ? ' onchange="sportal_theme_change(this)"' : '') . ' style="width: 95%;">';

foreach ($context['themes'] as $theme)
{
   if ($showPreviewImages && $context['current_theme'] == $theme['id'])
      $context['current_theme_thumb'] = $theme['thumbnail_href'];

   echo '
         <option value="', $theme['id'], '"', ($context['current_theme'] == $theme['id'] ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';
}

echo '
      </select>' . ($showPreviewImages ? '
      <img style="padding:5px 5px 5px 5px" id="sp_theme_thumbnail" src="'.$context['current_theme_thumb'].'" />' : '') . ($showSubmitButton ? '
      <input type="hidden" name="sesc" value="' . $context['session_id'] . '" />
      <input style="display:inline;" id="sp_theme_changer_submitt_button" type="submit" value="' . $txt['sp_ThemeChange_submit'] . '" name="submit" />' : '') . '
   </div>
</form>';

if ($autoRemoveButton)
   echo '
<script language="JavaScript" type="text/javascript">
   document.getElementById("sp_theme_changer_submitt_button").style.display = "none";
</script>';

Credits goes to ディン1031, original coder of the block. I just fixed a few bugs and cleaned codes.

Doesn't appear to work anymore, v 2.0 rc1.2 - Any ideas?
Title: Re: Themes block? O:
Post by: [SiNaN] on July 20, 2009, 02:11:09 PM
Why don't you use the built-in block? It has been there since 2.2.
Title: Re: Themes block? O:
Post by: neuikc on July 20, 2009, 02:31:53 PM
LoL, okay so chalk it up to not looking for a built in one - ;)

Thanks!

Brainfart central out!
SimplePortal 2.3.8 © 2008-2024, SimplePortal