You are here

function ajaxblocks_update_cache in Ajax Blocks 7

Same name and namespace in other branches
  1. 6 ajaxblocks.module \ajaxblocks_update_cache()

Stores AJAX settings for the blocks in the system cache table.

2 calls to ajaxblocks_update_cache()
ajaxblocks_is_ajax in ./ajaxblocks.module
Returns TRUE if the block is configured to be loaded via AJAX. Block specific settings are also returned.
ajaxblocks_save_settings in ./ajaxblocks.module
Additional submit handler for block settings form. Saves AJAX settings for the block.

File

./ajaxblocks.module, line 153
Loads dynamic blocks on cached page for anonymous users by performing AJAX request.

Code

function ajaxblocks_update_cache() {
  $block_roles = array();
  foreach (db_query('SELECT * FROM {block_role}') as $data) {
    $block_id = $data->module . '-' . $data->delta;
    if (!array_key_exists($block_id, $block_roles)) {
      $block_roles[$block_id] = array();
    }
    $block_roles[$block_id][] = $data->rid;
  }
  $ajax_block_data = array();
  foreach (db_query('SELECT * FROM {ajaxblocks} WHERE is_ajax = 1', array(), array(
    'fetch' => PDO::FETCH_ASSOC,
  )) as $data) {
    $roles = trim($data['cached_roles']);
    $data['cached_roles'] = explode(' ', $roles);
    if ($roles == '') {
      $data['cached_roles'] = array();
    }
    $roles = trim($data['uncached_roles']);
    $data['uncached_roles'] = explode(' ', $roles);
    if ($roles == '') {
      $data['uncached_roles'] = array();
    }
    $block_id = $data['block_id'];
    if (!array_key_exists($block_id, $block_roles)) {
      $block_roles[$block_id] = array();
    }
    $data['role_permission'] = $block_roles[$block_id];
    $ajax_block_data[$block_id] = $data;
  }
  cache_set('ajaxblocks', $ajax_block_data);
  return $ajax_block_data;
}