#webliberty::App::Image.pm (2006/02/18)
#Copyright(C) 2002-2006 Knight, All rights reserved.

package webliberty::App::Image;

use strict;
use base qw(webliberty::Basis);
use webliberty::File;
use webliberty::Skin;
use webliberty::App::Diary;

### コンストラクタ
sub new {
	my $class = shift;

	my $self = {
		init   => shift,
		config => shift,
		query  => shift
	};
	bless $self, $class;

	return $self;
}

### メイン処理
sub run {
	my $self = shift;

	$self->output;

	return;
}

### 画像表示
sub output {
	my $self = shift;

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_image}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info
	);

	my $file_ins  = new webliberty::File("$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$self->{query}->{file}");
	my $file_name = $file_ins->get_name . '.' . $file_ins->get_ext;
	my($file_width, $file_height) = $file_ins->get_size;

	if (!-e "$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file_name") {
		$self->error('指定されたファイルは存在しません。');
	}

	my $file_image = "<img src=\"$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file_name\" alt=\"アップロードファイル $file_name\" width=\"$file_width\" height=\"$file_height\" />";

	print $self->header;
	print $skin_ins->get_replace_data(
		'_all',
		INFO_IMAGE      => $file_image,
		INFO_FILENAME   => $file_name,
		INFO_FILEWIDTH  => $file_width,
		INFO_FILEHEIGHT => $file_height
	);

	return;
}

1;
