#==========================================================================#
# ■ B.Forum Ver.1.01                                                      #
# ■ プラグインSDK(index)                                                  #
# □ Encode = EUC                                                          #
# □ Hiroaki,Sakuma (sakuma@beetas.org)                                    #
#                                                                          #
# このアプリケーションはオープンソースウェアです.                          #
# 無料で使用することができます.                                            #
# なお, 詳細な使用条件/最新情報については下記サイトをご覧下さい.           #
# http://www.beetas.org/                                                   #
#                                                                          #
# ------------------------------------------------------------------------ #
# Copyright 2001-2002 Hiroaki,Sakuma All Rights Reserved.                  #
# Copyright 2001-2002 BEETAS.org All Rights Reserved.                      #
#                                                                          #
#==========================================================================#
package index;

use Exporter;
use strict;

@ISA = qw(Exporter);
@EXPORT = qw(version status require_min require_max main);

my (%in %SET);

sub version {
	# バージョン(要変更)
	$version = "Plugin SDK(index) 1.01(0055-0058)";
	return $version;
}

sub status {
	return 1;
}

sub require_min {
	# 最低動作バージョン(要変更)
	$require_min = "0055";
	return $require_min;
}

sub require_max {
	# 最高動作バージョン(要変更)
	$require_max = "0058";
	return $require_max;
}

sub main ($$$@) {

	# 変更の必要なし
	my $head = $_[0];
	my $foot = $_[1];
	%in = %{$_[2]};
	splice (@_,0,3);
	%SET = %Bforum::SET;



	# ここから変更

	my ($tmp1,$tmp2,$tmp3,$tmp4);
	my (@tmp5);
	@tmp5 = &Bforum::_open('file',"$SET{'USER_DIR'}/$in{'id'}/index");
	if (!@tmp5) { @tmp5 = (&Bforum::create); }

	if (defined $in{'s'} && $in{'s'} <= 1) { &about; }
	$in{'s'} ||= 1;
	$tmp1 = 0;
	$Bforum::line = 0;
	while (1) {

		$in{'t'} = $tmp5[$tmp1];

		chomp($in{'t'});
		if (!$in{'t'}) { last; }

		if (!-f "$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/1" && !-f "$SET{'USER_DIR'}/$in{'id'}/$in{'t'}.0.bfa")  {
			splice (@tmp5,$tmp1,1);
			next;
		}


		$tmp1 ++;

		if ($tmp1 > ($in{'s'} * $SET{'INDEX_NUMBER'})) {
			last;
		} elsif ($tmp1 > (($in{'s'} - 1) * $SET{'INDEX_NUMBER'})) {

			$Bforum::line++;

			undef %index;

			$index{'number'} = &Bforum::_open('line',"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list") + 1;
			(undef,$index{'thread'},$index{'author'},undef,$index{'date:thread'},undef) = &Bforum::_analysis(undef,&Bforum::_open(undef,"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/1"));
			(undef,undef,undef,undef,$index{'date:last'},undef) = &Bforum::_analysis(undef,&Bforum::_open(undef,"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/$index{'number'}"));

			&Bforum::_analysis(\%index,&Bforum::_open(undef,"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/1"));

			$index{'new'} = "";
			if ($index{'date:last'} + $SET{'NEW_TIME'} > time) { $index{'new'} = $SET{'NEW_ELEM'}; }
			&Bforum::_time($index{'date:thread'});
			&Bforum::_time($index{'date:last'});
			if ($index =~ /{date:thread:(.+?)}/o) { $index{"date:thread:$1"} = &Bforum::_time($index{'date:thread'},$1); }
			if ($index =~ /{date:last:(.+?)}/o) { $index{"date:last:$1"} = &Bforum::_time($index{'date:last'},$1); }
			if ($index =~ /{thread\((.+?)\)}/o) { $index{"thread($1)"} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}",&Bforum::_cut($index{'full_title'},$1,'...')); }
			if ($index =~ /{title\((.+?)\)}/o) { $index{"title($1)"} = &Bforum::_cut($index{'full_title'},$1,'...'); }
			$index{'thread'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}",$index{'thread'});
			$tmp2 = $Bforum::index;
			&Bforum::do($tmp2);
			&Bforum::change($tmp2,\%index);
			$tmp3 .= $tmp2;

		}

	}

	if ((($in{'s'} - 1) * $SET{'INDEX_NUMBER'}) >= (@tmp5)) { &about; }
	if ($in{'s'} < 2) {
		$print{'back'} = $SET{'DISP_INDEX_BACK_NL'};
	} else {
		if ($in{'s'} == '2') {
			$print{'back'} = &Bforum::_link($in{'id'},$SET{'DISP_INDEX_BACK'});
		} else {
			$print{'back'} = &Bforum::_link("id=$in{'id'}&s=" . ($in{'s'} - 1),$SET{'DISP_INDEX_BACK'});
		}
	}
	if (($in{'s'} * $SET{'INDEX_NUMBER'}) >= (@tmp5)) {
		$print{'next'} = $SET{'DISP_INDEX_NEXT_NL'};
	} else {
		$print{'next'} = &Bforum::_link("id=$in{'id'}&s=" . ($in{'s'} + 1),$SET{'DISP_INDEX_NEXT'});
	}


	$tmp4 = $head . $tmp3 . $foot;
	&Bforum::change($tmp4,\%print);
	undef %print;

	&Bforum::_hyperlink($head,'{url:thread}',"$cgi?id=$in{'id'}&i=thread");
	&Bforum::_hyperlink($head,'{url:number}',"$cgi?id=$in{'id'}&i=number");
	&Bforum::_hyperlink($head,'{url:no}',"$cgi?id=$in{'id'}&i=no");
	&Bforum::_hyperlink($head,'{url:last}',"$cgi?$in{'id'}");
	&Bforum::_hyperlink($head,'{url:see}',"$cgi?id=$in{'id'}&i=see");

	return $tmp4;

}

sub about {
	close (NULL);
	&Bforum::about((caller)[2] . '@' . &version);
}

1;

