Aliases

fanguelo@uoguelph.ca's picture

Is it possible to do aliases for people ala gaim or (your favorite instant messenger)? Full email addresses are great for IDing but i cant remember any of you. (I am bad with names) :D

Anyway, the reason I say aliases is because each user sets the other users name. So for example I may want to see aberry@uoguelph.ca as Andrew, but this in no way changes how others see the user

Am I making sense?

aberry@uoguelph.ca's picture

You mean within this site?

You mean within this site? Individuals can put their full names in their profile... ex. http://www.socis.ca/user/15

As for aliasing, that would have to be a pretty intense drupal module to intercept all UID display requests. But it could be neat, say "if real name exists, display it, otherwise, use email".

--
Andrew

fanguelo@uoguelph.ca's picture

.

yah, that's what i am talking about. some script that runs through the names and changes from asjdasjh@email.com to John. As per user

fanguelo@uoguelph.ca's picture

I think I figured it out

I think I figured it out with greasemonkey

(function() {
temp_body = String(document.body.innerHTML);
document.body.innerHTML = temp_body.replace(/blah@email.com/gi, 'Friend');
})();

gona give it a try

fanguelo@uoguelph.ca's picture

~

Yep that works. Whole script:

// ==UserScript==
// @name Alias For Socis Forums
// @description Replaces email addresses with names you actually know
// @include http://*socis.*
// ==/UserScript==

(function() {
temp_body = String(document.body.innerHTML);
document.body.innerHTML = temp_body.replace(/EpicBard/gi, 'EpicBard');
})();

fanguelo@uoguelph.ca's picture

Better Code

You can add as many people as you want with this:

// Based on a script in Mark Pilgram's upcoming "Dive into Greasemonkey"
// ==UserScript==
// @name Socis Alias Maker
// @namespace
// @description Replaces emails with user specified names.
// @include http://*socis.*
// @exclude http://www.socis.ca/user/*
// ==/UserScript==

(function() {
var replacements, regex, key, textnodes, node, s;

replacements = {
"fanguelo@uoguelph.ca": "Dr. Phil",
"friend@uoguelph.ca": "A Friend"};

regex = {};
for (key in replacements) {
regex[key] = new RegExp(key, 'g');
}

textnodes = document.evaluate( "//body//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < textnodes.snapshotLength; i++) {
node = textnodes.snapshotItem(i);
s = node.data;
for (key in replacements) {
s = s.replace(regex[key], replacements[key]);
}
node.data = s;
}

})();

ok the code tag sucks.. completely misses the last part

aberry@uoguelph.ca's picture

Greasemonkey FTW

Neat. It actually looks like this may become an 'in core' feature for drupal 6, as there is a issue about it: http://drupal.org/node/102679

--
Andrew

fanguelo@uoguelph.ca's picture

.

Hey good news. :D

This thing is quite nifty.

aberry@uoguelph.ca's picture

I implemented this on csaonline.ca

I overrode the theme_username function to strip out '@uoguelph.ca' from the display. Just place this function in /template.php to override the function. This might work with D5 as well, but you'll need to check against the D5 API. This is all nearly identical to the original function except for a few lines at the top.

function phptemplate_username($object) {

if ($object->uid && $object->name) {
// Remove @uoguelph.ca from display
$name = str_replace( '@uoguelph.ca', '', $object->name);

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

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', 'Anonymous');
}

return $output;
}


--
Andrew

aberry@uoguelph.ca's picture

I modified this code for our

I modified this code for our 3760 project to punt in a friendly name instead. It pulls in the profile field called "friendly_name", if you call it something else you'll need to change the code. This is verified to work with Drupal 5.x.

You could also combine this with the above to remove @uoguelph.ca from those users who haven't specified a friendly name.

--
Andrew

function phptemplate_username($object) { 

  if ($object->uid && $object->name) { 
    $query = "SELECT `value` FROM {profile_values}
      WHERE fid in (SELECT fid FROM profile_fields
      WHERE name = 'profile_friendly_name') and uid=%d";
    $result = db_query($query, $object->uid);
    $friendly = db_fetch_object($result)->value;

    // If the user hasn't specified a friendly name, use their system name
    if ($friendly != '') {
      $name = $friendly;
    }
    else {
      $name = $object->name;
    }
    
    // Shorten the name when it is too long or it will break many tables. 
    if (drupal_strlen($name) > 20) { 
      $name = drupal_substr($name, 0, 15) .'...'; 
    } 

    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', 'Anonymous'); 
  } 

  return $output; 
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.