1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugin to provide a user context
|
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("Forum"),
|
14
|
'description' => t('A single forum object.'),
|
15
|
'context' => 'advanced_forum_forum_context_create_forum',
|
16
|
'settings form' => 'advanced_forum_forum_context_settings_form',
|
17
|
'settings form validate' => 'advanced_forum_forum_context_settings_form_validate',
|
18
|
'keyword' => 'forum',
|
19
|
'context name' => 'forum',
|
20
|
'convert list' => array(
|
21
|
'tid' => t('Forum ID'),
|
22
|
'name' => t('Forum name'),
|
23
|
),
|
24
|
'convert' => 'advanced_forum_forum_context_convert',
|
25
|
'defaults' => array('tid' => 0),
|
26
|
);
|
27
|
|
28
|
/**
|
29
|
* Create a context, either from manual configuration or from an argument on the URL.
|
30
|
*
|
31
|
* @param bool $empty
|
32
|
* If true, just return an empty context.
|
33
|
*
|
34
|
* @param array|null $data
|
35
|
* If from settings form, an array as from a form. If from argument, a string.
|
36
|
*
|
37
|
* @param array|bool $conf
|
38
|
* TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg.
|
39
|
*
|
40
|
* @return object.
|
41
|
* a Context object.
|
42
|
*/
|
43
|
function advanced_forum_forum_context_create_forum($empty, $data = NULL, $conf = FALSE) {
|
44
|
$context = new ctools_context(array('forum', 'term'));
|
45
|
$context->plugin = 'forum';
|
46
|
|
47
|
if ($empty) {
|
48
|
return $context;
|
49
|
}
|
50
|
|
51
|
if ($conf) {
|
52
|
if (!empty($data['tid'])) {
|
53
|
$data = taxonomy_term_load($data['tid']);
|
54
|
}
|
55
|
else {
|
56
|
$data = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0));
|
57
|
$data->tid = 0;
|
58
|
}
|
59
|
}
|
60
|
|
61
|
if (!empty($data)) {
|
62
|
$data->container = (!$data->tid || in_array($data->tid, variable_get('forum_containers', array())));
|
63
|
$context->data = clone $data;
|
64
|
$context->title = $data->name;
|
65
|
$context->argument = $data->tid;
|
66
|
$context->vid = variable_get('forum_nav_vocabulary', '');
|
67
|
$context->vocabulary = taxonomy_vocabulary_load($context->vid);
|
68
|
if ($data->tid) {
|
69
|
$context->parents = taxonomy_get_parents_all($data->tid);
|
70
|
}
|
71
|
|
72
|
return $context;
|
73
|
}
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Context settings form.
|
78
|
*/
|
79
|
function advanced_forum_forum_context_settings_form($form, &$form_state) {
|
80
|
$conf = $form_state['conf'];
|
81
|
|
82
|
if (empty($conf)) {
|
83
|
$conf = array('tid' => 0);
|
84
|
}
|
85
|
|
86
|
$options = array();
|
87
|
$vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0));
|
88
|
$options[$vocabulary->vid] = $vocabulary->name;
|
89
|
|
90
|
$tree = taxonomy_get_tree($vocabulary->vid);
|
91
|
if ($tree) {
|
92
|
foreach ($tree as $term) {
|
93
|
$choice = new stdClass();
|
94
|
$choice->option = array($term->tid => str_repeat('-', $term->depth + 1) . $term->name);
|
95
|
$options[] = $choice;
|
96
|
}
|
97
|
}
|
98
|
|
99
|
$form['tid'] = array(
|
100
|
'#type' => 'select',
|
101
|
'#title' => t('Forum'),
|
102
|
'#default_value' => $conf['tid'],
|
103
|
'#options' => $options,
|
104
|
);
|
105
|
|
106
|
return $form;
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Convert a context into a string.
|
111
|
*/
|
112
|
function advanced_forum_forum_context_convert($context, $type) {
|
113
|
switch ($type) {
|
114
|
case 'tid':
|
115
|
return $context->data->tid;
|
116
|
|
117
|
case 'name':
|
118
|
$forum_term = $context->data;
|
119
|
|
120
|
if (module_exists('i18n_taxonomy')) {
|
121
|
$forum_term = i18n_taxonomy_localize_terms($forum_term);
|
122
|
}
|
123
|
|
124
|
return $forum_term->name;
|
125
|
}
|
126
|
}
|