1 # bsta_lib.pm is generated from bsta_lib.1.pm
5 # Copyright (C) 2016, 2017, 2019, 2020, 2022, 2023, 2024 Balthasar Szczepański
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # TODO: BB & INFO indent
31 use Encode ('encode', 'decode');
33 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
35 ###PERL_EXPORT_VERSION: our $VERSION = 'x.x.x';
36 our @ISA = qw(Exporter);
39 'STATE', 'TEXT_MODE', 'INTF_STATE', 'CHAT_STATE', 'CHAT_ACTION',
41 'fail_method', 'fail_content_type', 'fail_open_file', 'fail_attachment', 'fail_500',
43 'get_remote_addr', 'get_id', 'get_frame', 'get_password',
45 'print_html_start', 'print_html_end',
46 'print_html_head_start', 'print_html_head_end',
47 'print_html_body_start', 'print_html_body_end',
48 'print_viewer_page', 'print_goto',
49 'write_index', 'write_static_viewer_page', 'write_static_goto',
51 'eval_bb', 'bb_to_bbcode', 'bb_to_html'
54 ###PERL_LIB: use lib /botm/lib/bsta
57 'url_query_decode', 'url_query_encode',
58 'url_decode', 'url_encode',
59 'html_entity_encode_dec',
62 'read_data_file', 'write_data_file',
64 'copy_encoded', 'open_encoded', '_x_encoded',
65 'http_header_line', 'http_status',
66 'http_header_status', 'http_header_allow', 'http_header_location'
69 ###PERL_PATH_SEPARATOR: PATH_SEPARATOR = /
71 ###PERL_CGI_PATH: CGI_PATH = /bsta/
72 ###PERL_CGI_ATTACH_PATH: CGI_ATTACH_PATH = /bsta/a
73 ###PERL_CGI_2WORDS_PATH: CGI_2WORDS_PATH = /bsta/2words
74 ###PERL_CGI_BBCODE_PATH: CGI_BBCODE_PATH = /bsta/b
75 ###PERL_CGI_COIN_PATH: CGI_COIN_PATH = /bsta/coin
76 ###PERL_CGI_CSS_PATH: CGI_CSS_PATH = /bsta/bsta.css
77 ###PERL_CGI_FRAME_PATH: CGI_FRAME_PATH = /bsta/f
78 ###PERL_CGI_GOTO_PATH: CGI_GOTO_PATH = /bsta/g
79 ###PERL_CGI_INFO_PATH: CGI_INFO_PATH = /bsta/i
80 ###PERL_CGI_LIST_PATH: CGI_LIST_PATH = /bsta/goto.htm
81 ###PERL_CGI_LOGO_PATH: CGI_LOGO_PATH = /bsta/botmlogo.png
82 ###PERL_CGI_TIMER_PATH: CGI_TIMER_PATH = /bsta/timer.js
83 ###PERL_CGI_VIEWER_PATH: CGI_VIEWER_PATH = /bsta/v
84 ###PERL_CGI_WORDS_PATH: CGI_WORDS_PATH = /bsta/w
86 ###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta/
87 ###PERL_DATA_ATTACH_PATH: DATA_ATTACH_PATH = /botm/data/bsta/a
88 ###PERL_DATA_COIN_PATH: DATA_COIN_PATH = /botm/data/bsta/coincidence
89 ###PERL_DATA_DEFAULT_PATH: DATA_DEFAULT_PATH = /botm/data/bsta/default
90 ###PERL_DATA_LIST_PATH: DATA_LIST_PATH = /botm/data/bsta/list
91 ###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
92 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
93 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
94 ###PERL_DATA_WORDS_PATH: DATA_WORDS_PATH = /botm/data/bsta/words/
96 ###PERL_WWW_PATH: WWW_PATH = /botm/www/
97 ###PERL_WWW_GOTO_PATH: WWW_GOTO_PATH = /botm/www/1190/bsta/goto.htm
98 ###PERL_WWW_INDEX_PATH: WWW_INDEX_PATH = /botm/www/1190/bsta/index.htm
100 ###PERL_SCHEME: SCHEME = http
101 ###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info
102 ###PERL_WEBSITE_NAME: WEBSITE_NAME = Bicycles on the Moon
103 ###PERL_FAVICON_PATH: FAVICON_PATH = /img/favicon.png
105 ###PERL_COIN_DATE: COIN_DATE = 13-Nov-2016 22:15
106 ###PERL_INTF_DATE: INTF_DATE = 28-Sep-2016 20:34
108 ###PERL_STORY_CREDITS: STORY_CREDITS = "BSTA" by Balthasar Szczepański
109 ###PERL_INTF_CREDITS: INTF_CREDITS = Online interface © Balthasar Szczepański; AGPL 3 license
110 ###PERL_SOURCE_URL: SOURCE_URL = http://bicyclesonthemoon.info/git-projects/?p=ott/bsta
112 ###PERL_COMMENT_PAGE_LENGTH:COMMENT_PAGE_LENGTH= 16
114 use constant STATE => {
120 use constant INTF_STATE => {
133 use constant TEXT_MODE => {
139 use constant CHAT_STATE => {
144 use constant CHAT_ACTION => {
152 use constant tags_bbcode => {
159 'quote' => '[quote]',
160 'quote=' => '[quote="',
162 '/quote' => '[/quote]',
163 'ni' => '[color=#0057AF]',
165 'br' => '[color=#BB6622]',
167 'po' => '[color=#FF8800]',
178 '/list' => '[/list]',
182 '/?' => '[/unknown!]',
184 use constant tags_html => {
187 'fq' => '<div class="fq">',
189 'tq' => '<div class="tq">',
191 'quote' => '<div class="opomba"><div class="opomba_text">',
192 'quote=' => '<div class="opomba"><div class="opomba_info"><b>',
193 'quote/='=> '</b> wrote:</div><div class="opomba_text">',
194 '/quote' => '</div></div>',
195 'ni' => '<span class="ni">',
197 'br' => '<span class="br">',
199 'po' => '<span class="po">',
201 'url' => '<a href="#">',#think: how to add selfincluding?
202 'url=' => '<a href="',
208 'list=' => '<ol style="list-style-type: ',
209 'list=1' => 'decimal',
210 'list=A' => 'upper-alpha',
211 'list=a' => 'lower-alpha',
212 'list=I' => 'upper-roman',
213 'list=i' => 'lower-roman',
220 '/?' => '[/unknown!]',
224 # Function to return an error page
225 # arguments: 1 - header fields, 2 - page title, 3 - error message, 4 method
227 (my $header, my $title, my $message, my $method, my $hyperlink) = @_;
230 foreach my $header_name (keys %$header) {
231 print http_header_line($header_name, $header->{$header_name});
234 elsif($header ne '') {
237 if($method eq 'HEAD') {
241 my $_title = html_entity_encode_dec($title , 1);
242 my $_message = html_entity_encode_dec($message , 1);
243 my $_hyperlink = html_entity_encode_dec($hyperlink, 1);
245 print "Content-type: text/html; charset=UTF-8\n\n";
247 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
248 print ' <html lang="en">'."\n";
249 print ' <head>'."\n";
250 print ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
252 print ' <title>'.$_title.'</title>'."\n";
254 print ' </head>'."\n";
255 print ' <body>'."\n";
257 print ' <h1>'.$_title.'</h1>'."\n";
259 if (($message ne '') || ($hyperlink ne '')) {
261 if ($message ne '') {
262 print ' '.$_message.($hyperlink ne '' ? '<br>' : '')."\n";
264 if ($hyperlink ne '') {
265 print ' <a href="'.$_hyperlink.'">'.$_hyperlink."</a>\n";
269 print ' </body>'."\n";
270 print '</html>'."\n";
274 (my $method, my $allowed) = @_;
276 my $status = http_status(HTTP_STATUS->{'method_not_allowed'});
278 http_header_line('status', $status) .
279 http_header_allow($allowed);
284 "The interface does not support the $method method.",
289 sub fail_content_type
291 (my $method, my $content_type) = @_;
293 my $status = http_status(HTTP_STATUS->{'unsupported_media_type'});
294 my $header = http_header_line('status', $status);
299 "Unsupported Content-type: $content_type.",
306 (my $method, my $type, my $path) = @_;
308 my $status = http_status(HTTP_STATUS->{'not_found'});
309 my $header = http_header_line('status', $status);
315 ($type ne '' ? $type : 'file').
316 ($path ne '' ? ': "'.$path.'"' : '').
324 (my $method, my $ID) = @_;
326 my $status = http_status(HTTP_STATUS->{'not_found'});
327 my $header = http_header_line('status', $status);
332 "Attachment $ID not found.",
339 (my $method, my $text) = @_;
341 my $status = http_status(HTTP_STATUS->{'internal_server_error'});
342 my $header = http_header_line('status', $status);
354 (my $method, my $uri, my $code) = @_;
358 $code = HTTP_STATUS->{'found'};
360 # https://insanecoding.blogspot.com/2014/02/http-308-incompetence-expected.html
361 # 301 Moved Permanently
364 # 307 Temporary Redirect
365 # 308 Permanent Redirect
366 $status = http_status($code);
367 $header = http_header_line('status', $status);
368 $header .= http_header_location($uri);
380 # function to obtain address of remote agent
381 sub get_remote_addr {
382 if ($ENV{'HTTP_X_FORWARDED_FOR'} =~ /^.+$/) {
385 elsif ($ENV{'REMOTE_ADDR'} =~ /^.+$/) {
393 # functions to get ID/number etc.
395 (my $cgi, my $default, my $cgi_name) = @_;
396 if ($default eq '') {
399 if ($cgi_name eq '') {
403 if ($cgi->{$cgi_name} =~ /^.+$/) {
406 elsif ($ENV{'PATH_INFO'} =~ /^\/(.+)$/) {
410 return int($default);
414 # function to obtain frame number
416 (my $cgi, my $default) = @_;
417 return get_id($cgi, $default, 'f');
420 # function to obtain password
424 if ($cgi->{'p'} =~ /^.+$/) {
436 foreach my $settings (@_) {
437 foreach my $ind (keys %$settings) {
438 $final_settings{$ind} = $settings->{$ind};
441 return %final_settings;
446 # different & simpler implementation than in post library
450 #analyse bbcode text to build tag tree
451 #TODO make [/*] optional!
453 (my $bb, my $printdebug) = @_;
466 $bbtree{"_.name" } = "ht";
467 $bbtree{"_.value" } = '';
468 $bbtree{"_.type" } = "tag";
469 $bbtree{"_.count" } = 0;
470 $bbtree{"_.closed"} = 0;
471 $debug .= debug($printdebug,
473 "<!--GENERATING BBCODE TREE:\n".
474 '[_]automatic tag: [ht]'."\n"
478 my $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
480 if($bb =~ m/\[(\/?)([A-Za-z]+|\*)(=([^\[\]]*))?\]/g) {
487 if ($tag_value =~ /^"(.*)"$/) {
491 if ($pre_text ne '') {
492 $debug .= debug($printdebug, "[$new_ind]text: $pre_text\n");
493 $bbtree{$new_ind.'.type' } = 'text';
494 $bbtree{$new_ind.'.value'} = $pre_text;
495 $bbtree{ $ind.'.count'}+= 1;
496 $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
499 if($tag_name =~ /^(fq|tq|quote|br|ni|po|url|i|list|\*)$/) {
500 if ($tag_end ne '') {
502 ($tag_name ne $bbtree{$ind.'.name'}) ||
505 $debug .= debug($printdebug, "[$new_ind]text: $tag\n");
506 $bbtree{$new_ind.'.type' } = 'text';
507 $bbtree{$new_ind.'.value'} = $tag;
508 $bbtree{ $ind.'.count'}+= 1;
509 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
512 $debug .= debug($printdebug, "[$new_ind]tag: $tag\n");
513 $bbtree{$new_ind.'.type' } = 'tag';
514 $bbtree{$new_ind.'.name' } = '/'.$tag_name;
515 $bbtree{$new_ind.'.value' } = $tag_value;
516 $bbtree{ $ind.'.count' }+= 1;
517 $bbtree{ $ind.'.closed'} = 1;
519 $ind =~ s/\.[0-9]+$//;
520 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
525 $debug .= debug($printdebug, "[$new_ind]tag: $tag\n");
526 $bbtree{$new_ind.'.type' } = 'tag';
527 $bbtree{$new_ind.'.name' } = $tag_name;
528 $bbtree{$new_ind.'.value' } = $tag_value;
529 $bbtree{$new_ind.'.count' } = 0;
530 $bbtree{$new_ind.'.closed'} = 0;
531 $bbtree{ $ind.'.count' }+= 1;
534 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
538 $debug .= debug($printdebug, "[$new_ind]text: $tag\n");
539 $bbtree{$new_ind.'.type' } = 'text';
540 $bbtree{$new_ind.'.value'} = $tag;
541 $bbtree{ $ind.'.count'}+= 1;
542 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
546 $debug .= debug($printdebug, "[$new_ind]text: $bb\n");
547 $bbtree{$new_ind.'.type' } = 'text';
548 $bbtree{$new_ind.'.value'} = $bb;
549 $bbtree{ $ind.'.count'}+= 1;
550 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
554 my $final_ind = '_.'.$bbtree{"_.count"};
555 $debug .= debug($printdebug, "[$final_ind]automatic tag: [/ht]\n -->\n");
556 $bbtree{$final_ind.'.type' } = "tag";
557 $bbtree{$final_ind.'.name' } = '/ht';
558 $bbtree{ '_.count' }+= 1;
559 $bbtree{ '_.closed'} = 1;
561 return ($debug, %bbtree);
564 #convert tag tree to final text
566 (my $printdebug, my $debug, my $lang, my $bbtree) = @_;
571 my $tags = ($lang eq 'html') ? tags_html : tags_bbcode;
572 my $escape = ($lang eq 'html');
574 # $debug .= debug($printdebug, "\n****\n");
575 # foreach my $iiii (keys %tags) {
576 # $debug .= debug($printdebug, $iiii.'='.$tags->{$iiii}."\n");
578 # $debug .= debug($printdebug, "****\n");
583 $debug .= debug($printdebug, "\n<!--PROCESSING BBCODE TREE:\n");
585 while ($level >= 0) {
587 $debug .= debug($printdebug, "[$level:$ind:".int($bbtree->{$ind.'.count'})."]");
589 if ($bbtree->{$ind.'.type'} eq 'text') {
590 my $text = $bbtree->{$ind.'.value'};
591 $debug .= debug($printdebug, "text: ".$text);
592 $out .= $escape ? html_encode_line($text) : $text;
597 elsif ($bbtree->{$ind.'.type'} eq 'tag') {
598 my $name = $bbtree->{$ind.'.name'};
600 if ($name =~ /^\//) {
601 $debug .= debug($printdebug, "tag: [$name]");
603 $indd =~ s/\.([0-9]+)$//;
604 if (exists($tags->{$name.'='}) && ($bbtree->{$indd.'.value'} ne '')) {
605 $out .= $tags->{$name.'='};
607 elsif (exists($tags->{$name})) {
608 $out .= $tags->{$name};
611 $out .= $tags->{'/?'};
612 $debug .= debug($printdebug, "[unknown!]");
615 $ind =~ s/\.([0-9]+)$//;
617 $debug .= debug($printdebug, "[<]");
628 my $value = $bbtree->{$ind.'.value'};
629 if($bbtree->{$ind.'.closed'} ne '') {
630 $debug .= debug($printdebug, "tag: [$name]");
632 if (exists($tags->{$name.'='}) && ($value ne '')) {
633 if (exists($tags->{$name.'='.$value})) {
636 $tags->{$name.'='.$value} .
642 ($escape ? html_entity_encode_dec($value, 1) : $value) .
646 elsif (exists($tags->{$name})) {
647 $out .= $tags->{$name};
650 $out .= $out.$tags->{'?'};
651 $debug .= debug($printdebug, "[unknown!]");
655 $debug .= debug($printdebug, "unclosed tag: [$name]");
656 my $text = $name . (($value ne '') ? ('='.$value) : '');
657 $out .= '['.($escape ? html_encode_line($text) : $text).']';
659 if ($bbtree->{$ind.'.count'} > 0) {
662 $debug .= debug($printdebug, "[>]");
671 $debug .= debug($printdebug, "unknown thing: ".$bbtree->{$ind.'.type'});
672 #should not occur with a correct bbtree
673 #unless unimplemented
674 $ind =~ s/\.([0-9]+)$//;
676 $debug .= debug($printdebug, "[<ui]");
685 if ($goto_next ne '') {
687 $ind =~ s/\.([0-9]+)$//;
689 if (($i < $bbtree->{$ind.'.count'}) and ($1 ne '')){
696 # should not occur with a correct bbtree
697 $debug .= debug($printdebug, "[<$goto_next]");
700 } while ($level >= 0);}
703 $debug .= debug($printdebug, "[>$level:$ind]\n");
706 $debug .= debug($printdebug, "-->\n");
707 return ($debug, $out);
712 (my $bb, my $printdebug) = @_;
717 ($debug, %bbtree) = bbtree($bb, $printdebug);
718 ($debug, $ht) = convtree ($printdebug, $debug, 'html', \%bbtree);
725 (my $bb, my $printdebug) = @_;
730 ($debug, %bbtree) = bbtree($bb, $printdebug);
731 ($debug, $ht) = convtree ($printdebug, $debug, 'bb', \%bbtree);
737 (my $bb, my $full_url, my $password) = @_;
742 my $base_url = $full_url ?
743 {'scheme' => SCHEME(), 'host' => WEBSITE()} :
746 while ($bb =~ m/###([^#;]*);/g) {
751 if ($value =~ /^att&([0-9]+)$/) {
754 {'path' => CGI_ATTACH_PATH()},
758 elsif ($value =~ /^vw&([0-9]+)$/) {
761 {'path' => CGI_VIEWER_PATH()},
765 elsif ($value =~ /^fr&([0-9]+)$/) {
768 {'path' => CGI_FRAME_PATH()},
775 if (($value ne '') && ($password ne '')) {
778 {'query' => {'p' => $password}}
781 $bb = $before . $value . $after;
787 sub html_encode_line {
788 (my $text, my $non_ascii, my $all) = @_;
792 $text =~ s/\r\n/\n/gs;
795 while ($text ne '') {
796 $ind = index($text, "\n");
798 $html .= html_entity_encode_dec(substr($text, 0, $ind), $non_ascii, $all)."<br>\n";
799 $text = substr($text, $ind+1);
803 $html .= html_entity_encode_dec($text, 1);
811 (my $print, my $text) = @_;
821 sub print_html_start {
823 print $fh '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
824 print $fh '<html lang="en">'."\n";
829 print $fh '</html>'."\n";
832 sub print_html_head_start {
834 print $fh ' <head>'."\n";
835 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
836 print $fh ' <link rel="icon" type="image/png" href="'.html_entity_encode_dec(FAVICON_PATH(),1).'">'."\n";
837 print $fh ' <link rel="stylesheet" href="'.html_entity_encode_dec(CGI_CSS_PATH(),1).'">'."\n";
840 sub print_html_head_end {
842 print $fh ' </head>'."\n";
845 sub print_html_body_start {
847 print $fh ' <body>'."\n";
848 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";
849 print $fh ' <div id="all">'."\n";
852 sub print_html_body_end {
853 (my $fh, my $hide_credits) = @_;
854 print $fh ' </div>'."\n";
855 unless ($hide_credits) {
856 print $fh ' <p>'."\n";
857 print $fh ' '.html_entity_encode_dec(STORY_CREDITS(),1).'<br>'."\n";
858 print $fh ' '.html_entity_encode_dec(INTF_CREDITS(),1).'<br>'."\n";
859 print $fh ' <a href="'.html_entity_encode_dec(SOURCE_URL(),1).'" class="cz">source code</a>'."\n";
860 print $fh ' </p>'."\n";
862 print $fh ' <a href="/" class="cz">'.html_entity_encode_dec(WEBSITE(),1).'</a>'."\n";
863 print $fh ' </body>'."\n";
866 sub print_html_data {
867 (my $fh, my $data) = @_;
869 foreach my $key (keys %$data) {
870 unless ($key eq 'content') {
871 my $val = $data->{$key};
872 $val =~ s/(\r)?\n/\n /gs; # does the space make sense in HTML anyway?
873 print $fh html_encode_line("$key: $val\n", 1);
876 print $fh html_encode_line("\n".$data->{'content'});
893 $last_frame = int($state->{'last'});
894 $ong_state = int($state->{'state'});
895 $password_query = url_query_encode({'p', $settings->{'password'}});
897 my $_title = html_entity_encode_dec($settings->{'story'}, 1);
898 my $_website_name = html_entity_encode_dec(WEBSITE_NAME() , 1);
899 my $_base_url = html_entity_encode_dec(CGI_PATH() , 1);
903 unless (seek($fh, 0, 0)) {
904 #don't actually fail here
908 unless (open_encoded($fh, ">:encoding(UTF-8)", $file)) {
913 print_html_start($fh);
914 print_html_head_start($fh);
916 print $fh ' <title>GOTO • '.$_title.' • '.$_website_name.'</title>'."\n";
918 print_html_head_end($fh);
919 print_html_body_start($fh);
921 print $fh ' <div id="inst" class="ins">'."\n";
923 print $fh ' <div id="title">'."\n";
924 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
925 print $fh ' </div>'."\n";
927 print $fh ' </div>'."\n";
928 print $fh ' <div id="insb" class="ins">'."\n";
930 print $fh ' <div id="chat">'."\n";
932 for (my $frame = 0; ; $frame += 1) {
935 ($frame <= $last_frame) &&
936 ($ong_state >= STATE->{'waiting'})
949 $ongtime = $goto_list->{'ongtime-'.$frame};
950 $title = $goto_list->{'title-' .$frame};
951 if (($ongtime eq '') && ($title eq '')) {
952 my $frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
953 my %frame_data = read_data_file($frame_data_path);
954 $ongtime = $frame_data{'ongtime'};
955 $title = $frame_data{'title'};
956 unless (keys %frame_data) {
961 if ($ongtime ne '') {
962 @time_tab = gmtime($ongtime);
963 $time_text = sprintf(
964 '%02d.%02d.%02d %02d:%02d',
973 $time_text = (($frame <= $last_frame) && ($ong_state >= STATE->{'waiting'})) ?
974 'EE.EE.EE EE:EE' : '--.--.-- --:--';
979 $timer_color = (($frame > $last_frame) || ($ong_state < STATE->{'waiting'})) ?
981 (($frame == $last_frame) && ($ong_state < STATE->{'ready'})) ?
984 $frame_text = sprintf('%03d',$frame);
985 $viewer_url = merge_url(
986 {'path' => CGI_VIEWER_PATH()},
988 ); # TODO: consider static here?
990 $viewer_url = merge_url($viewer_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
993 my $_viewer_url = html_entity_encode_dec($viewer_url, 1);
994 my $_title = html_entity_encode_dec($title , 1);
996 print $fh ' <span class="'.$timer_color.'">'.$frame_text.'</span> '.$time_text.' <a href="'.$_viewer_url.'">'.$_title.'</a><br>'."\n";
998 print $fh ' </div>'."\n";
1000 print $fh ' <div id="underlinks">'."\n";
1001 print $fh ' <a href="'.$_base_url.'">BSTA</a>'."\n";
1002 print $fh ' </div>'."\n";
1004 print $fh ' </div>'."\n";
1006 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1007 print_html_end($fh);
1009 unless (ref($file)) {
1013 truncate ($fh , tell($fh));
1019 sub print_viewer_page {
1026 my $prev_frame_data,
1027 my $next_frame_data,
1032 my $launch = $context->{'launch'};
1033 my $access = $context->{'access'};
1034 my $password_ok = $context->{'password_ok'};
1035 my $static = $context->{'static'};
1037 my $frame = int($context->{'frame'});
1038 my $text_mode = int($context->{'text_mode'});
1039 my $timer_unlocked = int($context->{'timer_unlocked'});
1040 my $timer = int($context->{'timer'});
1041 # my $words_page = int($context->{'words_page'});
1043 my $prev_frame = $frame - 1;
1044 my $next_frame = $frame + 1;
1046 my $story = $settings->{'story'};
1047 my $title = $frame_data->{'title'};
1048 my $command = ($frame_data->{'command'} ne '') ?
1049 $frame_data->{'command'} :
1050 $next_frame_data->{'title'};
1052 my $last_frame = int($state->{'last'});
1053 my $ong_state = int($state->{'state'});
1055 my $width = int($frame_data->{'width'});
1056 my $height = int($frame_data->{'height'});
1057 my $frame_type = $frame_data->{'frametype'};
1059 my $timer_color_h = (($timer_unlocked >= 1) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
1060 my $timer_color_m = (($timer_unlocked >= 2) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
1061 my $timer_color_s = (($timer_unlocked >= 3) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
1068 (($timer >= 0) && ($frame == 0))
1070 $timer_s = sprintf('%02d', $timer % 60);
1071 $timer_h = int($timer / 60);
1072 $timer_m = sprintf('%02d', $timer_h % 60);
1073 $timer_h = sprintf('%02d', $timer_h / 60);
1075 elsif (($timer >= -15) && ($ong_state >= STATE->{'ready'})) {
1086 my $words_posts = int($words_data->{'posts'});
1087 my $words_link_text = 'Words'.(($words_posts > 0) ? "[$words_posts]" : '');
1089 my $prev_available = (($frame > 0) && $access);
1090 my $next_available = ($launch || $password_ok || ($next_frame <= $last_frame));
1091 my $prefetch_prev = (
1093 ($prev_frame < $last_frame) || ( # avoid unseen trigger!
1094 ($prev_frame <= $last_frame) &&
1095 ($ong_state >= STATE->{'ready'})
1098 my $prefetch_next = (
1100 ($next_frame < $last_frame) || ( # avoid unseen trigger!
1101 ($next_frame <= $last_frame) &&
1102 ($ong_state >= STATE->{'ready'})
1109 ($frame == $last_frame) && (
1110 ($ong_state == STATE->{'waiting'}) ||
1111 ($ong_state == STATE->{'ready'})
1115 my $show_command = (
1119 ($frame < $last_frame) || (
1120 ($ong_state >= STATE->{'ready'}) &&
1121 $context->{'show_command'}
1124 my $show_command_link = ($next_available || (!$access));
1125 my $show_command_cursor = ((!$next_available) || ($command eq ''));
1126 my $show_words = ($password_ok || ($access && !$launch));
1128 my $frame_indirect = !(
1130 ($frame <= $last_frame) &&
1131 ($ong_state > STATE->{'inactive'})
1134 my $prevframe_indirect = !($prev_frame <= $last_frame);
1135 my $nextframe_indirect = !($next_frame <= $last_frame);
1139 my $base_url = CGI_PATH();
1140 my $goto_url = CGI_GOTO_PATH();
1141 my $timer_url = CGI_TIMER_PATH();
1142 my $viewer_full_url = merge_url(
1143 {'scheme' => SCHEME(), 'host' => WEBSITE()},
1144 {'path' => CGI_VIEWER_PATH()},
1147 my $viewer_url = merge_url(
1148 {'path' => CGI_VIEWER_PATH()},
1151 my $viewer_0_url = merge_url(
1152 {'path' => CGI_VIEWER_PATH()},
1155 my $viewer_prev_url = merge_url(
1156 {'path' => CGI_VIEWER_PATH()},
1157 {'path' => $prev_frame}
1159 my $viewer_next_url = merge_url(
1160 {'path' => CGI_VIEWER_PATH()},
1161 {'path' => $next_frame}
1163 my $viewer_last_url = merge_url(
1164 {'path' => CGI_VIEWER_PATH()},
1165 {'path' => ($static ? -1 : $last_frame)}
1167 unless ($password_ok) {
1169 $viewer_0_url = $base_url;
1170 if ($prev_frame == 0) {
1171 $viewer_prev_url = $viewer_0_url;
1174 if ($prev_frame_data->{'page'} ne '') {
1175 $page_file = $prev_frame_data->{'page'};
1178 $page_file = sprintf(
1179 $settings->{'frame'},
1183 if (_x_encoded('-f',
1184 join_path(PATH_SEPARATOR(), WWW_PATH() , $page_file)
1186 $viewer_prev_url = merge_url(
1187 {'path' => $base_url},
1188 {'path' => $page_file}
1192 if ($next_frame < $last_frame) {
1193 if ($next_frame_data->{'page'} ne '') {
1194 $page_file = $next_frame_data->{'page'};
1197 $page_file = sprintf(
1198 $settings->{'frame'},
1202 if (_x_encoded('-f',
1203 join_path(PATH_SEPARATOR(), WWW_PATH() , $page_file)
1205 $viewer_next_url = merge_url(
1206 {'path' => $base_url},
1207 {'path' => $page_file}
1211 if (_x_encoded('-f',WWW_GOTO_PATH())) {
1212 $goto_url = CGI_LIST_PATH();
1215 my $bbcode_url = ($text_mode == TEXT_MODE->{'bb'}) ?
1217 {'path' => CGI_BBCODE_PATH()},
1224 'b' => TEXT_MODE->{'bb'}
1229 my $info_url = ($text_mode == TEXT_MODE->{'info'}) ?
1231 {'path' => CGI_INFO_PATH()},
1238 'b' => TEXT_MODE->{'info'}
1243 my $words_url = merge_url (
1247 'b' => TEXT_MODE->{'words'}
1256 my $frame_normal_url;
1258 if ($frame_data->{'frame'} ne '') {
1259 $frame_file = $frame_data->{'frame'};
1262 $frame_file = sprintf(
1263 $settings->{'frame'},
1264 $frame, $frame_data->{'ext'}
1267 $frame_normal_url = merge_url(
1268 {'path' => CGI_PATH()},
1269 {'path' => $frame_file}
1271 $frame_url = $frame_indirect ?
1273 {'path' => CGI_FRAME_PATH()},
1277 $frame_full_url = merge_url(
1278 {'scheme' => SCHEME(), 'host' => WEBSITE()},
1279 {'path' => $frame_normal_url}
1281 if ($prevframe_indirect) {
1282 $frame_prev_url = merge_url(
1283 {'path' => CGI_FRAME_PATH()},
1284 {'path' => $prev_frame}
1287 elsif ($prev_frame_data->{'frame'} ne '') {
1288 $frame_prev_url = merge_url(
1289 {'path' => CGI_PATH()},
1290 {'path' => $prev_frame_data->{'frame'}}
1294 $frame_prev_url = merge_url(CGI_PATH(), sprintf(
1295 $settings->{'frame'}, $prev_frame, $prev_frame_data->{'ext'}
1298 if ($nextframe_indirect) {
1299 $frame_next_url = merge_url(
1300 {'path' => CGI_FRAME_PATH()},
1301 {'path' => $next_frame}
1304 elsif ($next_frame_data->{'frame'} ne '') {
1305 $frame_next_url = merge_url(
1306 {'path' => CGI_PATH()},
1307 {'path' => $next_frame_data->{'frame'}}
1311 $frame_next_url = merge_url(CGI_PATH(), sprintf(
1312 $settings->{'frame'}, $next_frame, $next_frame_data->{'ext'}
1317 $password_query = url_query_encode({'p', $settings->{'password'}});
1318 $goto_url = merge_url($goto_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1319 $info_url = merge_url($info_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1320 $words_url = merge_url($words_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1321 $bbcode_url = merge_url($bbcode_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1322 $viewer_url = merge_url($viewer_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1323 $viewer_0_url = merge_url($viewer_0_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1324 $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1325 $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1326 $viewer_last_url = merge_url($viewer_last_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1327 if ($frame_indirect) {
1328 $frame_url = merge_url($frame_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1330 if ($prevframe_indirect) {
1331 $frame_prev_url= merge_url($frame_prev_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1333 if ($nextframe_indirect) {
1334 $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1337 my $_base_url = html_entity_encode_dec($base_url , 1);
1338 my $_goto_url = html_entity_encode_dec($goto_url , 1);
1339 my $_info_url = html_entity_encode_dec($info_url , 1);
1340 my $_words_url = html_entity_encode_dec($words_url , 1);
1341 my $_bbcode_url = html_entity_encode_dec($bbcode_url , 1);
1342 my $_timer_url = html_entity_encode_dec($timer_url , 1);
1343 my $_viewer_full_url = html_entity_encode_dec($viewer_full_url, 1);
1344 my $_viewer_url = html_entity_encode_dec($viewer_url , 1);
1345 my $_viewer_0_url = html_entity_encode_dec($viewer_0_url , 1);
1346 my $_viewer_prev_url = html_entity_encode_dec($viewer_prev_url, 1);
1347 my $_viewer_next_url = html_entity_encode_dec($viewer_next_url, 1);
1348 my $_viewer_last_url = html_entity_encode_dec($viewer_last_url, 1);
1349 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1350 my $_frame_prev_url = html_entity_encode_dec($frame_prev_url , 1);
1351 my $_frame_next_url = html_entity_encode_dec($frame_next_url , 1);
1352 my $_frame_full_url = html_entity_encode_dec($frame_full_url , 1);
1354 my $_story = html_entity_encode_dec($story , 1);
1355 my $_title = html_entity_encode_dec($title , 1);
1356 my $_command = html_entity_encode_dec($command , 1);
1357 my $_frame_type = html_entity_encode_dec($frame_type, 1);
1359 my $_website_name = html_entity_encode_dec(WEBSITE_NAME(), 1);
1361 if ($text_mode == TEXT_MODE->{'info'}) {
1362 if ($show_command) {
1363 $frame_data->{'command'} = $command;
1366 $frame_data->{'frame'} = $frame_file;
1368 if ($frame_data->{'page'} eq '') {
1369 unless (($access) && ($frame < $last_frame)) {
1370 $frame_data->{'page'} = '';
1372 elsif ($frame == 0) {
1373 $frame_data->{'page'} = 'index.htm';
1376 $frame_data->{'page'} = sprintf(
1377 $settings->{'frame'},
1384 # everything determined, now start generating
1388 unless (seek($fh, 0, 0)) {
1389 #don't actually fail here
1393 unless (open_encoded($fh, ">:encoding(UTF-8)", $file)) {
1398 print_html_start($fh);
1399 print_html_head_start($fh);
1401 print $fh ' <title>'.$_title;
1402 if ($story ne $title) {
1403 print $fh ' • '.$_story;
1405 print $fh ' • '.$_website_name.'</title>'."\n";
1406 print $fh ' <link rel="index" href="'.$_goto_url.'">'."\n";
1407 print $fh ' <link rel="start" href="'.$_viewer_0_url.'">'."\n";
1408 if ($prev_available) {
1409 print $fh ' <link rel="prev" href="'.$_viewer_prev_url.'">'."\n";
1410 if ($prefetch_prev) {
1411 print $fh ' <link rel="prefetch" href="'.$_viewer_prev_url.'">'."\n";
1412 print $fh ' <link rel="prefetch" href="'.$_frame_prev_url.'">'."\n";
1415 if ($next_available) {
1416 print $fh ' <link rel="next" href="'.$_viewer_next_url.'">'."\n";
1417 if ($prefetch_next) {
1418 print $fh ' <link rel="prefetch" href="'.$_viewer_next_url.'">'."\n";
1419 print $fh ' <link rel="prefetch" href="'.$_frame_next_url.'">'."\n";
1423 print $fh ' <script src="'.$_timer_url.'"></script>'."\n";
1426 print_html_head_end($fh);
1427 print_html_body_start($fh);
1429 print $fh ' <div id="inst" class="ins">'."\n";
1431 print $fh ' <div id="title">'."\n";
1432 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1433 print $fh ' </div>'."\n";
1435 print $fh ' </div>'."\n";
1436 print $fh ' <div id="framespace">'."\n";
1438 print $fh ' <img src="'.$_frame_url.'" id="frame" class="'.$_frame_type.'" alt="'.$frame.'" title="'.$_title.'" width="'.$width.'" height="'.$height.'">'."\n";
1440 print $fh ' </div>'."\n";
1441 print $fh ' <div id="insb" class="ins">'."\n";
1443 if ($text_mode == TEXT_MODE->{'info'}) {
1444 print $fh ' <div id="chat">'."\n";
1446 print_html_data($fh, $frame_data);
1448 print $fh ' </div>'."\n";
1450 elsif ($text_mode == TEXT_MODE->{'bb'}) {
1451 print $fh ' <div id="chat">'."\n";
1453 print $fh '[quote][center][size=200]'.$_title.'[/size]<br>'."\n";
1454 print $fh '[url='.$_viewer_full_url.'][img]'.$_frame_full_url.'[/img][/url][/center]<br>'."\n";
1455 print $fh html_encode_line(
1458 $frame_data->{'content'},
1463 print $fh '[/quote]'."\n";
1465 print $fh ' </div>'."\n";
1467 elsif ($frame_data->{'content'} ne '') {
1468 print $fh ' <div id="undertext">'."\n";
1469 print $fh bb_to_html(
1471 $frame_data->{'content'},
1473 $password_ok ? $settings->{'password'} : ''
1476 print $fh ' </div>'."\n";
1479 print $fh ' <div id="command">'."\n";
1482 print $fh ' <span id="timer">';
1483 print $fh '[<span id="ongh" class="hv '.$timer_color_h.'">'.$timer_h.'</span>';
1484 print $fh ':<span id="ongm" class="hv '.$timer_color_m.'">'.$timer_m.'</span>';
1485 print $fh ':<span id="ongs" class="hv '.$timer_color_s.'">'.$timer_s.'</span>]';
1486 print $fh '</span><br>'."\n";
1489 if ($show_command_link) {
1490 print $fh '<a href="'.($access ? $_viewer_next_url : $_viewer_last_url).'">';
1492 if ($show_command) {
1493 print $fh $_command;
1495 if ($show_command_cursor) {
1496 print $fh '<span class="inp">_</span>';
1498 if ($show_command_link) {
1502 print $fh " </div>\n";
1504 print $fh ' <div id="underlinks">'."\n ";
1506 unless (($frame == 0) && $static) {
1507 print $fh '<a href="'.$_base_url.'">Once again</a> | ';
1509 if ($prev_available) {
1510 print $fh '<a href="'.$_viewer_prev_url.'">Before</a> | ';
1512 unless ($frame == $last_frame) {
1513 print $fh '<a href="'.$_viewer_last_url.'">Now</a> | ';
1515 print $fh '<a href="'.$_goto_url.'">GOTO</a>'."\n";
1516 print $fh ' <span style="float: right;">'."\n ";
1517 if ($text_mode == TEXT_MODE->{'normal'}) {
1519 print $fh '<a href="'.$_words_url.'">'.$words_link_text.'</a> | ';
1523 print $fh '<a href="'.$_viewer_url.'">Without</a> | ';
1525 print $fh '<a href="'.$_info_url.'">Info</a> | ';
1526 print $fh '<a href="'.$_bbcode_url.'">BB</a>';
1527 print $fh "\n </span>\n";
1529 print $fh " </div>\n";
1530 print $fh " </div>\n";
1532 if (($text_mode == TEXT_MODE->{'words'}) && $show_words) {
1533 print_comments($fh, $context, $settings, $words_data);
1536 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1537 print_html_end($fh);
1540 unless (ref($file)) {
1544 truncate ($fh , tell($fh));
1550 sub print_comments {
1551 (my $fh, my $context, my $settings, my $words_data) = @_;
1553 my $password_ok = $context->{'password_ok'};
1554 my $frame = int($context->{'frame'});
1555 my $page = int($context->{'words_page'});
1556 my $post_count = int($words_data->{'posts'});
1557 my $id_start = $page * COMMENT_PAGE_LENGTH();
1558 my $id_stop = $id_start + COMMENT_PAGE_LENGTH();
1559 my $older = ($page > 0) ? ($page-1) : '';
1562 if ($id_stop >= $post_count) {
1563 $id_stop = $post_count;
1570 my $words_url = merge_url(
1571 {'path' => CGI_VIEWER_PATH()},
1574 'query' => {'b' => TEXT_MODE->{'words'}},
1577 my $older_url = merge_url(
1580 'query' => {'i' => $page-1},
1581 'fragment' => 'insw',
1585 my $newer_url = merge_url(
1588 'query' => {'i' => $page+1},
1589 'fragment' => 'insw',
1595 $password_query = url_query_encode({'p', $settings->{'password'}});
1596 $older_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1597 $newer_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1600 my $_post_url = html_entity_encode_dec(CGI_WORDS_PATH(), 1);
1601 my $_password = html_entity_encode_dec($settings->{'password'}, 1);
1602 my $_older_url = html_entity_encode_dec($older_url, 1);
1603 my $_newer_url = html_entity_encode_dec($newer_url, 1);
1605 if (($older ne '') || ($newer ne '')) {
1606 $links .= ' <div class="underlinks">'."\n";
1609 $links .= '<a href="'.$_older_url.'">Older</a>'
1611 if (($older ne '') && ($newer ne '')) {
1615 $links .= '<a href="'.$_newer_url.'">Newer</a>';
1618 $links .= ' </div>'."\n";
1621 print $fh ' <div class="space"></div>'."\n";
1622 print $fh ' <div id="insw" class="ins">'."\n";
1624 print $fh ' <div class="title" id="wordstitle">'."\n";
1625 print $fh ' <h1 class="titletext" id="wordstitletext">Words</h1>'."\n";
1626 print $fh ' </div>'."\n";
1632 print $fh ' <div class="undertext" id="words">'."\n";
1634 if ($post_count > 0) {
1635 for (my $i=$id_start; $i<$id_stop; ++$i) {
1636 my $ID = $words_data->{'content'}->[$i];
1637 my $post_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $ID);
1638 my %post_data = read_data_file($post_path);
1640 my $post_time = int($post_data{'posttime'});
1641 my $edit_time = int($post_data{'edittime'});
1646 if ($post_time != 0) {
1647 my @time_tab = gmtime($post_time);
1648 $post_time_text = sprintf(
1649 '%04d.%02d.%02d %02d:%02d:%02d UTC',
1658 if (($edit_time !=0) && ($edit_time != $post_time)) {
1659 my @time_tab = gmtime($edit_time);
1660 $edit_time_text = sprintf(
1661 '%04d.%02d.%02d %02d:%02d UTC',
1669 my $quote_url = merge_url(
1670 {'path' => CGI_WORDS_PATH()},
1675 'p' => ($password_ok ? $settings->{'password'} : '')
1679 my $edit_url = merge_url(
1680 {'path' => CGI_WORDS_PATH()},
1685 'key' => $post_data{'key'},
1686 'username' => $post_data{'name'},
1687 'p' => ($password_ok ? $settings->{'password'} : '')
1691 my $remove_url = merge_url(
1692 {'path' => CGI_WORDS_PATH()},
1697 'key' => $post_data{'key'},
1698 'username' => $post_data{'name'},
1699 'p' => ($password_ok ? $settings->{'password'} : '')
1704 my $_ID = html_entity_encode_dec($ID, 1);
1705 my $_name = html_entity_encode_dec($post_data{'name'}, 1);
1706 my $_quote_url = html_entity_encode_dec($quote_url, 1);
1707 my $_edit_url = html_entity_encode_dec($edit_url, 1);
1708 my $_remove_url = html_entity_encode_dec($remove_url, 1);
1710 print $fh ' <div id="'.$_ID.'"class="opomba">'."\n";
1711 print $fh ' <div class="opomba_info">'."\n";
1712 print $fh ' <a href="#'.$_ID.'" class="bi hu">'.$i.': '.$_name;
1713 if ($post_time_text ne '') {
1714 print $fh ' • '.$post_time_text;
1716 if ($edit_time_text ne '') {
1717 print $fh ' • '.$edit_time_text;
1719 print $fh '</a>'."\n";
1720 print $fh ' <div class="pr">'."\n";
1721 print $fh ' <a href="'.$_quote_url.'" class="bi hu">quote</a> | <a href="'.$_edit_url.'" class="bi hu">edit</a> | <a href="'.$_remove_url.'" class="bi hu">remove</a>'."\n";
1722 print $fh ' </div>'."\n";
1723 print $fh ' </div>'."\n";
1724 print $fh ' <div class="opomba_text">'."\n";
1725 print $fh bb_to_html(
1727 $post_data{'content'},
1729 $password_ok ? $settings->{'password'} : ''
1732 print $fh ' </div>'."\n";
1733 print $fh ' </div>'."\n";
1734 print $fh ' <br>'."\n";
1738 print $fh ' <form method="post" action="'.$_post_url.'">'."\n";
1739 print $fh ' <b>Your words:</b>'."\n";
1740 print $fh ' <textarea class="inta" name="words" rows="4"></textarea>'."\n";
1741 print $fh ' <table cellpadding="0" cellspacing="0" border="0"><tr>'."\n";
1742 print $fh ' <td><b>Your name: </b></td>'."\n";
1743 print $fh ' <td><input class="intx" type="text" name="username" value=""></td>'."\n";
1744 print $fh ' <td></td>'."\n";
1745 print $fh ' </tr><tr>'."\n";
1746 print $fh ' <td><b>Optional password: </b></td>'."\n";
1747 print $fh ' <td><input class="intx" type="password" name="password" value=""></td>'."\n";
1748 print $fh ' <td>(if you want to edit later)</td>'."\n";
1749 print $fh ' </tr><tr>'."\n";
1750 print $fh ' <td><b>Leave this empty: </b></td>'."\n";
1751 print $fh ' <td><input class="intx" type="text" name="password2" value=""></td>'."\n";
1752 print $fh ' <td>'."\n";
1753 print $fh ' <input class="inbt" type="submit" name="post" value="Send">'."\n";
1754 print $fh ' <input class="inbt" type="submit" name="preview" value="Preview">'."\n";
1755 print $fh ' </td>'."\n";
1756 print $fh ' </tr></table>'."\n";
1757 print $fh ' <input type="hidden" name="f" value="'.$frame.'">'."\n";
1759 print $fh ' <input type="hidden" name="p" value="'.$_password.'">'."\n";
1761 print $fh ' </form>'."\n";
1762 print $fh ' </div>'."\n";
1768 print $fh ' </div>'."\n";
1781 my $ong_state = int($state->{'state'});
1783 unless (open_encoded($fh, ">:encoding(UTF-8)", WWW_INDEX_PATH())) {
1787 # normal running story
1788 if ($ong_state > STATE->{'inactive'}) {
1789 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1790 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1791 my %default = read_data_file(DATA_DEFAULT_PATH());
1792 my %words_data = read_data_file(
1793 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), 0),
1800 %frame_data = merge_settings(\%default, \%frame_data);
1801 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1803 $r = print_viewer_page(
1810 'timer_unlocked' => 3, # not relevant
1811 'timer' => 0, # not relevant
1813 'show_command' => 1,
1814 'text_mode' => TEXT_MODE->{'normal'},
1815 'words_page' => 0 # not relevant
1825 # no conditions met, pretend a normal Apache2 index
1826 elsif ($pass != 1) {
1827 my $index_of = CGI_PATH;
1828 $index_of =~ s/\/$//g;
1830 my $_index_of = html_entity_encode_dec($index_of , 1);
1831 my $_2words_date = html_entity_encode_dec(INTF_DATE(), 1);
1832 my $_coin_date = html_entity_encode_dec(COIN_DATE(), 1);
1833 my $_website = html_entity_encode_dec(WEBSITE() , 1);
1835 print_html_start ($fh);
1836 print $fh ' <head>'."\n";
1837 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
1838 print $fh ' <title>Index of '.$_index_of.'</title>'."\n";
1839 print $fh ' </head>'."\n";
1840 print $fh ' <body>'."\n";
1841 print $fh ' <h1>Index of '.$_index_of.'</h1>'."\n";
1842 print $fh ' <table>'."\n";
1843 print $fh ' <tr>'."\n";
1844 print $fh ' <th><img src="/icons/blank.gif" alt="[ICO]"></th>'."\n";
1845 print $fh ' <th><a href="?C=N;O=D">Name</a></th>'."\n";
1846 print $fh ' <th><a href="?C=M;O=A">Last modified</a></th>'."\n";
1847 print $fh ' <th><a href="?C=S;O=A">Size</a></th>'."\n";
1848 print $fh ' <th><a href="?C=D;O=A">Description</a></th>'."\n";
1849 print $fh ' </tr><tr>'."\n";
1850 print $fh ' <th colspan="5"><hr></th>'."\n";
1851 print $fh ' </tr><tr>'."\n";
1852 print $fh ' <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>'."\n";
1853 print $fh ' <td><a href="/">Parent Directory</a></td>'."\n";
1854 print $fh ' <td> </td>'."\n";
1855 print $fh ' <td align="right"> - </td>'."\n";
1856 print $fh ' <td> </td>'."\n";
1857 print $fh ' </tr><tr>'."\n";
1858 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1859 print $fh ' <td><a href="2words/">2words/</a></td>'."\n";
1860 print $fh ' <td align="right">'.$_2words_date.' </td>'."\n";
1861 print $fh ' <td align="right"> - </td><td> </td>'."\n";
1862 print $fh ' </tr><tr>'."\n";
1863 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1864 print $fh ' <td><a href="coin/">coin/</a></td>'."\n";
1865 print $fh ' <td align="right">'.$_coin_date.' </td>'."\n";
1866 print $fh ' <td align="right"> - </td><td> Coincidence </td>'."\n";
1867 print $fh ' </tr><tr>'."\n";
1868 print $fh ' <th colspan="5"><hr></th>'."\n";
1869 print $fh ' </tr>'."\n";
1870 print $fh ' </table>'."\n";
1871 print $fh ' <address>Apache/2.2.22 (Debian) Server at '.$_website.' Port 80</address>'."\n";
1872 print $fh ' </body>'."\n";
1873 print_html_end ($fh);
1877 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1878 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1879 my %default = read_data_file(DATA_DEFAULT_PATH());
1880 my %coin_data = read_data_file(DATA_COIN_PATH());
1882 %frame_data = merge_settings(\%default, \%frame_data);
1883 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1885 if (($mode == INTF_STATE->{'>'}) && $pause) {
1886 $r = print_viewer_page(
1893 'timer_unlocked' => 3,
1896 'show_command' => 1,
1897 'text_mode' => TEXT_MODE->{'normal'},
1898 'words_page' => 0 # not relevant
1905 {'posts' => 0} # words_data
1910 my $index_of = CGI_PATH;
1911 $index_of =~ s/\/$//g;
1915 my $show_parent_dir = 0;
1917 my $show_folders = 0;
1919 my $timer_color = 'ni';
1920 if ($mode == INTF_STATE->{'>'}) {
1921 $title = $settings->{'story'}; # $frame_data{'title'} ?
1922 $frame_file = 'intf-tr.gif';
1926 elsif ($mode == INTF_STATE->{'<<'}) {
1927 $title = 'Index of';
1928 $frame_file = 'intf-ll.gif';
1929 $show_parent_dir = 1;
1932 $timer_color = 'br';
1934 elsif ($mode == INTF_STATE->{'>>'}) {
1935 $title = 'Index of';
1936 $frame_file = 'intf-pp.gif';
1937 $show_parent_dir = 1;
1943 $title = 'Index of '.$index_of;
1944 $frame_file = 'intf-kw.gif';
1945 $show_parent_dir = 1;
1948 my $frame_url = merge_url(
1949 {'path' => CGI_PATH()},
1950 {'path' => $frame_file}
1952 my $coin_server = $coin_data{'server'};
1954 my $_title = html_entity_encode_dec($title , 1);
1955 my $_website_name = html_entity_encode_dec(WEBSITE_NAME() , 1);
1956 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1957 my $_undertext = html_entity_encode_dec($undertext , 1);
1958 my $_2words_date = html_entity_encode_dec(INTF_DATE() , 1);
1959 my $_coin_date = html_entity_encode_dec(COIN_DATE() , 1);
1960 my $_coin_server = html_entity_encode_dec($coin_server , 1);
1961 my $_2words_url = html_entity_encode_dec(CGI_2WORDS_PATH(), 1);
1962 my $_coin_url = html_entity_encode_dec(CGI_COIN_PATH() , 1);
1964 print_html_start($fh);
1965 print_html_head_start($fh);
1967 print $fh ' <title>'.$_title.' • '.$_website_name.'</title>'."\n";
1969 print_html_head_end($fh);
1970 print_html_body_start($fh);
1972 print $fh ' <div id="inst" class="ins">'."\n";
1974 print $fh ' <div id="title">'."\n";
1975 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1976 print $fh ' </div>'."\n";
1978 print $fh ' </div>'."\n";
1979 print $fh ' <div id="framespace">'."\n";
1981 print $fh ' <img src="'.$_frame_url.'" id="frame" alt="0">'."\n"; # title="'.$_title.'"
1983 print $fh ' </div>'."\n";
1984 print $fh ' <div id="insb" class="ins">'."\n";
1986 print $fh ' <div id="undertext">'."\n";
1988 if ($show_parent_dir) {
1989 print $fh ' <img src="/icons/back.gif" alt="[DIR]"> <a href="..">Parent Directory</a><br>'."\n";
1991 if ($show_folders) {
1992 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">2words/</a> '.$_2words_date.' - <br>'."\n";
1993 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_coin_url.'">coin/</a> '.$_coin_date.' - '.$_coin_server."\n";
1996 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">yyyyb/</a>'."\n";
1998 if ($undertext ne '') {
1999 print $fh ' '.$_undertext."\n";
2002 print $fh ' </div>'."\n";
2005 print $fh ' <div id="command">'."\n";
2007 print $fh ' [<span id="ongh" class="'.$timer_color.'">'.$timer.'</span>';
2008 print $fh ':<span id="ongm" class="'.$timer_color.'">'.$timer.'</span>';
2009 print $fh ':<span id="ongs" class="'.$timer_color.'">'.$timer.'</span>]<br>'."\n";
2011 if ($undertext ne '') {
2012 print $fh '><a href="'.$_2words_url.'">'.$_undertext.'</a><span class="inp">_</span>'."\n";
2014 print $fh " </div>\n";
2017 print $fh " </div>\n";
2019 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
2020 print_html_end($fh);
2026 sub write_static_viewer_page {
2033 my $prev_frame_data_ref,
2034 my $next_frame_data_ref,
2042 my %prev_frame_data;
2043 my %next_frame_data;
2048 $frame = int($frame);
2049 my $prev_frame = $frame -1;
2050 my $next_frame = $frame +1;
2052 %state = (ref ($state_ref)) ?
2054 read_data_file(DATA_STATE_PATH());
2055 my $ong_state = int($state{'state'});
2056 my $last_frame = int($state{'last'});
2058 unless ($ong_state > STATE->{'inactive'}) {
2063 ($frame < $last_frame) || (
2064 ($frame <= $last_frame) &&
2065 ($ong_state >= STATE->{'end'})
2072 %settings = (ref ($settings_ref)) ?
2074 read_data_file(DATA_SETTINGS_PATH());
2075 %default = (ref ($default_ref)) ?
2077 read_data_file(DATA_DEFAULT_PATH());
2079 %frame_data = (ref ($frame_data_ref)) ?
2081 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $frame));
2083 %prev_frame_data = (ref ($prev_frame_data_ref)) ?
2084 %$prev_frame_data_ref : (
2085 ($prev_frame >= 0) ?
2086 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $prev_frame)) :
2090 %next_frame_data = (ref ($next_frame_data_ref)) ?
2091 %$next_frame_data_ref : (
2092 (($next_frame < $last_frame) || (
2093 ($next_frame <= $last_frame) &&
2094 ($next_frame >= STATE->{'end'})
2096 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $next_frame)) :
2100 %frame_data = merge_settings(\%default, \%frame_data);
2101 %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
2102 %next_frame_data = merge_settings(\%default, \%next_frame_data);
2104 %words_data = (ref ($words_data_ref)) ?
2107 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $frame), # file
2111 1, # as list; not relevant
2114 if ($frame_data{'page'} ne '') {
2115 $file = $frame_data{'page'}
2123 $file = join_path(PATH_SEPARATOR(), WWW_PATH(), $file);
2125 return print_viewer_page(
2132 'timer_unlocked'=> 3, # not relevant
2133 'timer' => 0, # not relevant
2135 'show_command' => 1,
2136 'text_mode' => TEXT_MODE->{'normal'},
2137 'words_page' => 0, # not relevant
2148 sub write_static_goto {
2149 (my $state_ref, my $settings_ref, my $goto_ref) = @_;
2154 %state = (ref ($state_ref)) ?
2156 read_data_file(DATA_STATE_PATH());
2157 %settings = (ref ($settings_ref)) ?
2159 read_data_file(DATA_SETTINGS_PATH());
2160 %goto_list = (ref ($goto_ref)) ?
2162 read_data_file(DATA_SETTINGS_PATH());
2173 # ONG the frame + attachment & stuff. NOT update state file.
2176 my $ID, my $ongtime, my $timer, my $update, my $print,
2177 my $settings_ref, my $default_ref, my $data_ref, my $goto_ref
2183 my $frame_data_path;
2191 my %frame_full_data;
2194 if ($ongtime eq '') {
2201 elsif ($ID eq 'c') {
2233 %settings = (ref ($settings_ref)) ?
2235 read_data_file(DATA_SETTINGS_PATH());
2236 %default = (ref ($default_ref)) ?
2238 read_data_file(DATA_DEFAULT_PATH());
2239 $frame_data_path = $cfrt ?
2240 DATA_NOACCESS_PATH() :
2241 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
2242 %frame_data = (ref ($data_ref)) ?
2244 read_data_file($frame_data_path);
2245 %frame_full_data = merge_settings(\%default, \%frame_data);
2247 ($frame_full_data{'frame'} ne '') ?
2248 $frame_full_data{'frame'} :
2251 $frame, $frame_full_data{'ext'}
2256 %goto_list = (ref ($goto_ref)) ?
2258 read_data_file(DATA_LIST_PATH());
2259 for (my $i=0; ;$i+=1) {
2260 my %file_data = read_data_file(DATA_ATTACH_PATH().$i);
2261 if ($file_data{'frame'} eq '') {
2264 if (int($file_data{'frame'}) != $frame) {
2267 if ($file_data{'content'} ne '') {
2270 unshift @files, $file_data{'filename'};
2274 ($frame_full_data{'ongtime'} eq '')
2276 $frame_data {'ongtime'} = $ongtime;
2277 $frame_full_data{'ongtime'} = $ongtime;
2283 ($frame_full_data{'timer'} eq '')
2286 $frame_data{'timer'} = int($timer);
2290 $r = write_data_file($frame_data_path, \%frame_data);
2292 print STDERR "fail writing $frame_data_path\n";
2294 print "write frame data fail\n";
2299 $goto_list{'title-' .$frame} = $frame_full_data{'title'};
2300 $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
2301 $r = write_data_file(DATA_LIST_PATH(), \%goto_list);
2303 print STDERR "fail writing ".DATA_LIST_PATH()."\n";
2305 print "write GOTO list fail\n";
2311 foreach my $file (@files) {
2312 $in_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file);
2313 $out_path = join_path(PATH_SEPARATOR(), WWW_PATH() , $file);
2315 print $in_path.' -> '.$out_path;
2317 $r = copy_encoded($in_path, $out_path);
2319 print (($r) ? " OK\n" : " FAIL\n");
2322 print STDERR "fail copy $in_path $out_path\n";