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',
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_WORDS_PATH: DATA_WORDS_PATH = /botm/data/bsta/words/
93 ###PERL_WWW_PATH: WWW_PATH = /botm/www/
94 ###PERL_WWW_INDEX_PATH: WWW_INDEX_PATH = /botm/www/1190/bsta/index.htm
96 ###PERL_SCHEME: SCHEME = http
97 ###PERL_WEBSITE: WEBSITE = 1190.bicyclesonthemoon.info
98 ###PERL_WEBSITE_NAME: WEBSITE_NAME = Bicycles on the Moon
99 ###PERL_FAVICON_PATH: FAVICON_PATH = /img/favicon.png
101 ###PERL_COIN_DATE: COIN_DATE = 13-Nov-2016 22:15
102 ###PERL_INTF_DATE: INTF_DATE = 28-Sep-2016 20:34
104 ###PERL_STORY_CREDITS: STORY_CREDITS = "BSTA" by Balthasar Szczepański
105 ###PERL_INTF_CREDITS: INTF_CREDITS = Online interface © Balthasar Szczepański; AGPL 3 license
106 ###PERL_SOURCE_URL: SOURCE_URL = http://bicyclesonthemoon.info/git-projects/?p=ott/bsta
108 ###PERL_COMMENT_PAGE_LENGTH:COMMENT_PAGE_LENGTH= 16
110 use constant STATE => {
116 use constant INTF_STATE => {
129 use constant TEXT_MODE => {
135 use constant CHAT_STATE => {
140 use constant CHAT_ACTION => {
148 use constant tags_bbcode => {
155 'quote' => '[quote]',
156 'quote=' => '[quote="',
158 '/quote' => '[/quote]',
159 'ni' => '[color=#0057AF]',
161 'br' => '[color=#BB6622]',
163 'po' => '[color=#FF8800]',
174 '/list' => '[/list]',
178 '/?' => '[/unknown!]',
180 use constant tags_html => {
183 'fq' => '<div class="fq">',
185 'tq' => '<div class="tq">',
187 'quote' => '<div class="opomba"><div class="opomba_text">',
188 'quote=' => '<div class="opomba"><div class="opomba_info"><b>',
189 'quote/='=> '</b> wrote:</div><div class="opomba_text">',
190 '/quote' => '</div></div>',
191 'ni' => '<span class="ni">',
193 'br' => '<span class="br">',
195 'po' => '<span class="po">',
197 'url' => '<a href="#">',#think: how to add selfincluding?
198 'url=' => '<a href="',
204 'list=' => '<ol style="list-style-type: ',
205 'list=1' => 'decimal',
206 'list=A' => 'upper-alpha',
207 'list=a' => 'lower-alpha',
208 'list=I' => 'upper-roman',
209 'list=i' => 'lower-roman',
216 '/?' => '[/unknown!]',
220 # Function to return an error page
221 # arguments: 1 - header fields, 2 - page title, 3 - error message, 4 method
223 (my $header, my $title, my $message, my $method, my $hyperlink) = @_;
226 foreach my $header_name (keys %$header) {
227 print http_header_line($header_name, $header->{$header_name});
230 elsif($header ne '') {
233 if($method eq 'HEAD') {
237 my $_title = html_entity_encode_dec($title , 1);
238 my $_message = html_entity_encode_dec($message , 1);
239 my $_hyperlink = html_entity_encode_dec($hyperlink, 1);
241 print "Content-type: text/html; charset=UTF-8\n\n";
243 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
244 print ' <html lang="en">'."\n";
245 print ' <head>'."\n";
246 print ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
248 print ' <title>'.$_title.'</title>'."\n";
250 print ' </head>'."\n";
251 print ' <body>'."\n";
253 print ' <h1>'.$_title.'</h1>'."\n";
255 if (($message ne '') || ($hyperlink ne '')) {
257 if ($message ne '') {
258 print ' '.$_message.($hyperlink ne '' ? '<br>' : '')."\n";
260 if ($hyperlink ne '') {
261 print ' <a href="'.$_hyperlink.'">'.$_hyperlink."</a>\n";
265 print ' </body>'."\n";
266 print '</html>'."\n";
270 (my $method, my $allowed) = @_;
272 my $status = http_status(HTTP_STATUS->{'method_not_allowed'});
274 http_header_line('status', $status) .
275 http_header_allow($allowed);
280 "The interface does not support the $method method.",
285 sub fail_content_type
287 (my $method, my $content_type) = @_;
289 my $status = http_status(HTTP_STATUS->{'unsupported_media_type'});
290 my $header = http_header_line('status', $status);
295 "Unsupported Content-type: $content_type.",
302 (my $method, my $type, my $path) = @_;
304 my $status = http_status(HTTP_STATUS->{'not_found'});
305 my $header = http_header_line('status', $status);
311 ($type ne '' ? $type : 'file').
312 ($path ne '' ? ': "'.$path.'"' : '').
320 (my $method, my $ID) = @_;
322 my $status = http_status(HTTP_STATUS->{'not_found'});
323 my $header = http_header_line('status', $status);
328 "Attachment $ID not found.",
335 (my $method, my $text) = @_;
337 my $status = http_status(HTTP_STATUS->{'internal_server_error'});
338 my $header = http_header_line('status', $status);
350 (my $method, my $uri, my $code) = @_;
354 $code = HTTP_STATUS->{'found'};
356 # 301 Moved Permanently
359 # 307 Temporary Redirect
360 # 308 Permanent Redirect
361 $status = http_status($code);
362 $header = http_header_line('status', $status);
363 $header .= http_header_location($uri);
375 # function to obtain address of remote agent
376 sub get_remote_addr {
377 if ($ENV{'HTTP_X_FORWARDED_FOR'} =~ /^.+$/) {
380 elsif ($ENV{'REMOTE_ADDR'} =~ /^.+$/) {
388 # functions to get ID/number etc.
390 (my $cgi, my $default, my $cgi_name) = @_;
391 if ($default eq '') {
394 if ($cgi_name eq '') {
398 if ($cgi->{$cgi_name} =~ /^.+$/) {
401 elsif ($ENV{'PATH_INFO'} =~ /^\/(.+)$/) {
405 return int($default);
409 # function to obtain frame number
411 (my $cgi, my $default) = @_;
412 return get_id($cgi, $default, 'f');
415 # function to obtain password
419 if ($cgi->{'p'} =~ /^.+$/) {
431 foreach my $settings (@_) {
432 foreach my $ind (keys %$settings) {
433 $final_settings{$ind} = $settings->{$ind};
436 return %final_settings;
441 # different & simpler implementation than in post library
445 #analyse bbcode text to build tag tree
446 #TODO make [/*] optional!
448 (my $bb, my $printdebug) = @_;
461 $bbtree{"_.name" } = "ht";
462 $bbtree{"_.value" } = '';
463 $bbtree{"_.type" } = "tag";
464 $bbtree{"_.count" } = 0;
465 $bbtree{"_.closed"} = 0;
466 $debug .= debug($printdebug,
468 "<!--GENERATING BBCODE TREE:\n".
469 '[_]automatic tag: [ht]'."\n"
473 my $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
475 if($bb =~ m/\[(\/?)([A-Za-z]+|\*)(=([^\[\]]*))?\]/g) {
482 if ($tag_value =~ /^"(.*)"$/) {
486 if ($pre_text ne '') {
487 $debug .= debug($printdebug, "[$new_ind]text: $pre_text\n");
488 $bbtree{$new_ind.'.type' } = 'text';
489 $bbtree{$new_ind.'.value'} = $pre_text;
490 $bbtree{ $ind.'.count'}+= 1;
491 $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
494 if($tag_name =~ /^(fq|tq|quote|br|ni|po|url|i|list|\*)$/) {
495 if ($tag_end ne '') {
497 ($tag_name ne $bbtree{$ind.'.name'}) ||
500 $debug .= debug($printdebug, "[$new_ind]text: $tag\n");
501 $bbtree{$new_ind.'.type' } = 'text';
502 $bbtree{$new_ind.'.value'} = $tag;
503 $bbtree{ $ind.'.count'}+= 1;
504 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
507 $debug .= debug($printdebug, "[$new_ind]tag: $tag\n");
508 $bbtree{$new_ind.'.type' } = 'tag';
509 $bbtree{$new_ind.'.name' } = '/'.$tag_name;
510 $bbtree{$new_ind.'.value' } = $tag_value;
511 $bbtree{ $ind.'.count' }+= 1;
512 $bbtree{ $ind.'.closed'} = 1;
514 $ind =~ s/\.[0-9]+$//;
515 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
520 $debug .= debug($printdebug, "[$new_ind]tag: $tag\n");
521 $bbtree{$new_ind.'.type' } = 'tag';
522 $bbtree{$new_ind.'.name' } = $tag_name;
523 $bbtree{$new_ind.'.value' } = $tag_value;
524 $bbtree{$new_ind.'.count' } = 0;
525 $bbtree{$new_ind.'.closed'} = 0;
526 $bbtree{ $ind.'.count' }+= 1;
529 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
533 $debug .= debug($printdebug, "[$new_ind]text: $tag\n");
534 $bbtree{$new_ind.'.type' } = 'text';
535 $bbtree{$new_ind.'.value'} = $tag;
536 $bbtree{ $ind.'.count'}+= 1;
537 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
541 $debug .= debug($printdebug, "[$new_ind]text: $bb\n");
542 $bbtree{$new_ind.'.type' } = 'text';
543 $bbtree{$new_ind.'.value'} = $bb;
544 $bbtree{ $ind.'.count'}+= 1;
545 # $new_ind = $ind.'.'.$bbtree{$ind.'.count'};
549 my $final_ind = '_.'.$bbtree{"_.count"};
550 $debug .= debug($printdebug, "[$final_ind]automatic tag: [/ht]\n -->\n");
551 $bbtree{$final_ind.'.type' } = "tag";
552 $bbtree{$final_ind.'.name' } = '/ht';
553 $bbtree{ '_.count' }+= 1;
554 $bbtree{ '_.closed'} = 1;
556 return ($debug, %bbtree);
559 #convert tag tree to final text
561 (my $printdebug, my $debug, my $lang, my $bbtree) = @_;
566 my $tags = ($lang eq 'html') ? tags_html : tags_bbcode;
567 my $escape = ($lang eq 'html');
569 # $debug .= debug($printdebug, "\n****\n");
570 # foreach my $iiii (keys %tags) {
571 # $debug .= debug($printdebug, $iiii.'='.$tags->{$iiii}."\n");
573 # $debug .= debug($printdebug, "****\n");
578 $debug .= debug($printdebug, "\n<!--PROCESSING BBCODE TREE:\n");
580 while ($level >= 0) {
582 $debug .= debug($printdebug, "[$level:$ind:".int($bbtree->{$ind.'.count'})."]");
584 if ($bbtree->{$ind.'.type'} eq 'text') {
585 my $text = $bbtree->{$ind.'.value'};
586 $debug .= debug($printdebug, "text: ".$text);
587 $out .= $escape ? html_encode_line($text) : $text;
592 elsif ($bbtree->{$ind.'.type'} eq 'tag') {
593 my $name = $bbtree->{$ind.'.name'};
595 if ($name =~ /^\//) {
596 $debug .= debug($printdebug, "tag: [$name]");
598 $indd =~ s/\.([0-9]+)$//;
599 if (exists($tags->{$name.'='}) && ($bbtree->{$indd.'.value'} ne '')) {
600 $out .= $tags->{$name.'='};
602 elsif (exists($tags->{$name})) {
603 $out .= $tags->{$name};
606 $out .= $tags->{'/?'};
607 $debug .= debug($printdebug, "[unknown!]");
610 $ind =~ s/\.([0-9]+)$//;
612 $debug .= debug($printdebug, "[<]");
623 my $value = $bbtree->{$ind.'.value'};
624 if($bbtree->{$ind.'.closed'} ne '') {
625 $debug .= debug($printdebug, "tag: [$name]");
627 if (exists($tags->{$name.'='}) && ($value ne '')) {
628 if (exists($tags->{$name.'='.$value})) {
631 $tags->{$name.'='.$value} .
637 ($escape ? html_entity_encode_dec($value, 1) : $value) .
641 elsif (exists($tags->{$name})) {
642 $out .= $tags->{$name};
645 $out .= $out.$tags->{'?'};
646 $debug .= debug($printdebug, "[unknown!]");
650 $debug .= debug($printdebug, "unclosed tag: [$name]");
651 my $text = $name . (($value ne '') ? ('='.$value) : '');
652 $out .= '['.($escape ? html_encode_line($text) : $text).']';
654 if ($bbtree->{$ind.'.count'} > 0) {
657 $debug .= debug($printdebug, "[>]");
666 $debug .= debug($printdebug, "unknown thing: ".$bbtree->{$ind.'.type'});
667 #should not occur with a correct bbtree
668 #unless unimplemented
669 $ind =~ s/\.([0-9]+)$//;
671 $debug .= debug($printdebug, "[<ui]");
680 if ($goto_next ne '') {
682 $ind =~ s/\.([0-9]+)$//;
684 if (($i < $bbtree->{$ind.'.count'}) and ($1 ne '')){
691 # should not occur with a correct bbtree
692 $debug .= debug($printdebug, "[<$goto_next]");
695 } while ($level >= 0);}
698 $debug .= debug($printdebug, "[>$level:$ind]\n");
701 $debug .= debug($printdebug, "-->\n");
702 return ($debug, $out);
707 (my $bb, my $printdebug) = @_;
712 ($debug, %bbtree) = bbtree($bb, $printdebug);
713 ($debug, $ht) = convtree ($printdebug, $debug, 'html', \%bbtree);
720 (my $bb, my $printdebug) = @_;
725 ($debug, %bbtree) = bbtree($bb, $printdebug);
726 ($debug, $ht) = convtree ($printdebug, $debug, 'bb', \%bbtree);
732 (my $bb, my $full_url, my $password) = @_;
737 my $base_url = $full_url ?
738 {'scheme' => SCHEME(), 'host' => WEBSITE()} :
741 while ($bb =~ m/###([^#;]*);/g) {
746 if ($value =~ /^att&([0-9]+)$/) {
749 {'path' => CGI_ATTACH_PATH()},
753 elsif ($value =~ /^vw&([0-9]+)$/) {
756 {'path' => CGI_VIEWER_PATH()},
760 elsif ($value =~ /^fr&([0-9]+)$/) {
763 {'path' => CGI_FRAME_PATH()},
770 if (($value ne '') && ($password ne '')) {
773 {'query' => {'p' => $password}}
776 $bb = $before . $value . $after;
782 sub html_encode_line {
783 (my $text, my $non_ascii, my $all) = @_;
787 $text =~ s/\r\n/\n/gs;
790 while ($text ne '') {
791 $ind = index($text, "\n");
793 $html .= html_entity_encode_dec(substr($text, 0, $ind), $non_ascii, $all)."<br>\n";
794 $text = substr($text, $ind+1);
798 $html .= html_entity_encode_dec($text, 1);
806 (my $print, my $text) = @_;
816 sub print_html_start {
818 print $fh '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
819 print $fh '<html lang="en">'."\n";
824 print $fh '</html>'."\n";
827 sub print_html_head_start {
829 print $fh ' <head>'."\n";
830 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
831 print $fh ' <link rel="icon" type="image/png" href="'.html_entity_encode_dec(FAVICON_PATH(),1).'">'."\n";
832 print $fh ' <link rel="stylesheet" href="'.html_entity_encode_dec(CGI_CSS_PATH(),1).'">'."\n";
835 sub print_html_head_end {
837 print $fh ' </head>'."\n";
840 sub print_html_body_start {
842 print $fh ' <body>'."\n";
843 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";
844 print $fh ' <div id="all">'."\n";
847 sub print_html_body_end {
848 (my $fh, my $hide_credits) = @_;
849 print $fh ' </div>'."\n";
850 unless ($hide_credits) {
851 print $fh ' <p>'."\n";
852 print $fh ' '.html_entity_encode_dec(STORY_CREDITS(),1).'<br>'."\n";
853 print $fh ' '.html_entity_encode_dec(INTF_CREDITS(),1).'<br>'."\n";
854 print $fh ' <a href="'.html_entity_encode_dec(SOURCE_URL(),1).'" class="cz">source code</a>'."\n";
855 print $fh ' </p>'."\n";
857 print $fh ' <a href="/" class="cz">'.html_entity_encode_dec(WEBSITE(),1).'</a>'."\n";
858 print $fh ' </body>'."\n";
861 sub print_html_data {
862 (my $fh, my $data) = @_;
864 foreach my $key (keys %$data) {
865 unless ($key eq 'content') {
866 my $val = $data->{$key};
867 $val =~ s/(\r)?\n/\n /gs; # does the space make sense in HTML anyway?
868 print $fh html_encode_line("$key: $val\n", 1);
871 print $fh html_encode_line("\n".$data->{'content'});
874 sub print_viewer_page {
887 my $launch = $context->{'launch'};
888 my $access = $context->{'access'};
889 my $password_ok = $context->{'password_ok'};
890 my $static = $context->{'static'};
892 my $frame = int($context->{'frame'});
893 my $text_mode = int($context->{'text_mode'});
894 my $timer_unlocked = int($context->{'timer_unlocked'});
895 my $timer = int($context->{'timer'});
896 # my $words_page = int($context->{'words_page'});
898 my $prev_frame = $frame - 1;
899 my $next_frame = $frame + 1;
901 my $story = $settings->{'story'};
902 my $title = $frame_data->{'title'};
903 my $command = ($frame_data->{'command'} ne '') ?
904 $frame_data->{'command'} :
905 $next_frame_data->{'title'};
907 my $last_frame = int($state->{'last'});
908 my $ong_state = int($state->{'state'});
910 my $width = int($frame_data->{'width'});
911 my $height = int($frame_data->{'height'});
912 my $frame_type = $frame_data->{'frametype'};
914 my $timer_color_h = (($timer_unlocked >= 1) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
915 my $timer_color_m = (($timer_unlocked >= 2) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
916 my $timer_color_s = (($timer_unlocked >= 3) || ($ong_state >= STATE->{'ready'})) ? 'br' : 'ni';
923 (($timer >= 0) && ($frame == 0))
925 $timer_s = sprintf('%02d', $timer % 60);
926 $timer_h = int($timer / 60);
927 $timer_m = sprintf('%02d', $timer_h % 60);
928 $timer_h = sprintf('%02d', $timer_h / 60);
930 elsif (($timer >= -15) && ($ong_state >= STATE->{'ready'})) {
941 my $words_posts = int($words_data->{'posts'});
942 my $words_link_text = 'Words'.(($words_posts > 0) ? "[$words_posts]" : '');
944 my $prev_available = (($frame > 0) && $access);
945 my $next_available = ($launch || $password_ok || ($next_frame <= $last_frame));
946 my $prefetch_prev = (
948 ($prev_frame < $last_frame) || ( # avoid unseen trigger!
949 ($prev_frame <= $last_frame) &&
950 ($ong_state >= STATE->{'ready'})
953 my $prefetch_next = (
955 ($next_frame < $last_frame) || ( # avoid unseen trigger!
956 ($next_frame <= $last_frame) &&
957 ($ong_state >= STATE->{'ready'})
964 ($frame == $last_frame) && (
965 ($ong_state == STATE->{'waiting'}) ||
966 ($ong_state == STATE->{'ready'})
974 ($frame < $last_frame) || (
975 ($ong_state >= STATE->{'ready'}) &&
976 $context->{'show_command'}
979 my $show_command_link = ($next_available || (!$access));
980 my $show_command_cursor = ((!$next_available) || ($command eq ''));
981 my $show_words = ($password_ok || ($access && !$launch));
983 my $frame_indirect = !(
985 ($frame <= $last_frame) &&
986 ($ong_state > STATE->{'inactive'})
989 my $prevframe_indirect = !($prev_frame <= $last_frame);
990 my $nextframe_indirect = !($next_frame <= $last_frame);
994 my $base_url = CGI_PATH();
995 my $goto_url = CGI_GOTO_PATH();
996 my $timer_url = CGI_TIMER_PATH();
997 my $viewer_full_url = merge_url(
998 {'scheme' => SCHEME(), 'host' => WEBSITE()},
999 {'path' => CGI_VIEWER_PATH()},
1002 my $viewer_url = merge_url(
1003 {'path' => CGI_VIEWER_PATH()},
1006 my $viewer_0_url = merge_url(
1007 {'path' => CGI_VIEWER_PATH()},
1010 my $viewer_prev_url = merge_url(
1011 {'path' => CGI_VIEWER_PATH()},
1012 {'path' => $prev_frame}
1014 my $viewer_next_url = merge_url(
1015 {'path' => CGI_VIEWER_PATH()},
1016 {'path' => $next_frame}
1018 my $viewer_last_url = merge_url(
1019 {'path' => CGI_VIEWER_PATH()},
1020 {'path' => ($static ? -1 : $last_frame)}
1022 my $bbcode_url = ($text_mode == TEXT_MODE->{'bb'}) ?
1024 {'path' => CGI_BBCODE_PATH()},
1031 'b' => TEXT_MODE->{'bb'}
1036 my $info_url = ($text_mode == TEXT_MODE->{'info'}) ?
1038 {'path' => CGI_INFO_PATH()},
1045 'b' => TEXT_MODE->{'info'}
1050 my $words_url = merge_url (
1054 'b' => TEXT_MODE->{'words'}
1063 my $frame_normal_url;
1065 if ($frame_data->{'frame'} ne '') {
1066 $frame_file = $frame_data->{'frame'};
1069 $frame_file = sprintf(
1070 $settings->{'frame'},
1071 $frame, $frame_data->{'ext'}
1074 $frame_normal_url = merge_url(
1075 {'path' => CGI_PATH()},
1076 {'path' => $frame_file}
1078 $frame_url = $frame_indirect ?
1080 {'path' => CGI_FRAME_PATH()},
1084 $frame_full_url = merge_url(
1085 {'scheme' => SCHEME(), 'host' => WEBSITE()},
1086 {'path' => $frame_normal_url}
1088 if ($prevframe_indirect) {
1089 $frame_prev_url = merge_url(
1090 {'path' => CGI_FRAME_PATH()},
1091 {'path' => $prev_frame}
1094 elsif ($prev_frame_data->{'frame'} ne '') {
1095 $frame_prev_url = merge_url(
1096 {'path' => CGI_PATH()},
1097 {'path' => $prev_frame_data->{'frame'}}
1101 $frame_prev_url = merge_url(CGI_PATH(), sprintf(
1102 $settings->{'frame'}, $prev_frame, $prev_frame_data->{'ext'}
1105 if ($nextframe_indirect) {
1106 $frame_next_url = merge_url(
1107 {'path' => CGI_FRAME_PATH()},
1108 {'path' => $next_frame}
1111 elsif ($next_frame_data->{'frame'} ne '') {
1112 $frame_next_url = merge_url(
1113 {'path' => CGI_PATH()},
1114 {'path' => $next_frame_data->{'frame'}}
1118 $frame_next_url = merge_url(CGI_PATH(), sprintf(
1119 $settings->{'frame'}, $next_frame, $next_frame_data->{'ext'}
1124 $password_query = url_query_encode({'p', $settings->{'password'}});
1125 $goto_url = merge_url($goto_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1126 $info_url = merge_url($info_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1127 $words_url = merge_url($words_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1128 $bbcode_url = merge_url($bbcode_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1129 $viewer_url = merge_url($viewer_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1130 $viewer_0_url = merge_url($viewer_0_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1131 $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1132 $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1133 $viewer_last_url = merge_url($viewer_last_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1134 if ($frame_indirect) {
1135 $frame_url = merge_url($frame_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1137 if ($prevframe_indirect) {
1138 $frame_prev_url= merge_url($frame_prev_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1140 if ($nextframe_indirect) {
1141 $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1144 my $_base_url = html_entity_encode_dec($base_url , 1);
1145 my $_goto_url = html_entity_encode_dec($goto_url , 1);
1146 my $_info_url = html_entity_encode_dec($info_url , 1);
1147 my $_words_url = html_entity_encode_dec($words_url , 1);
1148 my $_bbcode_url = html_entity_encode_dec($bbcode_url , 1);
1149 my $_timer_url = html_entity_encode_dec($timer_url , 1);
1150 my $_viewer_full_url = html_entity_encode_dec($viewer_full_url, 1);
1151 my $_viewer_url = html_entity_encode_dec($viewer_url , 1);
1152 my $_viewer_0_url = html_entity_encode_dec($viewer_0_url , 1);
1153 my $_viewer_prev_url = html_entity_encode_dec($viewer_prev_url, 1);
1154 my $_viewer_next_url = html_entity_encode_dec($viewer_next_url, 1);
1155 my $_viewer_last_url = html_entity_encode_dec($viewer_last_url, 1);
1156 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1157 my $_frame_prev_url = html_entity_encode_dec($frame_prev_url , 1);
1158 my $_frame_next_url = html_entity_encode_dec($frame_next_url , 1);
1159 my $_frame_full_url = html_entity_encode_dec($frame_full_url , 1);
1161 my $_story = html_entity_encode_dec($story , 1);
1162 my $_title = html_entity_encode_dec($title , 1);
1163 my $_command = html_entity_encode_dec($command , 1);
1164 my $_frame_type = html_entity_encode_dec($frame_type, 1);
1166 my $_website_name = html_entity_encode_dec(WEBSITE_NAME(), 1);
1168 if ($text_mode == TEXT_MODE->{'info'}) {
1169 if ($show_command) {
1170 $frame_data->{'command'} = $command;
1172 if ($context->{'access'}) {
1173 $frame_data->{'frame'} = $frame_file;
1177 # everything determined, now start generating
1181 unless (seek($fh, 0, 0)) {
1182 #don't actually fail here
1186 unless (open_encoded($fh, ">:encoding(UTF-8)", $file)) {
1191 print_html_start($fh);
1192 print_html_head_start($fh);
1194 print $fh ' <title>'.$_title;
1195 if ($story ne $title) {
1196 print $fh ' • '.$_story;
1198 print $fh ' • '.$_website_name.'</title>'."\n";
1199 print $fh ' <link rel="index" href="'.$_goto_url.'">'."\n";
1200 print $fh ' <link rel="start" href="'.$_viewer_0_url.'">'."\n";
1201 if ($prev_available) {
1202 print $fh ' <link rel="prev" href="'.$_viewer_prev_url.'">'."\n";
1203 if ($prefetch_prev) {
1204 print $fh ' <link rel="prefetch" href="'.$_viewer_prev_url.'">'."\n";
1205 print $fh ' <link rel="prefetch" href="'.$_frame_prev_url.'">'."\n";
1208 if ($next_available) {
1209 print $fh ' <link rel="next" href="'.$_viewer_next_url.'">'."\n";
1210 if ($prefetch_next) {
1211 print $fh ' <link rel="prefetch" href="'.$_viewer_next_url.'">'."\n";
1212 print $fh ' <link rel="prefetch" href="'.$_frame_next_url.'">'."\n";
1216 print $fh ' <script src="'.$_timer_url.'"></script>'."\n";
1219 print_html_head_end($fh);
1220 print_html_body_start($fh);
1222 print $fh ' <div id="inst" class="ins">'."\n";
1224 print $fh ' <div id="title">'."\n";
1225 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1226 print $fh ' </div>'."\n";
1228 print $fh ' </div>'."\n";
1229 print $fh ' <div id="framespace">'."\n";
1231 print $fh ' <img src="'.$_frame_url.'" id="frame" class="'.$_frame_type.'" alt="'.$frame.'" title="'.$_title.'" width="'.$width.'" height="'.$height.'">'."\n";
1233 print $fh ' </div>'."\n";
1234 print $fh ' <div id="insb" class="ins">'."\n";
1236 if ($text_mode == TEXT_MODE->{'info'}) {
1237 print $fh ' <div id="chat">'."\n";
1239 print_html_data($fh, $frame_data);
1241 print $fh ' </div>'."\n";
1243 elsif ($text_mode == TEXT_MODE->{'bb'}) {
1244 print $fh ' <div id="chat">'."\n";
1246 print $fh '[quote][center][size=200]'.$_title.'[/size]<br>'."\n";
1247 print $fh '[url='.$_viewer_full_url.'][img]'.$_frame_full_url.'[/img][/url][/center]<br>'."\n";
1248 print $fh html_encode_line(
1251 $frame_data->{'content'},
1256 print $fh '[/quote]'."\n";
1258 print $fh ' </div>'."\n";
1260 elsif ($frame_data->{'content'} ne '') {
1261 print $fh ' <div id="undertext">'."\n";
1262 print $fh bb_to_html(
1264 $frame_data->{'content'},
1266 $password_ok ? $settings->{'password'} : ''
1269 print $fh ' </div>'."\n";
1272 print $fh ' <div id="command">'."\n";
1275 print $fh ' <span id="timer">';
1276 print $fh '[<span id="ongh" class="hv '.$timer_color_h.'">'.$timer_h.'</span>';
1277 print $fh ':<span id="ongm" class="hv '.$timer_color_m.'">'.$timer_m.'</span>';
1278 print $fh ':<span id="ongs" class="hv '.$timer_color_s.'">'.$timer_s.'</span>]';
1279 print $fh '</span><br>'."\n";
1282 if ($show_command_link) {
1283 print $fh '<a href="'.($access ? $_viewer_next_url : $_viewer_last_url).'">';
1285 if ($show_command) {
1286 print $fh $_command;
1288 if ($show_command_cursor) {
1289 print $fh '<span class="inp">_</span>';
1291 if ($show_command_link) {
1295 print $fh " </div>\n";
1297 print $fh ' <div id="underlinks">'."\n ";
1299 unless (($frame == 0) && $static) {
1300 print $fh '<a href="'.$_base_url.'">Once again</a> | ';
1302 if ($prev_available) {
1303 print $fh '<a href="'.$_viewer_prev_url.'">Before</a> | ';
1305 unless ($frame == $last_frame) {
1306 print $fh '<a href="'.$_viewer_last_url.'">Now</a> | ';
1308 print $fh '<a href="'.$_goto_url.'">GOTO</a>'."\n";
1309 print $fh ' <span style="float: right;">'."\n ";
1310 if ($text_mode == TEXT_MODE->{'normal'}) {
1312 print $fh '<a href="'.$_words_url.'">'.$words_link_text.'</a> | ';
1316 print $fh '<a href="'.$_viewer_url.'">Without</a> | ';
1318 print $fh '<a href="'.$_info_url.'">Info</a> | ';
1319 print $fh '<a href="'.$_bbcode_url.'">BB</a>';
1320 print $fh "\n </span>\n";
1322 print $fh " </div>\n";
1323 print $fh " </div>\n";
1325 if (($text_mode == TEXT_MODE->{'words'}) && $show_words) {
1326 print_comments($fh, $context, $settings, $words_data);
1329 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1330 print_html_end($fh);
1333 unless (ref($file)) {
1337 truncate ($fh , tell($fh));
1343 sub print_comments {
1344 (my $fh, my $context, my $settings, my $words_data) = @_;
1346 my $password_ok = $context->{'password_ok'};
1347 my $frame = int($context->{'frame'});
1348 my $page = int($context->{'words_page'});
1349 my $post_count = int($words_data->{'posts'});
1350 my $id_start = $page * COMMENT_PAGE_LENGTH();
1351 my $id_stop = $id_start + COMMENT_PAGE_LENGTH();
1352 my $older = ($page > 0) ? ($page-1) : '';
1355 if ($id_stop >= $post_count) {
1356 $id_stop = $post_count;
1363 my $words_url = merge_url(
1364 {'path' => CGI_VIEWER_PATH()},
1367 'query' => {'b' => TEXT_MODE->{'words'}},
1370 my $older_url = merge_url(
1373 'query' => {'i' => $page-1},
1374 'fragment' => 'insw',
1378 my $newer_url = merge_url(
1381 'query' => {'i' => $page+1},
1382 'fragment' => 'insw',
1388 $password_query = url_query_encode({'p', $settings->{'password'}});
1389 $older_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1390 $newer_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
1393 my $_post_url = html_entity_encode_dec(CGI_WORDS_PATH(), 1);
1394 my $_password = html_entity_encode_dec($settings->{'password'}, 1);
1395 my $_older_url = html_entity_encode_dec($older_url, 1);
1396 my $_newer_url = html_entity_encode_dec($newer_url, 1);
1398 if (($older ne '') || ($newer ne '')) {
1399 $links .= ' <div class="underlinks">'."\n";
1402 $links .= '<a href="'.$_older_url.'">Older</a>'
1404 if (($older ne '') && ($newer ne '')) {
1408 $links .= '<a href="'.$_newer_url.'">Newer</a>';
1411 $links .= ' </div>'."\n";
1414 print $fh ' <div class="space"></div>'."\n";
1415 print $fh ' <div id="insw" class="ins">'."\n";
1417 print $fh ' <div class="title" id="wordstitle">'."\n";
1418 print $fh ' <h1 class="titletext" id="wordstitletext">Words</h1>'."\n";
1419 print $fh ' </div>'."\n";
1425 print $fh ' <div class="undertext" id="words">'."\n";
1427 if ($post_count > 0) {
1428 for (my $i=$id_start; $i<$id_stop; ++$i) {
1429 my $ID = $words_data->{'content'}->[$i];
1430 my $post_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $ID);
1431 my %post_data = read_data_file($post_path);
1433 my $post_time = int($post_data{'posttime'});
1434 my $edit_time = int($post_data{'edittime'});
1439 if ($post_time != 0) {
1440 my @time_tab = gmtime($post_time);
1441 $post_time_text = sprintf(
1442 '%04d.%02d.%02d %02d:%02d:%02d UTC',
1451 if (($edit_time !=0) && ($edit_time != $post_time)) {
1452 my @time_tab = gmtime($edit_time);
1453 $edit_time_text = sprintf(
1454 '%04d.%02d.%02d %02d:%02d UTC',
1462 my $quote_url = merge_url(
1463 {'path' => CGI_WORDS_PATH()},
1468 'p' => ($password_ok ? $settings->{'password'} : '')
1472 my $edit_url = merge_url(
1473 {'path' => CGI_WORDS_PATH()},
1478 'key' => $post_data{'key'},
1479 'username' => $post_data{'name'},
1480 'p' => ($password_ok ? $settings->{'password'} : '')
1484 my $remove_url = merge_url(
1485 {'path' => CGI_WORDS_PATH()},
1490 'key' => $post_data{'key'},
1491 'username' => $post_data{'name'},
1492 'p' => ($password_ok ? $settings->{'password'} : '')
1497 my $_ID = html_entity_encode_dec($ID, 1);
1498 my $_name = html_entity_encode_dec($post_data{'name'}, 1);
1499 my $_quote_url = html_entity_encode_dec($quote_url, 1);
1500 my $_edit_url = html_entity_encode_dec($edit_url, 1);
1501 my $_remove_url = html_entity_encode_dec($remove_url, 1);
1503 print $fh ' <div id="'.$_ID.'"class="opomba">'."\n";
1504 print $fh ' <div class="opomba_info">'."\n";
1505 print $fh ' <a href="#'.$_ID.'" class="bi hu">'.$i.': '.$_name;
1506 if ($post_time_text ne '') {
1507 print $fh ' • '.$post_time_text;
1509 if ($edit_time_text ne '') {
1510 print $fh ' • '.$edit_time_text;
1512 print $fh '</a>'."\n";
1513 print $fh ' <div class="pr">'."\n";
1514 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";
1515 print $fh ' </div>'."\n";
1516 print $fh ' </div>'."\n";
1517 print $fh ' <div class="opomba_text">'."\n";
1518 print $fh bb_to_html(
1520 $post_data{'content'},
1522 $password_ok ? $settings->{'password'} : ''
1525 print $fh ' </div>'."\n";
1526 print $fh ' </div>'."\n";
1527 print $fh ' <br>'."\n";
1531 print $fh ' <form method="post" action="'.$_post_url.'">'."\n";
1532 print $fh ' <b>Your words:</b>'."\n";
1533 print $fh ' <textarea class="inta" name="words" rows="4"></textarea>'."\n";
1534 print $fh ' <table cellpadding="0" cellspacing="0" border="0"><tr>'."\n";
1535 print $fh ' <td><b>Your name: </b></td>'."\n";
1536 print $fh ' <td><input class="intx" type="text" name="username" value=""></td>'."\n";
1537 print $fh ' <td></td>'."\n";
1538 print $fh ' </tr><tr>'."\n";
1539 print $fh ' <td><b>Optional password: </b></td>'."\n";
1540 print $fh ' <td><input class="intx" type="password" name="password" value=""></td>'."\n";
1541 print $fh ' <td>(if you want to edit later)</td>'."\n";
1542 print $fh ' </tr><tr>'."\n";
1543 print $fh ' <td><b>Leave this empty: </b></td>'."\n";
1544 print $fh ' <td><input class="intx" type="text" name="password2" value=""></td>'."\n";
1545 print $fh ' <td>'."\n";
1546 print $fh ' <input class="inbt" type="submit" name="post" value="Send">'."\n";
1547 print $fh ' <input class="inbt" type="submit" name="preview" value="Preview">'."\n";
1548 print $fh ' </td>'."\n";
1549 print $fh ' </tr></table>'."\n";
1550 print $fh ' <input type="hidden" name="f" value="'.$frame.'">'."\n";
1552 print $fh ' <input type="hidden" name="p" value="'.$_password.'">'."\n";
1554 print $fh ' </form>'."\n";
1555 print $fh ' </div>'."\n";
1561 print $fh ' </div>'."\n";
1574 my $ong_state = int($state->{'state'});
1576 unless (open_encoded($fh, ">:encoding(UTF-8)", WWW_INDEX_PATH())) {
1580 # normal running story
1581 if ($ong_state > STATE->{'inactive'}) {
1582 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1583 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1584 my %default = read_data_file(DATA_DEFAULT_PATH());
1585 my %words_data = read_data_file(
1586 join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), 0),
1593 %frame_data = merge_settings(\%default, \%frame_data);
1594 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1596 $r = print_viewer_page(
1603 'timer_unlocked' => 3, # not relevant
1604 'timer' => 0, # not relevant
1606 'show_command' => 1,
1607 'text_mode' => TEXT_MODE->{'normal'},
1608 'words_page' => 0 # not relevant
1618 # no conditions met, pretend a normal Apache2 index
1619 elsif ($pass != 1) {
1620 my $index_of = CGI_PATH;
1621 $index_of =~ s/\/$//g;
1623 my $_index_of = html_entity_encode_dec($index_of , 1);
1624 my $_2words_date = html_entity_encode_dec(INTF_DATE(), 1);
1625 my $_coin_date = html_entity_encode_dec(COIN_DATE(), 1);
1626 my $_website = html_entity_encode_dec(WEBSITE() , 1);
1628 print_html_start ($fh);
1629 print $fh ' <head>'."\n";
1630 print $fh ' <meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
1631 print $fh ' <title>Index of '.$_index_of.'</title>'."\n";
1632 print $fh ' </head>'."\n";
1633 print $fh ' <body>'."\n";
1634 print $fh ' <h1>Index of '.$_index_of.'</h1>'."\n";
1635 print $fh ' <table>'."\n";
1636 print $fh ' <tr>'."\n";
1637 print $fh ' <th><img src="/icons/blank.gif" alt="[ICO]"></th>'."\n";
1638 print $fh ' <th><a href="?C=N;O=D">Name</a></th>'."\n";
1639 print $fh ' <th><a href="?C=M;O=A">Last modified</a></th>'."\n";
1640 print $fh ' <th><a href="?C=S;O=A">Size</a></th>'."\n";
1641 print $fh ' <th><a href="?C=D;O=A">Description</a></th>'."\n";
1642 print $fh ' </tr><tr>'."\n";
1643 print $fh ' <th colspan="5"><hr></th>'."\n";
1644 print $fh ' </tr><tr>'."\n";
1645 print $fh ' <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>'."\n";
1646 print $fh ' <td><a href="/">Parent Directory</a></td>'."\n";
1647 print $fh ' <td> </td>'."\n";
1648 print $fh ' <td align="right"> - </td>'."\n";
1649 print $fh ' <td> </td>'."\n";
1650 print $fh ' </tr><tr>'."\n";
1651 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1652 print $fh ' <td><a href="2words/">2words/</a></td>'."\n";
1653 print $fh ' <td align="right">'.$_2words_date.' </td>'."\n";
1654 print $fh ' <td align="right"> - </td><td> </td>'."\n";
1655 print $fh ' </tr><tr>'."\n";
1656 print $fh ' <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>'."\n";
1657 print $fh ' <td><a href="coin/">coin/</a></td>'."\n";
1658 print $fh ' <td align="right">'.$_coin_date.' </td>'."\n";
1659 print $fh ' <td align="right"> - </td><td> Coincidence </td>'."\n";
1660 print $fh ' </tr><tr>'."\n";
1661 print $fh ' <th colspan="5"><hr></th>'."\n";
1662 print $fh ' </tr>'."\n";
1663 print $fh ' </table>'."\n";
1664 print $fh ' <address>Apache/2.2.22 (Debian) Server at '.$_website.' Port 80</address>'."\n";
1665 print $fh ' </body>'."\n";
1666 print_html_end ($fh);
1670 my %frame_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 0));
1671 my %next_frame_data= read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 1));
1672 my %default = read_data_file(DATA_DEFAULT_PATH());
1673 my %coin_data = read_data_file(DATA_COIN_PATH());
1675 %frame_data = merge_settings(\%default, \%frame_data);
1676 %next_frame_data= merge_settings(\%default, \%next_frame_data);
1678 if (($mode == INTF_STATE->{'>'}) && $pause) {
1679 $r = print_viewer_page(
1686 'timer_unlocked' => 3,
1689 'show_command' => 1,
1690 'text_mode' => TEXT_MODE->{'normal'},
1691 'words_page' => 0 # not relevant
1698 {'posts' => 0} # words_data
1703 my $index_of = CGI_PATH;
1704 $index_of =~ s/\/$//g;
1708 my $show_parent_dir = 0;
1710 my $show_folders = 0;
1712 my $timer_color = 'ni';
1713 if ($mode == INTF_STATE->{'>'}) {
1714 $title = $settings->{'story'}; # $frame_data{'title'} ?
1715 $frame_file = 'intf-tr.gif';
1719 elsif ($mode == INTF_STATE->{'<<'}) {
1720 $title = 'Index of';
1721 $frame_file = 'intf-ll.gif';
1722 $show_parent_dir = 1;
1725 $timer_color = 'br';
1727 elsif ($mode == INTF_STATE->{'>>'}) {
1728 $title = 'Index of';
1729 $frame_file = 'intf-pp.gif';
1730 $show_parent_dir = 1;
1736 $title = 'Index of '.$index_of;
1737 $frame_file = 'intf-kw.gif';
1738 $show_parent_dir = 1;
1741 my $frame_url = merge_url(
1742 {'path' => CGI_PATH()},
1743 {'path' => $frame_file}
1745 my $coin_server = $coin_data{'server'};
1747 my $_title = html_entity_encode_dec($title , 1);
1748 my $_website_name = html_entity_encode_dec(WEBSITE_NAME() , 1);
1749 my $_frame_url = html_entity_encode_dec($frame_url , 1);
1750 my $_undertext = html_entity_encode_dec($undertext , 1);
1751 my $_2words_date = html_entity_encode_dec(INTF_DATE() , 1);
1752 my $_coin_date = html_entity_encode_dec(COIN_DATE() , 1);
1753 my $_coin_server = html_entity_encode_dec($coin_server , 1);
1754 my $_2words_url = html_entity_encode_dec(CGI_2WORDS_PATH(), 1);
1755 my $_coin_url = html_entity_encode_dec(CGI_COIN_PATH() , 1);
1757 print_html_start($fh);
1758 print_html_head_start($fh);
1760 print $fh ' <title>'.$_title.' • '.$_website_name.'</title>'."\n";
1762 print_html_head_end($fh);
1763 print_html_body_start($fh);
1765 print $fh ' <div id="inst" class="ins">'."\n";
1767 print $fh ' <div id="title">'."\n";
1768 print $fh ' <h1 id="titletext">'.$_title.'</h1>'."\n";
1769 print $fh ' </div>'."\n";
1771 print $fh ' </div>'."\n";
1772 print $fh ' <div id="framespace">'."\n";
1774 print $fh ' <img src="'.$_frame_url.'" id="frame" alt="0">'."\n"; # title="'.$_title.'"
1776 print $fh ' </div>'."\n";
1777 print $fh ' <div id="insb" class="ins">'."\n";
1779 print $fh ' <div id="undertext">'."\n";
1781 if ($show_parent_dir) {
1782 print $fh ' <img src="/icons/back.gif" alt="[DIR]"> <a href="..">Parent Directory</a><br>'."\n";
1784 if ($show_folders) {
1785 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">2words/</a> '.$_2words_date.' - <br>'."\n";
1786 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_coin_url.'">coin/</a> '.$_coin_date.' - '.$_coin_server."\n";
1789 print $fh ' <img src="/icons/folder.gif" alt="[DIR]"> <a href="'.$_2words_url.'">yyyyb/</a>'."\n";
1791 if ($undertext ne '') {
1792 print $fh ' '.$_undertext."\n";
1795 print $fh ' </div>'."\n";
1798 print $fh ' <div id="command">'."\n";
1800 print $fh ' [<span id="ongh" class="'.$timer_color.'">'.$timer.'</span>';
1801 print $fh ':<span id="ongm" class="'.$timer_color.'">'.$timer.'</span>';
1802 print $fh ':<span id="ongs" class="'.$timer_color.'">'.$timer.'</span>]<br>'."\n";
1804 if ($undertext ne '') {
1805 print $fh '><a href="'.$_2words_url.'">'.$_undertext.'</a><span class="inp">_</span>'."\n";
1807 print $fh " </div>\n";
1810 print $fh " </div>\n";
1812 print_html_body_end($fh, $ong_state == STATE->{'inactive'});
1813 print_html_end($fh);
1820 # ONG the frame + attachment & stuff. NOT update state file.
1823 my $ID, my $ongtime, my $timer, my $update, my $print,
1824 my $settings_ref, my $default_ref, my $data_ref, my $goto_ref
1830 my $frame_data_path;
1838 my %frame_full_data;
1841 if ($ongtime eq '') {
1848 elsif ($ID eq 'c') {
1880 %settings = (ref ($settings_ref)) ?
1882 read_data_file(DATA_SETTINGS_PATH());
1883 %default = (ref ($default_ref)) ?
1885 read_data_file(DATA_DEFAULT_PATH());
1886 $frame_data_path = $cfrt ?
1887 DATA_NOACCESS_PATH() :
1888 join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
1889 %frame_data = (ref ($data_ref)) ?
1891 read_data_file($frame_data_path);
1892 %frame_full_data = merge_settings(\%default, \%frame_data);
1894 ($frame_full_data{'frame'} ne '') ?
1895 $frame_full_data{'frame'} :
1898 $frame, $frame_full_data{'ext'}
1903 %goto_list = (ref ($goto_ref)) ?
1905 read_data_file(DATA_LIST_PATH());
1906 for (my $i=0; ;$i+=1) {
1907 my %file_data = read_data_file(DATA_ATTACH_PATH().$i);
1908 if ($file_data{'frame'} eq '') {
1911 if (int($file_data{'frame'}) != $frame) {
1914 if ($file_data{'content'} ne '') {
1917 unshift @files, $file_data{'filename'};
1921 ($frame_full_data{'ongtime'} eq '')
1923 $frame_data {'ongtime'} = $ongtime;
1924 $frame_full_data{'ongtime'} = $ongtime;
1930 ($frame_full_data{'timer'} eq '')
1933 $frame_data{'timer'} = int($timer);
1937 $r = write_data_file($frame_data_path, \%frame_data);
1939 print STDERR "fail writing $frame_data_path\n";
1941 print "write frame data fail\n";
1946 $goto_list{'title-' .$frame} = $frame_full_data{'title'};
1947 $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
1948 $r = write_data_file(DATA_LIST_PATH(), \%goto_list);
1950 print STDERR "fail writing ".DATA_LIST_PATH()."\n";
1952 print "write GOTO list fail\n";
1958 foreach my $file (@files) {
1959 $in_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file);
1960 $out_path = join_path(PATH_SEPARATOR(), WWW_PATH() , $file);
1962 print $in_path.' -> '.$out_path;
1964 $r = copy_encoded($in_path, $out_path);
1966 print (($r) ? " OK\n" : " FAIL\n");
1969 print STDERR "fail copy $in_path $out_path\n";