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 1 Sep 2005 19:40:52 -0000 @@ -484,6 +484,78 @@ } /** + * Theme function for the user login block + * @param $login_url The URL to send the login password and username to. + * + * @ingroup themeable + */ +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 + * @param $online_users an array with user objects. $total_users count of logged in users. $total_guests count of guests. + * + * @ingroup themeable + */ +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; +} + +/** + * Theme function for the Navigation block + * @param $menu output of theme('menu_tree'). + * + * @ingroup themeable + */ +function theme_user_block_navigation($menu) { + return ''; +} + +/** + * Theme function for the Who's new block + * @param $users an array with user objects. + * + * @ingroup themeable + */ +function theme_user_block_whos_new($users) { + return theme('user_list', $users); +} + +/** * Implementation of hook_block(). */ function user_block($op = 'list', $delta = 0, $edit = array()) { @@ -517,37 +589,22 @@ 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')) { - $block['subject'] = $user->uid ? $user->name : t('Navigation'); - $block['content'] = ''; + + $block['subject'] = $user->uid ? $user->name : t('Navigation'); + $block['content'] = theme('user_block_navigation', $menu); + + return $block; } - return $block; + break; case 2: if (user_access('access content')) { @@ -555,12 +612,13 @@ while ($account = db_fetch_object($result)) { $items[] = $account; } - $output = theme('user_list', $items); $block['subject'] = t('Who\'s new'); - $block['content'] = $output; + $block['content'] = theme('user_block_whos_new', $items); + + return $block; } - return $block; + break; case 3: if (user_access('access content')) { @@ -572,15 +630,7 @@ $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(); @@ -588,14 +638,12 @@ $items[] = $account; } - if ($items) { - $output .= theme('user_list', $items, t('Online users')); - } - $block['subject'] = t('Who\'s online'); - $block['content'] = $output; + $block['content'] = theme('user_block_whos_online', $items, $total_users, $guests->count); + + return $block; } - return $block; + break; } } }