############################################## # $Id$ package main; use strict; use warnings; use vars qw($FW_subdir); # Sub-path in URL for extensions, e.g. 95_FLOORPLAN use vars qw($FW_ME); # webname (default is fhem), used by 97_GROUP/weblink use vars qw($FW_CSRF); # CSRF Token or empty use IO::File; ##################################### sub weblink_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "weblink_Define"; $hash->{AttrList} = "disable:0,1 disabledForIntervals htmlattr nodetaillink:1,0"; $hash->{FW_summaryFn} = "weblink_FwFn"; $hash->{FW_detailFn} = "weblink_FwFn"; $hash->{FW_atPageEnd} = 1; } ##################################### sub weblink_Define($$) { my ($hash, $def) = @_; my ($name, $type, $wltype, $link) = split("[ \t]+", $def, 4); my %thash = ( link=>1, image=>1, iframe=>1, htmlCode=>1, cmdList=>1, fileplot=>1, dbplot=>1); if(!$link || !$thash{$wltype}) { return "Usage: define weblink [" . join("|",sort keys %thash) . "] "; } if($wltype eq "fileplot" || $wltype eq "dbplot") { Log3 $name, 1, "Converting weblink $name ($wltype) to SVG"; my $newm = LoadModule("SVG"); return "Cannot load module SVG" if($newm eq "UNDEFINED"); $hash->{TYPE} = "SVG"; $hash->{DEF} = $link; return CallFn($name, "DefFn", $hash, "$name $type $link"); } $hash->{WLTYPE} = $wltype; $hash->{LINK} = $link; $hash->{STATE} = "initialized"; return undef; } ##################################### # FLOORPLAN compat sub FW_showWeblink($$$$) { my ($d,undef,undef,$buttons) = @_; if($buttons !~ m/HASH/) { my %h = (); $buttons = \%h; } FW_pO(weblink_FwFn(undef, $d, "", $buttons)); return $buttons; } ################## sub weblink_FwDetail($@) { my ($d, $text, $nobr)= @_; return "" if(AttrVal($d, "group", "") || AttrVal($d, "nodetaillink", "")); my $alias = AttrVal($d, "alias", $d); my $ret = ($nobr ? "" : "
"); $ret .= "$text " if($text); $ret .= FW_pHPlain("detail=$d", $alias) if(!$FW_subdir); $ret .= "
"; return $ret; } sub weblink_FwFn($$$$) { my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn. my $hash = $defs{$d}; my $link = $hash->{LINK}; my $wltype = $hash->{WLTYPE}; my $ret = ""; return "" if(IsDisabled($d)); my $attr = AttrVal($d, "htmlattr", ""); if($wltype eq "htmlCode") { $link = AnalyzePerlCommand(undef, $link) if($link =~ m/^{(.*)}$/s); $ret = $link; } elsif($wltype eq "link") { my $alias = AttrVal($d, "alias", $d); $ret = "$alias"; # no FW_pH, open extra browser } elsif($wltype eq "image") { $ret = "
" . weblink_FwDetail($d); } elsif($wltype eq "iframe") { $ret = "" . weblink_FwDetail($d); } elsif($wltype eq "cmdList") { my @lines = split(" ", $link); my $row = 1; $ret = ""; $ret .= ""; $ret .= ""; $ret .= "
"; foreach my $line (@lines) { my @args = split(":", $line, 3); $ret .= ""; $ret .= ""; $ret .= ""; } $ret .= "
". "$args[0]". "$args[1]

"; } return $ret; } 1; =pod =item helper =item summary define a HTTP link for the FHEMWEB frontend =item summary_DE HTTP Link fuer das FHEMWEB Frontend =begin html

weblink

=end html =cut