2006-07-23 21:07:30 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Object that provides entity lookup table from entity name to character
|
|
|
|
*/
|
2006-07-23 21:07:30 +00:00
|
|
|
class HTMLPurifier_EntityLookup {
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Assoc array of entity name to character represented.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-23 21:07:30 +00:00
|
|
|
var $table;
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Sets up the entity lookup table from the serialized file contents.
|
|
|
|
* @note The serialized contents are versioned, but were generated
|
|
|
|
* using the maintenance script generate_entity_file.php
|
|
|
|
* @warning This is not in constructor to help enforce the Singleton
|
|
|
|
*/
|
2006-07-24 11:35:46 +00:00
|
|
|
function setup($file = false) {
|
2006-07-23 21:07:30 +00:00
|
|
|
if (!$file) {
|
2006-09-30 20:18:08 +00:00
|
|
|
$file = dirname(__FILE__) . '/EntityLookup/entities.ser';
|
2006-07-23 21:07:30 +00:00
|
|
|
}
|
|
|
|
$this->table = unserialize(file_get_contents($file));
|
|
|
|
}
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Retrieves sole instance of the object.
|
|
|
|
* @param Optional prototype of custom lookup table to overload with.
|
|
|
|
*/
|
2006-07-24 11:35:46 +00:00
|
|
|
function instance($prototype = false) {
|
2006-07-23 21:07:30 +00:00
|
|
|
// no references, since PHP doesn't copy unless modified
|
|
|
|
static $instance = null;
|
2006-07-24 11:35:46 +00:00
|
|
|
if ($prototype) {
|
|
|
|
$instance = $prototype;
|
|
|
|
} elseif (!$instance) {
|
2006-07-23 21:07:30 +00:00
|
|
|
$instance = new HTMLPurifier_EntityLookup();
|
2006-07-24 11:35:46 +00:00
|
|
|
$instance->setup();
|
2006-07-23 21:07:30 +00:00
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|