Skip to:
Content

bbPress.org

Changeset 953


Ignore:
Timestamp:
10/06/2007 09:15:15 PM (19 years ago)
Author:
mdawaffe
Message:

attach orphaned forums to root, more efficient bb_get_forums_hierarchical(). Needs testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/functions.php

    r952 r953  
    2626/* Forums */
    2727
    28 function bb_get_forums_hierarchical( $root = 0, $depth = 0, $_leaves = false, $_recursed = false ) {
     28function bb_get_forums_hierarchical( $root = 0, $depth = 0, $leaves = false, $_recursed = false ) {
     29    static $_leaves = false;
    2930    $root = (int) $root;
    3031
    3132    if ( false === $_leaves )
    32         $_leaves = get_forums();
     33        $_leaves = $leaves ? $leaves : get_forums();
    3334
    3435    if ( !$_leaves )
     
    3738    $branch = array();
    3839
    39     foreach ( $_leaves as $l => $leaf ) {
     40    reset($_leaves);
     41
     42    while ( list($l, $leaf) = each($_leaves) ) {
    4043        if ( $root == $leaf->forum_parent ) {
    4144            $new_root = (int) $leaf->forum_id;
    4245            unset($_leaves[$l]);
    43             $branch[$new_root] = 1 == $depth ? true : bb_get_forums_hierarchical( $new_root, $depth - 1, $_leaves, true );
     46            $branch[$new_root] = 1 == $depth ? true : bb_get_forums_hierarchical( $new_root, $depth - 1, false, true );
     47            reset($_leaves);
    4448        }
    4549    }
    4650
    47     if ( !$_recursed )
     51    if ( !$_recursed ) {
     52        foreach ( $_leaves as $leaf ) // Attach orphans to root
     53            $branch[$leaf->forum_id] = true;
     54        $_leaves = false;
    4855        return $tree = empty($branch) ? false : $branch;
     56    }
    4957
    5058    return $branch ? $branch : true;
Note: See TracChangeset for help on using the changeset viewer.