################################################################
# テンプレート設定ファイル
#
#  自由にテンプレートを変更してください。
#  perl が分からないとちょっち厳しいかもしれません。
#  qq(...) というのは、ほぼ "..." と同義ですが、
#  中身の " をエスケープする必要がありません。 "
#
#  %year,%href などのパラメータについては、ドキュメントを参照して下さい。
#
# accesskey:
#
# 1.前(の日) 
# 2.一覧 
# 3.次(の日) 
# 4.予定 
# 5.日付移動(Go) 
# 6.TODO 
# 8.検索 
################################################################

use Template;
use Skelton;
use CGI::QueryString;
use TDS::Tdf::Command;
use TDS::Navigator::Daily;
use TDS::Navigator::Topic;
use TDS::Renderer;
use TDS::Status;
use TDS::Cache;
use TDS::Dynamic;
use TDS::Collection;

$Skelton::OutputJcode = q(sjis);

$TDS::Collection::RecentNum = 1;

$TDS::Cache::EnableCache = 0;

#$TDS::Dynamic;
#$TDS::Status;
#$TDS::Renderer::RECENT = "&#63880;タイトル";
$TDS::Renderer::RECENT = "タイトル";
$TDS::Renderer::SUMMARY = "一覧";
$TDS::Navigator::HrefTemplateDayDynamic = "title.cgi?%year%0m%0d";
$TDS::Navigator::Template = qq(<a href="%href" accesskey="%accesskey">%label</a>);
#$TDS::Renderer::PREV_DAY = "&#63879;[前日]";
#$TDS::Renderer::NEXT_DAY = "&#63881;[翌日]";
#$TDS::Renderer::PREV_TOPIC = "&#63879;[前]";
#$TDS::Renderer::NEXT_TOPIC = "&#63881;[次]";
$TDS::Renderer::PREV_DAY = "[前日]";
$TDS::Renderer::NEXT_DAY = "[翌日]";
$TDS::Renderer::PREV_TOPIC = "[前]";
$TDS::Renderer::NEXT_TOPIC = "[次]";

$TDS::Renderer::TopicNavigatorTemplate = qq(<a href="%href" accesskey="%accesskey">%label</a>);
$TDS::Renderer::TopicNavigatorHrefTemplateDynamic = qq(%path?%y%0m%0d-%new);

$TDS::Dynamic::ContentType = "text/x-hdml; charset=Shift_JIS";
#$TDS::Dynamic::ContentType = "text/plain";

# collection override
# for occasion that there is no content in specified diary
package TDS::Collection;

sub NoContentHook($)
{
    my $self = shift;
    
    my $html;
    my $diary = new TDS::Tdf::Command::DIARY;
    
#    my $date = new DateTime::Date;
#    $date->Set($TDS::Status->year, $TDS::Status->month, $TDS::Status->day_part);
#    my $params = $date->GetParams;
    $diary->{attr} = ['DIARY',
		      $TDS::Status->year, $TDS::Status->month,
		      $TDS::Status->day_part];
    $diary->{attr}->[1] = 2000;
    my $params;
#    print "NoContentHook:", $date->Dump, "\n";
#    print %$params;
    return $diary->AsHTML($params);
#    return qq(<display>no content</display>);
}
    
################################################################
# コマンドテンプレート
package TDS::Tdf::Command::DIARY;
use DateTime::Date;
use Template;
$Template =
    '<choice name="index">%diary_title %date
%topic_titles
%prev %next %recent %summary %title_jump
</choice>
';

$EndTemplate = undef;
#$TitleTemplate = qq(%year/%0m/%0d<br>);
#$TitleEndTemplate = "<hr>";
$DateFormat = "%year/%month/%day(%week)";

sub SetParams($$)
{
    my ($self, $params) = @_;

    my $date = new DateTime::Date;
    $date->Set($TDS::Status->year, $TDS::Status->month, $TDS::Status->day_part);
#    print $params;
    $date->Set($params->{year}, $params->{month}, $params->{day});
#    print "SetParams:", $date->Dump, "\n";
#    $params = $date->GetParams;    # ??? NG
#    $params->{year} = $date->year;
    $params->{date} = Expand($DateFormat, $params);
    
    # title
    $params->{diary_title} = $TDS::IdentInfo::Title;
    # for %topic_title
    {
	my $title;
	my $new = 1;
	my $cmd;
	my $tmp_params = $date->GetParams;
	for $cmd (@{$self->{content}}){    # yet: reverse
	    # yet: secret
	    next if $cmd->{secret} && !$TDS::Status->is_author;
	    $tmp_params->{'new'} = $new;
	    $tmp_params->{'title'} = $cmd->{ext_attrs};
	    $title .= $cmd->AsTitle($tmp_params);
	    $new++;
	}
	$params->{topic_titles} = $title;
    }
    # for navigator
    {

	# recent
	$params->{recent} = qq(<ce task="go" dest="TsDiary.cgi">[recent]\n);

	# jump
	$params->{title_jump} = qq(<ce task="go" dest="TsDiary.cgi?command=title_jump">[title jump]\n);
	
	# prev
	{
	    my $template = qq(<ce task="go" dest="?%y%0m%0d">[prev day]\n);
	    my $prev = $date->Dup;
	    $prev -= "1D";
	    my $tmp_params = $prev->GetParams;
	    $params->{prev} = Expand($template, $tmp_params);
	}
	# next
	{
	    my $template = qq(<ce task="go" dest="?%y%0m%0d">[next day]\n);
	    my $next = $date->Dup;
	    $next += "1D";
	    my $tmp_params = $next->GetParams;
	    $params->{next} = Expand($template, $tmp_params);
	}
    }
}

