ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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
 doValidate (&$uri, $config, $context)
 Validates the components of a URI for a specific scheme. More...
 
 validate (&$uri, $config, $context)
 Public interface for validating components of a URI. More...
 

Data Fields

 $browsable = true
 
 $allowed_types
 
 $may_omit_host = true
 
- Data Fields inherited from HTMLPurifier_URIScheme
 $default_port = null
 Scheme's default port (integer). More...
 
 $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. More...
 
 $secure = false
 Whether or not data transmitted over this scheme is encrypted. More...
 
 $hierarchical = false
 Whether or not the URI always uses <hier_part>, resolves edge cases with making relative URIs absolute. More...
 
 $may_omit_host = false
 Whether or not the URI may omit a hostname when the scheme is explicitly specified, ala file:///path/to/file. More...
 

Detailed Description

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

Definition at line 6 of file data.php.

Member Function Documentation

◆ doValidate()

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

Definition at line 20 of file data.php.

References $data, $file, and $result.

20  {
21  $result = explode(',', $uri->path, 2);
22  $is_base64 = false;
23  $charset = null;
24  $content_type = null;
25  if (count($result) == 2) {
26  list($metadata, $data) = $result;
27  // do some legwork on the metadata
28  $metas = explode(';', $metadata);
29  while(!empty($metas)) {
30  $cur = array_shift($metas);
31  if ($cur == 'base64') {
32  $is_base64 = true;
33  break;
34  }
35  if (substr($cur, 0, 8) == 'charset=') {
36  // doesn't match if there are arbitrary spaces, but
37  // whatever dude
38  if ($charset !== null) continue; // garbage
39  $charset = substr($cur, 8); // not used
40  } else {
41  if ($content_type !== null) continue; // garbage
42  $content_type = $cur;
43  }
44  }
45  } else {
46  $data = $result[0];
47  }
48  if ($content_type !== null && empty($this->allowed_types[$content_type])) {
49  return false;
50  }
51  if ($charset !== null) {
52  // error; we don't allow plaintext stuff
53  $charset = null;
54  }
55  $data = rawurldecode($data);
56  if ($is_base64) {
57  $raw_data = base64_decode($data);
58  } else {
59  $raw_data = $data;
60  }
61  // XXX probably want to refactor this into a general mechanism
62  // for filtering arbitrary content types
63  $file = tempnam("/tmp", "");
64  file_put_contents($file, $raw_data);
65  if (function_exists('exif_imagetype')) {
66  $image_code = exif_imagetype($file);
67  unlink($file);
68  } elseif (function_exists('getimagesize')) {
69  set_error_handler(array($this, 'muteErrorHandler'));
70  $info = getimagesize($file);
71  restore_error_handler();
72  unlink($file);
73  if ($info == false) return false;
74  $image_code = $info[2];
75  } else {
76  trigger_error("could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
77  }
78  $real_content_type = image_type_to_mime_type($image_code);
79  if ($real_content_type != $content_type) {
80  // we're nice guys; if the content type is something else we
81  // support, change it over
82  if (empty($this->allowed_types[$real_content_type])) return false;
83  $content_type = $real_content_type;
84  }
85  // ok, it's kosher, rewrite what we need
86  $uri->userinfo = null;
87  $uri->host = null;
88  $uri->port = null;
89  $uri->fragment = null;
90  $uri->query = null;
91  $uri->path = "$content_type;base64," . base64_encode($raw_data);
92  return true;
93  }
print $file
$result
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data

◆ muteErrorHandler()

HTMLPurifier_URIScheme_data::muteErrorHandler (   $errno,
  $errstr 
)

Definition at line 95 of file data.php.

95 {}

Field Documentation

◆ $allowed_types

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.

◆ $browsable

HTMLPurifier_URIScheme_data::$browsable = true

Definition at line 8 of file data.php.

◆ $may_omit_host

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: