'Jquerymenu Configuration', 'description' => t('Choose which menus will have a Jquery menu version and a corresponding block'), 'access arguments' => array('administer menu'), 'type' => MENU_NORMAL_ITEM, 'page callback' => 'jq_config' ); return $items; } /** * Admin page for jquery menu module. */ function jq_config() { $result = db_query("SELECT menu_name, title FROM {menu_custom}"); $output = ''; while ($menu = db_fetch_object($result)) { $menulist[$menu->menu_name] = $menu->title; $output .= $menu->title; } return drupal_get_form('jq_configuration_form'); } function jq_configuration_form() { $result = db_query("SELECT menu_name, title FROM {menu_custom}"); $menulist = array(); while ($menu = db_fetch_object($result)) { $menulist[$menu->menu_name] = $menu->title; } $result = db_query("SELECT menu_name FROM {jquerymenus}"); $enabledmenus = array(); while ($enabled = db_fetch_object($result)) { $enabledmenus[] = $enabled->menu_name; } $defaultvalue = array(); foreach ($menulist as $index => $value) { foreach ($enabledmenus as $em) { if ($index == $em) { $defaultvalue[] = $index; } else { $defaultvalue[] = 0; } } } $form['jq_activate'] = array( '#type' => 'checkboxes', '#title' => t('Jquery menu blocks'), '#options' => $menulist, '#default_value' => $defaultvalue, '#multiple' => TRUE, '#description' => t('Choose which menus you wish to create a jquery version for.
Please note that this only creates the block. You will still have to activate the block on the blocks page.'), ); $form['jq_animate'] = array( '#type' => 'checkbox', '#title' => t('Disable animation.'), '#description' => t('If checked your menus will open without any transition effects.'), '#default_value' => variable_get('jq_menu_animate', 0), ); $form['jq_editlink'] = array( '#type' => 'checkbox', '#title' => t('Display Edit Link.'), '#description' => t('If checked the edit link will display when hovering over menu items to those having administration privileges. This setting will only affect menus directly created by the jquery menu module. Other modules that implement the edit link will have their own settings.'), '#default_value' => variable_get('jq_edit_link', 1), ); $form['jq_submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); return $form; } function jq_configuration_form_submit($form, &$form_state) { $animate = $form_state['values']['jq_animate']; variable_set('jq_menu_animate', $animate); $editlink = $form_state['values']['jq_editlink']; variable_set('jq_edit_link', $editlink); $choices = $form_state['values']['jq_activate']; $result = db_query("SELECT menu_name FROM {jquerymenus}"); $enabledmenus = array(); while ($enabled = db_fetch_object($result)) { $enabledmenus[] = $enabled->menu_name; } foreach ($choices as $menuname => $value) { if ($value != '0' && !in_array($value, $enabledmenus)) { db_query("INSERT INTO {jquerymenus} (menu_name) VALUES ('%s')", $value); } if ($value == '0') { $delta = db_result(db_query("SELECT mid FROM {jquerymenus} WHERE menu_name = '%s'", $menuname)); $delta = $delta - 1 ; db_query("DELETE FROM {jquerymenus} WHERE menu_name = '%s'", $menuname); db_query("DELETE FROM {blocks} WHERE module = 'jquerymenu' AND delta = '%s'", $delta); } } drupal_set_message(t('Your settings have been saved.'), $type = 'status', $repeat = FALSE); } /** * Implementation of hook_block(). */ function jquerymenu_block($op = 'list', $delta = 0, $edit = array()) { $result = db_query("SELECT mid, menu_name FROM {jquerymenus}"); $enabledmenus = array(); while ($enabled = db_fetch_object($result)) { $enabledmenus[$enabled->mid] = $enabled->menu_name; } switch ($op) { case 'list': foreach ($enabledmenus as $mid => $name) { $title = db_result(db_query("SELECT title FROM {menu_custom} WHERE menu_name = '%s'", $name)); if (empty($title)) { db_query("DELETE FROM {jquerymenus} WHERE menu_name = '%s'", $name); db_query("DELETE FROM {blocks} WHERE module = 'jquerymenu' AND delta = %d", $mid); } $blocks[$mid]['info'] = $title .' - Jquerymenu'; $blocks[$mid]['cache'] = BLOCK_NO_CACHE; } return $blocks; case 'view': global $user; $old_activemenu = menu_get_active_menu_name(); foreach ($enabledmenus as $mid => $menuname) { $menutree = menu_tree_all_data($menuname); if (!empty($menutree)) { if ($delta == $mid) { if ($menuname == 'navigation' && !empty($user->uid)) { $title = theme('username', $user); } else { $title = db_result(db_query("SELECT title FROM {menu_custom} WHERE menu_name = '%s'", $menuname)); } menu_set_active_menu_name($menuname); $trail = jqmenu_trail_creator(); $block['subject'] = $title; $block['content'] = theme('menu_creation_by_array', $menutree, $trail); } } } menu_set_active_menu_name($old_activemenu); } //end switch ($op) return $block; } function theme_menu_creation_by_array($tree, $trail) { $menu_output = recursive_link_creator($tree, $trail); if (!empty($menu_output)) { //We create the shell to hold the menu outside the recursive function. // Add a div that only shows up for that pesky IE so that we can style it into obedience. $output = ''; $output .= '
'; $output .= ''; return $output; } } function jqmenu_trail_creator() { $activetrail = menu_get_active_trail(); $url_array = array(); $output = ''; foreach ($activetrail as $trail) { //Create an array of only the paths for easy evaluation. if (isset($trail['href'])) { $url_array[] = $trail['href']; } } return $url_array; } function recursive_link_creator($items = array(), $trail) { $url_array = $trail; $i = 0; if (!empty($items)) { foreach ($items as $item) { $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); if (!empty($nextlevel)) { $classes[] = 'parent'; } } // If the menu item is expanded or in the active trail and if has children add the "open" class. if (!empty($item['link']['expanded']) || ((in_array($item['link']['href'], $url_array) || ($_GET['q'] == $item['link']['href'])) && !empty($item['link']['has_children']) && !empty($nextlevel))) { $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']) { $classes[] = 'active'; } $options = array(); if (isset($item['link']['options'])) { $options = $item['link']['options']; } if (variable_get('jq_edit_link', 1) == 1) { if (empty($item['link']['editpath'] )) { if (!empty($item['link']['mlid'])) { $editpath = 'admin/build/menu/item/'.$item['link']['mlid'].'/edit'; } } else { $editpath = $item['link']['editpath']; } } if (empty($item['link']['editaccess'])) { $editaccess = 'administer menu'; } else { $editaccess = $item['link']['editaccess']; } 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); } if ($item['link']['hidden'] != 1 && $item['link']['hidden'] != -1) { $output .= '