I believe Tony Bibbs originally wrote the lib-custom hack that allows you to place a block on your Geeklog site that lets your users test drive a theme. This code has been floating around for a few years and still seems to work pretty well. I have made a couple of modifications to bring it up to date and add a couple of little features.
Installing and using the Theme Tester is a two step process.
function phpblock_themetester()
{
global $_TABLES, $_USER, $_CONF;
if( isset( $_COOKIE[$_CONF['cookie_theme']] ))
{
$theme = preg_replace( '/[^a-zA-Z0-9\-_\.]/', '',
$_COOKIE[$_CONF['cookie_theme']] );
$theme = str_replace( '..', '', $theme );
if( is_dir( $_CONF['path_themes'] . $theme ))
{
$usetheme = $theme;
}
if ( isset($_USER['theme']) ) {
$usetheme = $_USER['theme'];
}
}
$thememode = COM_applyFilter($_GET['thememode']);
if ($thememode == 'save') {
$usetheme = COM_applyFilter($_GET['usetheme']);
} else {
if ( isset($_POST['usetheme']) ) {
$usetheme = COM_applyFilter($_POST['usetheme']);
setcookie ($_CONF['cookie_theme'], $usetheme, time() + 31536000,
$_CONF['cookie_path'], $_CONF['cookiedomain'],
$_CONF['cookiesecure']);
}
}
if ( isset($_USER['uid']) && $_USER['uid'] > 1 && $thememode == 'save' && !empty($usetheme) ) {
DB_query("UPDATE {$_TABLES['users']} SET theme='$usetheme' WHERE uid = {$_USER['uid']}");
echo COM_refresh($_CONF['site_url']);
}
$themes = COM_getThemes();
if (count($themes) == 1) {
return 'Sorry, there is only one theme installed on this system';
}
$retval .= 'Test out available themes by selecting one below:<br>';
$retval .= '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
$retval .= '<select name="usetheme" onChange="this.form.submit()">';
$retval .= '<option value="">--</option>';
for ($i = 1; $i <= count($themes); $i++) {
$retval .= '<option value="' . current($themes);
if ($usetheme == current($themes)) {
$retval .= ' selected="SELECTED"';
}
$retval .= '">' . current($themes) . '</option>';
next($themes);
}
if ( isset($_USER['uid']) && $_USER['uid'] > 1 && !empty($usetheme) ) {
$args = 'thememode=save&usetheme=' . $usetheme;
for ($i = 1; $i <= count($_GET); $i++) {
if (key($_GET) <> 'thememode' AND key($_GET) <> 'usetheme') {
$args .= '&' . key($_GET) . '=' . urlencode(current($_GET));
}
next($_GET);
}
$retval .= '</select></form></center><a href="' . $_SERVER['PHP_SELF'] . '?' . $args . '">Use Permanently</a>';
} else {
$retval .= '</select></form></center></a>';
}
return $retval;
}
That should do it. You should now have a new block on your site where you can select from all the installed themes.
There isn't much to using the Theme Tester. If you have multiple themes installed on your site, they should appear in the drop down list.
If you are logged-in to the site, the theme tester will only change the theme for the current page. If you navigate to other areas of the site, the theme will reset to the one selected in your user profile.
If you are not logged-in to the site, the theme you choose will persist throughout the site browsing. This is a great way for someone to test drive a theme in all areas of the site, such as the forums or Media Gallery.
If you have questions or issues with this script, please use the support forums at http://www.gllabs.org.