| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: |
|
| 7: | class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
| 8: | {
|
| 9: |
|
| 10: | |
| 11: | |
| 12: |
|
| 13: | protected $parser;
|
| 14: |
|
| 15: | |
| 16: | |
| 17: |
|
| 18: | protected $embedsResource;
|
| 19: |
|
| 20: | |
| 21: | |
| 22: |
|
| 23: | public function __construct($embeds_resource = false)
|
| 24: | {
|
| 25: | $this->parser = new HTMLPurifier_URIParser();
|
| 26: | $this->embedsResource = (bool)$embeds_resource;
|
| 27: | }
|
| 28: |
|
| 29: | |
| 30: | |
| 31: | |
| 32: |
|
| 33: | public function make($string)
|
| 34: | {
|
| 35: | $embeds = ($string === 'embedded');
|
| 36: | return new HTMLPurifier_AttrDef_URI($embeds);
|
| 37: | }
|
| 38: |
|
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: |
|
| 45: | public function validate($uri, $config, $context)
|
| 46: | {
|
| 47: | if ($config->get('URI.Disable')) {
|
| 48: | return false;
|
| 49: | }
|
| 50: |
|
| 51: | $uri = $this->parseCDATA($uri);
|
| 52: |
|
| 53: |
|
| 54: | $uri = $this->parser->parse($uri);
|
| 55: | if ($uri === false) {
|
| 56: | return false;
|
| 57: | }
|
| 58: |
|
| 59: |
|
| 60: | $context->register('EmbeddedURI', $this->embedsResource);
|
| 61: |
|
| 62: | $ok = false;
|
| 63: | do {
|
| 64: |
|
| 65: |
|
| 66: | $result = $uri->validate($config, $context);
|
| 67: | if (!$result) {
|
| 68: | break;
|
| 69: | }
|
| 70: |
|
| 71: |
|
| 72: | $uri_def = $config->getDefinition('URI');
|
| 73: | $result = $uri_def->filter($uri, $config, $context);
|
| 74: | if (!$result) {
|
| 75: | break;
|
| 76: | }
|
| 77: |
|
| 78: |
|
| 79: | $scheme_obj = $uri->getSchemeObj($config, $context);
|
| 80: | if (!$scheme_obj) {
|
| 81: | break;
|
| 82: | }
|
| 83: | if ($this->embedsResource && !$scheme_obj->browsable) {
|
| 84: | break;
|
| 85: | }
|
| 86: | $result = $scheme_obj->validate($uri, $config, $context);
|
| 87: | if (!$result) {
|
| 88: | break;
|
| 89: | }
|
| 90: |
|
| 91: |
|
| 92: | $result = $uri_def->postFilter($uri, $config, $context);
|
| 93: | if (!$result) {
|
| 94: | break;
|
| 95: | }
|
| 96: |
|
| 97: |
|
| 98: | $ok = true;
|
| 99: |
|
| 100: | } while (false);
|
| 101: |
|
| 102: | $context->destroy('EmbeddedURI');
|
| 103: | if (!$ok) {
|
| 104: | return false;
|
| 105: | }
|
| 106: |
|
| 107: | return $uri->toString();
|
| 108: | }
|
| 109: | }
|
| 110: |
|
| 111: |
|
| 112: | |