#914 closed enhancement (worksforme)
Division by zero error in /buddypress/bp-activity/bp-activity-templatetags.php on line 56
Reported by: | jacobwg | Owned by: | jacobwg |
---|---|---|---|
Milestone: | 1.1 | Priority: | major |
Severity: | Version: | ||
Component: | Keywords: | ||
Cc: |
Description
The error seems to be coming from the code:
$this->pag_links = paginate_links( array( 'base' => add_query_arg( 'acpage', '%#%' ), 'format' => '', 'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ), 'current' => (int)$this->pag_page, 'prev_text' => '«', 'next_text' => '»', 'mid_size' => 1 ));
It seems that $this->pag_num is set to 0, thus the div by 0 error. I'll be looking into this.
Change History (7)
#1
@
15 years ago
- Owner set to jacobwg
- Status changed from new to accepted
- Summary changed from Division by zero error in \buddypress\bp-activity\bp-activity-templatetags.php on line 56 to Division by zero error in /buddypress/bp-activity/bp-activity-templatetags.php on line 56
#2
@
15 years ago
Ah... a little more digging found that page_num is not the number of pages, but the number of activity stream items per page. Apparently, it is not getting set. The code that sets the page_num var can be found on line 23:
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
Since the $_REQEST['num']
var is empty, then the culprit must be $per_page being 0.
Still digging...
#3
@
15 years ago
- Milestone set to 1.1
I just realized that I forgot to say that I am using the latest revision via SVN (revision 1635).
#4
@
15 years ago
- Resolution set to worksforme
- Status changed from accepted to closed
- Type changed from defect to enhancement
Okay, I found the issue: my widget for sitewide activity didn't have a Max Items set. You might consider adding a catch in the bp-activity-widget.php file (around line 25 so that line 26 would not execute if $instance['max_items']
was set to 0 or was undefined. If it was set to 0 or undefined, you could then display a message that would alert the user of the missing setting. Something like (lines 26-62):
<?php if ( $instance['max_items'] ) { if ( bp_has_activities( 'type=sitewide&max=' . $instance['max_items'] . '&per_page=' . $instance['per_page'] ) ) { ?> <div class="pag-count" id="activity-count"> <?php bp_activity_pagination_count() ?> </div> <div class="pagination-links" id="activity-pag"> <?php bp_activity_pagination_links() ?> </div> <ul id="activity-filter-links"> <?php bp_activity_filter_links() ?> </ul> <ul id="site-wide-stream" class="activity-list"> <?php while ( bp_activities() ) : bp_the_activity(); ?> <li class="<?php bp_activity_css_class() ?>"> <?php bp_activity_content() ?> </li> <?php endwhile; ?> </ul> <?php } else { ?> <div class="widget-error"> <?php _e('There has been no recent site activity.', 'buddypress') ?> </div> <?php } } else { ?> <div class="widget-error"> <?php _e('Please set the number of items per page setting in your widget configuration.', 'buddypress') ?> </div> <?php } ?>
#5
follow-up:
↓ 6
@
15 years ago
Another note is that if the total posts was less than the posts per page, the same error occurs
#6
in reply to:
↑ 5
;
follow-up:
↓ 7
@
15 years ago
Replying to epicalex:
Another note is that if the total posts was less than the posts per page, the same error occurs
What version of BuddyPress are you using? I'm cannot duplicate the problem, but I am using the latest version via SVN.
#7
in reply to:
↑ 6
@
15 years ago
No, I can't replicate it now either to be honest, but it was definitely the problem before, and I was running trunk. Well the problem is solved now anyway!
Replying to jacobwg:
Replying to epicalex:
Another note is that if the total posts was less than the posts per page, the same error occurs
What version of BuddyPress are you using? I'm cannot duplicate the problem, but I am using the latest version via SVN.
Okay, it seems like this is only an issue when the activity stream is less than one page long. I'm going to look into adding logic code to prevent this error.