Fix for Patch to site_map

  1. diff -up site_map/README.txt site_map/README.txt
  2. --- site_map/README.txt 2009-09-07 16:37:09.000000000 +0200
  3. +++ site_map/README.txt 2009-09-16 20:11:03.000000000 +0200
  4. @@ -41,6 +41,21 @@ Installation:
  5.  6. Visit http://example.com/sitemap.
  6.  
  7.  
  8. +Adding your own CSS skins:
  9. +-------------------------
  10. +If you want to add your own CSS to your site map, create a directory
  11. +at sites/all/libraries/site_map/css
  12. +
  13. +Any .css files you place in this directory will be available to select,
  14. +next to 'default' and 'none', in Administer -> Site configuration -> Site map
  15. +
  16. +A good example is the slick-map.css file you can find in this issue:
  17. +http://drupal.org/node/514436
  18. +
  19. +If you do not create the directory, the module still functions but your
  20. +only CSS options are either 'none' or 'default'.
  21. +
  22. +
  23.  Site map term path (and Pathauto):
  24.  -------------------------------
  25.  There is a "depth" setting on the Site map settings page where you can adjust
  26. diff -up site_map/site_map.admin.inc site_map/site_map.admin.inc
  27. --- site_map/site_map.admin.inc 2009-06-29 21:12:54.000000000 +0200
  28. +++ site_map/site_map.admin.inc 2009-09-16 20:00:50.000000000 +0200
  29. @@ -125,12 +125,29 @@ function site_map_admin_settings() {
  30.      '#multiple' => TRUE,
  31.      '#description' => t('Ctrl-click (Windows) or Command-click (Mac) to select more than one value.'),
  32.    );
  33. -  $form['site_map_content']['site_map_css'] = array(
  34. -    '#type' => 'checkbox',
  35. -    '#title' => t('Do not include site map CSS file'),
  36. -    '#default_value' => variable_get('site_map_css', 0),
  37. -    '#description' => t('If you don\'t want to load the included CSS file you can check this box.'),
  38. -  );
  39. +  // CSS selector
  40. +  if (_site_map_get_css()) {
  41. +    // call helper function in site_map.module to get CSS files
  42. +    $css_options = _site_map_get_css();
  43. +    array_unshift($css_options, 'none', 'default');
  44. +    $form['site_map_content']['site_map_css_selector'] = array(
  45. +      '#type' => 'select',
  46. +      '#title' => t('Site map CSS file'),
  47. +      '#default_value' => variable_get('site_map_css_selector', 1),
  48. +      '#options' => $css_options,
  49. +      '#description' => t('Select a CSS file to use for your site map.'),
  50. +    );
  51. +  }
  52. +  else {
  53. +    $css_options = array('none', 'default');
  54. +    $form['site_map_content']['site_map_css_selector'] = array(
  55. +      '#type' => 'select',
  56. +      '#title' => t('Site map CSS file'),
  57. +      '#default_value' => variable_get('site_map_css_selector', 1),
  58. +      '#options' => $css_options,
  59. +      '#description' => t('Select a CSS file to use for your site map.'),
  60. +    );
  61. +  }
  62.  
  63.    $form['site_map_taxonomy_options'] = array(
  64.      '#type' => 'fieldset',
  65. diff -up site_map/site_map.install site_map/site_map.install
  66. --- site_map/site_map.install   2009-06-29 21:12:54.000000000 +0200
  67. +++ site_map/site_map.install   2009-09-16 20:04:59.000000000 +0200
  68. @@ -20,6 +20,7 @@ function site_map_uninstall() {
  69.    variable_del('site_map_css');
  70.    variable_del('site_map_term_threshold');
  71.    variable_del('site_map_forum_threshold');
  72. +  variable_del('site_map_css_selector');
  73.  
  74.    if (function_exists('locale')) {
  75.      $langs = locale_language_list();
  76. diff -up site_map/site_map.module site_map/site_map.module
  77. --- site_map/site_map.module    2009-08-21 08:58:49.000000000 +0200
  78. +++ site_map/site_map.module    2009-09-16 19:48:21.000000000 +0200
  79. @@ -96,8 +96,17 @@ function site_map_block($op = 'list', $d
  80.   * Menu callback for the site map.
  81.   */
  82.  function site_map_page() {
  83. -  if (variable_get('site_map_css', 0) != 1) {
  84. -    drupal_add_css(drupal_get_path('module', 'site_map') .'/site_map.css');
  85. +  // make sure we haven't set the value 'none' in admin
  86. +  if (variable_get('site_map_css_selector', 1) != '0') {
  87. +    // if specified, use default site map CSS
  88. +    if (variable_get('site_map_css_selector', 1) == '1') {
  89. +      drupal_add_css(drupal_get_path('module', 'site_map') .'/site_map.css');
  90. +    }
  91. +    // otherwise, load selected css file from libraries
  92. +    else {
  93. +      $path = 'sites/all/libraries/site_map/css/' . variable_get('site_map_css_selector', 1);
  94. +      drupal_add_css($path);
  95. +    }
  96.    }
  97.  
  98.    return theme('site_map_display');
  99. @@ -534,3 +543,32 @@ function _sitemap_get_message($lang_code
  100.  
  101.    return $message;
  102.  }
  103. +
  104. +/**
  105. + * Load CSS files from sites/all/libraries/site_map/css
  106. + *
  107. + * @return
  108. + * Array of CSS files available or FALSE if directory does not exist.
  109. + */
  110. +function _site_map_get_css() {
  111. +  $path = realpath('./') . '/sites/all/libraries/site_map/css';
  112. +  // make sure the css directory exists
  113. +  if (is_dir($path)) {
  114. +    if ($handle = opendir($path)) {
  115. +      $css = array();
  116. +      // loop through all files
  117. +      while (false !== ($file = readdir($handle))) {
  118. +        // we only want .css files
  119. +        if (substr($file, -4, 4) == '.css') {
  120. +          // build array of available files
  121. +          $css[$file] = $file;
  122. +        }
  123. +      }
  124. +      closedir($handle);
  125. +      return $css;
  126. +    }
  127. +  }
  128. +  else {
  129. +    return FALSE;
  130. +  }
  131. +}
  132. Common subdirectories: site_map/translations and site_map/translations

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.