'prepare_post',
'wget',
'CODE',
+ 'bbcode_to_html'
);
###PERL_LIB: use lib '/botm/lib/post';
# BBCODE #
##########
+use constant BBCODE_SMILEY_FILE => {
+ ':D' => 'icon_biggrin.gif',
+ ':)' => 'icon_smile.gif',
+ ':(' => 'icon_sad.gif',
+ ':o' => 'icon_surprised.gif',
+ ':shock:' => 'icon_eek.gif',
+ ':?' => 'icon_confused.gif',
+ '8-)' => 'icon_cool.gif',
+ ':lol' => 'icon_lol.gif',
+ ':x' => 'icon_mad.gif',
+ ':P' => 'icon_razz.gif',
+ ':oops:' => 'icon_redface.gif',
+ ':cry:' => 'icon_cry.gif',
+ ':evil:' => 'icon_evil.gif',
+ ':twisted:'=> 'icon_twisted.gif',
+ ':roll:' => 'icon_rolleyes.gif',
+ ':wink:' => 'icon_wink.gif',
+ ';)' => 'icon_wink.gif',
+ ':!:' => 'icon_exclaim.gif',
+ ':?:' => 'icon_question.gif',
+ ':idea:' => 'icon_idea.gif',
+ ':arrow:' => 'icon_arrow.gif',
+ ':|' => 'icon_neutral.gif',
+ ':mrgreen:'=> 'icon_mrgreen.gif'
+};
+
+use constant BBCODE_SMILEY_TITLE => {
+ ':D' => 'Very Happy',
+ ':)' => 'Smile',
+ ':(' => 'Sad',
+ ':o' => 'Surprised',
+ ':shock:' => 'Shocked',
+ ':?' => 'Confused',
+ '8-)' => 'Cool',
+ ':lol' => 'Laughing',
+ ':x' => 'Mad',
+ ':P' => 'Razz',
+ ':oops:' => 'Embarassed',
+ ':cry:' => 'Crying or Very Sad',
+ ':evil:' => 'Evil or Very Mad',
+ ':twisted:'=> 'Twisted Evil',
+ ':roll:' => 'Rolling Eyes',
+ ':wink:' => 'Wink',
+ ';)' => 'Wink',
+ ':!:' => 'Exclamation',
+ ':?:' => 'Question',
+ ':idea:' => 'Idea',
+ ':arrow:' => 'Arrow',
+ ':|' => 'Neutral',
+ ':mrgreen:'=> 'Mr. Green'
+};
+
# bbtree is the representation of a BBcode tag tree as a Perl hash
# each element can be a tag or text.
# text only has value
$bbtree->{$new_ind.'.endtext'} = '';
if ($print) {
- print bbtree_debug(%bbtree, $new_ind);
+ print bbtree_debug($bbtree, $new_ind);
}
# enter NEW tag
}
if ($print){
- print bbtree_debug(%bbtree, $ind);
+ print bbtree_debug($bbtree, $ind);
}
return ($level, $ind);
}
$bbtree->{$ind.'closed'} = 1;
if ($print){
- print bbtree_debug(%bbtree, $ind);
+ print bbtree_debug($bbtree, $ind);
}
# return to PARENT tag
$bbtree->{$ind.'closed'} = 0;
if ($print){
- print bbtree_debug(%bbtree, $ind);
+ print bbtree_debug($bbtree, $ind);
}
# return to PARENT tag
# element is text, just print
elsif ($bbtree->{$ind.'.type'} eq 'text') {
- $debug .= 'text: '.$bbtree->{$ind.'.value'};
+ $debug .= 'text: '.$bbtree->{$ind.'.text'};
}
# unknown type, no idea what to print
my $in_code = 0; # if (and how deep) in [code] tag
my $in_spoiler = 0; # if (and how deep) in [spoiler] tag
my $in_size = 0; # if (and how deep) in [size] tag
- my $print = $cmd_options->{'verbose'} ne '' # allowed to print
+ my $print = ($cmd_options->{'verbose'} ne ''); # allowed to print
# initialise BB tree with top level
if ($print) {
print "Build BBcode tree:\n";
}
- ($ind, $level) = bbtree_init(\%bbtree, $print);
+ ($level, $ind) = bbtree_init(\%bbtree, $print);
while ($bbcode ne '') {
next;
}
- # opening tag\r if ($tag_end eq '') {
+ # opening tag
+ if ($tag_end eq '') {
# additional reasons for rejecting tag
if (
print "implicit [/*]\n";
}
# add [/*] to BB tree
- ($level, $ind) = bbtree_close_tag(\%bbtree, $level, $ind, '[/*]' $print);
+ ($level, $ind) = bbtree_close_tag(\%bbtree, $level, $ind, '[/*]', $print);
}
# handle special case tags
else {
$tag_value = 'QUOTE MARKS MISSING; '.html_entity_encode_dec($tag_value)
}
- $html .= '<blockquote><div><cite>'.tagvalue.' wrote:</cite>';
+ $html .= '<blockquote><div><cite>'.html_entity_encode_dec($tag_value).' wrote:</cite>';
# $html .= '<blockquote class="pq"><div><cite class="pq"><b class="br">'.tagvalue.'</b> wrote:</cite><br>';
}
}
}
elsif ($tag_name eq 'spoiler') {
- $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;">';
+ $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;">';
# $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 '') {
$html .= 'INVALID VALUE; ';
$html .= 'INVALID VALUE; ';
$tag_value = 'decimal';
}
- $html .= '<ol style="list-style-type: '.tag_value.'">';
+ $html .= '<ol style="list-style-type: '.$tag_value.'">';
}
}
# text
else {
- # TODO
+ $text = $bbtree{$ind.'.'.$sub_ind.'.text'};
+
+ # This here is kind of a hack.
+ # normally I should first detect URLs and smilies
+ # and convert them to HTML tags.
+ # And then do escapng of special characters in the parts
+ # of the text which were not converted.
+ # Instead I do it in reverse order.
+ # First I do the escaping and afterwards I'm detecting.
+ # This will not be messed up because the only escaped characters
+ # are "&<=> and none of these can be foung in existing smilies
+ # 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);
+
+ # preserve indentation in [code]
+ if ($in_code > 0) {
+ $text =~ s/ / /gs;
+ $text =~ s/\t/ /gs;
+ }
+
+ # convert URLs
+ if (($post->{'urls'}) and ($tag_name !~ /^((code)|(img)|(url))$/)) {
+ $text =~ s/https?:\/\/[^\n\r\t<> ]+/<a href="$&" class="postlink">$&<\/a>/gs;
+ }
+
+ # 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}.'" \/> '/ge;
+ # $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}.'"> '/ge;
+ }
+
+ # convert NL
+ $text =~ s/\r?\n/<br\/>\n/gs;
+ # $text =~ s/\r?\n/<br>\n/gs;
+
+ $html .= $text;
}
- ($level, $ind, $sub_ind) = bbtree_next(\%bbtree, $level, $ind, $sub_ind);
+ ($level, $ind, $sub_ind) = bbtree_next(\%bbtree, $level, $ind, $sub_ind, $print);
}
+ if ($print) {
+ print "\n";
+ }
+
+ return $html;
}
+
+
########
# WGET #
########