You are here

function ajaxblocks_preprocess_block in Ajax Blocks 6

Same name and namespace in other branches
  1. 7 ajaxblocks.module \ajaxblocks_preprocess_block()

Implements hook_preprocess_block().

File

./ajaxblocks.module, line 342
Loads dynamic blocks on cached page for anonymous users by performing AJAX request.

Code

function ajaxblocks_preprocess_block(&$vars) {
  if (ajaxblocks_in_ajax_handler()) {
    return;
  }
  $id = $vars['block']->module . '-' . $vars['block']->delta;
  $settings = array();
  if (!ajaxblocks_is_ajax($id, $settings)) {
    return;
  }
  $current_user_rids = array_keys($GLOBALS['user']->roles);
  if (ajaxblocks_page_cacheable()) {
    if (count(array_intersect($current_user_rids, $settings['cached_roles'])) == 0) {
      return;
    }
  }
  else {
    if (count(array_intersect($current_user_rids, $settings['uncached_roles'])) == 0) {
      return;
    }
  }
  ajaxblocks_page_ajax_list($id, $settings);
  $noscript = '';
  if ($settings['include_noscript']) {
    $noscript = '<script type="text/javascript"></script><noscript>' . $vars['block']->content . '</noscript>';
  }
  $wrapper_class = "ajaxblocks-wrapper";
  if ($settings['loader_picture']) {
    $wrapper_class = "ajaxblocks-wrapper-" . intval($settings['loader_picture']);
  }
  $vars['block']->content = '<div id="block-' . $id . '-ajax-content" class="' . $wrapper_class . '">' . $noscript . '</div>';
}