summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-08-22 09:37:52 +0200
committerYorhel <git@yorhel.nl>2011-08-22 09:37:52 +0200
commit3e50a783a073ba8359b221f7d9a8071e23ade967 (patch)
treead6c8e9277bf31c3dda7fb09d45283c8426f5d5e
parent6ff624ccffc043141d33884dcc75d015e924d5d4 (diff)
Use generic imgurl() and imgpath() functions to generate image URLs/paths
-rw-r--r--ChangeLog2
-rw-r--r--lib/VNDB/Func.pm17
-rw-r--r--lib/VNDB/Handler/Chars.pm11
-rw-r--r--lib/VNDB/Handler/Misc.pm3
-rw-r--r--lib/VNDB/Handler/VNEdit.pm8
-rw-r--r--lib/VNDB/Handler/VNPage.pm12
6 files changed, 34 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index a2b3ce85..06188156 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,13 @@
2.21 - ?
- New resolution: 1280x960
+ - New platforms: Android, Web and DB-PG
- Multi::Feed: Show full summary and refresh more often
- Switched back to Algorithm::Diff::XS
- Added secondary ordering on title on releases listing on VN page
- Added i+/c+ ID recognition to VN search
- JS: Don't consider 256x384 a "bad" screenshot resolution
- Changed location of 'add character/release' links on VN page
+ - Use generic imgurl() and imgpath() functions to generate image URLs/paths
- Bugfix: Properly make i+ IDs linkable in bb2html()
- Bugfix: Make sure the user dropdown boxes work on /v+/chars
- Bugfix: dbTraitGet() filtering would not always work correctly
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 67cd3f7e..a2cacf78 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -7,7 +7,10 @@ use TUWF ':html';
use Exporter 'import';
use POSIX 'strftime', 'ceil', 'floor';
use VNDBUtil;
-our @EXPORT = (@VNDBUtil::EXPORT, qw| clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags childtags charspoil |);
+our @EXPORT = (@VNDBUtil::EXPORT, qw|
+ clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags
+ childtags charspoil imgpath imgurl
+|);
# three ways to represent the same information
@@ -180,5 +183,17 @@ sub charspoil {
}
+# generates a local path to an image in static/
+sub imgpath { # <type>, <id>
+ return sprintf '%s/%s/%02d/%d.jpg', $VNDB::ROOT, $_[0], $_[1]%100, $_[1];
+}
+
+
+# generates a URL for an image in static/
+sub imgurl {
+ return sprintf '%s/%s/%02d/%d.jpg', $TUWF::OBJ->{url_static}, $_[0], $_[1]%100, $_[1];
+}
+
+
1;
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index 5e12aa03..9c8a1b5e 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -50,7 +50,7 @@ sub page {
[ main => htmlize => sub { $_[0] ? sprintf '<a href="/c%d">c%d</a>', $_[0], $_[0] : mt '_revision_empty' } ],
[ main_spoil=> serialize => sub { mt "_spoil_$_[0]" } ],
[ image => htmlize => sub {
- return $_[0] > 0 ? sprintf '<img src="%s/ch/%02d/%d.jpg" />', $self->{url_static}, $_[0]%100, $_[0]
+ return $_[0] > 0 ? sprintf '<img src="%s" />', imgurl(ch => $_[0])
: mt $_[0] < 0 ? '_chdiff_image_proc' : '_chdiff_image_none';
}],
[ traits => join => '<br />', split => sub {
@@ -110,8 +110,7 @@ sub charTable {
} elsif($r->{image} < 0) {
p mt '_charp_imgproc';
} else {
- img src => sprintf('%s/ch/%02d/%d.jpg', $self->{url_static}, $r->{image}%100, $r->{image}),
- alt => $r->{name} if $r->{image};
+ img src => imgurl(ch => $r->{image}), alt => $r->{name};
}
end 'div';
@@ -375,7 +374,7 @@ sub edit {
div class => 'img';
p mt '_chare_image_none' if !$frm->{image};
p mt '_chare_image_processing' if $frm->{image} && $frm->{image} < 0;
- img src => sprintf("%s/ch/%02d/%d.jpg", $self->{url_static}, $frm->{image}%100, $frm->{image}) if $frm->{image} && $frm->{image} > 0;
+ img src => imgurl(ch => $frm->{image}) if $frm->{image} && $frm->{image} > 0;
end;
div;
@@ -428,7 +427,7 @@ sub _uploadimage {
if($frm->{_err} || !$self->reqPost('img')) {
return 0 if !$frm->{image};
- push @{$frm->{_err}}, 'invalidimgid' if !-s sprintf '%s/static/ch/%02d/%d.jpg', $VNDB::ROOT, $frm->{image}%100, $frm->{image};
+ push @{$frm->{_err}}, 'invalidimgid' if !-s imgpath(ch => $frm->{image});
return $frm->{image};
}
@@ -440,7 +439,7 @@ sub _uploadimage {
# get image ID and save it, to be processed by Multi
my $imgid = $self->dbCharImageId;
- my $fn = sprintf '%s/static/ch/%02d/%d.jpg', $VNDB::ROOT, $imgid%100, $imgid;
+ my $fn = imgpath(ch => $imgid);
$self->reqSaveUpload('img', $fn);
chmod 0666, $fn;
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 643af1cf..d801c667 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -55,8 +55,7 @@ sub homepage {
for (@$scr) {
my($w, $h) = imgsize($_->{width}, $_->{height}, @{$self->{scr_size}});
a href => "/v$_->{vid}", title => $_->{title};
- img src => sprintf("%s/st/%02d/%d.jpg", $self->{url_static}, $_->{scr}%100, $_->{scr}),
- alt => $_->{title}, width => $w, height => $h;
+ img src => imgurl(st => $_->{scr}), alt => $_->{title}, width => $w, height => $h;
end;
}
end;
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index 10680f0e..0309a01c 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -124,7 +124,7 @@ sub _uploadimage {
if($frm->{_err} || !$self->reqPost('img')) {
return 0 if !$frm->{image};
- push @{$frm->{_err}}, 'invalidimgid' if !-s sprintf '%s/static/cv/%02d/%d.jpg', $VNDB::ROOT, $frm->{image}%100, $frm->{image};
+ push @{$frm->{_err}}, 'invalidimgid' if !-s imgpath(cv => $frm->{image});
return $frm->{image};
}
@@ -136,7 +136,7 @@ sub _uploadimage {
# get image ID and save it, to be processed by Multi
my $imgid = $self->dbVNImageId;
- my $fn = sprintf '%s/static/cv/%02d/%d.jpg', $VNDB::ROOT, $imgid%100, $imgid;
+ my $fn = imgpath(cv => $imgid);
$self->reqSaveUpload('img', $fn);
chmod 0666, $fn;
@@ -170,7 +170,7 @@ sub _form {
div class => 'img';
p mt '_vnedit_image_none' if !$frm->{image};
p mt '_vnedit_image_processing' if $frm->{image} < 0;
- img src => sprintf("%s/cv/%02d/%d.jpg", $self->{url_static}, $frm->{image}%100, $frm->{image}) if $frm->{image} > 0;
+ img src => imgurl(cv => $frm->{image}) if $frm->{image} > 0;
end;
div;
@@ -341,7 +341,7 @@ sub scrxml {
# no error? save and let Multi process it
if(!$id) {
$id = $self->dbScreenshotAdd;
- my $fn = sprintf '%s/static/sf/%02d/%d.jpg', $VNDB::ROOT, $id%100, $id;
+ my $fn = imgpath(sf => $id);
$self->reqSaveUpload($param, $fn);
chmod 0666, $fn;
}
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index bd8ebcf8..7c6d4d13 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -79,7 +79,7 @@ sub page {
p mt '_vnpage_imgproc';
} else {
p $v->{img_nsfw} ? (id => 'nsfw_hid', style => $self->authPref('show_nsfw') ? 'display: block' : '') : ();
- img src => sprintf("%s/cv/%02d/%d.jpg", $self->{url_static}, $v->{image}%100, $v->{image}), alt => $v->{title};
+ img src => imgurl(cv => $v->{image}), alt => $v->{title};
i mt '_vnpage_imgnsfw_foot' if $v->{img_nsfw};
end;
if($v->{img_nsfw}) {
@@ -245,15 +245,15 @@ sub _revision {
return @r ? @r : (mt '_revision_empty');
}],
[ screenshots => join => '<br />', split => sub {
- my @r = map sprintf('[%s] <a href="%s/sf/%02d/%d.jpg" rel="iv:%dx%d">%4$d</a> (%s)',
+ my @r = map sprintf('[%s] <a href="%s" rel="iv:%dx%d">%4$d</a> (%s)',
$_->{rid} ? qq|<a href="/r$_->{rid}">r$_->{rid}</a>| : 'no release',
- $self->{url_static}, $_->{id}%100, $_->{id}, $_->{width}, $_->{height},
+ imgurl(sf => $_->{id}), $_->{width}, $_->{height},
mt($_->{nsfw} ? '_vndiff_nsfw_notsafe' : '_vndiff_nsfw_safe')
), @{$_[0]};
return @r ? @r : (mt '_revision_empty');
}],
[ image => htmlize => sub {
- my $url = sprintf "%s/cv/%02d/%d.jpg", $self->{url_static}, $_[0]%100, $_[0];
+ my $url = imgurl(cv => $_[0]);
if($_[0] > 0) {
return $_[1]->{img_nsfw} && !$self->authPref('show_nsfw') ? "<a href=\"$url\">".mt('_vndiff_image_nsfw').'</a>' : "<img src=\"$url\" />";
} else {
@@ -547,10 +547,10 @@ sub _screenshots {
div class => 'scr';
for (@scr) {
my($w, $h) = imgsize($_->{width}, $_->{height}, @{$self->{scr_size}});
- a href => sprintf('%s/sf/%02d/%d.jpg', $self->{url_static}, $_->{id}%100, $_->{id}),
+ a href => imgurl(sf => $_->{id}),
class => sprintf('scrlnk%s%s', $_->{nsfw} ? ' nsfw':'', $_->{nsfw}&&!$self->authPref('show_nsfw')?' hidden':''),
rel => "iv:$_->{width}x$_->{height}:scr";
- img src => sprintf('%s/st/%02d/%d.jpg', $self->{url_static}, $_->{id}%100, $_->{id}),
+ img src => imgurl(st => $_->{id}),
width => $w, height => $h, alt => mt '_vnpage_scr_num', $_->{id};
end;
}