# Archive Date Header by nitoka.net use strict; use MT::Template::Context; MT::Template::Context->add_container_tag(ArchiveDateHeader => \&ArchiveDateHeader); sub ArchiveDateHeader { my($ctx, $args) = @_; my $this_date = 0; defined(my $at = $ctx->{current_archive_type}) or return $ctx->error('You used an tag ' . 'outside of an archive.'); my $ts = $args->{ts} || $_[0]->{current_timestamp}; $this_date = substr $ts, 0, 6; my ($month, $year) = (localtime(time))[4..5]; $year = sprintf("%04d", $year + 1900); $month = sprintf("%02d", $month + 2); if ($this_date < $year.$month ) { $ctx->{__stash}{archive_date_last_date} = $this_date; my $builder = $ctx->stash('builder'); my $tokens = $ctx->stash('tokens'); defined(my $out = $builder->build($ctx,$tokens)) or return ''; return $out; } } 1;