You are here

function recursive_link_creator in JQuery menu 7.3

Same name and namespace in other branches
  1. 7.4 jquerymenu.module \recursive_link_creator()
1 call to recursive_link_creator()
theme_jquerymenu_menu in ./jquerymenu.module

File

./jquerymenu.module, line 171
The jQuerymenu module parses hierarchical link arrays and renders them as click and expand menu blocks.

Code

function recursive_link_creator($items = array(), $trail, $parentid = '') {
  static $menucount = 0;
  $count = 0;
  $output = '';
  $nextlevel = '';
  if (!isset($edit_access)) {
    $edit_access = 'administer menu';

    //http://drupal.org/node/911726
  }
  if ($parentid == '') {
    $menucount++;
    $parentid = $menucount;
  }
  $url_array = $trail;
  unset($url_array[array_search('<front>', $url_array)]);
  $i = 0;
  if (!empty($items)) {
    foreach ($items as $item) {
      $count++;
      $id = $parentid . '-' . $count;
      $classes = array();
      $state = 'closed';

      // If there are submenu items we assign the parent a class.
      if (!empty($item['link']['has_children'])) {
        $nextlevel = '';
        $nextlevel = recursive_link_creator($item['below'], $url_array, $id);
        if (!empty($nextlevel)) {
          $classes[] = 'parent';
        }
      }
      else {
        $classes[] = 'leaf';
      }

      // If the menu item is expanded or in the active trail and if has children add the "open" class.
      if (!empty($item['link']['mlid']) && in_array($item['link']['mlid'], $url_array) || (in_array($item['link']['href'], $url_array) || $_GET['q'] == $item['link']['href']) && !empty($item['link']['has_children']) && !empty($nextlevel) && $item['link']['href'] != '<front>') {
        $classes[] = 'open';
        $state = 'open';
      }
      elseif (!empty($item['below']) && !empty($nextlevel)) {
        $classes[] = 'closed';
      }
      if (in_array($item['link']['href'], $url_array)) {

        //$classes[] = 'active-trail';
      }
      if ($_GET['q'] == $item['link']['href'] || $item['link']['href'] == '<front>' && $_GET['q'] == variable_get('site_frontpage', 'node')) {

        //$classes[] = 'active';
      }
      if ($count == 1) {
        $classes[] = 'first';
      }
      if ($count == count($items)) {
        $classes[] = 'last';
      }
      $options = array();
      if (isset($item['link']['options'])) {
        $options = $item['link']['options'];
      }
      if (variable_get('jquerymenu_edit_link', 1) == 1) {
        if (empty($item['link']['edit_path'])) {
          if (!empty($item['link']['mlid'])) {
            $edit_path = 'admin/structure/menu/item/' . $item['link']['mlid'] . '/edit';
          }
          else {
            $edit_path = '';
          }
        }
        else {
          $edit_path = $item['link']['edit_path'];
        }
      }
      else {
        $edit_path = '';
      }
      if (empty($item['link']['edit_access'])) {
        $edit_access = 'administer menu';
      }
      else {
        $edit_access = $item['link']['edit_access'];
      }
      if (empty($item['link']['edit_text'])) {
        $edit_text = t('Edit this link');
      }
      else {
        $edit_text = $item['link']['edit_text'];
      }
      if (!empty($item['link']['to_arg_functions'])) {
        $toarg_array = array();
        $patharray = explode('/', $item['link']['href']);
        foreach ($patharray as $chunk) {
          if ($chunk != '%') {
            $toarg_array[] = $chunk;
          }
          else {
            $function = $item['link']['to_arg_functions'];
            $function = explode('"', $function);
            $function = $function[1];
            $toarg_array[] = $function('%');
          }
        }
        $path = implode('/', $toarg_array);
      }
      else {
        $path = $item['link']['href'];
      }
      if ($item['link']['hidden'] == 1 && !empty($item['link']['has_children'])) {
        $output .= recursive_link_creator($item['below'], $url_array, $id);
      }
      if ($item['link']['hidden'] != 1 && $item['link']['hidden'] != -1) {
        $output .= theme('jquerymenu_listitem', array(
          'item' => $item,
          'title' => $item['link']['title'],
          'path' => $path,
          'options' => $options,
          'state' => $state,
          'classes' => $classes,
          'has_children' => $item['link']['has_children'],
          'edit_path' => $edit_path,
          'edit_text' => $edit_text,
          'edit_access' => $edit_access,
          'nextlevel' => $nextlevel,
        ));
      }
    }
  }
  return $output;
}