ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
HTMLPurifier_URIFilter_Munge Class Reference
+ Inheritance diagram for HTMLPurifier_URIFilter_Munge:
+ Collaboration diagram for HTMLPurifier_URIFilter_Munge:

Public Member Functions

 prepare ($config)
 
 filter (&$uri, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_URIFilter
 prepare ($config)
 Performs initialization for the filter. More...
 
 filter (&$uri, $config, $context)
 Filter a URI object. More...
 

Data Fields

 $name = 'Munge'
 string More...
 
 $post = true
 bool More...
 
- Data Fields inherited from HTMLPurifier_URIFilter
 $name
 Unique identifier of filter. More...
 
 $post = false
 True if this filter should be run after scheme validation. More...
 
 $always_load = false
 True if this filter should always be loaded. More...
 

Protected Member Functions

 makeReplace ($uri, $config, $context)
 

Protected Attributes

 $replace = array()
 array More...
 

Private Attributes

 $target
 string More...
 
 $parser
 HTMLPurifier_URIParser More...
 
 $doEmbed
 bool More...
 
 $secretKey
 string More...
 

Detailed Description

Definition at line 3 of file Munge.php.

Member Function Documentation

◆ filter()

HTMLPurifier_URIFilter_Munge::filter ( $uri,
  $config,
  $context 
)
Parameters
HTMLPurifier_URI$uri
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool

Definition at line 62 of file Munge.php.

References $doEmbed, and makeReplace().

63  {
64  if ($context->get('EmbeddedURI', true) && !$this->doEmbed) {
65  return true;
66  }
67 
68  $scheme_obj = $uri->getSchemeObj($config, $context);
69  if (!$scheme_obj) {
70  return true;
71  } // ignore unknown schemes, maybe another postfilter did it
72  if (!$scheme_obj->browsable) {
73  return true;
74  } // ignore non-browseable schemes, since we can't munge those in a reasonable way
75  if ($uri->isBenign($config, $context)) {
76  return true;
77  } // don't redirect if a benign URL
78 
79  $this->makeReplace($uri, $config, $context);
80  $this->replace = array_map('rawurlencode', $this->replace);
81 
82  $new_uri = strtr($this->target, $this->replace);
83  $new_uri = $this->parser->parse($new_uri);
84  // don't redirect if the target host is the same as the
85  // starting host
86  if ($uri->host === $new_uri->host) {
87  return true;
88  }
89  $uri = $new_uri; // overwrite
90  return true;
91  }
makeReplace($uri, $config, $context)
Definition: Munge.php:98
+ Here is the call graph for this function:

◆ makeReplace()

HTMLPurifier_URIFilter_Munge::makeReplace (   $uri,
  $config,
  $context 
)
protected
Parameters
HTMLPurifier_URI$uri
HTMLPurifier_Config$config
HTMLPurifier_Context$context

Definition at line 98 of file Munge.php.

Referenced by filter().

99  {
100  $string = $uri->toString();
101  // always available
102  $this->replace['%s'] = $string;
103  $this->replace['%r'] = $context->get('EmbeddedURI', true);
104  $token = $context->get('CurrentToken', true);
105  $this->replace['%n'] = $token ? $token->name : null;
106  $this->replace['%m'] = $context->get('CurrentAttr', true);
107  $this->replace['%p'] = $context->get('CurrentCSSProperty', true);
108  // not always available
109  if ($this->secretKey) {
110  $this->replace['%t'] = hash_hmac("sha256", $string, $this->secretKey);
111  }
112  }
+ Here is the caller graph for this function:

◆ prepare()

HTMLPurifier_URIFilter_Munge::prepare (   $config)
Parameters
HTMLPurifier_Config$config
Returns
bool

Definition at line 44 of file Munge.php.

45  {
46  $this->target = $config->get('URI.' . $this->name);
47  $this->parser = new HTMLPurifier_URIParser();
48  $this->doEmbed = $config->get('URI.MungeResources');
49  $this->secretKey = $config->get('URI.MungeSecretKey');
50  if ($this->secretKey && !function_exists('hash_hmac')) {
51  throw new Exception("Cannot use %URI.MungeSecretKey without hash_hmac support.");
52  }
53  return true;
54  }
Parses a URI into the components and fragment identifier as specified by RFC 3986.
Definition: URIParser.php:7

Field Documentation

◆ $doEmbed

HTMLPurifier_URIFilter_Munge::$doEmbed
private

bool

Definition at line 28 of file Munge.php.

Referenced by filter().

◆ $name

HTMLPurifier_URIFilter_Munge::$name = 'Munge'

string

Definition at line 8 of file Munge.php.

◆ $parser

HTMLPurifier_URIFilter_Munge::$parser
private

HTMLPurifier_URIParser

Definition at line 23 of file Munge.php.

◆ $post

HTMLPurifier_URIFilter_Munge::$post = true

bool

Definition at line 13 of file Munge.php.

◆ $replace

HTMLPurifier_URIFilter_Munge::$replace = array()
protected

array

Definition at line 38 of file Munge.php.

◆ $secretKey

HTMLPurifier_URIFilter_Munge::$secretKey
private

string

Definition at line 33 of file Munge.php.

◆ $target

HTMLPurifier_URIFilter_Munge::$target
private

string

Definition at line 18 of file Munge.php.


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