Changeset 2103

Show
Ignore:
Timestamp:
04/25/08 11:36:53 (4 months ago)
Author:
fumiakiy
Message:

Implemented PHP version of pager related tags. Dynamically published archives can now be pagination-enabled by adding these tags and specify "auto" to limit and offset.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-36/lib/MT/CMS/Blog.pm

    r2051 r2103  
    22112211  RewriteCond %{REQUEST_FILENAME} !-f 
    22122212  # anything else is handed to mtview.php for resolution 
    2213   RewriteRule ^(.*)\$ $mtview_server_url [L,QSA] 
     2213  # passthrough query parameters 
     2214  RewriteRule ^(.*)(\\?.*)\?\$ $mtview_server_url\$2 [L,QSA] 
    22142215</IfModule> 
    22152216 
  • branches/release-36/lib/MT/Template/ContextHandlers.pm

    r2062 r2103  
    561561                my $limit = $_[0]->stash('limit'); 
    562562                my $offset = $_[0]->stash('offset'); 
    563                 $limit ? $offset / $limit + 1 : 1 
     563                $limit ? $offset / $limit + 1 : 1; 
    564564            }, 
    565565            TotalPages => sub { 
    566566                my $limit = $_[0]->stash('limit'); 
     567                return 1 unless $limit; 
    567568                my $count = $_[0]->stash('count'); 
    568569                require POSIX; 
  • branches/release-36/php/lib/block.mtentries.php

    r1926 r2103  
    3939    } 
    4040 
     41    if ( isset($args['offset']) && ($args['offset'] == 'auto') ) { 
     42        $l = 0; 
     43        if ( $args['limit'] ) { 
     44            if ( $args['limit'] == 'auto' ) { 
     45                if ( $_REQUEST['limit'] ) 
     46                    $l = $_REQUEST['limit']; 
     47                else { 
     48                    $blog_id = intval($ctx->stash('blog_id')); 
     49                    $blog = $ctx->mt->db->fetch_blog($blog_id); 
     50                    $l = $blog['blog_entries_on_index']; 
     51                } 
     52            } 
     53            else 
     54                $l = $args['limit']; 
     55        } 
     56        if ( !$l ) 
     57            $l = 20; 
     58        $ctx->stash('__pager_limit', $l); 
     59        if ( $_REQUEST['offset'] ) 
     60            $ctx->stash('__pager_offset', $_REQUEST['offset']); 
     61    } 
     62 
    4163    $entries = $ctx->stash('entries'); 
    4264    if (!isset($entries)) { 
     
    7799            $args['tag'] or $args['tags'] or $args['tags'] = is_array($tag) ? $tag['tag_name'] : $tag; 
    78100        } 
    79         $entries =& $ctx->mt->db->fetch_entries($args); 
     101        if ( isset($args['offset']) && ($args['offset'] == 'auto') ) 
     102            $total_count = 0; 
     103        $entries =& $ctx->mt->db->fetch_entries($args, $total_count); 
     104        if ( isset($args['offset']) && ($args['offset'] == 'auto') ) 
     105            $ctx->stash('__pager_total_count', $total_count); 
    80106        $ctx->stash('entries', $entries); 
    81107    } 
  • branches/release-36/php/lib/mtdb_base.php

    r2091 r2103  
    413413    } 
    414414 
    415     function &fetch_entries($args) { 
     415    function &fetch_entries($args, &$total_count = NULL) { 
    416416        if ($sql = $this->include_exclude_blogs($args)) { 
    417417            $blog_filter = 'and entry_blog_id ' . $sql; 
     
    422422        } 
    423423 
     424        $pagination = 0; 
    424425        # automatically include offset if in request 
    425426        if ($args['offset'] == 'auto') { 
     427            $pagination = 1; 
    426428            $args['offset'] = 0; 
    427429            if ($args['limit'] || $args['lastn']) { 
     
    801803            $post_select_limit = $rco; 
    802804            $no_resort = 1; 
     805        } elseif ( !is_null($total_count) ) { 
     806            $orig_limit = $limit; 
     807            $orig_offset = $offset; 
    803808        } else { 
    804809            $sql = $this->apply_limit_sql($sql . " <LIMIT>", $limit, $offset); 
     
    810815        $entries = array(); 
    811816        $j = 0; 
    812         $offset = $post_select_offset ? $post_select_offset : 0
     817        $offset = $post_select_offset ? $post_select_offset : $orig_offset
    813818        $limit = $post_select_limit ? $post_select_limit : 0; 
    814819        $id_list = array(); 
     820        $_total_count = 0; 
    815821        while (true) { 
    816822            $e = $this->query_fetch(ARRAY_A); 
     
    826832                } 
    827833            } 
     834            $_total_count++; 
     835            if ( !is_null($total_count) ) { 
     836                if ( ($orig_limit > 0) 
     837                  && ( ($_total_count-$offset) > $orig_limit) ) { 
     838                    // collected all the entries; only count numbers; 
     839                    continue; 
     840                } 
     841            } 
    828842            if ($offset && ($j++ < $offset)) continue; 
    829843            $e['entry_authored_on'] = $this->db2ts($e['entry_authored_on']); 
     
    833847            $this->_comment_count_cache[$e['entry_id']] = $e['entry_comment_count']; 
    834848            $this->_ping_count_cache[$e['entry_id']] = $e['entry_ping_count']; 
    835             if (($limit > 0) && (count($entries) >= $limit)) break; 
     849            if ( is_null($total_count) ) { 
     850                // the request does not want total count; break early 
     851                if (($limit > 0) && (count($entries) >= $limit)) break; 
     852            } 
     853        } 
     854        if ( !is_null($total_count) ) { 
     855            $total_count = $_total_count; 
    836856        } 
    837857