From eb3c57408fcd84e4964b90f85bd8b07d42fb79ac Mon Sep 17 00:00:00 2001
From: b <rowerynaksiezycu@gmail.com>
Date: Fri, 29 Sep 2023 22:33:01 +0000
Subject: [PATCH] html output generator: bbcode, info, content parts mostly

---
 botm-common        |   2 +-
 bsta_lib.1.pm      | 439 ++++++++++-----------------------------------
 settings-again.txt |   1 +
 settings-bsta.txt  |   1 +
 settings-debug.txt |   1 +
 settings-tbst.txt  |   1 +
 settings.txt       |   1 +
 7 files changed, 102 insertions(+), 344 deletions(-)

diff --git a/botm-common b/botm-common
index 6881684..bd6107e 160000
--- a/botm-common
+++ b/botm-common
@@ -1 +1 @@
-Subproject commit 6881684b6dcb50d6d9e77584aadf3eaa47dd096c
+Subproject commit bd6107e790c6666a87a0e9f2bec9370868bf531b
diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm
index eca8565..a91aa68 100644
--- a/bsta_lib.1.pm
+++ b/bsta_lib.1.pm
@@ -825,7 +825,7 @@ sub convtree {
 }
 
 #bbcode to html, TBD
-sub bb2ht {
+sub bb_to_html {
 	(my $bb, my $printdebug) = @_;
 	my $ht;
 	my %bbtree;
@@ -835,173 +835,10 @@ sub bb2ht {
 	($debug, $ht) = convtree ($printdebug, $debug, 'html', %bbtree);
 	
 	return $ht;
-	
-	# $level=0;
-	# $ind='_';
-	# $ht='';
-	# $debug .= debug($printdebug, "\n<!--PROCESSING BBCODE TREE:\n");
-	
-	# while ($level >=0) {
-		# $debug .= debug($printdebug, "[$level:$ind:".int($bbtree{$ind.'.e'})."]");
-		# if($bbtree{$ind.'.t'} eq 'tx') {
-			# $debug .= debug($printdebug, "text: ".$bbtree{$ind.'.v'});
-			# $ht = $ht.html_encode_line($bbtree{$ind.'.v'});
-			
-			# {do{
-				# $ind =~ s/\.([0-9]+)$//;
-				# $indd = int($1)+1;
-				# if ($indd < $bbtree{$ind.'.e'}){
-					# $ind = $ind.'.'.$indd;
-					# last;
-				# }
-				# else {
-					# #should not occur with a correct bbtree
-					# $debug .= debug($printdebug, "[<tx]");
-					# $level -= 1;
-				# }
-			# } while ($level>=0);}
-		# }
-		# elsif($bbtree{$ind.'.t'} eq 'tg') {
-			# if($bbtree{$ind.'.n'} =~ /^\//) {
-				# $debug .= debug($printdebug, "tag: [".$bbtree{$ind.'.n'}."]");
-				# if($bbtree{$ind.'.n'} eq '/ht') {
-					# #
-				# }
-				# elsif ($bbtree{$ind.'.n'} =~ /^\/(fq|tq)$/) {
-					# $ht = $ht.'</div>';
-				# }
-				# elsif ($bbtree{$ind.'.n'} =~ /^\/(br|ni|po)$/) {
-					# $ht = $ht.'</span>';
-				# }
-				# elsif ($bbtree{$ind.'.n'} eq '/url') {
-					# $ht = $ht.'</a>';
-				# }
-				# elsif ($bbtree{$ind.'.n'} eq '/i') {
-					# $ht = $ht.'</i>';
-				# }
-				# else { #unimpl.
-					# $ht = $ht.'['.html_encode_line($bbtree{$ind.'.n'}).']';
-					# $debug .= debug($printdebug, "[unknown!]");
-				# }
-				# $ind =~ s/\.([0-9]+)$//;
-				# $level -= 1;
-				# $debug .= debug($printdebug, "[<]");
-				# if($level>=0) {
-					# {do{
-						# $ind =~ s/\.([0-9]+)$//;
-						# $indd = int($1)+1;
-						# if ($indd < $bbtree{$ind.'.e'}){
-							# $ind = $ind.'.'.$indd;
-							# last;
-						# }
-						# else {
-							# #should not occur with a correct bbtree
-							# $debug .= debug($printdebug, "[<nd]");
-							# $level -= 1;
-						# }
-					# } while ($level>=0);}
-				# }
-				# else {
-					# # time to end this
-					# $level = -1;
-				# }
-			# }
-			# else {
-				# if($bbtree{$ind.'.c'} ne '') {
-					# if($bbtree{$ind.'.n'} eq 'ht') {
-						# #
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'fq') {
-						# $ht = $ht.'<div class="fq">';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'tq') {
-						# $ht = $ht.'<div class="tq">';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'br') {
-						# $ht = $ht.'<span class="br">';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'ni') {
-						# $ht = $ht.'<span class="ni">';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'po') {
-						# $ht = $ht.'<span class="po">';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'i') {
-						# $ht = $ht.'<i>';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'url') {
-						# $ht = $ht.'<a href="'.entityencode($bbtree{$ind.'.v'}).'">';
-					# }
-					# else { #unimpl.
-						# $ht = $ht.'['.html_encode_line($bbtree{$ind.'.n'}).(($bbtree{$ind.'.v'} ne '' )?entityencode($bbtree{$ind.'.v'}):'').']';
-						# $debug .= debug($printdebug, "[unknown!]");
-					# }
-				# }
-				# else {
-					# $debug .= debug($printdebug, "unclosed tag: [".$bbtree{$ind.'.n'}."]");
-					# $ht = $ht.'['.html_encode_line($bbtree{$ind.'.n'}).']';
-				# }
-				# if($bbtree{$ind.'.e'}>0) {
-					# $ind = $ind.'.0';
-					# $level += 1;
-					# $debug .= debug($printdebug, "[>]");
-				# }
-				# else {
-					# {do{
-						# $ind =~ s/\.([0-9]+)$//;
-						# $indd = int($1)+1;
-						# if ($indd < $bbtree{$ind.'.e'}){
-							# $ind = $ind.'.'.$indd;
-							# last;
-						# }
-						# else {
-							# #should not occur with a correct bbtree
-							# $debug .= debug($printdebug, "[<st]");
-							# $level -= 1;
-						# }
-					# } while ($level>=0);}
-				# }
-			# }
-		# }
-		# else {
-			# $debug .= debug($printdebug, "unknown thing: ".$bbtree{$ind.'.t'});
-			# #should not occur with a correct bbtree
-			# #unless unimplemented
-			# $ind =~ s/\.([0-9]+)$//;
-			# $level -= 1;
-			# $debug .= debug($printdebug, "[<ui]");
-			# if($level>0) {
-				# {do{
-					# $ind =~ s/\.([0-9]+)$//;
-					# $indd = int($1)+1;
-					# if ($indd < $bbtree{$ind.'.e'}){
-						# $ind = $ind.'.'.$indd;
-						# last;
-					# }
-					# else {
-						# #should not occur with a correct bbtree
-						# $debug .= debug($printdebug, "[<un]");
-						# $level -= 1;
-					# }
-				# } while ($level>=0);}
-			# }
-			# else {
-				# # time to end this
-				# $level = -1;
-			# }
-		# }
-		# $debug .= debug($printdebug, "[>$level:$ind]\n");
-	# }
-	
-	# $debug .= debug($printdebug, "-->\n");
-	# # print $debug;
-	
-	
-	
 }
 
 #bbcode to bb, TBD
-sub bb2bb {
+sub bb_to_bbcode {
 	(my $bb, my $printdebug) = @_;
 	my $ht;
 	my %bbtree;
@@ -1011,167 +848,56 @@ sub bb2bb {
 	($debug, $ht) = convtree ($printdebug, $debug, 'bb', %bbtree);
 	
 	return $ht;
+}
+
+# TO REMOVE
+sub bb2ht {
+	return bb_to_html(@_);
+}
+
+# TO REMOVE
+sub bb2bb {
+	return bb_to_bbcode(@_);
+}
+
+sub eval_bb {
+	(my $bb) = @_;
+	my $value;
+	my $before;
+	my $after;
 	
-	# $level=0;
-	# $ind='_';
-	# $ht='';
-	# $debug .= debug($printdebug, "\n<!--PROCESSING BBCODE TREE:\n");
-	
-	# while ($level >=0) {
-		# $debug .= debug($printdebug, "[$level:$ind:".int($bbtree{$ind.'.e'})."]");
-		# if($bbtree{$ind.'.t'} eq 'tx') {
-			# $debug .= debug($printdebug, "text: ".$bbtree{$ind.'.v'});
-			# $ht = $ht.$bbtree{$ind.'.v'};
-			
-			# {do{
-				# $ind =~ s/\.([0-9]+)$//;
-				# $indd = int($1)+1;
-				# if ($indd < $bbtree{$ind.'.e'}){
-					# $ind = $ind.'.'.$indd;
-					# last;
-				# }
-				# else {
-					# #should not occur with a correct bbtree
-					# $debug .= debug($printdebug, "[<tx]");
-					# $level -= 1;
-				# }
-			# } while ($level>=0);}
-		# }
-		# elsif($bbtree{$ind.'.t'} eq 'tg') {
-			# if($bbtree{$ind.'.n'} =~ /^\//) {
-				# $debug .= debug($printdebug, "tag: [".$bbtree{$ind.'.n'}."]");
-				# if($bbtree{$ind.'.n'} eq '/ht') {
-					# #
-				# }
-				# elsif ($bbtree{$ind.'.n'} =~ /^\/(fq|tq)$/) {
-					# $ht = $ht.'[/quote]';
-				# }
-				# elsif ($bbtree{$ind.'.n'} =~ /^\/(br|ni|po)$/) {
-					# $ht = $ht.'[/color]';
-				# }
-				# elsif ($bbtree{$ind.'.n'} eq '/url') {
-					# $ht = $ht.'[/url]';
-				# }
-				# elsif ($bbtree{$ind.'.n'} eq '/i') {
-					# $ht = $ht.'[/i]';
-				# }
-				# else { #unimpl.
-					# $ht = $ht.'['.$bbtree{$ind.'.n'}.']';
-					# $debug .= debug($printdebug, "[unknown!]");
-				# }
-				# $ind =~ s/\.([0-9]+)$//;
-				# $level -= 1;
-				# $debug .= debug($printdebug, "[<]");
-				# if($level>0) {
-					# {do{
-						# $ind =~ s/\.([0-9]+)$//;
-						# $indd = int($1)+1;
-						# if ($indd < $bbtree{$ind.'.e'}){
-							# $ind = $ind.'.'.$indd;
-							# last;
-						# }
-						# else {
-							# #should not occur with a correct bbtree
-							# $debug .= debug($printdebug, "[<nd]");
-							# $level -= 1;
-						# }
-					# } while ($level>=0);}
-				# }
-				# else {
-					# # time to end this
-					# $level = -1;
-				# }
-			# }
-			# else {
-				# if($bbtree{$ind.'.c'} ne '') {
-					# $debug .= debug($printdebug, "tag: [".$bbtree{$ind.'.n'}."]");
-					# if($bbtree{$ind.'.n'} eq 'ht') {
-						# #
-					# }
-					# elsif($bbtree{$ind.'.n'} =~ /^(fq|tq)$/) {
-						# $ht = $ht.'[quote]';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'br') {
-						# $ht = $ht.'[color=#BB6622]';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'po') {
-						# $ht = $ht.'[color=#FF8800]';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'ni') {
-						# $ht = $ht.'[color=#0057AF]';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'url') {
-						# $ht = $ht.'[url='.$bbtree{$ind.'.v'}.']';
-					# }
-					# elsif($bbtree{$ind.'.n'} eq 'i') {
-						# $ht = $ht.'[i]';
-					# }
-					# else { #unimpl.
-						# $ht = $ht.'['.$bbtree{$ind.'.n'}.(($bbtree{$ind.'.v'} ne '' )?($bbtree{$ind.'.v'}):'').']';
-						# $debug .= debug($printdebug, "[unknown!]");
-					# }
-				# }
-				# else {
-					# $debug .= debug($printdebug, "unclosed tag: [".$bbtree{$ind.'.n'}."]");
-					# $ht = $ht.'['.$bbtree{$ind.'.n'}.']';
-				# }
-				# if($bbtree{$ind.'.e'}>0) {
-					# $ind = $ind.'.0';
-					# $level += 1;
-					# $debug .= debug($printdebug, "[>]");
-				# }
-				# else {
-					# {do{
-						# $ind =~ s/\.([0-9]+)$//;
-						# $indd = int($1)+1;
-						# if ($indd < $bbtree{$ind.'.e'}){
-							# $ind = $ind.'.'.$indd;
-							# last;
-						# }
-						# else {
-							# #should not occur with a correct bbtree
-							# $debug .= debug($printdebug, "[<st]");
-							# $level -= 1;
-						# }
-					# } while ($level>=0);}
-				# }
-			# }
-		# }
-		# else {
-			# $debug .= debug($printdebug, "unknown thing: ".$bbtree{$ind.'.t'});
-			# #should not occur with a correct bbtree
-			# #unless unimplemented
-			# $ind =~ s/\.([0-9]+)$//;
-			# $level -= 1;
-			# $debug .= debug($printdebug, "[<ui]");
-			# if($level>0) {
-				# {do{
-					# $ind =~ s/\.([0-9]+)$//;
-					# $indd = int($1)+1;
-					# if ($indd < $bbtree{$ind.'.e'}){
-						# $ind = $ind.'.'.$indd;
-						# last;
-					# }
-					# else {
-						# #should not occur with a correct bbtree
-						# $debug .= debug($printdebug, "[<un]");
-						# $level -= 1;
-					# }
-				# } while ($level>=0);}
-			# }
-			# else {
-				# # time to end this
-				# $level = -1;
-			# }
-		# }
-		# $debug .= debug($printdebug, "[>$level:$ind]\n");
-	# }
-	
-	# $debug .= debug($printdebug, "-->\n");
-	# # print $debug;
-	
-	
-	
+	while ($bb =~ m/###([^#;]*);/g) {
+		$value = $1;
+		$before = $`;
+		$after = $';
+		
+		if ($value =~ /^att&([0-9]+)$/) {
+			$value = merge_url(
+				SCHEME().WEBSITE(),
+				CGI_ATTACH_PATH(),
+				int($1)
+			)
+		}
+		elsif ($value =~ /^vw&([0-9]+)$/) {
+			$value = merge_url(
+				SCHEME().WEBSITE(),
+				CGI_VIEWER_PATH(),
+				int($1)
+			)
+		}
+		elsif ($value =~ /^fr&([0-9]+)$/) {
+			$value = merge_url(
+				SCHEME().WEBSITE(),
+				CGI_FRAME_PATH(),
+				int($1)
+			)
+		}
+		else {
+			$value = '';
+		}
+		$bb = $before . $value . $after;
+	}
+	return $bb;
 }
 
 
@@ -1311,23 +1037,34 @@ sub print_viewer_page {
 	
 	my $goto_url = CGI_GOTO_PATH;
 	my $timer_url = CGI_TIMER_PATH;
+	my $viewer_full_url = merge_url(
+		SCHEME().WEBSITE(),
+		CGI_VIEWER_PATH(),
+		$frame
+	);
 	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_url;
 	my $frame_next_url;
-	if ($frame_indirect) {
-		$frame_url = merge_url(CGI_FRAME_PATH(), $frame);
-	}
-	elsif ($frame_data->{'frame'} ne '') {
+	my $frame_normal_url;
+	my $frame_full_url;
+	if ($frame_data->{'frame'} ne '') {
 		$frame_file = $frame_data->{'frame'};
-		$frame_url = merge_url(CGI_PATH(), $frame_file);
+		$frame_normal_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);
+		$frame_normal_url = merge_url(CGI_PATH(), $frame_file);
 	}
+	$frame_url = $frame_indirect ?
+		merge_url(CGI_FRAME_PATH(), $frame) :
+		$frame_normal_url;
+	$frame_full_url = merge_url(
+		SCHEME().WEBSITE(),
+		$frame_normal_url
+	);
 	if ($nextframe_indirect) {
 		$frame_next_url = merge_url(CGI_FRAME_PATH(), $frame);
 	}
@@ -1355,11 +1092,13 @@ sub print_viewer_page {
 	}
 	my $_goto_url        = html_entity_encode_dec($goto_url       , 1);
 	my $_timer_url       = html_entity_encode_dec($timer_url      , 1);
+	my $_viewer_full_url = html_entity_encode_dec($viewer_full_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 $_frame_full_url  = html_entity_encode_dec($frame_full_url , 1);
 	
 	my $_title = html_entity_encode_dec($framedata->{'title'}, 1);
 	
@@ -1400,36 +1139,50 @@ sub print_viewer_page {
 		}
 	}
 	if ($show_timer) {
-		print '<!-- <script src="'.$_timer_url.'"></script> -->'."\n";
+		print $fh '<!-- <script src="'.$_timer_url.'"></script> -->'."\n";
 	}
 	
 	print_html_head_end($fh);
 	print_html_body_start($fh);
 	
-	print '<div id="inst" class="ins">'."\n";
+	print $fh '<div id="inst" class="ins">'."\n";
 	
-	print '<div id="title">'."\n";
-	print '<h1 id="titletext">'.$_title.'</h1>'."\n";
-	print '</div>'."\n";
+	print $fh '<div id="title">'."\n";
+	print $fh '<h1 id="titletext">'.$_title.'</h1>'."\n";
+	print $fh '</div>'."\n";
 	
-	print '</div><div id="framespace">'."\n";
+	print $fh '</div><div id="framespace">'."\n";
 	
-	print '<img src="'.$_frame_url.'" id="frame" alt="'.$frame.'" title="'.$_title.'">'."\n";
+	print $fh '<img src="'.$_frame_url.'" id="frame" alt="'.$frame.'" title="'.$_title.'">'."\n";
 	
-	print '</div><div id="insb" class="ins">'."\n";
+	print $fh '</div><div id="insb" class="ins">'."\n";
 	
 	if ($textmode == TEXT_MODE->{'info'}) {
-		print '<div id="chat">'."\n";
+		print $fh '<div id="chat">'."\n";
+		
+		print_html_data($fh, $frame_data); 
 		
-		print '</div>'."\n";
+		print $fh '</div>'."\n";
 	}
 	elsif ($textmode == TEXT_MODE->{'bb'}) {
+		print $fh '<div id="chat">'."\n";
+		
+		print $fh '[quote][center][size=200]'.$_title.'[/size]<br>'."\n";
+		print $fh '[url='.$_viewer_full_url.'][img]'.$_frame_full_url.'[/img][/url][/center]<br>'."\n";
+		print $fh html_encode_line(bb_to_bbcode(eval_bb($frame_data->{'content'})));
+		print $fh '[/quote]</div>'."\n";
 		
+		print $fh '</div>'."\n";
 	}
 	elsif ($frame_data->{'content'} ne '') {
-		
+		print $fh '<div id="undertext">'."\n";
+		print $fh bb_to_html(eval_bb($frame_data->{'content'}))."\n";
+		print $fh '</div>'."\n";
 	}
 	
+	print $fh '<div id="command">'."\n";
+	# TODO
+	
 	print_html_body_end($fh);
 	print_html_end($fh);
 	
diff --git a/settings-again.txt b/settings-again.txt
index 43b314b..10b67c0 100644
--- a/settings-again.txt
+++ b/settings-again.txt
@@ -73,6 +73,7 @@ reset_schedule: 33 4 * * *
 cron_user: b
 
 
+scheme      : http
 website     : 1190.bicyclesonthemoon.info
 website_name: Bicycles on the Moon
 favicon_path: /img/favicon.png
diff --git a/settings-bsta.txt b/settings-bsta.txt
index ac27eae..e2426f1 100644
--- a/settings-bsta.txt
+++ b/settings-bsta.txt
@@ -73,6 +73,7 @@ reset_schedule: #33 4 * * *
 cron_user: b
 
 
+scheme      : http
 website     : 1190.bicyclesonthemoon.info
 website_name: Bicycles on the Moon
 favicon_path: /img/favicon.png
diff --git a/settings-debug.txt b/settings-debug.txt
index 7a8ed15..ec1a28c 100644
--- a/settings-debug.txt
+++ b/settings-debug.txt
@@ -73,6 +73,7 @@ reset_schedule: #33 4 * * *
 cron_user: b
 
 
+scheme      : http
 website     : 1190.bicyclesonthemoon.info
 website_name: Bicycles on the Moon
 favicon_path: /img/favicon.png
diff --git a/settings-tbst.txt b/settings-tbst.txt
index ca7d30b..2365d73 100644
--- a/settings-tbst.txt
+++ b/settings-tbst.txt
@@ -73,6 +73,7 @@ reset_schedule: #33 4 * * *
 cron_user: b
 
 
+scheme      : http
 website     : 1190.bicyclesonthemoon.info
 website_name: Bicycles on the Moon
 favicon_path: /img/favicon.png
diff --git a/settings.txt b/settings.txt
index d52dee8..f6b4cd0 100644
--- a/settings.txt
+++ b/settings.txt
@@ -168,6 +168,7 @@ PERL_LOG_PATH           = @_PERL_CONSTANT_STR( LOG_PATH, $_log_path)
 PERL_WWW_PATH           = @_PERL_CONSTANT_STR( WWW_PATH      , $_www_path      )
 PERL_WWW_INDEX_PATH     = @_PERL_CONSTANT_STR( WWW_INDEX_PATH, $_www_index_path)
 
+PERL_SCHEME             = @_PERL_CONSTANT_STR( SCHEME      , $scheme://   )
 PERL_WEBSITE            = @_PERL_CONSTANT_STR( WEBSITE     , $website     )
 PERL_WEBSITE_NAME       = @_PERL_CONSTANT_STR( WEBSITE_NAME, $website_name)
 PERL_FAVICON_PATH       = @_PERL_CONSTANT_STR( FAVICON_PATH, $favicon_path)
-- 
2.30.2