/[drupal]/drupal/modules/block.module
ViewVC logotype

Diff of /drupal/modules/block.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.206, Wed Apr 26 21:53:24 2006 UTC revision 1.206.2.8, Sun Mar 25 21:07:19 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: block.module,v 1.205 2006/04/17 20:48:26 dries Exp $  // $Id: block.module,v 1.206.2.7 2006/11/14 10:46:07 killes Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 12  Line 12 
12  function block_help($section) {  function block_help($section) {
13    switch ($section) {    switch ($section) {
14      case 'admin/help#block':      case 'admin/help#block':
15        $output = '<p>'. t('Blocks are the boxes of related/grouped data that are visible in the sidebar(s) of your web site. These are usually generated automatically by modules (e.g. recent forum topics), but administrators can also create their own defined blocks.') .'</p>';        $output = '<p>'. t('Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. Blocks are usually generated automatically by modules (e.g., Recent Forum Topics), but administrators can also define custom blocks.') .'</p>';
16        $output .= '<p>'. t('The sidebar each block appears in depends on both which theme you are using (some are left-only, some right, some both), and on the settings in block management.') .'</p>';        $output .= '<p>'. t('The region each block appears in depends on both which theme you are using (some themes allow greater control over block placement than others), and on the settings in the block administration section.') .'</p>';
17        $output .= '<p>'. t('The block management screen lets you specify the vertical sort-order of the blocks within a sidebar. You do this by assigning a weight to each block. Lighter blocks (smaller weight) "float up" towards the top of the sidebar. Heavier ones "sink down" towards the bottom of it.') .'</p>';        $output .= '<p>'. t('The block administration screen lets you specify the vertical placement of the blocks within a region. You do this by assigning a weight to each block. Lighter blocks (those having a smaller weight) "float up" towards the top of the region; heavier ones "sink".') .'</p>';
18        $output .= t('<p>A block\'s visibility depends on:</p>        $output .= t('<p>A block\'s visibility depends on:</p>
19  <ul>  <ul>
20  <li>Its enabled checkbox. Disabled blocks are never shown.</li>  <li>Its enabled checkbox. Disabled blocks are never shown.</li>
21  <li>Its throttle checkbox. Throttled blocks are hidden during high server loads.</li>  <li>Its throttle checkbox. Throttled blocks are hidden during high server loads.</li>
22  <li>Its path options. Blocks can be configured to only show/hide on certain pages.</li>  <li>Its page visibility settings. Blocks can be configured to be visible/hidden on certain pages.</li>
23  <li>User settings. Administrators can choose to let your users decide whether to show/hide certain blocks.</li>  <li>Its custom visibility settings. Blocks can be configured to be visible only when specific conditions are true.</li>
24  <li>Its function. Dynamic blocks (such as those defined by modules) may be empty on certain pages and will not be shown.</li>  <li>Its user visibility settings. Administrators can choose to let users decide whether to show/hide certain blocks.</li>
25    <li>Its function. Some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.</li>
26  </ul>  </ul>
27  ');  ');
28        $output .= '<h3>'. t('Module blocks') .'</h3>';        $output .= '<h3>'. t('Module blocks') .'</h3>';
29        $output .= '<p>'. t('Module blocks are available when modules are enabled.  These blocks can be administered in block administration.') .'</p>';        $output .= '<p>'. t('Some modules generate blocks that become available when the modules are enabled. These blocks can be administered via the <a href="%admin-block">blocks administration page</a>.</p>', array('%admin-block' => url('admin/block'))) .'</p>';
30        $output .= '<h3>'. t('Administrator defined blocks') .'</h3>';        $output .= '<h3>'. t('Administrator defined blocks') .'</h3>';
31        $output .= '<p>'. t('An administrator defined block contains content supplied by the administrator. Each admin-defined block consists of a title, a description, and a body which can be as long as you wish. The Drupal engine will render the content of the block.') .'</p>';        $output .= '<p>'. t('Administrators can also define custom blocks. These blocks consist of a title, a description, and a body which can be as long as you wish. Block content can be in any of the input formats supported for other content.') .'</p>';
32        $output .= t('<p>You can</p>        $output .= t('<p>You can</p>
33  <ul>  <ul>
34  <li>enable throttle and configure blocks at <a href="%admin-block">administer &gt;&gt; blocks</a>.</li>  <li>enable, throttle and configure blocks at <a href="%admin-block">administer &gt;&gt; blocks</a>.</li>
35  <li>add a block at <a href="%admin-block-add">administer &gt;&gt; blocks &gt;&gt; add block</a>.</li>  <li>add an administrator-defined block at <a href="%admin-block-add">administer &gt;&gt; blocks &gt;&gt; add block</a>.</li>
36  </ul>  </ul>
37  ', array('%admin-block' => url('admin/block'), '%admin-block-add' => url('admin/block/add')));  ', array('%admin-block' => url('admin/block'), '%admin-block-add' => url('admin/block/add')));
38        $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%block">Block page</a>.', array('%block' => 'http://drupal.org/handbook/modules/block/')) .'</p>';        $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%block">Block page</a>.', array('%block' => 'http://drupal.org/handbook/modules/block/')) .'</p>';
# Line 40  function block_help($section) { Line 41  function block_help($section) {
41        return t('Controls the boxes that are displayed around the main content.');        return t('Controls the boxes that are displayed around the main content.');
42      case 'admin/block':      case 'admin/block':
43        return t("        return t("
44  <p>Blocks are content rendered into regions, often boxes in the left and right side bars of the web site. They are made available by modules or created manually.</p>  <p>Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. They are usually generated automatically by modules, but administrators can create blocks manually.</p>
45  <p>Only enabled blocks are shown. You can position the blocks by deciding which area of the page they will show up on (e.g., a sidebar) and in which order they appear (weight).  Highlighting on this page shows the regions where content will be rendered.</p>  <p>Only enabled blocks are shown. You can position blocks by specifying which area of the page they should appear in (e.g., a sidebar).  Highlighted labels on this page show the regions into which blocks can be rendered. You can specify where within a region a block will appear by adjusting its weight.</p>
46  <p>If you want certain blocks to disable themselves temporarily during high server loads, check the 'Throttle' box. You can configure the auto-throttle on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.</p>  <p>If you want certain blocks to disable themselves temporarily during high server loads, check the 'Throttle' box. You can configure the auto-throttle on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.</p>
47    <p>You can configure the behaviour of each block (for example, specifying on which pages and for what users it will appear) by clicking the 'configure' link for each block.</p>
48  ", array('%throttle' => url('admin/settings/throttle')));  ", array('%throttle' => url('admin/settings/throttle')));
49      case 'admin/block/add':      case 'admin/block/add':
50        return t('<p>Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href="%overview">blocks</a>. The title is used when displaying the block. The description is used in the "block" column on the <a href="%overview">blocks</a> page.</p>', array('%overview' => url('admin/block')));        return t('<p>Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href="%overview">blocks</a>. The title is used when displaying the block. The description is used in the "block" column on the <a href="%overview">blocks</a> page.</p>', array('%overview' => url('admin/block')));
# Line 143  function _block_rehash() { Line 145  function _block_rehash() {
145    
146    init_theme();    init_theme();
147    
148      db_lock_table('blocks');
149    
150    $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);    $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
151    while ($old_block = db_fetch_object($result)) {    while ($old_block = db_fetch_object($result)) {
152      $old_blocks[$old_block->module][$old_block->delta] = $old_block;      $old_blocks[$old_block->module][$old_block->delta] = $old_block;
153    }    }
154    
155    db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key);    $blocks = array();
156    
157    foreach (module_list() as $module) {    foreach (module_list() as $module) {
158      $module_blocks = module_invoke($module, 'block', 'list');      $module_blocks = module_invoke($module, 'block', 'list');
# Line 176  function _block_rehash() { Line 180  function _block_rehash() {
180            }            }
181          }          }
182    
         // Reinsert blocks into table  
         db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",  
           $block['module'], $block['delta'], $theme_key, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);  
