Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef / URI / Host.php
blob5344cdac252287ccbc5353dc220771b1ab01bccd
1 <?php
3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/AttrDef/URI/IPv4.php';
5 require_once 'HTMLPurifier/AttrDef/URI/IPv6.php';
7 /**
8 * Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
9 */
10 class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
13 /**
14 * Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
16 var $ipv4;
18 /**
19 * Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
21 var $ipv6;
23 function HTMLPurifier_AttrDef_URI_Host() {
24 $this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
25 $this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
28 function validate($string, $config, &$context) {
29 $length = strlen($string);
30 if ($string === '') return '';
31 if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
32 //IPv6
33 $ip = substr($string, 1, $length - 2);
34 $valid = $this->ipv6->validate($ip, $config, $context);
35 if ($valid === false) return false;
36 return '['. $valid . ']';
39 // need to do checks on unusual encodings too
40 $ipv4 = $this->ipv4->validate($string, $config, $context);
41 if ($ipv4 !== false) return $ipv4;
43 // validate a domain name here, do filtering, etc etc etc
45 // We could use this, but it would break I18N domain names
46 //$match = preg_match('/^[a-z0-9][\w\-\.]*[a-z0-9]$/i', $string);
47 //if (!$match) return false;
49 return $string;