These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* PROJECT: ReactOS Translation Tool |
||
3 | * LICENSE: GPL |
||
4 | * AUTHORS: Adam Stachowicz <[email protected]> |
||
5 | * AUTHOR URL: http://it-maniak.pl/ |
||
6 | */ |
||
7 | |||
8 | include_once 'header.php'; |
||
9 | ?> |
||
10 | |||
11 | <h1>Search for wrong encoded files</h1> |
||
12 | |||
13 | <div id="body"> |
||
14 | <center> |
||
15 | <form method="GET" class="form-horizontal"> |
||
16 | <fieldset> |
||
17 | <legend>Please type your <a href="https://beta.wikiversity.org/wiki/List_of_ISO_639-1_codes">language code in ISO 639-1</a>. For example: pl for Polish, de for German</legend> |
||
18 | <div class="form-group"> |
||
19 | <label class="col-md-4 control-label" for="lang">Language code:</label> |
||
20 | <div class="col-md-4"> |
||
21 | <input type="text" value="<?php echo isset($_SESSION['lang']) ? $_SESSION['lang'] : '' ?>" id="lang" name="lang" class="form-control input-md" required="required" autofocus="autofocus" pattern="[A-Za-z]{2}" title="Two letter language code"/> |
||
22 | </div> |
||
23 | </div> |
||
24 | <div class="form-group"> |
||
25 | <label class="col-md-4 control-label" for="dir">Directories:</label> |
||
26 | <div class="col-md-4"> |
||
27 | <select id="dir" name="dir" class="form-control"> |
||
28 | <option value="1">base, boot</option> |
||
29 | <option value="2" <?php if (isset($_GET['dir']) && $_GET['dir'] == '2') { |
||
30 | echo 'selected'; |
||
31 | }?>>dll</option> |
||
32 | <option value="3" <?php if (isset($_GET['dir']) && $_GET['dir'] == '3') { |
||
33 | echo 'selected'; |
||
34 | }?>>media, subsystems, win32ss</option> |
||
35 | <option value="100" <?php if (isset($_GET['dir']) && $_GET['dir'] == '100') { |
||
36 | echo 'selected'; |
||
37 | }?>>All ReactOS Source dir</option> |
||
38 | </select> |
||
39 | </div> |
||
40 | </div> |
||
41 | <div class="form-group"> |
||
42 | <button type="submit" class="btn btn-primary">Search</button> |
||
43 | </div> |
||
44 | </fieldset> |
||
45 | </form> |
||
46 | </center> |
||
47 | <br> |
||
48 | |||
49 | <?php |
||
50 | if (isset($_GET['lang']) && !empty($_GET['lang']) && isset($_GET['dir']) && is_numeric($_GET['dir'])) { |
||
51 | $it = new AppendIterator(); |
||
52 | |||
53 | // Switch for directories |
||
54 | View Code Duplication | switch ($_GET['dir']) { |
|
0 ignored issues
–
show
|
|||
55 | case '1': |
||
56 | $directories = [ |
||
57 | new RecursiveDirectoryIterator($ROSDir.'base/applications'), |
||
58 | new RecursiveDirectoryIterator($ROSDir.'base/setup'), |
||
59 | new RecursiveDirectoryIterator($ROSDir.'base/shell'), |
||
60 | new RecursiveDirectoryIterator($ROSDir.'base/system'), |
||
61 | new RecursiveDirectoryIterator($ROSDir.'boot/freeldr/fdebug'), |
||
62 | ]; |
||
63 | break; |
||
64 | |||
65 | case '2': |
||
66 | $directories = [ |
||
67 | new RecursiveDirectoryIterator($ROSDir.'dll/cpl'), |
||
68 | new RecursiveDirectoryIterator($ROSDir.'dll/shellext'), |
||
69 | new RecursiveDirectoryIterator($ROSDir.'dll/win32'), |
||
70 | ]; |
||
71 | break; |
||
72 | |||
73 | case '3': |
||
74 | $directories = [ |
||
75 | new RecursiveDirectoryIterator($ROSDir.'media/themes'), |
||
76 | new RecursiveDirectoryIterator($ROSDir.'subsystems/mvdm/ntvdm'), |
||
77 | new RecursiveDirectoryIterator($ROSDir.'win32ss/user'), |
||
78 | ]; |
||
79 | break; |
||
80 | |||
81 | case '100': |
||
82 | $directories = [ |
||
83 | new RecursiveDirectoryIterator($ROSDir), |
||
84 | ]; |
||
85 | break; |
||
86 | |||
87 | default: |
||
88 | echo 'Something is wrong! Please try again.'; |
||
89 | exit; |
||
90 | } |
||
91 | |||
92 | foreach ($directories as $directory) { |
||
93 | $it->append(new RecursiveIteratorIterator($directory)); |
||
94 | } |
||
95 | |||
96 | $regex = new RegexIterator($it, '/^.+'.$langDir.'.+('.$originLang.')\.'.$fileExt.'$/i', RecursiveRegexIterator::GET_MATCH); |
||
97 | |||
98 | $allWrongEnc = 0; |
||
99 | |||
100 | $lang = htmlspecialchars($_GET['lang']); |
||
101 | // Search for eg. PL,Pl,pl |
||
102 | $fileSearch = strtoupper($lang).','.ucfirst($lang).','.strtolower($lang); |
||
103 | |||
104 | // UTF-8 BOM starts with EF BB BF |
||
105 | define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF)); |
||
106 | |||
107 | $regex->rewind(); |
||
108 | while ($regex->valid()) { |
||
109 | if (!$regex->isDot()) { |
||
110 | $file = glob($regex->getPathInfo().'/*{'.$fileSearch.'}*.'.$fileExt, GLOB_BRACE); |
||
111 | |||
112 | $isFile = array_filter($file); |
||
113 | |||
114 | if (!empty($isFile)) { |
||
115 | $text = file_get_contents($file[0]); |
||
116 | // UTF-8 is good |
||
117 | if (mb_check_encoding($text, 'UTF-8')) { |
||
118 | $first3 = substr($text, 0, 3); |
||
119 | // But UTF-8 with BOM not! |
||
120 | if ($first3 === UTF8_BOM) { |
||
121 | echo 'Detected <b>UTF-8 BOM</b> in '.$file[0].'<br>'; |
||
122 | $allWrongEnc++; |
||
123 | } |
||
124 | } else { |
||
125 | // Other encoding |
||
126 | echo 'Detected <b>other encoding</b> in '.$file[0].'<br>'; |
||
127 | $allWrongEnc++; |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | $regex->next(); |
||
132 | } |
||
133 | echo "<h3>All files with wrong encoding: $allWrongEnc</h3>"; |
||
134 | } |
||
135 | |||
136 | include_once 'footer.php'; |
||
137 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.