Changeset 2409
- Timestamp:
- 05/21/08 00:09:27 (6 months ago)
- Files:
-
- branches/release-38/lib/MT/Template/Context.pm (modified) (1 diff)
- branches/release-38/lib/MT/Template/ContextHandlers.pm (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-38/lib/MT/Template/Context.pm
r2282 r2409 547 547 } 548 548 549 sub count_format { 550 my $ctx = shift; 551 my ($count, $args) = @_; 552 my $phrase; 553 $count ||= 0; 554 if ($count == 0) { 555 $phrase = exists $args->{none} 556 ? $args->{none} : (exists $args->{plural} 557 ? $args->{plural} : ''); 558 } elsif ($count == 1) { 559 $phrase = exists $args->{singular} ? $args->{singular} : ''; 560 } elsif ($count > 1) { 561 $phrase = exists $args->{plural} ? $args->{plural} : ''; 562 } 563 return $count if $phrase eq ''; 564 return $phrase unless $phrase =~ m/#/; 565 566 $phrase =~ s/(?<!\\)#/$count/g; 567 $phrase =~ s/\\#/#/g; 568 return $phrase; 569 } 570 549 571 sub _no_author_error { 550 572 my ($ctx) = @_; branches/release-38/lib/MT/Template/ContextHandlers.pm
r2400 r2409 4016 4016 } 4017 4017 4018 sub _count_format {4019 my ($count, $args) = @_;4020 my $phrase;4021 $count ||= 0;4022 if ($count == 0) {4023 $phrase = exists $args->{none}4024 ? $args->{none} : (exists $args->{plural}4025 ? $args->{plural} : '');4026 } elsif ($count == 1) {4027 $phrase = exists $args->{singular} ? $args->{singular} : '';4028 } elsif ($count > 1) {4029 $phrase = exists $args->{plural} ? $args->{plural} : '';4030 }4031 return $count if $phrase eq '';4032 return $phrase unless $phrase =~ m/#/;4033 4034 $phrase =~ s/(?<!\\)#/$count/g;4035 $phrase =~ s/\\#/#/g;4036 return $phrase;4037 }4038 4039 4018 ########################################################################### 4040 4019 … … 4067 4046 } 4068 4047 $count ||= 0; 4069 return _count_format($count, $args);4048 return $ctx->count_format($count, $args); 4070 4049 } 4071 4050 … … 6879 6858 or return $ctx->error($ctx->errstr); 6880 6859 my $count = MT::Category->count(\%terms, \%args); 6881 return _count_format($count, $args);6860 return $ctx->count_format($count, $args); 6882 6861 } 6883 6862 … … 6902 6881 $terms{status} = MT::Entry::RELEASE(); 6903 6882 my $count = $class->count(\%terms, \%args); 6904 return _count_format($count, $args);6883 return $ctx->count_format($count, $args); 6905 6884 } 6906 6885 … … 6924 6903 require MT::Comment; 6925 6904 my $count = MT::Comment->count(\%terms, \%args); 6926 return _count_format($count, $args);6905 return $ctx->count_format($count, $args); 6927 6906 } 6928 6907 … … 6948 6927 my $count = MT::Trackback->count(undef, 6949 6928 { 'join' => MT::TBPing->join_on('tb_id', \%terms, \%args) }); 6950 return _count_format($count, $args);6929 return $ctx->count_format($count, $args); 6951 6930 } 6952 6931 … … 8025 8004 $count = $i; 8026 8005 } 8027 return _count_format($count, $args);8006 return $ctx->count_format($count, $args); 8028 8007 } 8029 8008 … … 9171 9150 or return $ctx->_no_entry_error(); 9172 9151 my $count = $e->comment_count; 9173 return _count_format($count, $args);9152 return $ctx->count_format($count, $args); 9174 9153 } 9175 9154 … … 9188 9167 or return $ctx->_no_entry_error(); 9189 9168 my $count = $e->ping_count; 9190 return _count_format($count, $args);9169 return $ctx->count_format($count, $args); 9191 9170 } 9192 9171 … … 11802 11781 return _hdlr_category_count($ctx); 11803 11782 } elsif (my $count = $ctx->stash('archive_count')) { 11804 return _count_format($count, $args);11783 return $ctx->count_format($count, $args); 11805 11784 } 11806 11785 … … 11808 11787 my @entries = @$e if ref($e) eq 'ARRAY'; 11809 11788 my $count = scalar @entries; 11810 return _count_format($count, $args);11789 return $ctx->count_format($count, $args); 11811 11790 } 11812 11791 … … 12210 12189 $count = scalar $class->count(@args); 12211 12190 } 12212 return _count_format($count, $args);12191 return $ctx->count_format($count, $args); 12213 12192 } 12214 12193 … … 12237 12216 require MT::Comment; 12238 12217 $count = scalar MT::Comment->count(@args); 12239 return _count_format($count, $args);12218 return $ctx->count_format($count, $args); 12240 12219 } 12241 12220 … … 12330 12309 require MT::TBPing; 12331 12310 my $count = MT::TBPing->count( { tb_id => $tb->id, visible => 1 } ); 12332 return _count_format($count || 0, $args);12311 return $ctx->count_format($count || 0, $args); 12333 12312 } 12334 12313 … … 14461 14440 $terms{class} = $args->{type} || '*'; 14462 14441 my $count = MT::Asset->count(\%terms, \%args); 14463 return _count_format($count, $args);14442 return $ctx->count_format($count, $args); 14464 14443 } 14465 14444 … … 15344 15323 return '' unless $object; 15345 15324 my $count = $object->vote_for($key); 15346 return _count_format($count, $args);15325 return $ctx->count_format($count, $args); 15347 15326 } 15348 15327