sub GetTemplate($)
{
    my $self = shift;
    
    if ($TDS::Status->mode eq 'TOPIC'){
	return (undef, undef);
    } else {
	return $self->SUPER::GetTemplate;
    }
}
sub RecurseContent($$)
{
    my ($self, $params) = @_;

    if ($TDS::Status->mode eq 'TOPIC'){
	$self->SUPER::RecurseContent($params);
    } else {
	return undef;
    }
}

package TDS::Tdf::Command::TIMEDIV;
$Template = qq([%ext_attrs]<br>);
$EndTemplate = qq();
$TitleTemplate = qq([%ext_attrs]<br>);
$TitleEndTemplate = qq();
$Mark = "";

package TDS::Tdf::Command::NEW;
#$Template = qq(<A NAME="%anchor">%mark</A>%cat %ext_attrs<br>\n);
#$Template = qq(%mark %cat %ext_attrs<br>\n);
$Template =
    '<DISPLAY NAME="%new" TITLE="%date %new">
%date<br>%new: %ext_attrs %cat<br>
';
#$EndTemplate = "%footnote";
$EndTemplate = "%footnote</DISPLAY>\n";
#$TitleTemplate = qq(<a href="%href">%new</a>:%ext_attrs:);
$TitleTemplate = qq(<ce task="go" dest="?%y%0m%0d-%new" label="Read"><line>%title\n);
#$TitleEndTemplate = q(%subs<br>); #undef;
$TitleEndTemplate = undef;
$HrefTemplateDynamic = qq(?%y%0m%0d-%new);
$Mark = '$%n:';

package TDS::Tdf::Command::SNEW;
$Template = $TDS::Tdf::Command::NEW::Template;
$EndTemplate = $TDS::Tdf::Command::NEW::EndTemplate;
$TitleTemplate = qq(<ce task="go" dest="%new" label="Read"><line>%title\n);

package TDS::Tdf::Command::SUB;
#$Template = qq(<A NAME="%anchor">%mark</A>%cat %ext_attrs<br>);
$Template = qq(%mark %cat %ext_attrs<br>);
$EndTemplate = "";
$Mark = "_";

package TDS::Tdf::Command::P;
$Template = undef;
$EndTemplate = "<br><br>";

package TDS::Tdf::Command::STRIKE;
$Template = q(<STRIKE>);
$EndTemplate = q(</STRIKE>);

package TDS::Tdf::Command::UNDERLINE;
$Template = q(<U>);
$EndTemplate = q(</U>);

package TDS::Tdf::Command::LINK;
#$Template = qq([);
$Template = qq(<a href="%1">);
#$EndTemplate = qq(</a>[<a href="http://www.sjk.co.jp/c/w.exe?y=%1">通ブ経由</a>]);
#$EndTemplate = qq(]);
$EndTemplate = qq(</a>);

# CITEはblockquoteしません。
package TDS::Tdf::Command::CITE;
$Template = "";
$EndTemplate = "";

# CODEはblockquoteしません
package TDS::Tdf::Command::CODE;
$Template = "<pre>";
$EndTemplate = "</pre>";

# TABLEはCompact HTMLでは使えませんが、定義をなくすと破綻しそうなので
# いじりません。アイデア募集。

# DIVは解釈できません。削ります。
package TDS::Tdf::Command::DIV;
$Template = "";
$EndTemplate = "";

# HRは属性を解釈しますので、そのままにします。

# COMMENTはi-modeではソース見られないので削る
package TDS::Tdf::Command::COMMENT;
sub AsHTML($$){undef;}

# list
package TDS::Tdf::Command::UL;
$Template = undef;
$EndTemplate = undef;

package TDS::Tdf::Command::OL;
$Template = undef;
$EndTemplate = undef;

package TDS::Tdf::Command::LI;
$Template = "・";
$EntTemplate = undef;

package TDS::Tdf::Command::DL;
$Template = undef;
$EndTemplate = undef;

package TDS::Tdf::Command::DT;
$Template = "[";
$EndTemplate = "]<br>";

package TDS::Tdf::Command::DD;
$Template = undef;
$EndTemplate = undef;

package TDS::Tdf::Command::IMG;
$Template = qq([IMG:%ext_attrs]);

# FNは、small/spanを解釈しないので削ります。
package TDS::Tdf::Command::FN;
$Template = qq(<a href="\#%0d-%new-F%fn">*%fn</a>);

package TDS::Tdf::Command::FN_Content;
#$Template = qq(\n<a name="%0d-%new-F%fn">*%fn</a>:);
$Template = qq(\n*%fn<a>:);
$EndTemplate = qq(<br>);


# FN_Formatter : 脚注表示部
package TDS::Tdf::Command::FN_Formatter;
$Template = qq(<hr align="left" width="40%">\n);
$EndTemplate = qq(<br>\n);


################
package TDS::Admin::TdfEditor;
$TdfJcode = "sjis";

################
# 一覧テンプレート
package TDS::Summary;
$YearTemplate = "%year<br>";
$YearEndTemplate = "<br>";
$MonthTemplate = qq(*<A HREF="%href">%month</A>: );
$MonthNolinkTemplate = qq(*%month</A>);
$MonthEndTemplate = "<br>";
$PartTemplate = qq([<A HREF="%href">%part_str</A>]);
$PartTemplateNone = qq((%part));
$PartEndTemplate = undef;
$EachPart = "上,中,下";
$Reverse = 1;


################
# do not automatic replacing in hdml
$TDS::Collection::AutoReplace = 0;
1;
