function profile_block in Drupal 5
Same name and namespace in other branches
- 4 modules/profile.module \profile_block()
- 6 modules/profile/profile.module \profile_block()
Implementation of hook_block().
File
- modules/
profile/ profile.module, line 101 - Support for configurable user profiles.
Code
function profile_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks[0]['info'] = t('Author information');
return $blocks;
}
else {
if ($op == 'configure' && $delta == 0) {
// Compile a list of fields to show
$fields = array();
$result = db_query('SELECT name, title, weight, visibility FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($result)) {
$fields[$record->name] = check_plain($record->title);
}
$fields['user_profile'] = t('Link to full user profile');
$form['profile_block_author_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Profile fields to display'),
'#default_value' => variable_get('profile_block_author_fields', NULL),
'#options' => $fields,
'#description' => t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="@profile-admin">profile field configuration</a> are available.', array(
'@profile-admin' => url('admin/user/profile'),
)),
);
return $form;
}
else {
if ($op == 'save' && $delta == 0) {
variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
}
else {
if ($op == 'view') {
if (user_access('access user profiles')) {
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) {
$node = node_load(arg(1));
$account = user_load(array(
'uid' => $node->uid,
));
if ($use_fields = variable_get('profile_block_author_fields', array())) {
// Compile a list of fields to show.
$fields = array();
$result = db_query('SELECT name, title, type, visibility, weight FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($result)) {
// Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.
if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {
$fields[] = $record;
}
}
}
if ($fields) {
$profile = _profile_update_user_fields($fields, $account);
$output .= theme('profile_block', $account, $profile, TRUE);
}
if (isset($use_fields['user_profile']) && $use_fields['user_profile']) {
$output .= '<div>' . l(t('View full user profile'), 'user/' . $account->uid) . '</div>';
}
}
if ($output) {
$block['subject'] = t('About %name', array(
'%name' => $account->name,
));
$block['content'] = $output;
return $block;
}
}
}
}
}
}
}