[Bb-trac] [bbPress] #934: recursive statics not reset in
bb_get_forums_hierarchical() when called multiple times on single
page
bbPress
bb-trac at lists.bbpress.org
Mon Aug 18 17:39:18 GMT 2008
#934: recursive statics not reset in bb_get_forums_hierarchical() when called
multiple times on single page
-----------------------+----------------------------------------------------
Reporter: zappoman | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: Front-end | Version: 1.0-beta (trunk)
Severity: normal | Keywords: 0.8.x, 1.0-beta, 1.0-alpha, dropdown
-----------------------+----------------------------------------------------
The recursive function bb_get_forums_hierarchical() fails to produce
proper results if it is called more than once on a page. An use case
example is a home page that shows all forums and includes a post-form at
the bottom that includes the bb_new_topic_forum_dropdown() forum drop down
list.
The bug relates to the fact that the recursion is controlled by the static
_leaves variable, which starts out as false on the first call, and then is
reset to contain the current leaves of the recursive calls. This is all
well and good for the first top level call, but when the first call fully
unwinds the recursion, the static variable is left set to an empty array,
instead of being set to false... as a result, all subsequent calls will
return with an empty array.
One fix to this is to implement a top level wrapper, which is called as
the public api to bb_get_forums_hierarchical() which resets the control
variable to false, and calls the (pseudo) private function. Here is a diff
which fixes this problem.
{{{
Index: bb-includes/functions.php
===================================================================
--- bb-includes/functions.php (revision 1651)
+++ bb-includes/functions.php (working copy)
@@ -122,9 +122,15 @@
}
/* Forums */
+function bb_get_forums_hierarchical( $root = 0, $depth = 0, $leaves =
false, $_recursed = false ) {
+ global $_leaves;
+ $_leaves = false;
+ return
_bb_get_forums_hierarchical($root,$depth,$leaves,$_recursed);
+}
-function bb_get_forums_hierarchical( $root = 0, $depth = 0, $leaves =
false, $_recursed = false ) {
- static $_leaves = false;
+function _bb_get_forums_hierarchical( $root = 0, $depth = 0, $leaves =
false, $_recursed = false ) {
+ global $_leaves;
+
$root = (int) $root;
if ( false === $_leaves )
@@ -141,7 +147,7 @@
if ( $root == $leaf->forum_parent ) {
$new_root = (int) $leaf->forum_id;
unset($_leaves[$l]);
- $branch[$new_root] = 1 == $depth ? true :
bb_get_forums_hierarchical( $new_root, $depth - 1, false, true );
+ $branch[$new_root] = 1 == $depth ? true :
_bb_get_forums_hierarchical( $new_root, $depth - 1, false, true );
reset($_leaves);
}
}
}}}
--
Ticket URL: <http://trac.bbpress.org/ticket/934>
bbPress <http://bbpress.org/>
Innovative forum development
More information about the Bb-trac
mailing list