App-ZofCMS-PluginBundle-Naughty

 view release on metacpan or  search on metacpan

lib/App/ZofCMS/Plugin/ImageGallery.pm  view on Meta::CPAN


        binmode $fh_thumb;
        print $fh_thumb $gd->$img_type();
        close $fh_thumb;
    }
    else {
        copy $photo_file, $thumb_file;
    }

    if ( ref $conf->{photo_size} eq 'ARRAY'
        or ( ref $conf->{photo_size} eq 'HASH'
            and ( (%{ $conf->{photo_size} })[0] < $x
                or (%{ $conf->{photo_size} })[1] < $y
            )
        )
    ) {
        $conf->{photo_size} = [ %{ $conf->{photo_size} } ]
            if ref $conf->{photo_size} eq 'HASH';

        my $photo = Image::Resize->new( $photo_file );
        my $gd = $photo->resize( @{ $conf->{photo_size} } );

        open my $fh_photo, '>', $photo_file
            or $t->param( error => "Failed to resize photo [$!]" )
                and return;

        my $img_type = substr $ext, 1;
        $img_type = 'jpeg'
            unless $img_type eq 'png' or $img_type eq 'gif';

        binmode $fh_photo;
        print $fh_photo $gd->$img_type();
        close $fh_photo;

        ( $x, $y ) = ( $gd->width, $gd->height );
    }
    my ( $thumb_x, $thumb_y ) = imgsize $thumb_file;

    $t->param( success => 1 );

    $dbh->do(
        "INSERT INTO $conf->{table} VALUES(?, ?, ?, ?, ?, ?, ?, ?);",
        undef,
        $conf->{filename} . $ext,
        $x,
        $y,
        $thumb_x,
        $thumb_y,
        $query->{plug_image_gallery_description},
        time(),
        do { my $id = rand() . time() . rand(); $id =~ tr/.//d; $id },
    );

    return 1;
}

sub _form_template {
    return <<'END_TEMPLATE';
<tmpl_if name='success'>
    <p>Your image has been successfully uploaded.</p>
    <p><a href="<tmpl_var escape='html' name='success_href'>">Upload another image</a></p>
<tmpl_else>
    <form action="" method="POST" id="plug_image_gallery_form" enctype="multipart/form-data">
    <div>
        <tmpl_if name='error'><p class="error"><tmpl_var escape='html' name='error'></p></tmpl_if>
        <input type="hidden" name="page" value="<tmpl_var escape='html' name='page'>">
        <input type="hidden" name="dir" value="<tmpl_var escape='html' name='dir'>">
        <tmpl_if name='is_edit'><input type="hidden" name="plug_image_gallery_id" value="<tmpl_var escape='html' name='id'>"></tmpl_if>
        <ul>
            <tmpl_unless name='is_edit'><li>
                <label for="plug_image_gallery_file">Image: </label
                ><input type="file" name="plug_image_gallery_file" id="plug_image_gallery_file">
            </li></tmpl_unless>
            <li>
                <label for="plug_image_gallery_description">Description: </label
                ><textarea name="plug_image_gallery_description" id="plug_image_gallery_description" cols="60" rows="5"><tmpl_var escape='html' name='plug_image_gallery_description'></textarea>
            </li>
        </ul>
        <input type="submit" name="plug_image_gallery_submit" value="<tmpl_if name='is_edit'>Update<tmpl_else>Upload</tmpl_if>">
    </div>
    </form>
</tmpl_if>
END_TEMPLATE
}

sub _list_template {
    return <<'END_TEMPLATE';
<tmpl_if name='is_view'>
    <a class="plug_image_gallery_return_to_image_list" href="/index.pl?page=<tmpl_var escape='html' name='page'>&amp;dir=<tmpl_var escape='html' name='dir'>">Return to image list.</a>
    <div id="plug_image_gallery_photo"><img src="/<tmpl_var escape='html' name='photo'>" width="<tmpl_var escape='html' name='width'>" height="<tmpl_var escape='html' name='height'>" alt=""><tmpl_if name='has_description'><p class="plug_image_gallery...
<tmpl_else>
    <tmpl_if name='has_images'>
        <ul class="plug_image_gallery_list">
            <tmpl_loop name='images'>
                <li<tmpl_if name='alt'> class="alt"</tmpl_if>>
                    <tmpl_if name='has_view'><a <tmpl_if name='want_lightbox'>rel="<tmpl_var escape='html' name='lightbox_rel'>" href="/<tmpl_var escape='html' name='lightbox_src'>" title="<tmpl_var escape='html' name='lightbox_desc'>"<tmpl_else>href...
                    <tmpl_if name="has_description"><p><tmpl_var name='description'></p></tmpl_if>
                    <tmpl_if name="edit">
                        <form action="" method="POST">
                        <div>
                            <input type="hidden" name="plug_image_gallery_id" value="<tmpl_var escape='html' name='id'>">
                            <input type="hidden" name="page" value="<tmpl_var escape='html' name='page'>">
                            <input type="hidden" name="dir" value="<tmpl_var escape='html' name='dir'>">
                            <input type="submit" class="input_submit" name="plug_image_gallery_action" value="Edit">
                            <input type="submit" class="input_submit" name="plug_image_gallery_action" value="Delete">
                        </div>
                        </form>
                    </tmpl_if>
                </li>
            </tmpl_loop>
        </ul>
    <tmpl_else>
        <p>Currently there are no images.</p>
    </tmpl_if>
</tmpl_if>
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:



( run in 0.530 second using v1.01-cache-2.11-cpan-98e64b0badf )