
# UpdateEntryDate.pl
# UpdateEntryDate plugin for Movable Type
# by Kevin Shay
# http://www.staggernation.com/mtplugins/UpdateEntryDate/

use strict;
package MT::Plugin::UpdateEntryDate;

use vars qw( $VERSION );
$VERSION = '1.1';

require MT::Plugin;
require MT;
my $plugin = MT::Plugin->new({
	name => "UpdateEntryDate",
	description => 'Update the Entry Date timestamp of an entry by clicking a button.',
	doc_link => 'http://www.staggernation.com/mtplugins/UpdateEntryDate/',
	author_name => 'Kevin Shay',
	author_link => 'http://www.staggernation.com/',
	version => $VERSION
});
MT->add_plugin($plugin);

MT->add_callback('MT::App::CMS::AppTemplateSource.edit_entry', 9, $plugin, \&_template);

sub _template {
	my ($cb, $app, $template) = @_;
	my $old = qq{<a href="#" onclick="return openManual('entries', 'date')" class="help">?</a>};
	$old = quotemeta($old);
	my $new = <<"HTML";
<a href="#" onclick="return openManual('entries', 'date')" class="help">?</a>
<script type="text/javascript">
function zeropad(num) {
	return (num < 10) ? '0' + num : num;
}
function update_authored_on() {
	var now = new Date();
	var y = now.getFullYear();
	var m = zeropad(now.getMonth() + 1);
	var d = zeropad(now.getDate());
	var h = zeropad(now.getHours());
	var min = zeropad(now.getMinutes());
	var s = zeropad(now.getSeconds());
	document.entry_form.created_on_manual.value = y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s;
}
</script>
<input type="button" onclick="update_authored_on();" value="<MT_TRANS phrase="Update">">
HTML
	$$template =~ s/$old/$new/g;
}

1;
