Closed (fixed)
Project:
Buddylist
Version:
master
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
29 Nov 2005 at 00:22 UTC
Updated:
26 Feb 2006 at 22:15 UTC
At the moment, I think the buddylist interface is a little cumbersome. To add a buddy, a user must first navigate to a user's profile page. This is not obvious to causal users. I think a better method would be to replace all usernames on a site with username (add to buddylist) or username (remove from buddylist). This gives an immediate way to add any user to your buddylist. Quick, easy, intuitive.
This functionality can be implemented by having the module override the phptemplate_username function.
Pros:
Cons:
To test this patch, just drop the following code into your buddylist file (I think it will only work in HEAD):
<?php
function phptemplate_username($object) {
global $user;
/* Use the default theme_username for anonymous users, nodes by this user */
if ($user->uid == 0 || $object->uid == $user->uid || $object->uid == 0) {
return theme_username($object);
}
/* an array, keyed on buddy uids */
$buddies = buddylist_get_buddies($user->uid);
/* Find out if this buddy is in the user's buddy list */
foreach ($buddies as $buddyuid => $buddystructure) {
if ($buddyuid == $object->uid) {
$output .= theme_username($object);
$output .= " (";
$output .= l(t('remove from buddylist'), 'buddy/delete/' . $object->uid);
$output .= ")";
return $output;
}
}
/* The user is not in the buddylist, give a link to add */
$output .= theme_username($object);
$output .= " (";
$output .= l(t('add to buddylist'), 'buddy/add/' . $object->uid);
$output .= ")";
return $output;
}
?>
Comments
Comment #1
robertdouglass commentedYour code overlooks the role based permissions needed. Here is an updated version that depends on the buddylist module being prepared for 4.7. Note that it includes use of theme functions that aren't committed as of this writing, but will be soon.
Changed title to be more specific
Comment #2
robertdouglass commentedOther notes: this is for use with a PHPTemplate based theme. If you are using a different theme engine, you need to rename the function to use the name of your theme.
For PHPTemplate themes, the best place for this and other similar functions, is in a template.php file in your theme's directory. If you have such a file, paste this funciton into it. If you don't have one, create it.
I'm including this code in the INSTALL.txt file as that is the best place for sharing such theme functions until we actually have a theme functions repository. Marking as fixed.
Comment #3
mfredrickson commentedGood idea for putting it in the readme. Though I think a better idea might be to create a contrib module that does two things:
1. Implements this function for all theme engines.
2. Implements hook_user('load') to add buddies for the current user object. (Unless the the buddylist_get_buddies caches the look up..., in that case this if fine). Looking up the current user's buddies each time Drupal encoungers a username could be a potentially expensive operation....
I'll add this module to my lengthy to do list.
Keep the issue "fixed" anyway.
Comment #4
robertdouglass commentedcaching the lookup is good. I'll do that right now. You can work on the idea to make the theme function generally available.
Comment #5
robertdouglass commentedIt was already cached. No worries.
Comment #6
(not verified) commented