Changeset 2333
- Timestamp:
- 05/14/08 23:35:35 (18 months ago)
- Location:
- branches/release-38
- Files:
-
- 1 added
- 2 modified
-
lib/MT/Template/ContextHandlers.pm (modified) (5 diffs)
-
php/lib/MTViewer.php (modified) (1 diff)
-
php/lib/modifier.numify.php (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-38/lib/MT/Template/ContextHandlers.pm
r2329 r2333 561 561 }, 562 562 modifier => { 563 'numify' => \&_fltr_numify, 563 564 'mteval' => \&_fltr_mteval, 564 565 'filters' => \&_fltr_filters, … … 608 609 ########################################################################### 609 610 611 =head2 numify 612 613 Adds commas to a number. Converting "12345" into "12,345" for instance. 614 The argument for the numify attribute is the separator character to use 615 (ie, "," or "."); "," is the default. 616 617 =cut 618 619 sub _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 610 628 =head2 mteval 611 629 … … 1109 1127 my $re = eval { qr/$patt/ }; 1110 1128 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: $@"); 1120 1134 } 1121 1135 } … … 11998 12012 $class_type eq 'category' ? 'entry' : 'page'); 11999 12013 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 12000 12025 my $iter = $class->load_iter(\%terms, \%args); 12001 12026 my $res = ''; … … 12030 12055 local $vars->{__even__} = ($i % 2) == 0; 12031 12056 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}; 12040 12058 $cat = $next_cat,next unless $ctx->{__stash}{category_count} || $args->{show_empty}; 12041 12059 defined(my $out = $builder->build($ctx, $tokens, -
branches/release-38/php/lib/MTViewer.php
r2160 r2333 70 70 'wrap_text' => 1, 71 71 'setvar' => 1, 72 'numify' => 1, 72 73 # native smarty modifiers 73 74 'regex_replace' => 1,
