'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';
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; • &_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 #
##########
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 '_') {
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>';
}
}
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; ';
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') {
}
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; ';
}
if ($print) {
print "unknown tag\n"
}
- $add_html .= html_entity_encode_dec($tag);
+ $add_html .= html_entity_encode_dec($tag, 1);
}
}
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 '_') {
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>';
}
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; ';
}
if ($print) {
print "unknown tag\n";
}
- $add_html .= html_entity_encode_dec($tag_end);
+ $add_html .= html_entity_encode_dec($tag_end, 1);
}
}
# 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) {
# 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;
}
###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';
"\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".
'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'},
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";
}
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 '') {
}
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";
}
}
- 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'});
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);
}
# now generate preview
- my $html = bbcode_to_html(\%options, \%post);
+ $html = bbcode_to_html(\%options, \%post);
if ($options{'verbose'} ne '') {
print "HTML\n";
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