Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

58 rindas
1.6KB

  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 HTMLPurifier_Config $config Instance of HTMLPurifier_Config
  18. * @param HTMLPurifier_Context $context Instance of HTMLPurifier_Context
  19. * @return HTMLPurifier_IDAccumulator Fully initialized HTMLPurifier_IDAccumulator
  20. */
  21. public static function build($config, $context)
  22. {
  23. $id_accumulator = new HTMLPurifier_IDAccumulator();
  24. $id_accumulator->load($config->get('Attr.IDBlacklist'));
  25. return $id_accumulator;
  26. }
  27. /**
  28. * Add an ID to the lookup table.
  29. * @param string $id ID to be added.
  30. * @return bool status, true if success, false if there's a dupe
  31. */
  32. public function add($id)
  33. {
  34. if (isset($this->ids[$id])) {
  35. return false;
  36. }
  37. return $this->ids[$id] = true;
  38. }
  39. /**
  40. * Load a list of IDs into the lookup table
  41. * @param $array_of_ids Array of IDs to load
  42. * @note This function doesn't care about duplicates
  43. */
  44. public function load($array_of_ids)
  45. {
  46. foreach ($array_of_ids as $id) {
  47. $this->ids[$id] = true;
  48. }
  49. }
  50. }
  51. // vim: et sw=4 sts=4