You are here

function themekey_check_theme_enabled in ThemeKey 7.2

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. 6.3 themekey_base.inc \themekey_check_theme_enabled()
  4. 7.3 themekey.module \themekey_check_theme_enabled()
  5. 7 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

6 calls to themekey_check_theme_enabled()
themekey_blog_author2theme in modules/themekey.blog.inc
This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.
themekey_match_rule_childs in ./themekey_base.inc
Helper function of
themekey_rule_chain_form_validate in ./themekey_admin.inc
Validation 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 Drupal static themekey_custom_theme 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 Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.

... See full list

File

./themekey_base.inc, line 544
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_select('system', 's')
      ->fields('s', array(
      'name',
    ))
      ->condition('type', 'theme')
      ->condition('status', '1')
      ->execute()) {
      foreach ($result as $row) {
        $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(filter_xss(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/appearance',
        )), 'admin/appearance'),
      ))), 'error');
      $displayed_error = TRUE;
    }
  }
  else {
    if (!$warned && variable_get('themekey_debug_trace_rule_switching', FALSE)) {

      // Don't use the l() function at this early stage of bootstrapping because it will initialize the theme engine. Use url() instead.
      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 the current node if the theme was selected using ThemeKey UI.', array(
        '%theme' => $theme,
        '!build_themes' => '<a href="' . url('admin/appearance') . '">admin/appearance</a>',
        '!themekey_properties' => '<a href="' . url('admin/config/user-interface/themekey/properties') . '">admin/config/user-interface/themekey/properties</a>',
      ));
      $warned = TRUE;
    }
  }
  return FALSE;
}