adapt the image handler code to work with BSE::TB::File objects too
[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);
3f9c8a96 8use BSE::Util::HTML qw(escape_html);
f40af7e2 9
d585a3cf 10our $VERSION = "1.001";
cb7fd78d 11
f40af7e2
TC
12sub columns {
13 return qw/id articleId image alt width height url displayOrder name
14 storage src ftype/;
15}
16
17sub _handler_object {
18 my ($im, $cfg) = @_;
19
20 my $module = "BSE::ImageHandler::" . ucfirst($im->ftype);
21 (my $file = $module . ".pm") =~ s(::)(/)g;
22 require $file;
23 my $handler = $module->new(cfg => $cfg);
24}
25
26sub formatted {
27 my ($self, %opts) = @_;
28
29 my $cfg = delete $opts{cfg}
30 or confess "Missing cfg parameter";
31
32 my $handler = $self->_handler_object($cfg);
33
34 return $handler->format
35 (
36 image => $self,
37 %opts,
38 );
39}
40
41sub inline {
42 my ($self, %opts) = @_;
43
44 my $cfg = delete $opts{cfg}
45 or confess "Missing cfg parameter";
46
47 my $handler = $self->_handler_object($cfg);
48
49 return $handler->inline
50 (
51 image => $self,
52 %opts,
53 );
54}
55
56sub thumb {
57 my ($im, %opts) = @_;
58
59 my $cfg = delete $opts{cfg}
60 or confess "Missing cfg parameter";
61
62 my $handler = $im->_handler_object($cfg);
63
64 return $handler->thumb
65 (
66 image => $im,
67 %opts,
68 );
69}
70
3f23129e
TC
71sub popimage {
72 my ($im, %opts) = @_;
73
74 my $cfg = delete $opts{cfg}
75 or confess "Missing cfg parameter";
76
77 my $handler = $im->_handler_object($cfg);
78
79 return $handler->popimage
80 (
81 image => $im,
82 %opts,
83 );
84}
85
f40af7e2 86sub image_url {
d585a3cf 87 my ($im) = @_;
f40af7e2
TC
88
89 $im->src || "/images/$im->{image}";
90}
91
d585a3cf
TC
92sub json_data {
93 my ($self) = @_;
94
95 my $data = $self->data_only;
96 $data->{url} = $self->image_url;
97
98 return $data;
99}
100
f40af7e2 1011;