1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Plugin to provide access control based upon term vocabulary
|
6 |
|
|
*/
|
7 |
13c3c9b4
|
Assos Assos
|
|
8 |
85ad3d82
|
Assos Assos
|
/**
|
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("Forum: container"),
|
14 |
|
|
'description' => t('Control access by whether or not the forum is a container.'),
|
15 |
|
|
'callback' => 'advanced_forum_forum_container_ctools_access_check',
|
16 |
|
|
'default' => array('container' => 0),
|
17 |
|
|
'settings form' => 'advanced_forum_forum_container_ctools_access_settings',
|
18 |
|
|
'settings form submit' => 'advanced_forum_forum_container_ctools_access_settings_submit',
|
19 |
|
|
'summary' => 'advanced_forum_forum_container_ctools_acesss_summary',
|
20 |
|
|
'required context' => new ctools_context_required(t('Forum'), array('forum')),
|
21 |
|
|
);
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
13c3c9b4
|
Assos Assos
|
* Settings form for the 'by term_vocabulary' access plugin.
|
25 |
85ad3d82
|
Assos Assos
|
*/
|
26 |
|
|
function advanced_forum_forum_container_ctools_access_settings($form, &$form_state, $conf) {
|
27 |
|
|
$form['settings']['container'] = array(
|
28 |
|
|
'#type' => 'select',
|
29 |
|
|
'#title' => t('Container'),
|
30 |
|
|
'#options' => array(
|
31 |
|
|
0 => t('Pass if forum is a container'),
|
32 |
13c3c9b4
|
Assos Assos
|
1 => t('Pass if forum is not a container'),
|
33 |
85ad3d82
|
Assos Assos
|
),
|
34 |
|
|
'#default_value' => $conf['container'],
|
35 |
|
|
);
|
36 |
|
|
|
37 |
|
|
return $form;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Compress the term_vocabularys allowed to the minimum.
|
42 |
|
|
*/
|
43 |
|
|
function advanced_forum_forum_container_ctools_access_settings_submit($form, &$form_state) {
|
44 |
|
|
$form_state['values']['settings']['rids'] = array_keys(array_filter($form_state['values']['settings']['rids']));
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Check for access.
|
49 |
|
|
*/
|
50 |
|
|
function advanced_forum_forum_container_ctools_access_check($conf, $context) {
|
51 |
|
|
// As far as I know there should always be a context at this point, but this
|
52 |
|
|
// is safe.
|
53 |
|
|
if (empty($context) || empty($context->data)) {
|
54 |
|
|
return FALSE;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
13c3c9b4
|
Assos Assos
|
// Xor returns false if the two bools are the same, and true if they are not.
|
58 |
85ad3d82
|
Assos Assos
|
return $context->data->container xor !empty($conf['container']);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Provide a summary description based upon the checked term_vocabularys.
|
63 |
|
|
*/
|
64 |
|
|
function advanced_forum_forum_container_ctools_acesss_summary($conf, $context) {
|
65 |
|
|
$comparison = empty($conf['container']) ? "is" : 'is not';
|
66 |
|
|
|
67 |
|
|
return t('@id1 @comp a forum container', array('@comp' => $comparison, '@id1' => $context->identifier));
|
68 |
|
|
} |