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 .= '

' . t('Recent posts') . '

'; + $sql = db_rewrite_sql('SELECT DISTINCT(n.nid), n.title, l.comment_count, l.last_comment_timestamp AS last_post FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = 0 OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC'); + $output .= node_title_list(db_query_range($sql, $account->uid, $account->uid, 0, $count)); + if (module_exist('tracker')) { + $output .= ''; + } + } + if (in_array('user_profile', $use_fields)) { + $output .= '
' . l(t('View full user profile'), 'user/' . $account->uid) . '
'; + } + return $output; + } + } + } + return; +} + function profile_load_profile(&$user) { $result = db_query('SELECT f.name, f.type, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $user->uid); while ($field = db_fetch_object($result)) { @@ -558,7 +636,7 @@ print theme('page', $output); } -function theme_profile_profile($user, $fields = array()) { +function theme_profile_profile($user, $fields = array(), $field_titles = false) { $output = "
\n"; $output .= theme('user_picture', $user); @@ -566,7 +644,11 @@ foreach ($fields as $field) { if ($value = profile_view_field($user, $field)) { - $output .= "
$value
\n"; + $output .= "
"; + if ($field_titles) { + $output .= "$field->title: "; + } + $output .= "$value
\n"; } }