]> bicyclesonthemoon.info Git - ott/bsta/commitdiff
Started new viewer HTML output generator
authorb <rowerynaksiezycu@gmail.com>
Thu, 28 Sep 2023 14:12:13 +0000 (14:12 +0000)
committerb <rowerynaksiezycu@gmail.com>
Thu, 28 Sep 2023 14:12:13 +0000 (14:12 +0000)
bsta_lib.1.pm

index aed142b2d4872e638df8320591bc87c0eab328f0..d9b53cec96d9e3d62e431e211ebc8283af00921e 100644 (file)
@@ -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 =>
-       '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n".
-       '<html lang="en">'."\n";
-use constant HTML_END =>
-       '</html>'."\n";
-use constant HTML_HEAD_START =>
-       '<head>'."\n".
-       '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
-use constant HTML_HEAD_END =>
-       '</head>'."\n";
-use constant HTML_BODY_START =>
-       '<body>'."\n".
-       '<a href="/"><img id="botmlogo" src="'.html_entity_encode_dec(CGI_LOGO_PATH).'" alt="'.html_entity_encode_dec(WEBSITE).'"></a>'."\n".
-       '<div id="all">'."\n";
-use constant HTML_BODY_END =>
-       '</div>'."\n".
-       '<a href="/" class="cz">'.html_entity_encode_dec(WEBSITE).'</a>'."\n".
-       '</body></html>'."\n";
 
 
 # Function to return an error page
@@ -1378,4 +1367,233 @@ sub debug {
        return $text;
 }
 
+
+sub print_html_start {
+       (my $fh) = @_;
+       print $fh '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
+       print $fh '<html lang="en">'."\n";
+}
+
+sub print_html_end {
+       (my $fh) = @_;
+       print $fh '</html>'."\n";
+}
+
+sub print_html_head_start {
+       print $fh '<head>'."\n";
+       print $fh '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
+       print $fh '<link rel="icon" type="image/png" href="'.html_entity_encode_dec(FAVICON_PATH(),1).'">'."\n";
+       print $fh '<link rel="stylesheet" href="'.html_entity_encode_dec(CGI_CSS_PATH(),1).'">'."\n";
+}
+
+sub print_html_head_end {
+       (my $fh) = @_;
+       print $fh '</head>'."\n";
+}
+       
+sub print_html_body_start {
+       (my $fh) = @_;
+       print $fh '<body>'."\n";
+       print $fh '<a href="/"><img id="botmlogo" src="'.html_entity_encode_dec(CGI_LOGO_PATH(),1).'" alt="'.html_entity_encode_dec(WEBSITE(),1).'"></a>'."\n";
+       print $fh '<div id="all">'."\n";
+}
+
+sub print_html_body_end {
+       (my $fh) = @_;
+       print $fh '</div>'."\n";
+       print $fh '<a href="/" class="cz">'.html_entity_encode_dec(WEBSITE(),1).'</a>'."\n";
+       print $fh '</body></html>'."\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 '<link rel="index" href="'.$_goto_url.'">'."\n";
+       print $fh '<link rel="start" href="'.$_viewer_0_url.'">'."\n";
+       if ($prev_available) {
+               print $fh '<link rel="prev" href="'.$_viewer_prev_url.'">'."\n";
+       }
+       if ($next_available) {
+               print $fh '<link rel="next" href="'.$_viewer_next_url.'">'."\n";
+               if ($prefetch_next) {
+                       print $fh '<link rel="prefetch" href="'.$_viewer_next_url.'">'."\n";
+                       print $fh '<link rel="prefetch" href="'.$_frame_next_url.'">'."\n";
+               }
+       }
+       if ($show_timer) {
+               print '<!-- <script src="'.$_timer_url.'"></script> -->'."\n";
+       }
+       
+       print_html_head_end($fh);
+       print_html_body_start($fh);
+       
+       print '<div id="inst" class="ins">'."\n";
+       
+       print '<div id="title">'."\n";
+       print '<h1 id="titletext">'.$_title.'</h1>'."\n";
+       print '</div>'."\n";
+       
+       print '</div><div id="framespace">'."\n";
+       
+       print '<img src="'.$_frame_url.'" id="frame" alt="'.$frame.'" title="'.$_title.'">'."\n";
+       
+       print '</div><div id="insb" class="ins">'."\n";
+       
+       if ($textmode == TEXT_MODE->{'info'}) {
+               print '<div id="chat">'."\n";
+               
+               print '</div>'."\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