HTMLPurifier_DefinitionCache_Drupal.php in HTML Purifier 6
File
HTMLPurifier_DefinitionCache_Drupal.php
View source
<?php
require_once 'HTMLPurifier/DefinitionCache.php';
class HTMLPurifier_DefinitionCache_Drupal extends HTMLPurifier_DefinitionCache {
function add($def, $config) {
if (!$this
->checkDefType($def)) {
return;
}
$key = $this
->generateKey($config);
if ($this
->fetchFromDrupalCache($key)) {
return false;
}
$this
->storeInDrupalCache($def, $key);
return true;
}
function set($def, $config) {
if (!$this
->checkDefType($def)) {
return;
}
$key = $this
->generateKey($config);
$this
->storeInDrupalCache($def, $key);
return true;
}
function replace($def, $config) {
if (!$this
->checkDefType($def)) {
return;
}
$key = $this
->generateKey($config);
if (!$this
->fetchFromDrupalCache($key)) {
return false;
}
$this
->storeInDrupalCache($def, $key);
return true;
}
function get($config) {
$key = $this
->generateKey($config);
return $this
->fetchFromDrupalCache($key);
}
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) {
$res = db_query("SELECT cid FROM {cache} WHERE cid LIKE '%s%%'", 'htmlpurifier:');
while ($row = db_fetch_object($res)) {
$key = substr($row->cid, 13);
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);
}
}