Changeset 2333

Show
Ignore:
Timestamp:
05/14/08 23:35:35 (6 months ago)
Author:
bchoate
Message:

Adding 'numify' modifier. BugId:79765. Optimized counts gathered for Categories tag. Fix for 'g' modifier with regex_replace modifier.

Files:

Legend:

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

    r2329 r2333  
    561561        }, 
    562562        modifier => { 
     563            'numify' => \&_fltr_numify, 
    563564            'mteval' => \&_fltr_mteval, 
    564565            'filters' => \&_fltr_filters, 
     
    608609########################################################################### 
    609610 
     611=head2 numify 
     612 
     613Adds commas to a number. Converting "12345" into "12,345" for instance. 
     614The argument for the numify attribute is the separator character to use 
     615(ie, "," or "."); "," is the default. 
     616 
     617=cut 
     618 
     619sub _fltr_numify { 
     620    my ($str, $arg, $ctx) = @_; 
     621    $arg = ',' if (!defined $arg) || ($arg eq '1'); 
     622    $str =~ s/(^[−+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1$arg/g; 
     623    return $str; 
     624} 
     625 
     626########################################################################### 
     627 
    610628=head2 mteval 
    611629 
     
    11091127        my $re = eval { qr/$patt/ }; 
    11101128        if (defined $re) { 
    1111             $replace =~ s!\\\\(\d+)!\$$1!g; # for php, \\1 is how you write $1 
    1112             if ($global) { 
    1113                 $str =~ s/$re/$replace/g; 
    1114                 my @matches = ($&, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20); 
    1115                 $str =~ s/\$(\d+)/$matches[$1]/g; 
    1116             } else { 
    1117                 $str =~ s/$re/$replace/; 
    1118                 my @matches = ($&, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20); 
    1119                 $str =~ s/\$(\d+)/$matches[$1]/g; 
     1129            $replace =~ s!\\\\(\d+)!\$1!g; # for php, \\1 is how you write $1 
     1130            $replace =~ s!/!\\/!g; 
     1131            eval '$str =~ s/$re/' . $replace . '/' . ($global ? 'g' : ''); 
     1132            if ($@) { 
     1133                return $ctx->error("Invalid regular expression: $@"); 
    11201134            } 
    11211135        } 
     
    1199812012        $class_type eq 'category' ? 'entry' : 'page'); 
    1199912013 
     12014    # issue a single count_group_by for all categories 
     12015    my $cnt_iter = MT::Placement->count_group_by({ 
     12016        %terms 
     12017    }, { group => [ 'category_id' ], 
     12018        join => $entry_class->join_on('id', { status => MT::Entry::RELEASE() }), 
     12019    }); 
     12020    my %counts; 
     12021    while (my ($count, $cat_id) = $cnt_iter->()) { 
     12022        $counts{$cat_id} = $count; 
     12023    } 
     12024 
    1200012025    my $iter = $class->load_iter(\%terms, \%args); 
    1200112026    my $res = ''; 
     
    1203012055        local $vars->{__even__} = ($i % 2) == 0; 
    1203112056        local $vars->{__counter__} = $i; 
    12032         my @args = ( 
    12033             { blog_id => $cat->blog_id, 
    12034               status => MT::Entry::RELEASE() }, 
    12035             { 'join' => [ 'MT::Placement', 'entry_id', 
    12036                           { category_id => $cat->id } ], 
    12037               'sort' => 'authored_on', 
    12038               direction => 'descend', }); 
    12039         $ctx->{__stash}{category_count} = $entry_class->count(@args); 
     12057        $ctx->{__stash}{category_count} = $counts{$cat->id}; 
    1204012058        $cat = $next_cat,next unless $ctx->{__stash}{category_count} || $args->{show_empty}; 
    1204112059        defined(my $out = $builder->build($ctx, $tokens, 
  • branches/release-38/php/lib/MTViewer.php

    r2160 r2333  
    7070        'wrap_text' => 1, 
    7171        'setvar' => 1, 
     72        'numify' => 1, 
    7273         # native smarty modifiers 
    7374        'regex_replace' => 1,