# LastModified.pl # Movable Type plugin tag for displaying an entry's "last modified" date # by Kevin Shay # http://www.staggernation.com/ # see http://www.staggernation.com/mtplugins/ for documentation, # latest version, and other plugins # version 1.2 # last modified 28 Jan 2003 use strict; use MT::Template::Context; use MT::Util qw( format_ts ); MT::Template::Context->add_tag('LastModified' => sub{&_hdlr_last_modified;}); MT::Template::Context->add_container_tag('IfModified' => sub{&_hdlr_if_modified;}); sub _hdlr_last_modified { my ($ctx, $args) = @_; my $e = $ctx->stash('entry') or return $ctx->_no_entry_error('MTLastModified'); format_ts($args->{'format'}, $e->modified_on, $ctx->stash('blog'), $args->{'language'}); } sub _hdlr_if_modified { my ($ctx, $args) = @_; my $e = $ctx->stash('entry') or return $ctx->_no_entry_error('MTLastModified'); my $display; if (my $leeway = $args->{'leeway'}) { $leeway *= 60; my $diff = ts_to_local($e->modified_on) - ts_to_local($e->created_on); $display = ($diff > $leeway); } else { $display = ($e->modified_on ne $e->created_on); } if ($display) { defined(my $text = $ctx->stash('builder')->build($ctx, $ctx->stash('tokens'))) || return $ctx->error($ctx->errstr); return $text; } return ''; } sub ts_to_local { my ($ts) = @_; require Time::Local; import Time::Local qw(timelocal); my ($y, $m, $d, $h, $min, $s) = unpack('A4A2A2A2A2A2', $ts); $m--; return timelocal($s, $min, $h, $d, $m, $y); } 1;