1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugin to provide access control based upon node type.
|
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
|
if (module_exists('locale')) {
|
13
|
$plugin = array(
|
14
|
'title' => t("User: language"),
|
15
|
'description' => t('Control access by the language the user or site currently uses.'),
|
16
|
'callback' => 'ctools_site_language_ctools_access_check',
|
17
|
'default' => array('language' => array()),
|
18
|
'settings form' => 'ctools_site_language_ctools_access_settings',
|
19
|
'settings form submit' => 'ctools_site_language_ctools_access_settings_submit',
|
20
|
'summary' => 'ctools_site_language_ctools_access_summary',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Settings form for the 'by site_language' access plugin.
|
26
|
*/
|
27
|
function ctools_site_language_ctools_access_settings($form, &$form_state, $conf) {
|
28
|
$options = array(
|
29
|
'default' => t('Default site language'),
|
30
|
);
|
31
|
$options = array_merge($options, locale_language_list());
|
32
|
$form['settings']['language'] = array(
|
33
|
'#title' => t('Language'),
|
34
|
'#type' => 'checkboxes',
|
35
|
'#options' => $options,
|
36
|
'#description' => t('Pass only if the current site language is one of the selected languages.'),
|
37
|
'#default_value' => $conf['language'],
|
38
|
);
|
39
|
return $form;
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Check for access.
|
44
|
*/
|
45
|
function ctools_site_language_ctools_access_check($conf, $context) {
|
46
|
global $language;
|
47
|
|
48
|
// Specialcase: If 'default' is checked, return TRUE if the default site language
|
49
|
// matches the node language.
|
50
|
if (!empty($conf['language']['default'])) {
|
51
|
if ($language->language == language_default('language')) {
|
52
|
return TRUE;
|
53
|
}
|
54
|
}
|
55
|
|
56
|
if (array_filter($conf['language']) && empty($conf['language'][$language->language])) {
|
57
|
return FALSE;
|
58
|
}
|
59
|
|
60
|
return TRUE;
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Provide a summary description based upon the checked site_languages.
|
65
|
*/
|
66
|
function ctools_site_language_ctools_access_summary($conf, $context) {
|
67
|
$languages = array(
|
68
|
'default' => t('Default site language'),
|
69
|
);
|
70
|
$languages = array_merge($languages, locale_language_list());
|
71
|
|
72
|
if (!isset($conf['language'])) {
|
73
|
$conf['language'] = array();
|
74
|
}
|
75
|
|
76
|
$names = array();
|
77
|
foreach (array_filter($conf['language']) as $language) {
|
78
|
$names[] = $languages[$language];
|
79
|
}
|
80
|
|
81
|
if (empty($names)) {
|
82
|
return t('Site language is any language');
|
83
|
}
|
84
|
|
85
|
return format_plural(count($names), 'Site language is "@languages"', 'Site language is one of "@languages"', array('@languages' => implode(', ', $names)));
|
86
|
}
|