Index: site-map.tpl.php
===================================================================
--- site-map.tpl.php (revision 221)
+++ site-map.tpl.php (working copy)
@@ -32,42 +32,8 @@
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: site_map.admin.inc
===================================================================
--- site_map.admin.inc (revision 221)
+++ site_map.admin.inc (working copy)
@@ -31,6 +31,7 @@
'#type' => 'fieldset',
'#title' => t('Site map content'),
);
+ $site_map_ordering = array();
$form['site_map_content']['site_map_show_front'] = array(
'#type' => 'checkbox',
'#title' => t('Show front page'),
@@ -37,6 +38,7 @@
'#default_value' => variable_get('site_map_show_front', 1),
'#description' => t('When enabled, this option will include the front page in the site map.'),
);
+ $site_map_ordering['front'] = t('Front page');
$form['site_map_content']['site_map_show_titles'] = array(
'#type' => 'checkbox',
'#title' => t('Show titles'),
@@ -50,6 +52,7 @@
'#default_value' => variable_get('site_map_show_blogs', 1),
'#description' => t('When enabled, this option will show the 10 most active blog authors.'),
);
+ $site_map_ordering['blogs'] = t('Active blog authors');
}
if (module_exists('book')) {
$book_options = array();
@@ -69,11 +72,13 @@
'#default_value' => variable_get('site_map_books_expanded', 1),
'#description' => t('When enabled, this option will show all children pages for each book.'),
);
+ $site_map_ordering['books'] = t('Books');
}
-
$menu_options = array();
$menu_options = menu_get_menus();
-
+ foreach ($menu_options as $menu_id => $menu_title) {
+ $site_map_ordering['menus_' . $menu_id] = $menu_title;
+ }
$form['site_map_content']['site_map_show_menus'] = array(
'#type' => 'checkboxes',
'#title' => t('Menus to include in the site map'),
@@ -95,11 +100,13 @@
'#default_value' => variable_get('site_map_show_faq', 0),
'#description' => t('When enabled, this option will include the content from the FAQ module in the site map.'),
);
+ $site_map_ordering['faq'] = t('FAQ content');
}
$vocab_options = array();
if (module_exists('taxonomy')) {
foreach (taxonomy_get_vocabularies() as $vocabulary) {
$vocab_options[$vocabulary->machine_name] = $vocabulary->name;
+ $site_map_ordering['vocabularies_' . $vocabulary->vid] = $vocabulary->name;
}
}
$form['site_map_content']['site_map_show_vocabularies'] = array(
@@ -109,6 +116,29 @@
'#options' => $vocab_options,
'#multiple' => TRUE,
);
+ $form['site_map_content']['site_map_order'] = array(
+ '#type' => 'item',
+ '#title' => t('Site map order'),
+ '#theme' => 'site_map_order',
+ );
+ $site_map_order_defaults = variable_get('site_map_order', array());
+ foreach ($site_map_ordering as $content_id => $content_title) {
+ $form['site_map_content']['site_map_order'][$content_id] = array(
+ 'content' => array(
+ '#markup' => $content_title,
+ ),
+ 'weight' => array(
+ '#type' => 'weight',
+ '#title' => t('Weight for @title', array('@title' => $content_title)),
+ '#title_display' => 'invisible',
+ '#delta' => 50,
+ '#default_value' => $site_map_order_defaults[$content_id],
+ '#parents' => array('site_map_order', $content_id),
+ ),
+ '#weight' => $site_map_order_defaults[$content_id],
+ );
+ }
+ $form['#attached']['js'][] = drupal_get_path('module', 'site_map') . '/site_map.admin.js';
$form['site_map_taxonomy_options'] = array(
'#type' => 'fieldset',
Index: site_map.module
===================================================================
--- site_map.module (revision 221)
+++ site_map.module (working copy)
@@ -64,6 +64,10 @@
'variables' => array(),
'file' => 'site_map.theme.inc',
),
+ 'site_map_order' => array(
+ 'render element' => 'element',
+ 'file' => 'site_map.theme.inc',
+ ),
);
}
@@ -436,45 +440,37 @@
* @return string
* Returns HTML string of site map for menus.
*/
-function _site_map_menus() {
+function _site_map_menus($mid) {
$output = '';
+ $class = array();
$options = array();
- $mids = array_filter(variable_get('site_map_show_menus', array()));
- if (!empty($mids)) {
- foreach ($mids as $mid) {
- $class = array();
- $menu = menu_load($mid);
- // Use menu_tree_all_data to retrieve the expanded tree.
- $tree = menu_tree_all_data($mid);
- if (module_exists('i18n_menu')) {
- $tree = i18n_menu_localize_tree($tree, $GLOBALS['language']->language);
+ if (!empty($mid)) {
+ $menu = menu_load($mid);
+ // Use menu_tree_all_data to retrieve the expanded tree.
+ $tree = menu_tree_all_data($mid);
+ if (module_exists('i18n_menu')) {
+ $tree = i18n_menu_localize_tree($tree, $GLOBALS['language']->language);
+ }
+ $menu_display = _site_map_menu_tree_output($tree);
+ $menu_html = drupal_render($menu_display);
+ if (!empty($menu_html)) {
+ $title = t($menu['title']);
+ if (module_exists('i18n_string')) {
+ $m_array = array('menu', 'menu', $menu['menu_name'], 'title');
+ $title = i18n_string_plain($m_array, $title);
}
+ _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE);
- // Add an alter hook so other modules can manipulate the menu tree prior to rendering
- $alter_mid = preg_replace('/[^a-z0-9_]+/', '_', $mid);
- drupal_alter(array('site_map_menu_tree', 'site_map_menu_tree_' . $alter_mid), $tree, $menu);
-
- $menu_display = _site_map_menu_tree_output($tree);
- $menu_html = drupal_render($menu_display);
- if (!empty($menu_html)) {
- $title = t($menu['title']);
- if (module_exists('i18n_string')) {
- $m_array = array('menu', 'menu', $menu['menu_name'], 'title');
- $title = i18n_string_plain($m_array, $title);
- }
- _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE);
-
- $class[] = 'site-map-box-menu';
- $class[] = 'site-map-box-menu-' . $mid;
- $attributes = array('class' => $class);
- $output .= theme('site_map_box', array(
- 'title' => $title,
- 'content' => $menu_html,
- 'attributes' => $attributes,
- 'options' => $options,
- ));
- }
+ $class[] = 'site-map-box-menu';
+ $class[] = 'site-map-box-menu-' . $mid;
+ $attributes = array('class' => $class);
+ $output .= theme('site_map_box', array(
+ 'title' => $title,
+ 'content' => $menu_html,
+ 'attributes' => $attributes,
+ 'options' => $options,
+ ));
}
}
@@ -515,21 +511,17 @@
* @return string
* Returns HTML string of site map for taxonomies.
*/
-function _site_map_taxonomys() {
+function _site_map_taxonomys($voc) {
$output = '';
$options = array();
- $vnames = array_filter(variable_get('site_map_show_vocabularies', array()));
- if (module_exists('taxonomy') && !empty($vnames)) {
- $result = db_query('SELECT vid, name, description FROM {taxonomy_vocabulary} WHERE machine_name IN (:vnames) ORDER BY weight ASC, name', array(':vnames' => $vnames));
- foreach ($result as $voc) {
- if (module_exists('i18n_taxonomy')) {
- $voc->name = i18n_taxonomy_vocabulary_name($voc, $GLOBALS['language']->language);
- }
+ if (module_exists('taxonomy') && !empty($voc)) {
+ if (module_exists('i18n_taxonomy')) {
+ $voc->name = i18n_taxonomy_vocabulary_name($voc, $GLOBALS['language']->language);
+ }
+
$output .= _site_map_taxonomy_tree($voc->vid, $voc->name, $voc->description);
- }
- _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE);
-
+ _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE);
}
return $output;
Index: site_map.theme.inc
===================================================================
--- site_map.theme.inc (revision 221)
+++ site_map.theme.inc (working copy)
@@ -181,31 +181,62 @@
$variables['rss_legend'] = theme('site_map_rss_legend');
}
- if (variable_get('site_map_show_front', 1)) {
- $variables['front_page'] = _site_map_front_page();
- }
-
if (variable_get('site_map_show_titles', 1)) {
$variables['show_titles'] = TRUE;
}
- if (variable_get('site_map_show_blogs', 1)) {
- $variables['blogs'] = _site_map_blogs();
- }
+ $variables['site_map'] = '';
+ $site_map_order = variable_get('site_map_order', array());
+ asort($site_map_order);
- // Compile the books trees.
- $variables['books'] = _site_map_books();
+ foreach ($site_map_order as $content => $weight) {
+ // Get type of content
+ $type = substr($content, 0, strpos($content, '_'));
+ $id = substr($content, strpos($content, '_') + 1);
+ if (empty($type)) {
+ $type = $content;
+ $id = NULL;
+ }
- // Compile the menu trees.
- $variables['menus'] = _site_map_menus();
+ switch ($type) {
+ case 'front':
+ if (variable_get('site_map_show_front', 1)) {
+ $variables['site_map'] .= _site_map_front_page();
+ }
+ break;
+ case 'blogs':
+ if (variable_get('site_map_show_blogs', 1)) {
+ $variables['site_map'] .= _site_map_blogs();
+ }
+ break;
+ case 'books':
+ $books = variable_get('site_map_show_books', array());
+ if (!empty($books)) {
+ $variables['site_map'] .= _site_map_books();
+ }
+ break;
+ case 'menus':
+ $menus = variable_get('site_map_show_menus', array());
+ if (!empty($menus[$id])) {
+ $variables['site_map'] .= _site_map_menus($id);
+ }
+ break;
+ case 'faq':
+ if (variable_get('site_map_show_faq', 0)) {
+ $variables['site_map'] .= _site_map_faq();
+ }
+ break;
+ case 'vocabularies':
+ $vocabulary = taxonomy_vocabulary_load($id);
+ $vocabularies = variable_get('site_map_show_vocabularies', array());
- if (variable_get('site_map_show_faq', 0)) {
- $variables['faq'] = _site_map_faq();
+ if (!empty($vocabularies[$vocabulary->machine_name])) {
+ $variables['site_map'] .= _site_map_taxonomys($vocabulary);
+ }
+ break;
+ }
}
- // Compile the vocabulary trees.
- $variables['taxonomys'] = _site_map_taxonomys();
-
// Invoke all custom modules and integrate themed HTML into the site map.
$additional = module_invoke_all('site_map');
foreach ($additional as $themed_site_map_code) {
@@ -212,3 +243,37 @@
$variables['additional'] .= $themed_site_map_code;
}
}
+
+/**
+ * Returns HTML for the site map order form.
+ *
+ * Copied from the core theme_filter_admin_format_filter_order() function.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - element: A render element representing the form.
+ *
+ * @ingroup themeable
+ */
+function theme_site_map_order($variables) {
+ $element = $variables['element'];
+
+ // Site map order (tabledrag).
+ $rows = array();
+ foreach (element_children($element, TRUE) as $name) {
+ $element[$name]['weight']['#attributes']['class'][] = 'site-map-order-weight';
+ $rows[] = array(
+ 'data' => array(
+ drupal_render($element[$name]['content']),
+ drupal_render($element[$name]['weight']),
+ ),
+ 'class' => array('draggable'),
+ );
+ }
+ $output = drupal_render_children($element);
+ $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'site-map-order')));
+ drupal_add_tabledrag('site-map-order', 'order', 'sibling', 'site-map-order-weight', NULL, NULL, TRUE);
+
+ return $output;
+}
+