You are here

function esi_get_settings in ESI: Edge Side Includes 6.2

Get / Set the config for a particular block.

Parameters

$id: The ID for the configuration.

$config: (optinal) If this is set, it will save the settings passed in.

Return value

The saved configuration for the given ID.

6 calls to esi_get_settings()
context_reaction_esi_block::build_block in plugins/context_reaction_esi_block.inc
esi_form_block_admin_configure_alter in ./esi.module
Implementation of hook_form_FORM_ID_alter(). for block_admin_configure Add ESI-configuration options to the block-config pages.
esi__block_config_save in ./esi.module
Form-submit handler for ESI settings in block-config
esi__block_handler in ./esi.module
Menu handler for ESIs
esi__theme_blocks in ./esi.theme.inc
Replacement for core theme function: thene_blocks

... See full list

File

./esi.inc, line 142
Helper functions for the ESI module.

Code

function esi_get_settings($id, $config = NULL) {

  // TODO: replace with something more suited to in-code config than variables.
  $settings = variable_get('esi_block_config', array());
  if ($config) {
    while (!lock_acquire('esi_block_config')) {
      lock_wait('esi_block_config');
    }

    // Now that we have a lock, grab the settings from the database.
    $settings = unserialize(db_result(db_query("SELECT value FROM {variable} WHERE name = 'esi_block_config'")));
    $settings[$id] = $config;
    variable_set('esi_block_config', $settings);
    lock_release('esi_block_config');
  }
  elseif (!empty($settings[$id])) {
    $config = $settings[$id];
  }

  // Set defaults.
  if (!is_array($config)) {
    $config = array();
  }
  if (!isset($config['max_age'])) {
    $config['max_age'] = (int) variable_get('esi_block_default_max_age', ESI_BLOCK_DEFAULT_MAX_AGE);
  }
  if (!isset($config['scope'])) {
    $config['scope'] = (int) variable_get('esi_block_default_scope', ESI_BLOCK_DEFAULT_SCOPE);
  }

  // Return the configuration for this ID.
  return $config;
}