]> bicyclesonthemoon.info Git - ott/bsta/commitdiff
Done comment system v1.2.0
authorb <rowerynaksiezycu@gmail.com>
Tue, 9 Jan 2024 00:16:08 +0000 (00:16 +0000)
committerb <rowerynaksiezycu@gmail.com>
Tue, 9 Jan 2024 00:16:08 +0000 (00:16 +0000)
16 files changed:
2words.1.pl
bbcode.1.pl
botm-common
bsta.css
bsta_lib.1.pm
chat.1.pl
goto.1.pl
info.1.pl
ong.1.pl
opomba.1.pl
reset.1.pl
settings-again.txt
settings-bsta.txt
settings-debug.txt
settings.txt
viewer.1.pl

index 6f7030643e33c5412d43123df63dff4a93a51852..9a151035814a88fd1da4b85ada97e8427101d428 100644 (file)
@@ -191,7 +191,7 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STORY_PATH())) {
                                0 # pause
                        );
                }
-               write_data_file($fh, '', '', \%story);
+               write_data_file($fh, \%story);
        }
        
        if ($words ne '') {
@@ -226,7 +226,7 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STORY_PATH())) {
                                        if (split(/\r?\n/,$story{'content'}) >= (STORY_LENGTH-1)) {
                                                # store finished game
                                                $story_i_path = DATA_STORY_PATH.$story_id;
-                                               write_data_file($story_i_path, '', '', \%story);
+                                               write_data_file($story_i_path, \%story);
                                                # init new game
                                                $new_story{'id'     } = $story_id + 1;
                                                $new_story{'letter' } = '';
@@ -250,11 +250,11 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STORY_PATH())) {
                                                        );
                                                }
                                                # save new game
-                                               write_data_file($fh, '', '', \%new_story);
+                                               write_data_file($fh, \%new_story);
                                        }
                                        else {
                                                $message = 'To early to finish this wordgame.';
-                                               write_data_file($fh, '', '', \%story);
+                                               write_data_file($fh, \%story);
                                        }
                                }
                                else {
@@ -344,7 +344,7 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STORY_PATH())) {
                                                        }
                                                }
                                        }
-                                       write_data_file($fh, '', '', \%story);
+                                       write_data_file($fh, \%story);
                                }
                        }
                }
@@ -368,7 +368,7 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STORY_PATH())) {
                        $intf_mode,
                        $intf_pause
                );
-               write_data_file($fh, '', '', \%story);
+               write_data_file($fh, \%story);
        }
        @story_lines = split(/\r?\n/, $story{'content'});
        if(@story_lines & 1) {
index 3e3e05328db95ea948c9bffec8913bad89663a34..68953ab2ecd628c6bf823d040c1567535241181d 100644 (file)
@@ -28,7 +28,7 @@ use Encode ('encode', 'decode');
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
        'read_header_env',
-       'read_data_file', 'write_data_file',
+       'read_data_file',
        'url_query_decode',
        'join_path',
        'merge_url'
index 6b4b21b9139670faf83bb894ec378d49ecc6acdc..8dbd1b461e07f2894c4fcacacd681ab7c34b6bcb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 6b4b21b9139670faf83bb894ec378d49ecc6acdc
+Subproject commit 8dbd1b461e07f2894c4fcacacd681ab7c34b6bcb
index 62895587481c090d82925ebc503b2097bec40287..b1ae221aa4e6b0970c64740837936db05e39b4b5 100644 (file)
--- a/bsta.css
+++ b/bsta.css
@@ -233,6 +233,7 @@ div.fq
        text-align: left;
        border: solid #0057af 4px;
        font-family: monospace;
+       padding: 2px;
 }
 
 div.fq:hover
@@ -244,6 +245,7 @@ div.tq
 {
        text-align: left;
        border: solid #0057af 4px;
+       padding: 2px;
 }
 
 div.tq:hover
@@ -264,6 +266,18 @@ div.opomba:hover
        background-color: #bb6622;
 }
 
+div.opomba:target
+{
+       border-color: #bb6622;
+       background-color: #bb6622;
+}
+
+div.opomba:target:hover
+{
+       border-color: #bb6622;
+       background-color: #bb6622;
+}
+
 div.opomba_info
 {
        color: #ffffff!important;
@@ -274,6 +288,8 @@ div.opomba_text
 {
        background-color: #ffffff;
        color: #000000;
+       clear: both;
+       padding: 4px;
 }
 
 div.space
@@ -397,6 +413,22 @@ input.inbt:focus
        border-color: #bb6622;
 }
 
+input.hl {
+       background:none!important;
+       border:none!important; 
+       padding:0!important;
+/*     font-family:inherit;
+       font-size:inherit; */
+       font: inherit;
+       text-decoration:underline;
+       border-color: #0057af;
+       color: #0057af;
+}
+input.hl:hover {
+       border-color: #bb6622;
+       color: #bb6622;
+}
+
 .br
 {
        border-color: #bb6622!important;
@@ -435,6 +467,15 @@ input.inbt:focus
        color: #0057af!important;
 }
 
+.hu
+{
+       text-decoration:none!important;
+}
+.hu:hover
+{
+       text-decoration:underline!important;
+}
+
 div.le
 {
        float: left;
index 78c80a6fa315f6772e782ef0ca2e6be93dd3e29d..935bc2660152a322c77c36bdc136a7e394517a7c 100644 (file)
@@ -181,10 +181,10 @@ use constant tags_html => {
        '/fq'    => '</div>',
        'tq'     => '<div class="tq">',
        '/tq'    => '</div>',
-       'quote'  => '<div class="tq">',
-       'quote=' => '<div class="tq"><b class="br">',
-       'quote/='=> '</b> wrote:<br>',
-       '/quote' => '</div>',
+       'quote'  => '<div class="opomba"><div class="opomba_text">',
+       'quote=' => '<div class="opomba"><div class="opomba_info"><b>',
+       'quote/='=> '</b> wrote:</div><div class="opomba_text">',
+       '/quote' => '</div></div>',
        'ni'     => '<span class="ni">',
        '/ni'    => '</span>',
        'br'     => '<span class="br">',
@@ -951,6 +951,8 @@ sub print_viewer_page {
        );
        my $show_command_link = ($next_available || (!$access));
        my $show_command_cursor = ((!$next_available) || ($command eq ''));
+       my $show_words = ($password_ok || ($access && !$launch));
+       
        my $frame_indirect = !(
                (!$access) || (
                        ($frame <= $last_frame) &&
@@ -1074,20 +1076,20 @@ sub print_viewer_page {
        
        if ($password_ok) {
                $password_query = url_query_encode({'p', $settings->{'password'}});
-               $goto_url        = merge_url($goto_url       , {'query' => $password_query, 'append_query' => 1});
-               $info_url        = merge_url($info_url       , {'query' => $password_query, 'append_query' => 1});
-               $words_url       = merge_url($words_url      , {'query' => $password_query, 'append_query' => 1});
-               $bbcode_url      = merge_url($bbcode_url     , {'query' => $password_query, 'append_query' => 1});
-               $viewer_url      = merge_url($viewer_url     , {'query' => $password_query, 'append_query' => 1});
-               $viewer_0_url    = merge_url($viewer_0_url   , {'query' => $password_query, 'append_query' => 1});
-               $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query, 'append_query' => 1});
-               $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query, 'append_query' => 1});
-               $viewer_last_url = merge_url($viewer_last_url, {'query' => $password_query, 'append_query' => 1});
+               $goto_url        = merge_url($goto_url       , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $info_url        = merge_url($info_url       , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $words_url       = merge_url($words_url      , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $bbcode_url      = merge_url($bbcode_url     , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $viewer_url      = merge_url($viewer_url     , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $viewer_0_url    = merge_url($viewer_0_url   , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $viewer_prev_url = merge_url($viewer_prev_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $viewer_next_url = merge_url($viewer_next_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $viewer_last_url = merge_url($viewer_last_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
                if ($frame_indirect) {
-                       $frame_url     = merge_url($frame_url      , {'query' => $password_query, 'append_query' => 1});
+                       $frame_url     = merge_url($frame_url      , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
                }
                if ($nextframe_indirect) {
-                       $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1});
+                       $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
                }
        }
        my $_base_url        = html_entity_encode_dec($base_url       , 1);
@@ -1239,7 +1241,9 @@ sub print_viewer_page {
        print $fh '<a href="'.$_goto_url.'">GOTO</a>'."\n";
        print $fh '     <span style="float: right;">'."\n      ";
        if ($text_mode == TEXT_MODE->{'normal'}) {
-               print $fh '<a href="'.$_words_url.'">'.$words_link_text.'</a> | ';
+               if ($show_words) {
+                       print $fh '<a href="'.$_words_url.'">'.$words_link_text.'</a> | ';
+               }
        }
        else {
                print $fh '<a href="'.$_viewer_url.'">Without</a> | ';
@@ -1251,7 +1255,7 @@ sub print_viewer_page {
        print $fh "    </div>\n";
        print $fh "   </div>\n";
        
-       if ($text_mode == TEXT_MODE->{'words'}) {
+       if (($text_mode == TEXT_MODE->{'words'}) && $show_words) {
                print_comments($fh, $context, $settings, $words_data);
        }
        
@@ -1276,9 +1280,69 @@ sub print_comments {
        my $frame = int($context->{'frame'});
        my $page = int($context->{'words_page'});
        my $post_count = int($words_data->{'posts'});
+       my $id_start = $page * COMMENT_PAGE_LENGTH();
+       my $id_stop = $id_start + COMMENT_PAGE_LENGTH();
+       my $older = ($page > 0) ? ($page-1) : '';
+       my $newer;
+       my $password_query;
+       if ($id_stop >= $post_count) {
+                       $id_stop = $post_count;
+       }
+       else {
+               $newer = $page+1;
+       }
+       my $links;
+       
+       my $words_url = merge_url(
+               {'path' => CGI_VIEWER_PATH()},
+               {
+                       'path' => $frame,
+                       'query' => {'b' => TEXT_MODE->{'words'}},
+               }
+       );
+       my $older_url = merge_url(
+               $words_url,
+               {
+                       'query' => {'i' => $page-1},
+                       'fragment' => 'insw',
+                       'append_query' => 1
+               }
+       );
+       my $newer_url = merge_url(
+               $words_url,
+               {
+                       'query' => {'i' => $page+1},
+                       'fragment' => 'insw',
+                       'append_query' => 1
+               }
+       );
+       
+       if ($password_ok) {
+               $password_query = url_query_encode({'p', $settings->{'password'}});
+               $older_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               $newer_url = merge_url($older_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+       }
        
        my $_post_url = html_entity_encode_dec(CGI_WORDS_PATH(), 1);
        my $_password = html_entity_encode_dec($settings->{'password'}, 1);
+       my $_older_url = html_entity_encode_dec($older_url, 1);
+       my $_newer_url = html_entity_encode_dec($newer_url, 1);
+       
+       if (($older ne '') || ($newer ne '')) {
+               $links .= '    <div class="underlinks">'."\n";
+               $links .= '     ';
+               if ($older ne '') {
+                       $links .= '<a href="'.$_older_url.'">Older</a>'
+               }
+               if (($older ne '') && ($newer ne '')) {
+                       $links .= ' | ';
+               }
+               if ($newer ne '') {
+                       $links .= '<a href="'.$_newer_url.'">Newer</a>';
+               }
+               $links .= "\n";
+               $links .= '    </div>'."\n";
+       }
        
        print $fh '   <div class="space"></div>'."\n";
        print $fh '   <div id="insw" class="ins">'."\n";
@@ -1287,15 +1351,14 @@ sub print_comments {
        print $fh '     <h1 class="titletext" id="wordstitletext">Words</h1>'."\n";
        print $fh '    </div>'."\n";
        
+       if ($links ne '') {
+               print $fh $links;
+       }
+       
        print $fh '    <div class="undertext" id="words">'."\n";
        
        if ($post_count > 0) {
-               my $start = $page * COMMENT_PAGE_LENGTH();
-               my $stop = $start + COMMENT_PAGE_LENGTH();
-               if ($stop > $post_count) {
-                       $stop = $post_count;
-               }
-               for (my $i=$start; $i<$stop; ++$i) {
+               for (my $i=$id_start; $i<$id_stop; ++$i) {
                        my $ID = $words_data->{'content'}->[$i];
                        my $post_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $ID);
                        my %post_data = read_data_file($post_path);
@@ -1328,21 +1391,59 @@ sub print_comments {
                                        $time_tab[1]
                                );
                        }
+                       my $quote_url = merge_url(
+                               {'path' => CGI_WORDS_PATH()},
+                               {
+                                       'query' => {
+                                               'f' => $frame,
+                                               'quote' => $ID,
+                                               'p' => ($password_ok ? $settings->{'password'} : '')
+                                       }
+                               }
+                       );
+                       my $edit_url = merge_url(
+                               {'path' => CGI_WORDS_PATH()},
+                               {
+                                       'query' => {
+                                               'f' => $frame,
+                                               'edit' => $ID,
+                                               'key' => $post_data{'key'},
+                                               'username' => $post_data{'name'},
+                                               'p' => ($password_ok ? $settings->{'password'} : '')
+                                       }
+                               }
+                       );
+                       my $remove_url = merge_url(
+                               {'path' => CGI_WORDS_PATH()},
+                               {
+                                       'query' => {
+                                               'f' => $frame,
+                                               'remove' => $ID,
+                                               'key' => $post_data{'key'},
+                                               'username' => $post_data{'name'},
+                                               'p' => ($password_ok ? $settings->{'password'} : '')
+                                       }
+                               }
+                       );
                        
-                       my $_ID   = html_entity_encode_dec($ID, 1);
-                       my $_name = html_entity_encode_dec($post_data{'name'}, 1);
+                       my $_ID         = html_entity_encode_dec($ID, 1);
+                       my $_name       = html_entity_encode_dec($post_data{'name'}, 1);
+                       my $_quote_url  = html_entity_encode_dec($quote_url, 1);
+                       my $_edit_url   = html_entity_encode_dec($edit_url, 1);
+                       my $_remove_url = html_entity_encode_dec($remove_url, 1);
                        
                        print $fh '     <div id="'.$_ID.'"class="opomba">'."\n";
                        print $fh '      <div class="opomba_info">'."\n";
-                       print $fh '       '.$i.': '.$_name;
+                       print $fh '       <a href="#'.$_ID.'" class="bi hu">'.$i.': '.$_name;
                        if ($post_time_text ne '') {
                                print $fh ' &bull; '.$post_time_text;
                        }
                        if ($edit_time_text ne '') {
                                print $fh ' &bull; '.$edit_time_text;
                        }
+                       print $fh '</a>'."\n";
                        print $fh '       <div class="pr">'."\n";
-                       print $fh '        edit | remove'."\n";
+                       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";
                        print $fh '       </div>'."\n";
                        print $fh '      </div>'."\n";
                        print $fh '      <div class="opomba_text">'."\n";
@@ -1353,8 +1454,8 @@ sub print_comments {
                }
        }
        
-       print $fh '     <form method="get" action="'.$_post_url.'">'."\n";
-       print $fh '      <b>Your words</b>'."\n";
+       print $fh '     <form method="post" action="'.$_post_url.'">'."\n";
+       print $fh '      <b>Your words:</b>'."\n";
        print $fh '      <textarea class="inta" name="words" rows="4"></textarea>'."\n";
        print $fh '      <table cellpadding="0" cellspacing="0" border="0"><tr>'."\n";
        print $fh '       <td><b>Your name: </b></td>'."\n";
@@ -1367,7 +1468,10 @@ sub print_comments {
        print $fh '      </tr><tr>'."\n";
        print $fh '       <td><b>Leave this empty: </b></td>'."\n";
        print $fh '       <td><input class="intx" type="text" name="password2" value=""></td>'."\n";
-       print $fh '       <td><input class="inbt" type="submit" name="post" value="Send"></td>'."\n";
+       print $fh '       <td>'."\n";
+       print $fh '        <input class="inbt" type="submit" name="post" value="Send">'."\n";
+       print $fh '        <input class="inbt" type="submit" name="preview" value="Preview">'."\n";
+       print $fh '       </td>'."\n";
        print $fh '      </tr></table>'."\n";
        print $fh '      <input type="hidden" name="f" value="'.$frame.'">'."\n";
        if ($password_ok) {
@@ -1376,6 +1480,10 @@ sub print_comments {
        print $fh '     </form>'."\n";
        print $fh '    </div>'."\n";
        
+       if ($links ne '') {
+               print $fh $links;
+       }
+       
        print $fh '   </div>'."\n";
 }
 
@@ -1750,7 +1858,7 @@ sub ong {
                                $write_data = 1;
                        }
                        if ($write_data) {
-                               $r = write_data_file($frame_data_path, '', '', \%frame_data);
+                               $r = write_data_file($frame_data_path, \%frame_data);
                                unless ($r) {
                                        print STDERR "fail writing $frame_data_path\n";
                                        if ($print) {
@@ -1761,7 +1869,7 @@ sub ong {
                        }
                        $goto_list{'title-'  .$frame} = $frame_full_data{'title'};
                        $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
-                       $r = write_data_file(DATA_LIST_PATH(), '', '', \%goto_list);
+                       $r = write_data_file(DATA_LIST_PATH(), \%goto_list);
                        unless ($r) {
                                print STDERR "fail writing ".DATA_LIST_PATH()."\n";
                                if ($print) {
index 51fafdb2dd1c491fe2706626c9a9543ab641646c..583a46780ce7218543810cdf0eb8de10d5963e1b 100644 (file)
--- a/chat.1.pl
+++ b/chat.1.pl
@@ -156,7 +156,7 @@ if ($page < 0) {
                                                                $chat_state = CHAT_STATE->{'active'};
                                                                $chat{'state'} = $chat_state;
                                                        }
-                                                       write_data_file($fh, '', '', \%chat);
+                                                       write_data_file($fh, \%chat);
                                                }
                                                else {
                                                        $message = 'Invalid username.';
@@ -180,7 +180,7 @@ if ($page < 0) {
                                                                $chat_state = CHAT_STATE->{'ready'};
                                                                $chat{'state'} = $chat_state;
                                                        }
-                                                       write_data_file($fh, '', '', \%chat);
+                                                       write_data_file($fh, \%chat);
                                                }
                                                elsif ($words eq '') {
                                                        $message = 'Server ID missing.';
@@ -206,12 +206,12 @@ if ($page < 0) {
                                        if ($username =~ /^[A-Za-z]*$/) {
                                                $chat{'content'} .= 'leave@'.$username.': '.$words."\n";
                                                if ($username ne '') {
-                                                       write_data_file($fh, '', '', \%chat);
+                                                       write_data_file($fh, \%chat);
                                                }
                                                else {
                                                        my %new_chat;
                                                        if ($chat_state > 1) {
-                                                               write_data_file(DATA_CHAT_PATH.$chat_id, '', '', \%chat);
+                                                               write_data_file(DATA_CHAT_PATH.$chat_id, \%chat);
                                                                $new_chat{'id'} = $chat_id+1;
                                                        }
                                                        else {
@@ -219,7 +219,7 @@ if ($page < 0) {
                                                        }
                                                        $new_chat{'state'} = CHAT_STATE->{'disconnected'};
                                                        $new_chat{'content'} = '';
-                                                       write_data_file($fh, '', '', \%new_chat);
+                                                       write_data_file($fh, \%new_chat);
                                                }
                                        }
                                        else {
@@ -241,7 +241,7 @@ if ($page < 0) {
                                                        $chat_state = CHAT_STATE->{'active'};
                                                        $chat{'state'} = $chat_state;
                                                }
-                                               write_data_file($fh, '', '', \%chat);
+                                               write_data_file($fh, \%chat);
                                        }
                                        else {
                                                $message = 'Invalid username.';
@@ -305,10 +305,10 @@ my $newer_url = ($chat_id < ($last_id -1)) ?
 
 if ($password_ok) {
        my $password_query = url_query_encode({'p', $settings{'password'}});
-       $coin_url   = merge_url($coin_url  , {'query' => $password_query, 'append_query' => 1});
-       $oldest_url = merge_url($oldest_url, {'query' => $password_query, 'append_query' => 1});
-       $older_url  = merge_url($older_url , {'query' => $password_query, 'append_query' => 1});
-       $newer_url  = merge_url($newer_url , {'query' => $password_query, 'append_query' => 1});
+       $coin_url   = merge_url($coin_url  , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+       $oldest_url = merge_url($oldest_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+       $older_url  = merge_url($older_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+       $newer_url  = merge_url($newer_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
 }
 
 my $abbr = abbr_name($username);
index 1ecd8ce04680fdf7f5ba39c1b73d325f91a9bc94..8ea175383dabbc5761f8f6ec268eb69f36b60022 100644 (file)
--- a/goto.1.pl
+++ b/goto.1.pl
@@ -41,7 +41,8 @@ use bsta_lib (
        'print_html_start', 'print_html_end',
        'print_html_head_start', 'print_html_head_end',
        'print_html_body_start', 'print_html_body_end',
-       'write_index'
+       'write_index',
+       'merge_settings'
 );
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
@@ -201,7 +202,7 @@ for ($frame = 0; ; $frame += 1) {
                {'path' => $frame}
        );
        if ($password_ok) {
-               $viewer_url = merge_url($viewer_url, {'query' => $password_query, 'append_query' => 1});
+               $viewer_url = merge_url($viewer_url, {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
        }
        
        my $_viewer_url = html_entity_encode_dec($viewer_url, 1);
index c1eeda5e3b22942c754538a778f05523fdd606fa..09f185ae054d001fb76859c4b65af3c8c10f55c3 100644 (file)
--- a/info.1.pl
+++ b/info.1.pl
@@ -168,7 +168,12 @@ else {
        if ($method eq 'HEAD') {
                exit;
        }
-       write_data_file(\*STDOUT, '', '', \%state);
+       write_data_file(
+               \*STDOUT, \%state, '',
+               0, 0, 0,
+               '>>', 1
+       );
+       
        exit;
 }
 
@@ -219,4 +224,8 @@ print "\n";
 if($method eq 'HEAD') {
        exit;
 }
-write_data_file(\*STDOUT, '', '', \%frame_data);
+write_data_file(
+       \*STDOUT, \%frame_data, '',
+       0, 0, 0,
+       '>>', 1
+);
index 2ad11b84171eb3ae63db9da9638af985a450c818..c31009d2bf43bf95bf0e68bed8b3e51e0643ea1b 100644 (file)
--- a/ong.1.pl
+++ b/ong.1.pl
@@ -137,7 +137,7 @@ else {
                                                print "NO ONG\n";
                                        }
                                }
-                               write_data_file($fh, '', '', \%state);
+                               write_data_file($fh, \%state);
                        }
                }
        }
index 339d65df9a9b3a059c51f30b0be031767e4ee1c0..9e7ed380e0d58667ef1253c87d2e612015c6b575 100644 (file)
@@ -31,7 +31,9 @@ use botm_common (
        'read_data_file', 'write_data_file',
        'html_entity_encode_dec',
        'open_encoded',
-       'join_path'
+       'join_path',
+       'merge_url',
+       'make_id'
 );
 use bsta_lib (
        'TEXT_MODE',
@@ -40,16 +42,21 @@ use bsta_lib (
        'redirect',
        'print_html_start', 'print_html_end',
        'print_html_head_start', 'print_html_head_end',
-       'print_html_body_start', 'print_html_body_end'
+       'print_html_body_start', 'print_html_body_end',
+       'bb_to_html', 'eval_bb',
+       'merge_settings'
 );
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
 
 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
+###PERL_CGI_WORDS_PATH:     CGI_WORDS_PATH     = /bsta/w
 
 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
 ###PERL_DATA_WORDS_PATH:    DATA_WORDS_PATH    = /botm/data/bsta/words/
 
+###PERL_LOG_WORDS_PATH:     LOG_WORDS_PATH     = /botm/log/bsta/words.log
+
 ###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
 
 ###PERL_COMMENT_PAGE_LENGTH:COMMENT_PAGE_LENGTH= 16
@@ -93,7 +100,7 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
        $method = $1;
 }
-else{
+else {
        exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
 }
 
@@ -106,7 +113,7 @@ if ($method eq 'POST') {
                %cgi = merge_settings(\%cgi, \%cgi_post);
        }
        # multipart not supported
-       else{
+       else {
                exit fail_content_type($method, $http{'content-type'});
        }
 }
@@ -160,16 +167,18 @@ if ($ID ne '') {
 }
 
 if ($frame eq '') {
-       exit output(0, '', 'Frame ID not specified.');
+       exit output(0, '400 Bad Request', 'Frame ID not specified.');
 }
 
 $words_data_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $frame);
 
 unless (open_encoded($fh, "+<:encoding(UTF-8)", $words_data_path)) {
-       exit output(0, '500 Internal Server Error', 'Failed opening data file.');
+       unless (open_encoded($fh, "+>:encoding(UTF-8)", $words_data_path)) {
+               exit output(0, '500 Internal Server Error', 'Failed opening data file.', 1);
+       }
 }
 unless (flock($fh, 2)) {
-       exit output(0, '500 Internal Server Error', 'Failed locking data file.');
+       exit output(0, '500 Internal Server Error', 'Failed locking data file.', 1);
 }
 
 %words_data = read_data_file(
@@ -190,33 +199,47 @@ for (my $i=0; $i< scalar(@post_list); $i +=1) {
        }
 }
 
-if ($remove) {
+if ($remove || ($ID ne '')) {
        unless ($index ne '') {
                close($fh);
-               exit output(0, '404 Not Found', 'Nothing to remove.');
+               exit output(0, '404 Not Found', $remove ? 'Nothing to remove.' : 'No such message.');
        }
        unless ($cgi{'key'} eq $post_data{'key'}) {
                close($fh);
-               exit output(0, '403 Forbidden', 'Invalid request.');
+               exit output(0, '400 Bad Request', 'Invalid request.');
        }
-       
-       if (($cgi{'username'} eq '') && ($cgi{'password'} eq ''))
-       {
+}
+if ($remove) {
+       if ($cgi{'i'} eq '') { # followed a link, not confirmed yet
                close($fh);
-               exit output(0, '', '', 0, 1);
+               exit output(0, '', '', 1);
        }
-       
-       unless ($cgi{'username'} ne '') {
+}
+else {
+       unless ($post) { # followed a link, not confirmed yet
                close($fh);
-               exit output(0, '403 Forbidden', 'Missing user name.', 0, 1);
+               exit output(0, '', '', 1);
        }
+}
+if (!$remove) {
+       unless ($cgi{'words'} ne '') {
+               exit output(0, '400 Bad Request', 'Where are your words?', 1);
+       }
+}
+unless ($cgi{'username'} ne '') {
+       close($fh);
+       exit output(0, '400 Bad Request', 'Missing user name.', 1);
+}
+if ($remove || ($ID ne '')) {
        unless ($cgi{'username'} eq $post_data{'name'}) {
                close($fh);
-               exit output(0, '403 Forbidden', 'Wrong user name.', 0, 1);
+               exit output(0, '403 Forbidden', 'Wrong user name.', 1);
        }
-       unless ($cgi{'password'} ne '') {
+}
+if ($remove || ($ID ne '')) {
+               unless ($cgi{'password'} ne '') {
                close($fh);
-               exit output(0, '403 Forbidden', 'Missing password.', 0, 1);
+               exit output(0, '400 Bad Request', 'Missing password.', 1);
        }
        unless (
                ($cgi{'password'} eq $post_data{'password'}) || (
@@ -225,48 +248,139 @@ if ($remove) {
                )
        ) {
                close($fh);
-               exit output(0, '403 Forbidden', 'Wrong password.', 0, 1);
+               exit output(0, '403 Forbidden', 'Wrong password.', 1);
        }
-       
-       # all conditions fulfilled
-       
+       if ($password_ok) {
+               $cgi{'password'} = $post_data{'password'};
+       }
+}
+unless ($cgi{'password2'} eq '') {
+       close($fh);
+       exit output(0, '', 'Please don\'t write anything in the place which should remain empty.', 1);
+       # no error code to confuse spambot :)
+}
+
+# all conditions fulfilled
+
+if ($remove) {
        splice @post_list, $index, 1;
        $words_data{'posts'} = scalar(@post_list);
        $words_data{'content'} = \@post_list;
        
-       $r = write_data_file($fh, '', '', \%words_data);
-       unless($r) {
+       $r = write_data_file(
+               $fh, # file 
+               \%words_data,
+               '',  # encoding
+               0,   # no header
+               0,   # header only
+               1    # as list
+       );
+       unless ($r) {
                close($fh);
                exit output(0, '500 Internal Server Error', 'Failed writing data file.');
        }
+       
+       close ($fh);
+       
+       if (open_encoded($fh, ">>:encoding(UTF-8)", LOG_WORDS_PATH())) {
+               print $fh "$time REMOVE $ID\n";
+               write_data_file(
+                       $fh, \%post_data, '',
+                       0, 0, 0,
+                       '>>', 1
+               );
+               print $fh "\n\n";
+               close ($fh);
+       }
+       
        $ID = 'insw';
        exit output(1);
 }
 
+if ($ID eq '') {
+       $ID = make_id($frame, 1);
+}
+if ($index eq '') {
+       $index = scalar(@post_list);
+       $page = int($index / COMMENT_PAGE_LENGTH());
+       push @post_list, $ID;
+}
+$words_data{'posts'} = scalar(@post_list);
+$words_data{'content'} = \@post_list;
+
+$post_data_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $ID);
+
+$post_data{'frame'} = $frame;
+$post_data{'name'} = $cgi{'username'};
+$post_data{'password'} = $cgi{'password'};
+if ($post_data{'posttime'} eq '') {
+       $post_data{'posttime'} = $time;
+}
+else {
+       $post_data{'edittime'} = $time;
+}
+if ($post_data{'key'} eq '') {
+       my $new_key = '';
+       for (my $i=1; $i<16; $i+=1) {
+               $new_key .= sprintf('%02X', int(rand(0x100)));
+       }
+       $post_data{'key'} = $new_key;
+}
+$post_data{'content'} = $cgi{'words'};
+
+$r = write_data_file($post_data_path, \%post_data);
+unless ($r) {
+       close($fh);
+       exit output(0, '500 Internal Server Error', 'Failed writing post file.', 1, 0);
+}
+
+$r = write_data_file(
+       $fh, # file 
+       \%words_data,
+       '',  # encoding
+       0,   # no header
+       0,   # header only
+       1    # as list
+);
+unless ($r) {
+       close($fh);
+       exit output(0, '500 Internal Server Error', 'Failed writing data file.', 1, 0);
+}
+
 close($fh);
 
-exit output(0, '', '???');
+if (open_encoded($fh, ">>:encoding(UTF-8)", LOG_WORDS_PATH())) {
+       print $fh "$time POST $ID\n";
+       write_data_file(
+               $fh, \%post_data, '',
+               0, 0, 0,
+               '>>', 1
+       );
+       print $fh "\n\n";
+       close ($fh);
+}
+
+exit output(1);
+
 
 sub output {
-       (
-               my $posted, my $status, my $message,
-               my $edit, my $remove,
-       ) = @_;
+       (my $done, my $status, my $message, my $show_content) = @_;
        
-       if ($posted) {
-               my $redirect_url = merge_url(
-                       {'path' => CGI_VIEWER_PATH()},
-                       {
-                               'path' => $frame,
-                               'query' => {
-                                       'b' => TEXT_MODE->{'words'},
-                                       'i' => $page,
-                                       'p' => ($password_ok ? $settings{'password'} : '')
-                               },
-                               'fragment' => $ID
-                       }
-               );
-               return redirect ($method, $redirect_url, 303);
+       
+       my $return_url = merge_url(
+               {'path' => CGI_VIEWER_PATH()},
+               {
+                       'path' => $frame,
+                       'query' => {
+                               'b' => TEXT_MODE->{'words'},
+                               'i' => $page,
+                               'p' => ($password_ok ? $settings{'password'} : '')
+                       },
+                       'fragment' => $ID
+               }
+       );
+       if ($done) {
+               return redirect ($method, $return_url, 303);
        }
        
        print "Content-type: text/html\n";
@@ -278,14 +392,62 @@ sub output {
                return;
        }
        
+       my $title;
+       my $name;
+       my $content;
+       
+       if ($remove) {
+               $title = 'Remove message "'.$ID.'"';
+       }
+       elsif ($ID ne '') {
+               $title = 'Edit message "'.$ID.'"';
+       }
+       else {
+               $title = 'Words';
+       }
+       
+       if ($cgi{'username'} ne '') {
+               $name = $cgi{'username'}
+       }
+       elsif ($post_data{'name'} ne '') {
+               $name = $post_data{'name'}
+       }
+       else {
+               $name = '';
+       }
+       
+       if ($cgi{'words'} ne '') {
+               $content = $cgi{'words'};
+       }
+       elsif ($quote ne '') {
+               my $quote_data_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $quote);
+               my %quote_data = read_data_file($quote_data_path);
+               $content = '[quote="'.$quote_data{'name'}.'"]'.$quote_data{'content'}.'[/quote]';
+       }
+       elsif (($cgi{'edit'} ne '') || $remove) {
+               $content = $post_data{'content'};
+       }
+       else {
+               $content = '';
+       }
+       
+       my $_key = html_entity_encode_dec($post_data{'key'}, 1);
+       my $_ID = html_entity_encode_dec($ID, 1);
+       my $_title = html_entity_encode_dec($title, 1);
        my $_message = html_entity_encode_dec($message, 1);
+       my $_password = html_entity_encode_dec($settings{'password'}, 1);
        my $_story = html_entity_encode_dec($settings{'story'}, 1);
+       my $_name = html_entity_encode_dec($name, 1);
+       my $_content = html_entity_encode_dec($content, 1);
+       my $_empty = html_entity_encode_dec($cgi{'password2'}, 1);
        my $_website_name = html_entity_encode_dec(WEBSITE_NAME(), 1);
+       my $_post_url = html_entity_encode_dec(CGI_WORDS_PATH(), 1);
+       my $_return_url = html_entity_encode_dec($return_url, 1);
                
        print_html_start(\*STDOUT);
        print_html_head_start(\*STDOUT);
        
-       print '  <title>Words &bull; '.$_story.' &bull; '.$_website_name.'</title>';
+       print '  <title>'.$_title.' &bull; '.$_story.' &bull; '.$_website_name.'</title>';
        
        print_html_head_end(\*STDOUT);
        print_html_body_start(\*STDOUT);
@@ -293,7 +455,7 @@ sub output {
        print '   <div id="inst" class="ins">'."\n";
        
        print '    <div id="title">'."\n";
-       print '     <h1 id="titletext">Words</h1>'."\n";
+       print '     <h1 id="titletext">'.$_title.'</h1>'."\n";
        print '    </div>'."\n";
        
        print '   </div>'."\n";
@@ -308,20 +470,64 @@ sub output {
                print '   </div>'."\n";
        }
        
-       if ($edit) {
-               print "EDIT\n";
-       }
-       elsif ($remove) {
-               print "REMOVE\n";
+       if ($show_content) {
+               print '   <div id="insw" class="ins">'."\n";
+               
+               print '    <div class="undertext" id="words">'."\n";
+               print '     <form method="post" action="'.$_post_url.'">'."\n";
+               unless ($remove) {
+                       print '      <b>Your words:</b>'."\n";
+                       print '      <textarea class="inta" name="words" rows="4">'.$_content.'</textarea>'."\n";
+               }
+               print '      <table cellpadding="0" cellspacing="0" border="0"><tr>'."\n";
+               print '       <td><b>Your name: </b></td>'."\n";
+               print '       <td><input class="intx" type="text" name="username" value="'.$_name.'"></td>'."\n";
+               print '       <td></td>'."\n";
+               print '      </tr><tr>'."\n";
+               print '       <td><b>'.(($ID ne '') ? 'Password' : 'Optional password').': </b></td>'."\n";
+               print '       <td><input class="intx" type="password" name="password" value=""></td>'."\n";
+               print '       <td>'.(($ID ne '') ? '' : '(if you want to edit later)').'</td>'."\n";
+               print '      </tr><tr>'."\n";
+               print '       <td><b>Leave this empty: </b></td>'."\n";
+               print '       <td><input class="intx" type="text" name="password2" value="'.$_empty.'"></td>'."\n";
+               if ($remove) {
+                       print '       <td><input class="inbt" type="submit" name="remove" value="Remove"></td>'."\n";
+               }
+               else {
+                       print '       <td>'."\n";
+                       print '        <input class="inbt" type="submit" name="post" value="'.(($ID ne '') ? 'Update' : 'Send').'">'."\n";
+                       print '        <input class="inbt" type="submit" name="preview" value="Preview">'."\n";
+                       print '       </td>'."\n";
+               }
+               print '      </tr></table>'."\n";
+               print '      <input type="hidden" name="f" value="'.$frame.'">'."\n";
+               if ($ID ne '') {
+                       print '      <input type="hidden" name="i" value="'.$_ID.'">'."\n";
+               }
+               print '      <input type="hidden" name="key" value="'.$_key.'">'."\n";
+               if ($password_ok) {
+                       print '      <input type="hidden" name="p" value="'.$_password.'">'."\n";
+               }
+               print '     </form>'."\n";
+               if ($content ne ''){
+                       print '     <br>'."\n";
+                       print '     <div id="preview"class="opomba">'."\n";
+                       print '      <div class="opomba_info">'."\n";
+                       print '       Preview:'."\n";
+                       print '      </div>'."\n";
+                       print '      <div class="opomba_text">'."\n";
+                 print bb_to_html(eval_bb($content, 0))."\n";
+                       print '      </div>'."\n";
+                       print '     </div>'."\n";
+               }
+               print '    </div>'."\n";
+               print '    <div id="underlinks">'."\n";
+               print '     <a href="'.$_return_url.'">Return</a>'."\n";
+               print '    </div>'."\n";
+               
+               print '   </div>'."\n";
        }
        
        print_html_body_end(\*STDOUT); # , $ong_state == STATE->{'inactive'}
        print_html_end(\*STDOUT);
 }
-
-
-
-
-
-
-
index b289b5e5ec7fa6a35b871c59e41b384659a206e3..00f612988f81fcb311e18cc7675842040c79d349 100644 (file)
@@ -27,6 +27,8 @@ use Encode ('encode', 'decode');
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
        'read_data_file', 'write_data_file',
+       'opendir_encoded', 'readdir_decoded', 'unlink_encoded',
+       'join_path'
 );
 use bsta_lib (
        'STATE', 'INTF_STATE', 'CHAT_STATE',
@@ -38,11 +40,14 @@ binmode STDOUT, ':encoding(UTF-8)';
 binmode STDERR, ':encoding(UTF-8)';
 decode_argv();
 
+###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
+
 ###PERL_DATA_CHAT_PATH:     DATA_CHAT_PATH     = /botm/data/bsta/chat
 ###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/state
 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
 ###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
+###PERL_DATA_WORDS_PATH:    DATA_WORDS_PATH    = /botm/data/bsta/words/
 
 ###PERL_RESET_PASSWORD:     RESET_PASSWORD     = ''
 
@@ -91,10 +96,10 @@ unless (
 %goto_list = (
 );
 
-write_data_file(DATA_STATE_PATH(), '', '', \%state);
-write_data_file(DATA_STORY_PATH(), '', '', \%story);
-write_data_file(DATA_CHAT_PATH() , '', '', \%chat);
-write_data_file(DATA_LIST_PATH() , '', '', \%goto_list);
+write_data_file(DATA_STATE_PATH(), \%state);
+write_data_file(DATA_STORY_PATH(), \%story);
+write_data_file(DATA_CHAT_PATH() , \%chat);
+write_data_file(DATA_LIST_PATH() , \%goto_list);
 
 write_index(
        \%state,
@@ -103,3 +108,16 @@ write_index(
        $story{'state'},
        0 # pause
 );
+
+if (opendir_encoded(my $dir, DATA_WORDS_PATH())) {
+       print DATA_WORDS_PATH()."\n";
+       while (my $file_name = readdir_decoded($dir)) {
+               print $file_name."\n";
+               if ($file_name !~ /^[0-9]+$/) {
+                       next;
+               }
+               my $full_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $file_name);
+               print $full_path."\n";
+               unlink_encoded ($full_path);
+       }
+}
\ No newline at end of file
index aed8a7587b84ff7d6d349d2ef02b82a20fcaacb6..e9f74424f67cd1ac1f38588fc8f61786caaa1d51 100644 (file)
@@ -85,7 +85,7 @@ story_length    : 16
 firstpage_length: 4
 page_length     : 16
 
-comment_page_length: 16
+comment_page_length: 40
 
 story_credits: "BSTA" by Balthasar Szczepański
 intf_credits: Online interface © Balthasar Szczepański; AGPL 3 license
index 3efc3ad6fe1f3a9e9e0b61912b1d43604e9d686e..67cbc4a5d38852110783cc763c1e6d71821fb034 100644 (file)
@@ -85,7 +85,7 @@ story_length    : 16
 firstpage_length: 4
 page_length     : 16
 
-comment_page_length: 16
+comment_page_length: 40
 
 story_credits: "BSTA" by Balthasar Szczepański
 intf_credits: Online interface © Balthasar Szczepański; AGPL 3 license
index ffca4617befb10ac27de211cafe143c02c618206..5ee085f4b99b64783dbe31e9a6309bf3918d1a5d 100644 (file)
@@ -85,7 +85,7 @@ story_length    : 16
 firstpage_length: 4
 page_length     : 16
 
-comment_page_length: 16
+comment_page_length: 4
 
 story_credits: "BSTA" by Balthasar Szczepański
 intf_credits: Online interface © Balthasar Szczepański; AGPL 3 license
index b213531d991f92473e572c701690e86e4c50b99a..3152459838687adfad4ada9fccea4bb1cd259cc0 100644 (file)
@@ -67,8 +67,9 @@ _data_state_path    = @_PATH( $data_path, state      )
 _data_story_path    = @_PATH( $data_path, story      )
 _data_words_path    = @_PATH( $data_path, words      )
 
-_log_path           = @_PATH( $log_path,        )
-_log_ong_path       = @_PATH( $log_path, ong.log)
+_log_path           = @_PATH( $log_path,          )
+_log_ong_path       = @_PATH( $log_path, ong.log  )
+_log_words_path     = @_PATH( $log_path, words.log)
 
 _www_path           = @_PATH( $www_path,          )
 _www_index_path     = @_PATH( $www_path, index.htm)
@@ -176,7 +177,8 @@ PERL_DATA_STATE_PATH    = @_PERL_CONSTANT_STR( DATA_STATE_PATH   , $_data_state_
 PERL_DATA_STORY_PATH    = @_PERL_CONSTANT_STR( DATA_STORY_PATH   , $_data_story_path   )
 PERL_DATA_WORDS_PATH    = @_PERL_CONSTANT_STR( DATA_WORDS_PATH   , $_data_words_path   )
 
-PERL_LOG_PATH           = @_PERL_CONSTANT_STR( LOG_PATH, $_log_path)
+PERL_LOG_PATH           = @_PERL_CONSTANT_STR( LOG_PATH      , $_log_path      )
+PERL_LOG_WORDS_PATH     = @_PERL_CONSTANT_STR( LOG_WORDS_PATH, $_log_words_path)
 
 PERL_WWW_PATH           = @_PERL_CONSTANT_STR( WWW_PATH      , $_www_path      )
 PERL_WWW_INDEX_PATH     = @_PERL_CONSTANT_STR( WWW_INDEX_PATH, $_www_index_path)
index 1a4637f9c6c1f0b106613f23ce2a5a074990ca3c..24a72b49812853599d9dfda7ef0b8a2341224f42 100644 (file)
@@ -165,7 +165,7 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                                else {
                                        $new_state{'state'} = STATE->{'ready'};
                                }
-                               write_data_file($fh, '', '', \%new_state);
+                               write_data_file($fh, \%new_state);
                        }
                }
                elsif (
@@ -212,7 +212,7 @@ if (open_encoded($fh, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                                        $r = write_index(\%state, \%settings);
                                }
                                if ($r) {
-                                       $r = write_data_file($fh,     '','', \%state);
+                                       $r = write_data_file($fh, \%state);
                                }
                                unless ($r) {
                                        # FAILED ONG! Story as if it was inactive!