00001 <?php
00002
00006 class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
00007 {
00008
00012 protected $ipv4;
00013
00017 protected $ipv6;
00018
00019 public function __construct() {
00020 $this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
00021 $this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
00022 }
00023
00024 public function validate($string, $config, $context) {
00025 $length = strlen($string);
00026 if ($string === '') return '';
00027 if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
00028
00029 $ip = substr($string, 1, $length - 2);
00030 $valid = $this->ipv6->validate($ip, $config, $context);
00031 if ($valid === false) return false;
00032 return '['. $valid . ']';
00033 }
00034
00035
00036 $ipv4 = $this->ipv4->validate($string, $config, $context);
00037 if ($ipv4 !== false) return $ipv4;
00038
00039
00040
00041
00042
00043
00044
00045
00046 $a = '[a-z]';
00047 $an = '[a-z0-9]';
00048 $and = '[a-z0-9-]';
00049
00050 $domainlabel = "$an($and*$an)?";
00051
00052 $toplabel = "$a($and*$an)?";
00053
00054 $match = preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string);
00055 if (!$match) return false;
00056
00057 return $string;
00058 }
00059
00060 }
00061