? sites/default/modules ? sites/default/settings.php Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.299 diff -u -p -r1.299 menu.inc --- includes/menu.inc 31 Oct 2008 02:18:22 -0000 1.299 +++ includes/menu.inc 4 Nov 2008 09:31:40 -0000 @@ -1244,11 +1244,7 @@ function menu_get_names($reset = FALSE) static $names; if ($reset || empty($names)) { - $names = array(); - $result = db_query("SELECT DISTINCT(menu_name) FROM {menu_links} ORDER BY menu_name"); - while ($name = db_fetch_array($result)) { - $names[] = $name['menu_name']; - } + $names = db_query("SELECT DISTINCT(menu_name) FROM {menu_links} ORDER BY menu_name")->fetchAll(); } return $names; } @@ -1786,7 +1782,7 @@ function _menu_navigation_links_rebuild( array_multisort($sort, SORT_NUMERIC, $menu_links); foreach ($menu_links as $item) { - $existing_item = db_fetch_array(db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", $item['link_path'], 'system')); + $existing_item = db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = :link_path AND module = :module", array(':link_path' => $item['link_path'], ':module' => 'system'))->fetchAssoc(); if ($existing_item) { $item['mlid'] = $existing_item['mlid']; // A change in hook_menu may move the link to a different menu @@ -1812,7 +1808,13 @@ function _menu_navigation_links_rebuild( // If the router path and the link path matches, it's surely a working // item, so we clear the updated flag. $updated = $item['updated'] && $router_path != $item['link_path']; - db_query("UPDATE {menu_links} SET router_path = '%s', updated = %d WHERE mlid = %d", $router_path, $updated, $item['mlid']); + db_update('menu_links') + ->fields(array( + 'router_path' => $router_path, + 'updated' => $updated, + )) + ->condition('mlid', $item['mlid']) + ->execute(); } } // Find any item whose router path does not exist any more. @@ -1834,11 +1836,11 @@ function _menu_navigation_links_rebuild( */ function menu_link_delete($mlid, $path = NULL) { if (isset($mlid)) { - _menu_delete_item(db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $mlid))); + _menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc()); } else { - $result = db_query("SELECT * FROM {menu_links} WHERE link_path = '%s'", $path); - while ($link = db_fetch_array($result)) { + $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path)); + foreach ($result as $link) { _menu_delete_item($link); } } @@ -1863,7 +1865,7 @@ function _menu_delete_item($item, $force menu_link_save($child); } } - db_query('DELETE FROM {menu_links} WHERE mlid = %d', $item['mlid']); + db_delete('menu_links')->condition('mlid', $item['mlid'])->execute(); // Update the has_children status of the parent. _menu_update_parental_status($item); @@ -1962,23 +1964,25 @@ function menu_link_save(&$item) { $item['plid'] = $parent['mlid']; } + $item['options'] = serialize($item['options']); if (!$existing_item) { - db_query("INSERT INTO {menu_links} ( - menu_name, plid, link_path, - hidden, external, has_children, - expanded, weight, - module, link_title, options, - customized, updated) VALUES ( - '%s', %d, '%s', - %d, %d, %d, - %d, %d, - '%s', '%s', '%s', %d, %d)", - $item['menu_name'], $item['plid'], $item['link_path'], - $item['hidden'], $item['external'], $item['has_children'], - $item['expanded'], $item['weight'], - $item['module'], $item['link_title'], serialize($item['options']), - $item['customized'], $item['updated']); - $item['mlid'] = db_last_insert_id('menu_links', 'mlid'); + $item['mlid'] = db_insert('menu_links') + ->fields(array( + 'menu_name' => $item['menu_name'], + 'plid' => $item['plid'], + 'link_path' => $item['link_path'], + 'hidden' => $item['hidden'], + 'external' => $item['external'], + 'has_children' => $item['has_children'], + 'expanded' => $item['expanded'], + 'weight' => $item['weight'], + 'module' => $item['module'], + 'link_title' => $item['link_title'], + 'options' => $item['options'], + 'customized' => $item['customized'], + 'updated' => $item['updated'], + )) + ->execute(); } if (!$item['plid']) { @@ -2017,23 +2021,40 @@ function menu_link_save(&$item) { $item['router_path'] = _menu_find_router_path($menu, $item['link_path']); } } - $item['options'] = serialize($item['options']); // If every value in $existing_item is the same in the $item, there is no // reason to run the update queries or clear the caches. We use // array_diff_assoc() with the $existing_item as the first parameter // because $item has additional keys left over from the process of building // the router item. if (!$existing_item || array_diff_assoc($existing_item, $item)) { - db_query("UPDATE {menu_links} SET menu_name = '%s', plid = %d, link_path = '%s', - router_path = '%s', hidden = %d, external = %d, has_children = %d, - expanded = %d, weight = %d, depth = %d, - p1 = %d, p2 = %d, p3 = %d, p4 = %d, p5 = %d, p6 = %d, p7 = %d, p8 = %d, p9 = %d, - module = '%s', link_title = '%s', options = '%s', customized = %d WHERE mlid = %d", - $item['menu_name'], $item['plid'], $item['link_path'], - $item['router_path'], $item['hidden'], $item['external'], $item['has_children'], - $item['expanded'], $item['weight'], $item['depth'], - $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5'], $item['p6'], $item['p7'], $item['p8'], $item['p9'], - $item['module'], $item['link_title'], $item['options'], $item['customized'], $item['mlid']); + db_update('menu_links') + ->fields(array( + 'menu_name' => $item['menu_name'], + 'plid' => $item['plid'], + 'link_path' => $item['link_path'], + 'router_path' => $item['router_path'], + 'hidden' => $item['hidden'], + 'external' => $item['external'], + 'has_children' => $item['has_children'], + 'expanded' => $item['expanded'], + 'weight' => $item['weight'], + 'depth' => $item['depth'], + 'p1' => $item['p1'], + 'p2' => $item['p2'], + 'p3' => $item['p3'], + 'p4' => $item['p4'], + 'p5' => $item['p5'], + 'p6' => $item['p6'], + 'p7' => $item['p7'], + 'p8' => $item['p8'], + 'p9' => $item['p9'], + 'module' => $item['module'], + 'link_title' => $item['link_title'], + 'options' => $item['options'], + 'customized' => $item['customized'], + )) + ->condition('mlid', $item['mlid']) + ->execute(); // Check the has_children status of the parent. _menu_update_parental_status($item); menu_cache_clear($menu_name); @@ -2132,7 +2153,12 @@ function menu_link_maintain($module, $op return menu_link_save($menu_link); break; case 'update': - db_query("UPDATE {menu_links} SET link_title = '%s' WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_title, $link_path, $module); + db_update('menu_links') + ->fields(array('link_title' => $link_title)) + ->condition('link_path', $link_path) + ->condition('customized', 0) + ->condition('module', $module) + ->execute(); $result = db_query("SELECT menu_name FROM {menu_links} WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_path, $module); while ($item = db_fetch_array($result)) { menu_cache_clear($item['menu_name']); @@ -2245,8 +2271,10 @@ function _menu_update_parental_status($i } $parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0; - db_query("UPDATE {menu_links} SET has_children = %d WHERE mlid = %d", $parent_has_children, $item['plid']); - + db_update('menu_links') + ->fields(array('has_children' => $parent_has_children)) + ->condition('mlid', $item['plid']) + ->execute(); } } @@ -2358,7 +2386,31 @@ function _menu_router_build($callbacks) return array(); } // Delete the existing router since we have some data to replace it. - db_query('DELETE FROM {menu_router}'); + db_delete('menu_router')->execute(); + + // Prepare insert object. + $insert = db_insert('menu_router') + ->fields(array( + 'path', + 'load_functions', + 'to_arg_functions', + 'access_callback', + 'access_arguments', + 'page_callback', + 'page_arguments', + 'fit', + 'number_parts', + 'tab_parent', + 'tab_root', + 'title', + 'title_callback', + 'title_arguments', + 'type', + 'block_callback', + 'description', + 'position', + 'weight', + )); // Apply inheritance rules. foreach ($menu as $path => $v) { $item = &$menu[$path]; @@ -2424,24 +2476,32 @@ function _menu_router_build($callbacks) 'path' => $path, ); - $title_arguments = $item['title arguments'] ? serialize($item['title arguments']) : ''; - db_query("INSERT INTO {menu_router} - (path, load_functions, to_arg_functions, access_callback, - access_arguments, page_callback, page_arguments, fit, - number_parts, tab_parent, tab_root, - title, title_callback, title_arguments, - type, block_callback, description, position, weight) - VALUES ('%s', '%s', '%s', '%s', - '%s', '%s', '%s', %d, - %d, '%s', '%s', - '%s', '%s', '%s', - %d, '%s', '%s', '%s', %d)", - $path, $item['load_functions'], $item['to_arg_functions'], $item['access callback'], - serialize($item['access arguments']), $item['page callback'], serialize($item['page arguments']), $item['_fit'], - $item['_number_parts'], $item['tab_parent'], $item['tab_root'], - $item['title'], $item['title callback'], $title_arguments, - $item['type'], $item['block callback'], $item['description'], $item['position'], $item['weight']); + // Fill in insert object values. + $insert->values(array( + 'path' => $item['path'], + 'load_functions' => $item['load_functions'], + 'to_arg_functions' => $item['to_arg_functions'], + 'access_callback' => $item['access callback'], + 'access_arguments' => serialize($item['access arguments']), + 'page_callback' => $item['page callback'], + 'page_arguments' => serialize($item['page arguments']), + 'fit' => $item['_fit'], + 'number_parts' => $item['_number_parts'], + 'tab_parent' => $item['tab_parent'], + 'tab_root' => $item['tab_root'], + 'title' => $item['title'], + 'title_callback' => $item['title callback'], + 'title_arguments' => ($item['title arguments'] ? serialize($item['title arguments']) : ''), + 'type' => $item['type'], + 'block_callback' => $item['block callback'], + 'description' => $item['description'], + 'position' => $item['position'], + 'weight' => $item['weight'], + )); } + // Execute insert object. + $insert->execute(); + // Sort the masks so they are in order of descending fit, and store them. $masks = array_keys($masks); rsort($masks);