Fun with Theme Switching


Tags:

UPDATE: CODE REWORKED THANKS TO CHX

<?php
/**
* Implementation of hook_menu (D5 code)
*/
function SOMEMODULE_menu($may_cache) {
  if (!
$may_cache) {
    if (
$theme = $_GET['theme']) {
     
$themes = list_themes();
      if (isset(
$themes[$theme])) {
       
$GLOBALS['custom_theme'] = $theme;
      }
    }
  }
}
?>

With this you can amuse yourself by browsing to /node/1?theme=marvin

I was thinking this could actually be useful- for example you could make an all xml theme and have Flash get data from path/to/page?theme=xml_theme

SECURITY HOLE!!!!!!!!!!!!!!!!!!!!!!!

Drupal is NOT prepared for any random crap to be in $custom_theme. You must validate against theme_list(). Also, if this is Drupal 5 then this is not the right place, you should use hook_menu !$may_cache . Please update your post.

You can find similar code in

You can find similar code in Switchtheme module ( http://drupal.org/project/switchtheme )

Should be ok

Chx: In init_theme it looks like the $custom_theme gets validated against list_themes before being set. Still I edited my code to your suggestions just to be safe. Thanks.

Wow!

This looks to be a powerful technique. Thanks for sharing it! I could see a potential use for this in the upcoming Embed Widgets module as well.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options