images: fix utf8 output
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
no warnings 'redefine';
|
no warnings 'redefine';
|
||||||
|
use utf8;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use Apache2::Request;
|
use Apache2::Request;
|
||||||
@@ -26,7 +26,8 @@ use template();
|
|||||||
use images();
|
use images();
|
||||||
use localization();
|
use localization();
|
||||||
|
|
||||||
binmode STDOUT, ":utf8";
|
#binmode STDOUT, ":utf8"; #<! does not work here!
|
||||||
|
print "Content-type:text/html; charset=UTF-8;\n\n";
|
||||||
|
|
||||||
my $r = shift;
|
my $r = shift;
|
||||||
my $cgi = undef;
|
my $cgi = undef;
|
||||||
@@ -37,120 +38,6 @@ my $base_dir = $config->{locations}->{base_dir};
|
|||||||
my $tmp_dir = '/var/tmp';
|
my $tmp_dir = '/var/tmp';
|
||||||
my $upload_limit = 2048 * 1000;
|
my $upload_limit = 2048 * 1000;
|
||||||
|
|
||||||
#binmode STDOUT, ":utf8";
|
|
||||||
#binmode STDOUT, ":encoding(UTF-8)";
|
|
||||||
|
|
||||||
my $params = {};
|
|
||||||
my $upload = undef;
|
|
||||||
my $error = '';
|
|
||||||
|
|
||||||
#get image from multiform before anything else
|
|
||||||
if ( defined $r ) {
|
|
||||||
|
|
||||||
#$cgi = new CGI();
|
|
||||||
|
|
||||||
#Apache2::Request
|
|
||||||
my $apr = Apache2::Request->new( $r, POST_MAX => $upload_limit, TEMP_DIR => $tmp_dir );
|
|
||||||
|
|
||||||
$params = {
|
|
||||||
studio_id => $apr->param('studio_id'),
|
|
||||||
project_id => $apr->param('project_id'),
|
|
||||||
};
|
|
||||||
|
|
||||||
#copy params to hash
|
|
||||||
my $body = $apr->body();
|
|
||||||
if ( defined $body ) {
|
|
||||||
for my $key ( keys %$body ) {
|
|
||||||
$params->{ scalar($key) } = scalar( $apr->param($key) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my $status = $apr->parse;
|
|
||||||
$status = '' if ( $status =~ /missing input data/i );
|
|
||||||
if ( $status =~ /limit/i ) {
|
|
||||||
$error = $status;
|
|
||||||
} else {
|
|
||||||
$upload = $apr->upload('image') if defined $params->{image};
|
|
||||||
}
|
|
||||||
print STDERR "apr\n";
|
|
||||||
} else {
|
|
||||||
|
|
||||||
#CGI fallback
|
|
||||||
$CGI::POST_MAX = $upload_limit;
|
|
||||||
$CGI::TMPDIRECTORY = $tmp_dir;
|
|
||||||
$cgi = new CGI();
|
|
||||||
$error = $cgi->cgi_error() || $error;
|
|
||||||
my %params = $cgi->Vars();
|
|
||||||
$params = \%params;
|
|
||||||
print STDERR "fallback\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "Content-type:text/html; charset=UTF-8;\n\n";
|
|
||||||
my ( $user, $expires ) = auth::get_user( $config, $params, $cgi );
|
|
||||||
return if ( ( !defined $user ) || ( $user eq '' ) );
|
|
||||||
|
|
||||||
my $user_presets = uac::get_user_presets(
|
|
||||||
$config,
|
|
||||||
{
|
|
||||||
user => $user,
|
|
||||||
project_id => $params->{project_id},
|
|
||||||
studio_id => $params->{studio_id}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$params->{default_studio_id} = $user_presets->{studio_id};
|
|
||||||
$params = uac::setDefaultStudio( $params, $user_presets );
|
|
||||||
$params = uac::setDefaultProject( $params, $user_presets );
|
|
||||||
|
|
||||||
my $request = {
|
|
||||||
url => $ENV{QUERY_STRING} || '',
|
|
||||||
params => {
|
|
||||||
original => $params,
|
|
||||||
checked => check_params( $config, $params ),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
$request = uac::prepare_request( $request, $user_presets );
|
|
||||||
$params = $request->{params}->{checked};
|
|
||||||
return unless uac::check( $config, $params, $user_presets ) == 1;
|
|
||||||
|
|
||||||
my $permissions = $request->{permissions};
|
|
||||||
|
|
||||||
$params->{action} = '' unless defined $params->{action};
|
|
||||||
|
|
||||||
if ( $permissions->{create_image} ne '1' ) {
|
|
||||||
uac::permissions_denied("create image");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $file_info = undef;
|
|
||||||
if ( $error ne '' ) {
|
|
||||||
if ( $error =~ /limit/ ) {
|
|
||||||
$params->{error} .=
|
|
||||||
"Image size is limited to "
|
|
||||||
. int( $upload_limit / 1000000 ) . " MB!"
|
|
||||||
. "Please make it smaller and try again!";
|
|
||||||
} else {
|
|
||||||
$params->{error} .= "Error:'$error'";
|
|
||||||
}
|
|
||||||
} elsif ( $params->{action} eq 'upload' ) {
|
|
||||||
$file_info = upload_file( $config, $cgi, $upload, $user );
|
|
||||||
$params->{error} .= $file_info->{error};
|
|
||||||
$params = update_database( $config, $params, $file_info, $user ) if $params->{error} eq '';
|
|
||||||
}
|
|
||||||
|
|
||||||
print STDERR "upload error: $params->{error}\n" if $params->{error};
|
|
||||||
my $out = '';
|
|
||||||
$params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'image' } );
|
|
||||||
template::process( $config, 'print', $params->{template}, $params );
|
|
||||||
|
|
||||||
print $cgi->cgi_error() if ( defined $cgi ) && ( defined $cgi->cgi_error() );
|
|
||||||
return if $params->{action} eq '';
|
|
||||||
|
|
||||||
$params->{action_result} ||= '';
|
|
||||||
$params->{filename} ||= '';
|
|
||||||
$params->{image_id} ||= '';
|
|
||||||
$params->{name} ||= '';
|
|
||||||
|
|
||||||
sub upload_file {
|
sub upload_file {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $cgi = shift;
|
my $cgi = shift;
|
||||||
@@ -228,7 +115,7 @@ sub update_database {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( ( defined $entries ) && ( scalar(@$entries) > 0 ) ) {
|
if ( ( defined $entries ) && ( scalar(@$entries) > 0 ) ) {
|
||||||
print STDERR "update image\n";
|
print STDERR "update image\n".Dumper($image);
|
||||||
images::update( $dbh, $image );
|
images::update( $dbh, $image );
|
||||||
my $entry = $entries->[0];
|
my $entry = $entries->[0];
|
||||||
$params->{image_id} = $entry->{id};
|
$params->{image_id} = $entry->{id};
|
||||||
@@ -387,3 +274,114 @@ sub check_params {
|
|||||||
return $checked;
|
return $checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my $params = {};
|
||||||
|
my $upload = undef;
|
||||||
|
my $error = '';
|
||||||
|
|
||||||
|
#get image from multiform before anything else
|
||||||
|
if ( defined $r ) {
|
||||||
|
|
||||||
|
#$cgi = new CGI();
|
||||||
|
|
||||||
|
#Apache2::Request
|
||||||
|
my $apr = Apache2::Request->new( $r, POST_MAX => $upload_limit, TEMP_DIR => $tmp_dir );
|
||||||
|
|
||||||
|
$params = {
|
||||||
|
studio_id => $apr->param('studio_id'),
|
||||||
|
project_id => $apr->param('project_id'),
|
||||||
|
};
|
||||||
|
|
||||||
|
#copy params to hash
|
||||||
|
my $body = $apr->body();
|
||||||
|
if ( defined $body ) {
|
||||||
|
for my $key ( keys %$body ) {
|
||||||
|
$params->{ scalar($key) } = scalar( $apr->param($key) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $status = $apr->parse;
|
||||||
|
$status = '' if ( $status =~ /missing input data/i );
|
||||||
|
if ( $status =~ /limit/i ) {
|
||||||
|
$error = $status;
|
||||||
|
} else {
|
||||||
|
$upload = $apr->upload('image') if defined $params->{image};
|
||||||
|
}
|
||||||
|
print STDERR "apr\n";
|
||||||
|
} else {
|
||||||
|
|
||||||
|
#CGI fallback
|
||||||
|
$CGI::POST_MAX = $upload_limit;
|
||||||
|
$CGI::TMPDIRECTORY = $tmp_dir;
|
||||||
|
$cgi = new CGI();
|
||||||
|
$error = $cgi->cgi_error() || $error;
|
||||||
|
my %params = $cgi->Vars();
|
||||||
|
$params = \%params;
|
||||||
|
print STDERR "fallback\n";
|
||||||
|
}
|
||||||
|
print STDERR Dumper($params);
|
||||||
|
|
||||||
|
my ( $user, $expires ) = auth::get_user( $config, $params, $cgi );
|
||||||
|
return if ( ( !defined $user ) || ( $user eq '' ) );
|
||||||
|
|
||||||
|
my $user_presets = uac::get_user_presets(
|
||||||
|
$config,
|
||||||
|
{
|
||||||
|
user => $user,
|
||||||
|
project_id => $params->{project_id},
|
||||||
|
studio_id => $params->{studio_id}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$params->{default_studio_id} = $user_presets->{studio_id};
|
||||||
|
$params = uac::setDefaultStudio( $params, $user_presets );
|
||||||
|
$params = uac::setDefaultProject( $params, $user_presets );
|
||||||
|
|
||||||
|
my $request = {
|
||||||
|
url => $ENV{QUERY_STRING} || '',
|
||||||
|
params => {
|
||||||
|
original => $params,
|
||||||
|
checked => check_params( $config, $params ),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
$request = uac::prepare_request( $request, $user_presets );
|
||||||
|
$params = $request->{params}->{checked};
|
||||||
|
return unless uac::check( $config, $params, $user_presets ) == 1;
|
||||||
|
|
||||||
|
my $permissions = $request->{permissions};
|
||||||
|
|
||||||
|
$params->{action} = '' unless defined $params->{action};
|
||||||
|
|
||||||
|
if ( $permissions->{create_image} ne '1' ) {
|
||||||
|
uac::permissions_denied("create image");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $file_info = undef;
|
||||||
|
if ( $error ne '' ) {
|
||||||
|
if ( $error =~ /limit/ ) {
|
||||||
|
$params->{error} .=
|
||||||
|
"Image size is limited to "
|
||||||
|
. int( $upload_limit / 1000000 ) . " MB!"
|
||||||
|
. "Please make it smaller and try again!";
|
||||||
|
} else {
|
||||||
|
$params->{error} .= "Error:'$error'";
|
||||||
|
}
|
||||||
|
} elsif ( $params->{action} eq 'upload' ) {
|
||||||
|
$file_info = upload_file( $config, $cgi, $upload, $user );
|
||||||
|
$params->{error} .= $file_info->{error};
|
||||||
|
$params = update_database( $config, $params, $file_info, $user ) if $params->{error} eq '';
|
||||||
|
}
|
||||||
|
|
||||||
|
print STDERR "upload error: $params->{error}\n" if $params->{error};
|
||||||
|
$params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'image' } );
|
||||||
|
template::process( $config, 'print', $params->{template}, $params );
|
||||||
|
|
||||||
|
print $cgi->cgi_error() if ( defined $cgi ) && ( defined $cgi->cgi_error() );
|
||||||
|
return if $params->{action} eq '';
|
||||||
|
|
||||||
|
$params->{action_result} ||= '';
|
||||||
|
$params->{filename} ||= '';
|
||||||
|
$params->{image_id} ||= '';
|
||||||
|
$params->{name} ||= '';
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
no warnings 'redefine';
|
no warnings 'redefine';
|
||||||
|
use utf8;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use File::stat();
|
use File::stat();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
no warnings 'redefine';
|
no warnings 'redefine';
|
||||||
|
use utf8;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
use params();
|
use params();
|
||||||
|
|||||||
Reference in New Issue
Block a user