You are here

function theme_esi_tag in ESI: Edge Side Includes 6.2

Create the ESI-tag for a particular block.

4 theme calls to theme_esi_tag()
context_reaction_esi_block::build_block in plugins/context_reaction_esi_block.inc
esi_esi_cache_get_cache in plugins/cache/esi.inc
Get cached content.
esi_panels_pane_content_alter in ./esi.module
Implementation of hook_pane_content_alter().
esi__theme_blocks in ./esi.theme.inc
Replacement for core theme function: thene_blocks

File

./esi.theme.inc, line 68
Theme handlers for the ESI module.

Code

function theme_esi_tag($type, $data) {
  global $theme_key, $base_root, $base_path;
  require_once drupal_get_path('module', 'esi') . '/esi.inc';
  $added_to_url = array();
  if ($type == 'block') {
    $src = "esi/block/{$theme_key}:{$data->region}:{$data->module}:{$data->delta}";
    $css_id = "{$theme_key}-{$data->region}-{$data->module}-{$data->delta}";
    $config = esi_get_settings($data->module . '_' . $data->delta);
    $scope = $config['scope'];
  }
  elseif ($type == 'panel') {

    // Build the esi tag.
    $src = "esi/panels_pane/{$theme_key}:{$data->did}:{$data->pid}";
    $css_id = "{$theme_key}-{$data->did}-{$data->pid}";
    $scope = isset($data->cache['settings']['scope']) ? $data->cache['settings']['scope'] : (int) variable_get('esi_panel_default_scope', ESI_PANEL_DEFAULT_SCOPE);
    if (!empty($data->configuration['context']) && is_string($data->configuration['context'])) {
      $display = panels_get_current_page_display();

      // The cache-key variable is set by the panel-context render function.
      list($context, $task_name, $handler_name) = explode(':', $display->cache_key);

      // Add the URL the panel was requested from.
      $src .= '/' . base64_encode($_GET['q']);
      $added_to_url['page'] = TRUE;

      // Add the page-manager task name.
      $src .= '/' . $task_name;
      $added_to_url['task'] = TRUE;

      // Add the name of the context which is supplied to this pane.
      $src .= '/' . $data->configuration['context'];
      $added_to_url['context'] = TRUE;
    }
  }
  if ($type == 'external') {
    $src = $data->cache['settings']['external_text'];
    if (!empty($data->cache['settings']['context'])) {
      $full = base64_encode($base_root . request_uri());
      $internal = empty($_GET['q']) ? variable_get('site_frontpage', 'node') : $_GET['q'];
      $internal = base64_encode($internal);
      $parsed = parse_url($src);
      $glue_string = empty($parsed['query']) ? '?' : '&';
      $src .= $glue_string . 'esi_full=' . $full . '&esi_internal=' . $internal;
      $added_to_url['page'] = TRUE;
      $added_to_url['fullpage'] = TRUE;
    }
    $css_id = "{$theme_key}-{$data->did}-{$data->pid}";
  }
  $user_cache = '/CACHE=USER';
  $role_cache = '/CACHE=ROLE';
  if (variable_get('esi_role_user_direct_injection', ESI_ROLE_USER_DIRECT_INJECTION)) {
    $role_cache = '/CACHE=' . _esi__get_roles_hash();
    $user_cache = '/CACHE=' . esi_get_user_hash();
  }
  if (!empty($scope)) {
    switch ($scope) {

      // Global Scope.
      case 0:
      case 1:
      case 2:
        break;

      // Page Scope.
      case 3:
        if (empty($added_to_url['page'])) {
          $src .= '/' . base64_encode($_GET['q']);
          $added_to_url['page'] = TRUE;
        }
        break;

      // User Role.
      case 4:
        $src .= $role_cache;
        $added_to_url['cache'] = TRUE;
        break;

      // User Role/Page.
      case 5:
        if (empty($added_to_url['page'])) {
          $src .= '/' . base64_encode($_GET['q']);
          $added_to_url['page'] = TRUE;
        }
        $src .= $role_cache;
        $added_to_url['cache'] = TRUE;
        break;

      // User ID.
      case 6:
        $src .= $user_cache;
        $added_to_url['cache'] = TRUE;
        break;

      // User ID/Page.
      case 7:
        if (empty($added_to_url['page'])) {
          $src .= '/' . base64_encode($_GET['q']);
          $added_to_url['page'] = TRUE;
        }
        $src .= $user_cache;
        $added_to_url['cache'] = TRUE;
        break;
    }
  }
  $ajax_src = esi_build_uri($src);
  $fragments = @parse_url($src);
  if (!isset($fragments['host'])) {
    $src = $base_path . $src;
  }
  $setting = variable_get('esi_mode', ESI_MODE);
  switch ($setting) {
    case ESI__CONFIG_ESI:
      $output = '<esi:include src="' . $src . '" />';
      if (!empty($css_id) && variable_get('esi_ajax_fallback', ESI_AJAX_FALLBACK)) {
        drupal_add_js(array(
          'esi' => array(
            $css_id => $ajax_src,
          ),
        ), 'setting');
        $output .= '<esi:remove><div id="' . $css_id . '" class="esi-ajax"></div></esi:remove>';
      }
      break;
    case ESI__CONFIG_SSI:
      $output = '<!--# include virtual="' . $src . '" -->';
      break;
    case ESI__CONFIG_AJAX:
      if (!empty($css_id)) {
        drupal_add_js(array(
          'esi' => array(
            $css_id => $ajax_src,
          ),
        ), 'setting');
        $output = '<div id="' . $css_id . '" class="esi-ajax"></div>';
      }
      break;
  }
  return $output;
}