You are here

function taxonomy_xml_menu_get_item_by_path in Taxonomy import/export via XML 6.2

Return a menu item matching a given path or alias. The alias for the requested path will be tried automatically.

If the root menu was defined, the lookup will be restricted to that.

Return value

a menu link ARRAY. NULL if no valid menu item was found.

1 call to taxonomy_xml_menu_get_item_by_path()
menu_taxonomy_xml_term_postsave in includes/taxonomy_xml.menu.inc
Hook into importing term data.

File

includes/taxonomy_xml.menu.inc, line 116
Support for importing or exporting menu items along with terms

Code

function taxonomy_xml_menu_get_item_by_path($path, $menu_name = NULL) {

  // Use DB to fetch *all* aliases
  $aliases = array(
    $path,
  );
  $placeholders = array(
    " link_path = '%s' ",
  );
  $result = db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path);
  while ($row = db_fetch_array($result)) {
    $aliases[] = $row['src'];
    $placeholders[] = " link_path = '%s' ";
  }

  // It's bad mojo to mess with the DB directly, but menu doesn't provide a lookup API.
  // Or a way to avoid caching. Do it by hand if I need a newly added menu
  $check_menu_name = '';
  if ($menu_name) {
    $check_menu_name = ' AND menu_name = "%s" ';
    $aliases[] = $menu_name;
  }
  $row = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE link_path <> '' AND (" . join($placeholders, 'OR') . ") {$check_menu_name} ", $aliases));
  if ($row) {

    // If I don't unserialize this, it gets flattened later
    $row['options'] = unserialize($row['options']);
    return $row;
  }
  return NULL;
}