'fieldset', '#title' => t('Menu settings'), '#description' => t('The settings for the menus to include in the sitemap.'), '#collapsible' => TRUE, ); $form['xmlsitemap_menu']['xmlsitemap_menu_menus'] = array( '#type' => 'checkboxes', '#title' => t('Menus to include in sitemap'), '#default_value' => array_filter(variable_get('xmlsitemap_menu_menus', array())), '#options' => menu_get_root_menus(), '#checkall' => TRUE, ); $form['buttons']['#weight'] = 1; break; } } /** * Implementation of hook_menu(). */ function xmlsitemap_menu_menu($may_cache) { if ($may_cache) { global $user; if (!empty($user->uid)) { xmlsitemap_flag_sitemap(); } } } /** * Implementation of hook_xmlsitemap_description(). */ function xmlsitemap_menu_xmlsitemap_description() { return '
'. t('XML sitemap menu') .'
'. '
'. t('It allows menu items to be added to the sitemap. You can choose the menus to include on the XML sitemap administration page and can add and remove menu items on the menu administration page. The priority of a menu item is determined by its weight.', array('@menu' => url('admin/build/menu'))) .'
'; } /** * Implementation of hook_xmlsitmap_links(). */ function xmlsitemap_menu_xmlsitemap_links() { unset($GLOBALS['_menu']); $menu = menu_get_menu(); $root_menus = array(); foreach ($menu['items'][0]['children'] as $mid) { $root_menus[$mid] = $menu['items'][$mid]['title']; } foreach (array_filter(variable_get('xmlsitemap_menu_menus', array())) as $mid) { if (isset($root_menus[$mid])) { _xmlsitemap_menu_process_link($mid, $menu); } } } /***************************************************************************** * Private functions. ****************************************************************************/ /** * Add links for a menu item and all its children to the sitemap. * @param $mid: The ID of the menu to process * @param $menu: The full menu structure for a user * @return None */ function _xmlsitemap_menu_process_link($mid, $menu) { $item = $menu['visible'][$mid]; if (!empty($item['path']) && strpos($item['path'], '://') === FALSE && $item['path'] != variable_get('site_frontpage', 'node')) { $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $item['path'])); $alias = $alias === FALSE ? NULL : $alias; $priority = 1.0 - min(max(round(($menu['items'][$mid]['weight'] + 10) / 20, 1), 0.0), 1.0); db_query("INSERT INTO {xmlsitemap} (loc, priority) VALUES ('%s', %f)", xmlsitemap_url($item['path'], $alias, NULL, NULL, TRUE), $priority); } if (isset($item['children'])) { foreach ($item['children'] as $mid) { _xmlsitemap_menu_process_link($mid, $menu); } } } /** * @} End of "addtogroup xmlsitemap". */