Release 2.1.3, merged in 1404 to HEAD.
[htmlpurifier/bfroehle.git] / library / HTMLPurifier / IDAccumulator.php
blobc9f58835b0781ddc6fa316b5c93e08a5d42b9ae0
1 <?php
3 HTMLPurifier_ConfigSchema::define(
4 'Attr', 'IDBlacklist', array(), 'list',
5 'Array of IDs not allowed in the document.'
6 );
8 /**
9 * Component of HTMLPurifier_AttrContext that accumulates IDs to prevent dupes
10 * @note In Slashdot-speak, dupe means duplicate.
11 * @note The default constructor does not accept $config or $context objects:
12 * use must use the static build() factory method to perform initialization.
14 class HTMLPurifier_IDAccumulator
17 /**
18 * Lookup table of IDs we've accumulated.
19 * @public
21 var $ids = array();
23 /**
24 * Builds an IDAccumulator, also initializing the default blacklist
25 * @param $config Instance of HTMLPurifier_Config
26 * @param $context Instance of HTMLPurifier_Context
27 * @return Fully initialized HTMLPurifier_IDAccumulator
28 * @static
30 static function build($config, &$context) {
31 $id_accumulator = new HTMLPurifier_IDAccumulator();
32 $id_accumulator->load($config->get('Attr', 'IDBlacklist'));
33 return $id_accumulator;
36 /**
37 * Add an ID to the lookup table.
38 * @param $id ID to be added.
39 * @return Bool status, true if success, false if there's a dupe
41 function add($id) {
42 if (isset($this->ids[$id])) return false;
43 return $this->ids[$id] = true;
46 /**
47 * Load a list of IDs into the lookup table
48 * @param $array_of_ids Array of IDs to load
49 * @note This function doesn't care about duplicates
51 function load($array_of_ids) {
52 foreach ($array_of_ids as $id) {
53 $this->ids[$id] = true;