Changeset 1911
- Timestamp:
- 04/15/08 06:44:48 (22 months ago)
- Location:
- branches/release-35
- Files:
-
- 2 modified
-
lib/MT/Template/ContextHandlers.pm (modified) (5 diffs)
-
php/lib/mtdb_base.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-35/lib/MT/Template/ContextHandlers.pm
r1906 r1911 5058 5058 if ($comments) { 5059 5059 my $n = $args->{lastn}; 5060 my $col = lc($args->{sort_by} || 'created_on'); 5061 @$comments = $so eq 'ascend' ? 5062 sort { $a->$col() cmp $b->$col() } @$comments : 5063 sort { $b->$col() cmp $a->$col() } @$comments; 5064 $no_resort = 1; 5060 5065 if (@filters) { 5066 my $offset = $args->{offset} || 0; 5067 my $j = 0; 5061 5068 COMMENTS: for my $c (@$comments) { 5062 5069 for (@filters) { 5063 5070 next COMMENTS unless $_->($c); 5064 5071 } 5072 next if $offset && $j++ < $offset; 5065 5073 push @comments, $c; 5066 5074 } 5067 5075 } 5068 5076 else { 5069 @comments = @$comments; 5077 my $offset; 5078 if ($offset = $args->{offset}) { 5079 if ($offset < scalar @comments) { 5080 @comments = @$comments[$offset..$#comments]; 5081 } else { 5082 @comments = (); 5083 } 5084 } else { 5085 @comments = @$comments; 5086 } 5070 5087 $no_resort = 1 5071 5088 unless $args->{sort_order} || $args->{sort_by}; … … 5091 5108 $args{'sort'} = 'created_on'; 5092 5109 $args{'direction'} = 'descend'; 5093 my $c omments = $e->comments(\%terms, \%args);5094 my $ i =0;5110 my $cmts = $e->comments(\%terms, \%args); 5111 my $offset = $args->{offset} || 0; 5095 5112 if (@filters) { 5096 COMMENTS: for my $c (@$comments) { 5113 my $i = 0; 5114 my $j = 0; 5115 my $offset = $args->{offset} || 0; 5116 COMMENTS: for my $c (@$cmts) { 5097 5117 for (@filters) { 5098 5118 next COMMENTS unless $_->($c); 5099 5119 } 5120 next if $offset && $j++ < $offset; 5100 5121 push @comments, $c; 5101 5122 last if $n && ( $n <= ++$i ); 5102 5123 } 5103 } elsif ($n) { 5104 my $max = $n - 1 > $#$comments ? $#$comments : $n - 1; 5105 @comments = @$comments[0..$max]; 5124 } elsif ($offset || $n) { 5125 if ($offset) { 5126 if ($offset < scalar @$cmts - 1) { 5127 @$cmts = @$cmts[$offset..(scalar @$cmts - 1)]; 5128 } else { 5129 @$cmts = (); 5130 } 5131 } 5132 if ($n) { 5133 my $max = $n - 1 > scalar @$cmts - 1 ? scalar @$cmts - 1 : $n - 1; 5134 @$cmts = @$cmts[0..$max]; 5135 } 5136 @comments = @$cmts; 5106 5137 } else { 5107 @comments = @$c omments;5138 @comments = @$cmts; 5108 5139 } 5109 5140 } else { … … 5114 5145 if (!@filters) { 5115 5146 $args{limit} = $n if $n; 5147 $args{offset} = $args->{offset} if $args->{offset}; 5116 5148 $args{join} = MT->model('entry')->join_on( 5117 5149 undef, … … 5125 5157 my $iter = MT::Comment->load_iter(\%terms, \%args); 5126 5158 my %entries; 5159 my $j = 0; 5160 my $offset = $args->{offset} || 0; 5127 5161 COMMENT: while (my $c = $iter->()) { 5128 5162 my $e = $entries{$c->entry_id} ||= $c->entry; … … 5132 5166 next COMMENT unless $_->($c); 5133 5167 } 5168 next if $offset && $j++ < $offset; 5134 5169 push @comments, $c; 5135 5170 if ($n && (scalar @comments == $n)) { -
branches/release-35/php/lib/mtdb_base.php
r1800 r1911 2004 2004 } 2005 2005 2006 $order = 'desc';2006 $order = $query_order = 'desc'; 2007 2007 if (isset($args['sort_order'])) { 2008 2008 if ($args['sort_order'] == 'ascend') { 2009 $order = 'asc';2009 $order = $query_order = 'asc'; 2010 2010 } 2011 2011 } elseif (isset($blog) && isset($blog['blog_sort_order_comments'])) { 2012 2012 if ($blog['blog_sort_order_comments'] == 'ascend') { 2013 $order = 'asc';2014 } 2015 } 2016 if ($order == 'asc' && $args['lastn']) {2013 $order = $query_order = 'asc'; 2014 } 2015 } 2016 if ($order == 'asc' && (isset($args['lastn']) || isset($args['offset']))) { 2017 2017 $reorder = 1; 2018 $ order = 'desc';2018 $query_order = 'desc'; 2019 2019 } 2020 2020 … … 2041 2041 $limit = $args['limit']; 2042 2042 if (isset($args['offset'])) 2043 $ limit = $args['offset'];2043 $offset = $args['offset']; 2044 2044 if (count($filters)) { 2045 2045 $post_select_limit = $limit; … … 2058 2058 $entry_filter 2059 2059 $blog_filter 2060 order by comment_created_on $ order2060 order by comment_created_on $query_order 2061 2061 <LIMIT>"; 2062 2062 $sql = $this->apply_limit_sql($sql, $limit, $offset); 2063 2063 2064 # Fetch resultset 2064 2065 $result = $this->query_start($sql); … … 2066 2067 2067 2068 $comments = array(); 2069 $j = 0; 2068 2070 while (true) { 2069 2071 $e = $this->query_fetch(ARRAY_A); 2070 if ($offset && ($j++ < $offset)) continue;2071 2072 if (!isset($e)) break; 2072 2073 if (count($filters)) { … … 2074 2075 if (!$f($e, $ctx)) continue 2; 2075 2076 } 2077 if ($post_select_offset && ($j++ < $post_select_offset)) continue; 2078 if (($post_select_limit > 0) && (count($comments) >= $post_select_limit)) break; 2076 2079 } 2077 2080 $comments[] = $e; 2078 if (($limit > 0) && (count($comments) >= $limit)) break;2079 2081 } 2080 2082 … … 2124 2126 return array(); 2125 2127 2126 if ($reorder ) { // lastn and ascending sort2128 if ($reorder && !isset($args['sort_by'])) { // lastn and ascending sort 2127 2129 $asc_created_on = create_function('$a,$b', 'return strcmp($a["comment_created_on"], $b["comment_created_on"]);'); 2128 2130 usort($comments, $asc_created_on);
