You are here

themekey.module in ThemeKey 6

File

themekey.module
View source
<?php

require_once drupal_get_path('module', 'themekey') . '/themekey_base.inc';

/**
 * Implementation of hook_theme()
 */
function themekey_theme() {
  return array(
    'themekey_table' => array(
      'arguments' => array(
        'form' => NULL,
      ),
    ),
  );
}

/**
 * Implementation of hook_perm().
 */
function themekey_perm() {
  return array(
    'administer theme assignments',
    'administer themekey settings',
  );
}

/**
 * Implementation of hook_menu().
 */
function themekey_menu() {
  $items = array();
  $items['admin/settings/themekey'] = array(
    'title' => 'ThemeKey',
    'description' => 'Map themes to Drupal paths or object properties.',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer theme assignments',
    ),
    'file' => 'themekey_admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_themekey_paths_form',
    ),
  );
  $items['admin/settings/themekey/paths'] = array(
    'title' => 'Paths',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
  );
  $items['admin/settings/themekey/properties'] = array(
    'title' => 'Properties',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer theme assignments',
    ),
    'file' => 'themekey_admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_themekey_properties_form',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  );
  $items['admin/settings/themekey/settings'] = array(
    'title' => 'Settings',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer themekey settings',
    ),
    'file' => 'themekey_admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_themekey_settings_form',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 5,
  );
  $items['admin/settings/themekey/settings/general'] = array(
    'title' => 'General',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
  );
  return $items;
}

/**
 * Implementation of hook_themekey_properties().
 */
function themekey_themekey_properties() {
  require_once drupal_get_path('module', 'themekey') . '/themekey_build.inc';
  return _themekey_invoke_modules('themekey_properties');
}

/**
 * Implementation of hook_themekey_global().
 */
function themekey_themekey_global() {
  require_once drupal_get_path('module', 'themekey') . '/themekey_build.inc';
  return _themekey_invoke_modules('themekey_global');
}

/**
 * Implementation of hook_themekey_paths().
 */
function themekey_themekey_paths() {
  require_once drupal_get_path('module', 'themekey') . '/themekey_build.inc';
  return _themekey_invoke_modules('themekey_paths');
}

/**
 * Implementation of hook_init().
 */
function themekey_init() {
  global $custom_theme;
  $theme = NULL;

  // Try to get theme for the normal Drupal path
  $theme = _themekey_match_paths($_GET['q']);
  if (!$theme) {

    // Derive path from request_uri
    $offset = (variable_get('clean_url', 0) ? 0 : 3) + strlen(base_path());
    $alias_uri = substr(request_uri(), $offset);

    // For $alias_uri != $_GET['q'] the page was requested using an
    // aliased path, otherwise get the path alias internally
    if ($alias_uri == $_GET['q'] && module_exists('path')) {
      $alias_uri = drupal_get_path_alias($_GET['q']);
    }

    // Try to get the theme for the aliased Drupal path
    $theme = _themekey_match_paths($alias_uri);
  }

  // If no theme has been triggered but a theme
  // is in the user's session, use that theme.
  if (!$theme && isset($_SESSION['themekey_theme']) && (!$custom_theme || $custom_theme == variable_get('theme_default', 'bluemarine'))) {
    $custom_theme = $_SESSION['themekey_theme'];
  }

  // We have a theme, apply it
  if ($theme && $theme != 'default') {
    if (variable_get('themekey_theme_maintain', 0)) {
      $_SESSION['themekey_theme'] = $theme;
    }
    $custom_theme = $theme;
    init_theme();
  }
}

Functions

Namesort descending Description
themekey_init Implementation of hook_init().
themekey_menu Implementation of hook_menu().
themekey_perm Implementation of hook_perm().
themekey_theme Implementation of hook_theme()
themekey_themekey_global Implementation of hook_themekey_global().
themekey_themekey_paths Implementation of hook_themekey_paths().
themekey_themekey_properties Implementation of hook_themekey_properties().