]> bicyclesonthemoon.info Git - ott/post/commitdiff
now generate with full page html & css
authorb <rowerynaksiezycu@gmail.com>
Tue, 29 Aug 2023 22:45:30 +0000 (22:45 +0000)
committerb <rowerynaksiezycu@gmail.com>
Tue, 29 Aug 2023 22:45:30 +0000 (22:45 +0000)
botm-common
post_common.1.pm
preview.1.pl

index bdf2577b82d59fed0450c2a8fc61a46efe5d19eb..6b789b4bd0ac1d87d3a2d8598ad229298e2c4777 160000 (submodule)
@@ -1 +1 @@
-Subproject commit bdf2577b82d59fed0450c2a8fc61a46efe5d19eb
+Subproject commit 6b789b4bd0ac1d87d3a2d8598ad229298e2c4777
index e0c78dc038dbd003cc713008b3c13517c3b75c2e..b1a3f8e3a2bfcc2031b519076a5cf9b8d763bd6d 100644 (file)
@@ -31,7 +31,9 @@ our @EXPORT_OK = (
        'prepare_post',
        'wget',
        'CODE',
-       'bbcode_to_html'
+       'bbcode_to_html',
+       'HTML_PAGE_START', 'HTML_PAGE_END', 'HTML_POST_START', 'HTML_POST_END',
+       'HTML_STYLE'
 );
 
 ###PERL_LIB: use lib '/botm/lib/post';
@@ -181,6 +183,194 @@ sub prepare_post {
        return %post;
 }
 
+########
+# HTML #
+########
+
+use constant HTML_PAGE_START => {
+       'botm' => [
+               '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">',
+               '<html lang="en"><head>',
+               '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">',
+               '<title>&_title;</title>',
+               '<link rel="stylesheet" href="&_css_url;">',
+               '<style>&_inline_css;</style>',
+               '</head><body>',
+               # '<h1>&_title;</h1>',
+               ''
+       ],
+       'bsta' => [
+       ],
+       'phpbb' => [
+       ]
+};
+
+use constant HTML_POST_START => {
+       'botm' => [
+               '<div class="pl">',
+               '<div class="pls">&_subject;</div>',
+               '<div class="plt">&_username; &bull; &_time; </div>',
+               '<div class="&_post_class;">',
+               ''
+       ],
+       'bsta' => [
+       ],
+       'phpbb' => [
+       ]
+};
+
+use constant HTML_POST_END => {
+       'botm' => [
+               '</div></div>',
+               ''
+       ],
+       'bsta' => [
+       ],
+       'phpbb' => [
+       ]
+};
+
+use constant HTML_PAGE_END => {
+       'botm' => [
+               '</body></html>'
+       ],
+       'bsta' => [
+       ],
+       'phpbb' => [
+       ]
+};
+
+# TODO get CSS from silent chronotransponder
+use constant HTML_STYLE => {
+       'botm' => [
+               '',
+               'html',
+               '{',
+               '  background-color: #ffffff;',
+               '  border-color: #000000;',
+               '  color: #000000;',
+               '}',
+               'a',
+               '{',
+               '  border-color:',
+               '  #0057af;',
+               '  color: #0057af;',
+               '  text-decoration:underline;',
+               '}',
+               'a:visited',
+               '{',
+               '  border-color: #bb6622;',
+               '  color: #bb6622;',
+               '}',
+               'a:hover',
+               '{',
+               '  border-color: #bb6622;',
+               '  color: #bb6622;',
+               '}',
+               'a:hover:visited',
+               '{',
+               '  border-color: #0057af;',
+               '  color: #0057af;',
+               '}',
+               '::selection',
+               '{',
+               '  color: #ffffff;',
+               '  background-color: #bb6622;',
+               '}',
+               '.br',
+               '{',
+               '  border-color:',
+               '  #bb6622!important;',
+               '  color: #bb6622!important;',
+               '}',
+               '.ni',
+               '{',
+               '  border-color: #0057af!important;',
+               '  color: #0057af!important;',
+               '}',
+               '.bi',
+               '{',
+               '  border-color: #ffffff!important;',
+               '  color: #ffffff!important;',
+               '}',
+               'div.pl',
+               '{',
+               '  border-color: #0057af;',
+               '  border-width: 4px 16px 16px 16px;',
+               '  border-style: solid;',
+               '}',
+               '.tp',
+               '{',
+               '  text-align: right;',
+               '}',
+               'div.pls',
+               '{',
+               '  text-align: center;',
+               '  font-weight: bold;',
+               '  color: #ffffff;',
+               '  background-color: #0057af;',
+               '  width: 100%;',
+               '}',
+               'div.plt',
+               '{',
+               '  color: #ffffff;',
+               '  background-color: #0057af;',
+               '  width: 100%;',
+               '  clear: both;',
+               '}',
+               'div.plw',
+               '{',
+               '  background-color: #ffffff;',
+               '  color: #000000;',
+               '  padding: 4px;',
+               '  clear: both;',
+               '}',
+               'blockquote.pq',
+               '{',
+               '  color: #000000;',
+               '  background-color: #ffffff;',
+               '  text-decoration: inherit;',
+               '  font: inherit;',
+               '  border-color: #bb6622;',
+               '  border-width: 4px;',
+               '  border-style: solid;',
+               '  padding: 2px;',
+               '}',
+               'cite.pq',
+               '{',
+               '  text-decoration:',
+               '  inherit;',
+               '  font: inherit;',
+               '}',
+               'dl.pq',
+               '{',
+               '  color: #000000;',
+               '  background-color: #ffffff;',
+               '  border-color: #0057af;',
+               '  border-width: 4px;',
+               '  border-style: solid;',
+               '  padding: 2px;',
+               '}',
+               'dt.pq',
+               '{',
+               '  color: #0057af;',
+               '  font-weight: bold;',
+               '}',
+               'code.pq',
+               '{',
+               '  max-height: 200px;',
+               '  overflow: auto;',
+               '  white-space: normal;',
+               '  display: block;',
+               '}',
+               ''
+       ],
+       'bsta' => [
+       ],
+       'phpbb' => [
+       ]
+};
+
 ##########
 # BBCODE #
 ##########
