diff options
-rw-r--r-- | database/database.mysql | 3 | ||||
-rw-r--r-- | database/database.pgsql | 4 | ||||
-rw-r--r-- | database/updates.inc | 11 | ||||
-rw-r--r-- | modules/block.module | 61 | ||||
-rw-r--r-- | modules/block/block.module | 61 |
5 files changed, 107 insertions, 33 deletions
diff --git a/database/database.mysql b/database/database.mysql index 3a02be088..2b7bdc131 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -126,7 +126,8 @@ CREATE TABLE blocks ( custom tinyint(2) DEFAULT '0' NOT NULL, throttle tinyint(1) DEFAULT '0' NOT NULL, visibility tinyint(1) DEFAULT '0' NOT NULL, - pages text NOT NULL + pages text NOT NULL, + types text NOT NULL ) TYPE=MyISAM; -- diff --git a/database/database.pgsql b/database/database.pgsql index d2d807f24..de167cd41 100644 --- a/database/database.pgsql +++ b/database/database.pgsql @@ -55,7 +55,9 @@ CREATE TABLE blocks ( region smallint NOT NULL default '0', path varchar(255) NOT NULL default '', custom smallint NOT NULL default '0', - throttle smallint NOT NULL default '0' + throttle smallint NOT NULL default '0', + pages text default '', + types text default '' ); -- diff --git a/database/updates.inc b/database/updates.inc index 34272a0a9..fdcde4c61 100644 --- a/database/updates.inc +++ b/database/updates.inc @@ -97,7 +97,8 @@ $sql_updates = array( "2005-01-19" => "update_118", "2005-01-20" => "update_119", "2005-01-25" => "update_120", - "2005-01-26" => "update_121" + "2005-01-26" => "update_121", + "2005-01-27" => "update_122" ); function update_32() { @@ -2169,6 +2170,14 @@ function update_121() { return $ret; } +function update_122() { + + $ret = array(); + $ret[] = update_sql("ALTER TABLE {blocks} ADD type text"); + return $ret; + +} + function update_sql($sql) { $edit = $_POST["edit"]; $result = db_query($sql); diff --git a/modules/block.module b/modules/block.module index cec0a6c0b..687f0412a 100644 --- a/modules/block.module +++ b/modules/block.module @@ -152,15 +152,16 @@ function _block_rehash($order_by = array('weight')) { $block['pages'] = $old_blocks[$module][$delta]->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; @@ -191,7 +192,7 @@ function block_admin_display() { 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 +227,13 @@ function block_admin_configure($module = NULL, $delta = 0) { 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); + if ($edit['types']) { + $types = implode(',', $edit['types']); + } + else { + $types = ''; + } + 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'], $types, $module, $delta); module_invoke($module, 'block', 'save', $delta, $edit); drupal_set_message('The block configuration has been saved.'); cache_clear_all(); @@ -235,7 +242,7 @@ function block_admin_configure($module = NULL, $delta = 0) { 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. @@ -243,17 +250,23 @@ function block_admin_configure($module = NULL, $delta = 0) { $form = form_group(t('Block-specific settings'), $settings); } + foreach (node_list() as $type) { + $content_types[$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 '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page. ")); + $group_1 = 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.')); + $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'))); + $group_2 .= 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 '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page. ")); + $group_3 = form_checkboxes(t('Restrict block to specific content types'), 'types', explode(',', $edit['types']), $content_types, t('Selecting one or more content types will cause this block to only be shown on pages of the selected types. This featue works alone or in conjunction with page specific visibility settings. For example, you can specify that a block only appear on book pages in the \'FAQ\' path.'), 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('User specific visibility settings'), $group_1); + $form .= form_group(t('Page specific visibility settings'), $group_2); + $form .= form_group(t('Content specific visibility settings'), $group_3); - $form .= form_group(t('Visibility settings'), $group); $form .= form_submit(t('Save block')); @@ -293,12 +306,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' => '<em>'. $box['info'] .'</em>'))); + drupal_set_message(t('The block %name has been deleted.', array('%name' => '<em>' . $box['info'] . '</em>'))); cache_clear_all(); drupal_goto('admin/block'); default: - $form = '<p>'. t('Are you sure you want to delete the block %name?', array('%name' => '<em>'. $box['info'] .'</em>')) ."</p>\n"; + $form = '<p>' . t('Are you sure you want to delete the block %name?', array('%name' => '<em>' . $box['info'] . '</em>')) . "</p>\n"; $form .= form_submit(t('Delete')); $output = form($form); } @@ -415,13 +428,31 @@ function block_list($region) { if ($block['pages']) { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), 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))) { + $node = node_load(array('nid' => arg(1))); + $types = explode(',', $block['types']); + //Match on any one selected type + foreach ($types as $type) { + if ($node->type == $type) { + $type_match = TRUE; + break; + } + } + } } 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))) { diff --git a/modules/block/block.module b/modules/block/block.module index cec0a6c0b..687f0412a 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -152,15 +152,16 @@ function _block_rehash($order_by = array('weight')) { $block['pages'] = $old_blocks[$module][$delta]->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; @@ -191,7 +192,7 @@ function block_admin_display() { 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 +227,13 @@ function block_admin_configure($module = NULL, $delta = 0) { 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); + if ($edit['types']) { + $types = implode(',', $edit['types']); + } + else { + $types = ''; + } + 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'], $types, $module, $delta); module_invoke($module, 'block', 'save', $delta, $edit); drupal_set_message('The block configuration has been saved.'); cache_clear_all(); @@ -235,7 +242,7 @@ function block_admin_configure($module = NULL, $delta = 0) { 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. @@ -243,17 +250,23 @@ function block_admin_configure($module = NULL, $delta = 0) { $form = form_group(t('Block-specific settings'), $settings); } + foreach (node_list() as $type) { + $content_types[$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 '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page. ")); + $group_1 = 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.')); + $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'))); + $group_2 .= 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 '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page. ")); + $group_3 = form_checkboxes(t('Restrict block to specific content types'), 'types', explode(',', $edit['types']), $content_types, t('Selecting one or more content types will cause this block to only be shown on pages of the selected types. This featue works alone or in conjunction with page specific visibility settings. For example, you can specify that a block only appear on book pages in the \'FAQ\' path.'), 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('User specific visibility settings'), $group_1); + $form .= form_group(t('Page specific visibility settings'), $group_2); + $form .= form_group(t('Content specific visibility settings'), $group_3); - $form .= form_group(t('Visibility settings'), $group); $form .= form_submit(t('Save block')); @@ -293,12 +306,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' => '<em>'. $box['info'] .'</em>'))); + drupal_set_message(t('The block %name has been deleted.', array('%name' => '<em>' . $box['info'] . '</em>'))); cache_clear_all(); drupal_goto('admin/block'); default: - $form = '<p>'. t('Are you sure you want to delete the block %name?', array('%name' => '<em>'. $box['info'] .'</em>')) ."</p>\n"; + $form = '<p>' . t('Are you sure you want to delete the block %name?', array('%name' => '<em>' . $box['info'] . '</em>')) . "</p>\n"; $form .= form_submit(t('Delete')); $output = form($form); } @@ -415,13 +428,31 @@ function block_list($region) { if ($block['pages']) { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), 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))) { + $node = node_load(array('nid' => arg(1))); + $types = explode(',', $block['types']); + //Match on any one selected type + foreach ($types as $type) { + if ($node->type == $type) { + $type_match = TRUE; + break; + } + } + } } 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))) { |