Skip to:
Content

BuddyPress.org

Changeset 3245


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

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

Location:
branches/1.2
Files:
6 edited

Legend:

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

    r3214 r3245  
    2020
    2121        $this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
    22         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    23 
    24         /* Check if blog/forum replies are disabled */
     22        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     23
     24        // Check if blog/forum replies are disabled
    2525        $this->disable_blogforum_replies = $bp->site_options['bp-disable-blogforum-comments'];
    2626
    27         /* Get an array of the logged in user's favorite activities */
     27        // Get an array of the logged in user's favorite activities
    2828        $this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
    2929
    30         if ( !empty( $include ) ) {
    31             /* Fetch specific activity items based on ID's */
     30        // Fetch specific activity items based on ID's
     31        if ( !empty( $include ) )
    3232            $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
    33         } else {
     33        // Fetch all activity items
     34        else
    3435            $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
    35         }
    3636
    3737        if ( !$max || $max >= (int)$this->activities['total'] )
     
    4343
    4444        if ( $max ) {
    45             if ( $max >= count($this->activities) )
    46                 $this->activity_count = count($this->activities);
    47             else
     45            if ( $max >= count($this->activities) ) {
     46                $this->activity_count = count( $this->activities );
     47            } else {
    4848                $this->activity_count = (int)$max;
     49            }
    4950        } else {
    50             $this->activity_count = count($this->activities);
     51            $this->activity_count = count( $this->activities );
    5152        }
    5253
    5354        $this->full_name = $bp->displayed_user->fullname;
    5455
    55         /* Fetch parent content for activity comments so we do not have to query in the loop */
     56        // Fetch parent content for activity comments so we do not have to query in the loop
    5657        foreach ( (array)$this->activities as $activity ) {
    57             if ( 'activity_comment' != $activity->type ) continue;
     58            if ( 'activity_comment' != $activity->type )
     59                continue;
     60
    5861            $parent_ids[] = $activity->item_id;
    5962        }
     
    6366
    6467        if ( !empty( $activity_parents['activities'] ) ) {
    65             foreach( $activity_parents['activities'] as $parent ) $this->activity_parents[$parent->id] = $parent;
     68            foreach( $activity_parents['activities'] as $parent )
     69                $this->activity_parents[$parent->id] = $parent;
     70
    6671            unset( $activity_parents );
    6772        }
    6873
    69         if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
     74        if ( (int)$this->total_activity_count && (int)$this->pag_num ) {
    7075            $this->pag_links = paginate_links( array(
    71                 'base' => add_query_arg( 'acpage', '%#%' ),
    72                 'format' => '',
    73                 'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
    74                 'current' => (int)$this->pag_page,
     76                'base'      => add_query_arg( 'acpage', '%#%' ),
     77                'format'    => '',
     78                'total'     => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
     79                'current'   => (int)$this->pag_page,
    7580                'prev_text' => '←',
    7681                'next_text' => '→',
    77                 'mid_size' => 1
    78             ));
     82                'mid_size'  => 1
     83            ) );
    7984        }
    8085    }
  • branches/1.2/bp-blogs/bp-blogs-templatetags.php

    r3149 r3245  
    3737
    3838        if ( $max ) {
    39             if ( $max >= count($this->blogs) )
    40                 $this->blog_count = count($this->blogs);
    41             else
     39            if ( $max >= count($this->blogs) ) {
     40                $this->blog_count = count( $this->blogs );
     41            } else {
    4242                $this->blog_count = (int)$max;
     43            }
    4344        } else {
    44             $this->blog_count = count($this->blogs);
    45         }
    46 
    47         $this->pag_links = paginate_links( array(
    48             'base' => add_query_arg( 'bpage', '%#%' ),
    49             'format' => '',
    50             'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
    51             'current' => (int) $this->pag_page,
    52             'prev_text' => '←',
    53             'next_text' => '→',
    54             'mid_size' => 1
    55         ));
     45            $this->blog_count = count( $this->blogs );
     46        }
     47
     48        if ( (int)$this->total_blog_count && (int)$this->pag_num ) {
     49            $this->pag_links = paginate_links( array(
     50                'base'      => add_query_arg( 'bpage', '%#%' ),
     51                'format'    => '',
     52                'total'     => ceil( (int)$this->total_blog_count / (int)$this->pag_num ),
     53                'current'   => (int)$this->pag_page,
     54                'prev_text' => '←',
     55                'next_text' => '→',
     56                'mid_size'  => 1
     57            ) );
     58        }
    5659    }
    5760
  • branches/1.2/bp-core/bp-core-templatetags.php

    r3238 r3245  
    2222
    2323        $this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
    24         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    25         $this->type = $type;
    26 
    27         if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
     24        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     25        $this->type     = $type;
     26
     27        if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
    2828            $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
    29         } else {
     29        else
    3030            $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
    31         }
    3231
    3332        if ( !$max || $max >= (int)$this->members['total'] )
     
    3938
    4039        if ( $max ) {
    41             if ( $max >= count($this->members) )
    42                 $this->member_count = count($this->members);
    43             else
     40            if ( $max >= count($this->members) ) {
     41                $this->member_count = count( $this->members );
     42            } else {
    4443                $this->member_count = (int)$max;
     44            }
    4545        } else {
    46             $this->member_count = count($this->members);
     46            $this->member_count = count( $this->members );
    4747        }
    4848
    49         if ( (int) $this->total_member_count && (int) $this->pag_num ) {
     49        if ( (int)$this->total_member_count && (int)$this->pag_num ) {
    5050            $this->pag_links = paginate_links( array(
    51                 'base' => add_query_arg( 'upage', '%#%' ),
    52                 'format' => '',
    53                 'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
    54                 'current' => (int) $this->pag_page,
     51                'base'      => add_query_arg( 'upage', '%#%' ),
     52                'format'    => '',
     53                'total'     => ceil( (int)$this->total_member_count / (int)$this->pag_num ),
     54                'current'   => (int)$this->pag_page,
    5555                'prev_text' => '←',
    5656                'next_text' => '→',
    57                 'mid_size' => 1
    58             ));
     57                'mid_size'  => 1
     58            ) );
    5959        }
    6060    }
  • 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
  • branches/1.2/bp-groups/bp-groups-templatetags.php

    r3201 r3245  
    2727
    2828        $this->pag_page = isset( $_REQUEST['grpage'] ) ? intval( $_REQUEST['grpage'] ) : $page;
    29         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    30 
    31         if ( 'invites' == $type )
     29        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     30
     31        if ( 'invites' == $type ) {
    3232            $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page );
    33         else if ( 'single-group' == $type ) {
     33        } else if ( 'single-group' == $type ) {
    3434            $group = new stdClass;
    3535            $group->group_id = BP_Groups_Group::get_id_from_slug($slug);
    36             $this->groups = array( $group );
    37         } else
     36            $this->groups    = array( $group );
     37        } else {
    3838            $this->groups = groups_get_groups( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' =>$this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
     39        }
    3940
    4041        if ( 'invites' == $type ) {
    4142            $this->total_group_count = (int)$this->groups['total'];
    42             $this->group_count = (int)$this->groups['total'];
     43            $this->group_count       = (int)$this->groups['total'];
     44            $this->groups            = $this->groups['groups'];
     45        } else if ( 'single-group' == $type ) {
     46            $this->single_group      = true;
     47            $this->total_group_count = 1;
     48            $this->group_count       = 1;
     49        } else {
     50            if ( !$max || $max >= (int)$this->groups['total'] ) {
     51                $this->total_group_count = (int)$this->groups['total'];
     52            } else {
     53                $this->total_group_count = (int)$max;
     54            }
     55
    4356            $this->groups = $this->groups['groups'];
    44         } else if ( 'single-group' == $type ) {
    45             $this->single_group = true;
    46             $this->total_group_count = 1;
    47             $this->group_count = 1;
    48         } else {
    49             if ( !$max || $max >= (int)$this->groups['total'] )
    50                 $this->total_group_count = (int)$this->groups['total'];
    51             else
    52                 $this->total_group_count = (int)$max;
    53 
    54             $this->groups = $this->groups['groups'];
    5557
    5658            if ( $max ) {
    57                 if ( $max >= count($this->groups) )
    58                     $this->group_count = count($this->groups);
    59                 else
     59                if ( $max >= count($this->groups) ) {
     60                    $this->group_count = count( $this->groups );
     61                } else {
    6062                    $this->group_count = (int)$max;
     63                }
    6164            } else {
    62                 $this->group_count = count($this->groups);
     65                $this->group_count = count( $this->groups );
    6366            }
    6467        }
    6568
    66         $this->pag_links = paginate_links( array(
    67             'base' => add_query_arg( array( 'grpage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ),
    68             'format' => '',
    69             'total' => ceil($this->total_group_count / $this->pag_num),
    70             'current' => $this->pag_page,
    71             'prev_text' => '←',
    72             'next_text' => '→',
    73             'mid_size' => 1
    74         ));
     69        // Build pagination links
     70        if ( (int)$this->total_group_count && (int)$this->pag_num ) {
     71            $this->pag_links = paginate_links( array(
     72                'base'      => add_query_arg( array( 'grpage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ),
     73                'format'    => '',
     74                'total'     => ceil( (int)$this->total_group_count / (int)$this->pag_num ),
     75                'current'   => $this->pag_page,
     76                'prev_text' => '←',
     77                'next_text' => '→',
     78                'mid_size'  => 1
     79            ) );
     80        }
    7581    }
    7682
  • branches/1.2/bp-messages/bp-messages-templatetags.php

    r3206 r3245  
    2222    function bp_messages_box_template( $user_id, $box, $per_page, $max, $type ) {
    2323        $this->pag_page = isset( $_GET['mpage'] ) ? intval( $_GET['mpage'] ) : 1;
    24         $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page;
    25 
    26         $this->user_id = $user_id;
    27         $this->box = $box;
    28         $this->type = $type;
    29 
    30         if ( 'notices' == $this->box )
     24        $this->pag_num  = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page;
     25
     26        $this->user_id  = $user_id;
     27        $this->box      = $box;
     28        $this->type     = $type;
     29
     30        if ( 'notices' == $this->box ) {
    3131            $this->threads = BP_Messages_Notice::get_notices();
    32         else {
     32        } else {
    3333            $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page );
    3434
    35             $this->threads = $threads['threads'];
     35            $this->threads            = $threads['threads'];
    3636            $this->total_thread_count = $threads['total'];
    3737        }
    3838
    3939        if ( !$this->threads ) {
    40             $this->thread_count = 0;
     40            $this->thread_count       = 0;
    4141            $this->total_thread_count = 0;
    4242        } else {
     
    4444
    4545            if ( !$max || $max >= (int)$total_notice_count ) {
    46                 if ( 'notices' == $this->box )
     46                if ( 'notices' == $this->box ) {
    4747                    $this->total_thread_count = (int)$total_notice_count;
     48                }
    4849            } else {
    4950                $this->total_thread_count = (int)$max;
     
    5152
    5253            if ( $max ) {
    53                 if ( $max >= count($this->threads) )
     54                if ( $max >= count($this->threads) ) {
    5455                    $this->thread_count = count($this->threads);
    55                 else
     56                } else {
    5657                    $this->thread_count = (int)$max;
     58                }
    5759            } else {
    5860                $this->thread_count = count($this->threads);
     
    6062        }
    6163
    62         $this->pag_links = paginate_links( array(
    63             'base' => add_query_arg( 'mpage', '%#%' ),
    64             'format' => '',
    65             'total' => ceil($this->total_thread_count / $this->pag_num),
    66             'current' => $this->pag_page,
    67             'prev_text' => '←',
    68             'next_text' => '→',
    69             'mid_size' => 1
    70         ));
     64        if ( (int)$this->total_topic_count && (int)$this->pag_num ) {
     65            $this->pag_links = paginate_links( array(
     66                'base'      => add_query_arg( 'mpage', '%#%' ),
     67                'format'    => '',
     68                'total'     => ceil( (int)$this->total_thread_count / (int)$this->pag_num ),
     69                'current'   => $this->pag_page,
     70                'prev_text' => '←',
     71                'next_text' => '→',
     72                'mid_size'  => 1
     73            ) );
     74        }
    7175    }
    7276
Note: See TracChangeset for help on using the changeset viewer.