better file tag handling through the filen and gfile tags
[bse.git] / site / cgi-bin / modules / BSE / TB / Image.pm
CommitLineData
f40af7e2
TC
1package BSE::TB::Image;
2use strict;
3# represents an image from the database
4use Squirrel::Row;
5use vars qw/@ISA/;
6@ISA = qw/Squirrel::Row/;
7use Carp qw(confess);
8use DevHelp::HTML qw(escape_html);
9
10sub columns {
11 return qw/id articleId image alt width height url displayOrder name
12 storage src ftype/;
13}
14
15sub _handler_object {
16 my ($im, $cfg) = @_;
17
18 my $module = "BSE::ImageHandler::" . ucfirst($im->ftype);
19 (my $file = $module . ".pm") =~ s(::)(/)g;
20 require $file;
21 my $handler = $module->new(cfg => $cfg);
22}
23
24sub formatted {
25 my ($self, %opts) = @_;
26
27 my $cfg = delete $opts{cfg}
28 or confess "Missing cfg parameter";
29
30 my $handler = $self->_handler_object($cfg);
31
32 return $handler->format
33 (
34 image => $self,
35 %opts,
36 );
37}
38
39sub inline {
40 my ($self, %opts) = @_;
41
42 my $cfg = delete $opts{cfg}
43 or confess "Missing cfg parameter";
44
45 my $handler = $self->_handler_object($cfg);
46
47 return $handler->inline
48 (
49 image => $self,
50 %opts,
51 );
52}
53
54sub thumb {
55 my ($im, %opts) = @_;
56
57 my $cfg = delete $opts{cfg}
58 or confess "Missing cfg parameter";
59
60 my $handler = $im->_handler_object($cfg);
61
62 return $handler->thumb
63 (
64 image => $im,
65 %opts,
66 );
67}
68
69sub image_url {
70 my ($im, $cfg) = @_;
71
72 $im->src || "/images/$im->{image}";
73}
74
751;