ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_AttrDef_CSS_URI Class Reference

Validates a URI in CSS syntax, which uses url('http://example.com') More...

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_URI:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_URI:

Public Member Functions

 __construct ()
 validate ($uri_string, $config, $context)
 Validates and cleans passed string according to a definition.
- Public Member Functions inherited from HTMLPurifier_AttrDef_URI
 __construct ($embeds_resource=false)
 make ($string)
 Factory method for creating this class from a string.
- Public Member Functions inherited from HTMLPurifier_AttrDef
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA.

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized.
 $required = false
 Tells us whether or not an HTML attribute is required.
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.
- Protected Attributes inherited from HTMLPurifier_AttrDef_URI
 $parser
 $embedsResource

Detailed Description

Validates a URI in CSS syntax, which uses url('http://example.com')

Note
While theoretically speaking a URI in a CSS document could be non-embedded, as of CSS2 there is no such usage so we're generalizing it. This may need to be changed in the future.
Warning
Since HTMLPurifier_AttrDef_CSS blindly uses semicolons as the separator, you cannot put a literal semicolon in in the URI. Try percent encoding it, in that case.

Definition at line 12 of file URI.php.

Constructor & Destructor Documentation

HTMLPurifier_AttrDef_CSS_URI::__construct ( )

Definition at line 15 of file URI.php.

{
parent::__construct(true); // always embedded
}

Member Function Documentation

HTMLPurifier_AttrDef_CSS_URI::validate (   $string,
  $config,
  $context 
)

Validates and cleans passed string according to a definition.

Parameters
$stringString to be validated and cleaned.
$configMandatory HTMLPurifier_Config object.
$contextMandatory HTMLPurifier_AttrContext object.

Reimplemented from HTMLPurifier_AttrDef_URI.

Definition at line 19 of file URI.php.

References $config, $result, and HTMLPurifier_AttrDef\parseCDATA().

{
// parse the URI out of the string and then pass it onto
// the parent object
$uri_string = $this->parseCDATA($uri_string);
if (strpos($uri_string, 'url(') !== 0) return false;
$uri_string = substr($uri_string, 4);
$new_length = strlen($uri_string) - 1;
if ($uri_string[$new_length] != ')') return false;
$uri = trim(substr($uri_string, 0, $new_length));
if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) {
$quote = $uri[0];
$new_length = strlen($uri) - 1;
if ($uri[$new_length] !== $quote) return false;
$uri = substr($uri, 1, $new_length - 1);
}
$keys = array( '(', ')', ',', ' ', '"', "'");
$values = array('\\(', '\\)', '\\,', '\\ ', '\\"', "\\'");
$uri = str_replace($values, $keys, $uri);
$result = parent::validate($uri, $config, $context);
if ($result === false) return false;
// escape necessary characters according to CSS spec
// except for the comma, none of these should appear in the
// URI at all
$result = str_replace($keys, $values, $result);
return "url($result)";
}

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: