summaryrefslogtreecommitdiff
path: root/sites/all/modules/ctools/plugins/access/theme.inc
blob: 4f4be6ded916560a7da8873db4d1237aa4cc580d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

/**
 * @file
 * Plugin to provide access control based on user themeission strings.
 */

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = array(
  'title' => t("Current theme"),
  'description' => t('Control access by checking which theme is in use.'),
  'callback' => 'ctools_theme_ctools_access_check',
  'default' => array('theme' => variable_get('theme_default', 'garland')),
  'settings form' => 'ctools_theme_ctools_access_settings',
  'summary' => 'ctools_theme_ctools_access_summary',
);

/**
 * Settings form for the 'by theme' access plugin
 */
function ctools_theme_ctools_access_settings($form, &$form_state, $conf) {
  $themes = array();
  foreach (list_themes() as $key => $theme) {
    $themes[$key] = $theme->info['name'];
  }

  $form['settings']['theme'] = array(
    '#type' => 'select',
    '#options' => $themes,
    '#title' => t('Themes'),
    '#default_value' => $conf['theme'],
    '#description' => t('This will only be accessed if the current theme is the selected theme.'),
  );
  return $form;
}

/**
 * Check for access.
 */
function ctools_theme_ctools_access_check($conf, $context) {
  if (!empty($GLOBALS['theme'])) {
    $theme = $GLOBALS['theme'];
  }
  else if (!empty($GLOBALS['custom_theme'])) {
    $theme = $GLOBALS['custom_theme'];
  }
  else if (!empty($GLOBALS['user']->theme)) {
    $theme = $GLOBALS['user']->theme;
  }
  else {
    $theme = variable_get('theme_default', 'garland');
  }

  return $conf['theme'] == $theme;
}

/**
 * Provide a summary description based upon the checked roles.
 */
function ctools_theme_ctools_access_summary($conf, $context) {
  if (!isset($conf['theme'])) {
    return t('Error, unset theme');
  }
  $themes = list_themes();

  return t('Current theme is "@theme"', array('@theme' => $themes[$conf['theme']]->info['name']));
}