Initial support for overlay theme that can modify CSS
authorJamie Cameron <jcameron@webmin.com>
Tue, 16 Dec 2008 01:50:13 +0000 (01:50 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 16 Dec 2008 01:50:13 +0000 (01:50 +0000)
miniserv.pl
overlay-theme/config [new file with mode: 0644]
overlay-theme/theme.info [new file with mode: 0644]
overlay-theme/unauthenticated/overlay.css [new file with mode: 0644]
web-lib-funcs.pl

index ce2a469..c3cf3b6 100755 (executable)
@@ -1773,8 +1773,8 @@ if ($davpath) {
        return &handle_dav_request($davpath);
        }
 
-# Work out the active theme
-local $preroot = $mobile_device && defined($config{'mobile_preroot'}) ?
+# Work out the active theme(s)
+local $preroots = $mobile_device && defined($config{'mobile_preroot'}) ?
                        $config{'mobile_preroot'} :
                 $authuser && defined($config{'preroot_'.$authuser}) ?
                        $config{'preroot_'.$authuser} :
@@ -1782,16 +1782,17 @@ local $preroot = $mobile_device && defined($config{'mobile_preroot'}) ?
                     defined($config{'preroot_'.$baseauthuser}) ?
                        $config{'preroot_'.$baseauthuser} :
                        $config{'preroot'};
+local @preroots = reverse(split(/\s+/, $preroots));
 
 # Look for the file under the roots
 local ($full, @stfull);
-if ($preroot) {
+foreach my $preroot (@preroots) {
        # Always under the current webmin root
        $preroot =~ s/^.*\///g;
        $preroot = $roots[0].'/'.$preroot;
        }
 $foundroot = undef;
-if ($preroot) {
+foreach my $preroot (@preroots) {
        # Look in the theme root directory first
        $is_directory = 1;
        $sofar = "";
@@ -1851,6 +1852,7 @@ if ($preroot) {
                        @stfull = stat($full) if (!$foundidx);
                        }
                }
+       last if ($foundroot);
        }
 print DEBUG "handle_request: initial full=$full\n";
 
diff --git a/overlay-theme/config b/overlay-theme/config
new file mode 100644 (file)
index 0000000..61a6e0a
--- /dev/null
@@ -0,0 +1 @@
+headhtml=<link rel='stylesheet' type='text/css' href='/unauthenticated/overlay.css'>
diff --git a/overlay-theme/theme.info b/overlay-theme/theme.info
new file mode 100644 (file)
index 0000000..f880ad1
--- /dev/null
@@ -0,0 +1 @@
+desc=CSS Overlay Test
diff --git a/overlay-theme/unauthenticated/overlay.css b/overlay-theme/unauthenticated/overlay.css
new file mode 100644 (file)
index 0000000..bf4890d
--- /dev/null
@@ -0,0 +1,2 @@
+body { background-color: #ffeeee; }
+html { background-color: #ffeeee; }
index 90f408d..abf0a5b 100755 (executable)
@@ -665,6 +665,9 @@ local $dir = $current_lang_info->{'dir'} ? "dir=\"$current_lang_info->{'dir'}\""
                                         : "";
 print "<body bgcolor=#$bgcolor link=#$link vlink=#$link text=#$text ",
       "$bgimage $tconfig{'inbody'} $dir $_[8]>\n";
+if (defined(&theme_prebody)) {
+       &theme_prebody(@_);
+       }
 local $hostname = &get_display_hostname();
 local $version = &get_webmin_version();
 local $prebody = $tconfig{'prebody'};
@@ -683,9 +686,6 @@ if ($tconfig{'prebodyinclude'}) {
                }
        close(INC);
        }
-if (defined(&theme_prebody)) {
-       &theme_prebody(@_);
-       }
 if (@_ > 1) {
        print $tconfig{'preheader'};
        print "<table class='header' width=100%><tr>\n";
@@ -897,9 +897,13 @@ print "</body></html>\n";
 # For internal use only
 sub load_theme_library
 {
-return if (!$current_theme || !$tconfig{'functions'} ||
-          $loaded_theme_library++);
-do "$theme_root_directory/$tconfig{'functions'}";
+return if (!$current_theme || $loaded_theme_library++);
+for(my $i=0; $i<@theme_root_directories; $i++) {
+       if ($theme_configs[$i]->{'functions'}) {
+               do $theme_root_directories[$i]."/".
+                  $theme_configs[$i]->{'functions'};
+               }
+       }
 }
 
 # redirect
@@ -2828,16 +2832,24 @@ if ($gconfig{'debug_enabled'} && !$main::opened_debug_log++) {
 $main::initial_module_name ||= $module_name;
 
 # Set some useful variables
-$current_theme = $ENV{'MOBILE_DEVICE'} && defined($gconfig{'mobile_theme'}) ?
+local $current_themes;
+$current_themes = $ENV{'MOBILE_DEVICE'} && defined($gconfig{'mobile_theme'}) ?
                    $gconfig{'mobile_theme'} :
-                defined($gconfig{'theme_'.$remote_user}) ?
+                 defined($gconfig{'theme_'.$remote_user}) ?
                    $gconfig{'theme_'.$remote_user} :
-                defined($gconfig{'theme_'.$base_remote_user}) ?
+                 defined($gconfig{'theme_'.$base_remote_user}) ?
                    $gconfig{'theme_'.$base_remote_user} :
                    $gconfig{'theme'};
-if ($current_theme) {
-       $theme_root_directory = "$root_directory/$current_theme";
-       &read_file_cached("$theme_root_directory/config", \%tconfig);
+@current_themes = split(/\s+/, $current_themes);
+$current_theme = $current_themes[0];
+@theme_root_directories = map { "$root_directory/$_" } @current_themes;
+$theme_root_directory = $theme_root_directories[0];
+@theme_configs = ( );
+foreach my $troot (@theme_root_directories) {
+       local %onetconfig;
+       &read_file_cached("$troot/config", \%onetconfig);
+       &read_file_cached("$troot/config", \%tconfig);
+       push(@theme_configs, \%onetconfig);
        }
 $tb = defined($tconfig{'cs_header'}) ? "bgcolor=#$tconfig{'cs_header'}" :
       defined($gconfig{'cs_header'}) ? "bgcolor=#$gconfig{'cs_header'}" :