Breadcrumb dropdown menu (using forum structure tree)

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

Breadcrumb dropdown menu (using forum structure tree)

Post by PayBas »

Hey all. I was digging through the 3.1 code, and I couldn't find an answer to the following question:

Is there an existing function that builds a forum structure tree (using nested arrays or otherwise), which is available to extensions?

I ask this because I have written a custom function that does this in order to make a breadcrumb/navlinks dropdown tree structure menu. You can see it in action at: http://pbwow.com/forum/viewforum.php?f=8
If you mouse-hover over a breadcrumb/navlinks item, a dropdown menu will appear which contains the siblings and children of the level of the forum within the tree structure (hard to explain, just visit the demo link above).

I made this function myself, because I couldn't find similar functionality in other MODS, but obviously my code is sub-optimal, because it basically uses the forum jumpbox data and restructures it (not very efficient), and it does this for every page view (also not very efficient).

Code: Select all

/* Generate a forum array tree, based on an unordered array like the jumpbox data */
function build_jumpbox_tree($list) {
    $tree = $parent_memory = array();
    $prev_id = $prev_level = 0;

    foreach($list as $item => $vars) {
        $forum_id = $vars['FORUM_ID'];
        $level = (isset($vars['level']) && is_array($vars['level'])) ? count($vars['level']) : 0;

        if ($level == 0) {
            $parent_memory = array(0);
        } elseif ($level > $prev_level) {
            $parent_memory[$level] = $prev_id;
        } elseif ($level < $prev_level) {
            unset($parent_memory[$prev_level]);
            unset($parent_memory[$prev_level + 1]); // clean up
            unset($parent_memory[$prev_level + 2]); // clean up
        }

        $current = (isset($vars['SELECTED']) && !empty($vars['SELECTED']) ? true : false);
        
        $values = array('parent_id' => $parent_memory[$level], 'level' => $level, 'forum_name' => $vars['FORUM_NAME'], 'current' => $current);
        
        switch($level) {
            case 0:
                $tree[$forum_id] = $values;
            break;
            case 1:
                $tree[$parent_memory[$level]]['children'][$forum_id] = $values;
            break;
            case 2:
                $tree[$parent_memory[$level-1]]['children'][$parent_memory[$level]]['children'][$forum_id] = $values;
            break;
            case 3:
                $tree[$parent_memory[$level-2]]['children'][$parent_memory[$level-1]]['children'][$parent_memory[$level]]['children'][$forum_id] = $values;
            break;
        }

        $prev_id = $forum_id;
        $prev_level = $level;
    }

    unset($tree[-1]);
    return $tree;
}

Code: Select all

/* Generates menu blocks based on the forum array tree, to use for popup menus */
function generate_advanced_breadcrumb($tree, $crumb_current, $crumb_level = 0, $parents = array()) {
    $link = './viewforum.php?f=';
    $html = $childhtml = '';
    
    foreach ($tree as $id => $vars)
    {
        /*if (($crumb_level > $vars['level']) && $crumb_level !== 0)
        {
            continue;
        }*/
        
        if (isset($vars['children'])) {
            $childhtml = generate_advanced_breadcrumb($vars['children'], $crumb_current, $crumb_level, $parents);
        } else {
            $childhtml = '';
        }

        $parent_id = $vars['parent_id'];
        $level = $vars['level'];

        if (($crumb_level <= $vars['level'] && in_array($parent_id, $parents)) || $crumb_level == 0)
        {
            $class = (!empty($childhtml)) ? 'children' : '';
            $class .= ($vars['current'] == true || $id == $crumb_current) ? ' current' : '';

            $html .= '<li' . ((!empty($class)) ? (' class="' . $class . '">') : ('>'));

            $html .= '<a href="' . $link . $id .'">' . $vars['forum_name'] . '</a>';

            if (!empty($childhtml)) {
                $html .= '<div class="fly-out"><ul>';
                $html .= $childhtml;
                $html .= '</ul></div>';
            }

            $html .= "</li>\n";
        } else {
            $html .= $childhtml;
        }
    }

    return $html;
}

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by nickvergessen »

I think that should be implemented as an extension first
Member of the Development-TeamNo Support via PM


User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by PayBas »

If there is demand... I might make this a stand-alone extension. I personally love these breadcrumb drop-down menu's.
crumbmenu.png
crumbmenu.png (16.35 KiB) Viewed 9369 times

User avatar
Prosk8er
Registered User
Posts: 51
Joined: Sun Mar 11, 2007 1:19 am
Location: Rochester, Ny
Contact:

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by Prosk8er »

nice looks awesome

keith10456
Registered User
Posts: 523
Joined: Sat Apr 22, 2006 10:29 pm
Contact:

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by keith10456 »

PayBas wrote:If there is demand... I might make this a stand-alone extension. I personally love these breadcrumb drop-down menu's.
crumbmenu.png
Go for it... I'm sure the community would love the option once it's there. Of course that's easy for me to say since I'm not the one that have to code it :?

User avatar
Mess
Registered User
Posts: 199
Joined: Wed Jun 13, 2012 10:14 am

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by Mess »

Id use it. :)

User avatar
M.Gaetan89
Registered User
Posts: 64
Joined: Tue Jan 28, 2014 7:17 pm
Location: Divonne-les-Bains, France
Contact:

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by M.Gaetan89 »

I would use it too :)

User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

Re: Breadcrumb dropdown menu (using forum structure tree)

Post by PayBas »


Post Reply