You are here

function themekey_check_theme_enabled in ThemeKey 6.3

Same name and namespace in other branches
  1. 6.4 themekey_base.inc \themekey_check_theme_enabled()
  2. 6.2 themekey_base.inc \themekey_check_theme_enabled()
  3. 7.3 themekey.module \themekey_check_theme_enabled()
  4. 7 themekey_base.inc \themekey_check_theme_enabled()
  5. 7.2 themekey_base.inc \themekey_check_theme_enabled()

Checks if a theme is enabled and fires warning messages to the site's administrator

Parameters

$theme: name of the theme as string

$settings_page: boolean that indicates if the function is called from ThemeKey's administration backend which causes a different message

Return value

TRUE if the theme is enabled, otherwise FALSE

4 calls to themekey_check_theme_enabled()
themekey_form_alter in ./themekey_admin.inc
Implements hook_form_alter().
themekey_match_rule_childs in ./themekey_base.inc
Helper function of
themekey_ui_author2theme in ./themekey_ui.module
This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the global variable $custom_theme to a theme directly which will cause ThemeKey to use this theme.
themekey_ui_nid2theme in ./themekey_ui.module
This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the global variable $custom_theme to a theme directly, which will cause ThemeKey to use this theme.

File

./themekey_base.inc, line 475
The functions in this file are the back end of ThemeKey.

Code

function themekey_check_theme_enabled($theme, $settings_page = FALSE) {
  static $themes_enabled = array();
  static $warned = FALSE;
  static $displayed_error = FALSE;
  if (!$theme || 'default' == $theme) {
    return TRUE;
  }
  if (empty($themes_enabled)) {
    if ($result = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1;")) {
      while ($row = db_fetch_array($result)) {
        $themes_enabled[] = $row['name'];
      }
    }
  }
  if (in_array($theme, $themes_enabled)) {
    return TRUE;
  }
  elseif ('ThemeKeyAdminTheme' == $theme && variable_get('admin_theme', '0') && in_array(variable_get('admin_theme', '0'), $themes_enabled)) {
    return TRUE;
  }
  if ($settings_page) {
    if (!$displayed_error) {
      drupal_set_message(t("Your current configuration of theme rules uses at least one theme that is not enabled. Nevertheless, this configuration is stored, but affected rules won't be applied until the targeted theme is enabled at !build_themes.", array(
        '!build_themes' => l(t('!path', array(
          '!path' => 'admin/build/themes',
        )), 'admin/build/themes'),
      )), 'error');
      $displayed_error = TRUE;
    }
  }
  else {
    if (!$warned && variable_get('themekey_debug_trace_rule_switching', FALSE)) {
      themekey_set_debug_message('A matching Theme Switching Rule to select theme %theme was not applied because this theme is disabled. You can enable this theme at !build_themes, remove this Theme Switching Rule at !themekey_properties, or edit current node if the theme was selected using ThemeKey UI.', array(
        '%theme' => $theme,
        '!build_themes' => l(t('!path', array(
          '!path' => 'admin/build/themes',
        )), 'admin/build/themes'),
        '!themekey_properties' => l(t('!path', array(
          '!path' => 'admin/settings/themekey/properties',
        )), 'admin/settings/themekey/properties'),
      ));
      $warned = TRUE;
    }
  }
  return FALSE;
}