X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FInclude.pm;h=e619a228d7506402b232975eebf5ac6155d7f58c;hb=07aec9f5f20e4a605d65bbe2337a05663c0b16e7;hp=e35567a6d3ce5c9b970b00e228b2c99545dc0fc6;hpb=49c23244b1ba61909b726bb9189665a33027a1af;p=ndwebbie.git diff --git a/lib/NDWeb/Include.pm b/lib/NDWeb/Include.pm index e35567a..e619a22 100644 --- a/lib/NDWeb/Include.pm +++ b/lib/NDWeb/Include.pm @@ -21,68 +21,72 @@ package NDWeb::Include; use strict; use warnings; require Exporter; -use BBCode::Parser; +use Parse::BBCode; +use CGI qw/:standard/; our @ISA = qw/Exporter/; -our @EXPORT = qw/parseMarkup min max - alliances intelquery /; +our @EXPORT = qw/parseMarkup + html_escape + comma_value array_expand/; -sub parseMarkup ($) { - my ($text) = @_; - - #$text =~ s{\n}{\n
}g; - #$text =~ s{\[B\](.*?)\[/B\]}{$1}gi; - #$text =~ s{\[I\](.*?)\[/I\]}{$1}gi; - #$text =~ s{\[url\](.*?)\[/url\]}{$1}gi; - #$text =~ s{\[PRE\](.*?)\[/PRE\]}{
$1
}sgi; - #$text =~ s{\[PRE\](.*?)\[/PRE\]}{
$1
}sgi; - #$1 =~ s{
}{}g; +sub html_escape($) { + return CGI::escapeHTML @_; +} - eval{ - my $tree = BBCode::Parser->DEFAULT->parse($text); - $text = $tree->toHTML; - }; - $text =~ s/\x{3}\d\d?//g; #mirc color TODO: possibly match until \x{0F} and change to [color] block - $text =~ s/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//g; - return $text; +sub comma_value ($) { + my ($v) = @_; + $v =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g; + return $v; } -sub min { - my ($x,$y) = @_; - return ($x > $y ? $y : $x); -} +my $bbc = Parse::BBCode->new({ + tags => { + Parse::BBCode::HTML->defaults, + '' => sub { + my $e = ($_[2]); + $e =~ s/\r?\n|\r/
\n/g; + $e + }, + url => 'url:%s', + quote => 'block:
+
%{html}a wrote:
+
%s
', + code => 'block:
%{html}s
', + img => 'url:%s', + li => 'block:
  • %{parse}s
  • ', + size => '%s', -sub max { - my ($x,$y) = @_; - return ($x < $y ? $y : $x); -} + }, + close_open_tags => 1, + }); +sub parseMarkup ($) { + my ($text) = @_; -sub alliances { - my ($alliance) = @_; - my @alliances; - $alliance = -1 unless defined $alliance; - push @alliances,{Id => -1, Name => '', Selected => not $alliance}; - my $query = $ND::DBH->prepare(q{SELECT id,name FROM alliances ORDER BY LOWER(name)}); - $query->execute; - while (my $ally = $query->fetchrow_hashref){ - push @alliances,{Id => $ally->{id}, Name => $ally->{name}, Selected => $alliance == $ally->{id}}; + $text = $bbc->render($text); + if ($bbc->error){ + my $tree = $bbc->get_tree; + $text = $tree->raw_text; + $text = $bbc->render($text); } - return @alliances; + $text =~ s/\x{3}\d\d?//g; #mirc color TODO: possibly match until \x{0F} and change to [color] block + $text =~ s/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//g; + return $text; } -sub intelquery { - my ($columns,$where) = @_; - return qq{ -SELECT $columns, i.mission, i.tick AS landingtick,MIN(i.eta) AS eta, i.amount, i.ingal, u.username -FROM (fleets i NATURAL JOIN users u) - JOIN current_planet_stats t ON i.target = t.id - JOIN current_planet_stats o ON i.sender = o.id -WHERE $where -GROUP BY i.tick,i.mission,t.x,t.y,t.z,o.x,o.y,o.z,i.amount,i.ingal,u.username,t.alliance,o.alliance,t.nick,o.nick -ORDER BY i.tick DESC, i.mission}; +sub array_expand ($) { + my ($array) = @_; + + my @arrays; + for my $string (@{$array}){ + $string =~ s/^\((.*)\)$/$1/; + $string =~ s/"//g; + my @array = split /,/, $string; + push @arrays,\@array; + } + return \@arrays; }