#webliberty::App::List.pm (2006/03/13)
#Copyright(C) 2002-2006 Knight, All rights reserved.

package webliberty::App::List;

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

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

	my $self = {
		init   => shift,
		config => shift,
		query  => shift,
		field  => undef,
		index  => undef,
		past   => undef,
		html   => undef
	};
	bless $self, $class;

	my $i;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;

		$self->{field}->{++$i} = $_;
	}
	close(FH);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	while (<FH>) {
		chomp;
		my($date, $no, $id, $stat, $field, $name) = split(/\t/);

		if ($stat and $self->{query}->{no} == $no) {
			$self->{index}->{date} = $date;
			$self->{index}->{no}   = $no;
		} elsif ($stat and $self->{index}->{size} == $self->{query}->{page} * $self->{config}->{page_size}) {
			$self->{index}->{date} = $date;
			$self->{index}->{no}   = $no;
		}

		if ($stat and (!$self->{query}->{field} or $field =~ /^$self->{field}->{$self->{query}->{field}}(<|$)/)) {
			$self->{index}->{size}++;
		}

		if ($field =~ /<>/) {
			$self->{index}->{field}->{$field}++;
			$self->{index}->{field}->{(split(/<>/, $field))[0]}++;
		} else {
			$self->{index}->{field}->{$field}++;
		}

		if ($stat and $date =~ /^(\d\d\d\d)(\d\d)(\d\d)\d\d\d\d$/) {
			$self->{index}->{calendar}->{"$1$2$3"} = 1;
			$self->{past}->{"$1$2"}                = 1;
		}
	}
	close(FH);

	return $self;
}

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

	$self->output_list;

	return;
}

### 記事表示
sub output_list {
	my $self = shift;

	my $start_file;
	if ($self->{query}->{date} =~ /^(\d\d\d\d)(\d\d)/) {
		$start_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}";
	} elsif ($self->{index}->{date} =~ /^(\d\d\d\d)(\d\d)\d\d\d\d\d\d$/) {
		$start_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}";
	}

	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_diary}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_navigation}");
	$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
	);

	$self->{html}->{header} = $skin_ins->get_data('header');

	if (!$self->{query}->{no}) {
		$self->{html}->{logs_head} = $skin_ins->get_data('logs_head');
	}

	$self->_diary_list($skin_ins, $diary_ins, $start_file);

	if (!$self->{query}->{no} and !$self->{query}->{date}) {
		$self->_page_list($skin_ins);
		$self->_navi_list($skin_ins);
	}
	if (!$self->{query}->{no}) {
		$self->{html}->{logs_foot} = $skin_ins->get_data('logs_foot');
	}

	if (!$self->{query}->{no}) {
		$self->{html}->{navigation_head} = $skin_ins->get_data('navigation_head');
		$self->{html}->{navigation_foot} = $skin_ins->get_data('navigation_foot');

		$self->{html}->{information_head} = $skin_ins->get_data('information_head');
		$self->{html}->{information_foot} = $skin_ins->get_data('information_foot');

		$self->_calendar_navi($skin_ins);
		$self->_menu_navi($skin_ins);
		$self->_field_navi($skin_ins);
		$self->_search_navi($skin_ins);
		$self->_record_navi($skin_ins, $diary_ins);
		$self->_comment_navi($skin_ins, $diary_ins);
		$self->_trackback_navi($skin_ins, $diary_ins);
		$self->_past_navi($skin_ins, $diary_ins);
		$self->_link_navi($skin_ins);
		$self->_profile_navi($skin_ins, $diary_ins);
	}

	$self->{html}->{footer} = $skin_ins->get_data('footer');

	if (*STDOUT eq "*main::STDOUT") {
		print $self->header;
	}
	foreach ($skin_ins->get_list) {
		print $self->{html}->{$_};
	}

	return;
}

