<?php
// $Id: nice_menus.module,v 1.16.2.3 2007/04/30 16:08:16 add1sun Exp $
/*
By Jake Gordon (jakeg)
Module to enable nice navigation menus
Modifications and help by Simon Rawson.
*/
/*
* Implementation of hook_help().
*/
function nice_menus_help($section) {
switch ($section) {
case 'admin/settings/modules#description':
$output = t('Make drop down css/javascript menus for site navigation and admin menus.');
break;
case 'admin/settings/nice_menus':
$output = t('<p>This is a simple module that enables the site to have drop down css/javascript menus for site navigation and admin navigation.</p><p>Remember to activate and configure the menus in !link</p>', array('!link' => l('admin/build/block', 'admin/build/block')));
break;
}
return $output;
}
/**
* Implemention of hook_menu().
*/
function nice_menus_menu($may_cache) {
if (!$may_cache) {
// won't add if already added, but need this *before* our js
//drupal_add_js('misc/drupal.js', 'core');
// We only want to include the JS for IE, not browsers capable of doing everything in css
// We have to put all the js in drupal_set_html_head so they get called in the right order.
drupal_set_html_head('<!--[if lt IE 7]>
<script type="text/javascript" src="'. check_url(base_path() .'misc/jquery.js') .'"></script>
<script type="text/javascript" src="'. check_url(base_path() .'misc/drupal.js') .'"></script>
<script type="text/javascript" src="'. check_url(base_path() . drupal_get_path('module', 'nice_menus').'/nice_menus.js') .'"></script>
<![endif]-->');
//drupal_add_js(drupal_get_path('module', 'nice_menus') .'/nice_menus.js');
drupal_add_css(drupal_get_path('module', 'nice_menus') .'/nice_menus.css');
}
else {
$items[] = array(
'path' => 'admin/settings/nice_menus',
'title' => t('Nice Menus'),
'description' => t('Configure Nice Menus.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('nice_menus_admin_settings'),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
/*
* Settings form as implemented by hook_menu
*/
function nice_menus_admin_settings() {
$form['nice_menus_number'] = array(
'#type' => 'select',
'#title' => t('Number of Nice Menus'),
'#description' => t('The total number of independent nice menus (blocks) you want.'),
'#default_value' => variable_get('nice_menus_number', '2'),
'#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
);
return system_settings_form($form);
}
/*
* Implementation of hook_block().
*/
function nice_menus_block($op = 'list', $delta = 0, $edit = array()) {
global $user;
switch ($op) {
case 'list':
for ($i=1; $i <= variable_get('nice_menus_number', '2'); $i++) {
$blocks[$i]['info'] = variable_get('nice_menus_name_'. $i, 'Nice Menu '. $i) .' (Nice Menu)';
}
return $blocks;
break;
case 'configure':
$form['nice_menus_name_'. $delta] = array(
'#type' => 'textfield',
'#title' => t('Menu Name'),
'#default_value' => variable_get('nice_menus_name_'. $delta, 'Nice Menu '. $delta),
);
$form['nice_menus_menu_'. $delta] = array(
'#type' => 'select',
'#title' => t('Source Menu Tree'),
'#description' => t('The menu tree from which to show a nice menu.'),
'#default_value' => variable_get('nice_menus_menu_'. $delta, '1'),
'#options' => menu_parent_options(0),
);
$form['nice_menus_type_'. $delta] = array(
'#type' => 'select',
'#title' => t('Menu Style'),
'#description' => t('right: menu items are listed on top of each other and expand to the right') .'<br />'. t('left: menu items are listed on top of each other and expand to the left') .'<br />'. t('down: menu items are listed side by side and expand down'),
'#default_value' => variable_get('nice_menus_type_'. $delta, 'right'),
'#options' => drupal_map_assoc(array('right', 'left', 'down')),
);
return $form;
break;
case 'save':
variable_set('nice_menus_name_'. $delta, $edit['nice_menus_name_'. $delta]);
variable_set('nice_menus_menu_'. $delta, $edit['nice_menus_menu_'. $delta]);
variable_set('nice_menus_type_'. $delta, $edit['nice_menus_type_'. $delta]);
break;
case 'view':
if ($menu_tree = theme('nice_menu_tree', (variable_get('nice_menus_menu_'.$delta, '1')))) {
if ($menu_tree['content']) {
$block['content'] = '<ul class="nice-menu nice-menu-'. variable_get('nice_menus_type_'. $delta, 'right') .'" id="nice-menu-'. $delta .'">'. $menu_tree['content'];
if (variable_get('nice_menus_type_'. $delta, 'right') == 'down') {
$class = 'nice-menu-hide-title';
}
else {
$class = 'nice-menu-show-title';
}
$block['subject'] = '<span class="'. $class .'">'. check_plain($menu_tree['subject'] == t('Navigation') ? ($user->uid ? $user->name : t('Navigation')) : $menu_tree['subject']) .'</span>';
}
}
else $block['content'] = false;
return $block;
break;
}
}
/*
* Theme Nice Menus output
*/
//store and return second level block.
//must be this way because second level is not in the same locality
function nice_menu_second_menu($data='')
{
static $second_level='';
if($output !=''){$second_level=$data;}
return $second_level;
}
function theme_nice_menu_tree($pid = 1,$level=1) {
$menu = menu_get_menu();
$output['content'] = '';
$t='';
$output['subject'] = $menu['items'][$pid]['title'];
if ($menu['visible'][$pid]['children']) {
foreach ($menu['visible'][$pid]['children'] as $mid) {
// Build class name based on menu path e.g. to give each menu item individual style
$path_class = 'menu-path-'. str_replace('/', '-', $menu['items'][$mid]['path']);
if (count($menu['visible'][$mid]['children']) > 0) {
$output['content'] .= '<li id="menu-'. $mid .'" class="menuparent '. $path_class .'" >'. menu_item_link($mid);
//$output['content'] .= '<ul>';
$output['content'] .= '</li>'."\n";
$t .= '<ul id="ul'.$mid.'" class="hidden-submenu"><!--[if lt IE 7]><iframe></iframe><![endif]-->';
$tmp = theme('nice_menu_tree', $mid,$level+1);
$t .= $tmp['content'];
$t .= '</ul>';
}
else {
$output['content'] .= '<li id="menu-'. $mid .'" class="'. $path_class .'">'. menu_item_link($mid) .'</li>';
}
}
if($level==1) $output['content'] .= '</ul>';
//$output['content'] .= $t;
nice_menu_second_menu($t);
}
return $output;
}