ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
 @type bool More...
 
 $allowed_types
 @type array More...
 
 $may_omit_host = true
 @type bool More...
 
- Data Fields inherited from HTMLPurifier_URIScheme
 $default_port = null
 Scheme's default port (integer). More...
 
 $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. 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 @type bool. 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 
)
Parameters
HTMLPurifier_URI$uri
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool

Reimplemented from HTMLPurifier_URIScheme.

Definition at line 36 of file data.php.

37 {
38 $result = explode(',', $uri->path, 2);
39 $is_base64 = false;
40 $charset = null;
41 $content_type = null;
42 if (count($result) == 2) {
43 list($metadata, $data) = $result;
44 // do some legwork on the metadata
45 $metas = explode(';', $metadata);
46 while (!empty($metas)) {
47 $cur = array_shift($metas);
48 if ($cur == 'base64') {
49 $is_base64 = true;
50 break;
51 }
52 if (substr($cur, 0, 8) == 'charset=') {
53 // doesn't match if there are arbitrary spaces, but
54 // whatever dude
55 if ($charset !== null) {
56 continue;
57 } // garbage
58 $charset = substr($cur, 8); // not used
59 } else {
60 if ($content_type !== null) {
61 continue;
62 } // garbage
63 $content_type = $cur;
64 }
65 }
66 } else {
67 $data = $result[0];
68 }
69 if ($content_type !== null && empty($this->allowed_types[$content_type])) {
70 return false;
71 }
72 if ($charset !== null) {
73 // error; we don't allow plaintext stuff
74 $charset = null;
75 }
76 $data = rawurldecode($data);
77 if ($is_base64) {
78 $raw_data = base64_decode($data);
79 } else {
80 $raw_data = $data;
81 }
82 // XXX probably want to refactor this into a general mechanism
83 // for filtering arbitrary content types
84 $file = tempnam("/tmp", "");
85 file_put_contents($file, $raw_data);
86 if (function_exists('exif_imagetype')) {
87 $image_code = exif_imagetype($file);
88 unlink($file);
89 } elseif (function_exists('getimagesize')) {
90 set_error_handler(array($this, 'muteErrorHandler'));
91 $info = getimagesize($file);
92 restore_error_handler();
93 unlink($file);
94 if ($info == false) {
95 return false;
96 }
97 $image_code = $info[2];
98 } else {
99 trigger_error("could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
100 }
101 $real_content_type = image_type_to_mime_type($image_code);
102 if ($real_content_type != $content_type) {
103 // we're nice guys; if the content type is something else we
104 // support, change it over
105 if (empty($this->allowed_types[$real_content_type])) {
106 return false;
107 }
108 $content_type = $real_content_type;
109 }
110 // ok, it's kosher, rewrite what we need
111 $uri->userinfo = null;
112 $uri->host = null;
113 $uri->port = null;
114 $uri->fragment = null;
115 $uri->query = null;
116 $uri->path = "$content_type;base64," . base64_encode($raw_data);
117 return true;
118 }
$result
print $file
$data
$info
Definition: example_052.php:80

References $data, $file, $info, and $result.

◆ muteErrorHandler()

HTMLPurifier_URIScheme_data::muteErrorHandler (   $errno,
  $errstr 
)
Parameters
int$errno
string$errstr

Definition at line 124 of file data.php.

125 {
126 }

Field Documentation

◆ $allowed_types

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

@type array

Definition at line 16 of file data.php.

◆ $browsable

HTMLPurifier_URIScheme_data::$browsable = true

@type bool

Definition at line 11 of file data.php.

◆ $may_omit_host

HTMLPurifier_URIScheme_data::$may_omit_host = true

@type bool

Definition at line 28 of file data.php.


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