Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
The following code could be shipped in bio module or included as an example in the README. It uses the nice bio full name instead of username everywhere usernames are shown. There are only 3 lines of custom code here - the rest is copy/paste from core.
/**
* Use bio module name if available
*
* @param $object
* The user object to format, usually returned from user_load().
* @return
* A string containing an HTML link to the user's page if the passed object
* suggests that this is a site user. Otherwise, only the username is returned.
*/
function phptemplate_username($object) {
if ($object->uid && $object->name) {
// For bio module.
if ($nid = bio_for_user($object->uid)) {
$object->name = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $nid));
}
// 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, 'user/'. $object->uid, array('title' => t('View user profile.')));
}
else {
$output = check_plain($name);
}
}
else if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if ($object->homepage) {
$output = l($object->name, $object->homepage);
}
else {
$output = check_plain($object->name);
}
$output .= ' ('. t('not verified') .')';
}
else {
$output = variable_get('anonymous', t('Anonymous'));
}
return $output;
}
Comment | File | Size | Author |
---|---|---|---|
#6 | blog.module.tar_.gz | 3.39 KB | dugh |
Comments
Comment #1
najibx CreditAttribution: najibx commentedNice.
It simply takes the bio/node title which is expected to be the fullname. I guess to use this, change "Title" to "Full Name" in the bio content type would be best. No need to create an field for fullname.
Thank you.
Comment #2
webchickIn D6 I think we could just do this. I'll mull over the best way to document this...
Comment #3
najibx CreditAttribution: najibx commentedIt works fine except when writing a comment, since now those 3 lines has override $object->name,
it give an error message to provide valid author. This is the case for core comment module.
Need to put a conditional function here ... many modules looks fine except this one.... which i dunno :-(
TQ
Comment #4
palmergroup CreditAttribution: palmergroup commentedI was pumped when I found this then I discovered the mentioned error. I put a condition around the code but I hope this will be resolved. It probably wont work for the forum as well.
Comment #5
dugh CreditAttribution: dugh commentedForgive me but where do we put this code.
Comment #6
dugh CreditAttribution: dugh commentedOh i see, I added it to the bottom of the template.php file in my theme folder.
This still gives an error that you need a valid username if you try to make a comment while logged in.
Here is code I am using that uses profile fields instead of bio fields.
I don't overwrite $object->name, which I think causes the error with comments (see code near bottom of this thread: http://drupal.org/node/47308 )
Also if you look at the commented out lines, I added a rel nofollow to links, and took out the "not verified" part. Both of these changes appear to already be done for you in drupal 6.
I also had to hack up modules/blog/blog.module since it displays usernames all over the place instead of a full or real name. Attached is my version until this patch is incorporated into drupal core: http://drupal.org/node/102679
Comment #7
sunI'm inclined to mark this won't fix, or move this issue over to User Display API's queue.
Comment #8
fatcrobat CreditAttribution: fatcrobat commentedfound an issue with the forum comment validation where "You have to specify a valid author." prompt
this should fix the problem:
Comment #9
pribeh CreditAttribution: pribeh commentedHey, I've used this to fix most of my problems when it comes to displaying bioname instead of username but the page is still informing the browser of the username as its title. For example, the browser tab for the page will display the username as opposed to the username. Is there a conceivable way to correct this as well?
Comment #10
Prodigy CreditAttribution: Prodigy commented@#9
Yes, you need to use THEMENAME_preprocess_page
The snippet below is assuming you are using the core profile module. Just replace the values with the CCK type.
http://emmajane.net/node/844