summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Sansbury2010-02-09 00:13:20 (GMT)
committerJames Sansbury2010-02-09 00:13:20 (GMT)
commitd55b6e917ec5a1e2b1411dba300b04ace35bf504 (patch)
tree87d63d99069a0745b71381084da3e78a12b13137
parent81be80a5785e49a92de56c769dbf773c7c31ee9f (diff)
Update HEAD from DRUPAL-6--1.
-rw-r--r--README.txt7
-rw-r--r--images/arrow.pngbin0 -> 187 bytes
-rw-r--r--images/bg_dark-hover.gifbin0 -> 258 bytes
-rw-r--r--images/bg_dark.gifbin0 -> 269 bytes
-rw-r--r--images/bg_gradient-short.pngbin0 -> 154 bytes
-rw-r--r--images/bg_gradient-tall.pngbin0 -> 200 bytes
-rw-r--r--images/bg_region-manager-menu.pngbin0 -> 174 bytes
-rw-r--r--images/btn_add.pngbin0 -> 4384 bytes
-rw-r--r--images/btn_configure.pngbin0 -> 5818 bytes
-rw-r--r--images/btn_create.pngbin0 -> 5479 bytes
-rw-r--r--images/btn_disable.pngbin0 -> 5301 bytes
-rw-r--r--images/btn_remove.pngbin0 -> 4892 bytes
-rw-r--r--images/manage-icon.pngbin0 -> 2262 bytes
-rw-r--r--region-manager-manage-form.tpl.php72
-rw-r--r--region_manager.admin.inc246
-rw-r--r--region_manager.admin.js4
-rw-r--r--region_manager.css258
-rw-r--r--region_manager.inc448
-rw-r--r--region_manager.info4
-rw-r--r--region_manager.install84
-rw-r--r--region_manager.js175
-rw-r--r--region_manager.module439
-rw-r--r--region_manager.nodeblock.inc76
-rw-r--r--region_manager.pages.inc383
24 files changed, 1520 insertions, 676 deletions
diff --git a/README.txt b/README.txt
index 2be07a0..fed4800 100644
--- a/README.txt
+++ b/README.txt
@@ -12,4 +12,9 @@ per module, or even per block. For example, you can specify that menu module
blocks are only available in the header, or that the navigation menu block is
not available for any region.
-Recommended additional modules are nodeblock, and region_visibility. \ No newline at end of file
+Recommended additional modules are NodeBlock, and Visibility API.
+
+Region Manager also allows you to implement your own block creation methods.
+Please see region_manager.nodeblock.inc for an example. Note: You may need to
+implement your own submit handler, depending on what kind of block you are
+creating. See region_manager_nodeapi() for an example. \ No newline at end of file
diff --git a/images/arrow.png b/images/arrow.png
new file mode 100644
index 0000000..f92dd78
--- /dev/null
+++ b/images/arrow.png
Binary files differ
diff --git a/images/bg_dark-hover.gif b/images/bg_dark-hover.gif
new file mode 100644
index 0000000..d453f58
--- /dev/null
+++ b/images/bg_dark-hover.gif
Binary files differ
diff --git a/images/bg_dark.gif b/images/bg_dark.gif
new file mode 100644
index 0000000..ad8c191
--- /dev/null
+++ b/images/bg_dark.gif
Binary files differ
diff --git a/images/bg_gradient-short.png b/images/bg_gradient-short.png
new file mode 100644
index 0000000..0118218
--- /dev/null
+++ b/images/bg_gradient-short.png
Binary files differ
diff --git a/images/bg_gradient-tall.png b/images/bg_gradient-tall.png
new file mode 100644
index 0000000..ec53737
--- /dev/null
+++ b/images/bg_gradient-tall.png
Binary files differ
diff --git a/images/bg_region-manager-menu.png b/images/bg_region-manager-menu.png
new file mode 100644
index 0000000..654c7a9
--- /dev/null
+++ b/images/bg_region-manager-menu.png
Binary files differ
diff --git a/images/btn_add.png b/images/btn_add.png
new file mode 100644
index 0000000..a4f3e50
--- /dev/null
+++ b/images/btn_add.png
Binary files differ
diff --git a/images/btn_configure.png b/images/btn_configure.png
new file mode 100644
index 0000000..8df4e2b
--- /dev/null
+++ b/images/btn_configure.png
Binary files differ
diff --git a/images/btn_create.png b/images/btn_create.png
new file mode 100644
index 0000000..cfe9bef
--- /dev/null
+++ b/images/btn_create.png
Binary files differ
diff --git a/images/btn_disable.png b/images/btn_disable.png
new file mode 100644
index 0000000..976b6cb
--- /dev/null
+++ b/images/btn_disable.png
Binary files differ
diff --git a/images/btn_remove.png b/images/btn_remove.png
new file mode 100644
index 0000000..50ff262
--- /dev/null
+++ b/images/btn_remove.png
Binary files differ
diff --git a/images/manage-icon.png b/images/manage-icon.png
new file mode 100644
index 0000000..a401185
--- /dev/null
+++ b/images/manage-icon.png
Binary files differ
diff --git a/region-manager-manage-form.tpl.php b/region-manager-manage-form.tpl.php
index ddbd1f7..702214f 100644
--- a/region-manager-manage-form.tpl.php
+++ b/region-manager-manage-form.tpl.php
@@ -6,23 +6,18 @@
* Default theme implementation to configure blocks.
*
* Available variables:
- * - $block_regions: An array of regions. Keyed by name with the title as value.
+ * - $block_states: An array of states. Keyed by name with the title as value.
* - $block_listing: An array of blocks keyed by region and then delta.
* - $form_submit: Form submit button.
*
- * Each $block_listing[$region] contains an array of blocks for that region.
+ * Each $block_listing[$state] contains an array of blocks for that region.
*
- * Each $data in $block_listing[$region] contains:
+ * Each $data in $block_listing[$state] contains:
* - $data->region_title: Region title for the listed block.
- * - $data->block_title: Block title.
- * - $data->region_select: Drop-down menu for assigning a region.
+ * - $data->block_config: Block title and other config options.
+ * - $data->state_select: Drop-down menu for assigning a state.
* - $data->weight_select: Drop-down menu for setting weights.
- * - $data->throttle_check: Checkbox to enable throttling.
- * - $data->configure_link: Block configuration link.
- * - $data->delete_link: For deleting user added blocks.
- *
- * @see template_preprocess_block_admin_display_form()
- * @see theme_block_admin_display()
+ * - $data->operations: Row containing all the operations for the block.
*/
?>
<?php
@@ -30,32 +25,37 @@
drupal_add_js('misc/tableheader.js');
drupal_add_js(drupal_get_path('module', 'region_manager') .'/region_manager.js');
drupal_add_js(array('block_name' => _region_manager_block_name()), 'setting');
- foreach ($block_regions as $region => $title) {
- drupal_add_tabledrag('blocks', 'match', 'sibling', 'block-region-select', 'block-region-'. $region, NULL, FALSE);
- drupal_add_tabledrag('blocks', 'order', 'sibling', 'block-weight', 'block-weight-'. $region);
+ foreach ($block_states as $state => $title) {
+ //drupal_add_tabledrag('blocks', 'match', 'sibling', 'block-region-select', 'block-region-'. $region, NULL, FALSE);
+ drupal_add_tabledrag('region-manager-blocks-active_path', 'order', 'sibling', 'block-weight');
}
?>
-<table id="blocks" class="sticky-enabled">
- <tbody>
- <?php $row = 0; ?>
- <?php foreach ($block_regions as $region => $title): ?>
- <tr class="region region-<?php print $region?>">
- <td colspan="4" class="region"><?php print $title; ?></td>
- </tr>
- <tr class="region-message region-<?php print $region?>-message <?php print empty($block_listing[$region]) ? 'region-empty' : 'region-populated'; ?>">
- <td colspan="4"><em><?php print t('No @blocks', array('@block' => _region_manager_block_name())); ?></em></td>
- </tr>
- <?php foreach ($block_listing[$region] as $delta => $data): ?>
- <tr class="<?php print $row % 2 == 0 ? 'odd' : 'even'; ?><?php print $data->row_class ? ' '. $data->row_class : ''; ?>">
- <td class="block"><?php print $data->block_title; ?></td>
- <td><?php print $data->region_select; ?></td>
- <td><?php print $data->weight_select; ?></td>
- <td class="title-link"><?php print $data->title_link; ?></td>
- </tr>
- <?php $row++; ?>
- <?php endforeach; ?>
- <?php endforeach; ?>
- </tbody>
-</table>
+
+<?php foreach ($block_states as $state => $title): ?>
+ <?php $row = 0; ?>
+ <?php print $state_prefix[$state] ?>
+ <div class="table-wrapper">
+ <table id="region-manager-blocks-<?php print $state; ?>">
+ <tbody>
+ <tr class="rm-state rm-state-<?php print $state ?>">
+ <td colspan="4" class="rm-state"><?php print $title ?></td>
+ </tr>
+ <tr class="rm-state-message rm-state-<?php print $state?>-message <?php print empty($block_listing[$state]) ? 'rm-state-empty' : 'rm-state-populated'; ?>">
+ <td colspan="4"><em><?php print t('No @blocks @state.', array('@block' => _region_manager_block_name(), '@state' => strtolower($title))); ?></em></td>
+ </tr>
+ <?php foreach ($block_listing[$state] as $delta => $data): ?>
+ <tr class="rm-block rm-block-<?php print $delta; ?> rm-state-<?php print $state ?> <?php print $row % 2 == 0 ? 'odd' : 'even'; ?><?php print $data->row_class ? ' '. $data->row_class : ''; ?>">
+ <td class="block"><?php print $data->block_config; ?></td>
+ <td class="state"><?php print $data->state_select; ?></td>
+ <td class="weight"><?php print $data->weight_select; ?></td>
+ <td class="operations"><?php print $data->operations; ?></td>
+ </tr>
+ <?php $row++; ?>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+ </div>
+ <?php print $state_suffix[$state] ?>
+<?php endforeach; ?>
<?php print $form_submit; ?>
diff --git a/region_manager.admin.inc b/region_manager.admin.inc
index 13f2ca0..2e4d541 100644
--- a/region_manager.admin.inc
+++ b/region_manager.admin.inc
@@ -19,12 +19,7 @@ function region_manager_settings_form() {
'#default_value' => variable_get('region_manager_block_name', 'Block'),
);
- $form = system_settings_form($form);
-
- // Uncomment and update the callback to override the default system settings submit handler.
- // $form['#submit'] = array('_settings_form_submit');
-
- return $form;
+ return system_settings_form($form);
}
/**
@@ -35,7 +30,6 @@ function region_manager_regions_form() {
drupal_clear_css_cache();
$themes = system_theme_data();
- $settings = variable_get('region_manager_regions', array());
module_load_include('inc', 'system', 'system.admin');
uasort($themes, 'system_sort_modules_by_info_name');
@@ -43,18 +37,21 @@ function region_manager_regions_form() {
$form['region_manager_regions']['#tree'] = TRUE;
foreach($themes as $theme) {
+ $key = 'region_manager_regions_'. $theme->name;
+ $settings = region_manager_regions_variable_get($theme->name);
+
if ($theme->status) {
- $form['region_manager_regions'][$theme->name] = array(
+ $form[$key] = array(
'#type' => 'fieldset',
'#title' => $theme->info['name'],
'#tree' => TRUE,
);
foreach (system_region_list($theme->name) as $region => $title) {
- $form['region_manager_regions'][$theme->name][$region] = array(
+ $form[$key][$region] = array(
'#type' => 'checkbox',
'#title' => $title,
- '#default_value' => $settings[$theme->name][$region],
+ '#default_value' => $settings[$region],
);
}
}
@@ -76,7 +73,8 @@ function region_manager_blocks_form(&$form_state, $theme_key) {
$roles = user_roles();
$regions = region_manager_region_list($theme_key);
- $records = region_manager_regions_load($theme_key);
+ $records = region_manager_regions_load($theme_key, TRUE);
+ $all_blocks = _region_manager_block_rehash($theme_key);
if (empty($regions)) {
drupal_set_message(t('You must first enable some regions for this theme <a href="!href">here</a>.', array('!href' => 'admin/settings/region_manager')), 'error');
@@ -88,13 +86,16 @@ function region_manager_blocks_form(&$form_state, $theme_key) {
$form['regions']['#tree'] = TRUE;
+ $storage = REGION_MANAGER_STORAGE_NORMAL;
+
foreach(array_keys($regions) as $region) {
- // rid is the theme key and region delimited by a colon.
- $rid = $theme_key .':'. $region;
+ // Check the storage on this region.
+ if ($records[$region]['storage'] > $storage) {
+ $storage = $records[$region]['storage'];
+ }
// Now build each module form.
- foreach(_region_manager_block_rehash($theme_key) as $module => $blocks) {
-
+ foreach($all_blocks as $module => $blocks) {
// Add the label for this module to the block_names column.
$form['regions']['block_names']['modules'][$module] = array(
'#type' => 'markup',
@@ -104,7 +105,7 @@ function region_manager_blocks_form(&$form_state, $theme_key) {
// The select box for the module.
$form['regions'][$region]['modules'][$module] = array(
'#type' => 'select',
- '#default_value' => isset($records[$rid]['modules'][$module]) ? $records[$rid]['modules'][$module] : REGION_MANAGER_ALL_ENABLED,
+ '#default_value' => isset($records[$region]['modules'][$module]) ? $records[$region]['modules'][$module] : REGION_MANAGER_ALL_ENABLED,
'#options' => array(
REGION_MANAGER_ALL_ENABLED => t('All enabled'),
REGION_MANAGER_ALL_DISABLED => t('All disabled'),
@@ -124,7 +125,7 @@ function region_manager_blocks_form(&$form_state, $theme_key) {
// The checkbox for the block.
$form['regions'][$region]['blocked_blocks'][$module][$delta] = array(
'#type' => 'checkbox',
- '#default_value' => !in_array($key, (array) $records[$rid]['blocked_blocks']),
+ '#default_value' => !in_array($key, (array) $records[$region]['blocked_blocks']),
);
// Set tree to TRUE.
@@ -133,14 +134,32 @@ function region_manager_blocks_form(&$form_state, $theme_key) {
}
// Set tree to true for these arrays.
$form['regions'][$region]['#tree'] = $form['regions'][$region]['modules']['#tree'] = TRUE;
+
+ // Now set the rid for this region.
+ if (isset($records[$region]['rid'])) {
+ $form['regions'][$region]['rid'] = array(
+ '#type' => 'hidden',
+ '#value' => $records[$region]['rid'],
+ );
+ }
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+ switch($storage) {
+ case REGION_MANAGER_STORAGE_OVERRIDE:
+ $form['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
+ break;
+
+ case REGION_MANAGER_STORAGE_DEFAULT:
+ drupal_set_message(t('These regions are currently using default storage. Any changes submitted here will override the default values.'), 'warning');
+ $form['submit']['#value'] = t('Override');
+ break;
+ }
+
return $form;
}
-
-
+
/**
* Submit handler for region_manager_blocks_form
*/
@@ -148,45 +167,54 @@ function region_manager_blocks_form_submit($form, &$form_state) {
$regions = $form_state['values']['regions'];
$theme_key = $form['#theme_key'];
- foreach($regions as $region => $record) {
- // Set the rid for this record.
- $record['rid'] = $theme_key .':'. $region;
-
- // Now go through the modules.
- foreach($record['modules'] as $module => $module_val) {
- foreach($record['blocked_blocks'][$module] as $delta => $block_val) {
- // We were using the [module][delta] structure to ease in theming, but we
- // need it to be set with just a module:delta key, so let's do that now.
- $key = $module .':'. $delta;
- $record['blocked_blocks'][$key] = $block_val;
-
- // Now we switch through the $module_val to determine what needs to be done.
- switch($module_val) {
- case REGION_MANAGER_ALL_ENABLED:
- // All are enabled, so unset all.
- unset($record['blocked_blocks'][$key]);
- break;
-
- case REGION_MANAGER_CUSTOM:
- // We don't want to save the checked blocks, only unchecked blocks.
- if ($block_val) {
+ // If we're resetting, delete all from the db with this theme_key.
+ if ($form_state['values']['op'] == t('Reset')) {
+ $sql = "DELETE FROM {region_manager_regions} WHERE theme_key = '%s'";
+ db_query($sql, $theme_key);
+ }
+ else {
+ foreach($regions as $region => $record) {
+ // Set up the region and theme key for this record.
+ $record['region'] = $region;
+ $record['theme_key'] = $theme_key;
+
+ // Now go through the modules.
+ foreach($record['modules'] as $module => $module_val) {
+ foreach($record['blocked_blocks'][$module] as $delta => $block_val) {
+ // We were using the [module][delta] structure to ease in theming, but we
+ // need it to be set with just a module:delta key, so let's do that now.
+ $key = $module .':'. $delta;
+ $record['blocked_blocks'][$key] = $block_val;
+
+ // Now we switch through the $module_val to determine what needs to be done.
+ switch($module_val) {
+ case REGION_MANAGER_ALL_ENABLED:
+ // All are enabled, so unset all.
unset($record['blocked_blocks'][$key]);
- }
- break;
-
- case REGION_MANAGER_ALL_DISABLED:
- // Nothing to do here, since we want all of them.
- break;
+ break;
+
+ case REGION_MANAGER_CUSTOM:
+ // We don't want to save the checked blocks, only unchecked blocks.
+ if ($block_val) {
+ unset($record['blocked_blocks'][$key]);
+ }
+ break;
+
+ case REGION_MANAGER_ALL_DISABLED:
+ // Nothing to do here, since we want all of them.
+ break;
+ }
}
+ // Unset this module's array since we resaved using the module:delta format.
+ unset($record['blocked_blocks'][$module]);
}
- // Unset this module's array since we resaved using the module:delta format.
- unset($record['blocked_blocks'][$module]);
+ // Flip the array, as all we need are the keys at this point.
+ $record['blocked_blocks'] = implode(', ', array_keys($record['blocked_blocks']));
+ region_manager_region_save($record);
}
- // Flip the array, as all we need are the keys at this point.
- $record['blocked_blocks'] = implode(', ', array_keys($record['blocked_blocks']));
- region_manager_region_save($record);
}
+ cache_clear_all('region_manager:'. $theme_key, 'cache', TRUE);
drupal_set_message(t('The changes have been saved.'));
}
@@ -235,4 +263,118 @@ function theme_region_manager_blocks_form($form) {
$output .= drupal_render($form);
return $output;
+}
+
+/**
+ * List of themes for
+ */
+function region_manager_visibility_overview() {
+ $items = array();
+
+ foreach(list_themes() as $theme) {
+ if ($theme->status) {
+ $items[] = l(t($theme->info['name']), 'admin/settings/region_manager/visibility/'. $theme->name);
+ }
+ }
+
+ return theme('item_list', $items, t('Themes'), 'ul', array('class' => 'region-manager-visibility-overview'));
+}
+
+/**
+ * Visibility settings form.
+ */
+function region_manager_visibility_form(&$form_state, $theme_key) {
+ $form = array();
+ $first = TRUE;
+
+ foreach(region_manager_region_list($theme_key) as $region => $name) {
+ $key = $theme_key .':'. $region;
+ $record = $records[$region];
+
+ visibility_api_form($form, $key, 'region_manager');
+
+ $form['visibility_api'][$key]['#type'] = 'fieldset';
+ $form['visibility_api'][$key]['#title'] = $name;
+ $form['visibility_api'][$key]['#collapsible'] = TRUE;
+ $form['visibility_api'][$key]['#collapsed'] = !$first;
+
+ $first = FALSE;
+ }
+
+ visibility_api_form_prepare($form);
+
+ return $form;
+}
+
+/**
+ * Form to export region manager settings.
+ */
+function region_manager_export(&$form_state) {
+ $form = array();
+ $values = $_POST;
+
+ if ($values) {
+ return region_manager_export_results($values);
+ }
+
+ $form['themes']['#tree'] = TRUE;
+
+ foreach(system_theme_data() as $theme) {
+ $regions = array_filter(region_manager_regions_variable_get($theme->name));
+ if (!empty($regions)) {
+ $options[$theme->name] = $theme->info['name'];
+ }
+ }
+
+ $form['themes'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Themes'),
+ '#options' => $options,
+ );
+
+ $form['module_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Module name'),
+ '#description' => t('The short name of your module, used to prepend the hook.'),
+ );
+
+ $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+
+ return $form;
+}
+
+function region_manager_export_results($values) {
+ $form = $options = $export = array();
+ $themes = array_keys(array_filter($values['themes']));
+ $module_name = $values['module_name'] ? check_plain($values['module_name']) : 'hook';
+ $records = region_manager_regions_load_all();
+
+ foreach($records as $record) {
+ if (in_array($record['theme_key'], $themes)) {
+ unset($record['storage'], $record['rid']);
+ $export[$record['theme_key']][$record['region']] = $record;
+ }
+ }
+
+ $output = "/**\n";
+ $output .= " * Implementation of hook_region_manager_defaults().\n";
+ $output .= " */\n";
+ $output .= "function {$module_name}_region_manager_defaults(" . '$theme_key' . " = NULL) {\n";
+ $output .= ' $records = array();' . "\n";
+ $output .= "\n";
+ $output .= ' $records = '. var_export($export, TRUE) .";\n";
+ $output .= "\n";
+ $output .= ' return $theme_key ? $records[$theme_key] : $records;';
+ $output .= "\n}";
+
+ $rows = substr_count($output, "\n") + 1;
+
+ $form['export'] = array(
+ '#type' => 'textarea',
+ '#resizable' => FALSE,
+ '#rows' => $rows,
+ '#default_value' => $output,
+ );
+
+ return $form;
} \ No newline at end of file
diff --git a/region_manager.admin.js b/region_manager.admin.js
index 22cf62f..e1d60dd 100644
--- a/region_manager.admin.js
+++ b/region_manager.admin.js
@@ -24,10 +24,10 @@ showHideRows = function(module) {
}
});
if (show) {
- $('#region-manager-blocks-form tr[class^=' + module + ']').not('tr.' + module).show();
+ $('#region-manager-blocks-form tr.' + module + '-child').show();
}
else {
- $('#region-manager-blocks-form tr[class^=' + module + ']').not('tr.' + module).hide();
+ $('#region-manager-blocks-form tr.' + module + '-child').hide();
}
}
diff --git a/region_manager.css b/region_manager.css
index 5aef2fd..668a21d 100644
--- a/region_manager.css
+++ b/region_manager.css
@@ -1,5 +1,36 @@
/* $Id$ */
+/***************************
+ Region Manager Menu link
+***************************/
+
+div.region-manager-menu {
+ padding: 6px;
+ text-align: left;
+ border: 1px solid #535353;
+ background: #6e6e6e url(images/bg_dark.gif) repeat-x 0 bottom;
+ clear: both;
+}
+
+div.region-manager-menu:hover {
+ background-image: url(images/bg_dark-hover.gif);
+}
+
+.region-manager-menu a {
+ line-height: 20px;
+ padding-left: 56px;
+ height: 18px;
+ display: block;
+ background: url(images/manage-icon.png) no-repeat;
+ font-size: 12px;
+ text-transform: uppercase;
+ color: white !important;
+}
+
+/***************************
+ Region Manager Admin form
+***************************/
+
#region-manager-blocks-form tr.module td {
border-top: 1.5em solid #fff;
border-bottom: 1px solid #b4d7f0;
@@ -8,26 +39,233 @@
font-weight: bold;
}
-html.js #region-manager-manage-form select.block-region-select,
-html.js #region-manager-manage-form div.region-manager-block-title-wrapper,
-#region-manager-manage-form div.region-manager-block-title-wrapper div.form-radios,
-#region-manager-manage-form td.title-link a {
+/***************************
+ Region Manager Manage form
+***************************/
+
+#region-manager-manage-form td.rm-state {
+ font-weight: bold;
+ font-size: 1.2em;
+}
+
+#region-manager-manage-form table tbody{
+ border: 0;
+}
+
+/***************************
+ Create Menu
+***************************/
+
+div.region-manager-create-menu div.item-list-wrapper {
+ display: none;
+}
+
+/* @group Region Manager Block Operations */
+
+#region-manager-manage-form td.operations {
+ text-align: right;
+ vertical-align: top;
+ display: none;
+}
+
+html.js #region-manager-manage-form td.operations {
+ display: block;
+}
+
+#region-manager-manage-form td.operations div.item-list ul,
+#region-manager-manage-form td.operations div.item-list ul li {
+ list-style: none;
+ background: none;
+ margin: 0;
+ padding: 0;
+ height: 36px;
+}
+
+#region-manager-manage-form td.operations li {
+ display: inline;
+}
+
+#region-manager-manage-form td.operations li a,
+a.region-manager-create-menu-link {
+ display: block;
+ float: right;
+ text-align: left;
+ text-indent: -9999px;
+ height: 36px;
+ background-repeat: no-repeat;
+ background-position: 0 0;
+ outline: 0;
+}
+
+#region-manager-manage-form td.operations li a:hover,
+a.region-manager-create-menu-link:hover {
+ background-position: 100% 0;
+}
+
+#region-manager-manage-form td.operations li.rm-block-configure-operation a {
+ width: 108px;
+ background-image: url(images/btn_configure.png);
+}
+
+#region-manager-manage-form td.operations li.rm-block-disable-operation a {
+ width: 94px;
+ background-image: url(images/btn_disable.png);
+}
+
+#region-manager-manage-form td.operations li.rm-block-add-operation a {
+ width: 74px;
+ background-image: url(images/btn_add.png);
+}
+
+#region-manager-manage-form td.operations li.rm-block-remove-operation a {
+ width: 100px;
+ background-image: url(images/btn_remove.png);
+}
+
+a.region-manager-create-menu-link {
+ float: none;
+ width: 89px;
+ background-image: url(images/btn_create.png);
+}
+
+#region-manager-manage-form tr.locked li.rm-block-remove-operation,
+#region-manager-manage-form tr.locked li.rm-block-disable-operation,
+#region-manager-blocks-active_path td.operations li.rm-block-add-operation,
+#region-manager-blocks-active_path tr.rm-state-disabled li.rm-block-remove-operation,
+#region-manager-blocks-active td.operations li.rm-block-configure-operation,
+#region-manager-blocks-disabled td.operations li.rm-block-configure-operation,
+#region-manager-blocks-active td.operations li.rm-block-remove-operation,
+#region-manager-blocks-disabled td.operations li.rm-block-remove-operation,
+#region-manager-blocks-disabled td.operations li.rm-block-disable-operation {
+ display: none;
+}
+
+/* @end */
+
+tr.rm-state-populated,
+#region-manager-manage-form td.weight,
+#region-manager-manage-form td.state,
+html.js #region-manager-manage-form div.region-manager-block-config-wrapper,
+#region-manager-manage-form div.region-manager-block-config-wrapper div.form-radios {
display: none;
}
html.js #region-manager-manage-form td.title-link a {
- display: inline;
+ display: inline;
+}
+
+html.js #region-manager-manage-form div.region-manager-block-config-wrapper div.form-radios {
+ display: block;
+ margin-left: 24px;
+}
+
+.region-manager-block-config-wrapper div.form-item {
+ background-color: transparent;
+ margin-left: 24px;
+ background-image: none;
+ margin-bottom: 12px;
}
-html.js #region-manager-manage-form div.region-manager-block-title-wrapper div.form-radios {
- display: block;
+.region-manager-block-config-wrapper input.region-manager-manage-form-title {
}
#region-manager-manage-form td.title-link {
- text-align: right;
- vertical-align: top;
+ text-align: right;
}
#region-manager-manage-form .draggable a.tabledrag-handle {
- height: 100%;
+ height: 100%;
+ padding-right: 7px;
+ margin-left: 0;
+}
+
+div.region-manager-create-menu {
+ padding: 12px;
+ border: 3px solid #a3a3a3;
+ margin-top: 18px;
+ margin-bottom: 18px;
+ background: #f2f2f2 url(images/bg_gradient-tall.png) repeat-x 0 top;
+}
+
+.region-manager-create-menu h4 {
+ margin: 2px 0 0;
+ padding: 0;
+}
+
+#region-manager-blocks-active_path td.rm-state {
+ font-size: 1.71em;
+ padding-bottom: 6px;
+ padding-top: 8px;
+}
+
+td.rm-state {
+ color: #292929;
+ padding-bottom: 6px;
+ padding-top: 12px;
+}
+
+#region-manager-active-path-wrapper div.table-wrapper {
+ border-width: 3px;
+ border-color: #808080;
+}
+
+div.table-wrapper {
+ border: 1px solid #cacaca;
+ padding: 18px;
+ margin-top: 18px;
+ margin-bottom: 18px;
+ border-bottom-color: #a3a3a3;
+}
+
+#region-manager-manage-form tr.odd td {
+ background: url(images/bg_gradient-short.png) repeat-x 0 top !important;
+}
+
+#region-manager-manage-form td {
+ padding-top: 6px;
+ padding-bottom: 4px;
+}
+
+#region-manager-active-path-wrapper .region-manager-create-menu div.item-list-wrapper {
+ border: 1px solid #e9e9e9;
+ padding: 12px;
+ background-color: white;
+ margin-top: 8px;
+ border-bottom-color: #dadada;
+ color: #464646;
+}
+
+.region-manager-create-menu ul {
+ padding: 0 !important;
+}
+
+.region-manager-create-menu ul li {
+ border-top: 1px dotted #c8c8c8;
+ margin: 0;
+ list-style-type: none;
+ line-height: 1em;
+ padding: 0;
+}
+
+.region-manager-create-menu ul li a {
+ line-height: 1em;
+ display: block;
+ padding-top: 9px;
+ padding-bottom: 9px;
+ padding-left: 12px;
+ background: url(images/arrow.png) no-repeat 0 10px;
+}
+
+.region-manager-create-menu ul li a:hover {
+ background: #f2f2f2 url(images/bg_gradient-short.png) repeat-x 0 -2px;
+ text-decoration: none;
+}
+
+#region-manager-blocks-active_path tr.rm-state-active td,
+#region-manager-blocks-active_path tr.rm-state-active,
+#region-manager-blocks-active_path tr.rm-state-disabled td,
+#region-manager-blocks-active_path tr.rm-state-disabled {
+ background-color: #fbe28d !important;
+ background-image: none !important;
+ color: black !important;
} \ No newline at end of file
diff --git a/region_manager.inc b/region_manager.inc
new file mode 100644
index 0000000..4188695
--- /dev/null
+++ b/region_manager.inc
@@ -0,0 +1,448 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Holds all API functions for region_manager.module
+ */
+
+/**
+ * Retrieves a set of enabled Region Manager regions for the theme.
+ * If the variable has not been set for this particular theme, and
+ * the theme is a sub-theme, it will look to each base theme until
+ * it finds a setting. Returns an empty array if no settings found.
+ *
+ * @param $theme_key
+ * String name of a theme.
+ * @return
+ * An array of regions for the theme.
+ */
+function region_manager_regions_variable_get($theme_key) {
+ $themes = list_themes();
+ $theme_info = $themes[$theme_key];
+
+ $regions = variable_get('region_manager_regions_'. $theme_key, array());
+
+ if (empty($regions) && isset($theme_info->info['base theme'])) {
+ $regions = region_manager_regions_variable_get($theme_info->info['base theme']);
+ }
+
+ return $regions;
+}
+
+/**
+ * Get a list of available regions from a specified theme.
+ *
+ * @param $theme_key
+ * The name of a theme.
+ * @return
+ * An array of regions in the form $region['name'] = 'description'.
+ */
+function region_manager_region_list($theme_key) {
+ static $region_list = array();
+
+ if (empty($region_list)) {
+ $settings = region_manager_regions_variable_get($theme_key);
+ if (!empty($settings)) {
+ $regions = system_region_list($theme_key);
+ $region_list = array_intersect_key($regions, array_filter($settings));
+ }
+ }
+
+ return $region_list;
+}
+
+/**
+ * Loader function for regions by theme or rid.
+ *
+ * @param $theme_key
+ * A string containing the name of the theme.
+ * @param $reset
+ * Boolean, if TRUE the cache will be flushed.
+ * @return
+ * A single record in array format, or FALSE if none matched the incoming ID.
+ */
+function region_manager_regions_load($theme_key, $reset = FALSE) {
+ static $records = array();
+
+ $cache_key = 'region_manager:'. $theme_key;
+
+ if ($reset) {
+ cache_clear_all($cache_key, 'cache');
+ $records = array();
+ }
+
+ if (!empty($records)) {
+ return $records;
+ }
+
+ if (($cache = cache_get($cache_key, 'cache')) && is_array($cache->data)) {
+ $records = $cache->data;
+ }
+ else {
+ $sql = "SELECT * FROM {region_manager_regions} WHERE theme_key = '%s'";
+ $result = db_query($sql, $theme_key);
+
+ while ($record = db_fetch_array($result)) {
+ $record['modules'] = unserialize($record['modules']);
+ $record['blocked_blocks'] = explode(', ', $record['blocked_blocks']);
+ $record['storage'] = REGION_MANAGER_STORAGE_NORMAL;
+
+ $records[$record['region']] = $record;
+ }
+
+ // Call hook_region_manager_defaults().
+ foreach(module_invoke_all('region_manager_defaults', $theme_key) as $region => $record) {
+ if ($records[$region]) {
+ $records[$region]['storage'] = REGION_MANAGER_STORAGE_OVERRIDE;
+ }
+ else {
+ $record['storage'] = REGION_MANAGER_STORAGE_DEFAULT;
+ $records[$region] = $record;
+ }
+ }
+ cache_set($cache_key, $records);
+ }
+
+ // If there are no records, look to the base theme and see if it has records.
+ if (empty($records)) {
+ $themes = list_themes();
+ $theme_info = $themes[$theme_key];
+
+ if (isset($theme_info->info['base theme'])) {
+ $records = region_manager_regions_load($theme_info->info['base theme']);
+ }
+ }
+
+ return $records;
+}
+
+/**
+ * Public loader function for the full collection of records.
+ *
+ * @return
+ * An array of all records, keyed by id.
+ */
+function region_manager_regions_load_all() {
+ $sql = 'SELECT * FROM {region_manager_regions} ORDER BY rid ASC';
+ $result = db_query($sql);
+
+ $records = array();
+ while ($record = db_fetch_array($result)) {
+ $record['modules'] = unserialize($record['modules']);
+ $record['blocked_blocks'] = explode(', ', $record['blocked_blocks']);
+ $record['storage'] = REGION_MANAGER_STORAGE_NORMAL;
+
+ $records[$record['theme_key'] .':'. $record['region']] = $record;
+ }
+
+ // Call hook_region_manager_defaults().
+ foreach(module_invoke_all('region_manager_defaults') as $theme_key => $theme) {
+ foreach($theme as $region => $record) {
+ $key = $theme_key .':'. $region;
+ if ($records[$key]) {
+ $records[$key]['storage'] = REGION_MANAGER_STORAGE_OVERRIDE;
+ }
+ else {
+ $record['storage'] = REGION_MANAGER_STORAGE_DEFAULT;
+ $records[$key] = $record;
+ }
+ }
+ }
+
+ return $records;
+}
+
+/**
+ * Inserts a new record, or updates an existing one.
+ *
+ * @param $region
+ * A record to be saved.
+ * @return
+ * The saved record.
+ */
+function region_manager_region_save($region) {
+ if (isset($region['rid'])) {
+ drupal_write_record('region_manager_regions', $region, 'rid');
+ }
+ else {
+ drupal_write_record('region_manager_regions', $region);
+ }
+ return $region;
+}
+
+/**
+ * Deletes a record, given its unique ID.
+ *
+ * @param $rid
+ * An integer containing the ID of a record.
+ */
+function region_manager_region_delete($rid) {
+ $sql = "DELETE FROM {region_manager_regions} WHERE rid = %d";
+ db_query($sql, $rid);
+}
+
+/**
+ * Loads all available blocks organized by region.
+ */
+function region_manager_blocks_load_all($theme_key, $region = NULL) {
+ static $all_blocks = NULL;
+ static $records = NULL;
+
+ $blocks = array();
+
+ // Load the blocks and regions if we haven't yet.
+ if (is_null($all_blocks)) {
+ $all_blocks = _region_manager_block_rehash($theme_key);
+ }
+ if (is_null($records)) {
+ // Load all regions for this theme, so we don't have to reload for each region.
+ $records = region_manager_regions_load($theme_key);
+ }
+
+ // Might as well quit if we don't have any blocks.
+ if (empty($all_blocks)) {
+ return;
+ }
+
+ if (is_null($region)) {
+ foreach(array_keys(region_manager_region_list($theme_key)) as $region) {
+ $blocks[$region] = _region_manager_blocks_filter($region, $all_blocks, $records[$region]);
+ }
+ }
+ else {
+ $blocks = _region_manager_blocks_filter($region, $all_blocks, $records[$region]);
+ }
+
+ return $blocks;
+}
+
+/**
+ * Returns an array of links to create new blocks in this region.
+ *
+ * @param $theme_key
+ * A string containing the key of the active theme.
+ * @param $region
+ * A string containing the region to be managed.
+ * @return
+ * An array containing the links.
+ */
+function region_manager_create_links($theme_key, $region) {
+ $links = $options = array();
+
+ if ($path = $_REQUEST['destination']) {
+ $options['query'] = array(
+ 'destination' => $path,
+ 'theme_key' => $theme_key,
+ 'region' => $region,
+ );
+ }
+
+ foreach(region_manager_create_links_load($theme_key, $region) as $link) {
+ if ($link['options']) {
+ $options += $link['options'];
+ }
+ $links[] = l($link['title'], $link['path'], $options);
+ }
+ return $links;
+}
+
+/**
+ * Retrieves an array of link items, invoking hook_region_manager_create_links()
+ * and hook_region_manager_create_links_alter(). The links are cached and
+ * static to ensure optimum performance.
+ *
+ * @param $theme_key
+ * A string containing the key of the active theme.
+ * @param $region
+ * A string containing the region to be managed.
+ * @param $reset
+ * Boolean, if TRUE the cache will be flushed.
+ * @return
+ * An array containing the links.
+ */
+function region_manager_create_links_load($theme_key, $region, $reset = FALSE) {
+ static $links;
+
+ if (is_null($links) || $reset) {
+ if ($reset) {
+ cache_clear_all('region_manager_create_links', 'cache');
+ }
+
+ if ($cache = cache_get('region_manager_create_links')) {
+ $links = $cache->data;
+ }
+ else {
+ $links = module_invoke_all('region_manager_create_links', $theme_key, $region);
+ drupal_alter('region_manager_create_links', $links, $theme_key, $region);
+ cache_set('region_manager_create_links', $links, 'cache', CACHE_TEMPORARY);
+ }
+ }
+
+ return $links;
+}
+
+/**
+ * Helper function to filter all enabled and (available) disabled
+ * blocks for a particular region.
+ */
+function _region_manager_blocks_filter($region, $blocks = array(), $record = array()) {
+ $output = array();
+
+ foreach($blocks as $module => $modblocks) {
+ if (is_array($modblocks)) {
+
+ // If they're all disabled for this module, go on to the next module.
+ if ($record['modules'][$module] == REGION_MANAGER_ALL_DISABLED) {
+ continue;
+ }
+
+ // Otherwise, let's parse through each block.
+ else {
+ foreach($modblocks as $delta => $block) {
+ if ($block['status']) {
+ // Only add it to active if it's a part of this region.
+ if ($block['region'] == $region) {
+ $output[] = $block;
+ }
+ }
+ else {
+ // Check to see if we're using custom availability for this module.
+ if ($record['modules'][$module] == REGION_MANAGER_CUSTOM) {
+ $key = $module .':'. $delta;
+ // Is this block 'blocked'?
+ if (!in_array($key, $record['blocked_blocks'])) {
+ $output[] = $block;
+ }
+ }
+ // Otherwise add all blocks for this module.
+ else {
+ $output[] = $block;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return $output;
+}
+
+/**
+ * Helper function to assemble the blocks.
+ */
+function _region_manager_block_rehash($theme_key) {
+ $blocks = array();
+
+ $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
+ $old_blocks = array();
+ while ($old_block = db_fetch_array($result)) {
+ $old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
+ }
+
+ $blocks = array();
+ // Valid region names for the theme.
+ $regions = system_region_list($theme_key);
+
+ foreach (module_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])) {
+ // If it's a new block, add identifiers.
+ $block['module'] = $module;
+ $block['delta'] = $delta;
+ $block['theme'] = $theme_key;
+ if (!isset($block['pages'])) {
+ // {block}.pages is type 'text', so it cannot have a
+ // default value, and not null, so we need to provide
+ // value if the module did not.
+ $block['pages'] = '';
+ }
+ // Add defaults and save it into the database.
+ drupal_write_record('blocks', $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.
+ $blocks[$module][$delta] = $block;
+ }
+ else {
+ // If it's an existing block, database settings should overwrite
+ // the code. But aside from 'info' everything that's definable in
+ // code is stored in the database and we do not store 'info', so we
+ // do not need to update the database here.
+ // Add 'info' to this block.
+ $old_blocks[$module][$delta]['info'] = $block['info'];
+ // If the region name does not exist, disable the block and assign it to none.
+ if (!empty($old_blocks[$module][$delta]['region']) && !isset($regions[$old_blocks[$module][$delta]['region']])) {
+ drupal_set_message(t('The @block %info was assigned to the invalid region %region and has been disabled.', array('@block' => _region_manager_block_name(), '%info' => $old_blocks[$module][$delta]['info'], '%region' => $old_blocks[$module][$delta]['region'])), 'warning');
+ $old_blocks[$module][$delta]['status'] = 0;
+ $old_blocks[$module][$delta]['region'] = BLOCK_REGION_NONE;
+ }
+ else {
+ $old_blocks[$module][$delta]['region'] = $old_blocks[$module][$delta]['status'] ? $old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
+ }
+ // Add this block to the list of blocks we return.
+ $blocks[$module][$delta] = $old_blocks[$module][$delta];
+ // Remove this block from the list of blocks to be deleted.
+ unset($old_blocks[$module][$delta]);
+ }
+ }
+ }
+ }
+
+ // Remove blocks that are no longer defined by the code from the database.
+ foreach ($old_blocks as $module => $old_module_blocks) {
+ foreach ($old_module_blocks as $delta => $block) {
+ db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme_key);
+ }
+ }
+ return $blocks;
+}
+
+/**
+ * Helper function to determine if the block is visible for a certain path.
+ *
+ * @return
+ * Boolean FALSE if it's not visible, otherwise a string of the path.
+ */
+function _region_manager_block_check_visibility($block, $path = NULL) {
+ if ($block['visibility'] == 1 || $block['visibility'] == -1) {
+ $path = is_null($path) ? drupal_get_path_alias($_GET['q']) : $path;
+ // Compare with the internal and path alias (if any).
+ $page_match = drupal_match_path($path, $block['pages']);
+ if ($path != $_GET['q']) {
+ $page_match = $page_match || drupal_match_path($_GET['q'], $block['pages']);
+ }
+ }
+ return $page_match ? $path : FALSE;
+}
+
+/**
+ * Helper function to display the custom block name.
+ *
+ * @param $name
+ * String designating upper or lower case.
+ */
+function _region_manager_block_name($case = 'lower') {
+ static $name;
+
+ if (empty($name)) {
+ $name = variable_get('region_manager_block_name', 'Block');
+ }
+
+ if ($case == 'lower') {
+ return strtolower($name);
+ }
+ return ucfirst($name);
+}
+
+/**
+ * Helper function to output a path name or alias.
+ */
+function _region_manager_path_name($path) {
+ $frontpage = variable_get('site_frontpage', 'node');
+ $alias = ($path == $frontpage) ? t('home page') : drupal_get_path_alias($path);
+
+ return $alias;
+}
diff --git a/region_manager.info b/region_manager.info
index 39f5ad4..9646f82 100644
--- a/region_manager.info
+++ b/region_manager.info
@@ -1,5 +1,5 @@
; $Id$
name = Region Manager
description = Implements 'add new' block controls to select regions.
-; dependencies[] =
-core = 6.x \ No newline at end of file
+core = 6.x
+
diff --git a/region_manager.install b/region_manager.install
index ec4b862..43c58f3 100644
--- a/region_manager.install
+++ b/region_manager.install
@@ -23,11 +23,23 @@ function region_manager_schema() {
'description' => 'Describes {blocks} access per region.',
'fields' => array(
'rid' => array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'Primary Key: Unique region ID.',
+ ),
+ 'theme_key' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
- 'default' => '0',
- 'description' => 'A region ID, defined by the theme key and region.',
+ 'default' => '',
+ 'description' => 'The theme under which the region settings apply.',
+ ),
+ 'region' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'The region.',
),
'blocked_blocks' => array(
'type' => 'text',
@@ -44,6 +56,9 @@ function region_manager_schema() {
),
),
'primary key' => array('rid'),
+ 'unique keys' => array(
+ 'tr' => array('theme_key', 'region'),
+ ),
);
return $schema;
@@ -54,6 +69,69 @@ function region_manager_schema() {
*/
function region_manager_uninstall() {
drupal_uninstall_schema('region_manager');
+ cache_clear_all('region_manager:*', 'cache', TRUE);
variable_del('region_manager_block_name');
- variable_del('region_manager_regions');
}
+
+/**
+ * Change rid to serial, and add theme and region as a unique key.
+ */
+function region_manager_update_6100() {
+ $ret = array();
+
+ $theme_key_field = array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'The theme under which the region settings apply.',
+ );
+
+ $region_field = array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'The theme under which the region settings apply.',
+ );
+ $rid_field = array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'Primary Key: Unique region ID.',
+ );
+ $new_keys = array(
+ 'primary key' => array('rid'),
+ 'unique keys' => array(
+ 'tr' => array('theme_key', 'region'),
+ ),
+ );
+
+ db_add_field($ret, 'region_manager_regions', 'region', $region_field);
+ db_add_field($ret, 'region_manager_regions', 'theme_key', $theme_key_field);
+
+ foreach(region_manager_regions_load_all() as $old_rid => $record) {
+ list($theme_key, $region) = explode(':', $old_rid);
+ $ret[] = update_sql("UPDATE {region_manager_regions} SET theme_key = '$theme_key', region = '$region' WHERE rid = '$old_rid'");
+ }
+
+ db_drop_primary_key($ret, 'region_manager_regions');
+ db_change_field($ret, 'region_manager_regions', 'rid', 'rid', $rid_field, $new_keys);
+
+ return $ret;
+}
+
+/**
+ * Separate region settings into per theme variables.
+ */
+function region_manager_update_6101() {
+ $themes = variable_get('region_manager_regions', NULL);
+
+ if ($themes) {
+ foreach($themes as $theme_key => $regions) {
+ variable_set('region_manager_regions_'. $theme_key, $regions);
+ }
+ variable_del('region_manager_regions');
+ }
+
+ return array();
+} \ No newline at end of file
diff --git a/region_manager.js b/region_manager.js
index c7b99e4..85eaa31 100644
--- a/region_manager.js
+++ b/region_manager.js
@@ -1,31 +1,25 @@
// $Id$
-$(function() {
- // Move the textfields next to the label for the Use custom title radio.
- /*
- $('td.block div.region-manager-block-title-wrapper input.form-text').each(function () {
- var title = $(this).parent();
- $('input.form-radio', title.prev().children()).each(function () {
- if ($(this).val() == 1) {
- $(this).parent().parent().append(title);
- }
- });
- });
- */
-
+/**
+ * Show/hide form elements for editing a block title.
+ */
+Drupal.behaviors.blockTitle = function() {
+ // Show hide the textfield depending on the radio states.
$('input.region-manager-manage-form-title-status').change(function() {
if (this.checked) {
- var id = $(this).attr('id');
var textfield = $('input.form-text', $(this).parents('td.block'));
switch (this.value) {
+ // Default Title
case '0':
textfield.val('').hide('fast');
break;
+ // Disable Title
case '1':
textfield.val('<none>').hide();
break;
+ // Custom Title
case '2':
if (textfield.val() == '<none>') {
textfield.val('');
@@ -36,97 +30,65 @@ $(function() {
}
});
- // Simulate a change so we can disable the title field if need be.
+ // Instantiate a change so we can hide the title field if need be.
$('input.region-manager-manage-form-title-status').change();
-
- $('td.title-link a').click(function() {
- var class = $(this).attr('class');
- var wrapper = $('div.' + class);
- if (wrapper.is(':hidden')) {
- wrapper.show('fast');
- }
- else {
- wrapper.hide('fast');
- }
- return false;
- });
-});
+};
/**
- * Move a block in the blocks table from one region to another via select list.
- *
- * This behavior is dependent on the tableDrag behavior, since it uses the
- * objects initialized in that behavior to update the row.
+ * Perform actions from operation links
*/
-Drupal.behaviors.blockDrag = function(context) {
- var table = $('table#blocks');
- var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object.
-
- // Add a handler for when a row is swapped, update empty regions.
- tableDrag.row.prototype.onSwap = function(swappedRow) {
- checkEmptyRegions(table, this);
- };
+Drupal.behaviors.regionManagerOperations = function() {
+ $('td.operations a').click(function() {
+ var op = $(this).attr('class');
+ var rowClass = $(this).parents('ul').attr('class');
+ var row = $('tr.' + rowClass);
+ var configWrapper = $('div.region-manager-block-config-wrapper', row);
+ var tableDragObj = Drupal.tableDrag['region-manager-blocks-active_path'];
+ var tables = $('#region-manager-manage-form table');
- // A custom message for the blocks page specifically.
- Drupal.theme.tableDragChangedWarning = function () {
- return '<div class="warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("The changes to these @blocks will not be saved until the <em>@save</em> button is clicked.", { '@block' : Drupal.settings.block_name, '@save' : "Save " + Drupal.settings.block_name }) + '</div>';
- };
+ switch(op) {
+ case 'add':
+ row.appendTo('table#region-manager-blocks-active_path').each(function() { tableDragObj.makeDraggable(this) });
+ $('select.block-state-select', row).val('active_path');
+ break;
+
+ case 'configure':
+ if (configWrapper.is(':hidden')) {
+ configWrapper.show('fast');
+ }
+ else {
+ configWrapper.hide('fast');
+ }
+ break;
- // Add a handler so when a row is dropped, update fields dropped into new regions.
- tableDrag.onDrop = function() {
- dragObject = this;
- if ($(dragObject.rowObject.element).prev('tr').is('.region-message')) {
- var regionRow = $(dragObject.rowObject.element).prev('tr').get(0);
- var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
- var regionField = $('select.block-region-select', dragObject.rowObject.element);
- var weightField = $('select.block-weight', dragObject.rowObject.element);
- var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
+ case 'remove':
+ row.insertAfter('table#region-manager-blocks-active tr.rm-state-message');
+ $('select.block-state-select', row).val('active');
+ $('a.tabledrag-handle', row).remove();
+ configWrapper.hide();
+ break;
- if (!regionField.is('.block-region-'+ regionName)) {
- regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName);
- weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName);
- regionField.val(regionName);
- }
+ case 'disable':
+ row.insertAfter('table#region-manager-blocks-disabled tr.rm-state-message');
+ $('select.block-state-select', row).val('disabled');
+ $('a.tabledrag-handle', row).remove();
+ configWrapper.hide();
+ break;
}
- };
-
- // Add the behavior to each region select list.
- $('select.block-region-select:not(.blockregionselect-processed)', context).each(function() {
- $(this).change(function(event) {
- // Make our new row and select field.
- var row = $(this).parents('tr:first');
- var select = $(this);
- tableDrag.rowObject = new tableDrag.row(row);
-
- // Find the correct region and insert the row as the first in the region.
- $('tr.region-message', table).each(function() {
- if ($(this).is('.region-' + select[0].value + '-message')) {
- // Add the new row and remove the old one.
- $(this).after(row);
- // Manually update weights and restripe.
- tableDrag.updateFields(row.get(0));
- tableDrag.rowObject.changed = true;
- if (tableDrag.oldRowElement) {
- $(tableDrag.oldRowElement).removeClass('drag-previous');
- }
- tableDrag.oldRowElement = row.get(0);
- tableDrag.restripeTable();
- tableDrag.rowObject.markChanged();
- tableDrag.oldRowElement = row;
- $(row).addClass('drag-previous');
- }
- });
+ if (op != 'configure') {
+ tables.each(function() { checkEmptyRegions(this, row); });
+ }
+ $('tr', tables).filter(':odd').filter('.odd')
+ .removeClass('odd').addClass('even')
+ .end().end()
+ .filter(':even').filter('.even')
+ .removeClass('even').addClass('odd');
- // Modify empty regions with added or removed fields.
- checkEmptyRegions(table, row);
- // Remove focus from selectbox.
- select.get(0).blur();
- });
- $(this).addClass('blockregionselect-processed');
+ return false;
});
var checkEmptyRegions = function(table, rowObject) {
- $('tr.region-message', table).each(function() {
+ $('tr.rm-state-message', table).each(function() {
// If the dragged row is in this region, but above the message row, swap it down one space.
if ($(this).prev('tr').get(0) == rowObject.element) {
// Prevent a recursion problem when using the keyboard to move rows up.
@@ -135,13 +97,30 @@ Drupal.behaviors.blockDrag = function(context) {
}
}
// This region has become empty
- if ($(this).next('tr').not('.locked').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
- $(this).removeClass('region-populated').addClass('region-empty');
+ if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
+ $(this).removeClass('rm-state-populated').addClass('rm-state-empty');
}
// This region has become populated.
- else if ($(this).is('.region-empty')) {
- $(this).removeClass('region-empty').addClass('region-populated');
+ else if ($(this).is('.rm-state-empty')) {
+ $(this).removeClass('rm-state-empty').addClass('rm-state-populated');
}
});
};
-}; \ No newline at end of file
+}
+
+/**
+ * Perform actions from operation links
+ */
+Drupal.behaviors.regionManagerCreate = function() {
+ $('a.region-manager-create-menu-link').click(function() {
+ var typesList = $('div.region-manager-create-menu div.item-list-wrapper');
+ if (typesList.is(':hidden')) {
+ typesList.show('fast');
+ }
+ else {
+ typesList.hide('fast');
+ }
+
+ return false;
+ });
+} \ No newline at end of file
diff --git a/region_manager.module b/region_manager.module
index ac6de97..76eecbc 100644
--- a/region_manager.module
+++ b/region_manager.module
@@ -2,8 +2,10 @@
// $Id$
/**
- * @file
- * Adds add/remove block controls to select regions.
+ * @file Region Manager Module.
+ *
+ * Built by Sprocket.
+ * http://sprocketcreative.com
*/
/**
@@ -14,12 +16,43 @@ define('REGION_MANAGER_ALL_DISABLED', 1);
define('REGION_MANAGER_CUSTOM', 2);
/**
+ * Define storage methods.
+ */
+// Stored in the db.
+define('REGION_MANAGER_STORAGE_NORMAL', 0);
+// Stored in hook_region_manager_defaults().
+define('REGION_MANAGER_STORAGE_DEFAULT', 1);
+// Stored in hook_region_manager_defaults(), but overridden in the db.
+define('REGION_MANAGER_STORAGE_OVERRIDE', 2);
+
+/**
+ * Include some files right away.
+ */
+// Include Region Manager's API and helper functions.
+module_load_include('inc', 'region_manager', 'region_manager');
+// Include NodeBlock helpers.
+module_load_include('inc', 'region_manager', 'region_manager.nodeblock');
+
+/**
* Implementation of hook_help().
*/
function region_manager_help($path, $arg) {
switch ($path) {
- case 'admin/settings/region_manager':
+ case 'admin/settings/region_manager/regions':
return t('Please select for each theme which regions you would like to have region manager available on.');
+
+ case 'admin/build/region_manager/%/%':
+ $theme_key = $arg[3];
+ $region = $arg[4];
+ $path = _region_manager_path_name($_REQUEST['destination']);
+
+ $t_args = array(
+ '@region' => region_manager_region_title($theme_key, $region),
+ '%path' => _region_manager_path_name($path),
+ '@block' => _region_manager_block_name(),
+ );
+
+ return t('You are managing the @region as it displays on %path. Add existing, create new, remove, disable @blocks, or drag and drop to reorder them.', $t_args);
}
}
@@ -28,21 +61,29 @@ function region_manager_help($path, $arg) {
*/
function region_manager_init() {
if (user_access('manage regions')) {
- global $theme_key;
-
- init_theme();
-
// Add css and js.
$path = drupal_get_path('module', 'region_manager');
drupal_add_css($path .'/region_manager.css');
+ }
+}
+
+/**
+ * Implementation of hook_preprocess_page().
+ */
+function region_manager_preprocess_page(&$vars) {
+ if (user_access('manage regions')) {
+ global $theme_key;
// Add the menus.
- $regions = variable_get('region_manager_regions', array());
- if (is_array($regions[$theme_key])) {
- foreach($regions[$theme_key] as $region => $value) {
- if ($value) {
- $menu = theme('region_manager_region_menu', $theme_key, $region);
- drupal_set_content($region, $menu);
+ $regions = region_manager_regions_variable_get($theme_key);
+ if (!empty($regions)) {
+ foreach($regions as $region => $value) {
+ if (
+ $value &&
+ isset($vars[$region]) && // Ensure this theme has the region ($regions may be from a base theme).
+ (!function_exists('visibility_api_visible') || visibility_api_visible($theme_key .':'. $region, 'region_manager'))
+ ) {
+ $vars[$region] = theme('region_manager_region_menu', $theme_key, $region) . $vars[$region];
}
}
}
@@ -84,6 +125,22 @@ function region_manager_menu() {
'weight' => -10,
);
+ if (function_exists('visibility_api_visible')) {
+ $items['admin/settings/region_manager/visibility'] = array(
+ 'title' => 'Visibility',
+ 'description' => 'Configure visibility',
+ 'page callback' => 'region_manager_visibility_overview',
+ 'access arguments' => array('administer region manager'),
+ 'file' => 'region_manager.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ );
+ $items['admin/settings/region_manager/visibility/list'] = array(
+ 'title' => 'List',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+ }
+
foreach(list_themes() as $theme) {
if ($theme->status) {
$items['admin/settings/region_manager/regions/'. $theme->name] = array(
@@ -95,8 +152,29 @@ function region_manager_menu() {
'file' => 'region_manager.admin.inc',
'type' => MENU_LOCAL_TASK,
);
+ if (function_exists('visibility_api_visible')) {
+ $items['admin/settings/region_manager/visibility/'. $theme->name] = array(
+ 'title' => $theme->info['name'],
+ 'description' => 'Configure visibility',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('region_manager_visibility_form', 4),
+ 'access arguments' => array('administer region manager'),
+ 'file' => 'region_manager.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ );
+ }
}
}
+ $items['admin/settings/region_manager/regions/export'] = array(
+ 'title' => 'Export',
+ 'description' => 'Configure region manager settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('region_manager_export'),
+ 'access arguments' => array('administer region manager'),
+ 'file' => 'region_manager.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 99,
+ );
$items['admin/build/region_manager/%/%'] = array(
'title callback' => 'region_manager_region_title',
@@ -118,12 +196,16 @@ function region_manager_menu() {
function region_manager_region_title($theme_key, $region) {
static $list = array();
+ $output = '';
+
if (!array_key_exists($theme_key, $list)) {
$info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key)));
$list[$theme_key] = array_map('t', $info['regions']);
}
- return $list[$theme_key][$region];
+ $output = $list[$theme_key][$region];
+
+ return $output;
}
/**
@@ -145,7 +227,7 @@ function region_manager_theme() {
$items['region_manager_region_menu'] = array(
'arguments' => array('theme_key' => NULL, 'region' => NULL),
);
- $items['region_manager_nodeblock_menu'] = array(
+ $items['region_manager_create_menu'] = array(
'arguments' => array('links' => NULL),
);
$items['region_manager_manage_form'] = array(
@@ -158,56 +240,20 @@ function region_manager_theme() {
}
/**
- * Implementation of hook_form_alter().
- */
-function region_manager_form_alter(&$form, $form_state, $form_id) {
- if (function_exists('nodeblock_block') && $form['#id'] == 'node-form' && variable_get('nodeblock_'. $form['type']['#value'], 0) && !$form['nid']['#value']) {
- if (($theme_key = arg(3)) && ($region = arg(4)) && ($path = $_REQUEST['destination'])) {
- $frontpage = variable_get('site_frontpage', 'node');
- $path = ($path == $frontpage) ? '<front>' : $path;
-
- $form['region_manager'] = array(
- '#tree' => TRUE,
- );
- $form['region_manager']['theme_key'] = array(
- '#type' => 'hidden',
- '#value' => $theme_key,
- );
- $form['region_manager']['region'] = array(
- '#type' => 'hidden',
- '#value' => $region,
- );
- $form['region_manager']['path'] = array(
- '#type' => 'hidden',
- '#value' => $path,
- );
- }
- }
-}
-
-/**
* Implementation of hook_nodeapi().
*/
function region_manager_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
- if ($op == 'insert' && function_exists('nodeblock_block') && $node->region_manager) {
- _block_rehash();
- db_query("UPDATE {blocks} SET status = 1, region = '%s', visibility = 1, pages = '%s' WHERE module = 'nodeblock' AND delta = '%s' AND theme = '%s'", $node->region_manager['region'], $node->region_manager['path'], $node->nid, $node->region_manager['theme_key']);
- }
-}
+ if ($op == 'insert' && $node->region_manager) {
+ // Rehash the blocks for this theme key.
+ _region_manager_block_rehash($node->region_manager['theme_key']);
-/**
- * Get a list of available regions from a specified theme.
- *
- * @param $theme_key
- * The name of a theme.
- * @return
- * An array of regions in the form $region['name'] = 'description'.
- */
-function region_manager_region_list($theme_key) {
- $settings = variable_get('region_manager_regions', array());
- $regions = system_region_list($theme_key);
- if (!empty($settings)) {
- return array_intersect_key($regions, (array) array_filter($settings[$theme_key]));
+ // Set up the path, in case this was a frontpage
+ $path = $node->region_manager['path'];
+ $frontpage = variable_get('site_frontpage', 'node');
+ $node->region_manager['path'] = ($path == $frontpage) ? '<front>' : $path;
+
+ // Insert the block into blocks table.
+ db_query("UPDATE {blocks} SET status = 1, region = '%s', visibility = -1, pages = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $node->region_manager['region'], $node->region_manager['path'], $node->region_manager['module'], $node->nid, $node->region_manager['theme_key']);
}
}
@@ -218,7 +264,6 @@ function region_manager_region_list($theme_key) {
* A string containing the key for the active theme.
* @param $region
* A string containing the region to be managed.
- *
* @return
* A string containing the link wrapped in a div.
*
@@ -227,275 +272,7 @@ function region_manager_region_list($theme_key) {
function theme_region_manager_region_menu($theme_key, $region) {
$dest = $_REQUEST['destination'] ? array('destination' => $_REQUEST['destination']) : drupal_get_destination();
- $link = l(t('Configure'), "admin/build/region_manager/$theme_key/$region", array('query' => $dest));
+ $link = l(t(region_manager_region_title($theme_key, $region)), "admin/build/region_manager/$theme_key/$region", array('query' => $dest, 'attributes' => array('title' => t('Manage this region'))));
return "<div class='region-manager-menu'>$link</div>\n";
}
-
-/**
- * Loader function for regions by theme or rid.
- *
- * @param $theme_key
- * A string containing either a theme key only, or theme key and region name
- * delimited by ':'.
- * @return
- * A single record in array format, or FALSE if none matched the incoming ID.
- */
-function region_manager_regions_load($rid) {
- $regions = array();
-
- $sql = "SELECT * FROM {region_manager_regions} WHERE rid LIKE '%s%%'";
- $result = db_query($sql, $rid);
- while ($region = db_fetch_array($result)) {
- $region['modules'] = unserialize($region['modules']);
- $region['blocked_blocks'] = explode(', ', $region['blocked_blocks']);
- $regions[$region['rid']] = $region;
- }
-
- return $regions;
-}
-
-/**
- * Public loader function for the full collection of records.
- *
- * In situations where the module's data rarely changes, or is being used
- * frequently (for example, loaded and processed on every page load), this
- * is a prime candidate for caching. See The Beginner's Guide to Caching at
- * http://www.lullabot.com/articles/a_beginners_guide_to_caching_data for more
- * details.
- *
- * This function assumes that results should be sorted by 'weight' -- if your
- * module doesn't store a weight column on its records, or if you need to sort
- * on some other property, this function's SQL should be updated as well.
- *
- * @return
- * An array of all records, keyed by id.
- */
-function region_manager_regions_load_all() {
- $sql = 'SELECT * FROM {region_manager_blocks} ORDER BY theme ASC';
- $result = db_query($sql);
-
- $regions = array();
- while ($region = db_fetch_array($result)) {
- $region['modules'] = unserialize($region['modules']);
- $regions[$region['rid']] = $region;
- }
- return $regions;
-}
-
-/**
- * Inserts a new record, or updates an existing one.
- *
- * @param $region
- * A record to be saved.
- * @return
- * The saved record.
- */
-function region_manager_region_save($region) {
- region_manager_region_delete($region['rid']);
- drupal_write_record('region_manager_regions', $region);
- return $region;
-}
-
-/**
- * Deletes a record, given its unique ID.
- *
- * @param $rid
- * A string containing the ID of a record.
- */
-function region_manager_region_delete($rid) {
- $sql = "DELETE FROM {region_manager_regions} WHERE rid = '%s'";
- db_query($sql, $rid);
-}
-
-/**
- * Loads all available blocks organized by region.
- */
-function region_manager_blocks_load_all($theme_key, $region = NULL) {
- static $all_blocks = NULL;
- static $records = NULL;
-
- $blocks = array();
-
- // Load the blocks and regions if we haven't yet.
- if (is_null($all_blocks)) {
- $all_blocks = _region_manager_block_rehash($theme_key);
- }
- if (is_null($records)) {
- // Load all regions for this theme, so we don't have to reload for each region.
- $records = region_manager_regions_load($theme_key);
- }
-
- // Might as well quit if we don't have any blocks.
- if (empty($all_blocks)) {
- return;
- }
-
- if (is_null($region)) {
- foreach(array_keys(region_manager_region_list($theme_key)) as $region) {
- $rid = $theme_key .':'. $region;
- $blocks[$region] = _region_manager_blocks_filter($region, $all_blocks, $records[$rid]);
- }
- }
- else {
- $rid = $theme_key .':'. $region;
- $blocks = _region_manager_blocks_filter($region, $all_blocks, $records[$rid]);
- }
-
- return $blocks;
-}
-
-/**
- * Helper function to filter all enabled and (available) disabled
- * blocks for a particular region.
- */
-function _region_manager_blocks_filter($region, $blocks = array(), $record = array()) {
- $output = array();
-
- foreach($blocks as $module => $modblocks) {
- if (is_array($modblocks)) {
-
- // If they're all disabled for this module, go on to the next module.
- if ($record['modules'][$module] == REGION_MANAGER_ALL_DISABLED) {
- continue;
- }
-
- // Otherwise, let's parse through each block.
- else {
- foreach($modblocks as $delta => $block) {
- if ($block['status']) {
- // Only add it to active if it's a part of this region.
- if ($block['region'] == $region) {
- $output[] = $block;
- }
- }
- else {
- // Check to see if we're using custom availability for this module.
- if ($record['modules'][$module] == REGION_MANAGER_CUSTOM) {
- $key = $module .':'. $delta;
- // Is this block 'blocked'?
- if (!in_array($key, $record['blocked_blocks'])) {
- $output[] = $block;
- }
- }
- // Otherwise add all blocks for this module.
- else {
- $output[] = $block;
- }
- }
- }
- }
- }
- }
-
- return $output;
-}
-
-/**
- * Helper function to assemble the blocks
- */
-function _region_manager_block_rehash($theme_key) {
- $blocks = array();
-
- $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
- $old_blocks = array();
- while ($old_block = db_fetch_array($result)) {
- $old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
- }
-
- $blocks = array();
- // Valid region names for the theme.
- $regions = system_region_list($theme_key);
-
- foreach (module_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])) {
- // If it's a new block, add identifiers.
- $block['module'] = $module;
- $block['delta'] = $delta;
- $block['theme'] = $theme_key;
- if (!isset($block['pages'])) {
- // {block}.pages is type 'text', so it cannot have a
- // default value, and not null, so we need to provide
- // value if the module did not.
- $block['pages'] = '';
- }
- // Add defaults and save it into the database.
- drupal_write_record('blocks', $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.
- $blocks[$module][$delta] = $block;
- }
- else {
- // If it's an existing block, database settings should overwrite
- // the code. But aside from 'info' everything that's definable in
- // code is stored in the database and we do not store 'info', so we
- // do not need to update the database here.
- // Add 'info' to this block.
- $old_blocks[$module][$delta]['info'] = $block['info'];
- // If the region name does not exist, disable the block and assign it to none.
- if (!empty($old_blocks[$module][$delta]['region']) && !isset($regions[$old_blocks[$module][$delta]['region']])) {
- drupal_set_message(t('The @block %info was assigned to the invalid region %region and has been disabled.', array('@block' => _region_manager_block_name(), '%info' => $old_blocks[$module][$delta]['info'], '%region' => $old_blocks[$module][$delta]['region'])), 'warning');
- $old_blocks[$module][$delta]['status'] = 0;
- $old_blocks[$module][$delta]['region'] = BLOCK_REGION_NONE;
- }
- else {
- $old_blocks[$module][$delta]['region'] = $old_blocks[$module][$delta]['status'] ? $old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
- }
- // Add this block to the list of blocks we return.
- $blocks[$module][$delta] = $old_blocks[$module][$delta];
- // Remove this block from the list of blocks to be deleted.
- unset($old_blocks[$module][$delta]);
- }
- }
- }
- }
-
- // Remove blocks that are no longer defined by the code from the database.
- foreach ($old_blocks as $module => $old_module_blocks) {
- foreach ($old_module_blocks as $delta => $block) {
- db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme_key);
- }
- }
- return $blocks;
-}
-
-/**
- * Helper function to determine if the block is visible for a certain path.
- *
- * @return
- * Boolean FALSE if it's not visible, otherwise a string of the path.
- */
-function _region_manager_block_check_visibility($block, $path = NULL) {
- if ($block['visibility'] == 1) {
- $path = is_null($path) ? drupal_get_path_alias($_GET['q']) : $path;
- // Compare with the internal and path alias (if any).
- $page_match = drupal_match_path($path, $block['pages']);
- if ($path != $_GET['q']) {
- $page_match = $page_match || drupal_match_path($_GET['q'], $block['pages']);
- }
- }
- return $page_match ? $path : FALSE;
-}
-
-/**
- * Helper function to display the custom block name.
- *
- * @param $name
- * String designating upper or lower case.
- */
-function _region_manager_block_name($case = 'lower') {
- static $name;
-
- if (empty($name)) {
- $name = variable_get('region_manager_block_name', 'Block');
- }
-
- if ($case == 'lower') {
- return strtolower($name);
- }
- return ucfirst($name);
-} \ No newline at end of file
diff --git a/region_manager.nodeblock.inc b/region_manager.nodeblock.inc
new file mode 100644
index 0000000..1675f13
--- /dev/null
+++ b/region_manager.nodeblock.inc
@@ -0,0 +1,76 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ *
+ * Holds functions for the nodeblock implementation of Region Manager's block
+ * creation API.
+ */
+
+/**
+ * Implementation of hook_form_alter() on behalf of nodeblock. We need to use
+ * the region_manager namespace since nodeblock already implements this hook.
+ */
+function region_manager_form_alter(&$form, $form_state, $form_id) {
+ if (
+ function_exists('nodeblock_block') &&
+ $form['#id'] == 'node-form' &&
+ variable_get('nodeblock_'. $form['type']['#value'], 0) &&
+ !$form['nid']['#value'] && // Verifies we are inserting, not updating.
+ ($theme_key = $_GET['theme_key']) &&
+ ($region = $_GET['region']) &&
+ ($path = $_REQUEST['destination'])
+ ) {
+ $form['region_manager'] = array(
+ '#tree' => TRUE,
+ );
+ $form['region_manager']['theme_key'] = array(
+ '#type' => 'hidden',
+ '#value' => $theme_key,
+ );
+ $form['region_manager']['region'] = array(
+ '#type' => 'hidden',
+ '#value' => $region,
+ );
+ $form['region_manager']['module'] = array(
+ '#type' => 'hidden',
+ '#value' => 'nodeblock',
+ );
+ $form['region_manager']['path'] = array(
+ '#type' => 'hidden',
+ '#value' => $path,
+ );
+ }
+}
+
+/**
+ * Implementation of hook_region_manager_create_links() on behalf of nodeblock.
+ *
+ * @param $theme_key
+ * A string containing the key of the theme that is being managed.
+ * @param $region
+ * A string containing the region being managed.
+ */
+function nodeblock_region_manager_create_links($theme_key, $region) {
+ $links = array();
+ $records = region_manager_regions_load($theme_key);
+
+ if ($records[$region]['modules']['nodeblock'] != REGION_MANAGER_ALL_DISABLED) {
+ $types = node_get_types();
+ foreach ($types as $type) {
+ if (nodeblock_type_enabled($type)) {
+ if (node_access('create', $type)) {
+ $type_url_str = str_replace('_', '-', $type->type);
+ $path = "node/add/$type_url_str";
+ $links[$path] = array(
+ 'title' => t('@type @block', array('@type' => $type->name, '@block' => _region_manager_block_name())),
+ 'path' => $path,
+ );
+ }
+ }
+ }
+ }
+
+ return $links;
+} \ No newline at end of file
diff --git a/region_manager.pages.inc b/region_manager.pages.inc
index 0587802..5425ab5 100644
--- a/region_manager.pages.inc
+++ b/region_manager.pages.inc
@@ -2,6 +2,19 @@
// $Id$
/**
+ * Define our states.
+ */
+
+// Block is active for the path.
+define('RM_BLOCK_ACTIVE_PATH', 'active_path');
+// Block is a content block and only visible on the page from which it was created.
+define('RM_BLOCK_ACTIVE_CONTENT', 'active_content');
+// Block is active elsewhere.
+define('RM_BLOCK_ACTIVE', 'active');
+// Block is disabled.
+define('RM_BLOCK_DISABLED', 'disabled');
+
+/**
* @file
* Page callbacks for managing regions.
*/
@@ -13,24 +26,34 @@
* A string containing the key of the active theme.
* @param $region
* A string containing the region to be managed.
- *
* @return
* The HTML output of the page.
*/
-function region_manager_manage($theme_key, $region) {
- $output = '';
+function region_manager_manage($key, $region) {
+ global $theme_key;
- // Output the available content blocks to be added, if nodeblock is enabled.
- if (function_exists('nodeblock_block')) {
- $output .= theme('region_manager_nodeblock_menu', _region_manager_nodeblock_links($theme_key, $region));
- }
+ $output = '';
// Fetch and sort blocks
- $blocks = region_manager_blocks_load_all($theme_key, $region);
+ $blocks = region_manager_blocks_load_all($key, $region);
module_load_include('inc', 'block', 'block.admin');
+
+ // If we're setting blocks for a theme different than the active theme,
+ // we need to temporarily override the global $theme_key var for
+ // _block_compare to work properly.
+ if ($theme_key != $key) {
+ $orig_theme = $theme_key;
+ $theme_key = $key;
+ }
+
usort($blocks, '_block_compare');
+ // Now reset the $theme_key back if it was changed.
+ if ($orig_theme) {
+ $theme_key = $orig_theme;
+ }
+
$output .= drupal_get_form('region_manager_manage_form', $blocks, $theme_key, $region);
return $output;
@@ -47,7 +70,6 @@ function region_manager_manage($theme_key, $region) {
* A string containing the key of the active theme.
* @param $region
* A string containing the region to be managed.
- *
* @return
* The form structure.
*/
@@ -61,21 +83,18 @@ function region_manager_manage_form(&$form_state, $blocks, $theme_key, $region)
'#tree' => TRUE,
);
- $block_regions = array();
+ $block_states = array();
// If we're coming from a page, set that up as the top row label.
if ($path = $_REQUEST['destination']) {
- $frontpage = variable_get('site_frontpage', 'node');
- $alias = ($path == $frontpage) ? t('home page') : drupal_get_path_alias($path);
-
- $block_regions['active_path'] = t('Active on %path', array('%path' => $alias));
+ $block_states[RM_BLOCK_ACTIVE_PATH] = t('Active on @path', array('@path' => _region_manager_path_name($path)));
}
// Now add the Active and Disabled row labels.
- $block_regions[$region] = t('Active');
- $block_regions[BLOCK_REGION_NONE] = t('Disabled');
+ $block_states[RM_BLOCK_ACTIVE] = t('Active elsewhere');
+ $block_states[RM_BLOCK_DISABLED] = t('Disabled');
- $form['#block_regions'] = $block_regions;
+ $form['#block_states'] = $block_states;
$form['#region_manager'] = compact('theme_key', 'region', 'path');
// Weights range from -delta to +delta, so delta should be at least half
@@ -100,21 +119,15 @@ function region_manager_manage_form(&$form_state, $blocks, $theme_key, $region)
'#value' => $block['delta'],
);
- // Block name.
+ // Block administration name.
$form[$key]['info'] = array(
- '#value' => check_plain($block['info']),
+ '#value' => $block['info'],
);
- // Set up the javascript link to display the title edit form.
- $link_title = t('Edit/Configure @block Title', array('@block' => _region_manager_block_name('upper')));
- $link_path = 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta'];
- $link_options = array(
- 'attributes' => array('class' => 'region-manager-title-'. $key),
- 'query' => drupal_get_destination()
- );
- $form[$key]['title_link'] = array(
+ // Block operations
+ $form[$key]['operations'] = array(
'#type' => 'markup',
- '#value' => l($link_title, $link_path, $link_options),
+ '#value' => _region_manager_block_operations($block, $key),
);
// Set up the radios for the title status.
@@ -125,23 +138,37 @@ function region_manager_manage_form(&$form_state, $blocks, $theme_key, $region)
'#options' => array(t('Use Default Title'), t('Disable Title'), t('Use Custom Title')),
);
+ // Block title
$form[$key]['title'] = array(
'#attributes' => array('class' => 'region-manager-manage-form-title'),
'#type' => 'textfield',
'#size' => 40,
'#default_value' => $block['title'],
);
+
+ // If this is a content block, we need to add a checkbox so the user can expose
+ // the block to other pages.
+ if ($block['visibility'] == -1) {
+ $form[$key]['expose'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Expose',
+ '#default_value' => FALSE,
+ '#description' => t('Expose this content @block to other pages. <strong>NOTE: this cannot be undone.</strong>', array('@block' => _region_manager_block_name())),
+ );
+ }
+
+ // Block weight
$form[$key]['weight'] = array(
'#type' => 'weight',
'#default_value' => $block['weight'],
'#delta' => $weight_delta,
);
- $form[$key]['region'] = array(
+
+ $form[$key]['state'] = array(
'#type' => 'select',
- '#default_value' => $block['region'],
- '#options' => $block_regions,
+ '#default_value' => _region_manager_block_state($block, $path),
+ '#options' => $block_states,
);
-
$form[$key]['visibility'] = array(
'#type' => 'value',
'#value' => $block['visibility'],
@@ -151,23 +178,22 @@ function region_manager_manage_form(&$form_state, $blocks, $theme_key, $region)
'#value' => $block['pages'],
);
- // Now we customize this block depending on its status.
- if (_region_manager_block_check_visibility($block, $path)) {
- $form[$key]['region']['#default_value'] = 'active_path';
- }
$form[$key]['#attributes']['class'] = 'draggable';
- if ($block['visibility'] != 1) {
- // We can't allow dragging of items if the block visibility isn't 1 and the block is active.
- if ($block['status']) {
- $form[$key]['#attributes']['class'] = 'locked';
+ if ($block['status']) {
+ // We can't allow removal of items if the block visibility is 0 (active on all
+ // pages) or 2 (php code).
+ if ($block['visibility'] == 0 || $block['visibility'] == 2) {
+ $form[$key]['#attributes']['class'] .= ' locked';
$form[$key]['info']['#value'] .= ' '. t('(Locked)');
- }
- // Otherwise we flag this block as being disabled, to aid in processing the form after submission.
- else {
- $form[$key]['disabled'] = array('#type' => 'hidden', '#value' => TRUE);
+ $form[$key]['state']['#default_value'] = RM_BLOCK_ACTIVE_PATH;
}
}
+ // Otherwise we flag this block as being disabled, to aid in processing the form
+ // after submission.
+ else {
+ $form[$key]['disabled'] = array('#type' => 'hidden', '#value' => TRUE);
+ }
}
$form['submit'] = array(
@@ -190,46 +216,58 @@ function region_manager_manage_form_submit($form, &$form_state) {
$path = ($path == $frontpage) ? '<front>' : $path;
foreach ($form_state['values'] as $key => $block) {
- // Set the block status.
- $block['status'] = $block['region'] != BLOCK_REGION_NONE;
+ // Clean up the title.
$block['title'] = trim($block['title']);
- // Now let's go through our different scenarios for enabled blocks.
- if ($block['status']) {
- // If the block is enabled for this path, we have to set the region and
- // add the path to $block['pages'].
- if ($path && ($block['region'] == 'active_path')) {
- // Set the region.
+ // Now let's go through our different states.
+ switch($block['state']) {
+ case RM_BLOCK_ACTIVE_PATH:
$block['region'] = $region;
- // Add the path to pages, if it's not already there.
- if (!preg_match('/^'. preg_quote($path, '/') .'$/im', $block['pages'])) {
+ $block['status'] = 1;
+
+ // If the block was originally disabled, we need to set it up for our usage.
+ if ($block['disabled']) {
+ $block['visibility'] = 1;
+ $block['pages'] = $path;
+ }
+
+ // If this is a content block and 'expose' was checked, change visibility to 1.
+ if ($block['expose']) {
+ $block['visibility'] = 1;
+ }
+
+ // Otherwise, all we need to do is add our path to pages.
+ elseif (($block['visibility'] == 1) && !preg_match('/^'. preg_quote($path, '/') .'$/im', $block['pages'])) {
$block['pages'] .= empty($block['pages']) ? $path : "\n". $path;
}
- }
- // Otherwise, if it's active, but not enabled for this path, make sure
- // we remove the path from $block['pages']
- elseif ($block['region'] == $region) {
+ break;
+
+ case RM_BLOCK_ACTIVE:
+ $block['region'] = $region;
+ $block['status'] = 1;
+
// Remove path from the pages.
- if (_region_manager_block_check_visibility($block, $path)) {
- $block['pages'] = preg_replace('/^'. preg_quote($path, '/') .'$/im', '', $block['pages']);
+ $block['pages'] = trim(preg_replace('/^'. preg_quote($path, '/') .'$/im', '', $block['pages']));
+
+ // Now check to see if pages is empty, if so, completely disable.
+ if ($block['visibility'] == 1 && empty($block['pages'])) {
+ unset($block['disabled']);
+ $block['status'] = 0;
+ $block['region'] = '';
}
- }
+ break;
- // If the block was originally disabled, we need to set it up for our usage.
- if ($block['disabled']) {
- $block['visibility'] = 1;
- $block['pages'] = $path;
- }
- }
- // If the block is disabled, clean up region and pages.
- else {
- $block['region'] = '';
- if ($block['visibility'] == 1) {
- $block['pages'] = '';
- }
+ case RM_BLOCK_DISABLED:
+ $block['region'] = '';
+ if ($block['visibility'] == 1) {
+ $block['pages'] = '';
+ }
+ break;
}
+
db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', visibility = %d, pages = '%s', title = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['title'], $block['module'], $block['delta'], $block['theme']);
}
+
drupal_set_message(t('The @block settings have been updated.', array('@block' => _region_manager_block_name())));
cache_clear_all();
}
@@ -244,52 +282,48 @@ function region_manager_manage_form_submit($form, &$form_state) {
* @see theme_region_manager_manage_form()
*/
function template_preprocess_region_manager_manage_form(&$vars) {
- global $theme_key;
+ $theme_key = $vars['form']['#region_manager']['theme_key'];
- $block_regions = $vars['form']['#block_regions'];
- $vars['block_regions'] = $block_regions + array(BLOCK_REGION_NONE => t('Disabled'));
+ $block_states = $vars['block_states'] = $vars['form']['#block_states'];
+ $vars['state_prefix'] = $vars['state_suffix'] = array();
- foreach ($block_regions as $key => $value) {
- // Highlight regions on page to provide visual reference.
- drupal_set_content($key, '<div class="block-region">'. $value .'</div>');
- // Initialize an empty array for the region.
- $vars['block_listing'][$key] = array();
+ foreach ($block_states as $state => $value) {
+ _region_manager_manage_form_state_wrappers($vars, $state);
+ $vars['block_listing'][$state] = array();
}
// Initialize disabled blocks array.
$vars['block_listing'][BLOCK_REGION_NONE] = array();
// Set up to track previous region in loop.
- $last_region = '';
+ $last_state = '';
foreach (element_children($vars['form']) as $i) {
$block = &$vars['form'][$i];
// Only take form elements that are blocks.
if (isset($block['info'])) {
- // Fetch region for current block.
- $region = $block['region']['#default_value'];
+ // Fetch state for current block.
+ $state = $block['state']['#default_value'];
// Set special classes needed for table drag and drop.
- $vars['form'][$i]['region']['#attributes']['class'] = 'block-region-select block-region-'. $region;
- $vars['form'][$i]['weight']['#attributes']['class'] = 'block-weight block-weight-'. $region;
-
- $vars['block_listing'][$region][$i]->row_class = isset($block['#attributes']['class']) ? $block['#attributes']['class'] : '';
- $vars['block_listing'][$region][$i]->block_modified = isset($block['#attributes']['class']) && strpos($block['#attributes']['class'], 'block-modified') !== FALSE ? TRUE : FALSE;
-
- $vars['block_listing'][$region][$i]->block_title = '<strong class="block-info">'. drupal_render($block['info']) .'</strong>';
- $vars['block_listing'][$region][$i]->block_title .= '<div class="region-manager-block-title-wrapper region-manager-title-'. $i .'">';
- $vars['block_listing'][$region][$i]->block_title .= drupal_render($block['title_status']) . drupal_render($block['title']);
- $vars['block_listing'][$region][$i]->block_title .= '</div>';
- $vars['block_listing'][$region][$i]->title_link = drupal_render($block['title_link']);
-
- $vars['block_listing'][$region][$i]->region_select = drupal_render($block['region']) . drupal_render($block['theme']);
- $vars['block_listing'][$region][$i]->weight_select = drupal_render($block['weight']);
- $vars['block_listing'][$region][$i]->throttle_check = $vars['throttle'] ? drupal_render($block['throttle']) : '';
- $vars['block_listing'][$region][$i]->configure_link = drupal_render($block['configure']);
- $vars['block_listing'][$region][$i]->delete_link = !empty($block['delete']) ? drupal_render($block['delete']) : '';
- $vars['block_listing'][$region][$i]->printed = FALSE;
-
- $last_region = $region;
+ $vars['form'][$i]['state']['#attributes']['class'] = 'block-state-select block-state-'. $state;
+ $vars['form'][$i]['weight']['#attributes']['class'] = 'block-weight block-weight-'. $state;
+
+ $vars['block_listing'][$state][$i]->row_class = isset($block['#attributes']['class']) ? $block['#attributes']['class'] : '';
+ $vars['block_listing'][$state][$i]->block_modified = isset($block['#attributes']['class']) && strpos($block['#attributes']['class'], 'block-modified') !== FALSE ? TRUE : FALSE;
+
+ $vars['block_listing'][$state][$i]->block_config = '<strong class="block-info">'. drupal_render($block['info']) .'</strong>';
+ $vars['block_listing'][$state][$i]->block_config .= '<div class="region-manager-block-config-wrapper">';
+ $vars['block_listing'][$state][$i]->block_config .= drupal_render($block['title_status']) . drupal_render($block['title']);
+ $vars['block_listing'][$state][$i]->block_config .= ($block['expose']) ? drupal_render($block['expose']) : '';
+ $vars['block_listing'][$state][$i]->block_config .= '</div>';
+
+ $vars['block_listing'][$state][$i]->operations = drupal_render($block['operations']);
+
+ $vars['block_listing'][$state][$i]->state_select = drupal_render($block['state']) . drupal_render($block['theme']);
+ $vars['block_listing'][$state][$i]->weight_select = drupal_render($block['weight']);
+
+ $last_state = $state;
}
}
@@ -297,53 +331,121 @@ function template_preprocess_region_manager_manage_form(&$vars) {
}
/**
- * Theme function to output a list of nodeblock content types to add.
- *
- * @param $links
- * An array containing the available content types to add.
- *
- * @return
- * The HTML list of links.
+ * Helper function to assemble the prefixes and suffixes for the state tables.
*/
-function theme_region_manager_nodeblock_menu($links) {
- if (empty($links)) {
- return;
- }
- $output = '<div class="region-manager-nodeblock-menu">';
- $output .= '<h4>'. t('Add new:') .'</h4>';
+function _region_manager_manage_form_state_wrappers(&$vars, $state) {
+ $theme_key = $vars['form']['#region_manager']['theme_key'];
+ $region = $vars['form']['#region_manager']['region'];
+ $vars['state_prefix'][$state] = $vars['state_suffix'][$state] = '';
+
+ switch($state) {
+ case RM_BLOCK_ACTIVE_PATH:
+ $vars['state_prefix'][$state] = '<div id="region-manager-active-path-wrapper">';
+ // Output the create links, if there are any.
+ if ($links = region_manager_create_links($theme_key, $region)) {
+ $vars['state_prefix'][$state] .= theme('region_manager_create_menu', $links);
+ }
+ break;
- $output .= theme('item_list', $links);
- $output .= '</div>';
+ case RM_BLOCK_ACTIVE_CONTENT:
+ $vars['state_prefix'][$state] = '</div><div id="region-manager-active-content-wrapper">';
+ break;
+
+ case RM_BLOCK_ACTIVE:
+ $vars['state_prefix'][$state] = '</div><div id="region-manager-active-disabled-tables-wrapper">';
+ break;
+
+ case RM_BLOCK_DISABLED:
+ $vars['state_suffix'][$state] = '</div>';
+ }
return $output;
}
/**
- * Loads a list of links to add new nodeblock content types.
- *
- * @param $theme_key
- * A string containing the key of the active theme.
- * @param $region
- * A string containing the region to be managed.
+ * Helper function to assemble a list of operations for a block.
+ */
+function _region_manager_block_operations($block, $key) {
+ $links = array();
+
+ // Set up all the operations.
+ $args = array('@block' => _region_manager_block_name('upper'));
+ $ops = array(
+ 'disable' => t('Disable @block completely', $args),
+ 'remove' => t('Remove @block from this page', $args),
+ 'configure' => t('Configure @block', $args),
+ 'add' => t('Add @block to this page', $args),
+ );
+
+ // Get the path and destination.
+ $path = 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta'];
+ $dest = drupal_get_destination();
+
+ foreach($ops as $op => $title) {
+ $options = array(
+ 'attributes' => array(
+ 'title' => $title,
+ 'class' => $op,
+ ),
+ 'query' => $dest,
+ );
+
+ $links[] = array('data' => l($title, $path, $options), 'class' => 'rm-block-'. $op .'-operation');
+ }
+
+ return theme('item_list', $links, NULL, 'ul', array('class' => 'rm-block-'. $key));
+}
+
+/**
+ * Helper function to determine the state of a block.
*
* @return
- * An array containing the available content types to add.
+ * A string signifying the block state.
*/
-function _region_manager_nodeblock_links($theme_key, $region) {
- $types = node_get_types();
-
- foreach ($types as $type) {
- if (nodeblock_type_enabled($type)) {
- if (node_access('create', $type)) {
- $options = array();
- if ($path = $_REQUEST['destination']) {
- $options['query'] = array('destination' => $path);
- }
- $type_url_str = str_replace('_', '-', $type->type);
- $links[] = l(t('@type @block', array('@type' => $type->name, '@block' => _region_manager_block_name())), "node/add/$type_url_str/$theme_key/$region", $options);
- }
- }
+function _region_manager_block_state($block, $path) {
+ // Block is disabled and available for use.
+ if ($block['status'] == 0) {
+ return RM_BLOCK_DISABLED;
+ }
+ // Block is active on this path.
+ if (_region_manager_block_check_visibility($block, $path)) {
+ return RM_BLOCK_ACTIVE_PATH;
}
+ // Block is a content block and only visible on the page from which it was created.
+ if ($block['visibility'] == -1) {
+ return RM_BLOCK_ACTIVE_CONTENT;
+ }
+ // Block is active elsewhere.
+ return RM_BLOCK_ACTIVE;
+}
+
+/**
+ * Theme function to output a list of nodeblock content types to add.
+ *
+ * @param $links
+ * An array containing the available content types to add.
+ * @return
+ * The HTML list of links.
+ */
+function theme_region_manager_create_menu($links) {
+ $output = '<div class="region-manager-create-menu">';
+
+ // The arguments array for the t() func.
+ $t_args = array('@block' => _region_manager_block_name());
+
+ // Link options. We set a title here since we're going to be using
+ // a fancy button.
+ $options = array('attributes' => array(
+ 'title' => t('Create and add a new content @block', $t_args),
+ 'class' => 'region-manager-create-menu-link',
+ ));
+ $output .= '<h4>'. l(t('Create content @block', $t_args), 'node/add', $options) .'</h4>';
+
+ $output .= '<div class="item-list-wrapper"><p>'. t('Click on a link below to create a new content @block.', $t_args) .'</p>';
+ $output .= theme('item_list', $links);
+ $output .= '</div></div>';
+
+ return $output;
}
/**
@@ -356,7 +458,6 @@ function _region_manager_nodeblock_links($theme_key, $region) {
*
* @param $title
* A string containing the current title.
- *
* @return
* An integer containing the title state.
*/