init_theme

Versions
4.6 – 6
init_theme()

Initialize the theme system by loading the theme.

Return value

The name of the currently selected theme.

▾ 1 function calls init_theme()

theme in includes/theme.inc
Generate the themed representation of a Drupal object.

Code

includes/theme.inc, line 47

<?php
function init_theme() {
  global $user, $custom_theme, $theme_engine, $theme_key;

  $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 drupal_set_html_head().
  // 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]);
    }
  }

  return $theme;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.