Changeset 393
- Timestamp:
- 08/26/07 04:45:02 (1 year ago)
- Files:
-
- FiscalYearlyArchives/trunk/FiscalYearlyArchives/fiscal_yearly_archives.pl (modified) (9 diffs)
- FiscalYearlyArchives/trunk/FiscalYearlyArchives/lib/FiscalYearlyArchives/L10N/en_us.pm (modified) (2 diffs)
- FiscalYearlyArchives/trunk/FiscalYearlyArchives/lib/FiscalYearlyArchives/L10N/ja.pm (modified) (1 diff)
- FiscalYearlyArchives/trunk/FiscalYearlyArchives/tmpl (added)
- FiscalYearlyArchives/trunk/FiscalYearlyArchives/tmpl/system_config.tmpl (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
FiscalYearlyArchives/trunk/FiscalYearlyArchives/fiscal_yearly_archives.pl
r392 r393 12 12 13 13 use MT; 14 use MT::Template::Context;15 14 use MT::Entry; 16 use MT::Tag;17 use MT::ObjectTag;18 use MT::Promise qw(force);19 15 20 16 our $VERSION = '0.01'; 21 17 22 18 my $plugin = __PACKAGE__->new({ 19 id => 'fiscal_yearly_archives', 23 20 name => 'FiscalYearlyArchives', 24 21 description => q(<MT_TRANS phrase="A plugin for building Fiscal Yearly Archives">), … … 28 25 version => $VERSION, 29 26 l10n_class => 'FiscalYearlyArchives::L10N', 27 system_config_template => 'system_config.tmpl', 28 settings => new MT::PluginSettings([ 29 ['fiscal_start_month', { Default => 4, Scope => 'system' }], 30 ]), 31 30 32 }); 31 33 MT->add_plugin($plugin); … … 43 45 'FiscalYearly' => 44 46 ArchiveType( 45 name => 'FiscalYearly',46 archive_label => \&archive_label,47 archive_file => \&archive_file,48 archive_title => \&archive_title,49 date_range => \&date_range,50 archive_group_iter => \&archive_group_iter,51 archive_group_entries => \&archive_group_entries,52 archive_entries_count => \&archive_entries_count,53 default_archive_templates => [54 ArchiveFileTemplate(55 label => 'fiscal/yyyy/index.html',56 template => 'fiscal/<$MTArchiveFiscalYear$>/%i',57 default => 158 ),59 ],60 dynamic_template => 'fiscal/<$MTArchiveFiscalYear$>',61 dynamic_support => 1,62 date_based => 1,63 # ???64 template_params => {65 datebased_only_archive => 1,66 datebased_fiscal_yearly_archive => 1,67 module_fiscal_yearly_archives => 1,68 main_template => 1,69 archive_template => 1,70 archive_class => "datebased-fiscal-yearly-archive",71 },72 ),47 name => 'FiscalYearly', 48 archive_label => \&archive_label, 49 archive_file => \&archive_file, 50 archive_title => \&archive_title, 51 date_range => \&date_range, 52 archive_group_iter => \&archive_group_iter, 53 archive_group_entries => \&archive_group_entries, 54 archive_entries_count => \&archive_entries_count, 55 default_archive_templates => [ 56 ArchiveFileTemplate( 57 label => 'fiscal/yyyy/index.html', 58 template => 'fiscal/<$MTArchiveFiscalYear$>/%i', 59 default => 1 60 ), 61 ], 62 dynamic_template => 'fiscal/<$MTArchiveFiscalYear$>', 63 dynamic_support => 1, 64 date_based => 1, 65 # ??? 66 template_params => { 67 datebased_only_archive => 1, 68 datebased_fiscal_yearly_archive => 1, 69 module_fiscal_yearly_archives => 1, 70 main_template => 1, 71 archive_template => 1, 72 archive_class => "datebased-fiscal-yearly-archive", 73 }, 74 ), 73 75 } 74 76 }); 75 77 } 76 78 79 # This is a dirty hack to omit multiple get_config_value() calls for 80 # optimization. Basically, I don't like the way which a plugin loads 81 # and stores its configuration by using MT::PluginSettings. Because I 82 # believe it should be able to get_and_set to the 'registry' in a more 83 # flexible and transparent manner. 84 our $START_MONTH; 85 sub init_request { 86 my $plugin = shift; 87 $plugin->SUPER::init_request(@_); 88 $START_MONTH = $plugin->get_config_value('fiscal_start_month') || 4; 89 } 90 91 sub ts2fiscal { 92 my ($ts) = @_; 93 my ($y, $m) = unpack('A4A2', $ts); 94 $y-- if $m < $START_MONTH; 95 $y; 96 } 97 98 # MTArchiveFiscalYear tag 77 99 sub archive_fiscal_year { 78 100 my ($ctx, %param) = @_; … … 80 102 my $tag = $ctx->stash('tag'); 81 103 return $ctx->error(MT->translate("You used an [_1] tag without a date context set up.", "MT$tag")) 82 unless defined $ts; 83 $ts = start_end_fiscal_year($ts); 84 my ($year) = unpack 'A4', $ts; 85 $year; 104 unless defined $ts; 105 ts2fiscal($ts); 86 106 } 87 107 88 108 sub start_end_fiscal_year { 89 109 my ($ts) = @_; 90 my ($y, $m) = unpack('A4A2', $ts); 91 $y-- if $m < 4; 92 my $start = sprintf "%04d0401000000", $y; 110 my $start_year = ts2fiscal($ts); 111 my $start = sprintf("%04d%02d%02d000000", $start_year, $START_MONTH, 1); 93 112 return $start unless wantarray; 94 my $end = sprintf "%04d0331235959", $y + 1; 113 114 my ($end_year, $end_month, $end_day); 115 if ($START_MONTH == 1) { 116 ($end_year, $end_month, $end_day) = ($start_year, 12, 31); 117 } else { 118 ($end_year, $end_month) = ($start_year + 1, $START_MONTH - 1); 119 $end_day = MT::Util::days_in($end_month, $end_year); 120 } 121 my $end = sprintf("%04d%02d%02d235959", $end_year, $end_month, $end_day); 95 122 ($start, $end); 96 123 } … … 111 138 start_end_fiscal_year($timestamp); 112 139 } else { 113 my $start = start_end_fiscal_year($timestamp); 114 my ($year) = unpack 'A4', $start; 140 my $year = ts2fiscal($timestamp); 115 141 $file = sprintf("04d/index", $year); 116 142 } … … 121 147 my ($ctx, $entry_or_ts) = @_; 122 148 my $ts = ref $entry_or_ts ? $entry_or_ts->authored_on : $entry_or_ts; 123 my $start = start_end_fiscal_year($ts); 124 my ($year) = unpack 'A4', $start; 149 my $year = ts2fiscal($ts); 125 150 my $lang = lc MT->current_language || 'en_us'; 126 151 $lang = 'ja' if lc($lang) eq 'jp'; … … 152 177 my $ts = sprintf("%04d%02d%02d000000", $row[1], $row[2], 1); 153 178 my ($start, $end) = start_end_fiscal_year($ts); 154 my ($year) = unpack 'A4', $start;179 my $year = ts2fiscal($ts); 155 180 if ($year == $prev_year) { 156 181 $count_groups[-1]->{count} += $row[0]; … … 178 203 sub archive_group_entries { 179 204 my ($ctx, %param) = @_; 180 my $ts = sprintf("%04d%02d%02d000000", $param{fiscal_year}, 4, 1)205 my $ts = sprintf("%04d%02d%02d000000", $param{fiscal_year}, $START_MONTH, 1) 181 206 if %param; 182 207 my ($start, $end); … … 218 243 blog_id => $blog->id, 219 244 status => MT::Entry::RELEASE(), 220 ($ts ? (authored_on => [$start, $end]) : ()),221 ($auth ? (author_id => $auth->id) : ()),245 $ts ? (authored_on => [$start, $end]) : (), 246 $auth ? (author_id => $auth->id) : (), 222 247 }, { 223 ($ts ? (range => { authored_on => 1 }) : ()),224 ($cat ? ('join' => ['MT::Placement', 'entry_id', { category_id => $cat->id }]) : ()),248 $ts ? (range => { authored_on => 1 }) : (), 249 $cat ? ('join' => ['MT::Placement', 'entry_id', { category_id => $cat->id }]) : (), 225 250 }); 226 251 $count; FiscalYearlyArchives/trunk/FiscalYearlyArchives/lib/FiscalYearlyArchives/L10N/en_us.pm
r388 r393 1 1 # $Id$ 2 package FiscalYearlyArchives::L10N:: ja;2 package FiscalYearlyArchives::L10N::en_us; 3 3 4 4 use strict; … … 8 8 our %Lexicon = ( 9 9 'FISCAL-YEARLY_ADV' => 'Fiscal Yearly', 10 'FISCAL_MONTH-1' => 'January', 11 'FISCAL_MONTH-2' => 'February', 12 'FISCAL_MONTH-3' => 'March', 13 'FISCAL_MONTH-4' => 'April', 14 'FISCAL_MONTH-5' => 'May', 15 'FISCAL_MONTH-6' => 'June', 16 'FISCAL_MONTH-7' => 'July', 17 'FISCAL_MONTH-8' => 'August', 18 'FISCAL_MONTH-9' => 'September', 19 'FISCAL_MONTH-10' => 'October', 20 'FISCAL_MONTH-11' => 'November', 21 'FISCAL_MONTH-12' => 'December', 10 22 ); 11 23 FiscalYearlyArchives/trunk/FiscalYearlyArchives/lib/FiscalYearlyArchives/L10N/ja.pm
r389 r393 9 9 'FISCAL-YEARLY_ADV' => '年度別', 10 10 'A plugin for building Fiscal Yearly Archives' => '年度別アーカイブを生成するプラグイン', 11 'Fiscal Start Month' => '年度の開始月', 12 'FISCAL_MONTH-1' => '1月', 13 'FISCAL_MONTH-2' => '2月', 14 'FISCAL_MONTH-3' => '3月', 15 'FISCAL_MONTH-4' => '4月', 16 'FISCAL_MONTH-5' => '5月', 17 'FISCAL_MONTH-6' => '6月', 18 'FISCAL_MONTH-7' => '7月', 19 'FISCAL_MONTH-8' => '8月', 20 'FISCAL_MONTH-9' => '9月', 21 'FISCAL_MONTH-10' => '10月', 22 'FISCAL_MONTH-11' => '11月', 23 'FISCAL_MONTH-12' => '12月', 11 24 ); 12 25
