You are here

class HTMLPurifier_DefinitionCache_Drupal in HTML Purifier 7.2

Same name and namespace in other branches
  1. 5 HTMLPurifier_DefinitionCache_Drupal.php \HTMLPurifier_DefinitionCache_Drupal
  2. 6.2 HTMLPurifier_DefinitionCache_Drupal.php \HTMLPurifier_DefinitionCache_Drupal
  3. 6 HTMLPurifier_DefinitionCache_Drupal.php \HTMLPurifier_DefinitionCache_Drupal
  4. 7 HTMLPurifier_DefinitionCache_Drupal.php \HTMLPurifier_DefinitionCache_Drupal

Hierarchy

Expanded class hierarchy of HTMLPurifier_DefinitionCache_Drupal

1 string reference to 'HTMLPurifier_DefinitionCache_Drupal'
htmlpurifier_libraries_postload_callback in ./htmlpurifier.module
Registers the Drupal specific cache definition for HTML Purifier

File

./HTMLPurifier_DefinitionCache_Drupal.php, line 8

View source
class HTMLPurifier_DefinitionCache_Drupal extends HTMLPurifier_DefinitionCache {

  /**
   * Add an object to the cache without overwriting
   */
  function add($def, $config) {
    if (!$this
      ->checkDefType($def)) {
      return;
    }
    $key = $this
      ->generateKey($config);
    if ($this
      ->fetchFromDrupalCache($key)) {

      // already cached
      return FALSE;
    }
    $this
      ->storeInDrupalCache($def, $key);
    return TRUE;
  }

  /**
   * Unconditionally add an object to the cache, overwrites any existing object.
   */
  function set($def, $config) {
    if (!$this
      ->checkDefType($def)) {
      return;
    }
    $key = $this
      ->generateKey($config);
    $this
      ->storeInDrupalCache($def, $key);
    return TRUE;
  }

  /**
   * Replace an object that already exists in the cache.
   */
  function replace($def, $config) {
    if (!$this
      ->checkDefType($def)) {
      return;
    }
    $key = $this
      ->generateKey($config);
    if (!$this
      ->fetchFromDrupalCache($key)) {

      // object does not exist in cache
      return FALSE;
    }
    $this
      ->storeInDrupalCache($def, $key);
    return TRUE;
  }

  /**
   * Retrieve an object from the cache
   */
  function get($config) {
    $key = $this
      ->generateKey($config);
    return $this
      ->fetchFromDrupalCache($key);
  }

  /**
   * Delete an object from the cache
   */
  function remove($config) {
    $key = $this
      ->generateKey($config);
    cache_clear_all("htmlpurifier:{$key}", 'cache');
    return TRUE;
  }
  function flush($config) {
    cache_clear_all("htmlpurifier:*", 'cache', TRUE);
    return TRUE;
  }
  function cleanup($config) {

    // TODO: This does not work with the pluggable cache system in Drupal 7,
    // since it assumes a database cache is being used.
    $res = db_query("SELECT cid FROM {cache} WHERE cid LIKE :cid", array(
      ':cid' => 'htmlpurifier:%',
    ));
    foreach ($res as $row) {
      $key = substr($row->cid, 13);

      // 13 == strlen('htmlpurifier:')
      if ($this
        ->isOld($key, $config)) {
        cache_clear_all($row->cid, 'cache');
      }
    }
  }
  function fetchFromDrupalCache($key) {
    $cached = cache_get("htmlpurifier:{$key}");
    if ($cached) {
      return unserialize($cached->data);
    }
    return FALSE;
  }
  function storeInDrupalCache($def, $key) {
    cache_set("htmlpurifier:{$key}", serialize($def), 'cache', CACHE_PERMANENT);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HTMLPurifier_DefinitionCache_Drupal::add function Add an object to the cache without overwriting
HTMLPurifier_DefinitionCache_Drupal::cleanup function
HTMLPurifier_DefinitionCache_Drupal::fetchFromDrupalCache function
HTMLPurifier_DefinitionCache_Drupal::flush function
HTMLPurifier_DefinitionCache_Drupal::get function Retrieve an object from the cache
HTMLPurifier_DefinitionCache_Drupal::remove function Delete an object from the cache
HTMLPurifier_DefinitionCache_Drupal::replace function Replace an object that already exists in the cache.
HTMLPurifier_DefinitionCache_Drupal::set function Unconditionally add an object to the cache, overwrites any existing object.
HTMLPurifier_DefinitionCache_Drupal::storeInDrupalCache function