? sites/default/files ? sites/default/settings.php Index: modules/block/block.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v retrieving revision 1.31 diff -u -p -r1.31 block.admin.inc --- modules/block/block.admin.inc 22 Nov 2008 11:14:48 -0000 1.31 +++ modules/block/block.admin.inc 15 Dec 2008 15:04:31 -0000 @@ -171,14 +171,14 @@ function block_admin_configure(&$form_st ); // Module-specific block configurations. - if ($settings = module_invoke($module, 'block', 'configure', $delta)) { + if ($settings = module_invoke($module, 'block_configure', $delta)) { foreach ($settings as $k => $v) { $form['block_settings'][$k] = $v; } } // Get the block subject for the page title. - $info = module_invoke($module, 'block', 'list'); + $info = module_invoke($module, 'block_list'); if (isset($info[$delta])) { drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])), PASS_THROUGH); } @@ -285,7 +285,7 @@ function block_admin_configure_submit($f foreach (array_filter($form_state['values']['roles']) as $rid) { db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']); } - module_invoke($form_state['values']['module'], 'block', 'save', $form_state['values']['delta'], $form_state['values']); + module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']); drupal_set_message(t('The block configuration has been saved.')); cache_clear_all(); $form_state['redirect'] = 'admin/build/block'; Index: modules/block/block.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.api.php,v retrieving revision 1.1 diff -u -p -r1.1 block.api.php --- modules/block/block.api.php 25 Nov 2008 02:37:31 -0000 1.1 +++ modules/block/block.api.php 15 Dec 2008 15:04:31 -0000 @@ -12,87 +12,85 @@ */ /** - * Declare a block or set of blocks. + * List of all blocks defined by the module. * * Any module can export a block (or blocks) to be displayed by defining * the _block hook. This hook is called by theme.inc to display a block, * and also by block.module to procure the list of available blocks. * - * @param $op - * What kind of information to retrieve about the block or blocks. - * Possible values: - * - 'list': A list of all blocks defined by the module. - * - 'configure': Configuration form for the block. - * - 'save': Save the configuration options. - * - 'view': Process the block when enabled in a region in order to view its contents. - * @param $delta - * Which block to return (not applicable if $op is 'list'). This is a - * descriptive string used to identify blocks within each module and also - * within the theme system. The $delta for each block is defined within - * the array that your module returns when $op is 'list' (see below). - * @param $edit - * If $op is 'save', the submitted form data from the configuration form. * @return - * - If $op is 'list': An associative array whose keys define the $delta - * for each block and whose values contain the block descriptions. Each - * block description is itself an associative array, with the following - * key-value pairs: - * - 'info': (required) The human-readable name of the block. - * - 'cache': A bitmask of flags describing how the block should behave with - * respect to block caching. The following shortcut bitmasks are provided - * as constants in block.module: - * - BLOCK_CACHE_PER_ROLE (default): The block can change depending on the - * roles the user viewing the page belongs to. - * - BLOCK_CACHE_PER_USER: The block can change depending on the user - * viewing the page. This setting can be resource-consuming for sites - * with large number of users, and should only be used when - * BLOCK_CACHE_PER_ROLE is not sufficient. - * - BLOCK_CACHE_PER_PAGE: The block can change depending on the page - * being viewed. - * - BLOCK_CACHE_GLOBAL: The block is the same for every user on every - * page where it is visible. - * - BLOCK_NO_CACHE: The block should not get cached. - * - 'weight', 'status', 'region', 'visibility', 'pages': - * You can give your blocks an explicit weight, enable them, limit them to - * given pages, etc. These settings will be registered when the block is first - * loaded at admin/block, and from there can be changed manually via block - * administration. - * Note that if you set a region that isn't available in a given theme, the - * block will be registered instead to that theme's default region (the first - * item in the _regions array). - * - If $op is 'configure': optionally return the configuration form. - * - If $op is 'save': return nothing. - * - If $op is 'view': return an array which must define a 'subject' element - * and a 'content' element defining the block indexed by $delta. - * - * The functions mymodule_display_block_exciting and _amazing, as used in the - * example, should of course be defined somewhere in your module and return the - * content you want to display to your users. If the "content" element is empty, - * no block will be displayed even if "subject" is present. + * An associative array whose keys define the $delta + * for each block and whose values contain the block descriptions. Each + * block description is itself an associative array, with the following + * key-value pairs: + * - 'info': (required) The human-readable name of the block. + * - 'cache': A bitmask of flags describing how the block should behave with + * respect to block caching. The following shortcut bitmasks are provided + * as constants in block.module: + * - BLOCK_CACHE_PER_ROLE (default): The block can change depending on the + * roles the user viewing the page belongs to. + * - BLOCK_CACHE_PER_USER: The block can change depending on the user + * viewing the page. This setting can be resource-consuming for sites + * with large number of users, and should only be used when + * BLOCK_CACHE_PER_ROLE is not sufficient. + * - BLOCK_CACHE_PER_PAGE: The block can change depending on the page + * being viewed. + * - BLOCK_CACHE_GLOBAL: The block is the same for every user on every + * page where it is visible. + * - BLOCK_NO_CACHE: The block should not get cached. + * - 'weight', 'status', 'region', 'visibility', 'pages': + * You can give your blocks an explicit weight, enable them, limit them to + * given pages, etc. These settings will be registered when the block is first + * loaded at admin/block, and from there can be changed manually via block + * administration. + * Note that if you set a region that isn't available in a given theme, the + * block will be registered instead to that theme's default region (the first + * item in the _regions array). * * After completing your blocks, do not forget to enable them in the * block admin menu. * * For a detailed usage example, see block_example.module. */ -function hook_block($op = 'list', $delta = '', $edit = array()) { - if ($op == 'list') { - $blocks['exciting'] = array( - 'info' => t('An exciting block provided by Mymodule.'), - 'weight' => 0, - 'status' => 1, - 'region' => 'left', - // BLOCK_CACHE_PER_ROLE will be assumed for block 0. - ); +function hook_block_list() { + $blocks['exciting'] = array( + 'info' => t('An exciting block provided by Mymodule.'), + 'weight' => 0, + 'status' => 1, + 'region' => 'left', + // BLOCK_CACHE_PER_ROLE will be assumed for block 0. + ); - $blocks['amazing'] = array( - 'info' => t('An amazing block provided by Mymodule.'), - 'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE, - ); + $blocks['amazing'] = array( + 'info' => t('An amazing block provided by Mymodule.'), + 'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE, + ); - return $blocks; - } - elseif ($op == 'configure' && $delta == 'exciting') { + return $blocks; +} + +/** + * Configuration form for the block. + * + * Any module can export a block (or blocks) to be displayed by defining + * the _block hook. This hook is called by theme.inc to display a block, + * and also by block.module to procure the list of available blocks. + * + * @param $delta + * Which block to return. This is a descriptive string used to identify + * blocks within each module and also within the theme system. + * The $delta for each block is defined within the array that your module + * returns when the hook_block_list() implementation is called. + * @return + * Optionally return the configuration form. + * + * After completing your blocks, do not forget to enable them in the + * block admin menu. + * + * For a detailed usage example, see block_example.module. + */ +function hook_block_configure($delta = '') { + if ($delta == 'exciting') { $form['items'] = array( '#type' => 'select', '#title' => t('Number of items'), @@ -101,26 +99,76 @@ function hook_block($op = 'list', $delta ); return $form; } - elseif ($op == 'save' && $delta == 'exciting') { +} + +/** + * Save the configuration options. + * + * Any module can export a block (or blocks) to be displayed by defining + * the _block hook. This hook is called by theme.inc to display a block, + * and also by block.module to procure the list of available blocks. + * + * @param $delta + * Which block to save the settings for. This is a descriptive string used + * to identify blocks within each module and also within the theme system. + * The $delta for each block is defined within the array that your module + * returns when the hook_block_list() implementation is called. + * @param $edit + * The submitted form data from the configuration form. + * + * After completing your blocks, do not forget to enable them in the + * block admin menu. + * + * For a detailed usage example, see block_example.module. + */ +function hook_block_save($delta = '', $edit = array()) { + if ($delta == 'exciting') { variable_set('mymodule_block_items', $edit['items']); } - elseif ($op == 'view') { - switch ($delta) { - case 'exciting': - $block = array( - 'subject' => t('Default title of the exciting block'), - 'content' => mymodule_display_block_exciting(), - ); - break; - case 'amazing': - $block = array( - 'subject' => t('Default title of the amazing block'), - 'content' => mymodule_display_block_amazing(), - ); - break; - } - return $block; +} + +/** + * Process the block when enabled in a region in order to view its contents. + * + * Any module can export a block (or blocks) to be displayed by defining + * the _block hook. This hook is called by theme.inc to display a block, + * and also by block.module to procure the list of available blocks. + * + * @param $delta + * Which block to return. This is a descriptive string used to identify + * blocks within each module and also within the theme system. + * The $delta for each block is defined within the array that your module + * returns when the hook_block_list() implementation is called. + * @return + * An array which must define a 'subject' element and a 'content' element + * defining the block indexed by $delta. + * + * The functions mymodule_display_block_exciting and _amazing, as used in the + * example, should of course be defined somewhere in your module and return the + * content you want to display to your users. If the "content" element is empty, + * no block will be displayed even if "subject" is present. + * + * After completing your blocks, do not forget to enable them in the + * block admin menu. + * + * For a detailed usage example, see block_example.module. + */ +function hook_block_view($delta = '') { + switch ($delta) { + case 'exciting' + $block = array( + 'subject' => t('Default title of the exciting block'), + 'content' => mymodule_display_block_exciting(), + ); + break; + case 'amazing': + $block = array( + 'subject' => t('Default title of the amazing block'), + 'content' => mymodule_display_block_amazing(), + ); + break; } + return $block; } /** Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.315 diff -u -p -r1.315 block.module --- modules/block/block.module 15 Nov 2008 08:23:07 -0000 1.315 +++ modules/block/block.module 15 Dec 2008 15:04:31 -0000 @@ -180,42 +180,55 @@ function _block_themes_access($theme) { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). * - * Generates the administrator-defined blocks for display. + * Generates a list of the administrator-defined blocks. */ -function block_block($op = 'list', $delta = 0, $edit = array()) { - switch ($op) { - case 'list': - $blocks = array(); - - $result = db_query('SELECT bid, info FROM {box} ORDER BY info'); - while ($block = db_fetch_object($result)) { - $blocks[$block->bid]['info'] = $block->info; - // Not worth caching. - $blocks[$block->bid]['cache'] = BLOCK_NO_CACHE; - } - return $blocks; +function block_block_list() { + $blocks = array(); - case 'configure': - $box = array('format' => FILTER_FORMAT_DEFAULT); - if ($delta) { - $box = block_box_get($delta); - } - if (filter_access($box['format'])) { - return block_box_form($box); - } - break; + $result = db_query('SELECT bid, info FROM {box} ORDER BY info'); + while ($block = db_fetch_object($result)) { + $blocks[$block->bid]['info'] = $block->info; + // Not worth caching. + $blocks[$block->bid]['cache'] = BLOCK_NO_CACHE; + } + return $blocks; +} - case 'save': - block_box_save($edit, $delta); - break; - - case 'view': - $block = db_fetch_object(db_query('SELECT body, format FROM {box} WHERE bid = %d', $delta)); - $data['content'] = check_markup($block->body, $block->format, '', FALSE); - return $data; +/** + * Implementation of hook_block_configure(). + * + * Generates the configure for administrator-defined blocks. + */ +function block_block_configure($delta = 0, $edit = array()) { + $box = array('format' => FILTER_FORMAT_DEFAULT); + if ($delta) { + $box = block_box_get($delta); } + if (filter_access($box['format'])) { + return block_box_form($box); + } +} + +/** + * Implementation of hook_block_save(). + * + * Saves administrator-defined blocks. + */ +function block_block_save($delta = 0, $edit = array()) { + block_box_save($edit, $delta); +} + +/** + * Implementation of hook_block_view(). + * + * Generates the administrator-defined blocks for display. + */ +function block_block_view($delta = 0, $edit = array()) { + $block = db_fetch_object(db_query('SELECT body, format FROM {box} WHERE bid = %d', $delta)); + $data['content'] = check_markup($block->body, $block->format, '', FALSE); + return $data; } /** @@ -239,8 +252,8 @@ function _block_rehash() { // Valid region names for the theme. $regions = system_region_list($theme_key); - foreach (module_implements('block') as $module) { - $module_blocks = module_invoke($module, 'block', 'list'); + foreach (module_implements('block_list') as $module) { + $module_blocks = module_invoke($module, 'block_list'); if ($module_blocks) { foreach ($module_blocks as $delta => $block) { if (empty($old_blocks[$module][$delta])) { @@ -258,7 +271,7 @@ function _block_rehash() { drupal_write_record('block', $block); // Set region to none if not enabled. $block['region'] = $block['status'] ? $block['region'] : BLOCK_REGION_NONE; - // Add to the list of blocks we return. + // Add to the list of blocks we return.drupal davereid $blocks[] = $block; } else { @@ -349,7 +362,7 @@ function block_user_form(&$edit, &$accou $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids); $form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE); while ($block = db_fetch_object($result)) { - $data = module_invoke($block->module, 'block', 'list'); + $data = module_invoke($block->module, 'block_list'); if ($data[$block->delta]['info']) { $return = TRUE; $form['block'][$block->module][$block->delta] = array('#type' => 'checkbox', '#title' => check_plain($data[$block->delta]['info']), '#default_value' => isset($account->block[$block->module][$block->delta]) ? $account->block[$block->module][$block->delta] : ($block->custom == 1)); @@ -483,7 +496,7 @@ function _block_render_blocks($region_bl $array = $cache->data; } else { - $array = module_invoke($block->module, 'block', 'view', $block->delta); + $array = module_invoke($block->module, 'block_view', $block->delta); if (isset($cid)) { cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY); } Index: modules/blog/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.module,v retrieving revision 1.313 diff -u -p -r1.313 blog.module --- modules/blog/blog.module 9 Dec 2008 11:30:23 -0000 1.313 +++ modules/blog/blog.module 15 Dec 2008 15:04:31 -0000 @@ -165,25 +165,28 @@ function _blog_post_exists($account) { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). * * Displays the most recent 10 blog titles. */ -function blog_block($op = 'list', $delta = '') { +function blog_block_list() { + $block['recent']['info'] = t('Recent blog posts'); + return $block; +} + +/** + * Implementation of hook_block_view(). + */ +function blog_block_view($delta = '') { global $user; - if ($op == 'list') { - $block['recent']['info'] = t('Recent blog posts'); - return $block; - } - elseif ($op == 'view') { - if (user_access('access content')) { - $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10); - 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.')); - $block['subject'] = t('Recent blog posts'); - return $block; - } + + if (user_access('access content')) { + $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10); + 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.')); + $block['subject'] = t('Recent blog posts'); + return $block; } } } Index: modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.476 diff -u -p -r1.476 forum.module --- modules/forum/forum.module 13 Dec 2008 14:05:11 -0000 1.476 +++ modules/forum/forum.module 15 Dec 2008 15:04:32 -0000 @@ -466,50 +466,66 @@ function forum_form_alter(&$form, $form_ } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). * * Generates a block containing the currently active forum topics and the * most recently added forum topics. */ -function forum_block($op = 'list', $delta = '', $edit = array()) { - switch ($op) { - case 'list': - $blocks['active']['info'] = t('Active forum topics'); - $blocks['new']['info'] = t('New forum topics'); - return $blocks; - - case 'configure': - $form['forum_block_num_' . $delta] = array('#type' => 'select', '#title' => t('Number of topics'), '#default_value' => variable_get('forum_block_num_' . $delta, '5'), '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))); - return $form; +function forum_block_list() { + $blocks['active']['info'] = t('Active forum topics'); + $blocks['new']['info'] = t('New forum topics'); + return $blocks; +} - case 'save': - variable_set('forum_block_num_' . $delta, $edit['forum_block_num_' . $delta]); - break; +/** + * Implementation of hook_block_configure(). + * + * Generates a block containing the currently active forum topics and the + * most recently added forum topics. + */ +function forum_block_configure($delta = '') { + $form['forum_block_num_' . $delta] = array('#type' => 'select', '#title' => t('Number of topics'), '#default_value' => variable_get('forum_block_num_' . $delta, '5'), '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))); + return $form; +} - case 'view': - if (user_access('access content')) { - switch ($delta) { - case 'active': - $title = t('Active forum topics'); - $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY l.last_comment_timestamp DESC"); - $result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_active', '5')); - $content = node_title_list($result); - break; - - case 'new': - $title = t('New forum topics'); - $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY n.nid DESC"); - $result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_new', '5')); - $content = node_title_list($result); - break; - } - - if (!empty($content)) { - $block['subject'] = $title; - $block['content'] = $content . theme('more_link', url('forum'), t('Read the latest forum topics.')); - return $block; - } - } +/** + * Implementation of hook_block_save(). + * + * Generates a block containing the currently active forum topics and the + * most recently added forum topics. + */ +function forum_block_save($delta = '', $edit = array()) { + variable_set('forum_block_num_' . $delta, $edit['forum_block_num_' . $delta]); +} + +/** + * Implementation of hook_block_view(). + * + * Generates a block containing the currently active forum topics and the + * most recently added forum topics. + */ +function forum_block_view($delta = '') { + if (user_access('access content')) { + switch ($delta) { + case 'active': + $title = t('Active forum topics'); + $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY l.last_comment_timestamp DESC"); + $result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_active', '5')); + $content = node_title_list($result); + break; + case 'new': + $title = t('New forum topics'); + $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY n.nid DESC"); + $result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_new', '5')); + $content = node_title_list($result); + break; + } + + if (!empty($content)) { + $block['subject'] = $title; + $block['content'] = $content . theme('more_link', url('forum'), t('Read the latest forum topics.')); + return $block; + } } } Index: modules/menu/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v retrieving revision 1.175 diff -u -p -r1.175 menu.module --- modules/menu/menu.module 13 Nov 2008 05:54:35 -0000 1.175 +++ modules/menu/menu.module 15 Dec 2008 15:04:32 -0000 @@ -257,28 +257,35 @@ function menu_reset_item($item) { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). */ -function menu_block($op = 'list', $delta = '') { +function menu_block_list() { $menus = menu_get_menus(); // The Navigation menu is handled by the user module. unset($menus['navigation']); - if ($op == 'list') { - $blocks = array(); - foreach ($menus as $name => $title) { - // Default "Navigation" block is handled by user.module. - $blocks[$name]['info'] = check_plain($title); - // Menu blocks can't be cached because each menu item can have - // a custom access callback. menu.inc manages its own caching. - $blocks[$name]['cache'] = BLOCK_NO_CACHE; - } - return $blocks; - } - elseif ($op == 'view') { - $data['subject'] = check_plain($menus[$delta]); - $data['content'] = menu_tree($delta); - return $data; + + $blocks = array(); + foreach ($menus as $name => $title) { + // Default "Navigation" block is handled by user.module. + $blocks[$name]['info'] = check_plain($title); + // Menu blocks can't be cached because each menu item can have + // a custom access callback. menu.inc manages its own caching. + $blocks[$name]['cache'] = BLOCK_NO_CACHE; } + return $blocks; +} + +/** + * Implementation of hook_block_view(). + */ +function menu_block_view($delta = '') { + $menus = menu_get_menus(); + // The Navigation menu is handled by the user module. + unset($menus['navigation']); + + $data['subject'] = check_plain($menus[$delta]); + $data['content'] = menu_tree($delta); + return $data; } /** Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.944 diff -u -p -r1.944 user.module --- modules/user/user.module 29 Nov 2008 09:33:51 -0000 1.944 +++ modules/user/user.module 15 Dec 2008 15:04:34 -0000 @@ -733,112 +733,135 @@ function user_login_block() { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). */ -function user_block($op = 'list', $delta = '', $edit = array()) { +function user_block_list() { global $user; - if ($op == 'list') { - $blocks['login']['info'] = t('User login'); - // Not worth caching. - $blocks['login']['cache'] = BLOCK_NO_CACHE; - - $blocks['navigation']['info'] = t('Navigation'); - // Menu blocks can't be cached because each menu item can have - // a custom access callback. menu.inc manages its own caching. - $blocks['navigation']['cache'] = BLOCK_NO_CACHE; - - $blocks['new']['info'] = t('Who\'s new'); - - // Too dynamic to cache. - $blocks['online']['info'] = t('Who\'s online'); - $blocks['online']['cache'] = BLOCK_NO_CACHE; - return $blocks; - } - elseif ($op == 'configure' && $delta == 'new') { - $form['user_block_whois_new_count'] = array( - '#type' => 'select', - '#title' => t('Number of users to display'), - '#default_value' => variable_get('user_block_whois_new_count', 5), - '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), - ); - return $form; - } - elseif ($op == 'configure' && $delta == 'online') { - $period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval'); - $form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.')); - $form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.')); + $blocks['login']['info'] = t('User login'); + // Not worth caching. + $blocks['login']['cache'] = BLOCK_NO_CACHE; - return $form; - } - elseif ($op == 'save' && $delta == 'new') { - variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']); + $blocks['navigation']['info'] = t('Navigation'); + // Menu blocks can't be cached because each menu item can have + // a custom access callback. menu.inc manages its own caching. + $blocks['navigation']['cache'] = BLOCK_NO_CACHE; + + $blocks['new']['info'] = t('Who\'s new'); + + // Too dynamic to cache. + $blocks['online']['info'] = t('Who\'s online'); + $blocks['online']['cache'] = BLOCK_NO_CACHE; + return $blocks; +} + +/** + * Implementation of hook_block_configure(). + */ +function user_block_configure($delta = '') { + global $user; + + switch($delta) { + case 'new': + $form['user_block_whois_new_count'] = array( + '#type' => 'select', + '#title' => t('Number of users to display'), + '#default_value' => variable_get('user_block_whois_new_count', 5), + '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), + ); + return $form; + + case 'online': + $period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval'); + $form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.')); + $form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.')); + return $form; } - elseif ($op == 'save' && $delta == 'online') { - variable_set('user_block_seconds_online', $edit['user_block_seconds_online']); - variable_set('user_block_max_list_count', $edit['user_block_max_list_count']); +} + +/** + * Implementation of hook_block_save(). + */ +function user_block_save($delta = '', $edit = array()) { + global $user; + + switch ($delta) { + case 'new': + variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']); + break; + + case 'online': + variable_set('user_block_seconds_online', $edit['user_block_seconds_online']); + variable_set('user_block_max_list_count', $edit['user_block_max_list_count']); + break; } - elseif ($op == 'view') { - $block = array(); +} - 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)))) { +/** + * Implementation of hook_block_view(). + */ +function user_block_view($delta = '') { + global $user; - $block['subject'] = t('User login'); - $block['content'] = drupal_get_form('user_login_block'); - } - return $block; + $block = array(); - case 'navigation': - if ($menu = menu_tree()) { - $block['subject'] = $user->uid ? check_plain($user->name) : t('Navigation'); - $block['content'] = $menu; - } - return $block; + 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)))) { - 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', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll(); - $output = theme('user_list', $items); + $block['subject'] = t('User login'); + $block['content'] = drupal_get_form('user_login_block'); + } + return $block; - $block['subject'] = t('Who\'s new'); - $block['content'] = $output; - } - return $block; + case 'navigation': + if ($menu = menu_tree()) { + $block['subject'] = $user->uid ? check_plain($user->name) : t('Navigation'); + $block['content'] = $menu; + } + return $block; + + 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', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll(); + $output = theme('user_list', $items); - 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. - $anonymous_count = drupal_session_count($interval); - $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField(); - - // 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'))); - } - - // 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', array(':interval' => $interval), 0, $max_users)->fetchAll(); - $output .= theme('user_list', $items, t('Online users')); - } + $block['subject'] = t('Who\'s new'); + $block['content'] = $output; + } + return $block; - $block['subject'] = t('Who\'s online'); - $block['content'] = $output; + 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. + $anonymous_count = drupal_session_count($interval); + $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField(); + + // 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'))); } - return $block; - } + 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'))); + } + + // 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', array(':interval' => $interval), 0, $max_users)->fetchAll(); + $output .= theme('user_list', $items, t('Online users')); + } + + $block['subject'] = t('Who\'s online'); + $block['content'] = $output; + } + return $block; } } Index: modules/user/user.test =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.test,v retrieving revision 1.22 diff -u -p -r1.22 user.test --- modules/user/user.test 25 Nov 2008 13:14:29 -0000 1.22 +++ modules/user/user.test 15 Dec 2008 15:04:35 -0000 @@ -647,7 +647,7 @@ class UserBlocksUnitTests extends Drupal $this->insertSession(); // Test block output. - $block = user_block('view', 'online'); + $block = user_block_view('online'); $this->drupalSetContent($block['content']); $this->assertRaw(t('%members and %visitors', array('%members' => '2 users', '%visitors' => '2 guests')), t('Correct number of online users (2 users and 2 guests).')); $this->assertText($user1->name, t('Active user 1 found in online list.'));