You are here

function init_theme in Drupal 4

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

Initialize the theme system by loading the theme.

3 calls to init_theme()
block_admin_display in modules/block.module
Generate main block administration form.
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.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 = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'bluemarine');

  // 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 load the stylesheet using theme_add_style().
  // Otherwise, load the theme.
  if (strpos($themes[$theme]->filename, '.css')) {

    // File is a style; loads its CSS.
    // Set theme to its template/theme
    theme_add_style($themes[$theme]->filename);
    $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')) {
      theme_add_style($stylesheet);
    }
  }
  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]);
    }
  }
}