forked from dstuart/Drupal-ESI-Module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esi.theme.inc
57 lines (46 loc) · 1.57 KB
/
esi.theme.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// $Id: esi.theme.inc,v 1.2 2010/11/17 11:37:25 manarth Exp $
/**
* @file
* Theme handlers for the ESI module.
*/
/**
* Replacement for core theme function: thene_blocks
*/
function esi__theme_blocks($region) {
$output = '';
// load our helper file.
require_once(dirname(__FILE__) . '/esi.inc');
if ($list = block_list($region)) {
foreach ($list as $key => $block) {
// if ESI's enabled on the block, add an ESI tag instead of block content.
$esi_config = _esi__block_settings($block->module, $block->delta);
$output .= $esi_config->enabled
? theme('esi_tag', $block)
: theme('block', $block);
}
}
// Add any content assigned to this region through drupal_set_content() calls.
$output .= drupal_get_content($region);
return $output;
}
/**
* Create the ESI-tag for a particular block.
*/
function theme_esi_tag($block) {
global $theme_key, $base_url;
$bid = "{$theme_key}:{$block->region}:{$block->module}:{$block->delta}";
$src = $base_url . "/esi/block/{$bid}";
$params = array();
// if the block uses per-page cacheing, add the page param to the URL.
if ($block->cache & BLOCK_CACHE_PER_PAGE) {
$src .= '/' . base64_encode($_GET['q']);
}
// Finally, if the cache-mode is PER-USER or PER-ROLE, advise the proxy.
// Ideally, the proxy will remove this parameter.
if ($block->cache & BLOCK_CACHE_PER_USER || $block->cache & BLOCK_CACHE_PER_ROLE) {
$src .= '/CACHE=' . ($block->cache & BLOCK_CACHE_PER_USER ? 'USER' : 'ROLE');
}
$output = '<esi:include src="' . $src . '" />';
return $output;
}