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