]> git.imager.perl.org - bse.git/blob - site/cgi-bin/modules/BSE/TB/Image.pm
fix popimage[]
[bse.git] / site / cgi-bin / modules / BSE / TB / Image.pm
1 package BSE::TB::Image;
2 use strict;
3 # represents an image from the database
4 use Squirrel::Row;
5 use vars qw/@ISA/;
6 @ISA = qw/Squirrel::Row/;
7 use Carp qw(confess);
8 use DevHelp::HTML qw(escape_html);
9
10 sub columns {
11   return qw/id articleId image alt width height url displayOrder name
12             storage src ftype/;
13 }
14
15 sub _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
24 sub 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
39 sub 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
54 sub 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
69 sub popimage {
70   my ($im, %opts) = @_;
71
72   my $cfg = delete $opts{cfg}
73     or confess "Missing cfg parameter";
74
75   my $handler = $im->_handler_object($cfg);
76
77   return $handler->popimage
78     (
79      image => $im,
80      %opts,
81     );
82 }
83
84 sub image_url {
85   my ($im, $cfg) = @_;
86
87   $im->src || "/images/$im->{image}";
88 }
89
90 1;