You are here

function ultimenu_get_skins in Ultimenu 7

Retrieves stored CSS files for Ultimenu skins.

Parameters

bool $refresh: If TRUE, reload the CSS and flush the cached version.

Return value

array An array of available CSS files.

1 call to ultimenu_get_skins()
_ultimenu_block_configure in includes/ultimenu.admin.inc
Implements hook_block_configure().

File

includes/ultimenu.utilities.inc, line 16
Misc functions that hardly change.

Code

function ultimenu_get_skins($refresh = FALSE) {
  $skins =& drupal_static(__FUNCTION__);
  if (!isset($skins) || $refresh) {
    if (!$refresh && ($cache = cache_get('ultimenu:skin'))) {
      $skins = $cache->data;
    }
    else {
      $theme_skin = drupal_get_path('theme', variable_get('theme_default', 'bartik')) . '/css/ultimenu';
      $custom_skin = ultimenu_get_settings('skins');
      $module_skin = drupal_get_path('module', 'ultimenu') . '/skins';
      $mask = '/.css$/';
      $files = array();
      if (is_dir($module_skin)) {
        foreach (file_scan_directory($module_skin, $mask) as $filename => $file) {
          $files[$filename] = $file;
        }
      }
      if (!empty($custom_skin) && is_dir($custom_skin)) {
        foreach (file_scan_directory($custom_skin, $mask) as $filename => $file) {
          $files[$filename] = $file;
        }
      }
      if (is_dir($theme_skin)) {
        foreach (file_scan_directory($theme_skin, $mask) as $filename => $file) {
          $files[$filename] = $file;
        }
      }
      if ($files) {
        $skins = array();
        foreach ($files as $file) {
          $uri = $file->uri;

          // Simplify lengthy deep directory structure.
          if (strpos($uri, $module_skin) !== FALSE) {
            $uri = str_replace($module_skin . '/', "module|", $uri);
          }
          elseif (strpos($uri, $custom_skin) !== FALSE) {
            $uri = str_replace($custom_skin . '/', "custom|", $uri);
          }
          elseif (strpos($uri, $theme_skin) !== FALSE) {
            $uri = str_replace($theme_skin . '/', "theme|", $uri);
          }

          // Convert file name to CSS friendly for option label and styling.
          $skins[$uri] = drupal_html_class($file->name);
        }
        cache_set('ultimenu:skin', $skins, 'cache');
      }
    }
  }
  return $skins;
}