nid] = $child; $children[$child->nid]->children = book_structure($child->nid); } return $children; } // Create SQL queries for the structure of a book. function book_links_save($file, $menu_name, $book_mlid, $book_structure, $parents = array(), $mlid_start = 0) { static $mlid; if (!isset($mlid)) { $mlid = $mlid_start; } array_push($parents, $mlid); foreach ($book_structure as $page) { $mlid++; $plid = end($parents); $nid = $page->nid; $title = $page->title; $has_children = (int) !empty($page->children); $weight = $page->weight; $depth = count($parents); for ($index = 0; $index < 9; $index++) { ${'p' . ($index + 1)} = isset($parents[$index]) ? $parents[$index] : 0; } fwrite($file, "INSERT INTO menu_links (menu_name, mlid, plid, link_path, router_path, link_title, options, module, has_children, weight, depth, p1, p2, p3, p4, p5, p6, p7, p8, p9) VALUES ('$menu_name', $mlid, $plid, 'node/$nid', 'node/%', '$title', 'a:0:{}', 'book', $has_children, $weight, $depth, $p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8, $p9);\n"); if ($has_children) { book_links_save($file, $menu_name, $book_mlid, $page->children, $parents); } } } fclose($file);