]> ruin.nu Git - ndwebbie.git/blob - lib/NDWeb/Include.pm
Converted editRaid page
[ndwebbie.git] / lib / NDWeb / Include.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package NDWeb::Include;
21 use strict;
22 use warnings;
23 require Exporter;
24 use BBCode::Parser;
25 use CGI qw/:standard/;
26
27 our @ISA = qw/Exporter/;
28
29 our @EXPORT = qw/parseMarkup min max
30         intelquery html_escape
31         comma_value array_expand/;
32
33 sub html_escape($) {
34         return CGI::escapeHTML @_;
35 }
36
37 sub comma_value ($) {
38         my ($v) = @_;
39         $v =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
40         return $v;
41 }
42
43 sub parseMarkup ($) {
44         my ($text) = @_;
45
46         #$text =~ s{\n}{\n<br/>}g;
47         #$text =~ s{\[B\](.*?)\[/B\]}{<b>$1</b>}gi;
48         #$text =~ s{\[I\](.*?)\[/I\]}{<i>$1</i>}gi;
49         #$text =~ s{\[url\](.*?)\[/url\]}{<a href="$1">$1</a>}gi;
50         #$text =~ s{\[PRE\](.*?)\[/PRE\]}{<pre>$1</pre>}sgi;
51         #$text =~ s{\[PRE\](.*?)\[/PRE\]}{<pre>$1</pre>}sgi;
52         #$1 =~ s{<br/>}{}g;
53
54         eval{
55                 my $tree = BBCode::Parser->DEFAULT->parse($text);
56                 $text = $tree->toHTML;
57         };
58         $text =~ s/\x{3}\d\d?//g; #mirc color TODO: possibly match until \x{0F} and change to [color] block
59         $text =~ s/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//g;
60         return $text;
61 }
62
63
64 sub min {
65     my ($x,$y) = @_;
66     return ($x > $y ? $y : $x);
67 }
68
69 sub max {
70     my ($x,$y) = @_;
71     return ($x < $y ? $y : $x);
72 }
73
74 sub intelquery {
75         my ($columns,$where) = @_;
76         return qq{
77 SELECT $columns, i.mission, i.tick AS landingtick,MIN(i.eta) AS eta, i.amount, i.ingal, u.username
78 FROM (fleets i NATURAL JOIN users u)
79         JOIN current_planet_stats t ON i.target = t.id
80         JOIN current_planet_stats o ON i.sender = o.id
81 WHERE $where 
82 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
83 ORDER BY i.tick DESC, i.mission};
84 }
85
86 sub array_expand ($) {
87         my ($array) = @_;
88
89         my @arrays;
90         for my $string (@{$array}){
91                 $string =~ s/^\((.*)\)$/$1/;
92                 $string =~ s/"//g;
93                 my @array = split /,/, $string;
94                 push @arrays,\@array;
95         }
96         return \@arrays;
97 }
98
99
100
101 1;