| 1 |
<?php |
<?php |
| 2 |
// $Id: block.module,v 1.162.2.6 2006/08/22 19:32:56 dries Exp $ |
// $Id: block.module,v 1.210 2006/07/02 20:06:31 drumm Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 12 |
function block_help($section) { |
function block_help($section) { |
| 13 |
switch ($section) { |
switch ($section) { |
| 14 |
case 'admin/help#block': |
case 'admin/help#block': |
| 15 |
return t(' |
$output = '<p>'. t('Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. Blocks are usually generated automatically by modules (e.g., Recent Forum Topics), but administrators can also define custom blocks.') .'</p>'; |
| 16 |
<p>Blocks are the boxes visible in the sidebar(s) of your web site. These are usually generated automatically by modules (e.g. recent forum topics), but you can also create your own blocks.</p> |
$output .= '<p>'. t('The region each block appears in depends on both which theme you are using (some themes allow greater control over block placement than others), and on the settings in the block administration section.') .'</p>'; |
| 17 |
<p>The sidebar each block appears in depends on both which theme you are using (some are left-only, some right, some both), and on the settings in block management.</p> |
$output .= '<p>'. t('The block administration screen lets you specify the vertical placement of the blocks within a region. You do this by assigning a weight to each block. Lighter blocks (those having a smaller weight) "float up" towards the top of the region; heavier ones "sink".') .'</p>'; |
| 18 |
<p>The block management screen lets you specify the vertical sort-order of the blocks within a sidebar. You do this by assigning a weight to each block. Lighter blocks (smaller weight) "float up" towards the top of the sidebar. Heavier ones "sink down" towards the bottom of it.</p> |
$output .= t('<p>A block\'s visibility depends on:</p> |
|
<p>A block\'s visibility depends on:</p> |
|
| 19 |
<ul> |
<ul> |
| 20 |
<li>Its enabled checkbox. Disabled blocks are never shown.</li> |
<li>Its enabled checkbox. Disabled blocks are never shown.</li> |
| 21 |
<li>Its throttle checkbox. Throttled blocks are hidden during high server loads.</li> |
<li>Its throttle checkbox. Throttled blocks are hidden during high server loads.</li> |
| 22 |
<li>Its path options. Blocks can be configured to only show/hide on certain pages.</li> |
<li>Its page visibility settings. Blocks can be configured to be visible/hidden on certain pages.</li> |
| 23 |
<li>User settings. You can choose to let your users decide whether to show/hide certain blocks.</li> |
<li>Its custom visibility settings. Blocks can be configured to be visible only when specific conditions are true.</li> |
| 24 |
<li>Its function. Dynamic blocks (such as those defined by modules) may be empty on certain pages and will not be shown.</li> |
<li>Its user visibility settings. Administrators can choose to let users decide whether to show/hide certain blocks.</li> |
| 25 |
|
<li>Its user-role visibility settings. Administrators can choose to let blocks be visible only for certain user roles.</li> |
| 26 |
|
<li>Its function. Some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.</li> |
| 27 |
</ul> |
</ul> |
| 28 |
|
'); |
| 29 |
<h3>Administrator defined blocks</h3> |
$output .= '<h3>'. t('Module blocks') .'</h3>'; |
| 30 |
<p>An administrator defined block contains content supplied by you (as opposed to being generated automatically by a module). Each admin-defined block consists of a title, a description, and a body which can be as long as you wish. The Drupal engine will render the content of the block.</p>'); |
$output .= '<p>'. t('Some modules generate blocks that become available when the modules are enabled. These blocks can be administered via the <a href="%admin-block">blocks administration page</a>.</p>', array('%admin-block' => url('admin/block'))) .'</p>'; |
| 31 |
|
$output .= '<h3>'. t('Administrator defined blocks') .'</h3>'; |
| 32 |
|
$output .= '<p>'. t('Administrators can also define custom blocks. These blocks consist of a title, a description, and a body which can be as long as you wish. Block content can be in any of the input formats supported for other content.') .'</p>'; |
| 33 |
|
$output .= t('<p>You can</p> |
| 34 |
|
<ul> |
| 35 |
|
<li>enable, throttle and configure blocks at <a href="%admin-block">administer >> blocks</a>.</li> |
| 36 |
|
<li>add an administrator-defined block at <a href="%admin-block-add">administer >> blocks >> add block</a>.</li> |
| 37 |
|
</ul> |
| 38 |
|
', array('%admin-block' => url('admin/block'), '%admin-block-add' => url('admin/block/add'))); |
| 39 |
|
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%block">Block page</a>.', array('%block' => 'http://drupal.org/handbook/modules/block/')) .'</p>'; |
| 40 |
|
return $output; |
| 41 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 42 |
return t('Controls the boxes that are displayed around the main content.'); |
return t('Controls the boxes that are displayed around the main content.'); |
| 43 |
case 'admin/block': |
case 'admin/block': |
| 44 |
return t(" |
return t(" |
| 45 |
<p>Blocks are the boxes in the left and right side bars of the web site. They are made available by modules or created manually.</p> |
<p>Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. They are usually generated automatically by modules, but administrators can create blocks manually.</p> |
| 46 |
<p>Only enabled blocks are shown. You can position the blocks by deciding which side of the page they will show up on (sidebar) and in which order they appear (weight).</p> |
<p>Only enabled blocks are shown. You can position blocks by specifying which area of the page they should appear in (e.g., a sidebar). Highlighted labels on this page show the regions into which blocks can be rendered. You can specify where within a region a block will appear by adjusting its weight.</p> |
| 47 |
<p>If you want certain blocks to disable themselves temporarily during high server loads, check the 'Throttle' box. You can configure the auto-throttle on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.</p> |
<p>If you want certain blocks to disable themselves temporarily during high server loads, check the 'Throttle' box. You can configure the auto-throttle on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.</p> |
| 48 |
|
<p>You can configure the behaviour of each block (for example, specifying on which pages and for what users it will appear) by clicking the 'configure' link for each block.</p> |
| 49 |
", array('%throttle' => url('admin/settings/throttle'))); |
", array('%throttle' => url('admin/settings/throttle'))); |
| 50 |
case 'admin/block/add': |
case 'admin/block/add': |
| 51 |
return t('<p>Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href="%overview">blocks</a>. The title is used when displaying the block. The description is used in the "block" column on the <a href="%overview">blocks</a> page.</p>', array('%overview' => url('admin/block'))); |
return t('<p>Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href="%overview">blocks</a>. The title is used when displaying the block. The description is used in the "block" column on the <a href="%overview">blocks</a> page.</p>', array('%overview' => url('admin/block'))); |
| 56 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 57 |
*/ |
*/ |
| 58 |
function block_perm() { |
function block_perm() { |
| 59 |
return array('administer blocks'); |
return array('administer blocks', 'use PHP for block visibility'); |
| 60 |
} |
} |
| 61 |
|
|
| 62 |
/** |
/** |
| 68 |
if ($may_cache) { |
if ($may_cache) { |
| 69 |
$items[] = array('path' => 'admin/block', 'title' => t('blocks'), |
$items[] = array('path' => 'admin/block', 'title' => t('blocks'), |
| 70 |
'access' => user_access('administer blocks'), |
'access' => user_access('administer blocks'), |
| 71 |
'callback' => 'block_admin'); |
'callback' => 'block_admin_display'); |
| 72 |
$items[] = array('path' => 'admin/block/list', 'title' => t('list'), |
$items[] = array('path' => 'admin/block/list', 'title' => t('list'), |
| 73 |
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); |
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); |
| 74 |
$items[] = array('path' => 'admin/block/configure', 'title' => t('configure block'), |
$items[] = array('path' => 'admin/block/configure', 'title' => t('configure block'), |
| 83 |
'access' => user_access('administer blocks'), |
'access' => user_access('administer blocks'), |
| 84 |
'callback' => 'block_box_add', |
'callback' => 'block_box_add', |
| 85 |
'type' => MENU_LOCAL_TASK); |
'type' => MENU_LOCAL_TASK); |
| 86 |
|
foreach (list_themes() as $key => $theme) { |
| 87 |
|
if ($theme->status) { |
| 88 |
|
if ($key == variable_get('theme_default', 'bluemarine')) { |
| 89 |
|
$items[] = array('path' => 'admin/block/list/' . $key, 'title' => t('%key settings', array('%key' => $key)), |
| 90 |
|
'access' => user_access('administer blocks'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); |
| 91 |
|
} |
| 92 |
|
else { |
| 93 |
|
$items[] = array('path' => 'admin/block/list/' . $key, 'title' => t('%key settings', array('%key' => $key)), |
| 94 |
|
'access' => user_access('administer blocks'), 'type' => MENU_LOCAL_TASK); |
| 95 |
|
} |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
} |
} |
| 99 |
|
|
| 100 |
return $items; |
return $items; |
| 108 |
function block_block($op = 'list', $delta = 0, $edit = array()) { |
function block_block($op = 'list', $delta = 0, $edit = array()) { |
| 109 |
switch ($op) { |
switch ($op) { |
| 110 |
case 'list': |
case 'list': |
| 111 |
|
$blocks = array(); |
| 112 |
|
|
| 113 |
$result = db_query('SELECT bid, title, info FROM {boxes} ORDER BY title'); |
$result = db_query('SELECT bid, title, info FROM {boxes} ORDER BY title'); |
| 114 |
while ($block = db_fetch_object($result)) { |
while ($block = db_fetch_object($result)) { |
| 115 |
$blocks[$block->bid]['info'] = $block->info ? check_plain($block->info) : check_plain($block->title); |
$blocks[$block->bid]['info'] = $block->info ? check_plain($block->info) : check_plain($block->title); |
| 130 |
case 'view': |
case 'view': |
| 131 |
$block = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid = %d', $delta)); |
$block = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid = %d', $delta)); |
| 132 |
$data['subject'] = check_plain($block->title); |
$data['subject'] = check_plain($block->title); |
| 133 |
$data['content'] = check_output($block->body, $block->format); |
$data['content'] = check_markup($block->body, $block->format, FALSE); |
| 134 |
return $data; |
return $data; |
| 135 |
} |
} |
| 136 |
} |
} |
| 137 |
|
|
|
function block_admin_save($edit) { |
|
|
unset($edit['token']); |
|
|
foreach ($edit as $module => $blocks) { |
|
|
foreach ($blocks as $delta => $block) { |
|
|
db_query("UPDATE {blocks} SET region = %d, status = %d, weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'", |
|
|
$block['region'], $block['status'], $block['weight'], $block['throttle'], $module, $delta); |
|
|
} |
|
|
} |
|
|
|
|
|
return t('The block settings have been updated.'); |
|
|
} |
|
|
|
|
| 138 |
/** |
/** |
| 139 |
* Update the 'blocks' DB table with the blocks currently exported by modules. |
* Update the 'blocks' DB table with the blocks currently exported by modules. |
| 140 |
* |
* |
|
* @param $order_by php <a |
|
|
* href="http://www.php.net/manual/en/function.array-multisort.php">array_multisort()</a> |
|
|
* style sort ordering, eg. "weight", SORT_ASC, SORT_STRING. |
|
|
* |
|
| 141 |
* @return |
* @return |
| 142 |
* Blocks currently exported by modules, sorted by $order_by. |
* Blocks currently exported by modules. |
| 143 |
*/ |
*/ |
| 144 |
function _block_rehash($order_by = array('weight')) { |
function _block_rehash() { |
| 145 |
$result = db_query('SELECT * FROM {blocks} '); |
global $theme_key; |
| 146 |
|
|
| 147 |
|
init_theme(); |
| 148 |
|
|
| 149 |
|
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key); |
| 150 |
while ($old_block = db_fetch_object($result)) { |
while ($old_block = db_fetch_object($result)) { |
| 151 |
$old_blocks[$old_block->module][$old_block->delta] = $old_block; |
$old_blocks[$old_block->module][$old_block->delta] = $old_block; |
| 152 |
} |
} |
| 153 |
|
|
| 154 |
db_query('DELETE FROM {blocks} '); |
db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key); |
| 155 |
|
|
| 156 |
foreach (module_list() as $module) { |
foreach (module_list() as $module) { |
| 157 |
$module_blocks = module_invoke($module, 'block', 'list'); |
$module_blocks = module_invoke($module, 'block', 'list'); |
| 159 |
foreach ($module_blocks as $delta => $block) { |
foreach ($module_blocks as $delta => $block) { |
| 160 |
$block['module'] = $module; |
$block['module'] = $module; |
| 161 |
$block['delta'] = $delta; |
$block['delta'] = $delta; |
| 162 |
|
// If previously written to database, load values. |
| 163 |
if ($old_blocks[$module][$delta]) { |
if ($old_blocks[$module][$delta]) { |
| 164 |
$block['status'] = $old_blocks[$module][$delta]->status; |
$block['status'] = $old_blocks[$module][$delta]->status; |
| 165 |
$block['weight'] = $old_blocks[$module][$delta]->weight; |
$block['weight'] = $old_blocks[$module][$delta]->weight; |
| 168 |
$block['pages'] = $old_blocks[$module][$delta]->pages; |
$block['pages'] = $old_blocks[$module][$delta]->pages; |
| 169 |
$block['custom'] = $old_blocks[$module][$delta]->custom; |
$block['custom'] = $old_blocks[$module][$delta]->custom; |
| 170 |
$block['throttle'] = $old_blocks[$module][$delta]->throttle; |
$block['throttle'] = $old_blocks[$module][$delta]->throttle; |
|
$block['types'] = $old_blocks[$module][$delta]->types; |
|
| 171 |
} |
} |
| 172 |
|
// Otherwise, use any set values, or else substitute defaults. |
| 173 |
else { |
else { |
| 174 |
$block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0; |
$properties = array('status' => 0, 'weight' => 0, 'region' => 'left', 'pages' => '', 'custom' => 0); |
| 175 |
$block['pages'] = $block['types'] = ''; |
foreach ($properties as $property => $default) { |
| 176 |
|
if (!isset($block[$property])) { |
| 177 |
|
$block[$property] = $default; |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
} |
} |
| 181 |
|
|
| 182 |
// reinsert blocks into table |
// Reinsert blocks into table |
| 183 |
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')", |
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)", |
| 184 |
$block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['types']); |
$block['module'], $block['delta'], $theme_key, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']); |
|
|
|
| 185 |
$blocks[] = $block; |
$blocks[] = $block; |
|
|
|
|
// build array to sort on |
|
|
$order[$order_by[0]][] = $block[$order_by[0]]; |
|
| 186 |
} |
} |
| 187 |
} |
} |
| 188 |
} |
} |
| 189 |
|
|
|
// sort |
|
|
array_multisort($order[$order_by[0]], $order_by[1] ? $order_by[1] : SORT_ASC, $order_by[2] ? $order_by[2] : SORT_REGULAR, $blocks); |
|
|
|
|
| 190 |
return $blocks; |
return $blocks; |
| 191 |
} |
} |
| 192 |
|
|
| 193 |
/** |
/** |
| 194 |
* Prepare the main block administration form. |
* Generate main block administration form. |
| 195 |
*/ |
*/ |
| 196 |
function block_admin_display() { |
function block_admin_display() { |
| 197 |
$blocks = _block_rehash(); |
global $theme_key, $custom_theme; |
| 198 |
|
|
| 199 |
$header = array(t('Block'), t('Enabled'), t('Weight'), t('Sidebar')); |
// If non-default theme configuration has been selected, set the custom theme. |
| 200 |
if (module_exist('throttle')) { |
if (arg(3)) { |
| 201 |
$header[] = t('Throttle'); |
$custom_theme = arg(3); |
| 202 |
} |
} |
| 203 |
$header[] = array('data' => t('Operations'), 'colspan' => 2); |
else { |
| 204 |
|
$custom_theme = variable_get('theme_default', 'bluemarine'); |
| 205 |
|
} |
| 206 |
|
init_theme(); |
| 207 |
|
|
| 208 |
$left = array(); |
// Fetch and sort blocks |
| 209 |
$right = array(); |
$blocks = _block_rehash(); |
| 210 |
$disabled = array(); |
usort($blocks, '_block_compare'); |
|
foreach ($blocks as $block) { |
|
|
if ($block['module'] == 'block') { |
|
|
$delete = l(t('delete'), 'admin/block/delete/'. $block['delta']); |
|
|
} |
|
|
else { |
|
|
$delete = ''; |
|
|
} |
|
| 211 |
|
|
| 212 |
$row = array(array('data' => $block['info'], 'class' => 'block'), |
$throttle = module_exist('throttle'); |
| 213 |
form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), |
$block_regions = system_region_list($theme_key); |
|
form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), |
|
|
form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], |
|
|
array(t('left'), t('right')))); |
|
| 214 |
|
|
| 215 |
if (module_exist('throttle')) { |
// Build form tree |
| 216 |
$row[] = form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle']); |
$form['#action'] = arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block'); |
| 217 |
} |
$form['#tree'] = TRUE; |
| 218 |
$row[] = l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']); |
foreach ($blocks as $i => $block) { |
| 219 |
$row[] = $delete; |
$form[$i]['module'] = array('#type' => 'value', '#value' => $block['module']); |
| 220 |
if ($block['status']) { |
$form[$i]['delta'] = array('#type' => 'value', '#value' => $block['delta']); |
| 221 |
if ($block['region'] == 0) { |
$form[$i]['info'] = array('#value' => $block['info']); |
| 222 |
$left[] = $row; |
$form[$i]['status'] = array('#type' => 'checkbox', '#default_value' => $block['status']); |
| 223 |
} |
$form[$i]['theme'] = array('#type' => 'hidden', '#value' => $theme_key); |
| 224 |
if ($block['region'] == 1) { |
$form[$i]['weight'] = array('#type' => 'weight', '#default_value' => $block['weight']); |
| 225 |
$right[] = $row; |
$form[$i]['region'] = array('#type' => 'select', |
| 226 |
} |
'#default_value' => isset($block['region']) ? $block['region'] : system_default_region($theme_key), |
| 227 |
|
'#options' => $block_regions, |
| 228 |
|
); |
| 229 |
|
|
| 230 |
|
if ($throttle) { |
| 231 |
|
$form[$i]['throttle'] = array('#type' => 'checkbox', '#default_value' => $block['throttle']); |
| 232 |
} |
} |
| 233 |
else if ($block['region'] <= 1) { |
$form[$i]['configure'] = array('#value' => l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta'])); |
| 234 |
$disabled[] = $row; |
if ($block['module'] == 'block') { |
| 235 |
|
$form[$i]['delete'] = array('#value' => l(t('delete'), 'admin/block/delete/'. $block['delta'])); |
| 236 |
} |
} |
| 237 |
} |
} |
| 238 |
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Save blocks')); |
| 239 |
|
|
| 240 |
|
return drupal_get_form('block_admin_display', $form); |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
/** |
| 244 |
|
* Helper function for sorting blocks on admin/block. |
| 245 |
|
* |
| 246 |
|
* Active blocks are sorted by region, then by weight. |
| 247 |
|
* Disabled blocks are sorted by name. |
| 248 |
|
*/ |
| 249 |
|
function _block_compare($a, $b) { |
| 250 |
|
$status = $b['status'] - $a['status']; |
| 251 |
|
// Separate enabled from disabled. |
| 252 |
|
if ($status) { |
| 253 |
|
return $status; |
| 254 |
|
} |
| 255 |
|
// Enabled blocks |
| 256 |
|
if ($a['status']) { |
| 257 |
|
$place = strcmp($a['region'], $b['region']); |
| 258 |
|
return $place ? $place : ($a['weight'] - $b['weight']); |
| 259 |
|
} |
| 260 |
|
// Disabled blocks |
| 261 |
|
else { |
| 262 |
|
return strcmp($a['info'], $b['info']); |
| 263 |
|
} |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
/** |
| 267 |
|
* Process main block administration form submission. |
| 268 |
|
*/ |
| 269 |
|
function block_admin_display_submit($form_id, $form_values) { |
| 270 |
|
foreach ($form_values as $block) { |
| 271 |
|
db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', throttle = %d WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], $block['throttle'], $block['module'], $block['delta'], $block['theme']); |
| 272 |
|
} |
| 273 |
|
drupal_set_message(t('The block settings have been updated.')); |
| 274 |
|
cache_clear_all(); |
| 275 |
|
} |
| 276 |
|
|
| 277 |
|
/** |
| 278 |
|
* Theme main block administration form submission. |
| 279 |
|
* |
| 280 |
|
* Note: the blocks are already sorted in the right order, |
| 281 |
|
* grouped by status, region and weight. |
| 282 |
|
*/ |
| 283 |
|
function theme_block_admin_display($form) { |
| 284 |
|
global $theme_key; |
| 285 |
|
|
| 286 |
|
$throttle = module_exist('throttle'); |
| 287 |
|
$block_regions = system_region_list($theme_key); |
| 288 |
|
|
| 289 |
|
// Highlight regions on page to provide visual reference. |
| 290 |
|
foreach ($block_regions as $key => $value) { |
| 291 |
|
drupal_set_content($key, '<div class="block-region">' . $value . '</div>'); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
// Build rows |
| 295 |
$rows = array(); |
$rows = array(); |
| 296 |
if (count($left)) { |
$last_region = ''; |
| 297 |
$rows[] = array(array('data' => t('Left sidebar'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6))); |
$last_status = 1; |
| 298 |
$rows = array_merge($rows, $left); |
foreach (element_children($form) as $i) { |
| 299 |
} |
$block = $form[$i]; |
| 300 |
if (count($right)) { |
// Only take form elements that are blocks. |
| 301 |
$rows[] = array(array('data' => t('Right sidebar'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6))); |
if (is_array($block['info'])) { |
| 302 |
$rows = array_merge($rows, $right); |
// Fetch values |
| 303 |
} |
$region = $block['region']['#default_value']; |
| 304 |
if (count($disabled)) { |
$status = $block['status']['#default_value']; |
| 305 |
$rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6))); |
|
| 306 |
$rows = array_merge($rows, $disabled); |
// Output region header |
| 307 |
|
if ($status && $region != $last_region) { |
| 308 |
|
$region_title = t('%region', array('%region' => drupal_ucfirst($block_regions[$region]))); |
| 309 |
|
$rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => ($throttle ? 7 : 6))); |
| 310 |
|
$last_region = $region; |
| 311 |
|
} |
| 312 |
|
// Output disabled header |
| 313 |
|
elseif ($status != $last_status) { |
| 314 |
|
$rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => ($throttle ? 7 : 6))); |
| 315 |
|
$last_status = $status; |
| 316 |
|
} |
| 317 |
|
|
| 318 |
|
// Generate block row |
| 319 |
|
$row = array( |
| 320 |
|
array('data' => form_render($block['info']), 'class' => 'block'), |
| 321 |
|
form_render($block['status']) . form_render($block['theme']), |
| 322 |
|
form_render($block['weight']), |
| 323 |
|
form_render($block['region']) |
| 324 |
|
); |
| 325 |
|
if ($throttle) { |
| 326 |
|
$row[] = form_render($block['throttle']); |
| 327 |
|
} |
| 328 |
|
$row[] = form_render($block['configure']); |
| 329 |
|
$row[] = $block['delete'] ? form_render($block['delete']) : ''; |
| 330 |
|
$rows[] = $row; |
| 331 |
|
} |
| 332 |
|
} |
| 333 |
|
|
| 334 |
|
// Finish table |
| 335 |
|
$header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement')); |
| 336 |
|
if ($throttle) { |
| 337 |
|
$header[] = t('Throttle'); |
| 338 |
} |
} |
| 339 |
|
$header[] = array('data' => t('Operations'), 'colspan' => 2); |
| 340 |
|
|
| 341 |
$output = theme('table', $header, $rows, array('id' => 'blocks')); |
$output = theme('table', $header, $rows, array('id' => 'blocks')); |
| 342 |
$output .= form_submit(t('Save blocks')); |
$output .= form_render($form['submit']); |
| 343 |
|
// Also render the form_id as there is no form_render($form) call (as form_render does not appear to handle the |
| 344 |
|
// multi-dimensional block form array very well). |
| 345 |
|
$output .= form_render($form['form_id']); |
| 346 |
|
|
| 347 |
return form($output, 'post', url('admin/block')); |
return $output; |
| 348 |
} |
} |
| 349 |
|
|
| 350 |
function block_box_get($bid) { |
function block_box_get($bid) { |
| 355 |
* Menu callback; displays the block configuration form. |
* Menu callback; displays the block configuration form. |
| 356 |
*/ |
*/ |
| 357 |
function block_admin_configure($module = NULL, $delta = 0) { |
function block_admin_configure($module = NULL, $delta = 0) { |
|
$edit = $_POST['edit']; |
|
|
$op = $_POST['op']; |
|
|
|
|
|
switch ($op) { |
|
|
case t('Save block'): |
|
|
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(t('The block configuration has been saved.')); |
|
|
cache_clear_all(); |
|
|
drupal_goto('admin/block'); |
|
| 358 |
|
|
| 359 |
default: |
$form['module'] = array('#type' => 'value', '#value' => $module); |
| 360 |
// Always evaluates to TRUE, but a validation step may be added later. |
$form['delta'] = array('#type' => 'value', '#value' => $delta); |
|
if (!$edit) { |
|
|
$edit = db_fetch_array(db_query("SELECT pages, visibility, custom, types FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); |
|
|
} |
|
| 361 |
|
|
| 362 |
// Module-specific block configurations. |
$edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); |
|
if ($settings = module_invoke($module, 'block', 'configure', $delta)) { |
|
|
$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']))); |
|
| 363 |
|
|
| 364 |
// Standard block configurations. |
// Module-specific block configurations. |
| 365 |
$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.')); |
if ($settings = module_invoke($module, 'block', 'configure', $delta)) { |
| 366 |
$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.'))); |
$form['block_settings'] = array( |
| 367 |
$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.")); |
'#type' => 'fieldset', |
| 368 |
$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 feature 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); |
'#title' => t('Block specific settings'), |
| 369 |
|
'#collapsible' => TRUE, |
| 370 |
|
); |
| 371 |
|
|
| 372 |
$form .= form_group(t('User specific visibility settings'), $group_1); |
foreach ($settings as $k => $v) { |
| 373 |
$form .= form_group(t('Page specific visibility settings'), $group_2); |
$form['block_settings'][$k] = $v; |
| 374 |
$form .= form_group(t('Content specific visibility settings'), $group_3); |
} |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
// Get the block subject for the page title. |
| 378 |
|
$info = module_invoke($module, 'block', 'list'); |
| 379 |
|
drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); |
| 380 |
|
|
| 381 |
|
// Standard block configurations. |
| 382 |
|
|
| 383 |
|
$form['user_vis_settings'] = array( |
| 384 |
|
'#type' => 'fieldset', |
| 385 |
|
'#title' => t('User specific visibility settings'), |
| 386 |
|
'#collapsible' => TRUE, |
| 387 |
|
); |
| 388 |
|
$form['user_vis_settings']['custom'] = array( |
| 389 |
|
'#type' => 'radios', |
| 390 |
|
'#title' => t('Custom visibility settings'), |
| 391 |
|
'#options' => array( |
| 392 |
|
t('Users cannot control whether or not they see this block.'), |
| 393 |
|
t('Show this block by default, but let individual users hide it.'), |
| 394 |
|
t('Hide this block by default but let individual users show it.') |
| 395 |
|
), |
| 396 |
|
'#description' => t('Allow individual users to customize the visibility of this block in their account settings.'), |
| 397 |
|
'#default_value' => $edit['custom'], |
| 398 |
|
); |
| 399 |
|
|
| 400 |
|
// Role-based visibility settings |
| 401 |
|
$default_role_options = array(); |
| 402 |
|
$result = db_query("SELECT rid FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $module, $delta); |
| 403 |
|
while ($role = db_fetch_object($result)) { |
| 404 |
|
$default_role_options[] = $role->rid; |
| 405 |
|
} |
| 406 |
|
$result = db_query('SELECT rid, name FROM {role} ORDER BY name'); |
| 407 |
|
$role_options = array(); |
| 408 |
|
while ($role = db_fetch_object($result)) { |
| 409 |
|
$role_options[$role->rid] = $role->name; |
| 410 |
|
} |
| 411 |
|
$form['role_vis_settings'] = array( |
| 412 |
|
'#type' => 'fieldset', |
| 413 |
|
'#title' => t('Role specific visibility settings'), |
| 414 |
|
'#collapsible' => TRUE, |
| 415 |
|
); |
| 416 |
|
$form['role_vis_settings']['roles'] = array( |
| 417 |
|
'#type' => 'checkboxes', |
| 418 |
|
'#title' => t('Show block for specific roles'), |
| 419 |
|
'#default_value' => $default_role_options, |
| 420 |
|
'#options' => $role_options, |
| 421 |
|
'#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'), |
| 422 |
|
); |
| 423 |
|
|
| 424 |
|
$form['page_vis_settings'] = array( |
| 425 |
|
'#type' => 'fieldset', |
| 426 |
|
'#title' => t('Page specific visibility settings'), |
| 427 |
|
'#collapsible' => TRUE, |
| 428 |
|
); |
| 429 |
|
$access = user_access('use PHP for block visibility'); |
| 430 |
|
|
| 431 |
|
if ($edit['visibility'] == 2 && !$access) { |
| 432 |
|
$form['page_vis_settings'] = array(); |
| 433 |
|
$form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2); |
| 434 |
|
$form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']); |
| 435 |
|
} |
| 436 |
|
else { |
| 437 |
|
$options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); |
| 438 |
|
$description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'))); |
| 439 |
|
|
| 440 |
$form .= form_submit(t('Save block')); |
if ($access) { |
| 441 |
|
$options[] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).'); |
| 442 |
|
$description .= t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => theme('placeholder', '<?php ?>'))); |
| 443 |
|
} |
| 444 |
|
$form['page_vis_settings']['visibility'] = array( |
| 445 |
|
'#type' => 'radios', |
| 446 |
|
'#title' => t('Show block on specific pages'), |
| 447 |
|
'#options' => $options, |
| 448 |
|
'#default_value' => $edit['visibility'], |
| 449 |
|
); |
| 450 |
|
$form['page_vis_settings']['pages'] = array( |
| 451 |
|
'#type' => 'textarea', |
| 452 |
|
'#title' => t('Pages'), |
| 453 |
|
'#default_value' => $edit['pages'], |
| 454 |
|
'#description' => $description, |
| 455 |
|
); |
| 456 |
|
} |
| 457 |
|
|
| 458 |
|
$form['submit'] = array( |
| 459 |
|
'#type' => 'submit', |
| 460 |
|
'#value' => t('Save block'), |
| 461 |
|
); |
| 462 |
|
|
| 463 |
|
return drupal_get_form('block_admin_configure', $form); |
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
function block_admin_configure_validate($form_id, $form_values) { |
| 467 |
|
if ($form_values['module'] == 'block') { |
| 468 |
|
if (empty($form_values['info']) || db_num_rows(db_query("SELECT bid FROM {boxes} WHERE bid != %d AND info = '%s'", $form_values['delta'], $form_values['info']))) { |
| 469 |
|
form_set_error('info', t('Please ensure that each block description is unique.')); |
| 470 |
|
} |
| 471 |
|
} |
| 472 |
|
} |
| 473 |
|
|
| 474 |
print theme('page', form($form)); |
function block_admin_configure_submit($form_id, $form_values) { |
| 475 |
|
if (!form_get_errors()) { |
| 476 |
|
db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], $form_values['pages'], $form_values['custom'], $form_values['module'], $form_values['delta']); |
| 477 |
|
db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_values['module'], $form_values['delta']); |
| 478 |
|
foreach (array_filter($form_values['roles']) as $rid) { |
| 479 |
|
db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $form_values['delta']); |
| 480 |
|
} |
| 481 |
|
module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values); |
| 482 |
|
drupal_set_message(t('The block configuration has been saved.')); |
| 483 |
|
cache_clear_all(); |
| 484 |
|
return 'admin/block'; |
| 485 |
} |
} |
| 486 |
} |
} |
| 487 |
|
|
| 489 |
* Menu callback; displays the block creation form. |
* Menu callback; displays the block creation form. |
| 490 |
*/ |
*/ |
| 491 |
function block_box_add() { |
function block_box_add() { |
| 492 |
$edit = $_POST['edit']; |
$form = block_box_form(); |
| 493 |
$op = $_POST['op']; |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); |
| 494 |
|
|
| 495 |
switch ($op) { |
return drupal_get_form('block_box_add', $form); |
| 496 |
case t('Save block'): |
} |
|
block_box_save($edit); |
|
|
drupal_set_message(t('The new block has been added.')); |
|
|
drupal_goto('admin/block'); |
|
| 497 |
|
|
| 498 |
default: |
function block_box_add_validate($form_id, $form_values) { |
| 499 |
$form = block_box_form(); |
if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) { |
| 500 |
$form .= form_submit(t('Save block')); |
form_set_error('info', t('Please ensure that each block description is unique.')); |
|
$output .= form($form); |
|
| 501 |
} |
} |
| 502 |
|
} |
| 503 |
|
|
| 504 |
print theme('page', $output); |
function block_box_add_submit($form_id, $form_values) { |
| 505 |
|
if (!form_get_errors()) { |
| 506 |
|
if (block_box_save($form_values)) { |
| 507 |
|
drupal_set_message(t('The block has been created.')); |
| 508 |
|
return 'admin/block'; |
| 509 |
|
} |
| 510 |
|
} |
| 511 |
} |
} |
| 512 |
|
|
| 513 |
/** |
/** |
| 514 |
* Menu callback; confirm and delete custom blocks. |
* Menu callback; confirm deletion of custom blocks. |
| 515 |
*/ |
*/ |
| 516 |
function block_box_delete($bid = 0) { |
function block_box_delete($bid = 0) { |
|
$op = $_POST['op']; |
|
| 517 |
$box = block_box_get($bid); |
$box = block_box_get($bid); |
| 518 |
$info = $box['info'] ? $box['info'] : $box['title']; |
$form['info'] = array('#type' => 'hidden', '#value' => $box['info'] ? $box['info'] : $box['title']); |
| 519 |
|
$form['bid'] = array('#type' => 'hidden', '#value' => $bid); |
|
if ($_POST['edit']['confirm']) { |
|
|
db_query('DELETE FROM {boxes} WHERE bid = %d', $bid); |
|
|
drupal_set_message(t('The block %name has been deleted.', array('%name' => theme('placeholder', $info)))); |
|
|
cache_clear_all(); |
|
|
drupal_goto('admin/block'); |
|
|
} |
|
|
else { |
|
|
$output = theme('confirm', |
|
|
t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))), |
|
|
'admin/block', |
|
|
NULL, |
|
|
t('Delete')); |
|
|
} |
|
| 520 |
|
|
| 521 |
print theme('page', $output); |
return confirm_form('block_box_delete_confirm', $form, t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $box['info']))), 'admin/block', '', t('Delete'), t('Cancel')); |
| 522 |
} |
} |
| 523 |
|
|
| 524 |
|
/** |
| 525 |
|
* Deletion of custom blocks. |
| 526 |
|
*/ |
| 527 |
|
function block_box_delete_confirm_submit($form_id, $form_values) { |
| 528 |
|
db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']); |
| 529 |
|
drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info'])))); |
| 530 |
|
cache_clear_all(); |
| 531 |
|
return 'admin/block'; |
| 532 |
|
}; |
| 533 |
|
|
| 534 |
function block_box_form($edit = array()) { |
function block_box_form($edit = array()) { |
| 535 |
$output = form_textfield(t('Block title'), 'title', $edit['title'], 50, 64, t('The title of the block as shown to the user. Leave blank for no title.')); |
$form['info'] = array( |
| 536 |
$output .= filter_form('format', $edit['format']); |
'#type' => 'textfield', |
| 537 |
$output .= form_textarea(t('Block body'), 'body', $edit['body'], 70, 10, t('The content of the block as shown to the user.')); |
'#title' => t('Block description'), |
| 538 |
$output .= form_textfield(t('Block description'), 'info', $edit['info'], 50, 64, t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block')))); |
'#default_value' => $edit['info'], |
| 539 |
|
'#maxlength' => 64, |
| 540 |
|
'#description' => t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), |
| 541 |
|
'#required' => TRUE, |
| 542 |
|
'#weight' => -19, |
| 543 |
|
); |
| 544 |
|
$form['title'] = array( |
| 545 |
|
'#type' => 'textfield', |
| 546 |
|
'#title' => t('Block title'), |
| 547 |
|
'#default_value' => $edit['title'], |
| 548 |
|
'#maxlength' => 64, |
| 549 |
|
'#description' => t('The title of the block as shown to the user.'), |
| 550 |
|
'#weight' => -18, |
| 551 |
|
); |
| 552 |
|
$form['body_filter']['#weight'] = -17; |
| 553 |
|
$form['body_filter']['body'] = array( |
| 554 |
|
'#type' => 'textarea', |
| 555 |
|
'#title' => t('Block body'), |
| 556 |
|
'#default_value' => $edit['body'], |
| 557 |
|
'#rows' => 15, |
| 558 |
|
'#description' => t('The content of the block as shown to the user.'), |
| 559 |
|
'#weight' => -17, |
| 560 |
|
); |
| 561 |
|
$form['body_filter']['format'] = filter_form($edit['format'], -16); |
| 562 |
|
|
| 563 |
return $output; |
return $form; |
| 564 |
} |
} |
| 565 |
|
|
| 566 |
function block_box_save($edit, $delta = NULL) { |
function block_box_save($edit, $delta = NULL) { |
| 574 |
else { |
else { |
| 575 |
db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']); |
db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']); |
| 576 |
} |
} |
| 577 |
} |
return TRUE; |
|
|
|
|
/** |
|
|
* Menu callback; displays the block overview page. |
|
|
*/ |
|
|
function block_admin() { |
|
|
$edit = $_POST['edit']; |
|
|
$op = $_POST['op']; |
|
|
|
|
|
if ($op == t('Save blocks')) { |
|
|
drupal_set_message(block_admin_save($edit)); |
|
|
cache_clear_all(); |
|
|
drupal_goto($_GET['q']); |
|
|
} |
|
|
print theme('page', block_admin_display()); |
|
| 578 |
} |
} |
| 579 |
|
|
| 580 |
/** |
/** |
| 584 |
* the site. |
* the site. |
| 585 |
*/ |
*/ |
| 586 |
function block_user($type, $edit, &$user, $category = NULL) { |
function block_user($type, $edit, &$user, $category = NULL) { |
| 587 |
|
global $user; |
| 588 |
switch ($type) { |
switch ($type) { |
| 589 |
case 'form': |
case 'form': |
| 590 |
if ($category == 'account') { |
if ($category == 'account') { |
| 591 |
$result = db_query('SELECT * FROM {blocks} WHERE status = 1 AND custom != 0 ORDER BY weight, module, delta'); |
$result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.weight, b.module", implode(',', array_keys($user->roles))); |
| 592 |
|
$form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE); |
| 593 |
while ($block = db_fetch_object($result)) { |
while ($block = db_fetch_object($result)) { |
| 594 |
$data = module_invoke($block->module, 'block', 'list'); |
$data = module_invoke($block->module, 'block', 'list'); |
| 595 |
if ($data[$block->delta]['info']) { |
if ($data[$block->delta]['info']) { |
| 596 |
$form .= form_checkbox($data[$block->delta]['info'], 'block]['. $block->module .']['. $block->delta, 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1)); |
$return = TRUE; |
| 597 |
|
$form['block'][$block->module][$block->delta] = array('#type' => 'checkbox', '#title' => $data[$block->delta]['info'], '#default_value' => isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1)); |
| 598 |
} |
} |
| 599 |
} |
} |
| 600 |
|
|
| 601 |
if (isset($form)) { |
if ($return) { |
| 602 |
return array(array('title' => t('Block configuration'), 'data' => $form, 'weight' => 2)); |
return $form; |
| 603 |
} |
} |
| 604 |
} |
} |
| 605 |
|
|
| 612 |
} |
} |
| 613 |
} |
} |
| 614 |
|
|
| 615 |
/** |
/** |
| 616 |
* Return all blocks in the specied region for the current user. You may |
* Return all blocks in the specified region for the current user. |
| 617 |
* use this function to implement variable block regions. The default |
* |
| 618 |
* regions are 'left', 'right' and 'all', where 'all' means both left and |
* @param $region |
| 619 |
* right. |
* The name of a region. |
| 620 |
* |
* |
| 621 |
* @param $region |
* @return |
| 622 |
* This is a string which describes in a human readable form which region |
* An array of block objects, indexed with <i>module</i>_<i>delta</i>. |
| 623 |
* you need. |
* If you are displaying your blocks in one or two sidebars, you may check |
| 624 |
* |
* whether this array is empty to see how many columns are going to be |
| 625 |
* @param $regions |
* displayed. |
| 626 |
* This is an optional array and contains map(s) from the string $region to |
* |
| 627 |
* the numerical region value(s) in the blocks table. See default value for |
* @todo |
| 628 |
* examples. |
* Add a proper primary key (bid) to the blocks table so we don't have |
| 629 |
* |
* to mess around with this <i>module</i>_<i>delta</i> construct. |
| 630 |
* @return |
* Currently, the blocks table has no primary key defined! |
| 631 |
* An array of block objects, indexed with <i>module</i>_<i>delta</i>. |
*/ |
| 632 |
* If you are displaying your blocks in one or two sidebars, you may check |
function block_list($region) { |
| 633 |
* whether this array is empty to see how many columns are going to be |
global $user, $theme_key; |
| 634 |
* displayed. |
|
|
* |
|
|
* @todo |
|
|
* Add a proper primary key (bid) to the blocks table so we don't have |
|
|
* to mess around with this <i>module</i>_<i>delta</i> construct. |
|
|
* Currently, the blocks table has no primary key defined! |
|
|
*/ |
|
|
function block_list($region, $regions = array('left' => 0, 'right' => 1, 'all' => '0, 1')) { |
|
|
global $user; |
|
| 635 |
static $blocks = array(); |
static $blocks = array(); |
| 636 |
|
|
| 637 |
if (!isset($blocks[$region])) { |
if (!count($blocks)) { |
| 638 |
$blocks[$region] = array(); |
$result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", $theme_key, implode(',', array_keys($user->roles))); |
| 639 |
$result = db_query("SELECT * FROM {blocks} WHERE status = 1 AND region IN (%s) ORDER BY weight, module", $regions[$region]); |
while ($block = db_fetch_object($result)) { |
| 640 |
while ($block = db_fetch_array($result)) { |
if (!isset($blocks[$block->region])) { |
| 641 |
|
$blocks[$block->region] = array(); |
| 642 |
|
} |
| 643 |
// Use the user's block visibility setting, if necessary |
// Use the user's block visibility setting, if necessary |
| 644 |
if ($block['custom'] != 0) { |
if ($block->custom != 0) { |
| 645 |
if ($user->uid && isset($user->block[$block['module']][$block['delta']])) { |
if ($user->uid && isset($user->block[$block->module][$block->delta])) { |
| 646 |
$enabled = $user->block[$block['module']][$block['delta']]; |
$enabled = $user->block[$block->module][$block->delta]; |
| 647 |
} |
} |
| 648 |
else { |
else { |
| 649 |
$enabled = ($block['custom'] == 1); |
$enabled = ($block->custom == 1); |
| 650 |
} |
} |
| 651 |
} |
} |
| 652 |
else { |
else { |
| 654 |
} |
} |
| 655 |
|
|
| 656 |
// Match path if necessary |
// Match path if necessary |
| 657 |
if ($block['pages']) { |
if ($block->pages) { |
| 658 |
$path = drupal_get_path_alias($_GET['q']); |
if ($block->visibility < 2) { |
| 659 |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block['pages'], '/')) .')$/'; |
$path = drupal_get_path_alias($_GET['q']); |
| 660 |
$page_match = !($block['visibility'] xor preg_match($regexp, $path)); |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/'; |
| 661 |
} |
$page_match = !($block->visibility xor preg_match($regexp, $path)); |
| 662 |
else { |
} |
| 663 |
$page_match = TRUE; |
else { |
| 664 |
} |
$page_match = drupal_eval($block->pages); |
|
// 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; |
|
|
} |
|
|
} |
|
| 665 |
} |
} |
| 666 |
} |
} |
| 667 |
else { |
else { |
| 668 |
$type_match = TRUE; |
$page_match = TRUE; |
| 669 |
} |
} |
| 670 |
|
|
| 671 |
if ($enabled && $page_match && $type_match) { |
if ($enabled && $page_match) { |
| 672 |
// Check the current throttle status and see if block should be displayed |
// Check the current throttle status and see if block should be displayed |
| 673 |
// based on server load. |
// based on server load. |
| 674 |
if (!($block['throttle'] && (module_invoke('throttle', 'status') > 0))) { |
if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) { |
| 675 |
$array = module_invoke($block['module'], 'block', 'view', $block['delta']); |
$array = module_invoke($block->module, 'block', 'view', $block->delta); |
| 676 |
if (is_array($array)) { |
if (isset($array) && is_array($array)) { |
| 677 |
$block = array_merge($block, $array); |
foreach ($array as $k => $v) { |
| 678 |
|
$block->$k = $v; |
| 679 |
|
} |
| 680 |
} |
} |
| 681 |
} |
} |
| 682 |
if (isset($block['content']) && $block['content']) { |
if (isset($block->content) && $block->content) { |
| 683 |
$blocks[$region]["$block[module]_$block[delta]"] = (object) $block; |
$blocks[$block->region]["{$block->module}_{$block->delta}"] = $block; |
| 684 |
} |
} |
| 685 |
} |
} |
| 686 |
} |
} |
| 687 |
} |
} |
| 688 |
|
// Create an empty array if there were no entries |
| 689 |
|
if (!isset($blocks[$region])) { |
| 690 |
|
$blocks[$region] = array(); |
| 691 |
|
} |
| 692 |
return $blocks[$region]; |
return $blocks[$region]; |
| 693 |
} |
} |
|
|
|
|
?> |
|