I'm not sure if this is the right place to ask this, but if not, perhaps you can point me in the right direction.

I just updated my site from D5 to D6, and I found this module. Something I've wanted to do for a long time, but that has never worked, was to have the author name of a post link to the bio/profile node instead of the user page (this was supposedly possible even in 4.7 using a particular combination of settings, but I was never able to get that to work).

Is this possible with this module? Where do I do that? Overriding user/username didn't work (it didn't let me do that, and I didn't want to start deleting paths that might be important), so is there another general way to do this? It's okay if it's in the theme (some other function to create the link?), I have total control over that.

Comments

fago’s picture

It'd work when theming the theme_username function. However I've no code ready for this, sry. If you do it please share the code.

dydecker’s picture

Subscribing.

I've found setting up user profiles quite confusing, partly due to this issue. Not being nodes, Drupal's user pages seem like a natural home for settings and management (private content), while the public page is better created as a node (using Content Profile). Is that the philosophy behind this module?

If so, usernames throughout the site should logically link to the "public" profile, not the private stuff. I'd be interested to hear if there is code to accomplish this, or whether this is generally the right approach that people are taking.

dydecker’s picture

Here is a solution for replacing “Authored by” information on nodes. If you want it to work for comments, first you’d have to install the Node Comments module, which turns Drupal comments into nodes, allowing you to use CCK on them.

1) disable all “Display post information” in themes/settings, which removes the “Authored by” fields and date” from your site.

2) Create a View of type: Node. The settings are:

Filter - Node: Type = Content Profile
Field – Node: Title
Argument - User: Uid

Check “Provide default argument”, and enter the following into PHP argument handling code:

global $user;
$args[0]=$user->uid;
return $args;

3) Create a CCK field in the Content type you want the link to Content Profile in.

Type: nodereference
Widget: Select list
Global settings: check required
Number of values: 1
In “Advanced: Nodes that can be referenced”, select the view.

Now each node will link to the Content Profile rather than User Profile.

william_frane’s picture

usernames throughout the site should logically link to the "public" profile, not the private stuff

I would find this functionality quite useful as well.

techypaul’s picture

Version: 6.x-1.0-beta2 » 6.x-1.0-beta4
Component: Miscellaneous » Base module
Category: support » feature

subscribing.

Is this something that is likely to be resolved?

clicking on avatars or usernames etc should take you to their bio page not user page, in fact, my account is the only place that should take you to the user page.

p.

haagendazs’s picture

A temporary workaround could be creating a permanent redirect on the user page. On my site, all profiles are aliased using pathauto and are accessible through a URL as such: www.mysite.com/profile/username

To create the redirect, create a file called user-profile.tpl.php in your theme directory and add the following code to it:

  $path = 'profile/' . $user->name;
  drupal_goto($path, NULL, NULL, 301);

This of course assumes the title of the content profile is the username, which can be achieved using node_autotitle.

Agogo’s picture

I've been searching for some less hack of a way to do this but all my findings were none succesfull mainly because I use panels. No templates in the world seemed like a good idea and I dont like the idea of redirects anywhere but have to have the functionality some way! Anyway, I thought of sharing my little snippet for those banging their head against the keyboard. It mich help someone with the thinking process at least. This is the code I used in template.php:

function theme_preprocess_page(&$variables) {
  global $user;
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    $loggeduserid = $user->uid;
    $vieweduserid = arg(1);
    if ($loggeduserid != $vieweduserid) {
      $node_profile = content_profile_load(profile, $vieweduserid);
      if ($node_profile->nid) $path = 'node/'.$node_profile->nid;
      else $path = 'user/'.$vieweduserid;
      drupal_goto($path, NULL, NULL, 301);
    }
  }
}

It simply checks whether youre trying to view your own user page or someone elses - if youre not trying to get to your own one it looks for the node-id of the content profile for the user you want to check out and then redirects you to that node. Works well with Pathauto as well since drupals arg() function checks the "real" arguments used - not the clean and dandy url youre seeing in the browser.

Ehm. Yeah. GL.

You might wanna check out these threads as well:
#276545: Have username link to profile rather than regular userpage by default
#236467: Integrate profile with user/edit
#356759: Tighter integration between profile nodes and user pages
#355760: Useful function.

rickh’s picture

Daniel

For some strange reason the link then redirects to the online user instead of the user selected. For example the profile i want to access is "John" and it directs me to my profile. any help?

rickh’s picture

For anyone else that was uffering with this. By creating a user-profile.tpl.php file in your subtheme and putting the following code in, works like a charm. No idea how to code, but it works.

<?php 
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    $loggeduserid = $user->uid;
    $vieweduserid = arg(1);
      $node_profile = content_profile_load(profile, $vieweduserid);
      if ($node_profile->nid) $path = 'node/'.$node_profile->nid;
      drupal_goto($path, NULL, NULL, 301);
  } 
?>

Hope this helps someone at least.

kehogo’s picture

@rickh - thanks