### カレンダー
sub _calendar_navi {
	my $self     = shift;
	my $skin_ins = shift;

	if (!$self->{config}->{show_calendar}) {
		return;
	}

	my $info_path;
	if ($self->{init}->{script_file} =~ /([^\/\\]*)$/) {
		$info_path = "$self->{config}->{site_url}$1";
	}

	my $this_year;
	my $this_month;
	my $this_day;
	if ($self->{query}->{date} =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
		$this_year  = $1;
		$this_month = $2;
		$this_day   = $3;
	} elsif ($self->{query}->{date} =~ /^(\d\d\d\d)(\d\d)$/) {
		$this_year  = $1;
		$this_month = $2;
		$this_day   = 1;
	} elsif ($self->{query}->{date} =~ /^(\d\d\d\d)$/) {
		$this_year  = $1;
		$this_month = 1;
		$this_day   = 1;
	} else {
		my($sec, $min, $hour, $day, $mon, $year) = localtime(time);
		$this_year  = $year + 1900;
		$this_month = $mon + 1;
		$this_day   = $day;
	}

	my $prev_month = $this_month - 1;
	my $prev_year  = $this_year;
	if ($prev_month < 1) {
		$prev_month = 12;
		$prev_year--;
	}

	my $next_month = $this_month + 1;
	my $next_year  = $this_year;
	if ($next_month > 12) {
		$next_month = 1;
		$next_year++;
	}

	$skin_ins->replace_skin(
		CALENDAR_THIS_YEAR  => int($this_year),
		CALENDAR_THIS_MONTH => int($this_month),
		CALENDAR_THIS_DAY   => int($this_day),
		CALENDAR_PREV_YEAR  => sprintf("%04d", $prev_year),
		CALENDAR_PREV_MONTH => sprintf("%02d", $prev_month),
		CALENDAR_NEXT_YEAR  => sprintf("%04d", $next_year),
		CALENDAR_NEXT_MONTH => sprintf("%02d", $next_month)
	);

	my $day_ins  = new webliberty::Date;
	my $week_key = $day_ins->get_week($this_year, $this_month, 1);
	my $last_day = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$this_month - 1] + ($this_month == 2 and (($this_year % 4 == 0 and $this_year % 100 != 0) or $this_year % 400 == 0));
	$self->{html}->{calendar_head} = $skin_ins->get_data('calendar_head');

	my($show_flag, $holi_flag, $stat, $day, $week_number);

	foreach (1 .. 42) {
		if (($_ - 1) % 7 == $week_key) {
			$show_flag = 1;
		}
		if ($day == $last_day) {
			$show_flag = 0;
		}

		if ($_ % 7 == 1) {
			$self->{html}->{calendar_head} .= $skin_ins->get_data('calendar_weekhead');
		}

		if ($show_flag) {
			$day++;

			my $date = sprintf("%04d%02d%02d", $this_year, $this_month, $day);

			if ($_ % 7 == 1) {
				$stat = 'sunday';
			} elsif ($_ % 7 == 0) {
				$stat = 'satday';
			} else {
				$stat = 'day';
			}
			if ($holi_flag) {
				$stat = 'sunday';
				$holi_flag = 0;
			} else {
				foreach my $holiday (@{$self->{init}->{days_holiday}}) {
					if ((sprintf("%02d", $this_month) . sprintf("%02d", $day)) eq $holiday) {
						if ($_ % 7 == 1) {
							$holi_flag = 1;
						}
						$stat = 'sunday';
						last;
					}
				}
				while (my($month, $week) = each(%{$self->{init}->{weeks_holiday}})) {
					if ($_ % 7 == 2 and sprintf("%02d", $this_month) eq $month and $week_number eq $week) {
						$stat = 'sunday';
						last;
					}
				}
			}

			my($day_start, $day_end);
			if ($self->{index}->{calendar}->{$date}) {
				$day_start = "<a href=\"$info_path?date=$date\">";
				$day_end   = "</a>";
			} else {
				$day_start = '';
				$day_end   = '';
			}

			if ($stat eq 'sunday') {
				$self->{html}->{calendar_head} .= $skin_ins->get_replace_data(
					'calendar_sunday',
					CALENDAR_DAY       => $day,
					CALENDAR_DAY_START => $day_start,
					CALENDAR_DAY_END   => $day_end
				);
			} elsif ($stat eq 'satday') {
				$self->{html}->{calendar_head} .= $skin_ins->get_replace_data(
					'calendar_satday',
					CALENDAR_DAY       => $day,
					CALENDAR_DAY_START => $day_start,
					CALENDAR_DAY_END   => $day_end
				);
			} else {
				$self->{html}->{calendar_head} .= $skin_ins->get_replace_data(
					'calendar_day',
					CALENDAR_DAY       => $day,
					CALENDAR_DAY_START => $day_start,
					CALENDAR_DAY_END   => $day_end
				);
			}
		} else {
			$self->{html}->{calendar_head} .= $skin_ins->get_data('calendar_void');
		}

		if ($_ % 7 == 1 and $show_flag) {
			$week_number++;
		}
		if ($_ % 7 == 0) {
			$self->{html}->{calendar_head} .= $skin_ins->get_data('calendar_weekfoot');
		}
	}

	$self->{html}->{calendar_head} .= $skin_ins->get_data('calendar_foot');

	return;
}

