'Jquerymenu Configuration', 'access arguments' => array('administer content'), '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}"); 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}"); while ($enabled = db_fetch_object($result)){ $enabledmenus[] = $enabled->menu_name; } 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.'), ); $form['jq_submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); return $form; } function jq_configuration_form_submit($form, &$form_state){ $choices = $form_state['values']['jq_activate']; $result = db_query("SELECT menu_name FROM {jquerymenus}"); 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'){ db_query("DELETE FROM {jquerymenus} WHERE menu_name = '%s'", $menuname); } } 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}"); while ($enabled = db_fetch_object($result)){ $enabledmenus[] = $enabled->menu_name; } switch ($op){ case 'list': $x = 0; foreach ($enabledmenus as $name){ $title = db_result(db_query("SELECT title FROM {menu_custom} WHERE menu_name = '%s'", $name)); $blocks[$x]['info'] = $title. ' - Jquerymenu'; $blocks[$x]['cache'] = BLOCK_NO_CACHE; $x++; } return $blocks; case 'view': $d = 0; foreach ($enabledmenus as $menuname){ if ($delta == $d){ $title = db_result(db_query("SELECT title FROM {menu_custom} WHERE menu_name = '%s'", $name)); $block['subject'] = $title; $block['content'] = theme('menu_creation_byname',$menuname); } $d++; } } //end switch ($op) return $block; } function theme_menu_creation_byname($menuname){ //We create the shell to hold the menu outside the recursive function. $menutree = menu_tree_all_data($menuname); // 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 recursive_link_creator($items = array()){ // Get the active trail $activetrail = menu_get_active_trail(); foreach ($activetrail as $trail){ //Create an array of only the paths for easy evaluation. $url_array[] = $trail['link_path']; } foreach ($items as $item){ // If there are submenu items we assign the parent a class. if (!empty($item['link']['has_children'])){ $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']['link_path'], $url_array) && !empty($item['link']['has_children']))){ $classes .= ' open'; $state = 'open'; } elseif (!empty($item['below'])) { $classes .= ' closed'; $state = 'closed'; } if (in_array($item['link']['link_path'], $url_array)) { $classes .= ' active-trail'; } $options = array( 'attributes' => array( 'title' => $item['link']['options']['attributes']['title'], ), ); if ($item['link']['hidden'] != 1 && $item['link']['hidden'] != -1){ $output .= '
  • '; $output .= theme('jqmenu_links', $item['link']['title'], $item['link']['link_path'], $options, $state, $classes, $item['link']['has_children']); if (!empty($item['link']['has_children'])){ $output .= ''; } $output .= '
  • '; } } return $output; } function jquerymenu_theme(){ return array( 'jqmenu_links' => array( 'arguments' => array( 'title' => NULL, 'path' => NULL, 'options' => NULL, 'state' => NULL, 'classes' => NULL, 'has_children' => NULL), ), 'menu_creation_byname' => array( 'arguments' => array ( 'menuname' => NULL, ), ), ); } function theme_jqmenu_links($title, $path, $options, $state, $classes, $has_children){ global $base_path; $module_path = $base_path.drupal_get_path('module', 'jquerymenu'); // This is the span that becomes the little plus and minus symbol. $plus = ''; if ($has_children != 0) { $output .= $plus . l($title, $path, $options); } else { $output .= l($title, $path, $options); } return $output; }