183          $blocks[] = $block;          $blocks[] = $block;
184        }        }
185      }      }
186    }    }
187    
188      // Remove all blocks from table.
189      db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key);
190    
191      // Reinsert new set of blocks into table.
192      foreach ($blocks as $block) {
193        db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)", $block['module'], $block['delta'], $theme_key, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
194      }
195      db_unlock_tables();
196    
197    return $blocks;    return $blocks;
198  }  }
199    
# Line 220  function block_admin_display() { Line 230  function block_admin_display() {
230      $form[$i]['theme'] = array('#type' => 'hidden', '#value' => $theme_key);      $form[$i]['theme'] = array('#type' => 'hidden', '#value' => $theme_key);
231      $form[$i]['weight'] = array('#type' => 'weight', '#default_value' => $block['weight']);      $form[$i]['weight'] = array('#type' => 'weight', '#default_value' => $block['weight']);
232      $form[$i]['region'] = array('#type' => 'select',      $form[$i]['region'] = array('#type' => 'select',
233        '#default_value' => isset($block['region']) ? $block['region'] : system_default_region(),        '#default_value' => isset($block['region']) ? $block['region'] : system_default_region($theme_key),
234        '#options' => $block_regions,        '#options' => $block_regions,
235      );      );
236    
# Line 293  function theme_block_admin_display($form Line 303  function theme_block_admin_display($form
303    $last_region = '';    $last_region = '';
304    $last_status = 1;    $last_status = 1;
305    foreach (element_children($form) as $i) {    foreach (element_children($form) as $i) {
306      $block = $form[$i];      $block = &$form[$i];
307      // Only take form elements that are blocks.      // Only take form elements that are blocks.
308      if (is_array($block['info'])) {      if (is_array($block['info'])) {
309        // Fetch values        // Fetch values
# Line 337  function theme_block_admin_display($form Line 347  function theme_block_admin_display($form
347    
348    $output = theme('table', $header, $rows, array('id' => 'blocks'));    $output = theme('table', $header, $rows, array('id' => 'blocks'));
349    $output .= form_render($form['submit']);    $output .= form_render($form['submit']);
350    // Also render the form_id as there is no form_render($form) call (as form_render does not appear to handle the    $output .= form_render($form);
   // multi-dimensional block form array very well).  
   $output .= form_render($form['form_id']);  
   
351    return $output;    return $output;
352  }  }
353    
# Line 441  function block_admin_configure_validate( Line 448  function block_admin_configure_validate(
448    
449  function block_admin_configure_submit($form_id, $form_values) {  function block_admin_configure_submit($form_id, $form_values) {
450    if (!form_get_errors()) {    if (!form_get_errors()) {
451      db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], $form_values['pages'], $form_values['custom'], $form_values['module'], $form_values['delta']);      db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], trim($form_values['pages']), $form_values['custom'], $form_values['module'], $form_values['delta']);
452      module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);      module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
453      drupal_set_message(t('The block configuration has been saved.'));      drupal_set_message(t('The block configuration has been saved.'));
454      cache_clear_all();      cache_clear_all();
# Line 490  function block_box_delete($bid = 0) { Line 497  function block_box_delete($bid = 0) {
497   */   */
498  function block_box_delete_confirm_submit($form_id, $form_values) {  function block_box_delete_confirm_submit($form_id, $form_values) {
499    db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']);    db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']);
500      db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = %d", $form_values['bid']);
501    drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info']))));    drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info']))));
502    cache_clear_all();    cache_clear_all();
503    return 'admin/block';    return 'admin/block';
# Line 621  function block_list($region) { Line 629  function block_list($region) {
629          if ($block->visibility < 2) {          if ($block->visibility < 2) {
630            $path = drupal_get_path_alias($_GET['q']);            $path = drupal_get_path_alias($_GET['q']);
631            $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';            $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
632            $page_match = !($block->visibility xor preg_match($regexp, $path));            // Compare with the internal and path alias (if any).
633              $page_match = preg_match($regexp, $path);
634              if ($path != $_GET['q']) {
635                $page_match = $page_match || preg_match($regexp, $_GET['q']);
636              }
637              // When $block->visibility has a value of 0, the block is displayed on
638              // all pages except those listed in $block->pages. When set to 1, it
639              // is displayed only on those pages listed in $block->pages.
640              $page_match = !($block->visibility xor $page_match);
641          }          }
642          else {          else {
643            $page_match = drupal_eval($block->pages);            $page_match = drupal_eval($block->pages);

Legend:
Removed from v.1.206  
changed lines
  Added in v.1.206.2.8

  ViewVC Help
Powered by ViewVC 1.1.2