--- C:\Users\Thomas Gorgolione\Desktop\imagemenu-old\imagemenu.module 2007-03-20 07:44:07.000000000 -0400 +++ C:\Users\Thomas Gorgolione\Desktop\imagemenu\imagemenu.module 2008-08-13 23:37:27.974867600 -0400 @@ -211,6 +211,7 @@ return; } + function imagemenu_add_item($mid = 0) { // if there's no menu id set then check to see if there's any base menus to add an item to if (!$mid || !is_numeric($mid)) { @@ -239,16 +240,26 @@ '#required' => TRUE, ); $form['imagepath'] = array('#type' => 'textfield', - '#title' => t('Image Path'), + '#title' => t('Inactive (normal) Image Path'), '#default_value' => $item['imagepath'], - '#description' => t('The path to the image.'), + '#description' => t('The path to an image to display when a menu item is not active.'), '#required' => TRUE, ); + $form['activeimagepath'] = array('#type' => 'textfield', + '#title' => t('Active Image Path'), + '#default_value' => $item['activeimagepath'], + '#description' => t('Optional. The path to an image to display when a menu item is active.'), + ); $form['mouseover'] = array('#type' => 'textfield', - '#title' => t('Image Path'), + '#title' => t('Mouseover Image Path'), '#default_value' => $item['mouseover'], '#description' => t('Optional. The path to an image to display on mouseover.'), ); + $form['activemouseover'] = array('#type' => 'textfield', + '#title' => t('Active Mouseover Image Path'), + '#default_value' => $item['activemouseover'], + '#description' => t('Optional. If required, a mouseover for the active menu item.'), + ); $form['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#default_value' => $item['path'], @@ -287,20 +298,24 @@ function imagemenu_add_item_form_validate($form_id, $form) { $check = is_readable($form['imagepath']); if (!$check) form_set_error('imagepath', t('File not found.')); + $check = is_readable($form['activeimagepath']); + if (!$check && $form['activeimagepath']) form_set_error('activeimagepath', t('File not found.')); $check = is_readable($form['mouseover']); if (!$check && $form['mouseover']) form_set_error('mouseover', t('File not found.')); + $check = is_readable($form['activemouseover']); + if (!$check && $form['activemouseover']) form_set_error('activemouseover', t('File not found.')); } function imagemenu_add_item_form_submit($form_id, $form) { if ($form['path'] == 'node') $form['path'] = ''; if (!$form['mid']) { $mid = db_next_id('imagemenu'); - db_query("INSERT INTO {imagemenu} (mid, pid, path, imagepath, mouseover, title, alt, weight, type) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d)", $mid, $form['pid'], $form['path'], $form['imagepath'], $form['mouseover'], $form['title'], $form['alt'], $form['weight'], $form['expanded']); + db_query("INSERT INTO {imagemenu} (mid, pid, path, imagepath, activeimagepath, mouseover, activemouseover, title, alt, weight, type) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", $mid, $form['pid'], $form['path'], $form['imagepath'], $form['activeimagepath'], $form['mouseover'], $form['activemouseover'], $form['title'], $form['alt'], $form['weight'], $form['expanded']); drupal_set_message(t('Menu item successfully added.')); watchdog('imagemenu', t('imagemenu: added new item to menu \'%menu\'', array('%menu' => $form['pid'])), WATCHDOG_NOTICE); } else { - db_query("UPDATE {imagemenu} SET pid = %d, path = '%s', imagepath = '%s', mouseover = '%s', title = '%s', alt = '%s', weight = %d, type = %d WHERE mid = %d", $form['pid'], $form['path'], $form['imagepath'], $form['mouseover'], $form['title'], $form['alt'], $form['weight'], $form['expanded'], $form['mid']); + db_query("UPDATE {imagemenu} SET pid = %d, path = '%s', imagepath = '%s', activeimagepath = '%s', mouseover = '%s', activemouseover = '%s', title = '%s', alt = '%s', weight = %d, type = %d WHERE mid = %d", $form['pid'], $form['path'], $form['imagepath'], $form['activeimagepath'], $form['mouseover'], $form['activemouseover'], $form['title'], $form['alt'], $form['weight'], $form['expanded'], $form['mid']); drupal_set_message(t('Menu item successfully updated.')); watchdog('imagemenu', t('imagemenu: updated item in menu \'%menu\'', array('%menu' => $form['pid'])), WATCHDOG_NOTICE); } @@ -381,9 +396,87 @@ return $item->title; } -function imagemenu_fetch_item($item, $prefix = '') { - $script = $item['mouseover'] ? ' onMouseOver="document.imagemenu_'.$prefix.'_'.$item['mid'].'.src=\''.base_path().$item['mouseover'].'\'" onMouseOut="document.imagemenu_'.$prefix.'_'.$item['mid'].'.src=\''.base_path().$item['imagepath'].'\'"' : ''; - $output = ''.$item['alt'].''; +function imagemenu_fetch_item($item, $prefix = '', $active = FALSE) { + // test to see if the menu item path is a taxonomy page, or in a standard menu + // if so test to see if the current path is within the vocab, term, or menu that corresponds to the menu path + + if ($active == FALSE && (variable_get('imagemenu_taxonomy', '0') == 1)) { + // make sure we get the real paths to perform tests on before we do anything (we won't be able to use arg()) + $full_path = drupal_lookup_path("alias", $_GET["q"]) ? drupal_lookup_path("alias", $_GET["q"]) : $_GET["q"]; + $full_menu_path = drupal_lookup_path("alias", $item['path']) ? drupal_lookup_path("alias", $item['path']) : $item['path']; + $path_args = explode('/', $full_path); + $menu_path_args = explode('/', $full_menu_path); + + // is node or term page within specific vocabulary? + if ($menu_path_args[0] == "taxonomy" && $menu_path_args[1] == "vocabulary" && isset($menu_path_args[2])) { + // if we're in a taxonomy term, see if the term belongs to the vocab + if ($path_args[0] == "taxonomy" && $path_args[1] == "term") { + $term = taxonomy_get_term($path_args[2]); + $active = ($term->vid == $menu_path_args[2]) ? TRUE : $active; + } + + // if we're in a node, see if the node belongs to any terms in the vocab. if so, we can + // say that the node is associated to a vocabulary + else if ($path_args[0] == "node" && isset($path_args[1])) { + if (count(taxonomy_node_get_terms_by_vocabulary($path_args[1], $menu_path_args[2])) > 0) + $active = TRUE; + } + } + + // is node or subterm within specific term? + if ($menu_path_args[0] == "taxonomy" && $menu_path_args[1] == "term") { + + // if we're in a node, test for node type + if ($path_args[0] == "node" && isset($path_args[1])) { + $terms = taxonomy_node_get_terms($path_args[1]); + foreach ($terms as $term) { + $active = ($term == $menu_path_args[2]) ? TRUE : $active; + } + } + } + + // is node a blog post for a specific user? + if ($menu_path_args[0] == "blog" && isset($menu_path_args[1])) { + if ($path_args[0] == "node" && isset($path_args[1])) { + $this_node = node_load($path_args[1]); + $active = (($this_node->type == "blog") && ($this_node->uid == $menu_path_args[1])) ? TRUE : $active; + } + } + + // is node a blog post in general? + if ($menu_path_args[0] == "blog" && !isset($menu_path_args[1])) { + if ($path_args[0] == "node" && isset($path_args[1])) { + $this_node = node_load($path_args[1]); + $active = ($this_node->type == "blog") ? TRUE : $active; + } + } + + // is node a subitem in a menu? + if ($menu_path_args[0] == "node" && isset($menu_path_args[1])) { + + $menu_mids = db_query("SELECT * FROM {menu} WHERE path='%s'", $full_menu_path); + $path_mids = db_query("SELECT * FROM {menu} WHERE path='%s'", $full_path); + $path_mids_array = array(); + + while ($path_mid = db_fetch_object($path_mids)) + $path_mids_array[] = $path_mid; + + if((db_num_rows($menu_mids) > 0) && (db_num_rows($path_mids) > 0)) { + while ($menu_mid = db_fetch_object($menu_mids)) { + foreach ($path_mids_array as $path_mid) { + $active = (menu_in_active_trail_in_submenu($path_mid->mid, $menu_mid->mid)) ? TRUE : $active; + } + } + } + } + } + + $image_path = $active && $item['activeimagepath'] ? $item['activeimagepath'] : $item['imagepath']; + $mouse_over_img = $active && $item['activemouseover'] ? $item['activemouseover'] : $item['mouseover']; + + $script = $mouse_over_img ? ' onMouseOver="document.imagemenu_'.$prefix.'_'.$item['mid'].'.src=\''.base_path().$mouse_over_img.'\'" onMouseOut="document.imagemenu_'.$prefix.'_'.$item['mid'].'.src=\''.base_path().$image_path.'\'" onfocus="document.imagemenu_'.$prefix.'_'.$item['mid'].'.src=\''.base_path().$mouse_over_img.'\'" onblur="document.imagemenu_'.$prefix.'_'.$item['mid'].'.src=\''.base_path().$image_path.'\'"' : ''; + + $output = ''.$item['alt'].''; return $output; } @@ -423,6 +516,11 @@ '#default_value' => variable_get('imagemenu_layout', 'vertical'), '#description' => t('The orientation of the menu.'), ); + $form['admin_settings']['imagemenu_taxonomy'] = array('#type' => 'checkbox', + '#title' => t('Menuing and Taxonomy influence'), + '#default_value' => variable_get('imagemenu_taxonomy', '0'), + '#description' => t('If selected, taxonomy and standard menuing will determine whether an active image is shown.'), + ); return system_settings_form($form); } @@ -579,23 +677,27 @@ WHERE pid = %d ORDER BY weight, title', $pid); while ($item = db_fetch_object($query)) { - $output[$item->mid] = array('mid' => $item->mid, 'title' => $item->title, 'alt' => $item->alt, 'mouseover' => $item->mouseover, 'description' => $item->description, 'path' => $item->path, 'imagepath' => $item->imagepath, 'enabled' => $item->enabled, 'type' => $item->type, 'depth' => $depth); + $output[$item->mid] = array('mid' => $item->mid, 'title' => $item->title, 'alt' => $item->alt, 'mouseover' => $item->mouseover, 'activemouseover' => $item->activemouseover, 'description' => $item->description, 'path' => $item->path, 'imagepath' => $item->imagepath, 'activeimagepath' => $item->activeimagepath, 'enabled' => $item->enabled, 'type' => $item->type, 'depth' => $depth); } return $output; } function imagemenu_build_table_vertical($mid, $full = FALSE) { $menus = imagemenu_fetch_rows($mid, $full); + $visible = key(imagemenu_show_visible_tree($mid)); foreach ($menus as $menu) { - $output[] = array(array('data' => imagemenu_fetch_item($menu, $mid))); + $active = $menu['mid'] == $visible ? TRUE : FALSE; + $output[] = array(array('data' => imagemenu_fetch_item($menu, $mid, $active))); } return $output; } function imagemenu_build_table_horizontal($mid, $full = FALSE) { $menus = imagemenu_fetch_rows($mid, $full); + $visible = key(imagemenu_show_visible_tree($mid)); foreach ($menus as $menu) { - $output[$menu['depth']][] = array('data' => imagemenu_fetch_item($menu, $mid)); + $active = $menu['mid'] == $visible ? TRUE : FALSE; + $output[$menu['depth']][] = array('data' => imagemenu_fetch_item($menu, $mid, $active)); } return $output; } @@ -604,7 +706,7 @@ $path = $_GET['q']; $output = array(); $mids = array(); - if ($path == 'node' || !$path) $path = ''; + if ($path == 'node' || !$path || $path == 'front_page') $path = ''; $query = db_query("SELECT mid FROM {imagemenu} WHERE path = '%s' ORDER BY mid", $path); while ($tmp = db_fetch_object($query)) { $mids[] = $tmp->mid;