Index: modules/aggregator/aggregator.blocks.inc =================================================================== RCS file: modules/aggregator/aggregator.blocks.inc diff -N modules/aggregator/aggregator.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/aggregator/aggregator.blocks.inc 4 Oct 2009 18:34:54 -0000 @@ -0,0 +1,43 @@ + $fid)); + $read_more = theme('more_link', url('aggregator/sources/' . $fid), t("View this feed's recent news.")); + + $items = array(); + foreach ($result as $item) { + $items[] = theme('aggregator_block_item', $item); + } + + // Only display the block if there are items to show. + if (count($items) > 0) { + $output = theme('item_list', $items) . $read_more; + return $output; + } + + return ''; +} + +function aggregator_category_block($cid, $count) { + $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $count, array(':cid' => $cid)); + $read_more = theme('more_link', url('aggregator/categories/' . $cid), t("View this category's recent news.")); + + $items = array(); + foreach ($result as $item) { + $items[] = theme('aggregator_block_item', $item); + } + + // Only display the block if there are items to show. + if (count($items) > 0) { + $output = theme('item_list', $items) . $read_more; + return $output; + } + + return ''; +} Index: modules/aggregator/aggregator.module =================================================================== RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.module,v retrieving revision 1.424 diff -u -p -r1.424 aggregator.module --- modules/aggregator/aggregator.module 25 Sep 2009 15:20:12 -0000 1.424 +++ modules/aggregator/aggregator.module 4 Oct 2009 18:34:27 -0000 @@ -382,37 +382,29 @@ function aggregator_block_save($delta = * Generates blocks for the latest news items in each category and feed. */ function aggregator_block_view($delta = '') { + $block = array(); + module_load_include('inc', 'aggregator', 'aggregator.blocks'); + if (user_access('access news feeds')) { - $block = array(); list($type, $id) = explode('-', $delta); switch ($type) { case 'feed': if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) { $block['subject'] = check_plain($feed->title); - $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $feed->block, array(':fid' => $id)); - $read_more = theme('more_link', url('aggregator/sources/' . $feed->fid), t("View this feed's recent news.")); + $block['content'] = aggregator_feed_block($feed->fid, $feed->block); } break; case 'category': if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) { $block['subject'] = check_plain($category->title); - $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $category->block, array(':cid' => $category->cid)); - $read_more = theme('more_link', url('aggregator/categories/' . $category->cid), t("View this category's recent news.")); + $block['content'] = aggregator_category_block($category->cid, $category->block); } break; } - $items = array(); - foreach ($result as $item) { - $items[] = theme('aggregator_block_item', $item); - } - - // Only display the block if there are items to show. - if (count($items) > 0) { - $block['content'] = theme('item_list', $items) . $read_more; - } - return $block; } + + return $block; } /** Index: modules/blog/blog.blocks.inc =================================================================== RCS file: modules/blog/blog.blocks.inc diff -N modules/blog/blog.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/blog/blog.blocks.inc 4 Oct 2009 17:51:02 -0000 @@ -0,0 +1,26 @@ +fields('n', array('nid', 'title', 'created')) + ->condition('type', 'blog') + ->condition('status', 1) + ->orderBy('created', 'DESC') + ->range(0, 10) + ->addTag('node_access') + ->execute(); + + if ($node_title_list = node_title_list($result)) { + $output = $node_title_list; + $ouput .= theme('more_link', url('blog'), t('Read the latest blog entries.')); + return $output; + } + + return ''; +} Index: modules/blog/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.module,v retrieving revision 1.335 diff -u -p -r1.335 blog.module --- modules/blog/blog.module 29 Aug 2009 05:46:02 -0000 1.335 +++ modules/blog/blog.module 4 Oct 2009 18:39:29 -0000 @@ -163,24 +163,17 @@ function blog_block_info() { * Displays the most recent 10 blog titles. */ function blog_block_view($delta = '') { - global $user; + $block = array(); + module_load_include('inc', 'blog', 'blog.blocks'); if (user_access('access content')) { - $result = db_select('node', 'n') - ->fields('n', array('nid', 'title', 'created')) - ->condition('type', 'blog') - ->condition('status', 1) - ->orderBy('created', 'DESC') - ->range(0, 10) - ->addTag('node_access') - ->execute(); - - if ($node_title_list = node_title_list($result)) { - $block['content'] = $node_title_list; - $block['content'] .= theme('more_link', url('blog'), t('Read the latest blog entries.')); + $content = blog_recent_block(); + if (!empty($content)) { $block['subject'] = t('Recent blog posts'); - return $block; + $block['content'] = $content; } } + + return $block; } Index: modules/forum/forum.blocks.inc =================================================================== RCS file: modules/forum/forum.blocks.inc diff -N modules/forum/forum.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/forum/forum.blocks.inc 4 Oct 2009 18:37:38 -0000 @@ -0,0 +1,48 @@ +join('forum', 'f', 'f.vid = n.vid'); + $query->join('taxonomy_term_data', 'td', 'td.tid = f.tid'); + $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); + $query + ->fields('n', array('nid', 'title')) + ->fields('ncs', array('comment_count', 'last_comment_timestamp')) + ->condition('n.status', 1) + ->condition('td.vid', variable_get('forum_nav_vocabulary', 0)) + ->addTag('node_access'); + switch ($type) { + case 'active': + $query + ->orderBy('ncs.last_comment_timestamp', 'DESC') + ->range(0, variable_get('forum_block_num_active', '5')); + break; + + case 'new': + $query + ->orderBy('n.nid', 'DESC') + ->range(0, variable_get('forum_block_num_new', '5')); + break; + } + + $cache_keys = array_merge(array('forum', $delta), drupal_render_cid_parts()); + // Cache based on the altered query. Enables us to cache with node access enabled. + $query->preExecute(); + $cache_keys[] = md5(serialize(array((string) $query, $query->getArguments()))); + + return array( + '#access' => user_access('access content'), + '#pre_render' => array('forum_block_view_pre_render'), + '#cache' => array( + 'keys' => $cache_keys, + 'expire' => CACHE_TEMPORARY, + ), + '#query' => $query, + ); +} Index: modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.519 diff -u -p -r1.519 forum.module --- modules/forum/forum.module 18 Sep 2009 00:04:22 -0000 1.519 +++ modules/forum/forum.module 4 Oct 2009 18:15:33 -0000 @@ -512,47 +512,21 @@ function forum_block_save($delta = '', $ * most recently added forum topics. */ function forum_block_view($delta = '') { - $query = db_select('node', 'n'); - $query->join('forum', 'f', 'f.vid = n.vid'); - $query->join('taxonomy_term_data', 'td', 'td.tid = f.tid'); - $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); - $query - ->fields('n', array('nid', 'title')) - ->fields('ncs', array('comment_count', 'last_comment_timestamp')) - ->condition('n.status', 1) - ->condition('td.vid', variable_get('forum_nav_vocabulary', 0)) - ->addTag('node_access'); + $block = array(); + module_load_include('inc', 'forum', 'forum.blocks'); + switch ($delta) { case 'active': - $title = t('Active forum topics'); - $query - ->orderBy('ncs.last_comment_timestamp', 'DESC') - ->range(0, variable_get('forum_block_num_active', '5')); + $block['subject'] = t('Active forum topics'); + $block['content'] = forum_main_block('active'); break; case 'new': - $title = t('New forum topics'); - $query - ->orderBy('n.nid', 'DESC') - ->range(0, variable_get('forum_block_num_new', '5')); + $block['subject'] = t('New forum topics'); + $block['content'] = forum_main_block('new'); break; } - $cache_keys = array_merge(array('forum', $delta), drupal_render_cid_parts()); - // Cache based on the altered query. Enables us to cache with node access enabled. - $query->preExecute(); - $cache_keys[] = md5(serialize(array((string) $query, $query->getArguments()))); - - $block['subject'] = $title; - $block['content'] = array( - '#access' => user_access('access content'), - '#pre_render' => array('forum_block_view_pre_render'), - '#cache' => array( - 'keys' => $cache_keys, - 'expire' => CACHE_TEMPORARY, - ), - '#query' => $query, - ); return $block; } Index: modules/locale/locale.blocks.inc =================================================================== RCS file: modules/locale/locale.blocks.inc diff -N modules/locale/locale.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/locale/locale.blocks.inc 4 Oct 2009 17:41:58 -0000 @@ -0,0 +1,27 @@ +' : $_GET['q']; + $languages = language_list('enabled'); + $links = array(); + foreach ($languages[1] as $language) { + $links[$language->language] = array( + 'href' => $path, + 'title' => $language->native, + 'language' => $language, + 'attributes' => array('class' => array('language-link')), + ); + } + + // Allow modules to provide translations for specific links. + drupal_alter('translation_link', $links, $path); + $output = theme('links', $links, array()); + + return $output; +} Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.259 diff -u -p -r1.259 locale.module --- modules/locale/locale.module 22 Sep 2009 07:50:16 -0000 1.259 +++ modules/locale/locale.module 4 Oct 2009 18:40:27 -0000 @@ -639,26 +639,15 @@ function locale_block_info() { * web addresses, so we can actually link to other language versions. */ function locale_block_view($delta = '') { - if (variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != LANGUAGE_NEGOTIATION_NONE) { - $path = drupal_is_front_page() ? '' : $_GET['q']; - $languages = language_list('enabled'); - $links = array(); - foreach ($languages[1] as $language) { - $links[$language->language] = array( - 'href' => $path, - 'title' => $language->native, - 'language' => $language, - 'attributes' => array('class' => array('language-link')), - ); - } - - // Allow modules to provide translations for specific links. - drupal_alter('translation_link', $links, $path); + $block = array(); + module_load_include('inc', 'locale', 'locale.blocks'); + if (variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != LANGUAGE_NEGOTIATION_NONE) { $block['subject'] = t('Languages'); - $block['content'] = theme('links', $links, array()); - return $block; + $block['content'] = locale_language_switcher_block(); } + + return $block; } /** Index: modules/poll/poll.blocks.inc =================================================================== RCS file: modules/poll/poll.blocks.inc diff -N modules/poll/poll.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/poll/poll.blocks.inc 4 Oct 2009 19:00:30 -0000 @@ -0,0 +1,32 @@ +join('poll', 'p', 'p.nid = n.nid'); + $select->fields('n', array('nid')) + ->condition('n.status', 1) + ->condition('p.active', 1) + ->orderBy('n.created', 'DESC') + ->range(0, 1) + ->addTag('node_access'); + + $record = $select->execute()->fetchObject(); + if ($record) { + $poll = node_load($record->nid); + if ($poll->nid) { + $poll = poll_block_latest_poll_view($poll); + $output = $poll->content; + } + } + + return $output; +} Index: modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.315 diff -u -p -r1.315 poll.module --- modules/poll/poll.module 2 Oct 2009 00:04:20 -0000 1.315 +++ modules/poll/poll.module 4 Oct 2009 18:23:06 -0000 @@ -132,28 +132,18 @@ function poll_block_info() { * Generates a block containing the latest poll. */ function poll_block_view($delta = '') { + $block = array(); + module_load_include('inc', 'poll', 'poll.blocks'); + if (user_access('access content')) { - // Retrieve the latest poll. - $select = db_select('node', 'n'); - $select->join('poll', 'p', 'p.nid = n.nid'); - $select->fields('n', array('nid')) - ->condition('n.status', 1) - ->condition('p.active', 1) - ->orderBy('n.created', 'DESC') - ->range(0, 1) - ->addTag('node_access'); - - $record = $select->execute()->fetchObject(); - if ($record) { - $poll = node_load($record->nid); - if ($poll->nid) { - $poll = poll_block_latest_poll_view($poll); - $block['subject'] = t('Poll'); - $block['content'] = $poll->content; - return $block; - } + $content = poll_recent_block(); + if (!empty($content)) { + $block['subject'] = t('Poll'); + $block['content'] = $content; } } + + return $block; } /** Index: modules/profile/profile.blocks.inc =================================================================== RCS file: modules/profile/profile.blocks.inc diff -N modules/profile/profile.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/profile/profile.blocks.inc 4 Oct 2009 18:43:17 -0000 @@ -0,0 +1,34 @@ + array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS))); + foreach ($result as $record) { + // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions. + if (isset($use_fields[$record->name]) && $use_fields[$record->name]) { + $fields[] = $record; + } + } + } + + if (!empty($fields)) { + $profile = _profile_update_user_fields($fields, $account); + $output .= theme('profile_block', $account, $profile, TRUE); + } + + if (isset($use_fields['user_profile']) && $use_fields['user_profile']) { + $output .= '
' . l(t('View full user profile'), 'user/' . $account->uid) . '
'; + } + + return $output; +} Index: modules/profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.276 diff -u -p -r1.276 profile.module --- modules/profile/profile.module 22 Sep 2009 07:50:16 -0000 1.276 +++ modules/profile/profile.module 4 Oct 2009 18:42:18 -0000 @@ -173,40 +173,22 @@ function profile_block_save($delta = '', * Implement hook_block_view(). */ function profile_block_view($delta = '') { + $block = array(); + module_load_include('inc', 'profile', 'profile.blocks'); + if (user_access('access user profiles')) { - $output = ''; if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) { $node = node_load(arg(1)); $account = user_load(array('uid' => $node->uid)); - - if ($use_fields = variable_get('profile_block_author_fields', array())) { - // Compile a list of fields to show. - $fields = array(); - $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS))); - foreach ($result as $record) { - // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions. - if (isset($use_fields[$record->name]) && $use_fields[$record->name]) { - $fields[] = $record; - } - } - } - - if (!empty($fields)) { - $profile = _profile_update_user_fields($fields, $account); - $output .= theme('profile_block', $account, $profile, TRUE); - } - - if (isset($use_fields['user_profile']) && $use_fields['user_profile']) { - $output .= '
' . l(t('View full user profile'), 'user/' . $account->uid) . '
'; + $content = profile_author_information_block($node, $account); + if (!empty($content)) { + $block['subject'] = t('About %name', array('%name' => $account->name)); + $block['content'] = $content; } } - - if ($output) { - $block['subject'] = t('About %name', array('%name' => $account->name)); - $block['content'] = $output; - return $block; - } } + + return $block; } /** Index: modules/statistics/statistics.blocks.inc =================================================================== RCS file: modules/statistics/statistics.blocks.inc diff -N modules/statistics/statistics.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/statistics/statistics.blocks.inc 4 Oct 2009 17:18:01 -0000 @@ -0,0 +1,33 @@ +', $content); + return $output; + } + + return ''; +} Index: modules/statistics/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v retrieving revision 1.320 diff -u -p -r1.320 statistics.module --- modules/statistics/statistics.module 5 Sep 2009 13:49:28 -0000 1.320 +++ modules/statistics/statistics.module 4 Oct 2009 18:45:05 -0000 @@ -330,30 +330,18 @@ function statistics_block_save($delta = * Implement hook_block_view(). */ function statistics_block_view($delta = '') { - if (user_access('access content')) { - $content = array(); - - $daytop = variable_get('statistics_block_top_day_num', 0); - if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && ($node_title_list = node_title_list($result, t("Today's:")))) { - $content[] = $node_title_list; - } - - $alltimetop = variable_get('statistics_block_top_all_num', 0); - if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && ($node_title_list = node_title_list($result, t('All time:')))) { - $content[] = $node_title_list; - } + $block = array(); + module_load_include('inc', 'statistics', 'statistics.blocks'); - $lasttop = variable_get('statistics_block_top_last_num', 0); - if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && ($node_title_list = node_title_list($result, t('Last viewed:')))) { - $content[] = $node_title_list; - } - - if (count($content)) { - $block['content'] = implode('
', $content); + if (user_access('access content')) { + $content = statistics_popular_block(); + if (!empty($content)) { + $block['content'] = statistics_popular_block(); $block['subject'] = t('Popular content'); - return $block; } } + + return $block; } /** Index: modules/user/user.blocks.inc =================================================================== RCS file: modules/user/user.blocks.inc diff -N modules/user/user.blocks.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/user/user.blocks.inc 4 Oct 2009 17:15:19 -0000 @@ -0,0 +1,80 @@ + drupal_get_destination())); + $form['#id'] = 'user-login-form'; + $form['#validate'] = user_login_default_validators(); + $form['#submit'][] = 'user_login_submit'; + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Username'), + '#maxlength' => USERNAME_MAX_LENGTH, + '#size' => 15, + '#required' => TRUE, + ); + $form['pass'] = array( + '#type' => 'password', + '#title' => t('Password'), + '#maxlength' => 60, + '#size' => 15, + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Log in'), + ); + $items = array(); + if (variable_get('user_register', 1)) { + $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.')))); + } + $items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); + $form['links'] = array('#markup' => theme('item_list', $items)); + return $form; +} + +function user_online_block() { + // Count users active within the defined period. + $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900); + + // Perform database queries to gather online user lists. We use s.timestamp + // rather than u.access because it is much faster. + $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField(); + + // When page caching is enabled, sessions are only created for + // anonymous users when needed. + if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) { + $anonymous_count = drupal_session_count($interval); + // Format the output with proper grammar. + if ($anonymous_count == 1 && $authenticated_count == 1) { + $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests'))); + } + else { + $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests'))); + } + } + else { + $output = format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.'); + } + + // Display a list of currently online users. + $max_users = variable_get('user_block_max_list_count', 10); + if ($authenticated_count && $max_users) { + $items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', 0, $max_users, array(':interval' => $interval))->fetchAll(); + $output .= theme('user_list', $items, t('Online users')); + } + + return $output; +} + +function user_new_block() { + // Retrieve a list of new users who have subsequently accessed the site successfully. + $items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, variable_get('user_block_whois_new_count', 5))->fetchAll(); + $output = theme('user_list', $items); + return $output; +} Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1055 diff -u -p -r1.1055 user.module --- modules/user/user.module 2 Oct 2009 14:49:10 -0000 1.1055 +++ modules/user/user.module 4 Oct 2009 18:45:36 -0000 @@ -933,35 +933,6 @@ function user_user_categories() { )); } -function user_login_block($form) { - $form['#action'] = url($_GET['q'], array('query' => drupal_get_destination())); - $form['#id'] = 'user-login-form'; - $form['#validate'] = user_login_default_validators(); - $form['#submit'][] = 'user_login_submit'; - $form['name'] = array('#type' => 'textfield', - '#title' => t('Username'), - '#maxlength' => USERNAME_MAX_LENGTH, - '#size' => 15, - '#required' => TRUE, - ); - $form['pass'] = array('#type' => 'password', - '#title' => t('Password'), - '#maxlength' => 60, - '#size' => 15, - '#required' => TRUE, - ); - $form['submit'] = array('#type' => 'submit', - '#value' => t('Log in'), - ); - $items = array(); - if (variable_get('user_register', 1)) { - $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.')))); - } - $items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); - $form['links'] = array('#markup' => theme('item_list', $items)); - return $form; -} - /** * Implement hook_block_info(). */ @@ -1028,67 +999,34 @@ function user_block_save($delta = '', $e */ function user_block_view($delta = '') { global $user; - $block = array(); + module_load_include('inc', 'user', 'user.blocks'); switch ($delta) { case 'login': // For usability's sake, avoid showing two login forms on one page. if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) { - $block['subject'] = t('User login'); $block['content'] = drupal_get_form('user_login_block'); } - return $block; + break; case 'new': if (user_access('access content')) { - // Retrieve a list of new users who have subsequently accessed the site successfully. - $items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, variable_get('user_block_whois_new_count', 5))->fetchAll(); - $output = theme('user_list', $items); - - $block['subject'] = t('Who\'s new'); - $block['content'] = $output; + $block['subject'] = t("Who's new"); + $block['content'] = user_new_block(); } - return $block; + break; case 'online': if (user_access('access content')) { - // Count users active within the defined period. - $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900); - - // Perform database queries to gather online user lists. We use s.timestamp - // rather than u.access because it is much faster. - $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField(); - - // When page caching is enabled, sessions are only created for - // anonymous users when needed. - if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) { - $anonymous_count = drupal_session_count($interval); - // Format the output with proper grammar. - if ($anonymous_count == 1 && $authenticated_count == 1) { - $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests'))); - } - else { - $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests'))); - } - } - else { - $output = format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.'); - } - - // Display a list of currently online users. - $max_users = variable_get('user_block_max_list_count', 10); - if ($authenticated_count && $max_users) { - $items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', 0, $max_users, array(':interval' => $interval))->fetchAll(); - $output .= theme('user_list', $items, t('Online users')); - } - - $block['subject'] = t('Who\'s online'); - $block['content'] = $output; + $block['subject'] = t("Who's online"); + $block['content'] = user_online_block(); } - return $block; + break; } + + return $block; } /**