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',
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 my $bbcode_url = ($text_mode == TEXT_MODE->{'bb'}) ?
1025 {'path' => CGI_BBCODE_PATH()},
1032 'b' => TEXT_MODE->{'bb'}
1037 my $info_url = ($text_mode == TEXT_MODE->{'info'}) ?
1039 {'path' => CGI_INFO_PATH()},
1046 'b' => TEXT_MODE->{'info'}
1051 my $words_url = merge_url (
1055 'b' => TEXT_MODE->{'words'}
1064 my $frame_normal_url;
1066 if ($frame_data->{'frame'} ne '') {
1067 $frame_file = $frame_data->{'frame'};
1070 $frame_file = sprintf(
1071 $settings->{'frame'},
1072 $frame, $frame_data->{'ext'}
1075 $frame_normal_url = merge_url(
1076 {'path' => CGI_PATH()},
1077 {'path' => $frame_file}
1079 $frame_url = $frame_indirect ?
1081 {'path' => CGI_FRAME_PATH()},
1085 $frame_full_url = merge_url(
1086 {'scheme' => SCHEME(), 'host' => WEBSITE()},
1087 {'path' => $frame_normal_url}
1089 if ($prevframe_indirect) {
1090 $frame_prev_url = merge_url(
1091 {'path' => CGI_FRAME_PATH()},
1092 {'path' => $prev_frame}
1095 elsif ($prev_frame_data->{'frame'} ne '') {
1096 $frame_prev_url = merge_url(
1097 {'path' => CGI_PATH()},
1098 {'path' => $prev_frame_data->{'frame'}}
1102 $frame_prev_url = merge_url(CGI_PATH(), sprintf(
1103 $settings->{'frame'}, $prev_frame, $prev_frame_data->{'ext'}
1106 if ($nextframe_indirect) {
1107 $frame_next_url = merge_url(
1108 {'path' => CGI_FRAME_PATH()},
1109 {'path' => $next_frame}
1112 elsif ($next_frame_data->{'frame'} ne '') {
1113 $frame_next_url = merge_url(
1114 {'path' => CGI_PATH()},
1115 {'path' => $next_frame_data->{'frame'}}
1119 $frame_next_url = merge_url(CGI_PATH(), sprintf(
1120 $settings->{'frame'}, $next_frame, $next_frame_data->{'ext'}
1125 $password_query = url_query_encode({'p', $settings->{'password'}});
1126 $goto_url = merge_url($goto_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1127 $info_url = merge_url($info_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1128 $words_url = merge_url($words_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1129 $bbcode_url = merge_url($bbcode_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1130 $viewer_url = merge_url($viewer_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1131 $viewer_0_url = merge_url($viewer_0_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1132 $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1133 $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1134 $viewer_last_url = merge_url($viewer_last_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1135 if ($frame_indirect) {
1136 $frame_url = merge_url($frame_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1138 if ($prevframe_indirect) {
1139 $frame_prev_url= merge_url($frame_prev_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1141 if ($nextframe_indirect) {
1142 $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1145 my $_base_url = html_entity_encode_dec($base_url , 1);
1146 my $_goto_url = html_entity_encode_dec($goto_url , 1);
1147 my $_info_url = html_entity_encode_dec($info_url , 1);
1148 my $_words_url = html_entity_encode_dec($words_url , 1);
1149 my $_bbcode_url = html_entity_encode_dec($bbcode_url , 1);
1150 my $_timer_url = html_entity_encode_dec($timer_url , 1);
1151 my $_viewer_full_url = html_entity_encode_dec($viewer_full_url, 1);
1152 my $_viewer_url = html_entity_encode_dec($viewer_url , 1);
1153 my $_viewer_0_url = html_entity_encode_dec($viewer_0_url , 1);
1154 my $_viewer_prev_url = html_entity_encode_dec($viewer_prev_url, 1);
1155 my $_viewer_next_url = html_entity_encode_dec($viewer_next_url, 1);
1156 my $_viewer_last_url = html_entity_encode_dec($viewer_last_url, 1);
1157 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1158 my $_frame_prev_url = html_entity_encode_dec($frame_prev_url , 1);
1159 my $_frame_next_url = html_entity_encode_dec($frame_next_url , 1);
1160 my $_frame_full_url = html_entity_encode_dec($frame_full_url , 1);
1162 my $_story = html_entity_encode_dec($story , 1);
1163 my $_title = html_entity_encode_dec($title , 1);
1164 my $_command = html_entity_encode_dec($command , 1);
1165 my $_frame_type = html_entity_encode_dec($frame_type, 1);
1167 my $_website_name = html_entity_encode_dec(WEBSITE_NAME(), 1);
1169 if ($text_mode == TEXT_MODE->{'info'}) {
1170 if ($show_command) {
1171 $frame_data->{'command'} = $command;
1173 if ($context->{'access'}) {
1174 $frame_data->{'frame'} = $frame_file;
1178 # everything determined, now start generating
1182 unless (seek($fh, 0, 0)) {
1183 #don't actually fail here
1187 unless (open_encoded($fh, ">:encoding(UTF-8)", $file)) {
1192 print_html_start($fh);
1193 print_html_head_start($fh);
1195 print $fh ' <title>'.$_title;
1196 if ($story ne $title) {
1197 print $fh ' • '.$_story;
1199 print $fh ' • '.$_website_name.'</title>'."\n";
1200 print $fh ' <link rel="index" href="'.$_goto_url.'">'."\n";
1201 print $fh ' <link rel="start" href="'.$_viewer_0_url.'">'."\n";
1202 if ($prev_available) {
1203 print $fh ' <link rel="prev" href="'.$_viewer_prev_url.'">'."\n";
1204 if ($prefetch_prev) {
1205 print $fh ' <link rel="prefetch" href="'.$_viewer_prev_url.'">'."\n";
1206 print $fh ' <link rel="prefetch" href="'.$_frame_prev_url.'">'."\n";
1209 if ($next_available) {
1210 print $fh ' <link rel="next" href="'.$_viewer_next_url.'">'."\n";
1211 if ($prefetch_next) {
1212 print $fh ' <link rel="prefetch" href="'.$_viewer_next_url.'">'."\n";
1213 print $fh ' <link rel="prefetch" href="'.$_frame_next_url.'">'."\n";
1217 print $fh ' <script src="'.$_timer_url.'"></script>'."\n";
1220 print_html_head_end($fh);
1221 print_html_body_start($fh);
1223 print $fh ' <div id="inst" class="ins">'."\n";
1225 print $fh ' <div id="title">'."\n";
1226 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1227 print $fh ' </div>'."\n";
1229 print $fh ' </div>'."\n";
1230 print $fh ' <div id="framespace">'."\n";
1232 print $fh ' <img src="'.$_frame_url.'" id="frame" class="'.$_frame_type.'" alt="'.$frame.'" title="'.$_title.'" width="'.$width.'" height="'.$height.'">'."\n";
1234 print $fh ' </div>'."\n";
1235 print $fh ' <div id="insb" class="ins">'."\n";
1237 if ($text_mode == TEXT_MODE->{'info'}) {
1238 print $fh ' <div id="chat">'."\n";
1240 print_html_data($fh, $frame_data);
1242 print $fh ' </div>'."\n";
1244 elsif ($text_mode == TEXT_MODE->{'bb'}) {
1245 print $fh ' <div id="chat">'."\n";
1247 print $fh '[quote][center][size=200]'.$_title.'[/size]<br>'."\n";
1248 print $fh '[url='.$_viewer_full_url.'][img]'.$_frame_full_url.'[/img][/url][/center]<br>'."\n";
1249 print $fh html_encode_line(
1252 $frame_data->{'content'},
1257 print $fh '[/quote]'."\n";
1259 print $fh ' </div>'."\n";
1261 elsif ($frame_data->{'content'} ne '') {
1262 print $fh ' <div id="undertext">'."\n";
1263 print $fh bb_to_html(
1265 $frame_data->{'content'},
1267 $password_ok ? $settings->{'password'} : ''
1270 print $fh ' </div>'."\n";
1273 print $fh ' <div id="command">'."\n";
1276 print $fh ' <span id="timer">';
1277 print $fh '[<span id="ongh" class="hv '.$timer_color_h.'">'.$timer_h.'</span>';
1278 print $fh ':<span id="ongm" class="hv '.$timer_color_m.'">'.$timer_m.'</span>';
1279 print $fh ':<span id="ongs" class="hv '.$timer_color_s.'">'.$timer_s.'</span>]';
1280 print $fh '</span><br>'."\n";
1283 if ($show_command_link) {
1284 print $fh '<a href="'.($access ? $_viewer_next_url : $_viewer_last_url).'">';
1286 if ($show_command) {
1287 print $fh $_command;
1289 if ($show_command_cursor) {
1290 print $fh '<span class="inp">_</span>';
1292 if ($show_command_link) {
1296 print $fh " </div>\n";
1298 print $fh ' <div id="underlinks">'."\n ";
1300 unless (($frame == 0) && $static) {
1301 print $fh '<a href="'.$_base_url.'">Once again</a> | ';
1303 if ($prev_available) {
1304 print $fh '<a href="'.$_viewer_prev_url.'">Before</a> | ';
1306 unless ($frame == $last_frame) {
1307 print $fh '<a href="'.$_viewer_last_url.'">Now</a> | ';
1309 print $fh '<a href="'.$_goto_url.'">GOTO</a>'."\n";
1310 print $fh ' <span style="float: right;">'."\n ";
1311 if ($text_mode == TEXT_MODE->{'normal'}) {
1313 print $fh '<a href="'.$_words_url.'">'.$words_link_text.'</a> | ';
1317 print $fh '<a href="'.$_viewer_url.'">Without</a> | ';
1319 print $fh '<a href="'.$_info_url.'">Info</a> | ';
1320 print $fh '<a href="'.$_bbcode_url.'">BB</a>';
1321 print $fh "\n </span>\n";
1323 print $fh " </div>\n";
1324 print $fh " </div>\n";
1326 if (($text_mode == TEXT_MODE->{'words'}) && $show_words) {
1327 print_comments($fh, $context, $settings, $words_data);
1330 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1331 print_html_end($fh);
1334 unless (ref($file)) {
1338 truncate ($fh , tell($fh));
1344 sub print_comments {
1345 (my $fh, my $context, my $settings, my $words_data) = @_;
1347 my $password_ok = $context->{'password_ok'};
1348 my $frame = int($context->{'frame'});
1349 my $page = int($context->{'words_page'});
1350 my $post_count = int($words_data->{'posts'});
1351 my $id_start = $page * COMMENT_PAGE_LENGTH();
1352 my $id_stop = $id_start + COMMENT_PAGE_LENGTH();
1353 my $older = ($page > 0) ? ($page-1) : '';
1356 if ($id_stop >= $post_count) {
1357 $id_stop = $post_count;
1364 my $words_url = merge_url(
1365 {'path' => CGI_VIEWER_PATH()},
1368 'query' => {'b' => TEXT_MODE->{'words'}},
1371 my $older_url = merge_url(
1374 'query' => {'i' => $page-1},
1375 'fragment' => 'insw',
1379 my $newer_url = merge_url(
1382 'query' => {'i' => $page+1},
1383 'fragment' => 'insw',
1389 $password_query = url_query_encode({'p', $settings->{'password'}});
1390 $older_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1391 $newer_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1394 my $_post_url = html_entity_encode_dec(CGI_WORDS_PATH(), 1);
1395 my $_password = html_entity_encode_dec($settings->{'password'}, 1);
1396 my $_older_url = html_entity_encode_dec($older_url, 1);
1397 my $_newer_url = html_entity_encode_dec($newer_url, 1);
1399 if (($older ne '') || ($newer ne '')) {
1400 $links .= ' <div class="underlinks">'."\n";
1403 $links .= '<a href="'.$_older_url.'">Older</a>'
1405 if (($older ne '') && ($newer ne '')) {
1409 $links .= '<a href="'.$_newer_url.'">Newer</a>';
1412 $links .= ' </div>'."\n";
1415 print $fh ' <div class="space"></div>'."\n";
1416 print $fh ' <div id="insw" class="ins">'."\n";
1418 print $fh ' <div class="title" id="wordstitle">'."\n";
1419 print $fh ' <h1 class="titletext" id="wordstitletext">Words</h1>'."\n";
1420 print $fh ' </div>'."\n";
1426 print $fh ' <div class="undertext" id="words">'."\n";
1428 if ($post_count > 0) {
1429 for (my $i=$id_start; $i<$id_stop; ++$i) {
1430 my $ID = $words_data->{'content'}->[$i];
1431 my $post_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $ID);
1432 my %post_data = read_data_file($post_path);
1434 my $post_time = int($post_data{'posttime'});
1435 my $edit_time = int($post_data{'edittime'});
1440 if ($post_time != 0) {
1441 my @time_tab = gmtime($post_time);
1442 $post_time_text = sprintf(
1443 '%04d.%02d.%02d %02d:%02d:%02d UTC',
1452 if (($edit_time !=0) && ($edit_time != $post_time)) {
1453 my @time_tab = gmtime($edit_time);
1454 $edit_time_text = sprintf(
1455 '%04d.%02d.%02d %02d:%02d UTC',
1463 my $quote_url = merge_url(
1464 {'path' => CGI_WORDS_PATH()},
1469 'p' => ($password_ok ? $settings->{'password'} : '')
1473 my $edit_url = merge_url(
1474 {'path' => CGI_WORDS_PATH()},
1479 'key' => $post_data{'key'},
1480 'username' => $post_data{'name'},
1481 'p' => ($password_ok ? $settings->{'password'} : '')
1485 my $remove_url = merge_url(
1486 {'path' => CGI_WORDS_PATH()},
1491 'key' => $post_data{'key'},
1492 'username' => $post_data{'name'},
1493 'p' => ($password_ok ? $settings->{'password'} : '')
1498 my $_ID = html_entity_encode_dec($ID, 1);
1499 my $_name = html_entity_encode_dec($post_data{'name'}, 1);
1500 my $_quote_url = html_entity_encode_dec($quote_url, 1);
1501 my $_edit_url = html_entity_encode_dec($edit_url, 1);
1502 my $_remove_url = html_entity_encode_dec($remove_url, 1);
1504 print $fh ' <div id="'.$_ID.'"class="opomba">'."\n";
1505 print $fh ' <div class="opomba_info">'."\n";
1506 print $fh ' <a href="#'.$_ID.'" class="bi hu">'.$i.': '.$_name;
1507 if ($post_time_text ne '') {
1508 print $fh ' • '.$post_time_text;
1510 if ($edit_time_text ne '') {
1511 print $fh ' • '.$edit_time_text;
1513 print $fh '</a>'."\n";
1514 print $fh ' <div class="pr">'."\n";
1515 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";
1516 print $fh ' </div>'."\n";
1517 print $fh ' </div>'."\n";
1518 print $fh ' <div class="opomba_text">'."\n";
1519 print $fh bb_to_html(
1521 $post_data{'content'},
1523 $password_ok ? $settings->{'password'} : ''
1526 print $fh ' </div>'."\n";
1527 print $fh ' </div>'."\n";
1528 print $fh ' <br>'."\n";
1532 print $fh ' <form method="post" action="'.$_post_url.'">'."\n";
1533 print $fh ' <b>Your words:</b>'."\n";
1534 print $fh ' <textarea class="inta" name="words" rows="4"></textarea>'."\n";
1535 print $fh ' <table cellpadding="0" cellspacing="0" border="0"><tr>'."\n";
1536 print $fh ' <td><b>Your name: </b></td>'."\n";
1537 print $fh ' <td><input class="intx" type="text" name="username" value=""></td>'."\n";
1538 print $fh ' <td></td>'."\n";
1539 print $fh ' </tr><tr>'."\n";
1540 print $fh ' <td><b>Optional password: </b></td>'."\n";
1541 print $fh ' <td><input class="intx" type="password" name="password" value=""></td>'."\n";
1542 print $fh ' <td>(if you want to edit later)</td>'."\n";
1543 print $fh ' </tr><tr>'."\n";
1544 print $fh ' <td><b>Leave this empty: </b></td>'."\n";
1545 print $fh ' <td><input class="intx" type="text" name="password2" value=""></td>'."\n";
1546 print $fh ' <td>'."\n";
1547 print $fh ' <input class="inbt" type="submit" name="post" value="Send">'."\n";
1548 print $fh ' <input class="inbt" type="submit" name="preview" value="Preview">'."\n";
1549 print $fh ' </td>'."\n";
1550 print $fh ' </tr></table>'."\n";
1551 print $fh ' <input type="hidden" name="f" value="'.$frame.'">'."\n";
1553 print $fh ' <input type="hidden" name="p" value="'.$_password.'">'."\n";
1555 print $fh ' </form>'."\n";
1556 print $fh ' </div>'."\n";
1562 print $fh ' </div>'."\n";
1575 my $ong_state = int($state->{'state'});
1577 unless (open_encoded($fh, ">:encoding(UTF-8)", WWW_INDEX_PATH())) {
1581 # normal running story
1582 if ($ong_state > STATE->{'inactive'}) {
1583 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1584 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1585 my %default = read_data_file(DATA_DEFAULT_PATH());
1586 my %words_data = read_data_file(
1587 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), 0),
1594 %frame_data = merge_settings(\%default, \%frame_data);
1595 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1597 $r = print_viewer_page(
1604 'timer_unlocked' => 3, # not relevant
1605 'timer' => 0, # not relevant
1607 'show_command' => 1,
1608 'text_mode' => TEXT_MODE->{'normal'},
1609 'words_page' => 0 # not relevant
1619 # no conditions met, pretend a normal Apache2 index
1620 elsif ($pass != 1) {
1621 my $index_of = CGI_PATH;
1622 $index_of =~ s/\/$//g;
1624 my $_index_of = html_entity_encode_dec($index_of , 1);
1625 my $_2words_date = html_entity_encode_dec(INTF_DATE(), 1);
1626 my $_coin_date = html_entity_encode_dec(COIN_DATE(), 1);
1627 my $_website = html_entity_encode_dec(WEBSITE() , 1);
1629 print_html_start ($fh);
1630 print $fh ' <head>'."\n";
1631 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
1632 print $fh ' <title>Index of '.$_index_of.'</title>'."\n";
1633 print $fh ' </head>'."\n";
1634 print $fh ' <body>'."\n";
1635 print $fh ' <h1>Index of '.$_index_of.'</h1>'."\n";
1636 print $fh ' <table>'."\n";
1637 print $fh ' <tr>'."\n";
1638 print $fh ' <th><img src="/icons/blank.gif" alt="[ICO]"></th>'."\n";
1639 print $fh ' <th><a href="?C=N;O=D">Name</a></th>'."\n";
1640 print $fh ' <th><a href="?C=M;O=A">Last modified</a></th>'."\n";
1641 print $fh ' <th><a href="?C=S;O=A">Size</a></th>'."\n";
1642 print $fh ' <th><a href="?C=D;O=A">Description</a></th>'."\n";
1643 print $fh ' </tr><tr>'."\n";
1644 print $fh ' <th colspan="5"><hr></th>'."\n";
1645 print $fh ' </tr><tr>'."\n";
1646 print $fh ' <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>'."\n";
1647 print $fh ' <td><a href="/">Parent Directory</a></td>'."\n";
1648 print $fh ' <td> </td>'."\n";
1649 print $fh ' <td align="right"> - </td>'."\n";
1650 print $fh ' <td> </td>'."\n";
1651 print $fh ' </tr><tr>'."\n";
1652 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1653 print $fh ' <td><a href="2words/">2words/</a></td>'."\n";
1654 print $fh ' <td align="right">'.$_2words_date.' </td>'."\n";
1655 print $fh ' <td align="right"> - </td><td> </td>'."\n";
1656 print $fh ' </tr><tr>'."\n";
1657 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1658 print $fh ' <td><a href="coin/">coin/</a></td>'."\n";
1659 print $fh ' <td align="right">'.$_coin_date.' </td>'."\n";
1660 print $fh ' <td align="right"> - </td><td> Coincidence </td>'."\n";
1661 print $fh ' </tr><tr>'."\n";
1662 print $fh ' <th colspan="5"><hr></th>'."\n";
1663 print $fh ' </tr>'."\n";
1664 print $fh ' </table>'."\n";
1665 print $fh ' <address>Apache/2.2.22 (Debian) Server at '.$_website.' Port 80</address>'."\n";
1666 print $fh ' </body>'."\n";
1667 print_html_end ($fh);
1671 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1672 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1673 my %default = read_data_file(DATA_DEFAULT_PATH());
1674 my %coin_data = read_data_file(DATA_COIN_PATH());
1676 %frame_data = merge_settings(\%default, \%frame_data);
1677 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1679 if (($mode == INTF_STATE->{'>'}) && $pause) {
1680 $r = print_viewer_page(
1687 'timer_unlocked' => 3,
1690 'show_command' => 1,
1691 'text_mode' => TEXT_MODE->{'normal'},
1692 'words_page' => 0 # not relevant
1699 {'posts' => 0} # words_data
1704 my $index_of = CGI_PATH;
1705 $index_of =~ s/\/$//g;
1709 my $show_parent_dir = 0;
1711 my $show_folders = 0;
1713 my $timer_color = 'ni';
1714 if ($mode == INTF_STATE->{'>'}) {
1715 $title = $settings->{'story'}; # $frame_data{'title'} ?
1716 $frame_file = 'intf-tr.gif';
1720 elsif ($mode == INTF_STATE->{'<<'}) {
1721 $title = 'Index of';
1722 $frame_file = 'intf-ll.gif';
1723 $show_parent_dir = 1;
1726 $timer_color = 'br';
1728 elsif ($mode == INTF_STATE->{'>>'}) {
1729 $title = 'Index of';
1730 $frame_file = 'intf-pp.gif';
1731 $show_parent_dir = 1;
1737 $title = 'Index of '.$index_of;
1738 $frame_file = 'intf-kw.gif';
1739 $show_parent_dir = 1;
1742 my $frame_url = merge_url(
1743 {'path' => CGI_PATH()},
1744 {'path' => $frame_file}
1746 my $coin_server = $coin_data{'server'};
1748 my $_title = html_entity_encode_dec($title , 1);
1749 my $_website_name = html_entity_encode_dec(WEBSITE_NAME() , 1);
1750 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1751 my $_undertext = html_entity_encode_dec($undertext , 1);
1752 my $_2words_date = html_entity_encode_dec(INTF_DATE() , 1);
1753 my $_coin_date = html_entity_encode_dec(COIN_DATE() , 1);
1754 my $_coin_server = html_entity_encode_dec($coin_server , 1);
1755 my $_2words_url = html_entity_encode_dec(CGI_2WORDS_PATH(), 1);
1756 my $_coin_url = html_entity_encode_dec(CGI_COIN_PATH() , 1);
1758 print_html_start($fh);
1759 print_html_head_start($fh);
1761 print $fh ' <title>'.$_title.' • '.$_website_name.'</title>'."\n";
1763 print_html_head_end($fh);
1764 print_html_body_start($fh);
1766 print $fh ' <div id="inst" class="ins">'."\n";
1768 print $fh ' <div id="title">'."\n";
1769 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1770 print $fh ' </div>'."\n";
1772 print $fh ' </div>'."\n";
1773 print $fh ' <div id="framespace">'."\n";
1775 print $fh ' <img src="'.$_frame_url.'" id="frame" alt="0">'."\n"; # title="'.$_title.'"
1777 print $fh ' </div>'."\n";
1778 print $fh ' <div id="insb" class="ins">'."\n";
1780 print $fh ' <div id="undertext">'."\n";
1782 if ($show_parent_dir) {
1783 print $fh ' <img src="/icons/back.gif" alt="[DIR]"> <a href="..">Parent Directory</a><br>'."\n";
1785 if ($show_folders) {
1786 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">2words/</a> '.$_2words_date.' - <br>'."\n";
1787 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_coin_url.'">coin/</a> '.$_coin_date.' - '.$_coin_server."\n";
1790 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">yyyyb/</a>'."\n";
1792 if ($undertext ne '') {
1793 print $fh ' '.$_undertext."\n";
1796 print $fh ' </div>'."\n";
1799 print $fh ' <div id="command">'."\n";
1801 print $fh ' [<span id="ongh" class="'.$timer_color.'">'.$timer.'</span>';
1802 print $fh ':<span id="ongm" class="'.$timer_color.'">'.$timer.'</span>';
1803 print $fh ':<span id="ongs" class="'.$timer_color.'">'.$timer.'</span>]<br>'."\n";
1805 if ($undertext ne '') {
1806 print $fh '><a href="'.$_2words_url.'">'.$_undertext.'</a><span class="inp">_</span>'."\n";
1808 print $fh " </div>\n";
1811 print $fh " </div>\n";
1813 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1814 print_html_end($fh);
1820 sub write_static_viewer_page {
1827 my $prev_frame_data_ref,
1828 my $next_frame_data_ref,
1836 my %prev_frame_data;
1837 my %next_frame_data;
1842 $frame = int($frame);
1843 my $prev_frame = $frame -1;
1844 my $next_frame = $frame +1;
1846 %state = (ref ($state_ref)) ?
1848 read_data_file(DATA_STATE_PATH());
1849 my $ong_state = int($state{'state'});
1850 my $last_frame = int($state{'last'});
1852 unless ($ong_state > STATE->{'inactive'}) {
1857 ($frame < $last_frame) || (
1858 ($frame <= $last_frame) &&
1859 ($ong_state >= STATE->{'end'})
1866 %settings = (ref ($settings_ref)) ?
1868 read_data_file(DATA_SETTINGS_PATH());
1869 %default = (ref ($default_ref)) ?
1871 read_data_file(DATA_DEFAULT_PATH());
1873 %frame_data = (ref ($frame_data_ref)) ?
1875 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $frame));
1877 %prev_frame_data = (ref ($prev_frame_data_ref)) ?
1878 %$prev_frame_data_ref : (
1879 ($prev_frame >= 0) ?
1880 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $prev_frame)) :
1884 %next_frame_data = (ref ($next_frame_data_ref)) ?
1885 %$next_frame_data_ref : (
1886 (($next_frame < $last_frame) || (
1887 ($next_frame <= $last_frame) &&
1888 ($next_frame >= STATE->{'end'})
1890 read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), $next_frame)) :
1894 %frame_data = merge_settings(\%default, \%frame_data);
1895 %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
1896 %next_frame_data = merge_settings(\%default, \%next_frame_data);
1898 %words_data = (ref ($words_data_ref)) ?
1901 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $frame), # file
1905 1, # as list; not relevant
1908 if ($frame_data{'page'} ne '') {
1909 $file = $frame_data{'page'}
1917 $file = join_path(PATH_SEPARATOR(), WWW_PATH(), $file);
1919 return print_viewer_page(
1926 'timer_unlocked'=> 3, # not relevant
1927 'timer' => 0, # not relevant
1929 'show_command' => 1,
1930 'text_mode' => TEXT_MODE->{'normal'},
1931 'words_page' => 0, # not relevant
1942 sub write_static_goto {
1946 # ONG the frame + attachment & stuff. NOT update state file.
1949 my $ID, my $ongtime, my $timer, my $update, my $print,
1950 my $settings_ref, my $default_ref, my $data_ref, my $goto_ref
1956 my $frame_data_path;
1964 my %frame_full_data;
1967 if ($ongtime eq '') {
1974 elsif ($ID eq 'c') {
2006 %settings = (ref ($settings_ref)) ?
2008 read_data_file(DATA_SETTINGS_PATH());
2009 %default = (ref ($default_ref)) ?
2011 read_data_file(DATA_DEFAULT_PATH());
2012 $frame_data_path = $cfrt ?
2013 DATA_NOACCESS_PATH() :
2014 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
2015 %frame_data = (ref ($data_ref)) ?
2017 read_data_file($frame_data_path);
2018 %frame_full_data = merge_settings(\%default, \%frame_data);
2020 ($frame_full_data{'frame'} ne '') ?
2021 $frame_full_data{'frame'} :
2024 $frame, $frame_full_data{'ext'}
2029 %goto_list = (ref ($goto_ref)) ?
2031 read_data_file(DATA_LIST_PATH());
2032 for (my $i=0; ;$i+=1) {
2033 my %file_data = read_data_file(DATA_ATTACH_PATH().$i);
2034 if ($file_data{'frame'} eq '') {
2037 if (int($file_data{'frame'}) != $frame) {
2040 if ($file_data{'content'} ne '') {
2043 unshift @files, $file_data{'filename'};
2047 ($frame_full_data{'ongtime'} eq '')
2049 $frame_data {'ongtime'} = $ongtime;
2050 $frame_full_data{'ongtime'} = $ongtime;
2056 ($frame_full_data{'timer'} eq '')
2059 $frame_data{'timer'} = int($timer);
2063 $r = write_data_file($frame_data_path, \%frame_data);
2065 print STDERR "fail writing $frame_data_path\n";
2067 print "write frame data fail\n";
2072 $goto_list{'title-' .$frame} = $frame_full_data{'title'};
2073 $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
2074 $r = write_data_file(DATA_LIST_PATH(), \%goto_list);
2076 print STDERR "fail writing ".DATA_LIST_PATH()."\n";
2078 print "write GOTO list fail\n";
2084 foreach my $file (@files) {
2085 $in_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file);
2086 $out_path = join_path(PATH_SEPARATOR(), WWW_PATH() , $file);
2088 print $in_path.' -> '.$out_path;
2090 $r = copy_encoded($in_path, $out_path);
2092 print (($r) ? " OK\n" : " FAIL\n");
2095 print STDERR "fail copy $in_path $out_path\n";