ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_AttrDef_URI_Host Class Reference

Validates a host according to the IPv4, IPv6 and DNS (future) specifications. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_URI_Host:
+ Collaboration diagram for HTMLPurifier_AttrDef_URI_Host:

Public Member Functions

 __construct ()
 validate ($string, $config, $context)
 Validates and cleans passed string according to a definition.
- Public Member Functions inherited from HTMLPurifier_AttrDef
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA.
 make ($string)
 Factory method for creating this class from a string.

Protected Attributes

 $ipv4
 Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator.
 $ipv6
 Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator.

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized.
 $required = false
 Tells us whether or not an HTML attribute is required.
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.

Detailed Description

Validates a host according to the IPv4, IPv6 and DNS (future) specifications.

Definition at line 6 of file Host.php.

Constructor & Destructor Documentation

HTMLPurifier_AttrDef_URI_Host::__construct ( )

Definition at line 19 of file Host.php.

{
$this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
$this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
}

Member Function Documentation

HTMLPurifier_AttrDef_URI_Host::validate (   $string,
  $config,
  $context 
)

Validates and cleans passed string according to a definition.

Parameters
$stringString to be validated and cleaned.
$configMandatory HTMLPurifier_Config object.
$contextMandatory HTMLPurifier_AttrContext object.

Reimplemented from HTMLPurifier_AttrDef.

Definition at line 24 of file Host.php.

References $config, $ipv4, and $valid.

{
$length = strlen($string);
if ($string === '') return '';
if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
//IPv6
$ip = substr($string, 1, $length - 2);
$valid = $this->ipv6->validate($ip, $config, $context);
if ($valid === false) return false;
return '['. $valid . ']';
}
// need to do checks on unusual encodings too
$ipv4 = $this->ipv4->validate($string, $config, $context);
if ($ipv4 !== false) return $ipv4;
// A regular domain name.
// This breaks I18N domain names, but we don't have proper IRI support,
// so force users to insert Punycode. If there's complaining we'll
// try to fix things into an international friendly form.
// The productions describing this are:
$a = '[a-z]'; // alpha
$an = '[a-z0-9]'; // alphanum
$and = '[a-z0-9-]'; // alphanum | "-"
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
$domainlabel = "$an($and*$an)?";
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
$toplabel = "$a($and*$an)?";
// hostname = *( domainlabel "." ) toplabel [ "." ]
$match = preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string);
if (!$match) return false;
return $string;
}

Field Documentation

HTMLPurifier_AttrDef_URI_Host::$ipv4
protected

Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator.

Definition at line 12 of file Host.php.

Referenced by validate().

HTMLPurifier_AttrDef_URI_Host::$ipv6
protected

Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator.

Definition at line 17 of file Host.php.


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