1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of michaelbutler/phposh. |
||
5 | * Source: https://github.com/michaelbutler/phposh |
||
6 | * |
||
7 | * (c) Michael Butler <[email protected]> |
||
8 | * |
||
9 | * This source file is subject to the MIT license that is bundled |
||
10 | * with this source code in the file named LICENSE. |
||
11 | */ |
||
12 | |||
13 | // automatically change/randomize all the Hex based identifiers (a-f, 0-9) |
||
14 | |||
15 | $inputFile = $argv[1] ?? null; |
||
16 | if (!$inputFile) { |
||
17 | echo "ERROR: Input file argument required as argument 1.\n"; |
||
18 | exit(1); |
||
19 | } |
||
20 | |||
21 | $contents = file_get_contents($inputFile); |
||
22 | if (!$contents) { |
||
23 | echo "ERROR: Input file {$inputFile} is empty.\n"; |
||
24 | exit(1); |
||
25 | } |
||
26 | |||
27 | // First find all hex ids and create a map |
||
28 | $hexIds = []; |
||
29 | |||
30 | $matches = []; |
||
31 | preg_match_all('/([a-f0-9]{20,40})/', $contents, $matches); |
||
32 | |||
33 | if (empty($matches[1])) { |
||
34 | echo "No ids found. Exiting.\n"; |
||
35 | exit(0); |
||
36 | } |
||
37 | |||
38 | $allIds = array_unique($matches[1]); |
||
39 | $allIds = array_flip($allIds); |
||
40 | |||
41 | foreach ($allIds as $origId => $null) { |
||
42 | $allIds[$origId] = substr(hash('sha512', $origId), 0, 24); |
||
43 | } |
||
44 | |||
45 | $contents = str_replace(array_keys($allIds), array_values($allIds), $contents); |
||
46 | |||
47 | // CUSTOM REPLACEMENTS |
||
48 | if (true) { |
||
49 | // $matches = []; |
||
50 | // preg_match_all('/Buyer: <span class=\\\"value\\\">([^<]+)<\/span>/i', $contents, $matches); |
||
51 | // print_r($matches); |
||
52 | $contents = preg_replace_callback('/Buyer: <span class=\\\"value\\\">([^<]+)<\/span>/i', static function ($matches) { |
||
0 ignored issues
–
show
|
|||
53 | return 'Buyer: <span class=\\"value\\">Shopper' . random_int(1000, 99999999) . '</span>'; |
||
54 | }, $contents); |
||
55 | } |
||
56 | |||
57 | echo $contents; |
||
58 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.