| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: |
|
| 6: | class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
|
| 7: | {
|
| 8: | |
| 9: | |
| 10: | |
| 11: |
|
| 12: | public $elements = array();
|
| 13: |
|
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: | protected $whitespace = false;
|
| 19: |
|
| 20: | |
| 21: | |
| 22: |
|
| 23: | public function __construct($elements)
|
| 24: | {
|
| 25: | if (is_string($elements)) {
|
| 26: | $elements = str_replace(' ', '', $elements);
|
| 27: | $elements = explode('|', $elements);
|
| 28: | }
|
| 29: | $keys = array_keys($elements);
|
| 30: | if ($keys == array_keys($keys)) {
|
| 31: | $elements = array_flip($elements);
|
| 32: | foreach ($elements as $i => $x) {
|
| 33: | $elements[$i] = true;
|
| 34: | if (empty($i)) {
|
| 35: | unset($elements[$i]);
|
| 36: | }
|
| 37: | }
|
| 38: | }
|
| 39: | $this->elements = $elements;
|
| 40: | }
|
| 41: |
|
| 42: | |
| 43: | |
| 44: |
|
| 45: | public $allow_empty = false;
|
| 46: |
|
| 47: | |
| 48: | |
| 49: |
|
| 50: | public $type = 'required';
|
| 51: |
|
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: |
|
| 58: | public function validateChildren($children, $config, $context)
|
| 59: | {
|
| 60: |
|
| 61: | $this->whitespace = false;
|
| 62: |
|
| 63: |
|
| 64: | if (empty($children)) {
|
| 65: | return false;
|
| 66: | }
|
| 67: |
|
| 68: |
|
| 69: | $result = array();
|
| 70: |
|
| 71: |
|
| 72: |
|
| 73: |
|
| 74: | $pcdata_allowed = isset($this->elements['#PCDATA']);
|
| 75: |
|
| 76: |
|
| 77: | $all_whitespace = true;
|
| 78: |
|
| 79: | $stack = array_reverse($children);
|
| 80: | while (!empty($stack)) {
|
| 81: | $node = array_pop($stack);
|
| 82: | if (!empty($node->is_whitespace)) {
|
| 83: | $result[] = $node;
|
| 84: | continue;
|
| 85: | }
|
| 86: | $all_whitespace = false;
|
| 87: |
|
| 88: | if (!isset($this->elements[$node->name])) {
|
| 89: |
|
| 90: |
|
| 91: | if ($pcdata_allowed && $node instanceof HTMLPurifier_Node_Text) {
|
| 92: | $result[] = $node;
|
| 93: | continue;
|
| 94: | }
|
| 95: |
|
| 96: |
|
| 97: | if ($node instanceof HTMLPurifier_Node_Element) {
|
| 98: | for ($i = count($node->children) - 1; $i >= 0; $i--) {
|
| 99: | $stack[] = $node->children[$i];
|
| 100: | }
|
| 101: | continue;
|
| 102: | }
|
| 103: | continue;
|
| 104: | }
|
| 105: | $result[] = $node;
|
| 106: | }
|
| 107: | if (empty($result)) {
|
| 108: | return false;
|
| 109: | }
|
| 110: | if ($all_whitespace) {
|
| 111: | $this->whitespace = true;
|
| 112: | return false;
|
| 113: | }
|
| 114: | return $result;
|
| 115: | }
|
| 116: | }
|
| 117: |
|
| 118: |
|
| 119: | |