### コンテンツ一覧
sub _menu_navi {
	my $self     = shift;
	my $skin_ins = shift;

	if (!$self->{config}->{show_menu}) {
		return;
	}

	$self->{html}->{menu} = $skin_ins->get_data('menulist_head');

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_menu}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_menu}");
	my @menus = <FH>;
	close(FH);

	foreach (@menus) {
		chomp;
		my($field, $name, $url) = split(/\t/);

		if (!$field) {
			$self->{html}->{menu} .= $skin_ins->get_replace_data(
				'menu',
				MENU_NAME => $name,
				MENU_URL  => $url
			);
		}
	}

	foreach my $menu_list (split(/<>/, $self->{config}->{menu_list})) {
		$self->{html}->{menu} .= $skin_ins->get_replace_data(
			'menulist_field',
			MENU_FIELD => $menu_list
		);

		foreach (@menus) {
			chomp;
			my($field, $name, $url) = split(/\t/);

			if ($menu_list eq $field) {
				$self->{html}->{menu} .= $skin_ins->get_data('menu_head');

				$self->{html}->{menu} .= $skin_ins->get_replace_data(
					'menu',
					MENU_NAME => $name,
					MENU_URL  => $url
				);

				$self->{html}->{menu} .= $skin_ins->get_data('menu_foot');
			}
		}

		$self->{html}->{menu} .= $skin_ins->get_data('menulist_delimiter');
	}

	$self->{html}->{menu} .= $skin_ins->get_data('menulist_foot');

	return;
}

### 分類一覧
sub _field_navi {
	my $self     = shift;
	my $skin_ins = shift;

	if (!$self->{config}->{show_field}) {
		return;
	}

	$self->{html}->{field} = $skin_ins->get_data('field_head');

	my($parent_flag, $child_flag, $i);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;

		if ($_ =~ /^(.+)<>(.+)$/) {
			if (!$child_flag) {
				$self->{html}->{field} .= $skin_ins->get_data('child_head');
				$child_flag = 1;
			}

			$self->{html}->{field} .= $skin_ins->get_replace_data(
				'child',
				FIELD_NAME   => $2,
				FIELD_PARENT => $1,
				FIELD_NO     => ++$i,
				FIELD_SIZE   => $self->{index}->{field}->{$_} || 0
			);
		} else {
			if ($child_flag) {
				$self->{html}->{field} .= $skin_ins->get_data('child_foot');
				$child_flag = 0;
			}
			if ($parent_flag) {
				$self->{html}->{field} .= $skin_ins->get_data('field_delimiter');
			}

			$self->{html}->{field} .= $skin_ins->get_replace_data(
				'field',
				FIELD_NAME => $_,
				FIELD_NO   => ++$i,
				FIELD_SIZE => $self->{index}->{field}->{$_} || 0
			);

			$parent_flag = 1;
		}
	}
	close(FH);

	if ($child_flag) {
		$self->{html}->{field} .= $skin_ins->get_data('child_foot');
	}
	$self->{html}->{field} .= $skin_ins->get_data('field_delimiter');
	$self->{html}->{field} .= $skin_ins->get_data('field_foot');

	return;
}

### 検索フォーム
sub _search_navi {
	my $self     = shift;
	my $skin_ins = shift;

	if (!$self->{config}->{show_search}) {
		return;
	}

	$self->{html}->{search} = $skin_ins->get_data('search');

	return;
}

