Source for file URI.php

Documentation is available at URI.php

  1. <?php
  2.  
  3. /**
  4.  * Validates a URI in CSS syntax, which uses url('http://example.com')
  5.  * @note While theoretically speaking a URI in a CSS document could
  6.  *        be non-embedded, as of CSS2 there is no such usage so we're
  7.  *        generalizing it. This may need to be changed in the future.
  8.  * @warning Since HTMLPurifier_AttrDef_CSS blindly uses semicolons as
  9.  *           the separator, you cannot put a literal semicolon in
  10.  *           in the URI. Try percent encoding it, in that case.
  11.  */
  12. {
  13.     
  14.     public function __construct({
  15.         parent::__construct(true)// always embedded
  16.     }
  17.     
  18.     public function validate($uri_string$config$context{
  19.         // parse the URI out of the string and then pass it onto
  20.         // the parent object
  21.         
  22.         $uri_string $this->parseCDATA($uri_string);
  23.         if (strpos($uri_string'url('!== 0return false;
  24.         $uri_string substr($uri_string4);
  25.         $new_length strlen($uri_string1;
  26.         if ($uri_string[$new_length!= ')'return false;
  27.         $uri trim(substr($uri_string0$new_length));
  28.         
  29.         if (!empty($uri&& ($uri[0== "'" || $uri[0== '"')) {
  30.             $quote $uri[0];
  31.             $new_length strlen($uri1;
  32.             if ($uri[$new_length!== $quotereturn false;
  33.             $uri substr($uri1$new_length 1);
  34.         }
  35.         
  36.         $keys   array(  '(',   ')',   ',',   ' ',   '"',   "'");
  37.         $values array('\\(''\\)''\\,''\\ ''\\"'"\\'");
  38.         $uri str_replace($values$keys$uri);
  39.         
  40.         $result parent::validate($uri$config$context);
  41.         
  42.         if ($result === falsereturn false;
  43.         
  44.         // escape necessary characters according to CSS spec
  45.         // except for the comma, none of these should appear in the
  46.         // URI at all
  47.         $result str_replace($keys$values$result);
  48.         
  49.         return "url($result)";
  50.         
  51.     }
  52.     
  53. }

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