PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/vjCommentPlugin/lib/tools/htmlpurifier/library/HTMLPurifier/AttrDef/CSS/ListStyle.php

https://bitbucket.org/Kudlaty/360kdw
PHP | 78 lines | 46 code | 18 blank | 14 comment | 15 complexity | 3d888cc157a4ea616dc1e94dd5f1c21e MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Validates shorthand CSS property list-style.
  4. * @warning Does not support url tokens that have internal spaces.
  5. */
  6. class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
  7. {
  8. /**
  9. * Local copy of component validators.
  10. * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
  11. */
  12. protected $info;
  13. public function __construct($config) {
  14. $def = $config->getCSSDefinition();
  15. $this->info['list-style-type'] = $def->info['list-style-type'];
  16. $this->info['list-style-position'] = $def->info['list-style-position'];
  17. $this->info['list-style-image'] = $def->info['list-style-image'];
  18. }
  19. public function validate($string, $config, $context) {
  20. // regular pre-processing
  21. $string = $this->parseCDATA($string);
  22. if ($string === '') return false;
  23. // assumes URI doesn't have spaces in it
  24. $bits = explode(' ', strtolower($string)); // bits to process
  25. $caught = array();
  26. $caught['type'] = false;
  27. $caught['position'] = false;
  28. $caught['image'] = false;
  29. $i = 0; // number of catches
  30. $none = false;
  31. foreach ($bits as $bit) {
  32. if ($i >= 3) return; // optimization bit
  33. if ($bit === '') continue;
  34. foreach ($caught as $key => $status) {
  35. if ($status !== false) continue;
  36. $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
  37. if ($r === false) continue;
  38. if ($r === 'none') {
  39. if ($none) continue;
  40. else $none = true;
  41. if ($key == 'image') continue;
  42. }
  43. $caught[$key] = $r;
  44. $i++;
  45. break;
  46. }
  47. }
  48. if (!$i) return false;
  49. $ret = array();
  50. // construct type
  51. if ($caught['type']) $ret[] = $caught['type'];
  52. // construct image
  53. if ($caught['image']) $ret[] = $caught['image'];
  54. // construct position
  55. if ($caught['position']) $ret[] = $caught['position'];
  56. if (empty($ret)) return false;
  57. return implode(' ', $ret);
  58. }
  59. }
  60. // vim: et sw=4 sts=4