10 define(
'LIST_URL',
'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1');
12 define(
'OUTPUT_FILE', dirname(__FILE__) .
'/public-suffix-list.php');
14 require_once
'HTTP/Request2.php';
18 $part = trim(array_pop($tldParts));
20 if (!array_key_exists($part, $node)) {
21 $node[$part] = array();
24 if (0 < count($tldParts)) {
29 function writeNode($fp, $valueTree, $key = null, $indent = 0)
32 fwrite($fp,
"return ");
35 fwrite($fp, str_repeat(
' ', $indent) .
"'$key' => ");
38 if (0 == ($count = count($valueTree))) {
41 fwrite($fp,
"array(\n");
42 for ($keys = array_keys($valueTree), $i = 0; $i < $count; $i++) {
43 writeNode($fp, $valueTree[$keys[$i]], $keys[$i], $indent + 1);
44 if ($i + 1 != $count) {
50 fwrite($fp, str_repeat(
' ', $indent) .
")");
59 throw new Exception(
"List download URL returned status: " .
63 if (
false === strpos(
$list,
'// ===BEGIN ICANN DOMAINS===')) {
64 throw new Exception(
"List download URL does not contain expected phrase");
67 throw new Exception(
"Unable to open " .
OUTPUT_FILE);
70 }
catch (Exception $e) {
71 die($e->getMessage());
77 fwrite($fp,
"<?php\n");
79 foreach (array_filter(array_map(
'trim', explode(
"\n",
$list))) as $line) {
80 if (
'//' != substr($line, 0, 2)) {
84 if (0 === strpos($line,
"// ===BEGIN ICANN DOMAINS===")) {
88 fwrite($fp, $line .
"\n");