Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/10/2010 08:12:08 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Clean-up pagination in all components. Fixes #2625. Props BenFremer on your first trac ticket!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-forums/bp-forums-templatetags.php

    r3216 r3245  
    2424        global $bp;
    2525
    26         $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
    27         $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
    28         $this->type = $type;
     26        $this->pag_page     = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
     27        $this->pag_num      = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
     28        $this->type         = $type;
    2929        $this->search_terms = $search_terms;
    30         $this->forum_id = $forum_id;
     30        $this->forum_id     = $forum_id;
    3131
    3232        switch ( $type ) {
     
    5151
    5252        if ( !(int)$this->topics ) {
    53             $this->topic_count = 0;
     53            $this->topic_count       = 0;
    5454            $this->total_topic_count = 0;
    5555        } else {
     
    6363            }
    6464
    65             if ( !$max || $max >= $topic_count )
     65            if ( !$max || $max >= $topic_count ) {
    6666                $this->total_topic_count = $topic_count;
    67             else
     67            } else {
    6868                $this->total_topic_count = (int)$max;
     69            }
    6970
    7071            if ( $max ) {
    71                 if ( $max >= count($this->topics) )
     72                if ( $max >= count($this->topics) ) {
    7273                    $this->topic_count = count( $this->topics );
    73                 else
     74                } else {
    7475                    $this->topic_count = (int)$max;
     76                }
    7577            } else {
    7678                $this->topic_count = count( $this->topics );
     
    7880        }
    7981
    80         $this->topic_count = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
     82        $this->topic_count       = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
    8183        $this->total_topic_count = apply_filters( 'bp_forums_template_total_topic_count', $this->total_topic_count, $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
    8284
    83         if ( !$no_stickies) {
    84             /* Place stickies at the top - not sure why bbPress doesn't do this? */
     85        if ( !$no_stickies ) {
     86            // Place stickies at the top - not sure why bbPress doesn't do this?
    8587            foreach( (array)$this->topics as $topic ) {
    86                 if ( 1 == (int)$topic->topic_sticky )
     88                if ( 1 == (int)$topic->topic_sticky ) {
    8789                    $stickies[] = $topic;
    88                 else
     90                } else {
    8991                    $standard[] = $topic;
     92                }
    9093            }
     94
    9195            $this->topics = array_merge( (array)$stickies, (array)$standard );
    9296        }
    9397
    94         /* Fetch extra information for topics, so we don't have to query inside the loop */
     98        // Fetch extra information for topics, so we don't have to query inside the loop
    9599        $this->topics = bp_forums_get_topic_extras( &$this->topics );
    96100
    97         $this->pag_links = paginate_links( array(
    98             'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
    99             'format' => '',
    100             'total' => ceil($this->total_topic_count / $this->pag_num),
    101             'current' => $this->pag_page,
    102             'prev_text' => '←',
    103             'next_text' => '→',
    104             'mid_size' => 1
    105         ));
     101        if ( (int)$this->total_topic_count && (int)$this->pag_num ) {
     102            $this->pag_links = paginate_links( array(
     103                'base'      => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
     104                'format'    => '',
     105                'total'     => ceil( (int)$this->total_topic_count / (int)$this->pag_num),
     106                'current'   => $this->pag_page,
     107                'prev_text' => '←',
     108                'next_text' => '→',
     109                'mid_size'  => 1
     110            ) );
     111        }
    106112    }
    107113
     
    725731        $this->forum_id        = $forum_template->topic->forum_id;
    726732
    727         $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) );
     733        $this->posts           = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) );
    728734
    729735        if ( !$this->posts ) {
    730             $this->post_count = 0;
     736            $this->post_count       = 0;
    731737            $this->total_post_count = 0;
    732738        } else {
    733             if ( !$max || $max >= (int) $forum_template->topic->topic_posts )
    734                 $this->total_post_count = (int) $forum_template->topic->topic_posts;
    735             else
     739            if ( !$max || $max >= (int)$forum_template->topic->topic_posts ) {
     740                $this->total_post_count = (int)$forum_template->topic->topic_posts;
     741            } else {
    736742                $this->total_post_count = (int)$max;
     743            }
    737744
    738745            if ( $max ) {
    739                 if ( $max >= count($this->posts) )
     746                if ( $max >= count( $this->posts ) ) {
    740747                    $this->post_count = count( $this->posts );
    741                 else
     748                } else {
    742749                    $this->post_count = (int)$max;
     750                }
    743751            } else {
    744752                $this->post_count = count( $this->posts );
     
    746754        }
    747755
    748         $this->pag_links = paginate_links( array(
    749             'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => $this->pag_num ) ),
    750             'format' => '',
    751             'total' => ceil($this->total_post_count / $this->pag_num),
    752             'current' => $this->pag_page,
    753             'prev_text' => '←',
    754             'next_text' => '→',
    755             'mid_size' => 1
    756         ));
    757         $this->pag->total_pages = ceil($this->total_post_count / $this->pag_num);
     756        if ( (int)$this->total_post_count && (int)$this->pag_num ) {
     757            $this->pag_links = paginate_links( array(
     758                'base'      => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int)$this->pag_num ) ),
     759                'format'    => '',
     760                'total'     => ceil( (int)$this->total_post_count / (int)$this->pag_num ),
     761                'current'   => $this->pag_page,
     762                'prev_text' => '←',
     763                'next_text' => '→',
     764                'mid_size'  => 1
     765            ) );
     766
     767            $this->pag->total_pages = ceil( (int)$this->total_post_count / (int)$this->pag_num );
     768        } else {
     769            $this->pag->total_pages = 1;
     770        }
    758771    }
    759772
Note: See TracChangeset for help on using the changeset viewer.