]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Include.pm
Added model and renamed submodule
[ndwebbie.git] / 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 use CGI qw{:standard};
24 require Exporter;
25 use BBCode::Parser;
26
27 our @ISA = qw/Exporter/;
28
29 our @EXPORT = qw/parseMarkup min max
30         alliances intelquery /;
31
32 sub parseMarkup ($) {
33         my ($text) = @_;
34
35         #$text =~ s{\n}{\n<br/>}g;
36         #$text =~ s{\[B\](.*?)\[/B\]}{<b>$1</b>}gi;
37         #$text =~ s{\[I\](.*?)\[/I\]}{<i>$1</i>}gi;
38         #$text =~ s{\[url\](.*?)\[/url\]}{<a href="$1">$1</a>}gi;
39         #$text =~ s{\[PRE\](.*?)\[/PRE\]}{<pre>$1</pre>}sgi;
40         #$text =~ s{\[PRE\](.*?)\[/PRE\]}{<pre>$1</pre>}sgi;
41         #$1 =~ s{<br/>}{}g;
42
43         eval{
44                 my $tree = BBCode::Parser->DEFAULT->parse($text);
45                 $text = $tree->toHTML;
46         };
47         $text =~ s/\x{3}\d\d?//g; #mirc color TODO: possibly match until \x{0F} and change to [color] block
48         $text =~ s/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//g;
49         return $text;
50 }
51
52
53 sub min {
54     my ($x,$y) = @_;
55     return ($x > $y ? $y : $x);
56 }
57
58 sub max {
59     my ($x,$y) = @_;
60     return ($x < $y ? $y : $x);
61 }
62
63
64 sub alliances {
65         my ($alliance) = @_;
66         my @alliances;
67         $alliance = -1 unless defined $alliance;
68         push @alliances,{Id => -1, Name => '', Selected => not $alliance};
69         my $query = $ND::DBH->prepare(q{SELECT id,name FROM alliances ORDER BY LOWER(name)});
70         $query->execute;        
71         while (my $ally = $query->fetchrow_hashref){
72                 push @alliances,{Id => $ally->{id}, Name => $ally->{name}, Selected => $alliance == $ally->{id}};
73         }
74         return @alliances;
75 }
76
77 sub intelquery {
78         my ($columns,$where) = @_;
79         return qq{
80 SELECT $columns, i.mission, i.tick AS landingtick,MIN(i.eta) AS eta, i.amount, i.ingal, u.username
81 FROM (fleets i NATURAL JOIN users u)
82         JOIN current_planet_stats t ON i.target = t.id
83         JOIN current_planet_stats o ON i.sender = o.id
84 WHERE $where 
85 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
86 ORDER BY i.tick DESC, i.mission};
87 }
88
89
90
91 1;