Changeset 1956

Show
Ignore:
Timestamp:
04/17/08 21:48:11 (22 months ago)
Author:
bchoate
Message:

Added support for phrases on count tags. BugId:79359

Location:
branches/release-35
Files:
22 modified

Legend:

Unmodified
Added
Removed
  • branches/release-35/lib/MT/Template/ContextHandlers.pm

    r1953 r1956  
    21432143} 
    21442144 
     2145sub _count_format { 
     2146    my ($count, $args) = @_; 
     2147    my $phrase; 
     2148    $count ||= 0; 
     2149    if ($count == 0) { 
     2150        $phrase = exists $args->{none} 
     2151            ? $args->{none}   : (exists $args->{plural} 
     2152            ? $args->{plural} : ''); 
     2153    } elsif ($count == 1) { 
     2154        $phrase = exists $args->{singular} ? $args->{singular} : ''; 
     2155    } elsif ($count > 1) { 
     2156        $phrase = exists $args->{plural} ? $args->{plural} : ''; 
     2157    } 
     2158    return $count if $phrase eq ''; 
     2159    return $phrase unless $phrase =~ m/#/; 
     2160 
     2161    $phrase =~ s/(?<!\\)#/$count/g; 
     2162    $phrase =~ s/\\#/#/g; 
     2163    return $phrase; 
     2164} 
     2165 
    21452166sub _hdlr_tag_count { 
    21462167    my ($ctx, $args, $cond) = @_; 
     
    21482169    my $tag = $ctx->stash('Tag'); 
    21492170    my $blog_id = $ctx->stash('blog_id'); 
    2150     return 0 unless $tag; 
    2151     unless (defined $count) { 
    2152         $count = MT::Entry->tagged_count($tag->id, { status => MT::Entry::RELEASE(), 
    2153                                                      blog_id => $blog_id }); 
    2154     } 
    2155     $count || 0; 
     2171    if ($tag) { 
     2172        unless (defined $count) { 
     2173            $count = MT::Entry->tagged_count($tag->id, { 
     2174                status => MT::Entry::RELEASE(), 
     2175                blog_id => $blog_id 
     2176            }); 
     2177        } 
     2178    } 
     2179    $count ||= 0; 
     2180    return _count_format($count, $args); 
    21562181} 
    21572182 
     
    35573582    $ctx->set_blog_load_context($args, \%terms, \%args) 
    35583583        or return $ctx->error($ctx->errstr); 
    3559     MT::Category->count(\%terms, \%args); 
     3584    my $count = MT::Category->count(\%terms, \%args); 
     3585    return _count_format($count, $args); 
    35603586} 
    35613587                 
     
    35683594        or return $ctx->error($ctx->errstr); 
    35693595    $terms{status} = MT::Entry::RELEASE(); 
    3570     $class->count(\%terms, \%args); 
     3596    my $count = $class->count(\%terms, \%args); 
     3597    return _count_format($count, $args); 
    35713598} 
    35723599 
     
    35783605    $terms{visible} = 1; 
    35793606    require MT::Comment; 
    3580     MT::Comment->count(\%terms, \%args); 
     3607    my $count = MT::Comment->count(\%terms, \%args); 
     3608    return _count_format($count, $args); 
    35813609} 
    35823610 
     
    35893617    require MT::Trackback; 
    35903618    require MT::TBPing; 
    3591     MT::Trackback->count(undef, 
     3619    my $count = MT::Trackback->count(undef, 
    35923620        { 'join' => MT::TBPing->join_on('tb_id', \%terms, \%args) }); 
     3621    return _count_format($count, $args); 
    35933622} 
    35943623 
     
    42604289    my $e = $ctx->stash('entries');    
    42614290 
    4262     unless ($e) { 
     4291    my $count; 
     4292    if ($e) { 
     4293        $count = scalar @$e; 
     4294    } else { 
    42634295        my $class_type = $args->{class_type} || 'entry'; 
    42644296        my $class = MT->model($class_type); 
     
    42964328            $i++; 
    42974329        } 
    4298         return $i; 
    4299     } 
    4300  
    4301     return 0 unless $e; 
    4302     scalar @$e; 
     4330        $count = $i; 
     4331    } 
     4332    return _count_format($count, $args); 
    43034333 
    43044334 
     
    48324862 
    48334863sub _hdlr_entry_comments { 
    4834     my $e = $_[0]->stash('entry') 
    4835         or return $_[0]->_no_entry_error($_[0]->stash('tag')); 
    4836     $e->comment_count; 
    4837 } 
     4864    my ($ctx, $args, $cond) = @_; 
     4865    my $e = $ctx->stash('entry') 
     4866        or return $ctx->_no_entry_error($ctx->stash('tag')); 
     4867    my $count = $e->comment_count; 
     4868    return _count_format($count, $args); 
     4869} 
     4870 
    48384871sub _hdlr_entry_ping_count { 
    4839     my $e = $_[0]->stash('entry') 
    4840         or return $_[0]->_no_entry_error($_[0]->stash('tag')); 
    4841     $e->ping_count; 
    4842 } 
     4872    my ($ctx, $args, $cond) = @_; 
     4873    my $e = $ctx->stash('entry') 
     4874        or return $ctx->_no_entry_error($ctx->stash('tag')); 
     4875    my $count = $e->ping_count; 
     4876    return _count_format($count, $args); 
     4877} 
     4878 
    48434879sub _hdlr_entry_previous { 
    48444880    _hdlr_entry_nextprev('previous', @_); 
     
    53385374    $name = '' unless defined $name; 
    53395375    $name ||= $_[1]{default_name}; 
    5340     $name ||= ''; 
     5376    $name ||= MT->translate("Anonymous"); 
    53415377    my $show_email = $args->{show_email} ? 1 : 0; 
    53425378    my $show_url = 1 unless exists $args->{show_url} && !$args->{show_url}; 
     
    54875523        or return $_[0]->_no_comment_error('MTCommentParentID'); 
    54885524    my $id = $c->parent_id || 0; 
    5489     $args && $args->{pad} ? (sprintf "%06d", $id) : $id; 
     5525    $args && $args->{pad} ? (sprintf "%06d", $id) : ($id ? $id : ''); 
    54905526} 
    54915527 
     
    61616197 
    61626198sub _hdlr_archive_count { 
    6163     my $ctx = $_[0]; 
     6199    my ($ctx, $args, $cond) = @_; 
    61646200    my $at = $ctx->{current_archive_type} || $ctx->{archive_type}; 
    61656201    my $archiver = MT->publisher->archiver($at); 
     
    61676203        return _hdlr_category_count($ctx); 
    61686204    } elsif (my $count = $ctx->stash('archive_count')) { 
    6169         return $count; 
    6170     } else { 
    6171         my $e = $_[0]->stash('entries'); 
    6172         my @entries = @$e if ref($e) eq 'ARRAY'; 
    6173         return scalar @entries; 
    6174     } 
     6205        return _count_format($count, $args); 
     6206    } 
     6207 
     6208    my $e = $_[0]->stash('entries'); 
     6209    my @entries = @$e if ref($e) eq 'ARRAY'; 
     6210    my $count = scalar @entries; 
     6211    return _count_format($count, $args); 
    61756212} 
    61766213 
     
    64336470 
    64346471sub _hdlr_category_count { 
    6435     my($ctx) = @_; 
     6472    my ($ctx, $args, $cond) = @_; 
    64366473    my $cat = ($ctx->stash('category') || $_[0]->stash('archive_category')) 
    64376474        or return $_[0]->error(MT->translate( 
     
    64496486        $count = scalar $class->count(@args); 
    64506487    } 
    6451     $count; 
     6488    return _count_format($count, $args); 
    64526489} 
    64536490 
    64546491sub _hdlr_category_comment_count { 
    6455     my($ctx) = @_; 
     6492    my ($ctx, $args, $cond) = @_; 
    64566493    my $cat = ($ctx->stash('category') || $_[0]->stash('archive_category')) 
    64576494        or return $_[0]->error(MT->translate( 
     
    64706507    require MT::Comment; 
    64716508    $count = scalar MT::Comment->count(@args); 
    6472     $count; 
     6509    return _count_format($count, $args); 
    64736510} 
    64746511 
     
    65416578    require MT::TBPing; 
    65426579    my $count = MT::TBPing->count( { tb_id => $tb->id, visible => 1 } ); 
    6543     $count || 0; 
     6580    return _count_format($count || 0, $args); 
    65446581} 
    65456582 
     
    81538190    $terms{blog_id} = $ctx->stash('blog_id') if $ctx->stash('blog_id'); 
    81548191    $terms{class} = $args->{type} || '*'; 
    8155     MT::Asset->count(\%terms, \%args); 
     8192    my $count = MT::Asset->count(\%terms, \%args); 
     8193    return _count_format($count, $args); 
    81568194} 
    81578195  
     
    83488386    require MT::Page; 
    83498387    $args->{class_type} = MT::Page->properties->{class_type}; 
    8350     &_hdlr_blog_entry_count(@_); 
     8388    return _hdlr_blog_entry_count(@_); 
    83518389} 
    83528390 
     
    84178455    require MT::Folder; 
    84188456    $args->{class_type} = MT::Folder->properties->{class_type}; 
    8419     _hdlr_top_level_parent($ctx, $args, $cond); 
     8457    return _hdlr_top_level_parent($ctx, $args, $cond); 
    84208458} 
    84218459 
    84228460sub _hdlr_folder_basename { 
    84238461    return $_ unless &_check_folder(@_); 
    8424     &_hdlr_category_basename(@_); 
     8462    return _hdlr_category_basename(@_); 
    84258463} 
    84268464 
    84278465sub _hdlr_folder_description { 
    84288466    return $_ unless &_check_folder(@_); 
    8429     &_hdlr_category_desc(@_); 
     8467    return _hdlr_category_desc(@_); 
    84308468} 
    84318469 
    84328470sub _hdlr_folder_id { 
    84338471    return $_ unless &_check_folder(@_); 
    8434     &_hdlr_category_id(@_); 
     8472    return _hdlr_category_id(@_); 
    84358473} 
    84368474 
    84378475sub _hdlr_folder_label { 
    84388476    return $_ unless &_check_folder(@_); 
    8439     &_hdlr_category_label(@_); 
     8477    return _hdlr_category_label(@_); 
    84408478} 
    84418479 
    84428480sub _hdlr_folder_count { 
    84438481    return $_ unless &_check_folder(@_); 
    8444     &_hdlr_category_count(@_); 
     8482    return _hdlr_category_count(@_); 
    84458483} 
    84468484 
    84478485sub _hdlr_folder_path { 
    84488486    return $_ unless &_check_folder(@_); 
    8449     &_hdlr_sub_category_path(@_); 
     8487    return _hdlr_sub_category_path(@_); 
    84508488} 
    84518489 
    84528490sub _hdlr_if_folder { 
    84538491    return $_ unless &_check_folder(@_); 
    8454     &_hdlr_if_category(@_); 
     8492    return _hdlr_if_category(@_); 
    84558493} 
    84568494 
     
    86148652} 
    86158653 
     8654# FIXME: should this routine return an empty string? 
    86168655sub _object_score_count { 
    86178656    my ($stash_key, $ctx, $args, $cond) = @_; 
     
    86208659    my $object = $ctx->stash($stash_key); 
    86218660    return '' unless $object; 
    8622     return $object->vote_for($key); 
     8661    my $count = $object->vote_for($key); 
     8662    return _count_format($count, $args); 
    86238663} 
    86248664 
  • branches/release-35/php/lib/MTViewer.php

    r1876 r1956  
    456456            return null; 
    457457    } 
     458 
     459    function count_format($count, $args) { 
     460        $phrase = ''; 
     461        if ($count == 0) { 
     462            $phrase = array_key_exists('none', $args) ? $args['none'] : 
     463                (array_key_exists('plural', $args) ? $args['plural'] : ''); 
     464        } elseif ($count == 1) { 
     465            $phrase = array_key_exists('singular', $args) ? $args['singular'] : ''; 
     466        } elseif ($count > 1) { 
     467            $phrase = array_key_exists('plural', $args) ? $args['plural'] : ''; 
     468        } 
     469        if ($phrase == '') 
     470            return $count; 
     471 
     472        // \# of entries: #  --> # of entries: 10 
     473        $phrase = preg_replace('/(?<!\\\\)#/', $count, $phrase); 
     474        $phrase = preg_replace('/\\\\#/', '#', $phrase); 
     475 
     476        return $phrase; 
     477    } 
    458478} 
    459 ?> 
  • branches/release-35/php/lib/function.mtarchivecount.php

    r1766 r1956  
    1414        $archiver = $_archivers[$at]; 
    1515    } 
     16    $count = 0; 
    1617    if ((!isset($archiver) && $ctx->stash('inside_mt_categories')) || 
    1718        ($ctx->stash('inside_mt_categories') && !$archiver->is_date_based())) { 
    1819        return $ctx->tag('MTCategoryCount', $args); 
    1920    } elseif ($count = $ctx->stash('archive_count')) { 
    20         return $count; 
     21        # $count is set 
    2122    } elseif ($entries = $ctx->stash('entries')) { 
    22         return count($entries); 
     23        $count = count($entries); 
    2324    } else { 
    2425        $eargs = array(); 
     
    3839            $eargs['lastn'] = -1; 
    3940            $entries =& $ctx->mt->db->fetch_entries($eargs); 
    40             return count($entries); 
     41            $count = count($entries); 
    4142        } 
    4243    } 
    43     return 0; 
     44    $ctx->count_format($count, $args); 
    4445} 
    45 ?> 
  • branches/release-35/php/lib/function.mtassetcount.php

    r1174 r1956  
    99    $args['blog_id'] = $ctx->stash('blog_id'); 
    1010    $count = $ctx->mt->db->asset_count($args); 
    11     return $count; 
     11    return $ctx->count_format($count, $args); 
    1212} 
  • branches/release-35/php/lib/function.mtassetscorecount.php

    r1174 r1956  
    99 
    1010function smarty_function_mtassetscorecount($args, &$ctx) { 
    11     return hdlr_score_count($ctx, 'asset', $args['namespace']); 
     11    $count = hdlr_score_count($ctx, 'asset', $args['namespace']); 
     12    return $ctx->count_format($count, $args); 
    1213} 
    13 ?> 
    14  
  • branches/release-35/php/lib/function.mtauthorscorecount.php

    r1174 r1956  
    99 
    1010function smarty_function_mtauthorscorecount($args, &$ctx) { 
    11     return hdlr_score_count($ctx, 'author', $args['namespace']); 
     11    $count = hdlr_score_count($ctx, 'author', $args['namespace']); 
     12    return $ctx->count_format($count, $args); 
    1213} 
    13 ?> 
    14  
  • branches/release-35/php/lib/function.mtblogcategorycount.php

    r1174 r1956  
    1111    $args['blog_id'] = $ctx->stash('blog_id'); 
    1212    $count = $ctx->mt->db->blog_category_count($args); 
    13     return $count; 
     13    return $ctx->count_format($count, $args); 
    1414} 
    15 ?> 
  • branches/release-35/php/lib/function.mtblogcommentcount.php

    r1174 r1956  
    88function smarty_function_mtblogcommentcount($args, &$ctx) { 
    99    $args['blog_id'] = $ctx->stash('blog_id'); 
    10     return $ctx->mt->db->blog_comment_count($args); 
     10    $count = $ctx->mt->db->blog_comment_count($args); 
     11    return $ctx->count_format($count, $args); 
    1112} 
    12 ?> 
  • branches/release-35/php/lib/function.mtblogentrycount.php

    r1174 r1956  
    1111    $args['blog_id'] = $ctx->stash('blog_id'); 
    1212    $count = $ctx->mt->db->blog_entry_count($args); 
    13     return $count; 
     13    return $ctx->count_format($count, $args); 
    1414} 
    15 ?> 
  • branches/release-35/php/lib/function.mtblogpagecount.php

    r1174 r1956  
    1313    return smarty_function_mtblogentrycount($args, $ctx); 
    1414} 
    15 ?> 
  • branches/release-35/php/lib/function.mtblogpingcount.php

    r1174 r1956  
    88function smarty_function_mtblogpingcount($args, &$ctx) { 
    99    $args['blog_id'] = $ctx->stash('blog_id'); 
    10     return $ctx->mt->db->blog_ping_count($args); 
     10    $count = $ctx->mt->db->blog_ping_count($args); 
     11    return $ctx->count_format($count, $args); 
    1112} 
    12 ?> 
  • branches/release-35/php/lib/function.mtcategorycommentcount.php

    r1174 r1956  
    1111    $category = $ctx->stash('category'); 
    1212    $cat_id = (int)$category['category_id']; 
    13     if (!$cat_id) return 0; 
    14     return $db->category_comment_count(array( 'category_id' => $cat_id )); 
     13    $count = 0; 
     14    if ($cat_id) { 
     15        $count = $db->category_comment_count(array( 'category_id' => $cat_id )); 
     16    } 
     17    return $ctx->count_format($count, $args); 
    1518} 
    16 ?> 
  • branches/release-35/php/lib/function.mtcategorycount.php

    r1174 r1956  
    88function smarty_function_mtcategorycount($args, &$ctx) { 
    99    $category = $ctx->stash('category'); 
    10     return $category['category_count']; 
     10    $count = $category['category_count']; 
     11    return $ctx->count_format($count, $args); 
    1112} 
    12 ?> 
  • branches/release-35/php/lib/function.mtcategorytrackbackcount.php

    r1174 r1956  
    99    $cat = $ctx->stash('category'); 
    1010    $cat_id = $cat['category_id']; 
    11     return $ctx->mt->db->category_ping_count($cat_id); 
     11    $count = $ctx->mt->db->category_ping_count($cat_id); 
     12    return $ctx->count_format($count, $args); 
    1213} 
    13 ?> 
  • branches/release-35/php/lib/function.mtcommentscorecount.php

    r1174 r1956  
    99 
    1010function smarty_function_mtcommentscorecount($args, &$ctx) { 
    11     return hdlr_score_count($ctx, 'comment', $args['namespace']); 
     11    $count = hdlr_score_count($ctx, 'comment', $args['namespace']); 
     12    return $ctx->count_format($count, $args); 
    1213} 
    13 ?> 
  • branches/release-35/php/lib/function.mtentriescount.php

    r1174 r1956  
    1010        return $ctx->tag('MTCategoryCount', $args); 
    1111    } elseif ($count = $ctx->stash('archive_count')) { 
    12         return $count; 
     12        # $count is set 
    1313    } else { 
    1414        $entries = $ctx->stash('entries'); 
     
    2121        $lastn = $ctx->stash('_entries_lastn'); 
    2222        if ($lastn && $lastn <= count($entries)) 
    23             return $lastn; 
     23            $count = $lastn; 
    2424        else 
    25             return count($entries); 
     25            $count = count($entries); 
    2626    } 
     27    return $ctx->count_format($count, $args); 
    2728} 
    28 ?> 
  • branches/release-35/php/lib/function.mtentrycommentcount.php

    r1583 r1956  
    88function smarty_function_mtentrycommentcount($args, &$ctx) { 
    99    $entry = $ctx->stash('entry'); 
    10     return $entry['entry_comment_count']; 
     10    $count = $entry['entry_comment_count']; 
     11    return $ctx->count_format($count, $args); 
    1112} 
    12 ?> 
  • branches/release-35/php/lib/function.mtentryscorecount.php

    r1174 r1956  
    99 
    1010function smarty_function_mtentryscorecount($args, &$ctx) { 
    11     return hdlr_score_count($ctx, 'entry', $args['namespace']); 
     11    $count = hdlr_score_count($ctx, 'entry', $args['namespace']); 
     12    return $ctx->count_format($count, $args); 
    1213} 
    13 ?> 
  • branches/release-35/php/lib/function.mtentrytrackbackcount.php

    r1583 r1956  
    88function smarty_function_mtentrytrackbackcount($args, &$ctx) { 
    99    $entry = $ctx->stash('entry'); 
    10     return $entry['entry_ping_count']; 
     10    $count = $entry['entry_ping_count']; 
     11    return $ctx->count_format($count, $args); 
    1112} 
    12 ?> 
  • branches/release-35/php/lib/function.mtfoldercount.php

    r1174 r1956  
    1010    return smarty_function_mtcategorycount($args, $ctx); 
    1111} 
    12 ?> 
  • branches/release-35/php/lib/function.mtpingscorecount.php

    r1174 r1956  
    99 
    1010function smarty_function_mtpingscorecount($args, &$ctx) { 
    11     return hdlr_score_count($ctx, 'tbping', $args['namespace']); 
     11    $count = hdlr_score_count($ctx, 'tbping', $args['namespace']); 
     12    return $ctx->count_format($count, $args); 
    1213} 
    13 ?> 
  • branches/release-35/php/lib/function.mttagcount.php

    r1174 r1956  
    88function smarty_function_mttagcount($args, &$ctx) { 
    99    $tag = $ctx->stash('Tag'); 
    10     if (!$tag) return ''; 
    11     if (is_array($tag)) { 
    12         return $tag['tag_count']; 
    13     } else { 
    14         return 0; 
    15     } 
     10    $count = 0; 
     11    if ($tag && is_array($tag)) 
     12        $count = $tag['tag_count']; 
     13    return $ctx->count_format($count, $args); 
    1614} 
    17 ?>