You are here

function block_refresh_footer in Block Refresh 6

Same name and namespace in other branches
  1. 5 block_refresh.module \block_refresh_footer()

Implementation of hook_footer().

File

./block_refresh.module, line 127

Code

function block_refresh_footer($main = 0) {

  // don't bother to continue if the user can't refresh content anyway...
  if (!user_access('access block refresh content')) {
    return;
  }
  global $theme_key;
  $blocks = array();

  // Get an array of regions for the given theme
  $regions = system_region_list($theme_key);

  // Get all blocks that are in each region of the theme and put into $blocks array
  foreach ($regions as $region => $value) {
    $blocks = array_merge($blocks, block_list($region));
  }

  // Get the variable that holds all of the configured blocks information (this is an array)
  $settings = variable_get('block_refresh_settings', array());
  $js = '';

  // Test every block that is currently being displayed
  foreach ($settings as $block) {

    // If the block is configured for Block Refresh...
    if (isset($blocks[$block['block']['block'] . '_' . $block['block']['delta']])) {

      // I believe (though have not thoroughly tested) that this is an unnecessary test
      if ($block['enabled']) {

        // this is the block div css id and content class
        $div = "#block-{$block['block']['block']}-{$block['block']['delta']} .content";

        // we store seconds, but js expects milliseconds
        $timer = $block['timer'] * 1000;
        $base = base_path();

        // Set jQuery array to be set in page footer ... also checks to see whether clean URLs are enabled or not
        $js .= "  _block_refresh_data['{$div}'] = new block_refresh_data({$timer}, '{$base}" . (variable_get('clean_url', 0) == 0 ? "?q=" : "") . "block_refresh/{$block['block']['block']}/{$block['block']['delta']}');\n";
        $js .= "  block_refresh_timer('{$div}');";
      }

      // If the block is configured to be user-refreshed
      if ($block['manual']) {

        // this is the block div css id and content class
        $div = "block-{$block['block']['block']}-{$block['block']['delta']}";
        $base = base_path();
        $url = "{$base}block_refresh/{$block['block']['block']}/{$block['block']['delta']}";
        $content_url = "#{$div} .content";
        $js .= "  block_refresh_add_button('{$div}', '{$url}', '{$content_url}', '" . t('Refresh') . "');";
      }
    }
  }

  // If there is a block that is currently being displayed that is configured to work with Block Refresh...
  if (!empty($js)) {
    drupal_add_js("\$(document).ready(function() {\n{$js}\n})", 'inline', 'footer');
  }
}