You are here

function authcache_preprocess_block in Authenticated User Page Caching (Authcache) 6

Same name and namespace in other branches
  1. 7 authcache.module \authcache_preprocess_block()

Process block template variables

File

./authcache.module, line 520
Authenticated User Page Caching (and anonymous users, too!)

Code

function authcache_preprocess_block(&$variables) {
  if ($variables['is_page_authcache']) {
    global $user;
    $block = $variables['block'];

    // User navigation block; use cookie for displaying username.
    if ($block->module == 'user' && $user->uid && $user->name == $block->subject) {
      $variables['block']->subject = '<span class="authcache-user"></span>';
    }

    // Authcache Blocks
    $authcache_block = variable_get('authcache_block', array());
    $block_id = "{$block->module}-{$block->delta}";
    if (isset($authcache_block[$block_id])) {
      $data = array();

      // Max-age (local caching)
      if ($authcache_block[$block_id]) {
        $data[] = 'data-block-cache="' . $authcache_block[$block_id] . '"';
      }
      $data[] = 'data-block-cid="' . _block_get_cache_id($block) . '"';
      $variables['block']->subject = '<span id="authcache-block-subj-' . $block_id . '">' . $variables['block']->subject . '</span>';
      $variables['block']->content = '<div id="authcache-block-' . $block_id . '" class="authcache-block" ' . implode(' ', $data) . '></div>';
    }
  }
}