Source for file URI.php

Documentation is available at URI.php

  1. <?php
  2.  
  3. /**
  4.  * Validates a URI as defined by RFC 3986.
  5.  * @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme
  6.  */
  7. {
  8.     
  9.     protected $parser;
  10.     protected $embedsResource;
  11.     
  12.     /**
  13.      * @param $embeds_resource_resource Does the URI here result in an extra HTTP request?
  14.      */
  15.     public function __construct($embeds_resource false{
  16.         $this->parser = new HTMLPurifier_URIParser();
  17.         $this->embedsResource = (bool) $embeds_resource;
  18.     }
  19.     
  20.     public function make($string{
  21.         $embeds = (bool) $string;
  22.         return new HTMLPurifier_AttrDef_URI($embeds);
  23.     }
  24.     
  25.     public function validate($uri$config$context{
  26.         
  27.         if ($config->get('URI''Disable')) return false;
  28.         
  29.         $uri $this->parseCDATA($uri);
  30.         
  31.         // parse the URI
  32.         $uri $this->parser->parse($uri);
  33.         if ($uri === falsereturn false;
  34.         
  35.         // add embedded flag to context for validators
  36.         $context->register('EmbeddedURI'$this->embedsResource)
  37.         
  38.         $ok false;
  39.         do {
  40.             
  41.             // generic validation
  42.             $result $uri->validate($config$context);
  43.             if (!$resultbreak;
  44.             
  45.             // chained filtering
  46.             $uri_def $config->getDefinition('URI');
  47.             $result $uri_def->filter($uri$config$context);
  48.             if (!$resultbreak;
  49.             
  50.             // scheme-specific validation 
  51.             $scheme_obj $uri->getSchemeObj($config$context);
  52.             if (!$scheme_objbreak;
  53.             if ($this->embedsResource && !$scheme_obj->browsablebreak;
  54.             $result $scheme_obj->validate($uri$config$context);
  55.             if (!$resultbreak;
  56.             
  57.             // Post chained filtering
  58.             $result $uri_def->postFilter($uri$config$context);
  59.             if (!$resultbreak;
  60.             
  61.             // survived gauntlet
  62.             $ok true;
  63.             
  64.         while (false);
  65.         
  66.         $context->destroy('EmbeddedURI');
  67.         if (!$okreturn false;
  68.         
  69.         // back to string
  70.         return $uri->toString();
  71.         
  72.     }
  73.     
  74. }

Documentation generated on Thu, 19 Jun 2008 18:50:27 -0400 by phpDocumentor 1.4.2