From c81296cdea13fac8cec862226ec894722f2e340c Mon Sep 17 00:00:00 2001 From: b Date: Sat, 30 Sep 2023 17:51:27 +0000 Subject: [PATCH] Improve variable name & hash handling, & url_merging in viewer output generator --- bsta_lib.1.pm | 393 +++++++++++--------------------------------------- settings.txt | 2 +- 2 files changed, 86 insertions(+), 309 deletions(-) diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index a91aa68..048c083 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -39,7 +39,7 @@ our @EXPORT_OK = ( 'printdatafileht', # TO REMOVE ??? 'urlencode', # TO REMOVE 'linehtml', # TO REMOVE - 'bb2ht', 'bb2bb' + 'bb2ht', 'bb2bb' # TO REMOVE ); ###PERL_LIB: use lib /botm/lib/bsta @@ -56,264 +56,9 @@ use botm_common ( ###PERL_CGI_LOGO_PATH: CGI_LOGO_PATH = /bsta/botmlogo.png ###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info +###PERL_SCHEME: SCHEME = 1190.bicyclesonthemoon.info -# TO REMOVE -use constant entitycode => { - 'amp' => '&', - 'gt' => '>', - 'lt' => '<', - 'quot' => '"', - 'acute' => '´', - 'cedil' => '¸', - 'circ' => 'ˆ', - 'macr' => '¯', - 'middot' => '·', - 'tilde' => '˜', - 'uml' => '¨', - 'Aacute' => 'Á', - 'aacute' => 'á', - 'Acirc' => 'Â', - 'acirc' => 'â', - 'AElig' => 'Æ', - 'aelig' => 'æ', - 'Agrave' => 'À', - 'agrave' => 'à', - 'Aring' => 'Å', - 'aring' => 'å', - 'Atilde' => 'Ã', - 'atilde' => 'ã', - 'Auml' => 'Ä', - 'auml' => 'ä', - 'Ccedil' => 'Ç', - 'ccedil' => 'ç', - 'Eacute' => 'É', - 'eacute' => 'é', - 'Ecirc' => 'Ê', - 'ecirc' => 'ê', - 'Egrave' => 'È', - 'egrave' => 'è', - 'ETH' => 'Ð', - 'eth' => 'ð', - 'Euml' => 'Ë', - 'euml' => 'ë', - 'Iacute' => 'Í', - 'iacute' => 'í', - 'Icirc' => 'Î', - 'icirc' => 'î', - 'Igrave' => 'Ì', - 'igrave' => 'ì', - 'Iuml' => 'Ï', - 'iuml' => 'ï', - 'Ntilde' => 'Ñ', - 'ntilde' => 'ñ', - 'Oacute' => 'Ó', - 'oacute' => 'ó', - 'Ocirc' => 'Ô', - 'ocirc' => 'ô', - 'OElig' => 'Œ', - 'oelig' => 'œ', - 'Ograve' => 'Ò', - 'ograve' => 'ò', - 'Oslash' => 'Ø', - 'oslash' => 'ø', - 'Otilde' => 'Õ', - 'otilde' => 'õ', - 'Ouml' => 'Ö', - 'ouml' => 'ö', - 'Scaron' => 'Š', - 'scaron' => 'š', - 'szlig' => 'ß', - 'THORN' => 'Þ', - 'thorn' => 'þ', - 'Uacute' => 'Ú', - 'uacute' => 'ú', - 'Ucirc' => 'Û', - 'ucirc' => 'û', - 'Ugrave' => 'Ù', - 'ugrave' => 'ù', - 'Uuml' => 'Ü', - 'uuml' => 'ü', - 'Yacute' => 'Ý', - 'yacute' => 'ý', - 'yuml' => 'ÿ', - 'Yuml' => 'Ÿ', - 'cent' => '¢', - 'curren' => '¤', - 'euro' => '€', - 'pound' => '£', - 'yen' => '¥', - 'brvbar' => '¦', - 'bull' => '•', - 'copy' => '©', - 'dagger' => '†', - 'Dagger' => '‡', - 'frasl' => '⁄', - 'hellip' => '…', - 'iexcl' => '¡', - 'image' => 'ℑ', - 'iquest' => '¿', - 'lrm' => '‎', - 'mdash' => '—', - 'ndash' => '–', - 'not' => '¬', - 'oline' => '‾', - 'ordf' => 'ª', - 'ordm' => 'º', - 'para' => '¶', - 'permil' => '‰', - 'prime' => '′', - 'Prime' => '″', - 'real' => 'ℜ', - 'reg' => '®', - 'rlm' => '‏', - 'sect' => '§', - 'shy' => '­', - 'sup1' => '¹', - 'trade' => '™', - 'weierp' => '℘', - 'bdquo' => '„', - 'laquo' => '«', - 'ldquo' => '“', - 'lsaquo' => '‹', - 'lsquo' => '‘', - 'raquo' => '»', - 'rdquo' => '”', - 'rsaquo' => '›', - 'rsquo' => '’', - 'sbquo' => '‚', - 'emsp' => ' ', - 'ensp' => ' ', - 'nbsp' => ' ', - 'thinsp' => ' ', - 'zwj' => '‍', - 'zwnj' => '‌', - 'deg' => '°', - 'divide' => '÷', - 'frac12' => '½', - 'frac14' => '¼', - 'frac34' => '¾', - 'ge' => '≥', - 'le' => '≤', - 'minus' => '−', - 'sup2' => '²', - 'sup3' => '³', - 'times' => '×', - 'alefsym' => 'ℵ', - 'and' => '∧', - 'ang' => '∠', - 'asymp' => '≈', - 'cap' => '∩', - 'cong' => '≅', - 'cup' => '∪', - 'empty' => '∅', - 'equiv' => '≡', - 'exist' => '∃', - 'fnof' => 'ƒ', - 'forall' => '∀', - 'infin' => '∞', - 'int' => '∫', - 'isin' => '∈', - 'lang' => '⟨', - 'lceil' => '⌈', - 'lfloor' => '⌊', - 'lowast' => '∗', - 'micro' => 'µ', - 'nabla' => '∇', - 'ne' => '≠', - 'ni' => '∋', - 'notin' => '∉', - 'nsub' => '⊄', - 'oplus' => '⊕', - 'or' => '∨', - 'otimes' => '⊗', - 'part' => '∂', - 'perp' => '⊥', - 'plusmn' => '±', - 'prod' => '∏', - 'prop' => '∝', - 'radic' => '√', - 'rang' => '⟩', - 'rceil' => '⌉', - 'rfloor' => '⌋', - 'sdot' => '⋅', - 'sim' => '∼', - 'sub' => '⊂', - 'sube' => '⊆', - 'sum' => '∑', - 'sup' => '⊃', - 'supe' => '⊇', - 'there4' => '∴', - 'Alpha' => 'Α', - 'alpha' => 'α', - 'Beta' => 'Β', - 'beta' => 'β', - 'Chi' => 'Χ', - 'chi' => 'χ', - 'Delta' => 'Δ', - 'delta' => 'δ', - 'Epsilon' => 'Ε', - 'epsilon' => 'ε', - 'Eta' => 'Η', - 'eta' => 'η', - 'Gamma' => 'Γ', - 'gamma' => 'γ', - 'Iota' => 'Ι', - 'iota' => 'ι', - 'Kappa' => 'Κ', - 'kappa' => 'κ', - 'Lambda' => 'Λ', - 'lambda' => 'λ', - 'Mu' => 'Μ', - 'mu' => 'μ', - 'Nu' => 'Ν', - 'nu' => 'ν', - 'Omega' => 'Ω', - 'omega' => 'ω', - 'Omicron' => 'Ο', - 'omicron' => 'ο', - 'Phi' => 'Φ', - 'phi' => 'φ', - 'Pi' => 'Π', - 'pi' => 'π', - 'piv' => 'ϖ', - 'Psi' => 'Ψ', - 'psi' => 'ψ', - 'Rho' => 'Ρ', - 'rho' => 'ρ', - 'Sigma' => 'Σ', - 'sigma' => 'σ', - 'sigmaf' => 'ς', - 'Tau' => 'Τ', - 'tau' => 'τ', - 'Theta' => 'Θ', - 'theta' => 'θ', - 'thetasym' => 'ϑ', - 'upsih' => 'ϒ', - 'Upsilon' => 'Υ', - 'upsilon' => 'υ', - 'Xi' => 'Ξ', - 'xi' => 'ξ', - 'Zeta' => 'Ζ', - 'zeta' => 'ζ', - 'crarr' => '↵', - 'darr' => '↓', - 'dArr' => '⇓', - 'harr' => '↔', - 'hArr' => '⇔', - 'larr' => '←', - 'lArr' => '⇐', - 'rarr' => '→', - 'rArr' => '⇒', - 'uarr' => '↑', - 'uArr' => '⇑', - 'clubs' => '♣', - 'diams' => '♦', - 'hearts' => '♥', - 'spades' => '♠', - 'loz' => '◊', -}; - use constant STATE => { 'inactive' => 0, 'waiting' => 1, @@ -557,7 +302,6 @@ sub printdatafileht { return 1; } - # TO REMOVE sub urlencode { (my $t, my $all) = @_; @@ -929,7 +673,6 @@ sub linehtml { return html_encode_line($_[0], 1); } -# TO REMOVE ??? sub debug { (my $print, my $text) = @_; @@ -995,56 +738,76 @@ sub print_viewer_page { ( my $file, my $frame, - my $password_ok, - my $access, - my $textmode, - my $show_command, + my $context, my $state, my $settings, my $frame_data, - my $nextframe_data + my $next_frame_data ) = @_; my $fh; - my $prev_available = ($frame > 0 && $access); - my $next_available = ($password_ok || ($frame < int($state->{'last'}))); + my $frame = int($context->{'frame'}); + # my $prev_frame = $frame - 1; + my $next_frame = $frame + 1; + + my $access = $context->{'access'}; + my $password_ok = $context->{'password_ok'}; + my $text_mode = $context->{'text_mode'} + + my $last_frame = int($state->{'last'}); + my $ong_state = int($state->{'state'}); + + my $prev_available = (($frame > 0) && $access'); + my $next_available = ($password_ok' || ($next_frame <= $last_frame)); my $prefetch_next = ( $password_ok || - ($frame+1 < int($state->{'last'})) || ( - ($frame < int($state->{'last'})) && - (int($state->{'state'}) >= STATE->{'ready'}) + ($next_frame < $tast_frame) || ( + ($next_frame <= $last_frame) && + ($ong_state >= STATE->{'ready'}) ) ); - my $show_timer = ($password_ok || - ($frame == int($state->{'last'})) && - (int($state->{'state'}) >= STATE->{'waiting'}) && - (int($state->{'state'}) <= STATE->{'ready'}) + my $show_timer = ( + ($frame == $last_frame)) && ( + ($ong_state == STATE->{'waiting'}) || + ($ong_state == STATE->{'ready'}) + ) ); - $show_command = ( - $password_ok || - ($frame < int($state->{'last'})) || - ((int($state{'state'}) >= STATE->{'ready'} ) && $show_command) + my $show_command = ( + $password_ok' || + ($frame' < $last_frame) || ( + ($ong_state) >= STATE->{'ready'}) && + $context->{'show_command'} + ) ); my $frame_indirect = !( (!$access) || ( - ($frame < int($state->{'last'})) && - (int($state->{'state'}) > STATE->{'inactive'}) + ($frame <= $last_frame) && + ($ong_state > STATE->{'inactive'}) ) ); - my $nextframe_indirect = !($frame+1 < int($state{'last'})); + my $nextframe_indirect = !($next_frame < $last_frame); my $password_query; my $goto_url = CGI_GOTO_PATH; my $timer_url = CGI_TIMER_PATH; my $viewer_full_url = merge_url( - SCHEME().WEBSITE(), - CGI_VIEWER_PATH(), - $frame + {'scheme' => SCHEME(), 'host' => WEBSITE()}, + {'path' => CGI_VIEWER_PATH()}, + {'path' => $frame} + ); + my $viewer_0_url = merge_url( + {'path' => CGI_VIEWER_PATH()}, + {'path' => 0} + ); + my $viewer_prev_url = merge_url( + {'path' => CGI_VIEWER_PATH()}, + {'path' => $frame-1} + ); + my $viewer_next_url = merge_url( + {'path' => CGI_VIEWER_PATH()}, + {'path' => $next_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_file = ''; my $frame_url; my $frame_next_url; @@ -1052,42 +815,56 @@ sub print_viewer_page { my $frame_full_url; if ($frame_data->{'frame'} ne '') { $frame_file = $frame_data->{'frame'}; - $frame_normal_url = merge_url(CGI_PATH(), $frame_file); } else { - $frame_file = sprintf($settings->{'frame'}, $frame, $frame_data->{'ext'}); - $frame_normal_url = merge_url(CGI_PATH(), $frame_file); + $frame_file = sprintf( + $settings->{'frame'}, + $frame, $frame_data->{'ext'} + ); } + $frame_normal_url = merge_url( + {'path' => CGI_PATH()}, + {'path' => $frame_file} + ); $frame_url = $frame_indirect ? - merge_url(CGI_FRAME_PATH(), $frame) : + merge_url( + {'path' => CGI_FRAME_PATH()}, + {'path' => $context->{'frame'}} + ) : $frame_normal_url; $frame_full_url = merge_url( - SCHEME().WEBSITE(), - $frame_normal_url + {'scheme' => SCHEME(), 'host' => WEBSITE()}, + {'path' => $frame_normal_url} ); if ($nextframe_indirect) { - $frame_next_url = merge_url(CGI_FRAME_PATH(), $frame); + $frame_next_url = merge_url( + {'path' => CGI_FRAME_PATH()}, + {'path' => $nextframe} + ); } - elsif ($nextframe_data->{'frame'} ne '') { - $frame_next_url = merge_url(CGI_PATH(), $nextframe_data->{'frame'}); + elsif ($next_frame_data->{'frame'} ne '') { + $frame_next_url = merge_url( + {'path' => CGI_PATH()}, + {'path' => $next_frame_data->{'frame'}} + ); } else { $frame_next_url = merge_url(CGI_PATH(), sprintf( - $settings->{'frame'}, $frame+1, $nextframe_data->{'ext'} + $settings->{'frame'}, $next_frame, $next_frame_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); + $password_query = url_query_encode({'p', $settings->{'password'}}); + $goto_url = merge_url($goto_url , {'query' => $password_query}); + $viewer_0_url = merge_url($viewer_0_url , {'query' => $password_query}); + $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query}); + $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query}); if ($frame_indirect) { - $frame_url = merge_url($frame_url , $password_query); + $frame_url = merge_url($frame_url , {'query' => $password_query}); } if ($nextframe_indirect) { - $frame_url = merge_url($frame_next_url, $password_query); + $frame_url = merge_url($frame_next_url, {'query' => $password_query}); } } my $_goto_url = html_entity_encode_dec($goto_url , 1); @@ -1102,11 +879,11 @@ sub print_viewer_page { my $_title = html_entity_encode_dec($framedata->{'title'}, 1); - if ($textmode == TEXT_MODE->{'info'}) { + if ($text_mode == TEXT_MODE->{'info'}) { if ($show_command) { - $frame_data->{'command'} = $nextframe_data->{'title'}; + $frame_data->{'command'} = $next_frame_data->{'title'}; } - if ($access) { + if ($context->{'access'}) { $frame_data->{'frame'} = $frame_file; } } @@ -1157,14 +934,14 @@ sub print_viewer_page { print $fh '
'."\n"; - if ($textmode == TEXT_MODE->{'info'}) { + if ($text_mode == TEXT_MODE->{'info'}) { print $fh '
'."\n"; print_html_data($fh, $frame_data); print $fh '
'."\n"; } - elsif ($textmode == TEXT_MODE->{'bb'}) { + elsif ($text_mode == TEXT_MODE->{'bb'}) { print $fh '
'."\n"; print $fh '[quote][center][size=200]'.$_title.'[/size]
'."\n"; diff --git a/settings.txt b/settings.txt index f6b4cd0..fa9bd98 100644 --- a/settings.txt +++ b/settings.txt @@ -168,7 +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_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