From 1354751d9406f78520a3a73f90b7d75d8efde47b Mon Sep 17 00:00:00 2001 From: b Date: Thu, 28 Sep 2023 14:12:13 +0000 Subject: [PATCH] Started new viewer HTML output generator --- bsta_lib.1.pm | 258 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 238 insertions(+), 20 deletions(-) diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index aed142b..d9b53ce 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -44,7 +44,8 @@ our @EXPORT_OK = ( ###PERL_LIB: use lib /botm/lib/bsta use botm_common ( - 'html_entity_encode_dec' + 'html_entity_encode_dec', + 'merge_url', 'url_query_encode' ); ###PERL_CGI_GOTO_PATH: CGI_GOTO_PATH = /bsta/g @@ -312,7 +313,13 @@ use constant entitycode => { use constant STATE => { 'inactive' => 0, 'waiting' => 1, - 'ready' => 2 + 'ready' => 2, + 'end' => 3, +}; +use constant TEXT_MODE => { + 'normal' => 0, + 'bb' => 1, + 'info' => 2, }; use constant tagsbb => { @@ -378,24 +385,6 @@ use constant tagsht => { '/?' => '[/unknown!]', }; -use constant HTML_START => - ''."\n". - ''."\n"; -use constant HTML_END => - ''."\n"; -use constant HTML_HEAD_START => - ''."\n". - ''."\n"; -use constant HTML_HEAD_END => - ''."\n"; -use constant HTML_BODY_START => - ''."\n". - ''."\n". - '
'."\n"; -use constant HTML_BODY_END => - '
'."\n". - ''.html_entity_encode_dec(WEBSITE).''."\n". - ''."\n"; # Function to return an error page @@ -1378,4 +1367,233 @@ sub debug { return $text; } + +sub print_html_start { + (my $fh) = @_; + print $fh ''."\n"; + print $fh ''."\n"; +} + +sub print_html_end { + (my $fh) = @_; + print $fh ''."\n"; +} + +sub print_html_head_start { + print $fh ''."\n"; + print $fh ''."\n"; + print $fh ''."\n"; + print $fh ''."\n"; +} + +sub print_html_head_end { + (my $fh) = @_; + print $fh ''."\n"; +} + +sub print_html_body_start { + (my $fh) = @_; + print $fh ''."\n"; + print $fh ''."\n"; + print $fh '
'."\n"; +} + +sub print_html_body_end { + (my $fh) = @_; + print $fh '
'."\n"; + print $fh ''.html_entity_encode_dec(WEBSITE(),1).''."\n"; + print $fh ''."\n"; +} + +sub print_html_data { + (my $fh, my $data) = @_; + + foreach my $key (keys %$data) { + unless ($key eq 'content') { + my $val = $data->{'ind'}; + $val =~ s/(\r)?\n/\n /gs; + + } + } +} + +sub print_viewer_page { + ( + my $file, + my $frame, + my $password_ok, + my $access, + my $textmode, + my $show_command, + my $state, + my $settings, + my $frame_data, + my $nextframe_data + ) = @_; + my $fh; + + my $prev_available = ($frame > 0 && $access); + my $next_available = ($password_ok || ($frame < int($state->{'last'}))); + my $prefetch_next = ( + $password_ok || + ($frame+1 < int($state->{'last'})) || ( + ($frame < int($state->{'last'})) && + (int($state->{'state'}) >= STATE->{'ready'}) + ) + ); + my $show_timer = ($password_ok || + ($frame == int($state->{'last'})) && + (int($state->{'state'}) >= STATE->{'waiting'}) && + (int($state->{'state'}) <= STATE->{'ready'}) + ); + $show_command = ( + $password_ok || + ($frame < int($state->{'last'})) || + ((int($state{'state'}) >= STATE->{'ready'} ) && $show_command) + ); + my $frame_indirect = !( + (!$access) || ( + ($frame < int($state->{'last'})) && + (int($state->{'state'}) > STATE->{'inactive'}) + ) + ); + my $nextframe_indirect = !($frame+1 < int($state{'last'})); + + my $password_query; + + my $goto_url = CGI_GOTO_PATH; + my $timer_url = CGI_TIMER_PATH; + my $viewer_0_url = merge_url(CGI_VIEWER_PATH(), 0); + my $viewer_prev_url = merge_url(CGI_VIEWER_PATH(), $frame-1); + my $viewer_next_url = merge_url(CGI_VIEWER_PATH(), $frame+1); + my $frame_url; + my $frame_file = ''; + my $frame_next_url; + if ($frame_indirect) { + $frame_url = merge_url(CGI_FRAME_PATH(), $frame); + } + elsif ($frame_data->{'frame'} ne '') { + $frame_file = $frame_data->{'frame'}; + $frame_url = merge_url(CGI_PATH(), $frame_file); + } + else { + $frame_file = sprintf($settings->{'frame'}, $frame, $frame_data->{'ext'}); + $frame_url = merge_url(CGI_PATH(), $frame_file); + } + if ($nextframe_indirect) { + $frame_next_url = merge_url(CGI_FRAME_PATH(), $frame); + } + elsif ($nextframe_data->{'frame'} ne '') { + $frame_next_url = merge_url(CGI_PATH(), $nextframe_data->{'frame'}); + } + else { + $frame_next_url = merge_url(CGI_PATH(), sprintf( + $settings->{'frame'}, $frame+1, $nextframe_data->{'ext'} + )); + } + + if ($password_ok) { + $password_query = '?'.url_query_encode(\('p', $settings->{'password'})); + $goto_url = merge_url($goto_url , $password_query); + $viewer_0_url = merge_url($viewer_0_url , $password_query); + $viewer_prev_url = merge_url($viewer_prev_url, $password_query); + $viewer_next_url = merge_url($viewer_next_url, $password_query); + if ($frame_indirect) { + $frame_url = merge_url($frame_url , $password_query); + } + if ($nextframe_indirect) { + $frame_url = merge_url($frame_next_url, $password_query); + } + } + my $_goto_url = html_entity_encode_dec($goto_url , 1); + my $_timer_url = html_entity_encode_dec($timer_url , 1); + my $_viewer_0_url = html_entity_encode_dec($viewer_0_url , 1); + my $_viewer_prev_url = html_entity_encode_dec($viewer_prev_url, 1); + my $_viewer_next_url = html_entity_encode_dec($viewer_next_url, 1); + my $_frame_url = html_entity_encode_dec($frame_url , 1); + my $_frame_next_url = html_entity_encode_dec($frame_next_url , 1); + + my $_title = html_entity_encode_dec($framedata->{'title'}, 1); + + if ($textmode == TEXT_MODE->{'info'}) { + if ($show_command) { + $frame_data->{'command'} = $nextframe_data->{'title'}; + } + if ($access) { + $frame_data->{'frame'} = $frame_file; + } + } + + if (ref($file)) { + $fh=$file; + unless (seek($fh, 0, 0)) { + #don't actually fail here + } + } + else { + unless (open ($fh, ">:encoding(UTF-8)", encode('locale_fs', $file))) { + return 0; + } + } + + print_html_start($fh); + print_html_head_start($fh); + + print $fh ''."\n"; + print $fh ''."\n"; + if ($prev_available) { + print $fh ''."\n"; + } + if ($next_available) { + print $fh ''."\n"; + if ($prefetch_next) { + print $fh ''."\n"; + print $fh ''."\n"; + } + } + if ($show_timer) { + print ''."\n"; + } + + print_html_head_end($fh); + print_html_body_start($fh); + + print '
'."\n"; + + print '
'."\n"; + print '

'.$_title.'

'."\n"; + print '
'."\n"; + + print '
'."\n"; + + print ''.$frame.''."\n"; + + print '
'."\n"; + + if ($textmode == TEXT_MODE->{'info'}) { + print '
'."\n"; + + print '
'."\n"; + } + elsif ($textmode == TEXT_MODE->{'bb'}) { + + } + elsif ($frame_data->{'content'} ne '') { + + } + + print_html_body_end($fh); + print_html_end($fh); + + + unless (ref($file)) { + close ($fh); + } + else { + truncate ($fh , tell($fh)); + } + + return 1; +} + 1 -- 2.30.2