scratch – Blame information for rev 126
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
126 | office | 1 | <?php |
2 | /** |
||
3 | * |
||
4 | * Builds the PSL data array from the parts of a text line. |
||
5 | * |
||
6 | * @param array &$data The PSL data array. |
||
7 | * |
||
8 | * @param array $parts The parts of a PSL text line. |
||
9 | * |
||
10 | * @return void |
||
11 | * |
||
12 | */ |
||
13 | function build(array &$data, array $parts) |
||
14 | { |
||
15 | $part = array_pop($parts); |
||
16 | $is_domain = true; |
||
17 | |||
18 | if (strpos($part, '!') === 0) { |
||
19 | $part = substr($part, 1); |
||
20 | $is_domain = false; |
||
21 | } |
||
22 | |||
23 | if (! array_key_exists($part, $data)) { |
||
24 | if ($is_domain) { |
||
25 | $data[$part] = array(); |
||
26 | } else { |
||
27 | $data[$part] = array('!' => ''); |
||
28 | } |
||
29 | } |
||
30 | |||
31 | if ($is_domain && count($parts) > 0) { |
||
32 | build($data[$part], $parts); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * Update the public suffix list files. |
||
39 | * |
||
40 | */ |
||
41 | |||
42 | // get the origin text file |
||
43 | $text = file_get_contents('http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1'); |
||
44 | $lines = explode("\n", $text); |
||
45 | |||
46 | // convert text lines to data |
||
47 | $data = []; |
||
48 | foreach ($lines as $line) { |
||
49 | // massage the line |
||
50 | $line = trim($line); |
||
51 | // skip empty and comment lines |
||
52 | if (! $line || substr($line, 0, 2) == '//') { |
||
53 | continue; |
||
54 | } |
||
55 | // get the line parts and build into the psl data |
||
56 | $parts = explode('.', $line); |
||
57 | build($data, $parts); |
||
58 | } |
||
59 | |||
60 | // write the data to a PHP file |
||
61 | $code = '<?php' . PHP_EOL . 'return ' . var_export($data, true) . ';'; |
||
62 | $file = dirname(__DIR__) . DIRECTORY_SEPARATOR |
||
63 | . 'data' . DIRECTORY_SEPARATOR |
||
64 | . 'public-suffix-list.php'; |
||
65 | file_put_contents($file, $code); |
||
66 | |||
67 | // done! |
||
68 | exit(0); |