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',
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_LOGO_PATH: CGI_LOGO_PATH = /bsta/botmlogo.png
81 ###PERL_CGI_TIMER_PATH: CGI_TIMER_PATH = /bsta/timer.js
82 ###PERL_CGI_VIEWER_PATH: CGI_VIEWER_PATH = /bsta/v
83 ###PERL_CGI_WORDS_PATH: CGI_WORDS_PATH = /bsta/w
85 ###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta/
86 ###PERL_DATA_ATTACH_PATH: DATA_ATTACH_PATH = /botm/data/bsta/a
87 ###PERL_DATA_COIN_PATH: DATA_COIN_PATH = /botm/data/bsta/coincidence
88 ###PERL_DATA_DEFAULT_PATH: DATA_DEFAULT_PATH = /botm/data/bsta/default
89 ###PERL_DATA_LIST_PATH: DATA_LIST_PATH = /botm/data/bsta/list
90 ###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
91 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
92 ###PERL_DATA_WORDS_PATH: DATA_WORDS_PATH = /botm/data/bsta/words/
94 ###PERL_WWW_PATH: WWW_PATH = /botm/www/
95 ###PERL_WWW_INDEX_PATH: WWW_INDEX_PATH = /botm/www/1190/bsta/index.htm
97 ###PERL_SCHEME: SCHEME = http
98 ###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info
99 ###PERL_WEBSITE_NAME: WEBSITE_NAME = Bicycles on the Moon
100 ###PERL_FAVICON_PATH: FAVICON_PATH = /img/favicon.png
102 ###PERL_COIN_DATE: COIN_DATE = 13-Nov-2016 22:15
103 ###PERL_INTF_DATE: INTF_DATE = 28-Sep-2016 20:34
105 ###PERL_STORY_CREDITS: STORY_CREDITS = "BSTA" by Balthasar Szczepański
106 ###PERL_INTF_CREDITS: INTF_CREDITS = Online interface © Balthasar Szczepański; AGPL 3 license
107 ###PERL_SOURCE_URL: SOURCE_URL = http://bicyclesonthemoon.info/git-projects/?p=ott/bsta
109 ###PERL_COMMENT_PAGE_LENGTH:COMMENT_PAGE_LENGTH= 16
111 use constant STATE => {
117 use constant INTF_STATE => {
130 use constant TEXT_MODE => {
136 use constant CHAT_STATE => {
141 use constant CHAT_ACTION => {
149 use constant tags_bbcode => {
156 'quote' => '[quote]',
157 'quote=' => '[quote="',
159 '/quote' => '[/quote]',
160 'ni' => '[color=#0057AF]',
162 'br' => '[color=#BB6622]',
164 'po' => '[color=#FF8800]',
175 '/list' => '[/list]',
179 '/?' => '[/unknown!]',
181 use constant tags_html => {
184 'fq' => '<div class="fq">',
186 'tq' => '<div class="tq">',
188 'quote' => '<div class="opomba"><div class="opomba_text">',
189 'quote=' => '<div class="opomba"><div class="opomba_info"><b>',
190 'quote/='=> '</b> wrote:</div><div class="opomba_text">',
191 '/quote' => '</div></div>',
192 'ni' => '<span class="ni">',
194 'br' => '<span class="br">',
196 'po' => '<span class="po">',
198 'url' => '<a href="#">',#think: how to add selfincluding?
199 'url=' => '<a href="',
205 'list=' => '<ol style="list-style-type: ',
206 'list=1' => 'decimal',
207 'list=A' => 'upper-alpha',
208 'list=a' => 'lower-alpha',
209 'list=I' => 'upper-roman',
210 'list=i' => 'lower-roman',
217 '/?' => '[/unknown!]',
221 # Function to return an error page
222 # arguments: 1 - header fields, 2 - page title, 3 - error message, 4 method
224 (my $header, my $title, my $message, my $method, my $hyperlink) = @_;
227 foreach my $header_name (keys %$header) {
228 print http_header_line($header_name, $header->{$header_name});
231 elsif($header ne '') {
234 if($method eq 'HEAD') {
238 my $_title = html_entity_encode_dec($title , 1);
239 my $_message = html_entity_encode_dec($message , 1);
240 my $_hyperlink = html_entity_encode_dec($hyperlink, 1);
242 print "Content-type: text/html; charset=UTF-8\n\n";
244 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
245 print ' <html lang="en">'."\n";
246 print ' <head>'."\n";
247 print ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
249 print ' <title>'.$_title.'</title>'."\n";
251 print ' </head>'."\n";
252 print ' <body>'."\n";
254 print ' <h1>'.$_title.'</h1>'."\n";
256 if (($message ne '') || ($hyperlink ne '')) {
258 if ($message ne '') {
259 print ' '.$_message.($hyperlink ne '' ? '<br>' : '')."\n";
261 if ($hyperlink ne '') {
262 print ' <a href="'.$_hyperlink.'">'.$_hyperlink."</a>\n";
266 print ' </body>'."\n";
267 print '</html>'."\n";
271 (my $method, my $allowed) = @_;
273 my $status = http_status(HTTP_STATUS->{'method_not_allowed'});
275 http_header_line('status', $status) .
276 http_header_allow($allowed);
281 "The interface does not support the $method method.",
286 sub fail_content_type
288 (my $method, my $content_type) = @_;
290 my $status = http_status(HTTP_STATUS->{'unsupported_media_type'});
291 my $header = http_header_line('status', $status);
296 "Unsupported Content-type: $content_type.",
303 (my $method, my $type, my $path) = @_;
305 my $status = http_status(HTTP_STATUS->{'not_found'});
306 my $header = http_header_line('status', $status);
312 ($type ne '' ? $type : 'file').
313 ($path ne '' ? ': "'.$path.'"' : '').
321 (my $method, my $ID) = @_;
323 my $status = http_status(HTTP_STATUS->{'not_found'});
324 my $header = http_header_line('status', $status);
329 "Attachment $ID not found.",
336 (my $method, my $text) = @_;
338 my $status = http_status(HTTP_STATUS->{'internal_server_error'});
339 my $header = http_header_line('status', $status);
351 (my $method, my $uri, my $code) = @_;
355 $code = HTTP_STATUS->{'found'};
357 # 301 Moved Permanently
360 # 307 Temporary Redirect
361 # 308 Permanent Redirect
362 $status = http_status($code);
363 $header = http_header_line('status', $status);
364 $header .= http_header_location($uri);
376 # function to obtain address of remote agent
377 sub get_remote_addr {
378 if ($ENV{'HTTP_X_FORWARDED_FOR'} =~ /^.+$/) {
381 elsif ($ENV{'REMOTE_ADDR'} =~ /^.+$/) {
389 # functions to get ID/number etc.
391 (my $cgi, my $default, my $cgi_name) = @_;
392 if ($default eq '') {
395 if ($cgi_name eq '') {
399 if ($cgi->{$cgi_name} =~ /^.+$/) {
402 elsif ($ENV{'PATH_INFO'} =~ /^\/(.+)$/) {
406 return int($default);
410 # function to obtain frame number
412 (my $cgi, my $default) = @_;
413 return get_id($cgi, $default, 'f');
416 # function to obtain password
420 if ($cgi->{'p'} =~ /^.+$/) {
432 foreach my $settings (@_) {
433 foreach my $ind (keys %$settings) {
434 $final_settings{$ind} = $settings->{$ind};
437 return %final_settings;
442 # different & simpler implementation than in post library
446 #analyse bbcode text to build tag tree
447 #TODO make [/*] optional!
449 (my $bb, my $printdebug) = @_;
462 $bbtree{"_.name" } = "ht";
463 $bbtree{"_.value" } = '';
464 $bbtree{"_.type" } = "tag";
465 $bbtree{"_.count" } = 0;
466 $bbtree{"_.closed"} = 0;
467 $debug .= debug($printdebug,
469 "<!--GENERATING BBCODE TREE:\n".
470 '[_]automatic tag: [ht]'."\n"
474 my $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
476 if($bb =~ m/\[(\/?)([A-Za-z]+|\*)(=([^\[\]]*))?\]/g) {
483 if ($tag_value =~ /^"(.*)"$/) {
487 if ($pre_text ne '') {
488 $debug .= debug($printdebug, "[$new_ind]text: $pre_text\n");
489 $bbtree{$new_ind.'.type' } = 'text';
490 $bbtree{$new_ind.'.value'} = $pre_text;
491 $bbtree{ $ind.'.count'}+= 1;
492 $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
495 if($tag_name =~ /^(fq|tq|quote|br|ni|po|url|i|list|\*)$/) {
496 if ($tag_end ne '') {
498 ($tag_name ne $bbtree{$ind.'.name'}) ||
501 $debug .= debug($printdebug, "[$new_ind]text: $tag\n");
502 $bbtree{$new_ind.'.type' } = 'text';
503 $bbtree{$new_ind.'.value'} = $tag;
504 $bbtree{ $ind.'.count'}+= 1;
505 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
508 $debug .= debug($printdebug, "[$new_ind]tag: $tag\n");
509 $bbtree{$new_ind.'.type' } = 'tag';
510 $bbtree{$new_ind.'.name' } = '/'.$tag_name;
511 $bbtree{$new_ind.'.value' } = $tag_value;
512 $bbtree{ $ind.'.count' }+= 1;
513 $bbtree{ $ind.'.closed'} = 1;
515 $ind =~ s/\.[0-9]+$//;
516 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
521 $debug .= debug($printdebug, "[$new_ind]tag: $tag\n");
522 $bbtree{$new_ind.'.type' } = 'tag';
523 $bbtree{$new_ind.'.name' } = $tag_name;
524 $bbtree{$new_ind.'.value' } = $tag_value;
525 $bbtree{$new_ind.'.count' } = 0;
526 $bbtree{$new_ind.'.closed'} = 0;
527 $bbtree{ $ind.'.count' }+= 1;
530 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
534 $debug .= debug($printdebug, "[$new_ind]text: $tag\n");
535 $bbtree{$new_ind.'.type' } = 'text';
536 $bbtree{$new_ind.'.value'} = $tag;
537 $bbtree{ $ind.'.count'}+= 1;
538 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
542 $debug .= debug($printdebug, "[$new_ind]text: $bb\n");
543 $bbtree{$new_ind.'.type' } = 'text';
544 $bbtree{$new_ind.'.value'} = $bb;
545 $bbtree{ $ind.'.count'}+= 1;
546 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
550 my $final_ind = '_.'.$bbtree{"_.count"};
551 $debug .= debug($printdebug, "[$final_ind]automatic tag: [/ht]\n -->\n");
552 $bbtree{$final_ind.'.type' } = "tag";
553 $bbtree{$final_ind.'.name' } = '/ht';
554 $bbtree{ '_.count' }+= 1;
555 $bbtree{ '_.closed'} = 1;
557 return ($debug, %bbtree);
560 #convert tag tree to final text
562 (my $printdebug, my $debug, my $lang, my $bbtree) = @_;
567 my $tags = ($lang eq 'html') ? tags_html : tags_bbcode;
568 my $escape = ($lang eq 'html');
570 # $debug .= debug($printdebug, "\n****\n");
571 # foreach my $iiii (keys %tags) {
572 # $debug .= debug($printdebug, $iiii.'='.$tags->{$iiii}."\n");
574 # $debug .= debug($printdebug, "****\n");
579 $debug .= debug($printdebug, "\n<!--PROCESSING BBCODE TREE:\n");
581 while ($level >= 0) {
583 $debug .= debug($printdebug, "[$level:$ind:".int($bbtree->{$ind.'.count'})."]");
585 if ($bbtree->{$ind.'.type'} eq 'text') {
586 my $text = $bbtree->{$ind.'.value'};
587 $debug .= debug($printdebug, "text: ".$text);
588 $out .= $escape ? html_encode_line($text) : $text;
593 elsif ($bbtree->{$ind.'.type'} eq 'tag') {
594 my $name = $bbtree->{$ind.'.name'};
596 if ($name =~ /^\//) {
597 $debug .= debug($printdebug, "tag: [$name]");
599 $indd =~ s/\.([0-9]+)$//;
600 if (exists($tags->{$name.'='}) && ($bbtree->{$indd.'.value'} ne '')) {
601 $out .= $tags->{$name.'='};
603 elsif (exists($tags->{$name})) {
604 $out .= $tags->{$name};
607 $out .= $tags->{'/?'};
608 $debug .= debug($printdebug, "[unknown!]");
611 $ind =~ s/\.([0-9]+)$//;
613 $debug .= debug($printdebug, "[<]");
624 my $value = $bbtree->{$ind.'.value'};
625 if($bbtree->{$ind.'.closed'} ne '') {
626 $debug .= debug($printdebug, "tag: [$name]");
628 if (exists($tags->{$name.'='}) && ($value ne '')) {
629 if (exists($tags->{$name.'='.$value})) {
632 $tags->{$name.'='.$value} .
638 ($escape ? html_entity_encode_dec($value, 1) : $value) .
642 elsif (exists($tags->{$name})) {
643 $out .= $tags->{$name};
646 $out .= $out.$tags->{'?'};
647 $debug .= debug($printdebug, "[unknown!]");
651 $debug .= debug($printdebug, "unclosed tag: [$name]");
652 my $text = $name . (($value ne '') ? ('='.$value) : '');
653 $out .= '['.($escape ? html_encode_line($text) : $text).']';
655 if ($bbtree->{$ind.'.count'} > 0) {
658 $debug .= debug($printdebug, "[>]");
667 $debug .= debug($printdebug, "unknown thing: ".$bbtree->{$ind.'.type'});
668 #should not occur with a correct bbtree
669 #unless unimplemented
670 $ind =~ s/\.([0-9]+)$//;
672 $debug .= debug($printdebug, "[<ui]");
681 if ($goto_next ne '') {
683 $ind =~ s/\.([0-9]+)$//;
685 if (($i < $bbtree->{$ind.'.count'}) and ($1 ne '')){
692 # should not occur with a correct bbtree
693 $debug .= debug($printdebug, "[<$goto_next]");
696 } while ($level >= 0);}
699 $debug .= debug($printdebug, "[>$level:$ind]\n");
702 $debug .= debug($printdebug, "-->\n");
703 return ($debug, $out);
708 (my $bb, my $printdebug) = @_;
713 ($debug, %bbtree) = bbtree($bb, $printdebug);
714 ($debug, $ht) = convtree ($printdebug, $debug, 'html', \%bbtree);
721 (my $bb, my $printdebug) = @_;
726 ($debug, %bbtree) = bbtree($bb, $printdebug);
727 ($debug, $ht) = convtree ($printdebug, $debug, 'bb', \%bbtree);
733 (my $bb, my $full_url, my $password) = @_;
738 my $base_url = $full_url ?
739 {'scheme' => SCHEME(), 'host' => WEBSITE()} :
742 while ($bb =~ m/###([^#;]*);/g) {
747 if ($value =~ /^att&([0-9]+)$/) {
750 {'path' => CGI_ATTACH_PATH()},
754 elsif ($value =~ /^vw&([0-9]+)$/) {
757 {'path' => CGI_VIEWER_PATH()},
761 elsif ($value =~ /^fr&([0-9]+)$/) {
764 {'path' => CGI_FRAME_PATH()},
771 if (($value ne '') && ($password ne '')) {
774 {'query' => {'p' => $password}}
777 $bb = $before . $value . $after;
783 sub html_encode_line {
784 (my $text, my $non_ascii, my $all) = @_;
788 $text =~ s/\r\n/\n/gs;
791 while ($text ne '') {
792 $ind = index($text, "\n");
794 $html .= html_entity_encode_dec(substr($text, 0, $ind), $non_ascii, $all)."<br>\n";
795 $text = substr($text, $ind+1);
799 $html .= html_entity_encode_dec($text, 1);
807 (my $print, my $text) = @_;
817 sub print_html_start {
819 print $fh '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
820 print $fh '<html lang="en">'."\n";
825 print $fh '</html>'."\n";
828 sub print_html_head_start {
830 print $fh ' <head>'."\n";
831 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
832 print $fh ' <link rel="icon" type="image/png" href="'.html_entity_encode_dec(FAVICON_PATH(),1).'">'."\n";
833 print $fh ' <link rel="stylesheet" href="'.html_entity_encode_dec(CGI_CSS_PATH(),1).'">'."\n";
836 sub print_html_head_end {
838 print $fh ' </head>'."\n";
841 sub print_html_body_start {
843 print $fh ' <body>'."\n";
844 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";
845 print $fh ' <div id="all">'."\n";
848 sub print_html_body_end {
849 (my $fh, my $hide_credits) = @_;
850 print $fh ' </div>'."\n";
851 unless ($hide_credits) {
852 print $fh ' <p>'."\n";
853 print $fh ' '.html_entity_encode_dec(STORY_CREDITS(),1).'<br>'."\n";
854 print $fh ' '.html_entity_encode_dec(INTF_CREDITS(),1).'<br>'."\n";
855 print $fh ' <a href="'.html_entity_encode_dec(SOURCE_URL(),1).'" class="cz">source code</a>'."\n";
856 print $fh ' </p>'."\n";
858 print $fh ' <a href="/" class="cz">'.html_entity_encode_dec(WEBSITE(),1).'</a>'."\n";
859 print $fh ' </body>'."\n";
862 sub print_html_data {
863 (my $fh, my $data) = @_;
865 foreach my $key (keys %$data) {
866 unless ($key eq 'content') {
867 my $val = $data->{$key};
868 $val =~ s/(\r)?\n/\n /gs; # does the space make sense in HTML anyway?
869 print $fh html_encode_line("$key: $val\n", 1);
872 print $fh html_encode_line("\n".$data->{'content'});
875 sub print_viewer_page {
888 my $launch = $context->{'launch'};
889 my $access = $context->{'access'};
890 my $password_ok = $context->{'password_ok'};
891 my $static = $context->{'static'};
893 my $frame = int($context->{'frame'});
894 my $text_mode = int($context->{'text_mode'});
895 my $timer_unlocked = int($context->{'timer_unlocked'});
896 my $timer = int($context->{'timer'});
897 # my $words_page = int($context->{'words_page'});
899 my $prev_frame = $frame - 1;
900 my $next_frame = $frame + 1;
902 my $story = $settings->{'story'};
903 my $title = $frame_data->{'title'};
904 my $command = ($frame_data->{'command'} ne '') ?
905 $frame_data->{'command'} :
906 $next_frame_data->{'title'};
908 my $last_frame = int($state->{'last'});
909 my $ong_state = int($state->{'state'});
911 my $width = int($frame_data->{'width'});
912 my $height = int($frame_data->{'height'});
913 my $frame_type = $frame_data->{'frametype'};
915 my $timer_color_h = (($timer_unlocked >= 1) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
916 my $timer_color_m = (($timer_unlocked >= 2) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
917 my $timer_color_s = (($timer_unlocked >= 3) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
924 (($timer >= 0) && ($frame == 0))
926 $timer_s = sprintf('%02d', $timer % 60);
927 $timer_h = int($timer / 60);
928 $timer_m = sprintf('%02d', $timer_h % 60);
929 $timer_h = sprintf('%02d', $timer_h / 60);
931 elsif (($timer >= -15) && ($ong_state >= STATE->{'ready'})) {
942 my $words_posts = int($words_data->{'posts'});
943 my $words_link_text = 'Words'.(($words_posts > 0) ? "[$words_posts]" : '');
945 my $prev_available = (($frame > 0) && $access);
946 my $next_available = ($launch || $password_ok || ($next_frame <= $last_frame));
947 my $prefetch_prev = (
949 ($prev_frame < $last_frame) || ( # avoid unseen trigger!
950 ($prev_frame <= $last_frame) &&
951 ($ong_state >= STATE->{'ready'})
954 my $prefetch_next = (
956 ($next_frame < $last_frame) || ( # avoid unseen trigger!
957 ($next_frame <= $last_frame) &&
958 ($ong_state >= STATE->{'ready'})
965 ($frame == $last_frame) && (
966 ($ong_state == STATE->{'waiting'}) ||
967 ($ong_state == STATE->{'ready'})
975 ($frame < $last_frame) || (
976 ($ong_state >= STATE->{'ready'}) &&
977 $context->{'show_command'}
980 my $show_command_link = ($next_available || (!$access));
981 my $show_command_cursor = ((!$next_available) || ($command eq ''));
982 my $show_words = ($password_ok || ($access && !$launch));
984 my $frame_indirect = !(
986 ($frame <= $last_frame) &&
987 ($ong_state > STATE->{'inactive'})
990 my $prevframe_indirect = !($prev_frame <= $last_frame);
991 my $nextframe_indirect = !($next_frame <= $last_frame);
995 my $base_url = CGI_PATH();
996 my $goto_url = CGI_GOTO_PATH();
997 my $timer_url = CGI_TIMER_PATH();
998 my $viewer_full_url = merge_url(
999 {'scheme' => SCHEME(), 'host' => WEBSITE()},
1000 {'path' => CGI_VIEWER_PATH()},
1003 my $viewer_url = merge_url(
1004 {'path' => CGI_VIEWER_PATH()},
1007 my $viewer_0_url = merge_url(
1008 {'path' => CGI_VIEWER_PATH()},
1011 my $viewer_prev_url = merge_url(
1012 {'path' => CGI_VIEWER_PATH()},
1013 {'path' => $prev_frame}
1015 my $viewer_next_url = merge_url(
1016 {'path' => CGI_VIEWER_PATH()},
1017 {'path' => $next_frame}
1019 my $viewer_last_url = merge_url(
1020 {'path' => CGI_VIEWER_PATH()},
1021 {'path' => ($static ? -1 : $last_frame)}
1023 unless ($password_ok) {
1025 $viewer_0_url = $base_url;
1026 if ($prev_frame == 0) {
1027 $viewer_prev_url = $viewer_0_url;
1030 if ($prev_frame_data->{'page'} ne '') {
1031 $page_file = $prev_frame_data->{'page'};
1034 $page_file = sprintf(
1035 $settings->{'frame'},
1039 if (_x_encoded('-f',
1040 join_path(PATH_SEPARATOR(), WWW_PATH() , $page_file)
1042 $viewer_prev_url = merge_url(
1043 {'path' => $base_url},
1044 {'path' => $page_file}
1048 if ($next_frame < $last_frame) {
1049 if ($next_frame_data->{'page'} ne '') {
1050 $page_file = $next_frame_data->{'page'};
1053 $page_file = sprintf(
1054 $settings->{'frame'},
1058 if (_x_encoded('-f',
1059 join_path(PATH_SEPARATOR(), WWW_PATH() , $page_file)
1061 $viewer_next_url = merge_url(
1062 {'path' => $base_url},
1063 {'path' => $page_file}
1068 my $bbcode_url = ($text_mode == TEXT_MODE->{'bb'}) ?
1070 {'path' => CGI_BBCODE_PATH()},
1077 'b' => TEXT_MODE->{'bb'}
1082 my $info_url = ($text_mode == TEXT_MODE->{'info'}) ?
1084 {'path' => CGI_INFO_PATH()},
1091 'b' => TEXT_MODE->{'info'}
1096 my $words_url = merge_url (
1100 'b' => TEXT_MODE->{'words'}
1109 my $frame_normal_url;
1111 if ($frame_data->{'frame'} ne '') {
1112 $frame_file = $frame_data->{'frame'};
1115 $frame_file = sprintf(
1116 $settings->{'frame'},
1117 $frame, $frame_data->{'ext'}
1120 $frame_normal_url = merge_url(
1121 {'path' => CGI_PATH()},
1122 {'path' => $frame_file}
1124 $frame_url = $frame_indirect ?
1126 {'path' => CGI_FRAME_PATH()},
1130 $frame_full_url = merge_url(
1131 {'scheme' => SCHEME(), 'host' => WEBSITE()},
1132 {'path' => $frame_normal_url}
1134 if ($prevframe_indirect) {
1135 $frame_prev_url = merge_url(
1136 {'path' => CGI_FRAME_PATH()},
1137 {'path' => $prev_frame}
1140 elsif ($prev_frame_data->{'frame'} ne '') {
1141 $frame_prev_url = merge_url(
1142 {'path' => CGI_PATH()},
1143 {'path' => $prev_frame_data->{'frame'}}
1147 $frame_prev_url = merge_url(CGI_PATH(), sprintf(
1148 $settings->{'frame'}, $prev_frame, $prev_frame_data->{'ext'}
1151 if ($nextframe_indirect) {
1152 $frame_next_url = merge_url(
1153 {'path' => CGI_FRAME_PATH()},
1154 {'path' => $next_frame}
1157 elsif ($next_frame_data->{'frame'} ne '') {
1158 $frame_next_url = merge_url(
1159 {'path' => CGI_PATH()},
1160 {'path' => $next_frame_data->{'frame'}}
1164 $frame_next_url = merge_url(CGI_PATH(), sprintf(
1165 $settings->{'frame'}, $next_frame, $next_frame_data->{'ext'}
1170 $password_query = url_query_encode({'p', $settings->{'password'}});
1171 $goto_url = merge_url($goto_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1172 $info_url = merge_url($info_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1173 $words_url = merge_url($words_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1174 $bbcode_url = merge_url($bbcode_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1175 $viewer_url = merge_url($viewer_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1176 $viewer_0_url = merge_url($viewer_0_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1177 $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1178 $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1179 $viewer_last_url = merge_url($viewer_last_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1180 if ($frame_indirect) {
1181 $frame_url = merge_url($frame_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1183 if ($prevframe_indirect) {
1184 $frame_prev_url= merge_url($frame_prev_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1186 if ($nextframe_indirect) {
1187 $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1190 my $_base_url = html_entity_encode_dec($base_url , 1);
1191 my $_goto_url = html_entity_encode_dec($goto_url , 1);
1192 my $_info_url = html_entity_encode_dec($info_url , 1);
1193 my $_words_url = html_entity_encode_dec($words_url , 1);
1194 my $_bbcode_url = html_entity_encode_dec($bbcode_url , 1);
1195 my $_timer_url = html_entity_encode_dec($timer_url , 1);
1196 my $_viewer_full_url = html_entity_encode_dec($viewer_full_url, 1);
1197 my $_viewer_url = html_entity_encode_dec($viewer_url , 1);
1198 my $_viewer_0_url = html_entity_encode_dec($viewer_0_url , 1);
1199 my $_viewer_prev_url = html_entity_encode_dec($viewer_prev_url, 1);
1200 my $_viewer_next_url = html_entity_encode_dec($viewer_next_url, 1);
1201 my $_viewer_last_url = html_entity_encode_dec($viewer_last_url, 1);
1202 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1203 my $_frame_prev_url = html_entity_encode_dec($frame_prev_url , 1);
1204 my $_frame_next_url = html_entity_encode_dec($frame_next_url , 1);
1205 my $_frame_full_url = html_entity_encode_dec($frame_full_url , 1);
1207 my $_story = html_entity_encode_dec($story , 1);
1208 my $_title = html_entity_encode_dec($title , 1);
1209 my $_command = html_entity_encode_dec($command , 1);
1210 my $_frame_type = html_entity_encode_dec($frame_type, 1);
1212 my $_website_name = html_entity_encode_dec(WEBSITE_NAME(), 1);
1214 if ($text_mode == TEXT_MODE->{'info'}) {
1215 if ($show_command) {
1216 $frame_data->{'command'} = $command;
1218 if ($context->{'access'}) {
1219 $frame_data->{'frame'} = $frame_file;
1223 # everything determined, now start generating
1227 unless (seek($fh, 0, 0)) {
1228 #don't actually fail here
1232 unless (open_encoded($fh, ">:encoding(UTF-8)", $file)) {
1237 print_html_start($fh);
1238 print_html_head_start($fh);
1240 print $fh ' <title>'.$_title;
1241 if ($story ne $title) {
1242 print $fh ' • '.$_story;
1244 print $fh ' • '.$_website_name.'</title>'."\n";
1245 print $fh ' <link rel="index" href="'.$_goto_url.'">'."\n";
1246 print $fh ' <link rel="start" href="'.$_viewer_0_url.'">'."\n";
1247 if ($prev_available) {
1248 print $fh ' <link rel="prev" href="'.$_viewer_prev_url.'">'."\n";
1249 if ($prefetch_prev) {
1250 print $fh ' <link rel="prefetch" href="'.$_viewer_prev_url.'">'."\n";
1251 print $fh ' <link rel="prefetch" href="'.$_frame_prev_url.'">'."\n";
1254 if ($next_available) {
1255 print $fh ' <link rel="next" href="'.$_viewer_next_url.'">'."\n";
1256 if ($prefetch_next) {
1257 print $fh ' <link rel="prefetch" href="'.$_viewer_next_url.'">'."\n";
1258 print $fh ' <link rel="prefetch" href="'.$_frame_next_url.'">'."\n";
1262 print $fh ' <script src="'.$_timer_url.'"></script>'."\n";
1265 print_html_head_end($fh);
1266 print_html_body_start($fh);
1268 print $fh ' <div id="inst" class="ins">'."\n";
1270 print $fh ' <div id="title">'."\n";
1271 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1272 print $fh ' </div>'."\n";
1274 print $fh ' </div>'."\n";
1275 print $fh ' <div id="framespace">'."\n";
1277 print $fh ' <img src="'.$_frame_url.'" id="frame" class="'.$_frame_type.'" alt="'.$frame.'" title="'.$_title.'" width="'.$width.'" height="'.$height.'">'."\n";
1279 print $fh ' </div>'."\n";
1280 print $fh ' <div id="insb" class="ins">'."\n";
1282 if ($text_mode == TEXT_MODE->{'info'}) {
1283 print $fh ' <div id="chat">'."\n";
1285 print_html_data($fh, $frame_data);
1287 print $fh ' </div>'."\n";
1289 elsif ($text_mode == TEXT_MODE->{'bb'}) {
1290 print $fh ' <div id="chat">'."\n";
1292 print $fh '[quote][center][size=200]'.$_title.'[/size]<br>'."\n";
1293 print $fh '[url='.$_viewer_full_url.'][img]'.$_frame_full_url.'[/img][/url][/center]<br>'."\n";
1294 print $fh html_encode_line(
1297 $frame_data->{'content'},
1302 print $fh '[/quote]'."\n";
1304 print $fh ' </div>'."\n";
1306 elsif ($frame_data->{'content'} ne '') {
1307 print $fh ' <div id="undertext">'."\n";
1308 print $fh bb_to_html(
1310 $frame_data->{'content'},
1312 $password_ok ? $settings->{'password'} : ''
1315 print $fh ' </div>'."\n";
1318 print $fh ' <div id="command">'."\n";
1321 print $fh ' <span id="timer">';
1322 print $fh '[<span id="ongh" class="hv '.$timer_color_h.'">'.$timer_h.'</span>';
1323 print $fh ':<span id="ongm" class="hv '.$timer_color_m.'">'.$timer_m.'</span>';
1324 print $fh ':<span id="ongs" class="hv '.$timer_color_s.'">'.$timer_s.'</span>]';
1325 print $fh '</span><br>'."\n";
1328 if ($show_command_link) {
1329 print $fh '<a href="'.($access ? $_viewer_next_url : $_viewer_last_url).'">';
1331 if ($show_command) {
1332 print $fh $_command;
1334 if ($show_command_cursor) {
1335 print $fh '<span class="inp">_</span>';
1337 if ($show_command_link) {
1341 print $fh " </div>\n";
1343 print $fh ' <div id="underlinks">'."\n ";
1345 unless (($frame == 0) && $static) {
1346 print $fh '<a href="'.$_base_url.'">Once again</a> | ';
1348 if ($prev_available) {
1349 print $fh '<a href="'.$_viewer_prev_url.'">Before</a> | ';
1351 unless ($frame == $last_frame) {
1352 print $fh '<a href="'.$_viewer_last_url.'">Now</a> | ';
1354 print $fh '<a href="'.$_goto_url.'">GOTO</a>'."\n";
1355 print $fh ' <span style="float: right;">'."\n ";
1356 if ($text_mode == TEXT_MODE->{'normal'}) {
1358 print $fh '<a href="'.$_words_url.'">'.$words_link_text.'</a> | ';
1362 print $fh '<a href="'.$_viewer_url.'">Without</a> | ';
1364 print $fh '<a href="'.$_info_url.'">Info</a> | ';
1365 print $fh '<a href="'.$_bbcode_url.'">BB</a>';
1366 print $fh "\n </span>\n";
1368 print $fh " </div>\n";
1369 print $fh " </div>\n";
1371 if (($text_mode == TEXT_MODE->{'words'}) && $show_words) {
1372 print_comments($fh, $context, $settings, $words_data);
1375 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1376 print_html_end($fh);
1379 unless (ref($file)) {
1383 truncate ($fh , tell($fh));
1389 sub print_comments {
1390 (my $fh, my $context, my $settings, my $words_data) = @_;
1392 my $password_ok = $context->{'password_ok'};
1393 my $frame = int($context->{'frame'});
1394 my $page = int($context->{'words_page'});
1395 my $post_count = int($words_data->{'posts'});
1396 my $id_start = $page * COMMENT_PAGE_LENGTH();
1397 my $id_stop = $id_start + COMMENT_PAGE_LENGTH();
1398 my $older = ($page > 0) ? ($page-1) : '';
1401 if ($id_stop >= $post_count) {
1402 $id_stop = $post_count;
1409 my $words_url = merge_url(
1410 {'path' => CGI_VIEWER_PATH()},
1413 'query' => {'b' => TEXT_MODE->{'words'}},
1416 my $older_url = merge_url(
1419 'query' => {'i' => $page-1},
1420 'fragment' => 'insw',
1424 my $newer_url = merge_url(
1427 'query' => {'i' => $page+1},
1428 'fragment' => 'insw',
1434 $password_query = url_query_encode({'p', $settings->{'password'}});
1435 $older_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1436 $newer_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1439 my $_post_url = html_entity_encode_dec(CGI_WORDS_PATH(), 1);
1440 my $_password = html_entity_encode_dec($settings->{'password'}, 1);
1441 my $_older_url = html_entity_encode_dec($older_url, 1);
1442 my $_newer_url = html_entity_encode_dec($newer_url, 1);
1444 if (($older ne '') || ($newer ne '')) {
1445 $links .= ' <div class="underlinks">'."\n";
1448 $links .= '<a href="'.$_older_url.'">Older</a>'
1450 if (($older ne '') && ($newer ne '')) {
1454 $links .= '<a href="'.$_newer_url.'">Newer</a>';
1457 $links .= ' </div>'."\n";
1460 print $fh ' <div class="space"></div>'."\n";
1461 print $fh ' <div id="insw" class="ins">'."\n";
1463 print $fh ' <div class="title" id="wordstitle">'."\n";
1464 print $fh ' <h1 class="titletext" id="wordstitletext">Words</h1>'."\n";
1465 print $fh ' </div>'."\n";
1471 print $fh ' <div class="undertext" id="words">'."\n";
1473 if ($post_count > 0) {
1474 for (my $i=$id_start; $i<$id_stop; ++$i) {
1475 my $ID = $words_data->{'content'}->[$i];
1476 my $post_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $ID);
1477 my %post_data = read_data_file($post_path);
1479 my $post_time = int($post_data{'posttime'});
1480 my $edit_time = int($post_data{'edittime'});
1485 if ($post_time != 0) {
1486 my @time_tab = gmtime($post_time);
1487 $post_time_text = sprintf(
1488 '%04d.%02d.%02d %02d:%02d:%02d UTC',
1497 if (($edit_time !=0) && ($edit_time != $post_time)) {
1498 my @time_tab = gmtime($edit_time);
1499 $edit_time_text = sprintf(
1500 '%04d.%02d.%02d %02d:%02d UTC',
1508 my $quote_url = merge_url(
1509 {'path' => CGI_WORDS_PATH()},
1514 'p' => ($password_ok ? $settings->{'password'} : '')
1518 my $edit_url = merge_url(
1519 {'path' => CGI_WORDS_PATH()},
1524 'key' => $post_data{'key'},
1525 'username' => $post_data{'name'},
1526 'p' => ($password_ok ? $settings->{'password'} : '')
1530 my $remove_url = merge_url(
1531 {'path' => CGI_WORDS_PATH()},
1536 'key' => $post_data{'key'},
1537 'username' => $post_data{'name'},
1538 'p' => ($password_ok ? $settings->{'password'} : '')
1543 my $_ID = html_entity_encode_dec($ID, 1);
1544 my $_name = html_entity_encode_dec($post_data{'name'}, 1);
1545 my $_quote_url = html_entity_encode_dec($quote_url, 1);
1546 my $_edit_url = html_entity_encode_dec($edit_url, 1);
1547 my $_remove_url = html_entity_encode_dec($remove_url, 1);
1549 print $fh ' <div id="'.$_ID.'"class="opomba">'."\n";
1550 print $fh ' <div class="opomba_info">'."\n";
1551 print $fh ' <a href="#'.$_ID.'" class="bi hu">'.$i.': '.$_name;
1552 if ($post_time_text ne '') {
1553 print $fh ' • '.$post_time_text;
1555 if ($edit_time_text ne '') {
1556 print $fh ' • '.$edit_time_text;
1558 print $fh '</a>'."\n";
1559 print $fh ' <div class="pr">'."\n";
1560 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";
1561 print $fh ' </div>'."\n";
1562 print $fh ' </div>'."\n";
1563 print $fh ' <div class="opomba_text">'."\n";
1564 print $fh bb_to_html(
1566 $post_data{'content'},
1568 $password_ok ? $settings->{'password'} : ''
1571 print $fh ' </div>'."\n";
1572 print $fh ' </div>'."\n";
1573 print $fh ' <br>'."\n";
1577 print $fh ' <form method="post" action="'.$_post_url.'">'."\n";
1578 print $fh ' <b>Your words:</b>'."\n";
1579 print $fh ' <textarea class="inta" name="words" rows="4"></textarea>'."\n";
1580 print $fh ' <table cellpadding="0" cellspacing="0" border="0"><tr>'."\n";
1581 print $fh ' <td><b>Your name: </b></td>'."\n";
1582 print $fh ' <td><input class="intx" type="text" name="username" value=""></td>'."\n";
1583 print $fh ' <td></td>'."\n";
1584 print $fh ' </tr><tr>'."\n";
1585 print $fh ' <td><b>Optional password: </b></td>'."\n";
1586 print $fh ' <td><input class="intx" type="password" name="password" value=""></td>'."\n";
1587 print $fh ' <td>(if you want to edit later)</td>'."\n";
1588 print $fh ' </tr><tr>'."\n";
1589 print $fh ' <td><b>Leave this empty: </b></td>'."\n";
1590 print $fh ' <td><input class="intx" type="text" name="password2" value=""></td>'."\n";
1591 print $fh ' <td>'."\n";
1592 print $fh ' <input class="inbt" type="submit" name="post" value="Send">'."\n";
1593 print $fh ' <input class="inbt" type="submit" name="preview" value="Preview">'."\n";
1594 print $fh ' </td>'."\n";
1595 print $fh ' </tr></table>'."\n";
1596 print $fh ' <input type="hidden" name="f" value="'.$frame.'">'."\n";
1598 print $fh ' <input type="hidden" name="p" value="'.$_password.'">'."\n";
1600 print $fh ' </form>'."\n";
1601 print $fh ' </div>'."\n";
1607 print $fh ' </div>'."\n";
1620 my $ong_state = int($state->{'state'});
1622 unless (open_encoded($fh, ">:encoding(UTF-8)", WWW_INDEX_PATH())) {
1626 # normal running story
1627 if ($ong_state > STATE->{'inactive'}) {
1628 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1629 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1630 my %default = read_data_file(DATA_DEFAULT_PATH());
1631 my %words_data = read_data_file(
1632 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), 0),
1639 %frame_data = merge_settings(\%default, \%frame_data);
1640 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1642 $r = print_viewer_page(
1649 'timer_unlocked' => 3, # not relevant
1650 'timer' => 0, # not relevant
1652 'show_command' => 1,
1653 'text_mode' => TEXT_MODE->{'normal'},
1654 'words_page' => 0 # not relevant
1664 # no conditions met, pretend a normal Apache2 index
1665 elsif ($pass != 1) {
1666 my $index_of = CGI_PATH;
1667 $index_of =~ s/\/$//g;
1669 my $_index_of = html_entity_encode_dec($index_of , 1);
1670 my $_2words_date = html_entity_encode_dec(INTF_DATE(), 1);
1671 my $_coin_date = html_entity_encode_dec(COIN_DATE(), 1);
1672 my $_website = html_entity_encode_dec(WEBSITE() , 1);
1674 print_html_start ($fh);
1675 print $fh ' <head>'."\n";
1676 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
1677 print $fh ' <title>Index of '.$_index_of.'</title>'."\n";
1678 print $fh ' </head>'."\n";
1679 print $fh ' <body>'."\n";
1680 print $fh ' <h1>Index of '.$_index_of.'</h1>'."\n";
1681 print $fh ' <table>'."\n";
1682 print $fh ' <tr>'."\n";
1683 print $fh ' <th><img src="/icons/blank.gif" alt="[ICO]"></th>'."\n";
1684 print $fh ' <th><a href="?C=N;O=D">Name</a></th>'."\n";
1685 print $fh ' <th><a href="?C=M;O=A">Last modified</a></th>'."\n";
1686 print $fh ' <th><a href="?C=S;O=A">Size</a></th>'."\n";
1687 print $fh ' <th><a href="?C=D;O=A">Description</a></th>'."\n";
1688 print $fh ' </tr><tr>'."\n";
1689 print $fh ' <th colspan="5"><hr></th>'."\n";
1690 print $fh ' </tr><tr>'."\n";
1691 print $fh ' <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>'."\n";
1692 print $fh ' <td><a href="/">Parent Directory</a></td>'."\n";
1693 print $fh ' <td> </td>'."\n";
1694 print $fh ' <td align="right"> - </td>'."\n";
1695 print $fh ' <td> </td>'."\n";
1696 print $fh ' </tr><tr>'."\n";
1697 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1698 print $fh ' <td><a href="2words/">2words/</a></td>'."\n";
1699 print $fh ' <td align="right">'.$_2words_date.' </td>'."\n";
1700 print $fh ' <td align="right"> - </td><td> </td>'."\n";
1701 print $fh ' </tr><tr>'."\n";
1702 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1703 print $fh ' <td><a href="coin/">coin/</a></td>'."\n";
1704 print $fh ' <td align="right">'.$_coin_date.' </td>'."\n";
1705 print $fh ' <td align="right"> - </td><td> Coincidence </td>'."\n";
1706 print $fh ' </tr><tr>'."\n";
1707 print $fh ' <th colspan="5"><hr></th>'."\n";
1708 print $fh ' </tr>'."\n";
1709 print $fh ' </table>'."\n";
1710 print $fh ' <address>Apache/2.2.22 (Debian) Server at '.$_website.' Port 80</address>'."\n";
1711 print $fh ' </body>'."\n";
1712 print_html_end ($fh);
1716 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1717 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1718 my %default = read_data_file(DATA_DEFAULT_PATH());
1719 my %coin_data = read_data_file(DATA_COIN_PATH());
1721 %frame_data = merge_settings(\%default, \%frame_data);
1722 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1724 if (($mode == INTF_STATE->{'>'}) && $pause) {
1725 $r = print_viewer_page(
1732 'timer_unlocked' => 3,
1735 'show_command' => 1,
1736 'text_mode' => TEXT_MODE->{'normal'},
1737 'words_page' => 0 # not relevant
1744 {'posts' => 0} # words_data
1749 my $index_of = CGI_PATH;
1750 $index_of =~ s/\/$//g;
1754 my $show_parent_dir = 0;
1756 my $show_folders = 0;
1758 my $timer_color = 'ni';
1759 if ($mode == INTF_STATE->{'>'}) {
1760 $title = $settings->{'story'}; # $frame_data{'title'} ?
1761 $frame_file = 'intf-tr.gif';
1765 elsif ($mode == INTF_STATE->{'<<'}) {
1766 $title = 'Index of';
1767 $frame_file = 'intf-ll.gif';
1768 $show_parent_dir = 1;
1771 $timer_color = 'br';
1773 elsif ($mode == INTF_STATE->{'>>'}) {
1774 $title = 'Index of';
1775 $frame_file = 'intf-pp.gif';
1776 $show_parent_dir = 1;
1782 $title = 'Index of '.$index_of;
1783 $frame_file = 'intf-kw.gif';
1784 $show_parent_dir = 1;
1787 my $frame_url = merge_url(
1788 {'path' => CGI_PATH()},
1789 {'path' => $frame_file}
1791 my $coin_server = $coin_data{'server'};
1793 my $_title = html_entity_encode_dec($title , 1);
1794 my $_website_name = html_entity_encode_dec(WEBSITE_NAME() , 1);
1795 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1796 my $_undertext = html_entity_encode_dec($undertext , 1);
1797 my $_2words_date = html_entity_encode_dec(INTF_DATE() , 1);
1798 my $_coin_date = html_entity_encode_dec(COIN_DATE() , 1);
1799 my $_coin_server = html_entity_encode_dec($coin_server , 1);
1800 my $_2words_url = html_entity_encode_dec(CGI_2WORDS_PATH(), 1);
1801 my $_coin_url = html_entity_encode_dec(CGI_COIN_PATH() , 1);
1803 print_html_start($fh);
1804 print_html_head_start($fh);
1806 print $fh ' <title>'.$_title.' • '.$_website_name.'</title>'."\n";
1808 print_html_head_end($fh);
1809 print_html_body_start($fh);
1811 print $fh ' <div id="inst" class="ins">'."\n";
1813 print $fh ' <div id="title">'."\n";
1814 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1815 print $fh ' </div>'."\n";
1817 print $fh ' </div>'."\n";
1818 print $fh ' <div id="framespace">'."\n";
1820 print $fh ' <img src="'.$_frame_url.'" id="frame" alt="0">'."\n"; # title="'.$_title.'"
1822 print $fh ' </div>'."\n";
1823 print $fh ' <div id="insb" class="ins">'."\n";
1825 print $fh ' <div id="undertext">'."\n";
1827 if ($show_parent_dir) {
1828 print $fh ' <img src="/icons/back.gif" alt="[DIR]"> <a href="..">Parent Directory</a><br>'."\n";
1830 if ($show_folders) {
1831 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">2words/</a> '.$_2words_date.' - <br>'."\n";
1832 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_coin_url.'">coin/</a> '.$_coin_date.' - '.$_coin_server."\n";
1835 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">yyyyb/</a>'."\n";
1837 if ($undertext ne '') {
1838 print $fh ' '.$_undertext."\n";
1841 print $fh ' </div>'."\n";
1844 print $fh ' <div id="command">'."\n";
1846 print $fh ' [<span id="ongh" class="'.$timer_color.'">'.$timer.'</span>';
1847 print $fh ':<span id="ongm" class="'.$timer_color.'">'.$timer.'</span>';
1848 print $fh ':<span id="ongs" class="'.$timer_color.'">'.$timer.'</span>]<br>'."\n";
1850 if ($undertext ne '') {
1851 print $fh '><a href="'.$_2words_url.'">'.$_undertext.'</a><span class="inp">_</span>'."\n";
1853 print $fh " </div>\n";
1856 print $fh " </div>\n";
1858 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1859 print_html_end($fh);
1865 sub write_static_viewer_page {
1872 my $prev_frame_data_ref,
1873 my $next_frame_data_ref,
1881 my %prev_frame_data;
1882 my %next_frame_data;
1887 $frame = int($frame);
1888 my $prev_frame = $frame -1;
1889 my $next_frame = $frame +1;
1891 %state = (ref ($state_ref)) ?
1893 read_data_file(DATA_STATE_PATH());
1894 my $ong_state = int($state{'state'});
1895 my $last_frame = int($state{'last'});
1897 unless ($ong_state > STATE->{'inactive'}) {
1902 ($frame < $last_frame) || (
1903 ($frame <= $last_frame) &&
1904 ($ong_state >= STATE->{'end'})
1911 %settings = (ref ($settings_ref)) ?
1913 read_data_file(DATA_SETTINGS_PATH());
1914 %default = (ref ($default_ref)) ?
1916 read_data_file(DATA_DEFAULT_PATH());
1918 %frame_data = (ref ($frame_data_ref)) ?
1920 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $frame));
1922 %prev_frame_data = (ref ($prev_frame_data_ref)) ?
1923 %$prev_frame_data_ref : (
1924 ($prev_frame >= 0) ?
1925 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $prev_frame)) :
1929 %next_frame_data = (ref ($next_frame_data_ref)) ?
1930 %$next_frame_data_ref : (
1931 (($next_frame < $last_frame) || (
1932 ($next_frame <= $last_frame) &&
1933 ($next_frame >= STATE->{'end'})
1935 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $next_frame)) :
1939 %frame_data = merge_settings(\%default, \%frame_data);
1940 %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
1941 %next_frame_data = merge_settings(\%default, \%next_frame_data);
1943 %words_data = (ref ($words_data_ref)) ?
1946 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $frame), # file
1950 1, # as list; not relevant
1953 if ($frame_data{'page'} ne '') {
1954 $file = $frame_data{'page'}
1962 $file = join_path(PATH_SEPARATOR(), WWW_PATH(), $file);
1964 return print_viewer_page(
1971 'timer_unlocked'=> 3, # not relevant
1972 'timer' => 0, # not relevant
1974 'show_command' => 1,
1975 'text_mode' => TEXT_MODE->{'normal'},
1976 'words_page' => 0, # not relevant
1987 sub write_static_goto {
1991 # ONG the frame + attachment & stuff. NOT update state file.
1994 my $ID, my $ongtime, my $timer, my $update, my $print,
1995 my $settings_ref, my $default_ref, my $data_ref, my $goto_ref
2001 my $frame_data_path;
2009 my %frame_full_data;
2012 if ($ongtime eq '') {
2019 elsif ($ID eq 'c') {
2051 %settings = (ref ($settings_ref)) ?
2053 read_data_file(DATA_SETTINGS_PATH());
2054 %default = (ref ($default_ref)) ?
2056 read_data_file(DATA_DEFAULT_PATH());
2057 $frame_data_path = $cfrt ?
2058 DATA_NOACCESS_PATH() :
2059 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
2060 %frame_data = (ref ($data_ref)) ?
2062 read_data_file($frame_data_path);
2063 %frame_full_data = merge_settings(\%default, \%frame_data);
2065 ($frame_full_data{'frame'} ne '') ?
2066 $frame_full_data{'frame'} :
2069 $frame, $frame_full_data{'ext'}
2074 %goto_list = (ref ($goto_ref)) ?
2076 read_data_file(DATA_LIST_PATH());
2077 for (my $i=0; ;$i+=1) {
2078 my %file_data = read_data_file(DATA_ATTACH_PATH().$i);
2079 if ($file_data{'frame'} eq '') {
2082 if (int($file_data{'frame'}) != $frame) {
2085 if ($file_data{'content'} ne '') {
2088 unshift @files, $file_data{'filename'};
2092 ($frame_full_data{'ongtime'} eq '')
2094 $frame_data {'ongtime'} = $ongtime;
2095 $frame_full_data{'ongtime'} = $ongtime;
2101 ($frame_full_data{'timer'} eq '')
2104 $frame_data{'timer'} = int($timer);
2108 $r = write_data_file($frame_data_path, \%frame_data);
2110 print STDERR "fail writing $frame_data_path\n";
2112 print "write frame data fail\n";
2117 $goto_list{'title-' .$frame} = $frame_full_data{'title'};
2118 $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
2119 $r = write_data_file(DATA_LIST_PATH(), \%goto_list);
2121 print STDERR "fail writing ".DATA_LIST_PATH()."\n";
2123 print "write GOTO list fail\n";
2129 foreach my $file (@files) {
2130 $in_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file);
2131 $out_path = join_path(PATH_SEPARATOR(), WWW_PATH() , $file);
2133 print $in_path.' -> '.$out_path;
2135 $r = copy_encoded($in_path, $out_path);
2137 print (($r) ? " OK\n" : " FAIL\n");
2140 print STDERR "fail copy $in_path $out_path\n";