diff --git a/esi.admin.inc b/esi.admin.inc
new file mode 100644
index 0000000..b2b3bd3
--- /dev/null
+++ b/esi.admin.inc
@@ -0,0 +1,29 @@
+ 'Default block setting',
+ '#type' => 'radios',
+ '#options' => array(0 => 'Off', 1 => 'ESI', 2 => 'AJAX'),
+ '#default_value' => variable_get('esi_block_default_enabled', ESI__BLOCK_CONFIG_DEFAULT__IS_ENABLED),
+ );
+ $form['esi_seed_rotation_interval'] = array(
+ '#title' => 'Default seed key rotation interval',
+ '#type' => 'textfield',
+ '#default_value' => variable_get('esi_seed_rotation_interval', ESI__DEFAULT_SEED_KEY_ROTATION_INTERVAL),
+ );
+ $form['esi_block_default_ttl'] = array(
+ '#title' => 'Default block TTL',
+ '#type' => 'textfield',
+ '#default_value' => variable_get('esi_block_default_ttl', ESI__BLOCK_CONFIG_DEFAULT__TTL),
+ '#description' => t('Time-to-live on the proxy-cache'),
+ );
+
+ return system_settings_form($form);
+}
+
diff --git a/esi.inc b/esi.inc
index 7d40e9b..d6ed242 100644
--- a/esi.inc
+++ b/esi.inc
@@ -91,8 +91,8 @@ function _esi__block_settings($module, $delta, $config = NULL) {
}
else {
$config = new stdClass;
- $config->enabled = ESI__BLOCK_CONFIG_DEFAULT__IS_ENABLED;
- $config->ttl = ESI__BLOCK_CONFIG_DEFAULT__TTL;
+ $config->enabled = variable_get('esi_block_default_enabled', ESI__BLOCK_CONFIG_DEFAULT__IS_ENABLED);
+ $config->ttl = variable_get('esi_block_default_ttl', ESI__BLOCK_CONFIG_DEFAULT__TTL);
}
return $config;
diff --git a/esi.js b/esi.js
new file mode 100644
index 0000000..ccba67e
--- /dev/null
+++ b/esi.js
@@ -0,0 +1,11 @@
+Drupal.behaviors.esi = function(context) {
+ $(".esi-ajax:not(.esi-ajax-processed)").each(function() {
+ $(this).addClass('esi-ajax-processed');
+ var css_id = $(this).attr('id');
+ var src = Drupal.settings.esi[css_id];
+ $.get(src, function(data) {
+ $('#' + css_id).replaceWith(data);
+ Drupal.attachBehaviors(data);
+ });
+ });
+}
diff --git a/esi.module b/esi.module
index 7d381cc..13db807 100755
--- a/esi.module
+++ b/esi.module
@@ -14,7 +14,9 @@ define('ESI__BLOCK_CONFIG_DEFAULT__IS_ENABLED', TRUE);
// Default TTL for blocks: 5 minutes
define('ESI__BLOCK_CONFIG_DEFAULT__TTL', 300);
-
+// ESI block setting constants
+define('ESI__BLOCK_CONFIG_ESI', 1);
+define('ESI__BLOCK_CONFIG_AJAX', 2);
/**
* Implementation of hook_theme().
@@ -45,19 +47,35 @@ function esi_theme_registry_alter(&$theme_registry) {
/**
+ * Implementation of hook_init().
+ */
+function esi_init() {
+ drupal_add_js(drupal_get_path('module', 'esi') . '/esi.js');
+}
+
+/**
* Implementation of hook_menu().
* Define a menu-handler.
*/
function esi_menu() {
- return array(
- 'esi/block/%' => array(
- 'title' => 'ESI handler',
- 'page callback' => 'esi__block_handler',
- 'page arguments' => array(2),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK
- )
+ $items = array();
+ $items['esi/block/%'] = array(
+ 'title' => 'ESI handler',
+ 'page callback' => 'esi__block_handler',
+ 'page arguments' => array(2),
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK
+ );
+ $items['admin/settings/esi'] = array(
+ 'title' => 'ESI default settings',
+ 'description' => 'ESI default settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('esi_admin_settings'),
+ 'access arguments' => array('administer site configuration'),
+ 'file' => 'esi.admin.inc',
+ 'type' => MENU_CALLBACK,
);
+ return $items;
}
@@ -139,8 +157,9 @@ function esi_form_block_admin_configure_alter(&$form, $form_state) {
);
$element['esi_config']['enabled'] = array(
- '#type' => 'checkbox',
+ '#type' => 'radios',
'#title' => t('Enable ESI'),
+ '#options' => array(0 => 'Off', 1 => 'ESI', 2 => 'AJAX'),
'#default_value' => $config->enabled,
);
diff --git a/esi.theme.inc b/esi.theme.inc
index 60a1870..1365447 100644
--- a/esi.theme.inc
+++ b/esi.theme.inc
@@ -17,7 +17,7 @@ function esi__theme_blocks($region) {
// 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('esi_tag', $block, $esi_config->enabled)
: theme('block', $block);
}
}
@@ -32,7 +32,7 @@ function esi__theme_blocks($region) {
/**
* Create the ESI-tag for a particular block.
*/
-function theme_esi_tag($block) {
+function theme_esi_tag($block, $setting) {
global $theme_key, $base_url;
$bid = "{$theme_key}:{$block->region}:{$block->module}:{$block->delta}";
@@ -51,6 +51,17 @@ function theme_esi_tag($block) {
$src .= '/CACHE=' . ($block->cache & BLOCK_CACHE_PER_USER ? 'USER' : 'ROLE');
}
- $output = '