ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_URIScheme_data Class Reference

Implements data: URI for base64 encoded images supported by GD. More...

+ Inheritance diagram for HTMLPurifier_URIScheme_data:
+ Collaboration diagram for HTMLPurifier_URIScheme_data:

Public Member Functions

 doValidate (&$uri, $config, $context)
 Validates the components of a URI for a specific scheme.
 muteErrorHandler ($errno, $errstr)
- Public Member Functions inherited from HTMLPurifier_URIScheme
 validate (&$uri, $config, $context)
 Public interface for validating components of a URI.

Data Fields

 $browsable = true
 $allowed_types
 $may_omit_host = true
- Data Fields inherited from HTMLPurifier_URIScheme
 $default_port = null
 Scheme's default port (integer).
 $browsable = false
 Whether or not URIs of this schem are locatable by a browser http and ftp are accessible, while mailto and news are not.
 $secure = false
 Whether or not data transmitted over this scheme is encrypted.
 $hierarchical = false
 Whether or not the URI always uses <hier_part>, resolves edge cases with making relative URIs absolute.
 $may_omit_host = false
 Whether or not the URI may omit a hostname when the scheme is explicitly specified, ala file:///path/to/file.

Detailed Description

Implements data: URI for base64 encoded images supported by GD.

Definition at line 6 of file data.php.

Member Function Documentation

HTMLPurifier_URIScheme_data::doValidate ( $uri,
  $config,
  $context 
)

Validates the components of a URI for a specific scheme.

Parameters
$uriReference to a HTMLPurifier_URI object
$configHTMLPurifier_Config object
$contextHTMLPurifier_Context object
Returns
Bool success or failure

Reimplemented from HTMLPurifier_URIScheme.

Definition at line 20 of file data.php.

References $data, $file, and $result.

{
$result = explode(',', $uri->path, 2);
$is_base64 = false;
$charset = null;
$content_type = null;
if (count($result) == 2) {
list($metadata, $data) = $result;
// do some legwork on the metadata
$metas = explode(';', $metadata);
while(!empty($metas)) {
$cur = array_shift($metas);
if ($cur == 'base64') {
$is_base64 = true;
break;
}
if (substr($cur, 0, 8) == 'charset=') {
// doesn't match if there are arbitrary spaces, but
// whatever dude
if ($charset !== null) continue; // garbage
$charset = substr($cur, 8); // not used
} else {
if ($content_type !== null) continue; // garbage
$content_type = $cur;
}
}
} else {
$data = $result[0];
}
if ($content_type !== null && empty($this->allowed_types[$content_type])) {
return false;
}
if ($charset !== null) {
// error; we don't allow plaintext stuff
$charset = null;
}
$data = rawurldecode($data);
if ($is_base64) {
$raw_data = base64_decode($data);
} else {
$raw_data = $data;
}
// XXX probably want to refactor this into a general mechanism
// for filtering arbitrary content types
$file = tempnam("/tmp", "");
file_put_contents($file, $raw_data);
if (function_exists('exif_imagetype')) {
$image_code = exif_imagetype($file);
} elseif (function_exists('getimagesize')) {
set_error_handler(array($this, 'muteErrorHandler'));
$info = getimagesize($file);
restore_error_handler();
if ($info == false) return false;
$image_code = $info[2];
} else {
trigger_error("could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
}
$real_content_type = image_type_to_mime_type($image_code);
if ($real_content_type != $content_type) {
// we're nice guys; if the content type is something else we
// support, change it over
if (empty($this->allowed_types[$real_content_type])) return false;
$content_type = $real_content_type;
}
// ok, it's kosher, rewrite what we need
$uri->userinfo = null;
$uri->host = null;
$uri->port = null;
$uri->fragment = null;
$uri->query = null;
$uri->path = "$content_type;base64," . base64_encode($raw_data);
return true;
}
HTMLPurifier_URIScheme_data::muteErrorHandler (   $errno,
  $errstr 
)

Definition at line 93 of file data.php.

{}

Field Documentation

HTMLPurifier_URIScheme_data::$allowed_types
Initial value:
array(
'image/jpeg' => true,
'image/gif' => true,
'image/png' => true,
)

Definition at line 9 of file data.php.

HTMLPurifier_URIScheme_data::$browsable = true

Definition at line 8 of file data.php.

HTMLPurifier_URIScheme_data::$may_omit_host = true

Definition at line 18 of file data.php.


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