Index: modules/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile.module,v retrieving revision 1.91 diff -u -r1.91 profile.module --- modules/profile.module 11 Apr 2005 22:48:27 -0000 1.91 +++ modules/profile.module 17 Apr 2005 19:03:25 -0000 @@ -26,6 +26,45 @@ } /** + * Implementation of hook_block(). + */ +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) { + $output .= form_select(t('Number of recent posts'), 'profile_block_num_0', variable_get('profile_block_num_0', '0'), drupal_map_assoc(array(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), t('Select \'0\' to hide the recent posts section.')); + // Compile a list of fields to show + $fields = array(); + $result = db_query('SELECT name, title FROM {profile_fields} ORDER BY weight'); + while ($record = db_fetch_object($result)) { + $fields[$record->name] = $record->title; + } + $fields['user_profile'] = t('Link to full user profile'); + $output .= form_checkboxes(t('Profile fields to display'), 'profile_block_author_fields', variable_get('profile_block_author_fields', null), $fields, t('Select which profile fields you wish to display in the block. All defined fields are available, but fields designated as private in the profile field configuration will be shown in the block only to users with appropriate permissions.')); + return $output; + } + else if ($op == 'save' && $delta == 0) { + variable_set('profile_block_num_0', $edit['profile_block_num_0']); + variable_set('profile_block_author_fields', $edit['profile_block_author_fields']); + } + else if ($op == 'view') { + $block = array(); + + switch ($delta) { + case 0: + if ($block['content'] = profile_author_information()) { + $block['subject'] = t('About the author'); + return $block; + } + } + } +} + +/** * Implementation of hook_menu(). */ function profile_menu($may_cache) { @@ -143,6 +182,45 @@ } } +/** + * Generate content describing the author of a node page. + */ +function profile_author_information() { + if (user_access('access user profiles')) { + if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == null)) { + $result = db_query('SELECT uid FROM {node} WHERE nid = %d ORDER BY uid DESC', arg(1)); + $user = db_fetch_object($result); + if ($account = user_load(array('uid' => $user->uid, 'status' => 1))) { + $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 FROM {profile_fields} ORDER BY weight'); + while ($record = db_fetch_object($result)) { + // Endure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions. + if ($use_fields && in_array($record->name, $use_fields) && (user_access('administer users') || ($record->visibility != PROFILE_PRIVATE))) { + $fields[] = $record; + } + } + $output .= theme('profile_profile', $account, $fields, true); + + if ($count = variable_get('profile_block_num_0', '0')) { + $output .= '