summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Prelude.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNWeb/Prelude.pm')
-rw-r--r--lib/VNWeb/Prelude.pm78
1 files changed, 24 insertions, 54 deletions
diff --git a/lib/VNWeb/Prelude.pm b/lib/VNWeb/Prelude.pm
index c79cc09b..f422aa50 100644
--- a/lib/VNWeb/Prelude.pm
+++ b/lib/VNWeb/Prelude.pm
@@ -8,21 +8,23 @@
# use Exporter 'import';
# use Time::HiRes 'time';
# use List::Util 'min', 'max', 'sum';
-# use POSIX 'ceil', 'floor';
+# use POSIX 'ceil', 'floor', 'strftime';
#
-# use VNDBUtil;
# use VNDB::BBCode;
# use VNDB::Types;
# use VNDB::Config;
-# use VNDB::Func qw/fmtdate fmtage fmtvote fmtspoil fmtmedia minage resolution query_encode lang_attr md2html/;
+# use VNDB::Func;
# use VNDB::ExtLinks;
# use VNWeb::Auth;
# use VNWeb::HTML;
# use VNWeb::DB;
# use VNWeb::Validation;
+# use VNWeb::JS;
# use VNWeb::Elm;
+# use VNWeb::TableOpts;
+# use VNWeb::TitlePrefs;
#
-# + A few other handy tools.
+# + A handy dbobj() function.
#
# WARNING: This should not be used from the above modules.
package VNWeb::Prelude;
@@ -33,8 +35,8 @@ use feature ':5.26';
use utf8;
use VNWeb::Elm;
use VNWeb::Auth;
+use VNWeb::DB;
use TUWF;
-use JSON::XS;
sub import {
@@ -52,74 +54,42 @@ sub import {
use Exporter 'import';
use Time::HiRes 'time';
use List::Util 'min', 'max', 'sum';
- use POSIX 'ceil', 'floor';
+ use POSIX 'ceil', 'floor', 'strftime';
- use VNDBUtil;
use VNDB::BBCode;
use VNDB::Types;
use VNDB::Config;
- use VNDB::Func qw/fmtdate fmtage fmtvote fmtspoil fmtmedia minage resolution query_encode lang_attr md2html/;
+ use VNDB::Func;
use VNDB::ExtLinks;
use VNWeb::Auth;
use VNWeb::HTML;
use VNWeb::DB;
use VNWeb::Validation;
+ use VNWeb::JS;
use VNWeb::Elm;
+ use VNWeb::TableOpts;
+ use VNWeb::TitlePrefs;
1;
EOM;
no strict 'refs';
- *{$c.'::RE'} = *RE;
- *{$c.'::in'} = \∈
- *{$c.'::idcmp'} = \&idcmp;
+ *{$c.'::dbobj'} = \&dbobj;
}
-# Regular expressions for use in path registration
-my $num = qr{[1-9][0-9]{0,6}}; # Allow up to 10 mil, SQL vndbid type can't handle more than 2^26-1 (~ 67 mil).
-my $id = qr{(?<id>$num)};
-my $rev = qr{(?:\.(?<rev>$num))};
-our %RE = (
- num => qr{(?<num>$num)},
- uid => qr{u$id},
- vid => qr{v$id},
- rid => qr{r$id},
- sid => qr{s$id},
- cid => qr{c$id},
- pid => qr{p$id},
- iid => qr{i$id},
- did => qr{d$id},
- tid => qr{t$id},
- gid => qr{g$id},
- imgid=> qr{(?<id>(?:ch|cv|sf)$num)},
- vrev => qr{v$id$rev?},
- rrev => qr{r$id$rev?},
- prev => qr{p$id$rev?},
- srev => qr{s$id$rev?},
- crev => qr{c$id$rev?},
- drev => qr{d$id$rev?},
- postid => qr{t$id\.(?<num>$num)},
-);
+# Returns very generic information on a DB entry object.
+# Suitable for passing to HTML::framework_'s dbobj argument.
+sub dbobj {
+ my($id) = @_;
+ return undef if !$id;
+ if($id =~ /^u/) {
+ my $o = tuwf->dbRowi('SELECT id, username IS NULL AS entry_hidden,', sql_user(), 'FROM users u WHERE id =', \$id);
+ $o->{title} = [(undef, VNWeb::HTML::user_displayname $o)x2];
+ return $o;
+ }
-# Simple "is this element in the array?" function, using 'eq' to test equality.
-# Supports both an @array and \@array.
-# Usage:
-#
-# my $contains_hi = in 'hi', qw/ a b hi c /; # true
-#
-sub in {
- my($q, @a) = @_;
- $_ eq $q && return 1 for map ref $_ eq 'ARRAY' ? @$_ : ($_), @a;
- 0
-}
-
-
-# Compare two vndbids, using proper numeric order
-sub idcmp($$) {
- my($a1, $a2) = $_[0] =~ /^([a-z]+)([0-9]+)$/;
- my($b1, $b2) = $_[1] =~ /^([a-z]+)([0-9]+)$/;
- $a1 cmp $b1 || $a2 <=> $b2
+ tuwf->dbRowi('SELECT', \$id, 'AS id, title, hidden AS entry_hidden, locked AS entry_locked FROM', VNWeb::TitlePrefs::item_info(\$id, 'NULL'), ' x');
}
1;