### 最近の記事一覧
sub _record_navi {
	my $self       = shift;
	my $skin_ins   = shift;
	my $diary_ins  = shift;

	if (!$self->{config}->{list_size}) {
		return;
	}

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}");
	my @dir = sort { $b <=> $a } readdir(DIR);
	closedir(DIR);

	my $flag = 1;
	my $i;

	$self->{html}->{list} = $skin_ins->get_data('list_head');

	foreach my $entry (@dir) {
		if ($entry !~ /^\d\d\d\d\d\d\.$self->{init}->{data_ext}$/) {
			next;
		}
		if ($flag) {
			open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry");
			while (<FH>) {
				chomp;
				my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

				if (!$stat) {
					next;
				}

				$i++;
				if ($i > $self->{config}->{list_size}) {
					$flag = 0;
					last;
				}

				$self->{html}->{list} .= $skin_ins->get_replace_data(
					'list',
					$diary_ins->diary_article($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host)
				);
			}
			close(FH);
		}
	}

	$self->{html}->{list} .= $skin_ins->get_data('list_foot');

	return;
}

### コメント一覧
sub _comment_navi {
	my $self      = shift;
	my $skin_ins  = shift;
	my $diary_ins = shift;

	if (!$self->{config}->{cmtlist_size}) {
		return;
	}

	$self->{html}->{cmtlist} = $skin_ins->get_data('cmtlist_head');

	my($index_size, $i);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}");
	while (<FH>) {
		$index_size++;
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $name, $subj, $host) = split(/\t/);

		$i++;
		if ($i > $self->{config}->{cmtlist_size}) {
			last;
		}

		$self->{html}->{cmtlist} .= $skin_ins->get_replace_data(
			'cmtlist',
			$diary_ins->comment_article($no, $pno, $stat, $date, $name, '', '', $subj, '', '', '', '', '', '', $host)
		);
	}
	close(FH);

	$self->{html}->{cmtlist} .= $skin_ins->get_data('cmtlist_foot');

	return;
}

### トラックバック一覧
sub _trackback_navi {
	my $self      = shift;
	my $skin_ins  = shift;
	my $diary_ins = shift;

	if (!$self->{config}->{tblist_size}) {
		return;
	}

	$self->{html}->{tblist} = $skin_ins->get_data('tblist_head');

	my($index_size, $i);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
	while (<FH>) {
		$index_size++;
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $blog, $title, $url) = split(/\t/);

		$i++;
		if ($i > $self->{config}->{tblist_size}) {
			last;
		}

		$self->{html}->{tblist} .= $skin_ins->get_replace_data(
			'tblist',
			$diary_ins->trackback_article($no, $pno, $stat, $date, $blog, $title, $url, '')
		);
	}
	close(FH);

	$self->{html}->{tblist} .= $skin_ins->get_data('tblist_foot');

	return;
}

### 過去ログ一覧
sub _past_navi {
	my $self       = shift;
	my $skin_ins   = shift;
	my $diary_ins  = shift;

	if (!$self->{config}->{show_past}) {
		return;
	}

	$self->{html}->{past} = $skin_ins->get_data('past_head');

	foreach my $past (sort { $b <=> $a } keys %{$self->{past}}) {
		if ($past =~ /^(\d\d\d\d)(\d\d)$/) {
			my $past_year  = $1;
			my $past_month = $2;

			$self->{html}->{past} .= $skin_ins->get_replace_data(
				'past',
				PAST_YEAR  => $past_year,
				PAST_MONTH => $past_month
			);
		}
	}

	$self->{html}->{past} .= $skin_ins->get_data('past_foot');

	return;
}

