1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
*/
|
6
|
|
7
|
if (module_exists('profile') && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') && !is_null(profile_user_categories())) {
|
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
|
'single' => TRUE,
|
14
|
'title' => t('Profile category'),
|
15
|
'icon' => 'icon_user.png',
|
16
|
'description' => t('Contents of a single profile category.'),
|
17
|
'required context' => new ctools_context_required(t('User'), 'user'),
|
18
|
'category' => t('User'),
|
19
|
'defaults' => array('category' => '', 'empty' => ''),
|
20
|
'hook theme' => 'ctools_profile_fields_content_type_theme',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* 'Render' callback for the 'profile fields' content type.
|
26
|
*/
|
27
|
function ctools_profile_fields_content_type_render($subtype, $conf, $panel_args, $context) {
|
28
|
$account = isset($context->data) ? clone $context->data : NULL;
|
29
|
$block = new stdClass();
|
30
|
$block->module = 'profile fields';
|
31
|
|
32
|
if ($account) {
|
33
|
// Get the category from the options.
|
34
|
$category = str_replace("_", " ", $conf['category']);
|
35
|
|
36
|
// Set the subject to the name of the category.
|
37
|
$block->subject = $category;
|
38
|
|
39
|
// Put all the fields in the category into an array.
|
40
|
profile_view_profile($account);
|
41
|
|
42
|
if (is_array($account->content[$category])) {
|
43
|
foreach ($account->content[$category] as $field) {
|
44
|
if (is_array($field['#attributes'])) {
|
45
|
// @todo 'class' is *always* an array now. 04/10/2009 sun
|
46
|
$vars[$field['#attributes']['class']]['title'] = $field['#title'];
|
47
|
$vars[$field['#attributes']['class']]['value'] = $field['#value'];
|
48
|
}
|
49
|
}
|
50
|
}
|
51
|
|
52
|
if (count($vars) == 0) {
|
53
|
// Output the given empty text.
|
54
|
$output = $conf['empty'];
|
55
|
}
|
56
|
else {
|
57
|
// Call the theme function with the field vars.
|
58
|
$output = theme('profile_fields_pane', $category, $vars);
|
59
|
}
|
60
|
|
61
|
$block->content = $output;
|
62
|
$block->delta = $account->uid;
|
63
|
}
|
64
|
else {
|
65
|
$block->subject = $conf['category'];
|
66
|
$block->content = t('Profile content goes here.');
|
67
|
$block->delta = 'unknown';
|
68
|
}
|
69
|
|
70
|
return $block;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Helper function : build the list of categories for the 'edit' form.
|
75
|
*/
|
76
|
function _ctools_profile_fields_options() {
|
77
|
$cat_list = array();
|
78
|
|
79
|
$categories = profile_categories();
|
80
|
foreach ($categories as $key => $value) {
|
81
|
$cat_list[str_replace(" ", "_", $value['name'])] = $value['title'];
|
82
|
}
|
83
|
|
84
|
return $cat_list;
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* 'Edit' callback for the 'profile fields' content type.
|
89
|
*/
|
90
|
function ctools_profile_fields_content_type_edit_form($form, &$form_state) {
|
91
|
$conf = $form_state['conf'];
|
92
|
$form['category'] = array(
|
93
|
'#type' => 'radios',
|
94
|
'#title' => t('Which category'),
|
95
|
'#options' => _ctools_profile_fields_options(),
|
96
|
'#default_value' => $conf['category'],
|
97
|
'#prefix' => '<div class="clearfix no-float">',
|
98
|
'#suffix' => '</div>',
|
99
|
);
|
100
|
|
101
|
$form['empty'] = array(
|
102
|
'#type' => 'textarea',
|
103
|
'#title' => 'Empty text',
|
104
|
'#description' => t('Text to display if category has no data. Note that title will not display unless overridden.'),
|
105
|
'#rows' => 5,
|
106
|
'#default_value' => $conf['empty'],
|
107
|
'#prefix' => '<div class="clearfix no-float">',
|
108
|
'#suffix' => '</div>',
|
109
|
);
|
110
|
|
111
|
return $form;
|
112
|
}
|
113
|
|
114
|
function ctools_profile_fields_content_type_edit_form_submit($form, &$form_state) {
|
115
|
// Copy everything from our defaults.
|
116
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
117
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
118
|
}
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* 'Title' callback for the 'profile fields' content type.
|
123
|
*/
|
124
|
function ctools_profile_fields_content_type_admin_title($subtype, $conf, $context) {
|
125
|
return t('"@s" profile fields', array('@s' => $conf['category']));
|
126
|
}
|
127
|
|
128
|
function ctools_profile_fields_content_type_theme(&$theme, $plugin) {
|
129
|
$theme['profile_fields_pane'] = array(
|
130
|
'variables' => array('category' => NULL, 'vars' => NULL),
|
131
|
'path' => $plugin['path'],
|
132
|
'template' => 'profile_fields_pane',
|
133
|
);
|
134
|
}
|