You are here

function menu_node_enable in Menu Node API 6

Same name and namespace in other branches
  1. 7 menu_node.install \menu_node_enable()

Implements hook_enable().

On module enable, populate the {menu_node} table based on existing menu items.

File

./menu_node.install, line 45
Install file for Menu Node API.

Code

function menu_node_enable() {
  $items = array();
  $result = db_query("SELECT ml.mlid, ml.link_path FROM {menu_links} ml INNER JOIN {menu_custom} mc ON ml.menu_name = mc.menu_name WHERE ml.link_path LIKE 'node/%' AND ml.router_path = 'node/%%'");
  while ($data = db_fetch_object($result)) {
    $nid = str_replace('node/', '', $data->link_path);

    // Ensure that we did not grab any bad links accidentally.
    $check = (bool) db_result(db_query("SELECT COUNT(*) FROM {node} WHERE nid = %d", $nid));
    if ($check) {
      db_query("INSERT INTO {menu_node} (nid, mlid) VALUES (%d, %d)", $nid, $data->mlid);
    }
  }
}