You are here

function panels_content_cache_get_cid in Panels Content Cache 7

Figure out a cache id for our cache based upon input and settings.

2 calls to panels_content_cache_get_cid()
panels_content_cache_get_cache in plugins/cache/content.inc
Get cached content.
panels_content_cache_set_cache in plugins/cache/content.inc
Set cached content.

File

plugins/cache/content.inc, line 66
Provides a content-based caching option for panel panes.

Code

function panels_content_cache_get_cid($conf, $display, $args, $contexts, $pane) {
  $cid = panels_content_cache_get_base_cid($display);
  if ($pane) {
    $cid[] = 'pid_' . $pane->pid;
  }

  // Backwards compatibility for the old single selector on the granularity
  // option.
  if (empty($conf['granularity'])) {
    $conf['granularity'] = array();
  }
  if (!empty($conf['granularity']) && !is_array($conf['granularity'])) {
    $conf['granularity'] = array(
      $conf['granularity'] => $conf['granularity'],
    );
  }

  // Granularity: URL.
  if (!empty($conf['granularity']['url']) && !empty($conf['granularity_url'])) {
    switch ($conf['granularity_url']) {

      // Example: 'http://example.com/site',
      // How to generate: $GLOBALS['base_url'] . base_path()
      case 'base_url':
        $cid[] = $GLOBALS['base_url'];
        break;

      // Example: 'http://example.com/site/node/123',
      // How to generate: $GLOBALS['base_url'] . base_path() . current_path()
      case 'base_url_system':
        $cid[] = $GLOBALS['base_url'] . base_path() . current_path();
        break;

      // Example: 'http://example.com/site/page/alias',
      // How to generate: $GLOBALS['base_url'] . base_path() . request_path()
      case 'base_url_alias':
        $cid[] = $GLOBALS['base_url'] . base_path() . request_path();
        break;

      // Example: '/site/',
      // How to generate: base_path()
      case 'base_path':
        $cid[] = base_path();
        break;

      // Example: '/site/node/123',
      // How to generate: base_path() . current_path()
      case 'base_path_system':
        $cid[] = base_path() . current_path();
        break;

      // Example: '/site/page/alias',
      // How to generate: base_path() . request_path()
      case 'base_path_alias':
        $cid[] = base_path() . request_path();
        break;
    }

    // Optionally include the query string.
    if (!empty($conf['granularity_url_query'])) {
      $get = $_GET;
      unset($get['q']);
      if (!empty($get)) {
        $cid[] = http_build_query($get);
      }
    }
  }

  // Support for the Domain Access module.
  if (!empty($conf['granularity']['domain']) && module_exists('domain')) {
    $current_domain = domain_get_domain();
    if (is_array($current_domain) && isset($current_domain['domain_id'])) {
      $cid[] = 'domain_' . $current_domain['domain_id'];
    }
  }

  // Granularity: Page arguments.
  if (!empty($conf['granularity']['args'])) {
    foreach ($args as $pos => $arg) {
      $cid[] = 'arg_' . $pos . '_' . $arg;
    }
  }

  // Granularity: Page context.
  if (!empty($conf['granularity']['context'])) {
    if (!is_array($contexts)) {
      $contexts = array(
        $contexts,
      );
    }

    // Loop through each context.
    foreach ($contexts as $context) {

      // Add the plugin name.
      $plugin_pieces = array();
      if (isset($context->plugin)) {
        $cid[] = 'ctxplugin_' . $context->plugin;

        // If this is an entity, the plugin should be in the format
        // 'entity:[entity_type]', e.g. 'entity:node'. Extract this for later.
        $plugin_pieces = explode(':', $context->plugin);
      }

      // Add the argument, which is often a numeric ID.
      if (isset($context->argument)) {
        $cid[] = 'ctxarg_' . $context->argument;

        // If this is an entity, try looking for a revision_id too.
        if (!empty($plugin_pieces[0]) && $plugin_pieces[0] == 'entity' && !empty($plugin_pieces[1])) {
          if (isset($context->data) && is_object($context->data)) {
            list($entity_id, $revision_id, $bundle) = entity_extract_ids($plugin_pieces[1], $context->data);
            if (!empty($revision_id)) {
              $cid[] = 'ctxrev_' . $revision_id;
            }
          }
        }
      }
    }
  }

  // Granularity: Current page's user.
  if (!empty($conf['granularity']['user'])) {
    global $user;
    $cid[] = 'uid_' . $user->uid;
  }

  // Granularity: Current page's user roles.
  if (!empty($conf['granularity']['user_role'])) {
    global $user;

    // Anonymous.
    if (isset($user->roles[DRUPAL_ANONYMOUS_RID])) {
      $cid[] = 'anon';
    }
    elseif ($user->uid == 1) {
      $cid[] = 'admin';
    }
    else {

      // Clean up the settings.
      if (!empty($conf['granularity_roles_as_anon']) && is_array($conf['granularity_roles_as_anon'])) {

        // Filter out the empty values.
        $conf['granularity_roles_as_anon'] = array_filter($conf['granularity_roles_as_anon']);
      }

      // User only has one role, i.e. 'authenticated user'.
      if (count($user->roles) == 1) {

        // Optionally consider authenticated users who have no other roles to be
        // the same as anonymous users.
        if (!empty($conf['granularity_roles_as_anon'][DRUPAL_AUTHENTICATED_RID])) {
          $cid[] = 'anon';
        }
        else {
          $cid[] = 'auth';
        }
      }
      else {
        $users_roles = $user->roles;

        // Make sure the "authenticated user" role isn't caught by mistake.
        unset($users_roles[DRUPAL_AUTHENTICATED_RID]);
        $users_roles = array_keys($users_roles);

        // Check if one of the user's other roles is flagged as anonymous.
        if (array_intersect($users_roles, $conf['granularity_roles_as_anon'])) {
          $cid[] = 'anon';
        }
        else {

          // Optionally index against the first role.
          if (isset($conf['granularity_role_selection']) && $conf['granularity_role_selection'] == 'all') {
            $cid[] = 'role_' . array_shift($users_roles);
          }
          elseif (isset($conf['granularity_role_selection']) && $conf['granularity_role_selection'] == 'last') {
            $cid[] = 'role_' . array_pop($users_roles);
          }
          else {
            $cid[] = 'roles_' . implode(',', $users_roles);
          }
        }
      }
    }
  }
  if (module_exists('locale')) {
    global $language;
    $cid[] = 'lang_' . $language->language;
  }
  if (isset($_GET['page']) && !empty($pane->configuration['use_pager'])) {
    $cid[] = 'page_' . intval($_GET['page']);
  }

  // Take into consideration all configuration values, to avoid multiple panes
  // stomping on each other.
  if (!empty($pane->configuration)) {
    $options = _array_flatten($pane->configuration);

    // The pager was already accounted for.
    unset($options['use_pager']);

    // Remove empty values.
    $options = array_filter($options);
    if (!empty($options)) {
      $cid += $options;
    }
  }
  return implode(':', $cid);
}