HTMLPurifier/AttrDef/URI.php Quellcode

URI.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
8 {
9 
13  protected $parser;
14 
18  protected $embedsResource;
19 
23  public function __construct($embeds_resource = false)
24  {
25  $this->parser = new HTMLPurifier_URIParser();
26  $this->embedsResource = (bool)$embeds_resource;
27  }
28 
33  public function make($string)
34  {
35  $embeds = ($string === 'embedded');
36  return new HTMLPurifier_AttrDef_URI($embeds);
37  }
38 
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  // parse the URI
54  $uri = $this->parser->parse($uri);
55  if ($uri === false) {
56  return false;
57  }
58 
59  // add embedded flag to context for validators
60  $context->register('EmbeddedURI', $this->embedsResource);
61 
62  $ok = false;
63  do {
64 
65  // generic validation
66  $result = $uri->validate($config, $context);
67  if (!$result) {
68  break;
69  }
70 
71  // chained filtering
72  $uri_def = $config->getDefinition('URI');
73  $result = $uri_def->filter($uri, $config, $context);
74  if (!$result) {
75  break;
76  }
77 
78  // scheme-specific validation
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  // Post chained filtering
92  $result = $uri_def->postFilter($uri, $config, $context);
93  if (!$result) {
94  break;
95  }
96 
97  // survived gauntlet
98  $ok = true;
99 
100  } while (false);
101 
102  $context->destroy('EmbeddedURI');
103  if (!$ok) {
104  return false;
105  }
106  // back to string
107  return $uri->toString();
108  }
109 }
110 
111 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.