#use wml::std::lang # # # use Cwd; use Text::ParseWords; my @path; $level = grep(/\.\./, split(/\//, '')); $cwd = cwd; $file = '' . '.html'; @path = (split(/\//, $cwd), $file); @path = @path[$#path - $level .. $#path]; local @lines; local @langs = split ( ' ', "" ); buttons ( 0 ); # # buttons($level) # sub buttons { my ($level) = @_; my $pat='([^"\s]+)|"([^"]*)"'; my (@in, $reldir, $absdir); my ($href, $text); #say ( "Called buttons ( $level )\n" ); my $dir = '../' x ($#path - $level); my $found_one = 0; #say("in buttons, level $level, buttons file: $dir$buttonsfile\n"); #say ( "Reading buttons in... \"${dir}buttons\"\n" ); if (open(FD, "${dir}buttons")) { chomp ( @in = ); close(FD); $found_one = 0; for (@in) { ## skip comment lines /^\s*#/ && next; ## split the line my ( $id, $href, @text ) = shellwords ( $_ ); my %mltext; my $mltextstr; my $mlhref; #say ( "Got: id=$id, href=$href, text_nof=$#text text0=$text[0], text1=$text[1] \n" ); ## initialize the text-per-language hash foreach ( @text ) { my $found = 0; foreach $l ( @langs ) { if ( /^$l:/ ) { $mltext{$l} = substr ( $_, 3 ); $found = 1; last; } } $mltext{all} = "$_" unless $found; } ## create a WML compliant multi-language string, consisting of all available languages foreach ( keys ( %mltext )) { if ( /all/ ) { $mltextstr .= $mltext{$_} } else { $mltextstr .= "[LANG_\U$_:" . $mltext{$_} . ":]"; } } ## create a WML compliant multi-language string for the href target (replace "*" with country-code) foreach ( @langs ) { my $r = $href; $r =~ s/\*/$_/; $mlhref .= "[LANG_\U$_:"; $mlhref .= "$dir$r:]"; } ## no href? - no button $href =~ s/\.\*//; if ( length $href ) { ## if this is the first button at the current level, than start an
    tag if ( ! $found_one ) { $found_one = 1;
      } if ( $href =~ m#^$path[$level]/?# ) { ## OPEN if ($level < $#path) { ## OPEN PARENT if ($path[$level + 1] eq 'index.html') { #say ( "OPEN PARENT index: name=$text sel=1\n" );
    • $mltextstr } else { #say ( "OPEN PARENT non-index: name=$text url=$dir$href sel=0\n" );
    • $mltextstr } buttons($level + 1);
    • } else { #say ( "OPEN SELF: name=$text sel=1\n" ); ## OPEN SELF
    • $mltextstr
    • } } else { # NOT OPEN #say ( "NOT OPEN: name=$text url=$mlhref sel=0\n" );
    • $mltextstr
    • } } } if ( $found_one ) {
    } } }