Parley

 view release on metacpan or  search on metacpan

lib/Parley/Controller/My.pm  view on Meta::CPAN

package Parley::Controller::My;
use strict;
use warnings;

use Parley::Version;  our $VERSION = $Parley::VERSION;
use base 'Catalyst::Controller';

use Image::Magick;
use JSON;
use Image::Size qw( html_imgsize imgsize );

use Parley::App::Error qw( :methods );

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Global class data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

my %dfv_profile_for = (
    # DFV validation profile for preferences
    time_format => {
        # make sure we get *something* for checkboxes
        # (which don't submit anything at all when unchecked)
        defaults => {
            use_utc     => 0,
            show_tz     => 0,
        },

        require_some => {
            tz_data => [ 1, qw(use_utc selectZone) ],
        },
        optional => [
            qw( show_tz time_format ),
        ],

        filters     => [qw( trim )],
        msgs => {
            format  => q{%s},
            missing => q{One ore more required fields are missing.},

            constraints => {
                tz_data => 'you must do stuff',
            },
        },
    },

    notifications => {
        # make sure we get *something* for checkboxes
        # (which don't submit anything at all when unchecked)
        defaults => {
            watch_on_post       => 0,
            notify_thread_watch => 0,
        },

        required => [
            qw(
                watch_on_post
                notify_thread_watch
            )
        ],
    },

    skin => {
        required => [
            qw(
                skin
            )
        ],
    },

lib/Parley/Controller/My.pm  view on Meta::CPAN

        # perform the update
        eval {
            # update the relevant field
            $person->update(
                {
                    $db_column => $c->request->param('value'),
                }
            );
        };
        # check for errors
        if ($@) {
            parley_warn($c, $@);
            $return_data->{message} = qq{<p>ERROR: $@</p>};
            $return_data->{updated} = 0;
            $json = objToJson($return_data);
            $c->response->body( $json );
            return;
        }
        else {
            $return_data->{message} =
                  q{<p>Updated }
                . $fieldname
                . q{ from '}
                . $c->request->param('ovalue')
                . q{' to '}
                . $c->request->param('value')
                . q{'</p>}
            ;
            $return_data->{updated} = 1;
            $json = objToJson($return_data);
            $c->log->info( $json );
            $c->response->body( $json );
            return;
        }
    }
    else {
        $return_data->{message} =
              q{<p>}
            . $c->localize(q{Unknown field name})
            . q{</p>};
        $return_data->{updated} = 0;
        $json = objToJson($return_data);
        $c->response->body( $json );
        return;
    }

    return;
}

sub _convert_and_scale_image {
    my ($file, $destdir) = @_;
    my $options = {
        'width'  => 100,
        'height' => 150,
    };

    # get the image dimensions
    my ($width, $height) = imgsize($file);

    # create a new image mangling object
    my $img = Image::Magick->new()
        or die $!;

    # read in the image file
    $img->Read($file);

    if ($width > $options->{width} or $height > $options->{height}) {
        # scale the longest side - if it's square, scale by height
        if ($width > $height) {
            # scale down by width
            #warn('# scale down by width');
            $img->Resize(
                geometry => $options->{width}
            );
        }
        elsif ($height >= $width) {
            # scale down by height
            #warn('# scale down by height');
            $img->Resize(
                geometry => q{x} . $options->{height}
            );
        }
    }

    # write out the scaled image
    $img->Write($destdir . q{/avatar.jpg});

    return;
}

=head1 NAME

Parley::Controller::My - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=head2 index 

=head1 AUTHOR

Chisel Wright C<< <chiselwright@users.berlios.de> >>

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;



( run in 2.209 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )