#==========================================================================#
# ■ B.Forum Ver.1.01                                                      #
# ■ プラグインSDK(tree)                                                   #
# □ 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 tree;

use Exporter;
use strict;

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

my (%in %SET);

sub version {
	# バージョン(要変更)
	$version = "Plugin SDK(tree) 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,$tmp5);

	if (!&Bforum::_indexcheck) { &about; }

	if (defined $in{'s'} && $in{'s'} < 1) { &about; }
	$in{'s'} ||= 1;
	$tmp1 = &Bforum::_open('line',"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list") + 1;
	$tmp2 = $tmp1 - ($in{'s'} - 1) * $SET{'TREE_NUMBER'};
	$Bforum::line = 0;
	foreach (reverse(1 .. $SET{'TREE_NUMBER'})) {

		$tree{'number'} = (split(/<0>/,&Bforum::_open(($tmp2 - $_),"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list")))[0] || 1;
		if (0 > ($tmp2 - $_)) { next; }

		$Bforum::line++;

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

		if ($tree{'number'} == 1) {
			$stage[$tree{'number'}] = (split(/<0>/,&Bforum::_open(($tmp2 - $_),"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list")))[1];
		} else {
			$stage[$tree{'number'}] = (split(/<0>/,&Bforum::_open(($tmp2 - $_),"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list")))[1] + 1;
		}

		$tree{'new'} = "";
		if ($tree{'date'} + $SET{'NEW_TIME'} > time) {
			$tree{'new'} = $SET{'NEW_ELEM'};
		}
		&Bforum::_time($tree{'date'});
		if ($tree =~ /{date:(.+?)}/o) { $tree{"date:$1"} = &Bforum::_time($tree{'date'},$1); }
		if ($tree{'delete'}) {
			$tree{'title'} = '(削除)' . $tree{'title'};
			&Bforum::_analysis(\%tree,&Bforum::_open(undef,"$SET{'USER_DIR'}/$in{'id'}/BF.delete$Bforum::browser->{browser}","$SET{'USER_DIR'}/BF.delete$Bforum::browser->{browser}"));
			$tree{'email'} = $SET{'ADDRESS'};
		}
		if ($tree =~ /{title:(.+?)}/o) { $tree{"title:$1"} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=$tree{'no'}",&Bforum::_cut($tree{'full_title'},$1,'...')); }
		$tree{'title'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=$tree{'no'}",$tree{'title'});

		$tmp3 = ('<dl>' x $stage[$tree{'number'}]) . $Bforum::tree . ('</dl>' x $stage[$tree{'number'}]);
		&Bforum::do($tmp3);
		&Bforum::change($tmp3,\%tree);
		$tmp4 .= $tmp3;

	}

	if ((($in{'s'} - 1) * $SET{'TREE_NUMBER'}) >= $tmp1) { &about; }

	if ($in{'s'} < 2) {
		$print{'back'} = $SET{'DISP_TREE_BACK_NL'};
	} else {
		if ($in{'s'} == 1) {
			$print{'back'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=tree",$SET{'DISP_TREE_BACK'});
		} else {
			$print{'back'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=tree&s=" . ($in{'s'} - 1),$SET{'DISP_TREE_BACK'});
		}
	}
	if (($in{'s'} * $SET{'TREE_NUMBER'}) >= $tmp1) {
		$print{'next'} = $SET{'DISP_TREE_NEXT_NL'};
	} else {
		$print{'next'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=tree&s=" . ($in{'s'} + 1),$SET{'DISP_TREE_NEXT'});
	}

	$print{'list'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=list&s=1",$SET{'DISP_LIST'});
	$print{'tree'} = $SET{'DISP_TREE_NL'};

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

	return $tmp5;

}

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

1;

