You are here

function system_theme_data in Drupal 4

Same name and namespace in other branches
  1. 5 modules/system/system.module \system_theme_data()
  2. 6 modules/system/system.module \system_theme_data()

Collect data about all currently available themes

2 calls to system_theme_data()
system_themes in modules/system.module
Menu callback; displays a listing of all themes.
system_theme_settings in modules/system.module
Menu callback; display theme configuration for entire site and individual themes.

File

modules/system.module, line 549
Configuration system that lets administrators modify the workings of the site.

Code

function system_theme_data() {

  // Find themes
  $themes = system_listing('\\.theme$', 'themes');

  // Find theme engines
  $engines = system_listing('\\.engine$', 'themes/engines');

  // can't iterate over array itself as it uses a copy of the array items
  foreach (array_keys($themes) as $key) {
    drupal_get_filename('theme', $themes[$key]->name, $themes[$key]->filename);
    drupal_load('theme', $themes[$key]->name);
    $themes[$key]->owner = $themes[$key]->filename;
    $themes[$key]->prefix = $key;
  }

  // Remove all theme engines from the system table
  db_query("DELETE FROM {system} WHERE type = 'theme_engine'");
  foreach ($engines as $engine) {

    // Insert theme engine into system table
    drupal_get_filename('theme_engine', $engine->name, $engine->filename);
    drupal_load('theme_engine', $engine->name);
    db_query("INSERT INTO {system} (name, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', %d, %d, %d)", $engine->name, 'theme_engine', $engine->filename, 1, 0, 0);

    // Add templates to the site listing
    foreach (call_user_func($engine->name . '_templates') as $template) {

      // Do not double-insert templates with theme files in their directory,
      // but do register their engine data.
      if (array_key_exists($template->name, $themes)) {
        $themes[$template->name]->template = TRUE;
        $themes[$template->name]->owner = $engine->filename;
        $themes[$template->name]->prefix = $engine->name;
      }
      else {
        $template->template = TRUE;
        $template->name = basename(dirname($template->filename));
        $template->owner = $engine->filename;
        $template->prefix = $engine->name;
        $themes[$template->name] = $template;
      }
    }
  }

  // Find styles in each theme's directory.
  foreach ($themes as $theme) {
    foreach (file_scan_directory(dirname($theme->filename), 'style.css$') as $style) {
      $style->style = TRUE;
      $style->template = isset($theme->template) ? $theme->template : FALSE;
      $style->name = basename(dirname($style->filename));
      $style->owner = $theme->filename;
      $style->prefix = $theme->template ? $theme->prefix : $theme->name;

      // do not double-insert styles with theme files in their directory
      if (array_key_exists($style->name, $themes)) {
        continue;
      }
      $themes[$style->name] = $style;
    }
  }

  // Extract current files from database.
  system_get_files_database($themes, 'theme');
  db_query("DELETE FROM {system} WHERE type = 'theme'");
  foreach ($themes as $theme) {
    db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, 'theme', $theme->filename, $theme->status, 0, 0);
  }
  return $themes;
}