###PERL_LIB: use lib '/botm/lib/post';
use botm_common (
'system_encoded',
+ 'write_data_file',
'write_postdata_file',
'html_entity_encode_dec'
);
':shock:' => 'icon_eek.gif',
':?' => 'icon_confused.gif',
'8-)' => 'icon_cool.gif',
- ':lol' => 'icon_lol.gif',
+ ':lol:' => 'icon_lol.gif',
':x' => 'icon_mad.gif',
':P' => 'icon_razz.gif',
':oops:' => 'icon_redface.gif',
':shock:' => 'Shocked',
':?' => 'Confused',
'8-)' => 'Cool',
- ':lol' => 'Laughing',
+ ':lol:' => 'Laughing',
':x' => 'Mad',
':P' => 'Razz',
':oops:' => 'Embarassed',
if ($count >= 0) {
my $ind_last = $ind.'.'.($count-1);
if ($bbtree->{$ind_last.'.type'} eq 'text') {
- $bbtree->{$ind_last.'.text'} += $text;
+ $bbtree->{$ind_last.'.text'} .= $text;
$text = '';
}
}
sub bbtree_close_tag {
(my $bbtree, my $level, my $ind, my $text, my $print) = @_;
- $bbtree->{$ind.'endtext'} = $text;
+ $bbtree->{$ind.'.endtext'} = $text;
# mark CURRENT tag as closed
- $bbtree->{$ind.'closed'} = 1;
+ $bbtree->{$ind.'.closed'} = 1;
if ($print){
print bbtree_debug($bbtree, $ind);
sub bbtree_drop_tag {
(my $bbtree, my $level, my $ind, my $text, my $print) = @_;
- $bbtree->{$ind.'endtext'} = $text;
+ $bbtree->{$ind.'.endtext'} = $text;
# mark CURRENT tag as NOT closed
- $bbtree->{$ind.'closed'} = 0;
+ $bbtree->{$ind.'.closed'} = 0;
if ($print){
print bbtree_debug($bbtree, $ind);
my $level = 0;
if ($print) {
+ # print 'GOTO ['.$ind."]\n";
print bbtree_info($bbtree, $ind);
}
return ($level, $ind, $sub_ind);
}
my $full_ind = $ind.'.'.$sub_ind;
- if ($print) {
- print '['.$full_ind."]\n";
- }
+ # if ($print) {
+ # print 'GOTO ['.$full_ind."]\n";
+ # }
+
# next element is a tag; enter it
- if ($bbtree->{'.type'} eq 'tag') {
+ if ($bbtree->{$full_ind.'.type'} eq 'tag') {
$ind = $full_ind;
$sub_ind = '';
+ $level += 1;
}
if ($print) {
return ($level, $ind, $sub_ind);
}
+sub bbtree_finish {
+ (my $bbtree, my $print) = @_;
+ my $level;
+ my $ind;
+ my $sub_ind;
+
+ ($level, $ind, $sub_ind) = bbtree_start($bbtree, 0);
+ ($level, $ind) = bbtree_close_tag($bbtree, $level, $ind, '', $print);
+}
+
# full info about bbtree element
sub bbtree_info {
(my $bbtree, my $ind) = @_;
next;
}
+ # additional reasons for rejecting tag
+ if (
+ # no [/*] not in [list] or [*]
+ (($tag_name eq '*') and ($bbtree{$ind.'.name'} !~ /^((list)|\*)$/)) or
+ # no tags in [img]
+ (($tag_name ne 'img') and ($bbtree{$ind.'.name'} eq 'img'))
+ ) {
+ if ($print) {
+ print "this tag forbidden here\n";
+ }
+ bbtree_add_text(\%bbtree, $level, $ind, $tag, $print);
+ # skip
+ next;
+ }
+
# unclosed [*] before [/list]
# add implicit [/*]
if (($tag_name eq 'list' ) and ($bbtree{$ind.'.name'} eq '*')) {
}
# add bad tag to BB tree as text and close current tag
($level, $ind) = bbtree_drop_tag(\%bbtree, $level, $ind, $tag, $print);
+ #skip
+ next;
}
# close current tag
($level, $ind) = bbtree_close_tag(\%bbtree, $level, $ind, $tag, $print);
}
}
+ bbtree_finish(\%bbtree, $print);
$in_code = 0;
if ($print) {
+ print "BBTREE:\n";
+ write_data_file(\*STDOUT, 'console_out', 0, \%bbtree);
print "\nGenerate HTML from BBcode tree:\n";
}
($level, $ind, $sub_ind) = bbtree_start(\%bbtree, $print);
while ($level >= 0) {
+ # if ($print) {
+ # print "[$level][$ind][$sub_ind]\n";
+ # }
+
$tag = $bbtree{$ind.'.text'};
$tag_end = $bbtree{$ind.'.endtext'};
$tag_name = $bbtree{$ind.'.name'};
$tag_value = $bbtree{$ind.'.value'};
$tag_count = $bbtree{$ind.'.count'};
$tag_closed = $bbtree{$ind.'.closed'};
+ my $add_html = '';
# tag start
if ($sub_ind eq '') {
if ($print) {
print "unmatched tag\n";
}
- $html .= html_entity_encode_dec($tag);
+ $add_html .= html_entity_encode_dec($tag);
+ }
+
+ elsif ($tag_name eq '_') {
+ # post start here
}
elsif ($tag_name eq 'quote') {
if ($tag_value eq '') {
- $html .= '<blockquote class="uncited"><div>';
- #$html .= '<blockquote class="pq"><div>';
+ $add_html .= '<blockquote class="uncited"><div>';
+ #$add_html .= '<blockquote class="pq"><div>';
}
else {
if ($tag_value =~ m/^"(.*)"$/gs) {
else {
$tag_value = 'QUOTE MARKS MISSING; '.html_entity_encode_dec($tag_value)
}
- $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>';
+ $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>';
}
}
elsif ($tag_name eq 'b') {
- $html .= '<span style="font-weight: bold">';
+ $add_html .= '<span style="font-weight: bold">';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 'i') {
- $html .= '<span style="font-style: italic">';
+ $add_html .= '<span style="font-style: italic">';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 'u') {
- $html .= '<span style="text-decoration: underline">';
+ $add_html .= '<span style="text-decoration: underline">';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
if ($print) {
print "not a tag, actually\n";
}
- $html .= html_entity_encode_dec($tag);
+ $add_html .= html_entity_encode_dec($tag);
}
else {
- $html .= '<dl class="codebox"><dt>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code>';
- # $html .= '<dl class="pq"><dt class="pq">Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code class="pq">';
+ $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 ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
$in_code += 1;
}
elsif ($tag_name eq 'img') {
- if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
- }
- $html .= '<img src="';
+ $add_html .= '<img src="';
}
elsif ($tag_name eq 'url') {
print 'Implied value: '.$tag_value."\n";
}
}
- $html .= '<a href="'.html_entity_encode_dec($tag_value).'" class="postlink">';
+ $add_html .= '<a href="'.html_entity_encode_dec($tag_value).'" class="postlink">';
}
elsif ($tag_name eq 'size') {
if (($tag_value =~ m/^([0-9]+)$/gs) and (int($tag_value) <= 200)) {
- $html .= '<span style="font-size: '.$1.'%; line-height: 116%;">';
+ $add_html .= '<span style="font-size: '.$1.'%; line-height: 116%;">';
}
else {
- $html .= '<span style="font-size: 130%; line-height: 116%;"> INVALID VALUE; ';
+ $add_html .= '<span style="font-size: 130%; line-height: 116%;"> INVALID VALUE; ';
}
}
elsif ($tag_name eq 'color') {
if ($tag_value =~ m/^(#[0-9A-F]{6})$/gs) {
- $html .= '<span style="color: '.$1.'">';
+ $add_html .= '<span style="color: '.$1.'">';
}
else {
- $html .= '<span style="color: #EE0000"> INVALID VALUE; ';
+ $add_html .= '<span style="color: #EE0000"> INVALID VALUE; ';
}
}
elsif ($tag_name eq 'center') {
- $html .= '<div align="center">';
+ $add_html .= '<div align="center">';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 'right') {
- $html .= '<div align="right">';
+ $add_html .= '<div align="right">';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 's') {
- $html .= '<strike>';
+ $add_html .= '<strike>';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 'sub') {
- $html .= '<sub>';
+ $add_html .= '<sub>';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 'sup') {
- $html .= '<sup>';
+ $add_html .= '<sup>';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
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" 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;">';
+ $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 ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
elsif ($tag_name eq 'list') {
if ($tag_value eq '') {
- $html .= '<ul>';
+ $add_html .= '<ul>';
}
else {
if ($tag_value eq '1') {
$tag_value = 'upper-alpha';
}
else {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
$tag_value = 'decimal';
}
- $html .= '<ol style="list-style-type: '.$tag_value.'">';
+ $add_html .= '<ol style="list-style-type: '.$tag_value.'">';
}
}
elsif ($tag_name eq '*') {
- $html .= '<li>';
+ $add_html .= '<li>';
if ($tag_value ne '') {
- $html .= 'INVALID VALUE; ';
+ $add_html .= 'INVALID VALUE; ';
}
}
if ($print) {
print "unknown tag\n"
}
- $html .= html_entity_encode_dec($tag);
+ $add_html .= html_entity_encode_dec($tag);
}
}
if ($print) {
print "unmatched tag\n";
}
- $html .= html_entity_encode_dec($tag_end);
+ $add_html .= html_entity_encode_dec($tag_end);
+ }
+
+ elsif ($tag_name eq '_') {
+ # post end here
}
elsif ($tag_name eq 'quote') {
- $html .= '</div></blockquote>';
+ $add_html .= '</div></blockquote>';
}
elsif ($tag_name =~ m/^(b|i|u|(size)|(color))$/gs) {
- $html .= '</span>';
+ $add_html .= '</span>';
}
elsif ($tag_name eq 'code') {
if ($print) {
print "not a tag, actually\n";
}
- $html .= html_entity_encode_dec($tag_end);
+ $add_html .= html_entity_encode_dec($tag_end);
}
else {
- $html .= '</code></dd></dl>';
+ $add_html .= '</code></dd></dl>';
}
}
+ elsif ($tag_name eq 'img') {
+ $add_html .= '" alt="Image" />';
+ # $add_html .= '" alt="Image">';
+ if ($tag_value ne '') {
+ $add_html .= 'INVALID VALUE; ';
+ }
+
+ }
+
elsif ($tag_name eq 'url') {
- $html .= '</a>';
+ $add_html .= '</a>';
}
elsif ($tag_name =~ /^((center)|(right))$/) {
- $html .= '</div>';
+ $add_html .= '</div>';
}
elsif ($tag_name eq 's') {
- $html .= '</strike>';
+ $add_html .= '</strike>';
}
elsif ($tag_name eq 'sub') {
- $html .= '</sub>';
+ $add_html .= '</sub>';
}
elsif ($tag_name eq 'sup') {
- $html .= '</sup>';
+ $add_html .= '</sup>';
}
elsif ($tag_name eq 'spoiler') {
- $html .= '</div></div></div>';
+ $add_html .= '</div></div></div>';
}
elsif ($tag_name eq 'list') {
if ($tag_value eq '') {
- $html .= '</ul>';
+ $add_html .= '</ul>';
}
else {
- $html .= '</ol>';
+ $add_html .= '</ol>';
}
}
elsif ($tag_name eq '*') {
- $html .= '</li>';
+ $add_html .= '</li>';
}
else {
if ($print) {
print "unknown tag\n";
}
- $html .= html_entity_encode_dec($tag_end);
+ $add_html .= html_entity_encode_dec($tag_end);
}
}
# 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;
+ $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;
}
# convert NL
$text =~ s/\r?\n/<br\/>\n/gs;
# $text =~ s/\r?\n/<br>\n/gs;
- $html .= $text;
+ $add_html .= $text;
+ }
+
+ if ($print) {
+ print "HTML=$add_html\n";
}
+ $html .= $add_html;
($level, $ind, $sub_ind) = bbtree_next(\%bbtree, $level, $ind, $sub_ind, $print);
}