Code coverage for /20081101/modules/block/block.module

Line #Times calledCode
1
<?php
2
// $Id: block.module,v 1.312 2008/10/09 15:15:50 webchick Exp $
3
4
/**
5
 * @file
6
 * Controls the boxes that are displayed around the main content.
7
 */
8
9
/**
10
 * Denotes that a block is not enabled in any region and should not be
shown.
11
 */
122366
define('BLOCK_REGION_NONE', -1);
13
14
/**
15
 * Constants defining cache granularity for blocks.
16
 *
17
 * Modules specify the caching patterns for their blocks using binary
18
 * combinations of these constants in their hook_block(op 'list'):
19
 *   $block[delta]['cache'] = BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE;
20
 * BLOCK_CACHE_PER_ROLE is used as a default when no caching pattern is
21
 * specified.
22
 *
23
 * The block cache is cleared in cache_clear_all(), and uses the same
clearing
24
 * policy than page cache (node, comment, user, taxonomy added or
updated...).
25
 * Blocks requiring more fine-grained clearing might consider disabling the
26
 * built-in block cache (BLOCK_NO_CACHE) and roll their own.
27
 *
28
 * Note that user 1 is excluded from block caching.
29
 */
30
31
/**
32
 * The block should not get cached. This setting should be used:
33
 * - for simple blocks (notably those that do not perform any db query),
34
 * where querying the db cache would be more expensive than directly
generating
35
 * the content.
36
 * - for blocks that change too frequently.
37
 */
382366
define('BLOCK_NO_CACHE', -1);
39
40
/**
41
 * The block can change depending on the roles the user viewing the page
belongs to.
42
 * This is the default setting, used when the block does not specify
anything.
43
 */
442366
define('BLOCK_CACHE_PER_ROLE', 0x0001);
45
46
/**
47
 * The block can change depending on the user viewing the page.
48
 * This setting can be resource-consuming for sites with large number of
users,
49
 * and thus should only be used when BLOCK_CACHE_PER_ROLE is not
sufficient.
50
 */
512366
define('BLOCK_CACHE_PER_USER', 0x0002);
52
53
/**
54
 * The block can change depending on the page being viewed.
55
 */
562366
define('BLOCK_CACHE_PER_PAGE', 0x0004);
57
58
/**
59
 * The block is the same for every user on every page where it is visible.
60
 */
612366
define('BLOCK_CACHE_GLOBAL', 0x0008);
62
63
/**
64
 * Implementation of hook_help().
65
 */
662366
function block_help($path, $arg) {
67
  switch ($path) {
681676
    case 'admin/help#block':
6927
      $output = '<p>' . t('Blocks are boxes of content rendered into an
area, or region, of a web page. The default theme Garland, for example,
implements the regions "left sidebar", "right sidebar", "content",
"header", and "footer", and a block may appear in any one of these areas.
The <a href="@blocks">blocks administration page</a> provides a
drag-and-drop interface for assigning a block to a region, and for
controlling the order of blocks within regions.', array('@blocks' =>
url('admin/build/block'))) . '</p>';
7027
      $output .= '<p>' . t('Although blocks are usually generated
automatically by modules (like the <em>User login</em> block, for example),
administrators can also define custom blocks. Custom blocks have a title,
description, and body. The body of the block can be as long as necessary,
and can contain content supported by any available <a
href="@input-format">input format</a>.', array('@input-format' =>
url('admin/settings/filters'))) . '</p>';
7127
      $output .= '<p>' . t('When working with blocks, remember that:') .
