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

package webliberty::App::Profile;

use strict;
use base qw(webliberty::Basis);
use webliberty::String;
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_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_profile}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

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

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

	my(%name, %text);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_profile}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_profile}");
	while (<FH>) {
		chomp;
		my($user, $name, $text) = split(/\t/);

		if (!$name) {
			$name = 'admin';
		}

		$name{$user} = $name;
		$text{$user} = $text;
	}
	close(FH);

	my $user_ins = new webliberty::String('admin');
	my $name_ins = new webliberty::String($name{'admin'});
	my $text_ins = new webliberty::String($text{'admin'});

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_replace_data(
		'contents',
		PROFILE_USER => $user_ins->create_line,
		PROFILE_NAME => $name_ins->create_line,
		PROFILE_TEXT => $text_ins->create_text
	);
	print $skin_ins->get_data('footer');

	return;
}

1;