### リンク集
sub _link_navi {
	my $self     = shift;
	my $skin_ins = shift;

	if (!$self->{config}->{show_link}) {
		return;
	}

	$self->{html}->{link} = $skin_ins->get_data('linklist_head');

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_link}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_link}");
	my @links = <FH>;
	close(FH);

	foreach (@links) {
		chomp;
		my($field, $name, $url) = split(/\t/);

		if (!$field) {
			$self->{html}->{link} .= $skin_ins->get_replace_data(
				'link',
				LINK_NAME => $name,
				LINK_URL  => $url
			);
		}
	}

	foreach my $link_list (split(/<>/, $self->{config}->{link_list})) {
		$self->{html}->{link} .= $skin_ins->get_replace_data(
			'linklist_field',
			LINK_FIELD => $link_list
		);

		foreach (@links) {
			chomp;
			my($field, $name, $url) = split(/\t/);

			if ($link_list eq $field) {
				$self->{html}->{link} .= $skin_ins->get_data('link_head');

				$self->{html}->{link} .= $skin_ins->get_replace_data(
					'link',
					LINK_NAME => $name,
					LINK_URL  => $url
				);

				$self->{html}->{link} .= $skin_ins->get_data('link_foot');
			}
		}

		$self->{html}->{link} .= $skin_ins->get_data('linklist_delimiter');
	}

	$self->{html}->{link} .= $skin_ins->get_data('linklist_foot');

	return;
}

### プロフィール一覧
sub _profile_navi {
	my $self     = shift;
	my $skin_ins = shift;

	if (!$self->{config}->{show_profile}) {
		return;
	}

	$self->{html}->{profile} = $skin_ins->get_data('profile_head');

	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/);

		$self->{html}->{profile} .= $skin_ins->get_replace_data(
			'profile',
			PROFILE_USER => $user,
			PROFILE_NAME => $name,
			PROFILE_TEXT => $text
		);
	}
	close(FH);

	$self->{html}->{profile} .= $skin_ins->get_data('profile_foot');

	return;
}

### 記事一覧
sub _diary_list {
	my $self       = shift;
	my $skin_ins   = shift;
	my $diary_ins  = shift;
	my $start_file = shift;

	my $no_ins    = new webliberty::String($self->{query}->{no});
	my $date_ins  = new webliberty::String($self->{query}->{date});
	my $field_ins = new webliberty::String($self->{query}->{field});

	$no_ins->create_number;
	$date_ins->create_number;
	$field_ins->create_number;

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}");
	my @dir = sort { $b <=> $a } readdir(DIR);
	closedir(DIR);

	my($dir_flag, $file_flag, $show_flag, $comt_flag, $tb_flag, $i);

	$self->{html}->{diary} = $skin_ins->get_data('diary_head');

	foreach my $entry (@dir) {
		if ($entry !~ /^\d\d\d\d\d\d\.$self->{init}->{data_ext}$/) {
			next;
		}
		if ($start_file eq "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry") {
			$dir_flag = 1;
		}
		if ($dir_flag) {
			open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry");
			while (<FH>) {
				chomp;
				my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

				if ($date_ins->get_string or $no == $self->{index}->{no}) {
					$file_flag = 1;
				}
				if ($file_flag and $stat) {
					if ($no_ins->get_string and $no != $no_ins->get_string) {
						next;
					}
					if ($date_ins->get_string and $date !~ /^$self->{query}->{date}/) {
						next;
					}
					if ($field_ins->get_string and $field !~ /^$self->{field}->{$self->{query}->{field}}(<|$)/) {
						next;
					}
					if (!$field_ins->get_string or $field =~ /^$self->{field}->{$self->{query}->{field}}(<|$)/) {
						$i++;
					}

					$self->{html}->{diary} .= $skin_ins->get_replace_data(
						'diary',
						$diary_ins->diary_article($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host)
					);

					$show_flag = 1;

					if (!$date_ins->get_string and ($no_ins->get_string or $i >= $self->{config}->{page_size})) {
						if ($no_ins->get_string) {
							$comt_flag = $comt;
							$tb_flag   = $tb;
						}

						$dir_flag  = 0;
						$file_flag = 0;

						last;
					}
				}
			}
			close(FH);
		}
	}
	if (!$show_flag) {
		$self->{html}->{diary} .= $skin_ins->get_replace_data(
			'diary',
			$diary_ins->diary_article(0, '', 1, 1, 0, 0, '未分類', '', '', 'No Data', '該当する記事はありません。', '', '', '', '')
		);
	}

	if ($show_flag and $no_ins->get_string and $tb_flag) {
		$self->{html}->{trackback_head} = $skin_ins->get_replace_data(
			'trackback_head',
			ARTICLE_NO => $no_ins->get_string
		);

		if (-e "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}" . $no_ins->get_string . "\.$self->{init}->{data_ext}") {
			open(FH, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{query}->{no}\.$self->{init}->{data_ext}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{query}->{no}\.$self->{init}->{data_ext}");
			while (<FH>) {
				chomp;
				my($no, $pno, $stat, $date, $blog, $title, $url, $excerpt) = split(/\t/);

				$self->{html}->{trackback} .= $skin_ins->get_replace_data(
					'trackback',
					$diary_ins->trackback_article($no, $pno, $stat, $date, $blog, $title, $url, $excerpt)
				);
			}
			close(FH);
		}

		$self->{html}->{trackback_foot} = $skin_ins->get_data('trackback_foot');
	}

	if ($show_flag and $no_ins->get_string and $comt_flag) {
		$self->{html}->{comment} = $skin_ins->get_replace_data(
			'comment_head',
			ARTICLE_NO => $no_ins->get_string
		);

		if (-e "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}" . $no_ins->get_string . "\.$self->{init}->{data_ext}") {
			open(FH, "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{query}->{no}\.$self->{init}->{data_ext}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{query}->{no}\.$self->{init}->{data_ext}");
			while (<FH>) {
				chomp;
				my($no, $pno, $stat, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $rank, $pwd, $host) = split(/\t/);

				$self->{html}->{comment} .= $skin_ins->get_replace_data(
					'comment',
					$diary_ins->comment_article($no, $pno, $stat, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $rank, $pwd, $host)
				);
			}
			close(FH);
		}

		$self->{html}->{comment} .= $skin_ins->get_data('comment_foot');
	}

	$self->{html}->{diary} .= $skin_ins->get_data('diary_foot');

	return;
}

