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 14 Apr 2005 17:06:51 -0000
@@ -26,6 +26,61 @@
}
/**
+ * Implementation of hook_block().
+ */
+function profile_block($op = 'list', $delta = 0, $edit = array()) {
+
+ if ($op == 'list') {
+ $blocks[0]['info'] = t('Author info');
+
+ 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} WHERE visibility = %d', PROFILE_PUBLIC_LISTINGS);
+ 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.'));
+ 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_info()) {
+ $block['subject'] = t('About the author');
+ return $block;
+ }
+ }
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function profile_nodeapi(&$node, $op, $arg) {
+ switch ($op) {
+ case 'settings':
+ return form_radios(t('Author info'), 'profile_author_info_'. $node->type, variable_get('profile_author_info_'. $node->type, 0), array(t('Disabled'), t('Enabled')), t('Include author information on pages of this content type. Note: use the %block_admin to select what author information fields to include.', array('%block_admin' => l(t('block admin page'), 'admin/block/configure/profile/0'))));
+
+ case 'view':
+ if (variable_get("profile_author_info_$node->type", 0) && user_access('access content')) {
+ $node->body .= '
' . t('About the author') . '
' . profile_author_info();
+ }
+ break;
+ }
+}
+
+/**
* Implementation of hook_menu().
*/
function profile_menu($may_cache) {
@@ -143,6 +198,48 @@
}
}
+/**
+ * Generate content describing the author of a node page.
+ */
+function profile_author_info() {
+ if (user_access('access content')) {
+ 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', null);
+ // Compile a list of fields to show
+ $fields = array();
+ $result = db_query('SELECT name, title, type FROM {profile_fields} WHERE visibility = %d', PROFILE_PUBLIC_LISTINGS);
+ while ($record = db_fetch_object($result)) {
+ if ($use_fields && in_array($record->name, $use_fields)) {
+ $fields[] = $record;
+ }
+ // If no fields designated, use all.
+ else if (!$use_fields) {
+ $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 .= '' . l(t('more'), 'user/' . $account->uid . '/track', array('title' => t('View all of user\'s recent posts.'))) . '
';
+ }
+ }
+ 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 +655,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 +663,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";
}
}