Changeset 2409

Show
Ignore:
Timestamp:
05/21/08 00:09:27 (6 months ago)
Author:
bchoate
Message:

Made count_format a method of context class for easier access.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-38/lib/MT/Template/Context.pm

    r2282 r2409  
    547547} 
    548548 
     549sub 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 
    549571sub _no_author_error { 
    550572    my ($ctx) = @_; 
  • branches/release-38/lib/MT/Template/ContextHandlers.pm

    r2400 r2409  
    40164016} 
    40174017 
    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  
    40394018########################################################################### 
    40404019 
     
    40674046    } 
    40684047    $count ||= 0; 
    4069     return _count_format($count, $args); 
     4048    return $ctx->count_format($count, $args); 
    40704049} 
    40714050 
     
    68796858        or return $ctx->error($ctx->errstr); 
    68806859    my $count = MT::Category->count(\%terms, \%args); 
    6881     return _count_format($count, $args); 
     6860    return $ctx->count_format($count, $args); 
    68826861} 
    68836862 
     
    69026881    $terms{status} = MT::Entry::RELEASE(); 
    69036882    my $count = $class->count(\%terms, \%args); 
    6904     return _count_format($count, $args); 
     6883    return $ctx->count_format($count, $args); 
    69056884} 
    69066885 
     
    69246903    require MT::Comment; 
    69256904    my $count = MT::Comment->count(\%terms, \%args); 
    6926     return _count_format($count, $args); 
     6905    return $ctx->count_format($count, $args); 
    69276906} 
    69286907 
     
    69486927    my $count = MT::Trackback->count(undef, 
    69496928        { 'join' => MT::TBPing->join_on('tb_id', \%terms, \%args) }); 
    6950     return _count_format($count, $args); 
     6929    return $ctx->count_format($count, $args); 
    69516930} 
    69526931 
     
    80258004        $count = $i; 
    80268005    } 
    8027     return _count_format($count, $args); 
     8006    return $ctx->count_format($count, $args); 
    80288007 
    80298008 
     
    91719150        or return $ctx->_no_entry_error(); 
    91729151    my $count = $e->comment_count; 
    9173     return _count_format($count, $args); 
     9152    return $ctx->count_format($count, $args); 
    91749153} 
    91759154 
     
    91889167        or return $ctx->_no_entry_error(); 
    91899168    my $count = $e->ping_count; 
    9190     return _count_format($count, $args); 
     9169    return $ctx->count_format($count, $args); 
    91919170} 
    91929171 
     
    1180211781        return _hdlr_category_count($ctx); 
    1180311782    } elsif (my $count = $ctx->stash('archive_count')) { 
    11804         return _count_format($count, $args); 
     11783        return $ctx->count_format($count, $args); 
    1180511784    } 
    1180611785 
     
    1180811787    my @entries = @$e if ref($e) eq 'ARRAY'; 
    1180911788    my $count = scalar @entries; 
    11810     return _count_format($count, $args); 
     11789    return $ctx->count_format($count, $args); 
    1181111790} 
    1181211791 
     
    1221012189        $count = scalar $class->count(@args); 
    1221112190    } 
    12212     return _count_format($count, $args); 
     12191    return $ctx->count_format($count, $args); 
    1221312192} 
    1221412193 
     
    1223712216    require MT::Comment; 
    1223812217    $count = scalar MT::Comment->count(@args); 
    12239     return _count_format($count, $args); 
     12218    return $ctx->count_format($count, $args); 
    1224012219} 
    1224112220 
     
    1233012309    require MT::TBPing; 
    1233112310    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); 
    1233312312} 
    1233412313 
     
    1446114440    $terms{class} = $args->{type} || '*'; 
    1446214441    my $count = MT::Asset->count(\%terms, \%args); 
    14463     return _count_format($count, $args); 
     14442    return $ctx->count_format($count, $args); 
    1446414443} 
    1446514444 
     
    1534415323    return '' unless $object; 
    1534515324    my $count = $object->vote_for($key); 
    15346     return _count_format($count, $args); 
     15325    return $ctx->count_format($count, $args); 
    1534715326} 
    1534815327