Index: modules/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user.module,v retrieving revision 1.502 diff -u -r1.502 user.module --- modules/user.module 25 Aug 2005 21:14:17 -0000 1.502 +++ modules/user.module 31 Aug 2005 08:32:01 -0000 @@ -484,6 +484,52 @@ } /** + * Theme function for the user login block + */ +function theme_user_block_login($login_url) { + $output = "
\n"; + + // NOTE: special care needs to be taken because on pages with forms, + // such as node and comment submission pages, the $edit variable + // might already be set. + + $output .= form_textfield(t('Username'), 'name', $edit['name'], 15, 64); + $output .= form_password(t('Password'), 'pass', $pass, 15, 64); + $output .= form_submit(t('Log in')); + $output .= "
\n"; + + $output = form($output, 'post', $login_url); + + if (variable_get('user_register', 1)) { + $items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.'))); + } + $items[] = l(t('Request new password'), 'user/password', array('title' => t('Request new password via e-mail.'))); + + $output .= theme('item_list', $items); + + return $output; +} + +/** + * Theme function for the Who's online block + */ +function theme_user_block_whos_online($online_users, $total_users, $total_guests) { + // Format the output with proper grammar. + if ($total_users == 1 && $total_guests == 1) { + $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($total_guests, '1 guest', '%count guests'))); + } + else { + $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($total_guests, '1 guest', '%count guests'))); + } + + if ($online_users) { + $output .= theme('user_list', $online_users, t('Online users')); + } + + return $output; +} + +/** * Implementation of hook_block(). */ function user_block($op = 'list', $delta = 0, $edit = array()) { @@ -516,31 +562,12 @@ // For usability's sake, avoid showing two login forms on one page. if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) { $edit = $_POST['edit']; - - $output = "
\n"; - - // NOTE: special care needs to be taken because on pages with forms, - // such as node and comment submission pages, the $edit variable - // might already be set. - - $output .= form_textfield(t('Username'), 'name', $edit['name'], 15, 64); - $output .= form_password(t('Password'), 'pass', $pass, 15, 64); - $output .= form_submit(t('Log in')); - $output .= "
\n"; - - $output = form($output, 'post', url('user/login', drupal_get_destination())); - - if (variable_get('user_register', 1)) { - $items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.'))); - } - $items[] = l(t('Request new password'), 'user/password', array('title' => t('Request new password via e-mail.'))); - - $output .= theme('item_list', $items); - $block['subject'] = t('User login'); - $block['content'] = $output; + $block['content'] = theme('user_block_login',url('user/login', drupal_get_destination())); + + return $block; } - return $block; + break; case 1: if ($menu = theme('menu_tree')) { @@ -572,30 +599,20 @@ $users = db_query('SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period); $total_users = db_num_rows($users); - // Format the output with proper grammar. - if ($total_users == 1 && $guests->count == 1) { - $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests'))); - } - else { - $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests'))); - } - - // Display a list of currently online users. + // List of currently online users. $max_users = variable_get('user_block_max_list_count', 10); $items = array(); while ($max_users-- && $account = db_fetch_object($users)) { $items[] = $account; - } - - if ($items) { - $output .= theme('user_list', $items, t('Online users')); - } + } + $block['content'] = theme('user_block_whos_online', $items, $total_users, $guests->count); $block['subject'] = t('Who\'s online'); - $block['content'] = $output; + + return $block; } - return $block; + break; } } }