I ended taking rickh's code and using it to override the "submitted by" string on content pages and have it link to the user content profile page using the title of that page (which was set to be the user's first and last name by using Automatic Nodetitle (http://drupal.org/project/auto_nodetitle)). I'm sure there's a slightly more elegant way of doing it, but it seems to work the way I need it to.

In node.tpl.php, replace print $submitted;
with

		// strip the user id from the themed username anchor string
		$user_id_re = '|/user/([^"]+)"|';
		preg_match( $user_id_re, theme('username', $node), $matches );
		$uid = $matches[1];
		
		print 'Submitted by ';			  

		// use the content_profile_load function to get the corresponding profile node of the user id
		$node_profile = content_profile_load( profile, $uid );
		
		// if there is a corresponding profile node, use that id and the title for the anchor tag
		if ( $node_profile->nid ) {
			$path = 'node/'.$node_profile->nid;
			print '<a href="/node/' . $node_profile->nid . '">'. $node_profile->title . '</a>';
		} else {
			print 'Anonymous';
		}
		
		// format the date
		print ' &mdash; ' . date( 'F d, Y', $node->created );
	
kehogo’s picture

After some further work, I have a few clarifications.

First, getting the user id of the content creator is much easier:

		$uid = $node->uid;

Next, the first argument in the content_profile_load() function should be a string that is the exact name of the Content Type you've created. The Content Profile module creates a content type called 'Profile' so if you change this Content Type, you'll need to change this argument to match.

superdorx’s picture

#9 works perfectly. Would be nice if the URL path for the link didn't still show the path to the Drupal user page. All links are being redirect to Content Profile user page. But this seems to me making good progress! Great job so far everyone.

TwoD’s picture

Usng theme_username as suggested in #1 seems the easiest way to do this, here's the function I used in template.php. It's a mix between the original theme_username and acquia_marina's override which allows to toggle the "(not verified)" text. This way the links to "My account" still works and the public/private separation in #2 is achieved. One can also do the same with template_preprocess_user_picture() if you use the default user pictures.

function acquia_marina_username($object) {
  // Cache the node ids to save a few db queries.
  static $profiles = array();

  if ((!$object->uid) && $object->name) {
    $output = (!empty($object->homepage)) ? l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow'))) : check_plain($object->name);
    $output .= (theme_get_setting('user_notverified_display') == 1) ? ' ('. t('not verified') .')' : '';
  }
  else {
    if (!isset($profiles[$object->uid])) {
      $profile = content_profile_load('profile', $object->uid);
      $profiles[$object->uid] = $profile->nid;
    }
    $profileNid = $profiles[$object->uid];

    // Shorten the name when it is too long or it will break many tables.
    if (drupal_strlen($object->name) > 20) {
      $name = drupal_substr($object->name, 0, 15) .'...';
    }
    else {
      $name = $object->name;
    }

    if (user_access('access user profiles')) {
      $output = l($name, 'node/'. $profileNid, array('attributes' => array('title' => t('View user profile.'))));
    }
    else {
      $output = check_plain($name);
    }
  }  
  return $output;
}
stevep’s picture

Thanks Rickh

Worked okay, but lost My Account link to user. Now a new logged in user cannot access their account, only their profile.

Did anyone else have this problem?

Cheers
Steve

mojito_’s picture

Having same problem. Any ideas?

mojito_’s picture

OK, I used #13 and amended template.php. Works perfectly. Thanks TwoD!

robby.smith’s picture

Could someone please help add 'profile_first_name' as the themed username + #13 where it will link to the content profile node?

sean_a’s picture

This works great! If a user doesn't have a profile though the link goes to /node. Is there a way to link to their user page if a content profile doesn't exist?

hedac’s picture

Thanks #13

I don't know why but removing the if of: if (!isset($profiles[$object->uid])) {
then works better for me.... I wanted to also replace the username with the Profile Title... so I need always the profile variable to update for some reason. so I just used $profile->title instead of $object->name if title is not empty. If it is empty in case user has no profile created then use username. It also links to user page if content profile does not exist.

<?php
function YOURTHEME_username($object) {
  // Cache the node ids to save a few db queries.
  static $profiles = array();

  if ((!$object->uid) && $object->name) {
    $output = (!empty($object->homepage)) ? l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow'))) : check_plain($object->name);
    $output .= (theme_get_setting('user_notverified_display') == 1) ? ' ('. t('not verified') .')' : '';
  }
  else {
    //if (!isset($profiles[$object->uid])) { 
      $profile = content_profile_load('profile', $object->uid);
      $profiles[$object->uid] = $profile->nid;
    //}
    $profileNid = $profiles[$object->uid];

    // Shorten the name when it is too long or it will break many tables.
    if (!$profile->title) $profileusername = $object->name; else $profileusername = $profile->title;  // if profile title is empty then use user name
    if (drupal_strlen($profileusername) > 20) {
      $name = drupal_substr($profileusername, 0, 17) .'...';
    }
    else {
      $name = $profileusername;
    }

    if (user_access('access user profiles')) {
      if (!$profile->title){ // redirect to normal user page if content profile does not exist
      $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user page.'))));
      }else{
      $output = l($name, 'node/'. $profileNid, array('attributes' => array('title' => t('View user profile.'))));
      }
    }
    else {
      $output = check_plain($name);
    }
  } 
  return $output;
}
?>
honorfield’s picture

You can automatically assign the username as title for the profile. Please see here: http://drupal.org/node/285367

sean_a’s picture

#19 works great

small note: if you change the name of your content type for profiles, be sure to edit the line

$profile = content_profile_load('profile', $object->uid);

to whatever is your content type name.

darrenmothersele’s picture

I'd already implemented something like this before I found this thread. In my theme I created this function:

function THEMENAME_username($object) {  
  if (empty($object->uid) && !empty($object->name)) {
    return ((!empty($object->homepage)) ? 
      l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow'))) 
      : check_plain($object->name)) . t('not verified');
  }
  $profile = content_profile_load('profile', $object->uid);
  if (!empty($profile->nid)) {
    return l($object->name, 'node/'. $profile->nid);
  }
  return t('Guest');
}

It works, generating a link to the profile node for valid users who have a public profile. I think I will add some of the functionality from #19 but the static cache code seems to be commented out. Is there a reason for this?

Michsk’s picture

Isn't this really a duplicate of http://drupal.org/node/661572