You are here

function init_theme in Drupal 5

Same name and namespace in other branches
  1. 4 includes/theme.inc \init_theme()
  2. 6 includes/theme.inc \init_theme()

Initialize the theme system by loading the theme.

5 calls to init_theme()
block_admin_display in modules/block/block.module
Generate main block administration form.
path_to_engine in includes/theme.inc
Return the path to the currently selected engine.
path_to_theme in includes/theme.inc
Return the path to the currently selected theme.
theme_get_function in includes/theme.inc
Determine if a theme function exists, and if so return which one was found.
_block_rehash in modules/block/block.module
Update the 'blocks' DB table with the blocks currently exported by modules.

File

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

Code

function init_theme() {
  global $theme, $user, $custom_theme, $theme_engine, $theme_key;

  // If $theme is already set, assume the others are set, too, and do nothing
  if (isset($theme)) {
    return;
  }
  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  $themes = list_themes();

  // Only select the user selected theme if it is available in the
  // list of enabled themes.
  $theme = !empty($user->theme) && !empty($themes[$user->theme]->status) ? $user->theme : variable_get('theme_default', 'garland');

  // Allow modules to override the present theme... only select custom theme
  // if it is available in the list of installed themes.
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;

  // Store the identifier for retrieving theme settings with.
  $theme_key = $theme;

  // If we're using a style, load its appropriate theme,
  // which is stored in the style's description field.
  // Also add the stylesheet using drupal_add_css().
  // Otherwise, load the theme.
  if (strpos($themes[$theme]->filename, '.css')) {

    // File is a style; loads its CSS.
    // Set theme to its template/theme
    drupal_add_css($themes[$theme]->filename, 'theme');
    $theme = basename(dirname($themes[$theme]->description));
  }
  else {

    // File is a template/theme
    // Load its CSS, if it exists
    if (file_exists($stylesheet = dirname($themes[$theme]->filename) . '/style.css')) {
      drupal_add_css($stylesheet, 'theme');
    }
  }
  if (strpos($themes[$theme]->filename, '.theme')) {

    // file is a theme; include it
    include_once './' . $themes[$theme]->filename;
  }
  elseif (strpos($themes[$theme]->description, '.engine')) {

    // file is a template; include its engine
    include_once './' . $themes[$theme]->description;
    $theme_engine = basename($themes[$theme]->description, '.engine');
    if (function_exists($theme_engine . '_init')) {
      call_user_func($theme_engine . '_init', $themes[$theme]);
    }
  }
}