Same name and namespace in other branches
  1. 4.6.x includes/theme.inc \list_themes()
  2. 4.7.x includes/theme.inc \list_themes()
  3. 5.x includes/theme.inc \list_themes()
  4. 7.x includes/theme.inc \list_themes()

Provides a list of currently available themes.

If the database is active then it will be retrieved from the database. Otherwise it will retrieve a new list.

Parameters

$refresh: Whether to reload the list of themes from the database.

Return value

An array of the currently available themes.

8 calls to list_themes()
color_form_alter in modules/color/color.module
Implementation of hook_form_alter().
init_theme in includes/theme.inc
Initialize the theme system by loading the theme.
system_themes_form_submit in modules/system/system.admin.inc
Process system_themes_form form submissions.
system_theme_select_form in modules/system/system.module
Returns a fieldset containing the theme select form.
system_update_6042 in modules/system/system.install
Upgrade recolored theme stylesheets to new array structure.

... See full list

File

includes/theme.inc, line 470
The theme system, which controls the output of Drupal.

Code

function list_themes($refresh = FALSE) {
  static $list = array();
  if ($refresh) {
    $list = array();
  }
  if (empty($list)) {
    $list = array();
    $themes = array();

    // Extract from the database only when it is available.
    // Also check that the site is not in the middle of an install or update.
    if (db_is_active() && !defined('MAINTENANCE_MODE')) {
      $result = db_query("SELECT * FROM {system} WHERE type = '%s'", 'theme');
      while ($theme = db_fetch_object($result)) {
        if (file_exists($theme->filename)) {
          $theme->info = unserialize($theme->info);
          $themes[] = $theme;
        }
      }
    }
    else {

      // Scan the installation when the database should not be read.
      $themes = _system_theme_data();
    }
    foreach ($themes as $theme) {
      foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
        foreach ($stylesheets as $stylesheet => $path) {
          $theme->stylesheets[$media][$stylesheet] = $path;
        }
      }
      foreach ($theme->info['scripts'] as $script => $path) {
        if (file_exists($path)) {
          $theme->scripts[$script] = $path;
        }
      }
      if (isset($theme->info['engine'])) {
        $theme->engine = $theme->info['engine'];
      }
      if (isset($theme->info['base theme'])) {
        $theme->base_theme = $theme->info['base theme'];
      }

      // Status is normally retrieved from the database. Add zero values when
      // read from the installation directory to prevent notices.
      if (!isset($theme->status)) {
        $theme->status = 0;
      }
      $list[$theme->name] = $theme;
    }
  }
  return $list;
}