web/drupal/modules/block/block.module
author cavaliet@caf4f556-3d62-0410-8435-a86758001935
Fri, 21 Aug 2009 16:26:26 +0000
branchdrupal
changeset 74 0ff3ba646492
permissions -rw-r--r--
Create branch for drupal with first commit from local working copy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     1
<?php
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     2
// $Id: block.module,v 1.299.2.3 2008/06/24 14:40:08 goba Exp $
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     3
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     4
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     5
 * @file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     6
 * Controls the boxes that are displayed around the main content.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     7
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     8
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     9
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    10
 * Denotes that a block is not enabled in any region and should not
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    11
 * be shown.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    12
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    13
define('BLOCK_REGION_NONE', -1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    14
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    15
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    16
 * Constants defining cache granularity for blocks.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    17
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    18
 * Modules specify the caching patterns for their blocks using binary
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    19
 * combinations of these constants in their hook_block(op 'list'):
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    20
 *   $block[delta]['cache'] = BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    21
 * BLOCK_CACHE_PER_ROLE is used as a default when no caching pattern is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    22
 * specified.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    23
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    24
 * The block cache is cleared in cache_clear_all(), and uses the same clearing
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    25
 * policy than page cache (node, comment, user, taxonomy added or updated...).
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    26
 * Blocks requiring more fine-grained clearing might consider disabling the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    27
 * built-in block cache (BLOCK_NO_CACHE) and roll their own.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    28
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    29
 * Note that user 1 is excluded from block caching.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    30
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    31
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    32
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    33
 * The block should not get cached. This setting should be used:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    34
 * - for simple blocks (notably those that do not perform any db query),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    35
 * where querying the db cache would be more expensive than directly generating
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    36
 * the content.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    37
 * - for blocks that change too frequently.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    38
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    39
define('BLOCK_NO_CACHE', -1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    40
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    41
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    42
 * The block can change depending on the roles the user viewing the page belongs to.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    43
 * This is the default setting, used when the block does not specify anything.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    44
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    45
define('BLOCK_CACHE_PER_ROLE', 0x0001);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    46
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    47
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    48
 * The block can change depending on the user viewing the page.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    49
 * This setting can be resource-consuming for sites with large number of users,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    50
 * and thus should only be used when BLOCK_CACHE_PER_ROLE is not sufficient.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    51
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    52
define('BLOCK_CACHE_PER_USER', 0x0002);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    53
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    54
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    55
 * The block can change depending on the page being viewed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    56
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    57
define('BLOCK_CACHE_PER_PAGE', 0x0004);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    58
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    59
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    60
 * The block is the same for every user on every page where it is visible.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    61
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    62
define('BLOCK_CACHE_GLOBAL', 0x0008);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    63
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    64
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    65
 * Implementation of hook_help().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    66
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    67
function block_help($path, $arg) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    68
  switch ($path) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    69
    case 'admin/help#block':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    70
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    71
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    72
      $output .= '<p>'. t('When working with blocks, remember that:') .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    73
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    74
      $output .= '<li>'. t('disabled blocks, or blocks not in a region, are never shown.') .'</li>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    75
      $output .= '<li>'. t('when throttle module is enabled, throttled blocks (blocks with the <em>Throttle</em> checkbox selected) are hidden during high server loads.') .'</li>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    76
      $output .= '<li>'. t('blocks can be configured to be visible only on certain pages.') .'</li>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    77
      $output .= '<li>'. t('blocks can be configured to be visible only when specific conditions are true.') .'</li>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    78
      $output .= '<li>'. t('blocks can be configured to be visible only for certain user roles.') .'</li>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    79
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    80
      $output .= '<li>'. t('some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.') .'</li></ul>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    81
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    82
      return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    83
    case 'admin/build/block':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    84
      $throttle = module_exists('throttle');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    85
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    86
      if ($throttle) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    87
        $output .= '<p>'. t('To reduce CPU usage, database traffic or bandwidth, blocks may be automatically disabled during high server loads by selecting their <em>Throttle</em> checkbox. Adjust throttle thresholds on the <a href="@throttleconfig">throttle configuration page</a>.', array('@throttleconfig' => url('admin/settings/throttle'))) .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    88
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    89
      $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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    90
      return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    91
    case 'admin/build/block/add':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    92
      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>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    93
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    94
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    95
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    96
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    97
 * Implementation of hook_theme()
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    98
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    99
function block_theme() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   100
  return array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   101
    'block_admin_display_form' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   102
      'template' => 'block-admin-display-form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   103
      'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   104
      'arguments' => array('form' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   105
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   106
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   107
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   108
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   109
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   110
 * Implementation of hook_perm().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   111
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   112
function block_perm() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   113
  return array('administer blocks', 'use PHP for block visibility');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   114
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   115
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   116
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   117
 * Implementation of hook_menu().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   118
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   119
function block_menu() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   120
  $items['admin/build/block'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   121
    'title' => 'Blocks',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   122
    'description' => 'Configure what block content appears in your site\'s sidebars and other regions.',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   123
    'page callback' => 'block_admin_display',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   124
    'access arguments' => array('administer blocks'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   125
    'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   126
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   127
  $items['admin/build/block/list'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   128
    'title' => 'List',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   129
    'type' => MENU_DEFAULT_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   130
    'weight' => -10,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   131
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   132
  $items['admin/build/block/list/js'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   133
    'title' => 'JavaScript List Form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   134
    'page callback' => 'block_admin_display_js',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   135
    'access arguments' => array('administer blocks'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   136
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   137
    'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   138
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   139
  $items['admin/build/block/configure'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   140
    'title' => 'Configure block',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   141
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   142
    'page arguments' => array('block_admin_configure'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   143
    'access arguments' => array('administer blocks'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   144
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   145
    'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   146
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   147
  $items['admin/build/block/delete'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   148
    'title' => 'Delete block',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   149
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   150
    'page arguments' => array('block_box_delete'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   151
    'access arguments' => array('administer blocks'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   152
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   153
    'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   154
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   155
  $items['admin/build/block/add'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   156
    'title' => 'Add block',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   157
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   158
    'page arguments' => array('block_add_block_form'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   159
    'access arguments' => array('administer blocks'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   160
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   161
    'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   162
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   163
  $default = variable_get('theme_default', 'garland');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   164
  foreach (list_themes() as $key => $theme) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   165
    $items['admin/build/block/list/'. $key] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   166
      'title' => check_plain($theme->info['name']),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   167
      'page arguments' => array($key),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   168
      'type' => $key == $default ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   169
      'weight' => $key == $default ? -10 : 0,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   170
      'file' => 'block.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   171
      'access callback' => '_block_themes_access',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   172
      'access arguments' => array($theme),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   173
    );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   174
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   175
  return $items;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   176
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   177
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   178
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   179
 * Menu item access callback - only admin or enabled themes can be accessed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   180
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   181
function _block_themes_access($theme) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   182
  return user_access('administer blocks') && ($theme->status || $theme->name == variable_get('admin_theme', '0'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   183
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   184
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   185
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   186
 * Implementation of hook_block().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   187
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   188
 * Generates the administrator-defined blocks for display.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   189
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   190
function block_block($op = 'list', $delta = 0, $edit = array()) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   191
  switch ($op) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   192
    case 'list':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   193
      $blocks = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   194
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   195
      $result = db_query('SELECT bid, info FROM {boxes} ORDER BY info');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   196
      while ($block = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   197
        $blocks[$block->bid]['info'] = $block->info;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   198
        // Not worth caching.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   199
        $blocks[$block->bid]['cache'] = BLOCK_NO_CACHE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   200
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   201
      return $blocks;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   202
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   203
    case 'configure':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   204
      $box = array('format' => FILTER_FORMAT_DEFAULT);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   205
      if ($delta) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   206
        $box = block_box_get($delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   207
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   208
      if (filter_access($box['format'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   209
        return block_box_form($box);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   210
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   211
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   212
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   213
    case 'save':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   214
      block_box_save($edit, $delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   215
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   216
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   217
    case 'view':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   218
      $block = db_fetch_object(db_query('SELECT body, format FROM {boxes} WHERE bid = %d', $delta));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   219
      $data['content'] = check_markup($block->body, $block->format, FALSE);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   220
      return $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   221
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   222
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   223
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   224
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   225
 * Update the 'blocks' DB table with the blocks currently exported by modules.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   226
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   227
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   228
 *   Blocks currently exported by modules.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   229
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   230
function _block_rehash() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   231
  global $theme_key;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   232
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   233
  init_theme();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   234
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   235
  $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   236
  $old_blocks = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   237
  while ($old_block = db_fetch_array($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   238
    $old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   239
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   240
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   241
  $blocks = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   242
  // Valid region names for the theme.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   243
  $regions = system_region_list($theme_key);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   244
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   245
  foreach (module_list() as $module) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   246
    $module_blocks = module_invoke($module, 'block', 'list');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   247
    if ($module_blocks) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   248
      foreach ($module_blocks as $delta => $block) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   249
        if (empty($old_blocks[$module][$delta])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   250
          // If it's a new block, add identifiers.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   251
          $block['module'] = $module;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   252
          $block['delta']  = $delta;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   253
          $block['theme']  = $theme_key;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   254
          if (!isset($block['pages'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   255
            // {block}.pages is type 'text', so it cannot have a
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   256
            // default value, and not null, so we need to provide
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   257
            // value if the module did not.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   258
            $block['pages']  = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   259
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   260
          // Add defaults and save it into the database.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   261
          drupal_write_record('blocks', $block);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   262
          // Set region to none if not enabled.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   263
          $block['region'] = $block['status'] ? $block['region'] : BLOCK_REGION_NONE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   264
          // Add to the list of blocks we return.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   265
          $blocks[] = $block;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   266
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   267
        else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   268
          // If it's an existing block, database settings should overwrite
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   269
          // the code. But aside from 'info' everything that's definable in
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   270
          // code is stored in the database and we do not store 'info', so we
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   271
          // do not need to update the database here.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   272
          // Add 'info' to this block.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   273
          $old_blocks[$module][$delta]['info'] = $block['info'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   274
          // If the region name does not exist, disable the block and assign it to none.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   275
          if (!empty($old_blocks[$module][$delta]['region']) && !isset($regions[$old_blocks[$module][$delta]['region']])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   276
            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');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   277
            $old_blocks[$module][$delta]['status'] = 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   278
            $old_blocks[$module][$delta]['region'] = BLOCK_REGION_NONE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   279
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   280
          else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   281
            $old_blocks[$module][$delta]['region'] = $old_blocks[$module][$delta]['status'] ? $old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   282
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   283
          // Add this block to the list of blocks we return.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   284
          $blocks[] = $old_blocks[$module][$delta];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   285
          // Remove this block from the list of blocks to be deleted.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   286
          unset($old_blocks[$module][$delta]);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   287
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   288
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   289
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   290
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   291
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   292
  // Remove blocks that are no longer defined by the code from the database.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   293
  foreach ($old_blocks as $module => $old_module_blocks) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   294
    foreach ($old_module_blocks as $delta => $block) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   295
      db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme_key);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   296
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   297
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   298
  return $blocks;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   299
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   300
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   301
function block_box_get($bid) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   302
  return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   303
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   304
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   305
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   306
 * Define the custom block form.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   307
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   308
function block_box_form($edit = array()) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   309
  $edit += array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   310
    'info' => '',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   311
    'body' => '',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   312
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   313
  $form['info'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   314
    '#type' => 'textfield',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   315
    '#title' => t('Block description'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   316
    '#default_value' => $edit['info'],
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   317
    '#maxlength' => 64,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   318
    '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array('@overview' => url('admin/build/block'))),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   319
    '#required' => TRUE,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   320
    '#weight' => -19,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   321
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   322
  $form['body_field']['#weight'] = -17;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   323
  $form['body_field']['body'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   324
    '#type' => 'textarea',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   325
    '#title' => t('Block body'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   326
    '#default_value' => $edit['body'],
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   327
    '#rows' => 15,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   328
    '#description' => t('The content of the block as shown to the user.'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   329
    '#weight' => -17,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   330
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   331
  if (!isset($edit['format'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   332
    $edit['format'] = FILTER_FORMAT_DEFAULT;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   333
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   334
  $form['body_field']['format'] = filter_form($edit['format'], -16);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   335
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   336
  return $form;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   337
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   338
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   339
function block_box_save($edit, $delta) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   340
  if (!filter_access($edit['format'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   341
    $edit['format'] = FILTER_FORMAT_DEFAULT;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   342
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   343
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   344
  db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['format'], $delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   345
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   346
  return TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   347
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   348
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   349
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   350
 * Implementation of hook_user().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   351
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   352
 * Allow users to decide which custom blocks to display when they visit
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   353
 * the site.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   354
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   355
function block_user($type, $edit, &$account, $category = NULL) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   356
  switch ($type) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   357
    case 'form':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   358
      if ($category == 'account') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   359
        $rids = array_keys($account->roles);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   360
        $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);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   361
        $form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   362
        while ($block = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   363
          $data = module_invoke($block->module, 'block', 'list');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   364
          if ($data[$block->delta]['info']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   365
            $return = TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   366
            $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));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   367
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   368
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   369
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   370
        if (!empty($return)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   371
          return $form;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   372
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   373
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   374
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   375
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   376
    case 'validate':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   377
      if (empty($edit['block'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   378
        $edit['block'] = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   379
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   380
      return $edit;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   381
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   382
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   383
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   384
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   385
 * Return all blocks in the specified region for the current user.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   386
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   387
 * @param $region
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   388
 *   The name of a region.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   389
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   390
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   391
 *   An array of block objects, indexed with <i>module</i>_<i>delta</i>.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   392
 *   If you are displaying your blocks in one or two sidebars, you may check
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   393
 *   whether this array is empty to see how many columns are going to be
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   394
 *   displayed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   395
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   396
 * @todo
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   397
 *   Now that the blocks table has a primary key, we should use that as the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   398
 *   array key instead of <i>module</i>_<i>delta</i>.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   399
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   400
function block_list($region) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   401
  global $user, $theme_key;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   402
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   403
  static $blocks = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   404
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   405
  if (!count($blocks)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   406
    $rids = array_keys($user->roles);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   407
    $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));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   408
    while ($block = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   409
      if (!isset($blocks[$block->region])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   410
        $blocks[$block->region] = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   411
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   412
      // Use the user's block visibility setting, if necessary
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   413
      if ($block->custom != 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   414
        if ($user->uid && isset($user->block[$block->module][$block->delta])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   415
          $enabled = $user->block[$block->module][$block->delta];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   416
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   417
        else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   418
          $enabled = ($block->custom == 1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   419
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   420
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   421
      else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   422
        $enabled = TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   423
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   424
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   425
      // Match path if necessary
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   426
      if ($block->pages) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   427
        if ($block->visibility < 2) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   428
          $path = drupal_get_path_alias($_GET['q']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   429
          // Compare with the internal and path alias (if any).
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   430
          $page_match = drupal_match_path($path, $block->pages);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   431
          if ($path != $_GET['q']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   432
            $page_match = $page_match || drupal_match_path($_GET['q'], $block->pages);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   433
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   434
          // When $block->visibility has a value of 0, the block is displayed on
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   435
          // all pages except those listed in $block->pages. When set to 1, it
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   436
          // is displayed only on those pages listed in $block->pages.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   437
          $page_match = !($block->visibility xor $page_match);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   438
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   439
        else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   440
          $page_match = drupal_eval($block->pages);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   441
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   442
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   443
      else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   444
        $page_match = TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   445
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   446
      $block->enabled = $enabled;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   447
      $block->page_match = $page_match;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   448
      $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   449
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   450
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   451
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   452
  // Create an empty array if there were no entries
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   453
  if (!isset($blocks[$region])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   454
    $blocks[$region] = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   455
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   456
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   457
  foreach ($blocks[$region] as $key => $block) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   458
    // Render the block content if it has not been created already.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   459
    if (!isset($block->content)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   460
      // Erase the block from the static array - we'll put it back if it has content.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   461
      unset($blocks[$region][$key]);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   462
      if ($block->enabled && $block->page_match) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   463
        // Check the current throttle status and see if block should be displayed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   464
        // based on server load.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   465
        if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   466
          // Try fetching the block from cache. Block caching is not compatible with
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   467
          // node_access modules. We also preserve the submission of forms in blocks,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   468
          // by fetching from cache only if the request method is 'GET'.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   469
          if (!count(module_implements('node_grants')) && $_SERVER['REQUEST_METHOD'] == 'GET' && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   470
            $array = $cache->data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   471
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   472
          else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   473
            $array = module_invoke($block->module, 'block', 'view', $block->delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   474
            if (isset($cid)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   475
              cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   476
            }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   477
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   478
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   479
          if (isset($array) && is_array($array)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   480
            foreach ($array as $k => $v) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   481
              $block->$k = $v;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   482
            }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   483
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   484
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   485
        if (isset($block->content) && $block->content) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   486
          // Override default block title if a custom display title is present.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   487
          if ($block->title) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   488
            // Check plain here to allow module generated titles to keep any markup.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   489
            $block->subject = $block->title == '<none>' ? '' : check_plain($block->title);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   490
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   491
          if (!isset($block->subject)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   492
            $block->subject = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   493
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   494
          $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   495
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   496
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   497
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   498
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   499
  return $blocks[$region];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   500
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   501
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   502
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   503
 * Assemble the cache_id to use for a given block.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   504
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   505
 * The cache_id string reflects the viewing context for the current block
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   506
 * instance, obtained by concatenating the relevant context information
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   507
 * (user, page, ...) according to the block's cache settings (BLOCK_CACHE_*
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   508
 * constants). Two block instances can use the same cached content when
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   509
 * they share the same cache_id.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   510
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   511
 * Theme and language contexts are automatically differenciated.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   512
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   513
 * @param $block
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   514
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   515
 *   The string used as cache_id for the block.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   516
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   517
function _block_get_cache_id($block) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   518
  global $theme, $base_root, $user;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   519
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   520
  // User 1 being out of the regular 'roles define permissions' schema,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   521
  // it brings too many chances of having unwanted output get in the cache
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   522
  // and later be served to other users. We therefore exclude user 1 from
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   523
  // block caching.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   524
  if (variable_get('block_cache', 0) && $block->cache != BLOCK_NO_CACHE && $user->uid != 1) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   525
    $cid_parts = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   526
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   527
    // Start with common sub-patterns: block identification, theme, language.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   528
    $cid_parts[] = $block->module;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   529
    $cid_parts[] = $block->delta;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   530
    $cid_parts[] = $theme;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   531
    if (module_exists('locale')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   532
      global $language;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   533
      $cid_parts[] = $language->language;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   534
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   535
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   536
    // 'PER_ROLE' and 'PER_USER' are mutually exclusive. 'PER_USER' can be a
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   537
    // resource drag for sites with many users, so when a module is being
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   538
    // equivocal, we favor the less expensive 'PER_ROLE' pattern.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   539
    if ($block->cache & BLOCK_CACHE_PER_ROLE) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   540
      $cid_parts[] = 'r.'. implode(',', array_keys($user->roles));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   541
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   542
    elseif ($block->cache & BLOCK_CACHE_PER_USER) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   543
      $cid_parts[] = "u.$user->uid";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   544
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   545
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   546
    if ($block->cache & BLOCK_CACHE_PER_PAGE) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   547
      $cid_parts[] = $base_root . request_uri();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   548
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   549
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   550
    return implode(':', $cid_parts);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   551
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   552
}