END_TEMPLATE
}
sub conf {
my $self = shift;
@_ and $self->{CONF} = shift;
return $self->{CONF};
}
sub template {
my $self = shift;
@_ and $self->{TEMPLATE} = shift;
return $self->{TEMPLATE};
}
sub query {
my $self = shift;
@_ and $self->{QUERY} = shift;
return $self->{QUERY};
}
sub config {
my $self = shift;
@_ and $self->{CONFIG} = shift;
return $self->{CONFIG};
}
sub dbh {
my $self = shift;
@_ and $self->{dbh} = shift;
return $self->{dbh};
}
1;
__END__
=encoding utf8
=for stopwords lightbox crapolio subref
=head1 NAME
App::ZofCMS::Plugin::ImageGallery - CRUD-like plugin for managing images.
=head1 SYNOPSIS
In your Main Config File or ZofCMS Template file:
plugins => [ qw/ImageGallery/ ],
plug_image_gallery => {
dsn => "DBI:mysql:database=test;host=localhost",
user => 'test',
pass => 'test',
no_form => 0,
allow_edit => 1,
},
In your L template:
Viola, now you can upload photos with descriptions, delete them and edit descriptions. \o/
=head1 DESCRIPTION
The module is a plugin for L that allows one to add a CRUD-like functionality
for managing photos. The plugin automatically makes thumbnails and can also resize the
actual photos if you tell it to. So far, only
C<.jpg>, C<.png> and C<.gif> images are supported; however, plugin does not check
C of the uploaded image.
The image file name and description are stored in a SQL database.
This documentation assumes you've read L, L and L
=head1 USED SQL TABLE FORMAT
When C option is turned on (see below) the plugin will create the following
table where C is derived from C
argument in C
(see below).
CREATE TABLE table_name (
photo TEXT,
width SMALLINT,
height SMALLINT,
thumb_width SMALLINT,
thumb_height SMALLINT,
description TEXT,
time VARCHAR(10),
id TEXT
);
=head1 MAIN CONFIG FILE AND ZofCMS TEMPLATE FIRST-LEVEL KEYS
=head2 C
plugins => [ qw/ImageGallery/, ],
You obviously need to include the plugin in the list of plugins to execute.
=head2 C
plug_image_gallery => {
dsn => "DBI:mysql:database=test;host=localhost",
# everything below is optional
user => '',
pass => '',
opt => { RaiseError => 1, AutoCommit => 1 },
table => 'photos',
photo_dir => 'photos/',
filename => '[:rand:]',
thumb_dir => 'photos/thumbs/',
create_table => 0,
t_name => 'plug_image_gallery',
no_form => 1,
no_list => 0,
no_thumb_desc => 0,
allow_edit => 0,
thumb_size => { 200, 200 },
# photo_size => [ 600, 600 ],
has_view => 1,
want_lightbox => 0,
lightbox_rel => 'lightbox',
lightbox_desc => 1,
}
plug_image_gallery => sub {
my ( $t, $q, $config ) = @_;
return {
dsn => "DBI:mysql:database=test;host=localhost",
};
}
The plugin takes its configuration from C first-level key that takes
a hashref or a subref as a value and can be specified in either (or both) Main Config File and
ZofCMS Template file. If the same key in that hashref is specified in both, Main Config File
and ZofCMS Template file, then the value given to it in ZofCMS Template will take precedence.
If subref is specified,
its return value will be assigned to C as if it was already there. If sub returns
an C, then plugin will stop further processing. The C<@_> of the subref will
contain (in that order): ZofCMS Template hashref, query parameters hashref and
L object.
The plugin will B run if C is not set or if B C
B C arguments (see below) are set to true values.
The possible C hashref's keys/values are as follows:
=head3 C
dsn => "DBI:mysql:database=test;host=localhost",
B. Takes a scalar as a value which must contain a valid
"$data_source" as explained in L's C method (which
plugin currently uses).
=head3 C
user => '',
B. Takes a string as a value that specifies the user name to use when authorizing
with the database. B empty string
=head3 C
pass => '',
B. Takes a string as a value that specifies the password to use when authorizing
with the database. B empty string
=head3 C
opt => { RaiseError => 1, AutoCommit => 1 },
B. Takes a hashref as a value, this hashref contains additional L
parameters to pass to C L's method. B
C<< { RaiseError => 1, AutoCommit => 1 } >>
=head3 C
table => 'photos',
B. Takes a string as a value, specifies the name of the SQL table in which to
store information about photos. B C
=head3 C
create_table => 0,
B. When set to a true value, the plugin will automatically create needed SQL table,
you can create it manually if you wish, see its format in C section
above. Generally you'd set this to a true value only once, at the start, and then you'd remove
it because there is no "IF EXISTS" checks. B C<0>
=head3 C
t_name => 'plug_image_gallery',
B. Takes a string as a value. This string will be
used as a "base name" for two keys that plugin generates in C<{t}> special key.
The keys are C and C
(providing C is set to
default) and are explained below in C section below. B
C
=head3 C
photo_dir => 'photos/',
B. Takes a string that specifies the directory (relative to C) where
the plugin will store photos. B plugin does B automatically create this directory.
B C
=head3 C
thumb_dir => 'photos/thumbs/',
B. Takes a string that specifies the directory (relative to C) where
the plugin will store thumbnails.
B plugin does B automatically create this directory. B this directory
B be the same as C.
B C
=head3 C
filename => '[:rand:]',
B. Specifies the name for the image file (and its thumbnail) without the extension
for when new image is uploaded. You'd obviously want to manipulate this value with some
other plugin (e.g. L) to make sure it's not the same
as existing images. B of C<[:rand:]> (value includes the brackets) will make
the plugin generate random filenames (along with check of whether the generated name
already exists). B C<[:rand:]>
=head3 C
thumb_size => { 200, 200 }, # resize only if larger
thumb_size => [ 200, 200 ], # always resize
B. Takes either an arrayref with two elements or a hashref with one key/value pair.
The plugin will generate thumbnails automatically. The C specifies the dimensions
of the thumbnails. The proportions are always kept when resizing. When C is set
to an I, the plugin will resize the image even if its smaller than the specified
size (i.e. a 50x50 image's thumb will be scaled to 200x200 when C is set to
C<[200, 200]> ). The first element of the arrayref denotes the x (width) dimension and the
second element denotes the y (height) dimension. When the value for C is a
I then the key denotes the width and the value denotes the height; the image will
be resized only if one of its dimensions (width or height) is larger than the specified
values. In other words, when C is set to C<{ 200, 200 }>, a 50x50 image's thumbnail
will be left at 50x50 while a 500x500 image's thumbnail will be scaled to 200x200.
B C<{ 200, 200 }>
=head3 C
photo_size => { 600, 600 },
photo_size => [ 600, 600 ],
B. When specified takes either an arrayref or a hashref as a value. Everything is
the same (regarding values) as the values for C argument described above except
that resizing is done on the original image. If C is not specified, no resizing
will be performed. B the thumbnail will be generated first, thus it's possible to
have thumbnails that are larger than the original image even when hashrefs are used for
both C and C. B
=head3 C
no_form => 1,
B. Takes either true or false values. When
set to a B value, the plugin will generate as well as process an HTML form that
is to be used for uploading new images or editing descriptions on existing ones.
B even if you are making your own HTML form, the plugin will B process
editing or deleting of items when C is set to a true value. B C<1>
=head3 C
no_list => 0,
B. Takes either true or false values. When set to a B value, the plugin
will pull the data from the database and generate an HTML list with image thumbnails and their
descriptions (unless C argument described below is set to a true value).
B C<0>
=head3 C
no_thumb_desc => 0,
B. Takes either true or false values. Makes sense only when C is set to
a false value. When C is set to a B value, the plugin will not put
descriptions in the generated list of thumbnails. The description will be visible only when
the user clicks on the image to view it in large size (providing C option that
is described below is set to a true value). B C<0>
=head3 C
has_view => 1,
B. Takes either true or false values. Makes sense only when C is set
to a false value. When set to a true value, plugin will generate links for each thumbnail
in the list; when user will click that link, he or she will be presented with an original
image and a link to go back to the list of thumbs. When set to a false value no link
will be generated. B C<1>
=head3 C
allow_edit => 0,
B. Takes either true or false values. When set to a true value, B C
and B must be set to false values. When set to a true value, the plugin will
generate C and C buttons under each thumbnail in the list. Clicking "Delete" will
delete the image, thumbnail and entry in the database. Clicking "Edit" will fetch the
description into the "description" field in the form, allowing the user to edit it.
B C<0>
=head3 C
want_lightbox => 0,
B. The list of thumbs generated by the plugin can be generated for use with
"Lightbox" JavaScript crapolio. Takes true or false values. When set to a true value, the
thumb list will be formatted for use with "Lightbox". B C B be set
to a true value as well. B C<0>
=head3 C
lightbox_rel => 'lightbox',
B. Used only when C is set to a true value. Takes a string as a value,
this string will be used for C attribute on links. B C
=head3 C
lightbox_desc => 1,
B. Takes either true or false values. When set to a true value, the plugin will
stick image descriptions into C attribute that makes them visible in the Lightbox.
B C<1>
=head1 HTML::Template VARIABLES
The plugin generates two keys in C<{t}> ZofCMS Template special key, thus making them
available for use in your L templates. Assuming C is left at its
default value the following are the names of those two keys:
=head2 C
This variable will contain HTML form generated by the plugin, the form also includes display
of errors.
=head2 C
This variable will contain the list of photos generated by the plugin.
=head1 GENERATED HTML CODE
=head2 form
=head2 form when "Edit" was clicked
=head2 form when upload or update was successful
=head1 REPOSITORY
Fork this module on GitHub:
L
=head1 BUGS
To report bugs or request features, please use
L
If you can't access GitHub, you can email your request
to C
=head1 AUTHOR
Zoffix Znet
(L, L)
=head1 LICENSE
You can use and distribute this module under the same terms as Perl itself.
See the C file included in this distribution for complete
details.
=cut