Commit a2314370 authored by Nancy Wichmann's avatar Nancy Wichmann
Browse files

Add feature to override theme_username.

Added default to standard username if no fields populated.
parent dd19b04d
......@@ -25,4 +25,5 @@ function realname_enable() {
function realname_uninstall() {
variable_del('realname_sep');
variable_del('realname_fields');
variable_del('realname_theme');
}
......@@ -3,11 +3,11 @@
/**
* @file
* The RealName module allows the admin to choose fields from teh user profile
* The RealName module allows the admin to choose fields from the user profile
* that will be used to add a "realname" element (method) to a user object.
* Hook_user is used to automatically add this to any user object that is loaded.
*
* @copyright Copyright (c) 2007-200 Nancy Wichmann. All rights reserved.
* @copyright Copyright (c) 2007-2008 Nancy Wichmann. All rights reserved.
*/
//********************************************************************
......@@ -31,6 +31,12 @@ function realname_menu($may_cache) {
'callback arguments' => array('realname_admin_settings'),
);
}
else {
// If desired, load the theme override file.
if (variable_get('realname_theme', false)) {
include_once(drupal_get_path('module', 'realname') .'/realname_theme.inc');
}
}
return $items;
}
......@@ -56,6 +62,7 @@ function realname_help($path, $args = null) {
}
}
//********************************************************************
//* Module Functions
//********************************************************************
......@@ -85,6 +92,11 @@ function realname_make_name(&$account) {
}
}
// If no fields set, use username.
if (count($stuff) == 0) {
$stuff[] = $account->name;
}
// TODO: Make a pattern, rather than hard separator.
return implode($sep, $stuff);
}
......@@ -182,6 +194,13 @@ function realname_admin_settings() {
'#default_value' => variable_get('realname_sep', ' '),
);
$form['realname_theme'] = array(
'#type' => 'checkbox',
'#title' => '<strong>'. t('Override username theme') .'</strong>',
'#description' => t('If this option is selected, the standard username theme function will be overriden to use the "Real name."'),
'#default_value' => variable_get('realname_theme', false),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
......@@ -213,4 +232,7 @@ function realname_admin_settings_submit($form_id, $form_values) {
// Okay, save the stuff.
variable_set('realname_fields', $realname_fields);
variable_set('realname_sep', $form_values['realname_sep']);
variable_set('realname_theme', $form_values['realname_theme']);
drupal_set_message(t('Configuration has been updated.'), 'status');
}
<?php
// $Id$
/**
* @file
* This include file intercepts the theme('username'... function
* and uses the RealName instead of the username.
*
* @copyright Copyright (c) 2007-2008 Nancy Wichmann. All rights reserved.
*/
/**
* Format a username. (copied from theme.inc)
*
* @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->realname) {
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->realname) > 20) {
$name = drupal_substr($object->realname, 0, 15) .'...';
}
else {
$name = $object->realname;
}
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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment