Index: block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block.module,v retrieving revision 1.148 diff -u -F^f -r1.148 block.module --- block.module 6 Jan 2005 01:17:31 -0000 1.148 +++ block.module 25 Jan 2005 07:11:16 -0000 @@ -1,6 +1,5 @@ pages; $block['custom'] = $old_blocks[$module][$delta]->custom; $block['throttle'] = $old_blocks[$module][$delta]->throttle; + $block['types'] = $old_blocks[$module][$delta]->types; } else { $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0; - $block['pages'] = ''; + $block['pages'] = $block['types'] = ''; } - // reinsert blocks into table - db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d)", - $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']); + db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle, types) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d, '%s')", + $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['types']); $blocks[] = $block; - // build array to sort on $order[$order_by[0]][] = $block[$order_by[0]]; } } } - // sort array_multisort($order[$order_by[0]], $order_by[1] ? $order_by[1] : SORT_ASC, $order_by[2] ? $order_by[2] : SORT_REGULAR, $blocks); @@ -188,10 +185,9 @@ function block_admin_display() { } $header[] = array('data' => t('Operations'), 'colspan' => 2); - foreach ($blocks as $block) { if ($block['module'] == 'block') { - $operation = l(t('delete'), 'admin/block/delete/'. $block['delta']); + $operation = l(t('delete'), 'admin/block/delete/' . $block['delta']); } else { $operation = ''; @@ -226,7 +222,7 @@ function block_admin_configure($module = switch ($op) { case t('Save block'): - db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $module, $delta); + db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, types = '%s' WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], implode(',', $edit['types']), $module, $delta); module_invoke($module, 'block', 'save', $delta, $edit); drupal_set_message('The block configuration has been saved.'); cache_clear_all(); @@ -235,24 +231,24 @@ function block_admin_configure($module = default: // Always evaluates to TRUE, but a validation step may be added later. if (!$edit) { - $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); + $edit = db_fetch_array(db_query("SELECT pages, visibility, custom, types FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); } - // Module-specific block configurations. if ($settings = module_invoke($module, 'block', 'configure', $delta)) { $form = form_group(t('Block-specific settings'), $settings); } + foreach (node_list() as $type) { + $nodetypes[$type] = node_invoke($type, 'node_name'); + } // Get the block subject for the page title. $info = module_invoke($module, 'block', 'list'); drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); - // Standard block configurations. $group = form_radios(t('Show on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'))); $group .= form_textarea(t('Pages'), 'pages', $edit['pages'], 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' is the front page. ")); - + $group .= form_checkboxes(t('Show for specific node types'), 'types', explode(',', $edit['types']), $nodetypes, t('Show this block only on pages of these node types.'), NULL, FALSE); $group .= form_radios(t('Custom visibility settings'), 'custom', $edit['custom'], array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.')); - $form .= form_group(t('Visibility settings'), $group); $form .= form_submit(t('Save block')); @@ -293,12 +289,12 @@ function block_box_delete($bid = 0) { switch ($op) { case t('Delete'): db_query('DELETE FROM {boxes} WHERE bid = %d', $bid); - drupal_set_message(t('The block %name has been deleted.', array('%name' => ''. $box['info'] .''))); + drupal_set_message(t('The block %name has been deleted.', array('%name' => '' . $box['info'] . ''))); cache_clear_all(); drupal_goto('admin/block'); default: - $form = '

'. t('Are you sure you want to delete the block %name?', array('%name' => ''. $box['info'] .'')) ."

\n"; + $form = '

' . t('Are you sure you want to delete the block %name?', array('%name' => '' . $box['info'] . '')) . "

\n"; $form .= form_submit(t('Delete')); $output = form($form); } @@ -410,18 +406,33 @@ function block_list($region) { else { $enabled = TRUE; } - // Match path if necessary if ($block['pages']) { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($block['pages'], '/')) .')$/'; - $matched = !($block['visibility'] xor preg_match($regexp, $path)); + $page_match = !($block['visibility'] xor preg_match($regexp, $path)); + } + else { + $page_match = TRUE; + } + // Match node type if necessary + $type_match = FALSE; + if ($block['types'] != '') { + if (arg(0) == 'node' && is_numeric(arg(1))) { + $foo = db_query('SELECT type FROM {node} WHERE nid = %d', arg(1)); + $node = db_fetch_object($foo); + $types = explode(',', $block['types']); + //Match on any one selected type + foreach ($types as $type) { + if ($type_match = ($node->type == $type)) break 1; + } + } } else { - $matched = TRUE; + $type_match = TRUE; } - if ($enabled && $matched) { + if ($enabled && $page_match && $type_match) { // Check the current throttle status and see if block should be displayed // based on server load. if (!($block['throttle'] && (module_invoke('throttle', 'status') > 0))) { ***** CVS exited normally with code 1 *****