drop the tables we create (for clean installs)
[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
cb7fd78d
TC
10our $VERSION = "1.000";
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
TC
86sub image_url {
87 my ($im, $cfg) = @_;
88
89 $im->src || "/images/$im->{image}";
90}
91
921;