From 85661d8e22fd57ff1cec5a2a040335d146a001ab Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Mon, 9 Apr 2012 07:18:36 +0000 Subject: [PATCH] Allow to search icons in subdirectories activated again Icons are searched in the FHEM/ directory first (if set) git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1425 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- webfrontend/pgm2/01_FHEMWEB.pm | 40 +++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/webfrontend/pgm2/01_FHEMWEB.pm b/webfrontend/pgm2/01_FHEMWEB.pm index ea3449455..cc9e9f816 100755 --- a/webfrontend/pgm2/01_FHEMWEB.pm +++ b/webfrontend/pgm2/01_FHEMWEB.pm @@ -342,11 +342,12 @@ FW_AnswerCall($) $FW_dir = AttrVal($FW_wname, "fwmodpath", "$attr{global}{modpath}/FHEM"); $FW_ss = AttrVal($FW_wname, "smallscreen", 0); $FW_tp = AttrVal($FW_wname, "touchpad", $FW_ss); + my $prf = AttrVal($FW_wname, "stylesheetPrefix", ""); # Lets go: if($arg =~ m,^${FW_ME}/(.*)\.(css|html|js)$,) { my ($file, $ext) = ($1, $2); - $file =~ s,/,,g; # little bit of security + $file =~ s,\.\./,,g; # little bit of security open(FH, "$FW_dir/$file.$ext") || return 0; FW_pO join("", ); close(FH); @@ -358,14 +359,19 @@ FW_AnswerCall($) $arg =~ m,^$FW_ME/(.*.png)$,i || $arg =~ m,^/(favicon.ico)$,) { my ($img, $cachable) = ($1, 1); - $img =~ s,/,,g; - if(!open(FH, "$FW_dir/$img")) { # Hack: convert device state to icon name - return 0 if($arg eq "/favicon.ico"); + $img =~ s,\.\./,,g; + + my $fnd; + $fnd = open(FH, "$FW_dir/$prf/$img") if($prf); + $fnd = open(FH, "$FW_dir/$img") if(!$fnd); + if(!$fnd && $arg =~ m,/icons/,) { # Hack: convert device state to icon name FW_ReadIcons(); $img = FW_dev2image($img); $cachable = 0; - return 0 if(!$img || !open(FH, "$FW_dir/$img")); + $fnd = open(FH, "$FW_dir/$prf/$img") if($img); + $fnd = open(FH, "$FW_dir/$img") if(!$fnd && $img); } + return 0 if(!$fnd); binmode (FH); # necessary for Windows FW_pO join("", ); close(FH); @@ -502,7 +508,6 @@ FW_AnswerCall($) my $rf = AttrVal($FW_wname, "refresh", ""); FW_pO "" if($rf); - my $prf = AttrVal($FW_wname, "stylesheetPrefix", ""); $prf = "smallscreen" if(!$prf && $FW_ss); $prf = "touchpad" if(!$prf && $FW_tp); FW_pO ""; @@ -1820,17 +1825,26 @@ FW_ReadIcons() { my $now = time(); return if($FW_iconsread && ($now - $FW_iconsread) <= 5); + %FW_icons = (); + my @files; if(opendir(DH, $FW_dir)) { - my @files = readdir(DH); + @files = readdir(DH); closedir(DH); - foreach my $l (sort @files) { # Order: .gif,.jpg,.png - next if($l !~ m/\.(png|gif|jpg)$/i); - my $x = $l; - $x =~ s/\.[^.]+$//; # Cut .gif/.jpg - $FW_icons{$x} = $l; - } } + my $prf = AttrVal($FW_wname, "stylesheetPrefix", ""); + if($prf && opendir(DH, "$FW_dir/$prf")) { + push @files, readdir(DH); + closedir(DH); + } + + foreach my $l (sort @files) { # Order: .gif,.jpg,.png + next if($l !~ m/\.(png|gif|jpg)$/i); + my $x = $l; + $x =~ s/\.[^.]+$//; # Cut .gif/.jpg + $FW_icons{$x} = $l; + } + $FW_iconsread = $now; }