Changeset 1956
- Timestamp:
- 04/17/08 21:48:11 (22 months ago)
- Location:
- branches/release-35
- Files:
-
- 22 modified
-
lib/MT/Template/ContextHandlers.pm (modified) (22 diffs)
-
php/lib/MTViewer.php (modified) (1 diff)
-
php/lib/function.mtarchivecount.php (modified) (2 diffs)
-
php/lib/function.mtassetcount.php (modified) (1 diff)
-
php/lib/function.mtassetscorecount.php (modified) (1 diff)
-
php/lib/function.mtauthorscorecount.php (modified) (1 diff)
-
php/lib/function.mtblogcategorycount.php (modified) (1 diff)
-
php/lib/function.mtblogcommentcount.php (modified) (1 diff)
-
php/lib/function.mtblogentrycount.php (modified) (1 diff)
-
php/lib/function.mtblogpagecount.php (modified) (1 diff)
-
php/lib/function.mtblogpingcount.php (modified) (1 diff)
-
php/lib/function.mtcategorycommentcount.php (modified) (1 diff)
-
php/lib/function.mtcategorycount.php (modified) (1 diff)
-
php/lib/function.mtcategorytrackbackcount.php (modified) (1 diff)
-
php/lib/function.mtcommentscorecount.php (modified) (1 diff)
-
php/lib/function.mtentriescount.php (modified) (2 diffs)
-
php/lib/function.mtentrycommentcount.php (modified) (1 diff)
-
php/lib/function.mtentryscorecount.php (modified) (1 diff)
-
php/lib/function.mtentrytrackbackcount.php (modified) (1 diff)
-
php/lib/function.mtfoldercount.php (modified) (1 diff)
-
php/lib/function.mtpingscorecount.php (modified) (1 diff)
-
php/lib/function.mttagcount.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-35/lib/MT/Template/ContextHandlers.pm
r1953 r1956 2143 2143 } 2144 2144 2145 sub _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 2145 2166 sub _hdlr_tag_count { 2146 2167 my ($ctx, $args, $cond) = @_; … … 2148 2169 my $tag = $ctx->stash('Tag'); 2149 2170 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); 2156 2181 } 2157 2182 … … 3557 3582 $ctx->set_blog_load_context($args, \%terms, \%args) 3558 3583 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); 3560 3586 } 3561 3587 … … 3568 3594 or return $ctx->error($ctx->errstr); 3569 3595 $terms{status} = MT::Entry::RELEASE(); 3570 $class->count(\%terms, \%args); 3596 my $count = $class->count(\%terms, \%args); 3597 return _count_format($count, $args); 3571 3598 } 3572 3599 … … 3578 3605 $terms{visible} = 1; 3579 3606 require MT::Comment; 3580 MT::Comment->count(\%terms, \%args); 3607 my $count = MT::Comment->count(\%terms, \%args); 3608 return _count_format($count, $args); 3581 3609 } 3582 3610 … … 3589 3617 require MT::Trackback; 3590 3618 require MT::TBPing; 3591 MT::Trackback->count(undef,3619 my $count = MT::Trackback->count(undef, 3592 3620 { 'join' => MT::TBPing->join_on('tb_id', \%terms, \%args) }); 3621 return _count_format($count, $args); 3593 3622 } 3594 3623 … … 4260 4289 my $e = $ctx->stash('entries'); 4261 4290 4262 unless ($e) { 4291 my $count; 4292 if ($e) { 4293 $count = scalar @$e; 4294 } else { 4263 4295 my $class_type = $args->{class_type} || 'entry'; 4264 4296 my $class = MT->model($class_type); … … 4296 4328 $i++; 4297 4329 } 4298 return $i; 4299 } 4300 4301 return 0 unless $e; 4302 scalar @$e; 4330 $count = $i; 4331 } 4332 return _count_format($count, $args); 4303 4333 } 4304 4334 … … 4832 4862 4833 4863 sub _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 4838 4871 sub _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 4843 4879 sub _hdlr_entry_previous { 4844 4880 _hdlr_entry_nextprev('previous', @_); … … 5338 5374 $name = '' unless defined $name; 5339 5375 $name ||= $_[1]{default_name}; 5340 $name ||= '';5376 $name ||= MT->translate("Anonymous"); 5341 5377 my $show_email = $args->{show_email} ? 1 : 0; 5342 5378 my $show_url = 1 unless exists $args->{show_url} && !$args->{show_url}; … … 5487 5523 or return $_[0]->_no_comment_error('MTCommentParentID'); 5488 5524 my $id = $c->parent_id || 0; 5489 $args && $args->{pad} ? (sprintf "%06d", $id) : $id;5525 $args && $args->{pad} ? (sprintf "%06d", $id) : ($id ? $id : ''); 5490 5526 } 5491 5527 … … 6161 6197 6162 6198 sub _hdlr_archive_count { 6163 my $ctx = $_[0];6199 my ($ctx, $args, $cond) = @_; 6164 6200 my $at = $ctx->{current_archive_type} || $ctx->{archive_type}; 6165 6201 my $archiver = MT->publisher->archiver($at); … … 6167 6203 return _hdlr_category_count($ctx); 6168 6204 } 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); 6175 6212 } 6176 6213 … … 6433 6470 6434 6471 sub _hdlr_category_count { 6435 my ($ctx) = @_;6472 my ($ctx, $args, $cond) = @_; 6436 6473 my $cat = ($ctx->stash('category') || $_[0]->stash('archive_category')) 6437 6474 or return $_[0]->error(MT->translate( … … 6449 6486 $count = scalar $class->count(@args); 6450 6487 } 6451 $count;6488 return _count_format($count, $args); 6452 6489 } 6453 6490 6454 6491 sub _hdlr_category_comment_count { 6455 my ($ctx) = @_;6492 my ($ctx, $args, $cond) = @_; 6456 6493 my $cat = ($ctx->stash('category') || $_[0]->stash('archive_category')) 6457 6494 or return $_[0]->error(MT->translate( … … 6470 6507 require MT::Comment; 6471 6508 $count = scalar MT::Comment->count(@args); 6472 $count;6509 return _count_format($count, $args); 6473 6510 } 6474 6511 … … 6541 6578 require MT::TBPing; 6542 6579 my $count = MT::TBPing->count( { tb_id => $tb->id, visible => 1 } ); 6543 $count || 0;6580 return _count_format($count || 0, $args); 6544 6581 } 6545 6582 … … 8153 8190 $terms{blog_id} = $ctx->stash('blog_id') if $ctx->stash('blog_id'); 8154 8191 $terms{class} = $args->{type} || '*'; 8155 MT::Asset->count(\%terms, \%args); 8192 my $count = MT::Asset->count(\%terms, \%args); 8193 return _count_format($count, $args); 8156 8194 } 8157 8195 … … 8348 8386 require MT::Page; 8349 8387 $args->{class_type} = MT::Page->properties->{class_type}; 8350 &_hdlr_blog_entry_count(@_);8388 return _hdlr_blog_entry_count(@_); 8351 8389 } 8352 8390 … … 8417 8455 require MT::Folder; 8418 8456 $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); 8420 8458 } 8421 8459 8422 8460 sub _hdlr_folder_basename { 8423 8461 return $_ unless &_check_folder(@_); 8424 &_hdlr_category_basename(@_);8462 return _hdlr_category_basename(@_); 8425 8463 } 8426 8464 8427 8465 sub _hdlr_folder_description { 8428 8466 return $_ unless &_check_folder(@_); 8429 &_hdlr_category_desc(@_);8467 return _hdlr_category_desc(@_); 8430 8468 } 8431 8469 8432 8470 sub _hdlr_folder_id { 8433 8471 return $_ unless &_check_folder(@_); 8434 &_hdlr_category_id(@_);8472 return _hdlr_category_id(@_); 8435 8473 } 8436 8474 8437 8475 sub _hdlr_folder_label { 8438 8476 return $_ unless &_check_folder(@_); 8439 &_hdlr_category_label(@_);8477 return _hdlr_category_label(@_); 8440 8478 } 8441 8479 8442 8480 sub _hdlr_folder_count { 8443 8481 return $_ unless &_check_folder(@_); 8444 &_hdlr_category_count(@_);8482 return _hdlr_category_count(@_); 8445 8483 } 8446 8484 8447 8485 sub _hdlr_folder_path { 8448 8486 return $_ unless &_check_folder(@_); 8449 &_hdlr_sub_category_path(@_);8487 return _hdlr_sub_category_path(@_); 8450 8488 } 8451 8489 8452 8490 sub _hdlr_if_folder { 8453 8491 return $_ unless &_check_folder(@_); 8454 &_hdlr_if_category(@_);8492 return _hdlr_if_category(@_); 8455 8493 } 8456 8494 … … 8614 8652 } 8615 8653 8654 # FIXME: should this routine return an empty string? 8616 8655 sub _object_score_count { 8617 8656 my ($stash_key, $ctx, $args, $cond) = @_; … … 8620 8659 my $object = $ctx->stash($stash_key); 8621 8660 return '' unless $object; 8622 return $object->vote_for($key); 8661 my $count = $object->vote_for($key); 8662 return _count_format($count, $args); 8623 8663 } 8624 8664 -
branches/release-35/php/lib/MTViewer.php
r1876 r1956 456 456 return null; 457 457 } 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 } 458 478 } 459 ?> -
branches/release-35/php/lib/function.mtarchivecount.php
r1766 r1956 14 14 $archiver = $_archivers[$at]; 15 15 } 16 $count = 0; 16 17 if ((!isset($archiver) && $ctx->stash('inside_mt_categories')) || 17 18 ($ctx->stash('inside_mt_categories') && !$archiver->is_date_based())) { 18 19 return $ctx->tag('MTCategoryCount', $args); 19 20 } elseif ($count = $ctx->stash('archive_count')) { 20 return $count;21 # $count is set 21 22 } elseif ($entries = $ctx->stash('entries')) { 22 returncount($entries);23 $count = count($entries); 23 24 } else { 24 25 $eargs = array(); … … 38 39 $eargs['lastn'] = -1; 39 40 $entries =& $ctx->mt->db->fetch_entries($eargs); 40 returncount($entries);41 $count = count($entries); 41 42 } 42 43 } 43 return 0;44 $ctx->count_format($count, $args); 44 45 } 45 ?> -
branches/release-35/php/lib/function.mtassetcount.php
r1174 r1956 9 9 $args['blog_id'] = $ctx->stash('blog_id'); 10 10 $count = $ctx->mt->db->asset_count($args); 11 return $c ount;11 return $ctx->count_format($count, $args); 12 12 } -
branches/release-35/php/lib/function.mtassetscorecount.php
r1174 r1956 9 9 10 10 function 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); 12 13 } 13 ?>14 -
branches/release-35/php/lib/function.mtauthorscorecount.php
r1174 r1956 9 9 10 10 function 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); 12 13 } 13 ?>14 -
branches/release-35/php/lib/function.mtblogcategorycount.php
r1174 r1956 11 11 $args['blog_id'] = $ctx->stash('blog_id'); 12 12 $count = $ctx->mt->db->blog_category_count($args); 13 return $c ount;13 return $ctx->count_format($count, $args); 14 14 } 15 ?> -
branches/release-35/php/lib/function.mtblogcommentcount.php
r1174 r1956 8 8 function smarty_function_mtblogcommentcount($args, &$ctx) { 9 9 $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); 11 12 } 12 ?> -
branches/release-35/php/lib/function.mtblogentrycount.php
r1174 r1956 11 11 $args['blog_id'] = $ctx->stash('blog_id'); 12 12 $count = $ctx->mt->db->blog_entry_count($args); 13 return $c ount;13 return $ctx->count_format($count, $args); 14 14 } 15 ?> -
branches/release-35/php/lib/function.mtblogpagecount.php
r1174 r1956 13 13 return smarty_function_mtblogentrycount($args, $ctx); 14 14 } 15 ?> -
branches/release-35/php/lib/function.mtblogpingcount.php
r1174 r1956 8 8 function smarty_function_mtblogpingcount($args, &$ctx) { 9 9 $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); 11 12 } 12 ?> -
branches/release-35/php/lib/function.mtcategorycommentcount.php
r1174 r1956 11 11 $category = $ctx->stash('category'); 12 12 $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); 15 18 } 16 ?> -
branches/release-35/php/lib/function.mtcategorycount.php
r1174 r1956 8 8 function smarty_function_mtcategorycount($args, &$ctx) { 9 9 $category = $ctx->stash('category'); 10 return $category['category_count']; 10 $count = $category['category_count']; 11 return $ctx->count_format($count, $args); 11 12 } 12 ?> -
branches/release-35/php/lib/function.mtcategorytrackbackcount.php
r1174 r1956 9 9 $cat = $ctx->stash('category'); 10 10 $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); 12 13 } 13 ?> -
branches/release-35/php/lib/function.mtcommentscorecount.php
r1174 r1956 9 9 10 10 function 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); 12 13 } 13 ?> -
branches/release-35/php/lib/function.mtentriescount.php
r1174 r1956 10 10 return $ctx->tag('MTCategoryCount', $args); 11 11 } elseif ($count = $ctx->stash('archive_count')) { 12 return $count;12 # $count is set 13 13 } else { 14 14 $entries = $ctx->stash('entries'); … … 21 21 $lastn = $ctx->stash('_entries_lastn'); 22 22 if ($lastn && $lastn <= count($entries)) 23 return$lastn;23 $count = $lastn; 24 24 else 25 returncount($entries);25 $count = count($entries); 26 26 } 27 return $ctx->count_format($count, $args); 27 28 } 28 ?> -
branches/release-35/php/lib/function.mtentrycommentcount.php
r1583 r1956 8 8 function smarty_function_mtentrycommentcount($args, &$ctx) { 9 9 $entry = $ctx->stash('entry'); 10 return $entry['entry_comment_count']; 10 $count = $entry['entry_comment_count']; 11 return $ctx->count_format($count, $args); 11 12 } 12 ?> -
branches/release-35/php/lib/function.mtentryscorecount.php
r1174 r1956 9 9 10 10 function 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); 12 13 } 13 ?> -
branches/release-35/php/lib/function.mtentrytrackbackcount.php
r1583 r1956 8 8 function smarty_function_mtentrytrackbackcount($args, &$ctx) { 9 9 $entry = $ctx->stash('entry'); 10 return $entry['entry_ping_count']; 10 $count = $entry['entry_ping_count']; 11 return $ctx->count_format($count, $args); 11 12 } 12 ?> -
branches/release-35/php/lib/function.mtfoldercount.php
r1174 r1956 10 10 return smarty_function_mtcategorycount($args, $ctx); 11 11 } 12 ?> -
branches/release-35/php/lib/function.mtpingscorecount.php
r1174 r1956 9 9 10 10 function 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); 12 13 } 13 ?> -
branches/release-35/php/lib/function.mttagcount.php
r1174 r1956 8 8 function smarty_function_mttagcount($args, &$ctx) { 9 9 $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); 16 14 } 17 ?>
