HTMLPurifier_URI::getSchemeObj PHP Method

getSchemeObj() public method

Retrieves a scheme object corresponding to the URI's scheme/default
public getSchemeObj ( HTMLPurifier_Config $config, HTMLPurifier_Context $context ) : HTMLPurifier_URIScheme
$config HTMLPurifier_Config
$context HTMLPurifier_Context
return HTMLPurifier_URIScheme Scheme object appropriate for validating this URI
    public function getSchemeObj($config, $context)
    {
        $registry = HTMLPurifier_URISchemeRegistry::instance();
        if ($this->scheme !== null) {
            $scheme_obj = $registry->getScheme($this->scheme, $config, $context);
            if (!$scheme_obj) {
                return false;
            }
            // invalid scheme, clean it out
        } else {
            // no scheme: retrieve the default one
            $def = $config->getDefinition('URI');
            $scheme_obj = $def->getDefaultScheme($config, $context);
            if (!$scheme_obj) {
                // something funky happened to the default scheme object
                trigger_error('Default scheme object "' . $def->defaultScheme . '" was not readable', E_USER_WARNING);
                return false;
            }
        }
        return $scheme_obj;
    }

Usage Example

Esempio n. 1
0
 /**
  * @param HTMLPurifier_URI $uri
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool
  */
 public function filter(&$uri, $config, $context)
 {
     if ($context->get('EmbeddedURI', true) && !$this->doEmbed) {
         return true;
     }
     $scheme_obj = $uri->getSchemeObj($config, $context);
     if (!$scheme_obj) {
         return true;
     }
     // ignore unknown schemes, maybe another postfilter did it
     if (!$scheme_obj->browsable) {
         return true;
     }
     // ignore non-browseable schemes, since we can't munge those in a reasonable way
     if ($uri->isBenign($config, $context)) {
         return true;
     }
     // don't redirect if a benign URL
     $this->makeReplace($uri, $config, $context);
     $this->replace = array_map('rawurlencode', $this->replace);
     $new_uri = strtr($this->target, $this->replace);
     $new_uri = $this->parser->parse($new_uri);
     // don't redirect if the target host is the same as the
     // starting host
     if ($uri->host === $new_uri->host) {
         return true;
     }
     $uri = $new_uri;
     // overwrite
     return true;
 }