ILIAS  Release_5_0_x_branch Revision 61816
 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)
 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
 bool
 $allowed_types
 array
 $may_omit_host = true
 bool
- Data Fields inherited from HTMLPurifier_URIScheme
 $default_port = null
 Scheme's default port (integer).
 $browsable = false
 Whether or not URIs of this scheme 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 bool.
 $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 
)
Parameters
HTMLPurifier_URI$uri
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool

Reimplemented from HTMLPurifier_URIScheme.

Definition at line 36 of file data.php.

References $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);
unlink($file);
} elseif (function_exists('getimagesize')) {
set_error_handler(array($this, 'muteErrorHandler'));
$info = getimagesize($file);
restore_error_handler();
unlink($file);
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 
)
Parameters
int$errno
string$errstr

Definition at line 124 of file data.php.

{
}

Field Documentation

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

array

Definition at line 16 of file data.php.

HTMLPurifier_URIScheme_data::$browsable = true

bool

Definition at line 11 of file data.php.

HTMLPurifier_URIScheme_data::$may_omit_host = true

bool

Definition at line 28 of file data.php.


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