'</p>';
7227
      $output .= '<ul><li>' . t('since not all themes implement the same
regions, or display regions in the same way, blocks are positioned on a
per-theme basis.') . '</li>';
7327
      $output .= '<li>' . t('disabled blocks, or blocks not in a region,
are never shown.') . '</li>';
7427
      $output .= '<li>' . t('blocks can be configured to be visible only on
certain pages.') . '</li>';
7527
      $output .= '<li>' . t('blocks can be configured to be visible only
when specific conditions are true.') . '</li>';
7627
      $output .= '<li>' . t('blocks can be configured to be visible only
for certain user roles.') . '</li>';
7727
      $output .= '<li>' . t('when allowed by an administrator, specific
blocks may be enabled or disabled on a per-user basis using the <em>My
account</em> page.') . '</li>';
7827
      $output .= '<li>' . t('some dynamic blocks, such as those generated
by modules, will be displayed only on certain pages.') . '</li></ul>';
7927
      $output .= '<p>' . t('For more information, see the online handbook
entry for <a href="@block">Block module</a>.', array('@block' =>
'http://drupal.org/handbook/modules/block/')) . '</p>';
8027
      return $output;
811676
    case 'admin/build/block':
8220
      $output = '<p>' . t('This page provides a drag-and-drop interface for
assigning a block to a region, and for controlling the order of blocks
within regions. To change the region or order of a block, grab a
drag-and-drop handle under the <em>Block</em> column and drag the block to
a new location in the list. (Grab a handle by clicking and holding the
mouse while hovering over a handle icon.) Since not all themes implement
the same regions, or display regions in the same way, blocks are positioned
on a per-theme basis. Remember that your changes will not be saved until
you click the <em>Save blocks</em> button at the bottom of the page.') .
'</p>';
8320
      $output .= '<p>' . t('Click the <em>configure</em> link next to each
block to configure its specific title and visibility settings. Use the <a
href="@add-block">add block page</a> to create a custom block.',
array('@add-block' => url('admin/build/block/add'))) . '</p>';
8420
      return $output;
851656
    case 'admin/build/block/add':
861
      return '<p>' . t('Use this page to create a new custom block. New
blocks are disabled by default, and must be moved to a region on the <a
href="@blocks">blocks administration page</a> to be visible.',
array('@blocks' => url('admin/build/block'))) . '</p>';
870
  }
881655
}
89
90
/**
91
 * Implementation of hook_theme().
92
 */
932366
function block_theme() {
94
  return array(
95
    'block_admin_display_form' => array(
96178
      'template' => 'block-admin-display-form',
97178
      'file' => 'block.admin.inc',
98178
      'arguments' => array('form' => NULL),
99178
    ),
100178
  );
1010
}
102
103
/**
104
 * Implementation of hook_perm().
105
 */
1062366
function block_perm() {
107
  return array(
108
    'administer blocks' => array(
109172
      'title' => t('Administer blocks'),
110172
      'description' => t('Select which blocks are displayed, and arrange
them on the page.'),
111172
    ),
112
    'use PHP for block visibility' => array(
113172
      'title' => t('Use PHP for block visibility'),
114172
      'description' => t('Enter PHP code in the field for block visibility
settings. %warning', array('%warning' => t('Warning: Give to trusted roles
only; this permission has security implications.'))),
115172
    ),
116172
  );
1170
}
118
119
/**
120
 * Implementation of hook_menu().
121
 */
1222366
function block_menu() {
123161
  $items['admin/build/block'] = array(
124161
    'title' => 'Blocks',
125161
    'description' => 'Configure what block content appears in your site\'s
sidebars and other regions.',
126161
    'page callback' => 'block_admin_display',
127161
    'access arguments' => array('administer blocks'),
128
  );
129161
  $items['admin/build/block/list'] = array(
130161
    'title' => 'List',
131161
    'type' => MENU_DEFAULT_LOCAL_TASK,
132161
    'weight' => -10,
133
  );
134161
  $items['admin/build/block/list/js'] = array(
135161
    'title' => 'JavaScript List Form',
136161
    'page callback' => 'block_admin_display_js',
137161
    'access arguments' => array('administer blocks'),
138161
    'type' => MENU_CALLBACK,
139
  );
140161
  $items['admin/build/block/configure'] = array(
141161
    'title' => 'Configure block',
142161
    'page callback' => 'drupal_get_form',
143161
    'page arguments' => array('block_admin_configure'),
144161
    'access arguments' => array('administer blocks'),
145161
    'type' => MENU_CALLBACK,
146
  );
147161
  $items['admin/build/block/delete'] = array(
148161
    'title' => 'Delete block',
149161
    'page callback' => 'drupal_get_form',
150161
    'page arguments' => array('block_box_delete'),
151161
    'access arguments' => array('administer blocks'),
152161
    'type' => MENU_CALLBACK,
153
  );
154161
  $items['admin/build/block/add'] = array(
155161
    'title' => 'Add block',
156161
    'page callback' => 'drupal_get_form',
157161
    'page arguments' => array('block_add_block_form'),
158161
    'access arguments' => array('administer blocks'),
159161
    'type' => MENU_LOCAL_TASK,
160
  );
161161
  $default = variable_get('theme_default', 'garland');
162161
  foreach (list_themes() as $key => $theme) {
163161
    $items['admin/build/block/list/' . $key] = array(
164161
      'title' => check_plain($theme->info['name']),
165161
      'page arguments' => array($key),
166161
      'type' => $key == $default ? MENU_DEFAULT_LOCAL_TASK :
MENU_LOCAL_TASK,
167161
      'weight' => $key == $default ? -10 : 0,
168161
      'access callback' => '_block_themes_access',
169161
      'access arguments' => array($theme),
170
    );
171161
  }
172161
  return $items;
1730
}
174
175
/**
176
 * Menu item access callback - only admin or enabled themes can be
accessed.
177
 */
1782366
function _block_themes_access($theme) {
17922
  return user_access('administer blocks') && ($theme->status ||
$theme->name == variable_get('admin_theme', '0'));
1800
}
181
182
/**
183
 * Implementation of hook_block().
184
 *
185
 * Generates the administrator-defined blocks for display.
186
 */
1872366
function block_block($op = 'list', $delta = 0, $edit = array()) {
188
  switch ($op) {
18932
    case 'list':
19031
      $blocks = array();
191
19231
      $result = db_query('SELECT bid, info FROM {boxes} ORDER BY info');
19331
      while ($block = db_fetch_object($result)) {
1944
        $blocks[$block->bid]['info'] = $block->info;
195
        // Not worth caching.
1964
        $blocks[$block->bid]['cache'] = BLOCK_NO_CACHE;
1974
      }
19831
      return $blocks;
199
2004
    case 'configure':
2012
      $box = array('format' => FILTER_FORMAT_DEFAULT);
2022
      if ($delta) {
2030
        $box = block_box_get($delta);
2040
      }
2052
      if (filter_access($box['format'])) {
2062
        return block_box_form($box);
2070
      }
2080
      break;
209
2102
    case 'save':
2110
      block_box_save($edit, $delta);
2120
      break;
213
2142
    case 'view':
2152
      $block = db_fetch_object(db_query('SELECT body, format FROM {boxes}
WHERE bid = %d', $delta));
2162
      $data['content'] = check_markup($block->body, $block->format, FALSE);
2172
      return $data;
2180
  }
2190
}
220
221
/**
222
 * Update the 'blocks' DB table with the blocks currently exported by
modules.
223
 *
224
 * @return
225
 *   Blocks currently exported by modules.
226
 */
2272366
function _block_rehash() {
22829
  global $theme_key;
229
23029
  init_theme();
231
23229
  $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'",
$theme_key);
23329
  $old_blocks = array();
23429
  while ($old_block = db_fetch_array($result)) {
23529
    $old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
23629
  }
237
23829
  $blocks = array();
239
  // Valid region names for the theme.
24029
  $regions = system_region_list($theme_key);
241
24229
  foreach (module_list() as $module) {
24329
    $module_blocks = module_invoke($module, 'block', 'list');
24429
    if ($module_blocks) {
24529
      foreach ($module_blocks as $delta => $block) {
24629
        if (empty($old_blocks[$module][$delta])) {
247
          // If it's a new block, add identifiers.
2486
          $block['module'] = $module;
2496
          $block['delta']  = $delta;
2506
          $block['theme']  = $theme_key;
2516
          if (!isset($block['pages'])) {
252
            // {block}.pages is type 'text', so it cannot have a
253
            // default value, and not null, so we need to provide
254
            // value if the module did not.
2556
            $block['pages']  = '';
2566
          }
257
          // Add defaults and save it into the database.
2586
          drupal_write_record('blocks', $block);
259
          // Set region to none if not enabled.
2606
          $block['region'] = $block['status'] ? $block['region'] :
BLOCK_REGION_NONE;
261
          // Add to the list of blocks we return.
2626
          $blocks[] = $block;
2636
        }
264
        else {
265
          // If it's an existing block, database settings should overwrite
266
          // the code. But aside from 'info' everything that's definable in
267
          // code is stored in the database and we do not store 'info', so
we
268
          // do not need to update the database here.
269
          // Add 'info' to this block.
27029
          $old_blocks[$module][$delta]['info'] = $block['info'];
271
          // If the region name does not exist, disable the block and
assign it to none.
27229
          if (!empty($old_blocks[$module][$delta]['region']) &&
!isset($regions[$old_blocks[$module][$delta]['region']])) {
2730
            drupal_set_message(t('The block %info was assigned to the
invalid region %region and has been disabled.', array('%info' =>
$old_blocks[$module][$delta]['info'], '%region' =>
$old_blocks[$module][$delta]['region'])), 'warning');
2740
            $old_blocks[$module][$delta]['status'] = 0;
2750
            $old_blocks[$module][$delta]['region'] = BLOCK_REGION_NONE;
2760
          }
277
          else {
27829
            $old_blocks[$module][$delta]['region'] =
$old_blocks[$module][$delta]['status'] ?
$old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
279
          }
280
          // Add this block to the list of blocks we return.
28129
          $blocks[] = $old_blocks[$module][$delta];
282
          // Remove this block from the list of blocks to be deleted.
28329
          unset($old_blocks[$module][$delta]);
284
        }
28529
      }
28629
    }
28729
  }
288
289
  // Remove blocks that are no longer defined by the code from the
database.
29029
  foreach ($old_blocks as $module => $old_module_blocks) {
29129
    foreach ($old_module_blocks as $delta => $block) {
2920
      db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'
AND theme = '%s'", $module, $delta, $theme_key);
2930
    }
29429
  }
29529
  return $blocks;
2960
}
297
2982366
function block_box_get($bid) {
2992
  return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d",
$bid));
3000
}
301
302
/**
303
 * Define the custom block form.
304
 */
3052366
function block_box_form($edit = array()) {
306
  $edit += array(
3072
    'info' => '',
3082
    'body' => '',
3090
  );
3102
  $form['info'] = array(
3112
    '#type' => 'textfield',
3122
    '#title' => t('Block description'),
3132
    '#default_value' => $edit['info'],
3142
    '#maxlength' => 64,
3152
    '#description' => t('A brief description of your block. Used on the <a
href="@overview">block overview page</a>.', array('@overview' =>
url('admin/build/block'))),
3162
    '#required' => TRUE,
3172
    '#weight' => -19,
318
  );
3192
  $form['body_field']['#weight'] = -17;
3202
  $form['body_field']['body'] = array(
3212
    '#type' => 'textarea',
3222
    '#title' => t('Block body'),
3232
    '#default_value' => $edit['body'],
3242
    '#input_format' => isset($edit['format']) ? $edit['format'] :
FILTER_FORMAT_DEFAULT,
3252
    '#rows' => 15,
3262
    '#description' => t('The content of the block as shown to the user.'),
3272
    '#weight' => -17,
328
  );
329
3302
  return $form;
3310
}
332
3332366
function block_box_save($edit, $delta) {
3340
  if (!filter_access($edit['body_format'])) {
3350
    $edit['body_format'] = FILTER_FORMAT_DEFAULT;
3360
  }
337
3380
  db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE
bid = %d", $edit['body'], $edit['info'], $edit['body_format'], $delta);
339
3400
  return TRUE;
3410
}
342
343
/**
344
 * Implementation of hook_user_form().
345
 */
3462366
function block_user_form(&$edit, &$account, $category = NULL) {
34758
  if ($category == 'account') {
34815
    $rids = array_keys($account->roles);
34915
    $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 (" . db_placeholders($rids) .
") OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids);
35015
    $form['block'] = array('#type' => 'fieldset', '#title' => t('Block
configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE);
35115
    while ($block = db_fetch_object($result)) {
3520
      $data = module_invoke($block->module, 'block', 'list');
3530
      if ($data[$block->delta]['info']) {
3540
        $return = TRUE;
3550
        $form['block'][$block->module][$block->delta] = array('#type' =>
'checkbox', '#title' => check_plain($data[$block->delta]['info']),
'#default_value' => isset($account->block[$block->module][$block->delta]) ?
$account->block[$block->module][$block->delta] : ($block->custom == 1));
3560
      }
3570
    }
358
35915
    if (!empty($return)) {
3600
      return $form;
3610
    }
36215
  }
36358
}
364
365
/**
366
 * Implementation of hook_user_validate().
367
 */
3682366
function block_user_validate(&$edit, &$account, $category = NULL) {
36915
  if (empty($edit['block'])) {
37015
    $edit['block'] = array();
37115
  }
37215
  return $edit;
3730
}
374
375
/**
376
 * Return all blocks in the specified region for the current user.
377
 *
378
 * @param $region
379
 *   The name of a region.
380
 *
381
 * @return
382
 *   An array of block objects, indexed with <i>module</i>_<i>delta</i>.
383
 *   If you are displaying your blocks in one or two sidebars, you may
check
384
 *   whether this array is empty to see how many columns are going to be
385
 *   displayed.
386
 *
387
 * @todo
388
 *   Now that the blocks table has a primary key, we should use that as the
389
 *   array key instead of <i>module</i>_<i>delta</i>.
390
 */
3912366
function block_list($region) {
3921740
  static $blocks = array();
393
3941740
  if (!count($blocks)) {
3951740
    $blocks = _block_load_blocks();
3961740
  }
397
398
  // Create an empty array if there were no entries.
3991740
  if (!isset($blocks[$region])) {
4001740
    $blocks[$region] = array();
4011740
  }
402
4031740
  $blocks[$region] = _block_render_blocks($blocks[$region]);
404
4051740
  return $blocks[$region];
4060
}
407
408
/**
409
 * Load blocks information from the database.
410
 */
4112366
function _block_load_blocks() {
4121740
  global $user, $theme_key;
413
4141740
  $blocks = array();
4151740
  $rids = array_keys($user->roles);
4161740
  $result = db_query(db_rewrite_sql("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 (" .
db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.region, b.weight,
b.module", 'b', 'bid'), array_merge(array($theme_key), $rids));
4171740
  while ($block = db_fetch_object($result)) {
4181740
    if (!isset($blocks[$block->region])) {
4191740
      $blocks[$block->region] = array();
4201740
    }
421
    // Use the user's block visibility setting, if necessary.
4221740
    if ($block->custom != 0) {
4230
      if ($user->uid && isset($user->block[$block->module][$block->delta]))
{
4240
        $enabled = $user->block[$block->module][$block->delta];
4250
      }
426
      else {
4270
        $enabled = ($block->custom == 1);
428
      }
4290
    }
430
    else {
4311740
      $enabled = TRUE;
432
    }
433
434
    // Match path if necessary.
4351740
    if ($block->pages) {
4360
      if ($block->visibility < 2) {
4370
        $path = drupal_get_path_alias($_GET['q']);
438
        // Compare with the internal and path alias (if any).
4390
        $page_match = drupal_match_path($path, $block->pages);
4400
        if ($path != $_GET['q']) {
4410
          $page_match = $page_match || drupal_match_path($_GET['q'],
$block->pages);
4420
        }
443
        // When $block->visibility has a value of 0, the block is displayed
on
444
        // all pages except those listed in $block->pages. When set to 1,
it
445
        // is displayed only on those pages listed in $block->pages.
4460
        $page_match = !($block->visibility xor $page_match);
4470
      }
448
      else {
4490
        $page_match = drupal_eval($block->pages);
450
      }
4510
    }
452
    else {
4531740
      $page_match = TRUE;
454
    }
4551740
    $block->enabled = $enabled;
4561740
    $block->page_match = $page_match;
4571740
    $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block;
4581740
  }
459
4601740
  return $blocks;
4610
}
462
463
/**
464
 * Render the content and subject for a set of blocks.
465
 *
466
 * @param $region_blocks
467
 *   An array of block objects such as returned for one region by
_block_load_blocks().
468
 *
469
 * @return
470
 *   An array of visible blocks with subject and content rendered.
471
 */
4722366
function _block_render_blocks($region_blocks) {
4731740
  foreach ($region_blocks as $key => $block) {
474
    // Render the block content if it has not been created already.
4751740
    if (!isset($block->content)) {
476
      // Erase the block from the static array - we'll put it back if it
has content.
4771740
      unset($region_blocks[$key]);
4781740
      if ($block->enabled && $block->page_match) {
479
        // Try fetching the block from cache. Block caching is not
compatible with
480
        // node_access modules. We also preserve the submission of forms in
blocks,
481
        // by fetching from cache only if the request method is 'GET' (or
'HEAD').
4821740
        if (!count(module_implements('node_grants')) &&
($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] ==
'HEAD') && ($cid = _block_get_cache_id($block)) && ($cache =
cache_get($cid, 'cache_block'))) {
4830
          $array = $cache->data;
4840
        }
485
        else {
4861740
          $array = module_invoke($block->module, 'block', 'view',
$block->delta);
4871740
          if (isset($cid)) {
4880
            cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
4890
          }
490
        }
491
4921740
        if (isset($array) && is_array($array)) {
4931740
          foreach ($array as $k => $v) {
4941740
            $block->$k = $v;
4951740
          }
4961740
        }
4971740
        if (isset($block->content) && $block->content) {
498
          // Override default block title if a custom display title is
present.
4991740
          if ($block->title) {
500
            // Check plain here to allow module generated titles to keep
any markup.
5019
            $block->subject = $block->title == '<none>' ? '' :
check_plain($block->title);
5029
          }
5031740
          if (!isset($block->subject)) {
5041740
            $block->subject = '';
5051740
          }
5061740
          $region_blocks["{$block->module}_{$block->delta}"] = $block;
5071740
        }
5081740
      }
5091740
    }
5101740
  }
5111740
  return $region_blocks;
5120
}
513
514
/**
515
 * Assemble the cache_id to use for a given block.
516
 *
517
 * The cache_id string reflects the viewing context for the current block
518
 * instance, obtained by concatenating the relevant context information
519
 * (user, page, ...) according to the block's cache settings (BLOCK_CACHE_*
520
 * constants). Two block instances can use the same cached content when
521
 * they share the same cache_id.
522
 *
523
 * Theme and language contexts are automatically differenciated.
524
 *
525
 * @param $block
526
 * @return
527
 *   The string used as cache_id for the block.
528
 */
5292366
function _block_get_cache_id($block) {
5301670
  global $theme, $base_root, $user;
531
532
  // User 1 being out of the regular 'roles define permissions' schema,
533
  // it brings too many chances of having unwanted output get in the cache
534
  // and later be served to other users. We therefore exclude user 1 from
535
  // block caching.
5361670
  if (variable_get('block_cache', 0) && $block->cache != BLOCK_NO_CACHE &&
$user->uid != 1) {
5370
    $cid_parts = array();
538
539
    // Start with common sub-patterns: block identification, theme,
language.
5400
    $cid_parts[] = $block->module;
5410
    $cid_parts[] = $block->delta;
5420
    $cid_parts[] = $theme;
5430
    if (module_exists('locale')) {
5440
      global $language;
5450
      $cid_parts[] = $language->language;
5460
    }
547
548
    // 'PER_ROLE' and 'PER_USER' are mutually exclusive. 'PER_USER' can be
a
549
    // resource drag for sites with many users, so when a module is being
550
    // equivocal, we favor the less expensive 'PER_ROLE' pattern.
5510
    if ($block->cache & BLOCK_CACHE_PER_ROLE) {
5520
      $cid_parts[] = 'r.' . implode(',', array_keys($user->roles));
5530
    }
5540
    elseif ($block->cache & BLOCK_CACHE_PER_USER) {
5550
      $cid_parts[] = "u.$user->uid";
5560
    }
557
5580
    if ($block->cache & BLOCK_CACHE_PER_PAGE) {
5590
      $cid_parts[] = $base_root . request_uri();
5600
    }
561
5620
    return implode(':', $cid_parts);
5630
  }
5641670
}
5652366