1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Plugin to provide access control based on user themeission strings.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
10 |
|
|
* by the system that includes this file.
|
11 |
|
|
*/
|
12 |
|
|
$plugin = array(
|
13 |
|
|
'title' => t("Current theme"),
|
14 |
|
|
'description' => t('Control access by checking which theme is in use.'),
|
15 |
|
|
'callback' => 'ctools_theme_ctools_access_check',
|
16 |
|
|
'default' => array('theme' => variable_get('theme_default', 'garland')),
|
17 |
|
|
'settings form' => 'ctools_theme_ctools_access_settings',
|
18 |
|
|
'summary' => 'ctools_theme_ctools_access_summary',
|
19 |
|
|
);
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
c304a780
|
Assos Assos
|
* Settings form for the 'by theme' access plugin.
|
23 |
85ad3d82
|
Assos Assos
|
*/
|
24 |
|
|
function ctools_theme_ctools_access_settings($form, &$form_state, $conf) {
|
25 |
|
|
$themes = array();
|
26 |
|
|
foreach (list_themes() as $key => $theme) {
|
27 |
|
|
$themes[$key] = $theme->info['name'];
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
$form['settings']['theme'] = array(
|
31 |
|
|
'#type' => 'select',
|
32 |
|
|
'#options' => $themes,
|
33 |
|
|
'#title' => t('Themes'),
|
34 |
|
|
'#default_value' => $conf['theme'],
|
35 |
|
|
'#description' => t('This will only be accessed if the current theme is the selected theme.'),
|
36 |
|
|
);
|
37 |
|
|
return $form;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Check for access.
|
42 |
|
|
*/
|
43 |
|
|
function ctools_theme_ctools_access_check($conf, $context) {
|
44 |
|
|
if (!empty($GLOBALS['theme'])) {
|
45 |
|
|
$theme = $GLOBALS['theme'];
|
46 |
|
|
}
|
47 |
c304a780
|
Assos Assos
|
elseif (!empty($GLOBALS['custom_theme'])) {
|
48 |
85ad3d82
|
Assos Assos
|
$theme = $GLOBALS['custom_theme'];
|
49 |
|
|
}
|
50 |
c304a780
|
Assos Assos
|
elseif (!empty($GLOBALS['user']->theme)) {
|
51 |
85ad3d82
|
Assos Assos
|
$theme = $GLOBALS['user']->theme;
|
52 |
|
|
}
|
53 |
|
|
else {
|
54 |
|
|
$theme = variable_get('theme_default', 'garland');
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
return $conf['theme'] == $theme;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* Provide a summary description based upon the checked roles.
|
62 |
|
|
*/
|
63 |
|
|
function ctools_theme_ctools_access_summary($conf, $context) {
|
64 |
|
|
if (!isset($conf['theme'])) {
|
65 |
|
|
return t('Error, unset theme');
|
66 |
|
|
}
|
67 |
|
|
$themes = list_themes();
|
68 |
|
|
|
69 |
|
|
return t('Current theme is "@theme"', array('@theme' => $themes[$conf['theme']]->info['name']));
|
70 |
|
|
} |