You are here

function block_refresh_footer in Block Refresh 5

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

implements hook_footer calls the jquery to refresh blocks automatically, but only if the blocks exist on the current page and are enabled

File

./block_refresh.module, line 168

Code

function block_refresh_footer() {

  // 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();
  $regions = system_region_list($theme_key);
  foreach ($regions as $region => $value) {
    $blocks = array_merge($blocks, block_list($region));
  }
  $settings = variable_get('block_refresh_settings', array());
  foreach ($settings as $block) {
    if (isset($blocks[$block['block']['block'] . '_' . $block['block']['delta']])) {
      if ($block['enabled']) {
        $js .= theme('block_refresh_js', $block);
      }
      if ($block['manual']) {
        $js .= theme('block_manual_refresh_js', $block);
      }
    }
  }
  if ($js) {
    if (!module_invoke('jq', 'add', 'block_refresh')) {
      drupal_add_js(drupal_get_path('module', 'block_refresh') . '/js/block_refresh.js');
      drupal_add_css(drupal_get_path('module', 'block_refresh') . '/css/block_refresh.css');
    }
    drupal_add_js(theme('block_refresh_js_wrapper', $js), 'inline');
  }
}