Geeklog France
 

Geeklog Theme Tester

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.

ChangeLog

  • Properly filter all input
  • Set cookie with new theme selection, allows the theme to continue to be used throughout the browsing session (only for non-logged in users).
  • Fixed infinite loop if logged-in user selected 'Use Permanently'

Installation

Installing and using the Theme Tester is a two step process.

  • Add the following code to your lib-custom.php file. lib-custom.php is located in the system/ directory.
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;
}

This sites uses UTF-8 character encoding. There have been problems in the past when you cut / paste code from this wiki directly into your files if you do not use a UTF-8 aware editor. You may want to download the source file here.

  • Create a new block with the following attributes:
  1. Title: Theme Tester
  2. Enabled: Checked
  3. Block Name: themetester
  4. Type: PHP Block
  5. Block Function: phpblock_themetester

That should do it. You should now have a new block on your site where you can select from all the installed themes.

Usage

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.

Support

If you have questions or issues with this script, please use the support forums at http://www.gllabs.org.

Connecté en tant que : Guest (Guest)
blocks/themetester.txt · Dernière modification: 2008/09/09 01:28 par ::Ben
 

Download geeklog

Last version 1.8.1

Espace Membre





Devenir membre
Enregistrez-vous

Mot de passe oublié ?

Change language

Categories

  • Geeklog (38)
  • Plugins (53)
  • Thèmes (17)
  • My cart

    Votre panier (0 article)

    Votre panier est vide!

    0.00 EUR

    Visual Theme Switcher

    Test out available themes by selecting from one of the 6 available themes or give the Visual Switcher a try:

    Follow us on twitter

    En ligne

    Visiteurs: 6