You are here

function authcache_example_display_block_example in Authenticated User Page Caching (Authcache) 7

Display user-customized block

1 call to authcache_example_display_block_example()
authcache_example_block_view in modules/authcache_example/authcache_example.module

File

modules/authcache_example/authcache_example.module, line 147
authcache_example.module

Code

function authcache_example_display_block_example() {
  global $user, $_authcache_is_cacheable;
  if (!$user->uid) {
    return 'Please login to test this block.';
  }
  else {
    if ($_authcache_is_cacheable) {

      // Use JS to retrieve block content
      drupal_add_js(drupal_get_path('module', 'authcache_example') . '/js/authcache_example.js', 'module', 'header');
      return ' ';
    }
  }
  $block_text = check_plain(db_query("SELECT block_text FROM {authcache_example} WHERE uid = :uid", array(
    ':uid' => $user->uid,
  ))
    ->fetchField());
  $output = t("Hello, !user, this is a customized block of content that can be cached by the browser.  Update it <a href=\"!url\">here</a>!", array(
    '!user' => $user->name,
    '!url' => url("user/{$user->uid}/authcache_example"),
  ));
  $output .= "<p><strong class=\"error\">{$block_text}</strong></p>";
  return $output;
}