IDAccumulator.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Component of HTMLPurifier_AttrContext that accumulates IDs to prevent dupes
  4. * @note In Slashdot-speak, dupe means duplicate.
  5. * @note The default constructor does not accept $config or $context objects:
  6. * use must use the static build() factory method to perform initialization.
  7. */
  8. class HTMLPurifier_IDAccumulator
  9. {
  10. /**
  11. * Lookup table of IDs we've accumulated.
  12. * @public
  13. */
  14. public $ids = array();
  15. /**
  16. * Builds an IDAccumulator, also initializing the default blacklist
  17. * @param $config Instance of HTMLPurifier_Config
  18. * @param $context Instance of HTMLPurifier_Context
  19. * @return Fully initialized HTMLPurifier_IDAccumulator
  20. */
  21. public static function build($config, $context) {
  22. $id_accumulator = new HTMLPurifier_IDAccumulator();
  23. $id_accumulator->load($config->get('Attr.IDBlacklist'));
  24. return $id_accumulator;
  25. }
  26. /**
  27. * Add an ID to the lookup table.
  28. * @param $id ID to be added.
  29. * @return Bool status, true if success, false if there's a dupe
  30. */
  31. public function add($id) {
  32. if (isset($this->ids[$id])) return false;
  33. return $this->ids[$id] = true;
  34. }
  35. /**
  36. * Load a list of IDs into the lookup table
  37. * @param $array_of_ids Array of IDs to load
  38. * @note This function doesn't care about duplicates
  39. */
  40. public function load($array_of_ids) {
  41. foreach ($array_of_ids as $id) {
  42. $this->ids[$id] = true;
  43. }
  44. }
  45. }
  46. // vim: et sw=4 sts=4