[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/menu_block/ -> menu_block.sort.inc (source)

   1  <?php
   2  // $Id: menu_block.sort.inc,v 1.2 2010/03/13 20:05:53 johnalbin Exp $
   3  
   4  /**
   5   * @file
   6   * Provides optional sorting of the active trail in the menu tree.
   7   */
   8  
   9  /**
  10   * Sort the active trail to the top of the tree.
  11   *
  12   * @param $tree
  13   *   array The menu tree to sort.
  14   * @return
  15   *   void
  16   */
  17  function _menu_tree_sort_active_path(&$tree) {
  18    // To traverse the original tree down the active trail, we use a pointer.
  19    $current_level =& $tree;
  20  
  21    // Traverse the tree along the active trail.
  22    do {
  23      $next_level = $sort = $first_key = FALSE;
  24      foreach (array_keys($current_level) AS $key) {
  25        // Save the first key for later use.
  26        if (!$first_key) {
  27          $first_key = $key;
  28        }
  29        if ($current_level[$key]['link']['in_active_trail'] && $current_level[$key]['below']) {
  30          // Don't re-sort if its already sorted.
  31          if ($key != $first_key) {
  32            // Create a new key that will come before the first key.
  33            list($first_key, ) = explode(' ', $first_key);
  34            $first_key--;
  35            list(, $new_key) = explode(' ', $key, 2);
  36            $new_key = "$first_key $new_key";
  37            // Move the item to the new key.
  38            $current_level[$new_key] = $current_level[$key];
  39            unset($current_level[$key]);
  40            $key = $new_key;
  41            $sort = TRUE; // Flag sorting.
  42          }
  43          $next_level = $key; // Flag subtree.
  44          break;
  45        }
  46      }
  47      // Sort this level.
  48      if ($sort) {
  49        ksort($current_level);
  50      }
  51      // Continue in the subtree, if it exists.
  52      if ($next_level) {
  53        $current_level =& $current_level[$next_level]['below'];
  54      }
  55    } while ($next_level);
  56  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7