random change of theme- is it possible?

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
renata
Regular
Posts: 33
Joined: Mon Sep 05, 2005 12:50 pm

random change of theme- is it possible?

Post by renata »

there are so mnay themes i like, and i find it totally refreshing to see a different one vere so often. is it possible to make the different themes appear random? (not by choice in the drop-down, which of course i have already installed)
the more themes appear, the more of them i want to use- guys, this is YOUR fault. every time one comes out i think, wooww!! i want this, and this, and...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: random change of theme- is it possible?

Post by garvinhicking »

Hi!

This would work with a REALLY simple plugin. Just save this code as plugins/serendipity_event_randomtemplate/serendipity_event_randomtemplate.php:

Code: Select all

<?php # $Id: serendipity_event_randomtemplate.php 880 2006-01-27 14:40:21Z garvinhicking $

class serendipity_event_randomtemplate extends serendipity_event
{
    var $title = PLUGIN_EVENT_TEMPLATECHOOSER_NAME;

    function introspect(&$propbag)
    {
        global $serendipity;

        $propbag->add('name',        'Random Template');
        $propbag->add('description', '');
        $propbag->add('stackable',   false);
        $propbag->add('author',      'Garvin Hicking');
        $propbag->add('version',     '1.0');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('groups', array('BACKEND_TEMPLATES'));
        $propbag->add('event_hooks', array('frontend_configure' => true));
    }

    function generate_content(&$title) {
        $title = $this->title;
    }

    function event_hook($event, &$bag, &$eventData) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
              case 'frontend_configure':
                $templates = serendipity_fetchTemplates();
                $mytemplate = array_rand($templates);
                $_SESSION['serendipityUseTemplate'] = $templates[$mytemplate];
                $templateInfo = serendipity_fetchTemplateInfo($_SESSION['serendipityUseTemplate']);
                $eventData['template'] = $_SESSION['serendipityUseTemplate'];
                $eventData['template_engine'] = isset($templateInfo['engine']) ? $templateInfo['engine'] : $serendipity['defaultTemplate'];
                $serendipity['smarty_vars']['head_link_stylesheet'] = $serendipity['baseURL'] . 'serendipity.css.php?switch=' . $_REQUEST['user_template'];

                return true;
                break;

              default:
                return false;
            }

        } else {
            return false;
        }
    }
}

/* vim: set sts=4 ts=4 expandtab : */

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

Garvin, is there any chance of adding that to spartacus? That could be a popular plugin.
renata
Regular
Posts: 33
Joined: Mon Sep 05, 2005 12:50 pm

Post by renata »

fab!!!
does the code contain a frequency of change? i can look a the code, but i am not able to read it without total instructions.. sorry (can't wait to put it up!!!)
:D
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

It contains no frequency of change; it changes every page request.

Carl, I think this plugin is plain too small to add it to Spartacus on its own. It could be integrted into the current templatechooser plugin, though. I'll see if I have the time to integrate it, but I don't find that functionality so terribly exciting - actually, I would find it confusing if a blog changes its layout time and again.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
renata
Regular
Posts: 33
Joined: Mon Sep 05, 2005 12:50 pm

Post by renata »

ahh. i thought it would miraculously change at a certain frequency.. haha.
shows my ignorance, i guess. so the [page will remeber you, the redare,and then put on a new outfit?
as far as it's worth as a plugin is concerned- i think it is fine for personal webpages, and it only works well if you cutomize the themes for yourself.
i noticed for sure that pictures look so different in the various schemes that some old "stuff" i saw revsiting my page really looked appealing in a new way.
ahh- and where is the big easter-egg them with lots of bunnies and chocolate and flowers???
only kidding. i know it is a lot of work, even if yu coudl remold the bunnies to angels to father christmas... and so on (definitley not for random, though)
Post Reply