summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/dump.sql3
-rwxr-xr-xutil/skingen.pl93
-rw-r--r--util/updates/update_2.1.sql4
-rwxr-xr-xutil/vndb.pl30
4 files changed, 129 insertions, 1 deletions
diff --git a/util/dump.sql b/util/dump.sql
index 848ddd34..719f0f75 100644
--- a/util/dump.sql
+++ b/util/dump.sql
@@ -184,7 +184,8 @@ CREATE TABLE users (
show_nsfw boolean NOT NULL DEFAULT FALSE,
show_list boolean NOT NULL DEFAULT TRUE,
c_votes integer NOT NULL DEFAULT 0,
- c_changes integer NOT NULL DEFAULT 0
+ c_changes integer NOT NULL DEFAULT 0,
+ skin varchar(128) NOT NULL DEFAULT ''
);
-- vn
diff --git a/util/skingen.pl b/util/skingen.pl
new file mode 100755
index 00000000..9c06b077
--- /dev/null
+++ b/util/skingen.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+package VNDB;
+
+use strict;
+use warnings;
+use Cwd 'abs_path';
+use Data::Dumper 'Dumper';
+use Image::Magick;
+
+
+our($ROOT, %O);
+BEGIN { ($ROOT = abs_path $0) =~ s{/util/skingen\.pl$}{}; }
+require $ROOT.'/data/global.pl';
+
+
+if(@ARGV) {
+ writeskin(readskin($_)) for (@ARGV);
+} else {
+ /([^\/]+)$/ && writeskin(readskin($1)) for (glob($ROOT.'/static/s/*'));
+}
+
+
+sub readskin { # skin name
+ my $name = shift;
+ my %o;
+ open my $F, '<', $ROOT.'/static/s/'.$name.'/conf' or die $!;
+ while(<$F>) {
+ chomp;
+ s{[\t\s]*//.+$}{};
+ next if !/^([a-z0-9]+)[\t\s]+(.+)$/;
+ $o{$1} = $2;
+ }
+ close $F;
+ $o{_name} = $name;
+ return \%o;
+}
+
+
+sub writeskin { # $obj
+ my $o = shift;
+
+ # fix image locations
+ $o->{$_} && ($o->{$_} = '/s/'.$o->{_name}.'/'.$o->{$_}) for (qw|imglefttop imgrighttop|);
+
+ # get the right top image
+ if($o->{imgrighttop}) {
+ my $img = Image::Magick->new;
+ $img->Read($ROOT.'/static'.$o->{imgrighttop});
+ $o->{_bgright} = sprintf 'background: url(%s) no-repeat; width: %dpx; height: %dpx',
+ $o->{imgrighttop}, $img->Get('width'), $img->Get('height');
+ } else {
+ $o->{_bgright} = 'display: none';
+ }
+
+ # body background
+ if(!$o->{imglefttop}) {
+ $o->{_bodybg} = "background-color: $o->{bodybg}";
+ } else {
+ $o->{_bodybg} = "background: $o->{bodybg} url($o->{imglefttop}) no-repeat";
+ }
+
+
+ # create boxbg.png
+ my $img = Image::Magick->new(size => '1x1');
+ $img->Read('xc:'.$o->{boxbg});
+ $img->Write(filename => $ROOT.'/static/s/'.$o->{_name}.'/boxbg.png');
+ $o->{_boxbg} = '/s/'.$o->{_name}.'/boxbg.png';
+
+ # get the blend color
+ $img = Image::Magick->new(size => '1x1');
+ $img->Read('xc:'.$o->{bodybg}, 'xc:'.$o->{boxbg});
+ $img = $img->Flatten();
+ $o->{_blendbg} = '#'.join '', map sprintf('%02x', $_*255), $img->GetPixel(x=>1,y=>1);
+
+ # write the CSS
+ open my $CSS, '<', "$ROOT/data/skingen/style.css" or die $!;
+ open my $SKIN, '>', "$ROOT/static/s/$o->{_name}/style.css" or die $!;
+ while((my $d = <$CSS>)) {
+ if($O{debug}) {
+ chomp $d;
+ $d =~ s/^\s*/ /;
+ $d =~ s{/\*.+\*/}{}; # NOTE: multiline comments or multiple comments per line won't work
+ next if $d !~ /[^\s\t]/;
+ }
+ $d =~ s/\$$_\$/$o->{$_}/g for (keys %$o);
+ print $SKIN $d;
+ }
+ close $SKIN;
+ close $CSS;
+}
+
+
diff --git a/util/updates/update_2.1.sql b/util/updates/update_2.1.sql
new file mode 100644
index 00000000..7ae8fecf
--- /dev/null
+++ b/util/updates/update_2.1.sql
@@ -0,0 +1,4 @@
+
+-- skin selector
+ALTER TABLE users ADD COLUMN skin varchar(128) NOT NULL DEFAULT '';
+
diff --git a/util/vndb.pl b/util/vndb.pl
index 5ef0bf40..a9ac36b4 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -22,6 +22,11 @@ use YAWF ':html';
our(%O, %S);
+# load and (if required) regenerate the skins
+# NOTE: $S{skins} can be modified in data/config.pl, allowing deletion of skins or forcing only one skin
+$S{skins} = readskins();
+
+
# load settings from global.pl
require $ROOT.'/data/global.pl';
@@ -73,3 +78,28 @@ sub handle404 {
}
+sub readskins {
+ my %skins; # dirname => skin name
+ my $regen = 0;
+ my $lasttemplate = [stat "$ROOT/data/skingen/style.css"]->[9];
+ for my $f (glob "$ROOT/static/s/*") {
+ my $n = $1 if $f =~ m{([^/]+)$};
+ open my $F, '<', "$f/conf" or die $!;
+ while(<$F>) {
+ chomp;
+ s{[\t\s]*//.*$}{};
+ next if !/^name[\t\s]+(.+)$/;
+ $skins{$n} = $1;
+ last;
+ }
+ close $F;
+
+ my $lastgen = [stat "$f/style.css"]->[9];
+ $regen = 1 if (!-f "$f/style.css" && -x $f)
+ || ([stat "$f/conf"]->[9] > $lastgen || $lasttemplate > $lastgen) && -w "$f/style.css";
+ }
+ # note: this only works if the current process has write access to the skins
+ `$ROOT/util/skingen.pl` if $regen;
+ return \%skins;
+}
+