@@ -777,7 +967,7 @@ sub bbcode_to_html {
                                if ($print) {
                                        print "unmatched tag\n";
                                }
-                               $add_html .= html_entity_encode_dec($tag);
+                               $add_html .= html_entity_encode_dec($tag, 1);
                        }
                        
                        elsif ($tag_name eq '_') {
@@ -786,18 +976,26 @@ sub bbcode_to_html {
                        
                        elsif ($tag_name eq 'quote') {
                                if ($tag_value eq '') {
-                                       $add_html .= '<blockquote class="uncited"><div>';
-                                       #$add_html .= '<blockquote class="pq"><div>';
+                                       if ($cmd_options->{'post-style'} eq 'phpbb') {
+                                               $add_html .= '<blockquote class="uncited"><div>';
+                                       }
+                                       else {
+                                               $add_html .= '<blockquote class="pq"><div>';
+                                       }
                                }
                                else {
                                        if ($tag_value =~ m/^"(.*)"$/gs) {
                                                $tag_value = bbcode_to_html($cmd_options, $post, $1);
                                        }
                                        else {
-                                               $tag_value = 'QUOTE MARKS MISSING; '.html_entity_encode_dec($tag_value)
+                                               $tag_value = 'QUOTE MARKS MISSING; '.html_entity_encode_dec($tag_value, 1)
+                                       }
+                                       if ($cmd_options->{'post-style'} eq 'phpbb') {
+                                               $add_html .= '<blockquote><div><cite>'.$tag_value.' wrote:</cite>';
+                                       }
+                                       else {
+                                               $add_html .= '<blockquote class="pq"><div><cite class="pq"><b class="br">'.$tag_value.'</b> wrote:</cite><br>';
                                        }
-                                       $add_html .= '<blockquote><div><cite>'.$tag_value.' wrote:</cite>';
-                                       # $add_html .= '<blockquote class="pq"><div><cite class="pq"><b class="br">'.$tag_value.'</b> wrote:</cite><br>';
                                }
                        }
                        
@@ -827,11 +1025,15 @@ sub bbcode_to_html {
                                        if ($print) {
                                                print "not a tag, actually\n";
                                        }
-                                       $add_html .= html_entity_encode_dec($tag);
+                                       $add_html .= html_entity_encode_dec($tag, 1);
                                }
                                else {
-                                       $add_html .= '<dl class="codebox"><dt>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code>';
-                                       # $add_html .= '<dl class="pq"><dt class="pq">Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code class="pq">';
+                                       if ($cmd_options->{'post-style'} eq 'phpbb') {
+                                               $add_html .= '<dl class="codebox"><dt>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code>';
+                                       }
+                                       else {
+                                               $add_html .= '<dl class="pq"><dt class="pq">Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code class="pq">';
+                                       }
                                }
                                if ($tag_value ne '') {
                                        $add_html .= 'INVALID VALUE; ';
@@ -850,7 +1052,7 @@ sub bbcode_to_html {
                                                print 'Implied value: '.$tag_value."\n";
                                        }
                                }
-                               $add_html .= '<a href="'.html_entity_encode_dec($tag_value).'" class="postlink">';
+                               $add_html .= '<a href="'.html_entity_encode_dec($tag_value, 1).'" class="postlink">';
                        }
                        
                        elsif ($tag_name eq 'size') {
@@ -907,8 +1109,12 @@ sub bbcode_to_html {
                        }
                        
                        elsif ($tag_name eq 'spoiler') {
-                               $add_html .= '<div style="margin:20px; margin-top:5px"><div class="quotetitle"><b>Spoiler:</b> <input type="button" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onclick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\';        this.innerText = \'\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; }" /></div><div class="quotecontent"><div style="display: none;">';
-                               # $add_html .= '<div style="margin:20px; margin-top:5px"><div class="quotetitle"><b>Spoiler:</b> <input type="button" class="pk" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onclick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\';        this.innerText = \'\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; }" /></div><div class="quotecontent"><div style="display: none;">';
+                               if ($cmd_options->{'post-style'} eq 'phpbb') {
+                                       $add_html .= '<div style="margin:20px; margin-top:5px"><div class="quotetitle"><b>Spoiler:</b> <input type="button" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onclick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\';        this.innerText = \'\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; }" /></div><div class="quotecontent"><div style="display: none;">';
+                               }
+                               else {
+                                       $add_html .= '<div style="margin:20px; margin-top:5px"><div class="quotetitle"><b>Spoiler:</b> <input type="button" class="pk" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onclick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\';        this.innerText = \'\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; }" /></div><div class="quotecontent"><div style="display: none;">';
+                               }
                                if ($tag_value ne '') {
                                        $add_html .= 'INVALID VALUE; ';
                                }
@@ -953,7 +1159,7 @@ sub bbcode_to_html {
                                if ($print) {
                                        print "unknown tag\n"
                                }
-                               $add_html .= html_entity_encode_dec($tag);
+                               $add_html .= html_entity_encode_dec($tag, 1);
                        }
                }
                
@@ -964,7 +1170,7 @@ sub bbcode_to_html {
                                if ($print) {
                                        print "unmatched tag\n";
                                }
-                               $add_html .= html_entity_encode_dec($tag_end);
+                               $add_html .= html_entity_encode_dec($tag_end, 1);
                        }
                        
                        elsif ($tag_name eq '_') {
@@ -985,7 +1191,7 @@ sub bbcode_to_html {
                                        if ($print) {
                                                print "not a tag, actually\n";
                                        }
-                                       $add_html .= html_entity_encode_dec($tag_end);
+                                       $add_html .= html_entity_encode_dec($tag_end, 1);
                                }
                                else {
                                        $add_html .= '</code></dd></dl>';
@@ -993,8 +1199,12 @@ sub bbcode_to_html {
                        }
                        
                        elsif ($tag_name eq 'img') {
-                               $add_html .= '" alt="Image" />';
-                               # $add_html .= '" alt="Image">';
+                               if ($cmd_options->{'post-style'} eq 'phpbb') {
+                                       $add_html .= '" alt="Image" />';
+                               }
+                               else {
+                                       $add_html .= '" alt="Image">';
+                               }
                                if ($tag_value ne '') {
                                        $add_html .= 'INVALID VALUE; ';
                                }
@@ -1042,7 +1252,7 @@ sub bbcode_to_html {
                                if ($print) {
                                        print "unknown tag\n";
                                }
-                               $add_html .= html_entity_encode_dec($tag_end);
+                               $add_html .= html_entity_encode_dec($tag_end, 1);
                        }
                }
                
@@ -1062,7 +1272,7 @@ sub bbcode_to_html {
                        # and this will not interfere with detecting the start and end
                        # of an URL which needs to be escaped anyway.
                        
-                       $text = html_entity_encode_dec($text);
+                       $text = html_entity_encode_dec($text, 1);
                        
                        # preserve indentation in [code]
                        if ($in_code > 0) {
@@ -1077,13 +1287,21 @@ sub bbcode_to_html {
                        
                        # convert smilies
                        if (($post->{'smilies'}) and ($tag_name !~ /^((code)|(img))$/)) {
-                               $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' <img title="'.BBCODE_SMILEY_TITLE->{$2}.'" alt="'.$2.'" src="'.BBCODE_SMILEY_FILE->{$2}.'" \/> '/gme;
-                               # $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' <img title="'.BBCODE_SMILEY_TITLE->{$2}.'" alt="'.$2.'" src="'.BBCODE_SMILEY_FILE->{$2}.'"> '/gme;
+                               if ($cmd_options->{'post-style'} eq 'phpbb') {
+                                       $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' <img title="'.BBCODE_SMILEY_TITLE->{$2}.'" alt="'.$2.'" src="'.BBCODE_SMILEY_FILE->{$2}.'" \/> '/gme;
+                               }
+                               else {
+                                       $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' <img title="'.BBCODE_SMILEY_TITLE->{$2}.'" alt="'.$2.'" src="'.BBCODE_SMILEY_FILE->{$2}.'"> '/gme;
+                               }
                        }
                        
                        # convert NL
-                       $text =~ s/\r?\n/<br\/>\n/gs;
-                       # $text =~ s/\r?\n/<br>\n/gs;
+                       if ($cmd_options->{'post-style'} eq 'phpbb') {
+                               $text =~ s/\r?\n/<br\/>\n/gs;
+                       }
+                       else {
+                               $text =~ s/\r?\n/<br>\n/gs;
+                       }
                        
                        $add_html .= $text;
                }
index e1489aa2c5817d4d75b154cff4fe915a1de062d0..e17671196331520da49df42aa3ef4c1b181a9f0b 100644 (file)
@@ -23,12 +23,15 @@ use Encode ('encode', 'decode');
 
 ###PERL_LIB: use lib '/botm/lib/post';
 use botm_common (
-       'read_data_file', 'write_data_file'
+       'read_data_file', 'write_data_file',
+       'html_entity_encode_dec'
 );
 use post_common (
        'prepare_post',
        'CODE',
-       'bbcode_to_html'
+       'bbcode_to_html',
+       'HTML_PAGE_START', 'HTML_PAGE_END', 'HTML_POST_START', 'HTML_POST_END',
+       'HTML_STYLE'
 );
 
 ###PERL_VERSION: use constant VERSION => 'x.x.x';
@@ -59,6 +62,14 @@ use constant HELP_TEXT =>
        "\n".
        "  -o,  --output-file=OUTPUT_FILE\n".
        "\n".
+       "       --content-only\n".
+       "       --smiley-url=SMILEY_URL\n".
+       "       --css-url=CSS_URL\n".
+       "       --inline-css\n".
+       "       --post-style=\n".
+       "                    phpbb\n".
+       "                    botm\n".
+       "\n".
        "  -q,  --quiet\n".
        "  -v,  --verbose\n".
        # "       --keep-tempfile\n".
@@ -95,7 +106,13 @@ GetOptions (
        'notify|N'       => \$options{   'notify'},
        'no-notify|n'    => \$options{'no-notify'},
        
-       'output-file|o=s' => \$options{'output-file'},
+       'output-file|o=s'=> \$options{'output-file'},
+       
+       'content-only'   => \$options{'content-only'},
+       'smiley-url=s'   => \$options{'smiley-url'},
+       'css-url=s'      => \$options{'css-url'},
+       'inline-css'     => \$options{'inline-css'},
+       'post-style=s'   => \$options{'post-style'},
        
        'quiet|q'        => \$options{'quiet'},
        'verbose|v'      => \$options{'verbose'},
@@ -127,6 +144,10 @@ if ($options{'quiet'} ne '') {
 if (($options{'output-file'} eq '') and ($options{'verbose'} eq '')) {
        $options{'quiet'} = '1';
 }
+if ($options{'post-style'} !~ /^((botm)|(bsta)|(phpbb))$/) {
+       # $options{'post-style'} = 'phpbb';
+       $options{'post-style'} = 'botm';
+}
 
 unless ($options{'quiet'} ne '') {
        print "PREVIEW $$ $time - $timetext\n\n";
@@ -142,6 +163,11 @@ if ((scalar @ARGV) == 0) {
 }
 
 my $fh;
+my $code;
+my %data;
+my %post;
+my $html;
+
 if ($options{'output-file'} ne '') {
        unless (open ($fh, '>:encoding(UTF-8)', encode('locale_fs', $options{'output-file'}))) {
                unless ($options{'quiet'} ne '') {
@@ -153,12 +179,16 @@ if ($options{'output-file'} ne '') {
 }
 else {
        $fh = \*STDOUT;
+       binmode STDOUT, ':encoding(UTF-8)';
+}
+
+$code = CODE->{'OK'};
+
+unless ($options{'content-only'} ne '') { 
+       print_preview($fh, HTML_PAGE_START(), \%post, \%options);
 }
 
-my $code = CODE->{'OK'};
 foreach my $arg (@ARGV) {
-       my $r;
-       
        unless ($options{'quiet'} ne '') {
                if ($arg == \*STDIN) {
                        print "STDIN\n";
@@ -168,7 +198,7 @@ foreach my $arg (@ARGV) {
                }
        }
        
-       my %data  = ();
+       %data  = ();
        unless (($arg == \*STDIN) and ($options{'content'} ne '') and ($options{'data-only'} ne ''))
        {
                %data = read_data_file($arg, ENCODING_FILE, $options{'data-only'});
@@ -192,7 +222,7 @@ foreach my $arg (@ARGV) {
                print "\n";
        }
        
-       my %post = prepare_post(\%options, \%data);
+       %post = prepare_post(\%options, \%data);
        if ($options{'verbose'} ne '') {
                print "POST\n";
                write_data_file(\*STDOUT, 'console_out', 0, \%post);
@@ -200,7 +230,7 @@ foreach my $arg (@ARGV) {
        }
        
        # now generate preview
-       my $html = bbcode_to_html(\%options, \%post);
+       $html = bbcode_to_html(\%options, \%post);
        
        if ($options{'verbose'} ne '') {
                print "HTML\n";
@@ -208,9 +238,53 @@ foreach my $arg (@ARGV) {
                print "\n";
        }
        
+       unless ($options{'content-only'} ne '') { 
+               print_preview($fh, HTML_POST_START(), \%post, \%options);
+       }
+       
        print $fh $html."\n";
+       
+       unless ($options{'content-only'} ne '') { 
+               print_preview($fh, HTML_POST_END(), \%post, \%options);
+       }
+}
+unless ($options{'content-only'} ne '') {
+       print_preview($fh, HTML_PAGE_END(), \%post, \%options);
 }
-
 close ($fh);
 
 exit $code;
+
+
+sub print_preview {
+       (my $fh, my $data, my $post, my $options) = @_;
+       
+       my @data_list = @{$data->{$options->{'post-style'}}};
+       
+       foreach my $data_line (@data_list) {
+               
+               if ($data_line =~ m/&_css_url;/gs) {
+                       if ($options->{'css-url'} ne '') {
+                               print $fh $`. $options->{'css-url'} . $' . "\n";
+                       }
+                       next;
+               }
+               
+               if ($data_line =~ m/&_inline_css;/gs) {
+                       if ($options->{'inline-css'} ne '') {
+                               print $fh $`;
+                               print_preview($fh, HTML_STYLE(), $post, $options);
+                               print $fh $' . "\n";
+                       }
+                       next;
+               }
+               
+               $data_line =~ s/&_title;/preview/gs;
+               $data_line =~ s/&_subject;/html_entity_encode_dec($post->{'subject'},1)/gse;
+               $data_line =~ s/&_username;/html_entity_encode_dec($post->{'username'},1)/gse;
+               $data_line =~ s/&_time;/\$time/gs;  # TODO
+               $data_line =~ s/&_post_class;/html_entity_encode_dec($post->{'class'},1)/gse;
+               
+               print $fh $data_line."\n";
+       }
+}
\ No newline at end of file