### ページ移動リンク一覧
sub _page_list {
	my $self     = shift;
	my $skin_ins = shift;

	my $field_ins = new webliberty::String($self->{query}->{field});
	my $page_ins  = new webliberty::String($self->{query}->{page});

	$field_ins->create_number;
	$page_ins->create_number;

	my $info_path;
	if ($self->{init}->{script_file} =~ /([^\/\\]*)$/) {
		$info_path = "$self->{config}->{site_url}$1";
	}

	my($field_link, $prev_start, $prev_end, $next_start, $next_end);

	if ($field_ins->get_string) {
		$field_link = '&amp;field=' . $field_ins->get_string;
	}

	if ($page_ins->get_string > 0) {
		$prev_start = "<a href=\"$info_path?page=" . ($page_ins->get_string - 1) . "$field_link\">";
		$prev_end   = "</a>";
	}
	if (int(($self->{index}->{size} - 1) / $self->{config}->{page_size}) > $page_ins->get_string) {
		$next_start = "<a href=\"$info_path?page=" . ($page_ins->get_string + 1) . "$field_link\">";
		$next_end   = "</a>";
	}

	$self->{html}->{page} = $skin_ins->get_replace_data(
		'page',
		PAGE_PREV_START => $prev_start,
		PAGE_PREV_END   => $prev_end,
		PAGE_NEXT_START => $next_start,
		PAGE_NEXT_END   => $next_end
	);

	return;
}

### ナビゲーション一覧
sub _navi_list {
	my $self     = shift;
	my $skin_ins = shift;

	my $field_ins = new webliberty::String($self->{query}->{field});
	$field_ins->create_number;

	my $info_path;
	if ($self->{init}->{script_file} =~ /([^\/\\]*)$/) {
		$info_path = "$self->{config}->{site_url}$1";
	}

	$self->{html}->{navi} = $skin_ins->get_data('navi_head');

	foreach (0 .. int(($self->{index}->{size} - 1) / $self->{config}->{page_size})) {
		my($field_link, $prev_start, $prev_end);

		if ($field_ins->get_string) {
			$field_link = '&amp;field=' . $field_ins->get_string;
		}

		if ($_ != $field_ins->get_string) {
			$prev_start = "<a href=\"$info_path?page=$_$field_link\">";
			$prev_end   = "</a>";
		}
		$self->{html}->{navi} .= $skin_ins->get_replace_data(
			'navi',
			NAVI_NO    => $_ + 1,
			NAVI_START => $prev_start,
			NAVI_END   => $prev_end,
		);
	}

	$self->{html}->{navi} .= $skin_ins->get_data('navi_foot');

	return;
}

1;
