
# UpdateAuthoredOn.pl
# UpdateAuthoredOn plugin for Movable Type
# by Kevin Shay
# http://www.staggernation.com/mtplugins/UpdateAuthoredOn/
# last modified 8/22/05

use strict;
package MT::Plugin::UpdateAuthoredOn;

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

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

MT->add_callback('bigpapi::template::edit_entry', 9, $plugin, \&_template);

sub _template {
	my ($cb, $app, $template) = @_;
	my $help_label = ($$template =~ m/item_authored_on/)
		? 'item_authored_on' : 'date';
	my $old = qq{<a href="#" onclick="return openManual('entries', '$help_label')" class="help">?</a>};
	$old = quotemeta($old);
	my $new = <<"HTML";
<a href="#" onclick="return openManual('entries', '$help_label')" 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/;
}

1;
