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

use Exporter;
use strict;

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

my (%in %SET);

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

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

	if (!$view{'no'}) { &about; }

	$view{'number'} = $Bforum::num + 1;

	$view{'new'} = "";
	if ($view{'date'} + $SET{'NEW_TIME'} > time) {
		$view{'new'} = $SET{'NEW_ELEM'};
	}
	&Bforum::_time($view{'date'});
	if ($view =~ /{date:(.+?)}/o) { $view{"date:$1"} = &Bforum::_time($view{'date'},$1); }

	if ($view{'delete'} || !&Bforum::_listcheck($in{'v'})) {
		$view{'title'} = '(削除)' . $view{'title'};
		&Bforum::_analysis(\%view,&Bforum::_open(undef,"$SET{'USER_DIR'}/$in{'id'}/BF.delete$Bforum::browser->{browser}","$SET{'USER_DIR'}/BF.delete$Bforum::browser->{browser}"));
		$view{'email'} = $SET{'ADDRESS'};
	}

	if ($view =~ /{title\((.+?)\)}/o) { $view{"title($1)"} = &Bforum::_cut($view{'full_title'},$1,'...'); }

	&Bforum::tag($view{'message'});

	&Bforum::_autolink($view{'message'});

	$view{'message'} =~ s/(^|\n)(\s*(&gt;[(&gt;)(\s*)]*)[^\n]*)/$1<span style="color:#990000">$2<\/span>/go;
	$view{'message'} =~ s/(^|\n)(\s*(#[#(\s*)]*)[^\n]*)/$1<span style="color:#009900">$2<\/span>/go;

	$tmp2 = int(($in{'v'} - 1) / $SET{'LIST_NUMBER'}) + 1;

	if ($in{'v'} eq '1') {
		$tmp3 = 1;
		$in{'s'} ||= 1;
	} else {
		$tmp1 = &Bforum::_open('line',"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list");
		foreach (0 .. $tmp1) {
			if ($in{'v'} eq (split(/<0>/,&Bforum::_open($_,"$SET{'USER_DIR'}/$in{'id'}/$in{'t'}/list")))[0]) {
				$tmp3 = int(($tmp1 - $_) / $SET{'TREE_NUMBER'}) + 1;
				last;
			}
		}
	}

	$tmp4 = $Bforum::view;

	&Bforum::do($tmp4);
	&Bforum::change($tmp4,\%view);

	if ($in{'v'} <= 1) {
		$print{'back'} = $SET{'DISP_BACK_NL'};
	} else {
		$tmp5 = $in{'v'} - 1;
		$print{'back'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=$tmp5",$SET{'DISP_BACK'});
	}

	if ($in{'v'} >= $view{'number'}) {
		$print{'next'} = $SET{'DISP_NEXT_NL'};
	} else {
		$tmp5 = $in{'v'} + 1;
		$print{'next'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=$tmp5",$SET{'DISP_NEXT'});
	}

	if (!$_[0] && $view{'number'} ne '1') {
		$print{'tree'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=tree&s=$tmp3",$SET{'DISP_TREE'});
	} else {
		$print{'tree'} = $SET{'DISP_TREE_NL'};
	}
	$print{'list:url'} = "id=$in{'id'}&t=$in{'t'}&v=list&s=$tmp2";
	$print{'tree:url'} = "id=$in{'id'}&t=$in{'t'}&v=tree&s=$tmp3";
	$print{'list'} = &Bforum::_link("id=$in{'id'}&t=$in{'t'}&v=list&s=$tmp2",$SET{'DISP_LIST'});

	&Bforum::change($tmp4,\%print);
	undef %print;

	return $tmp4;

}

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

1;

