16
16
prepareCLIhandler ();
17
17
18
18
// All the stuff we need to build and their versions.
19
- $ buildFiles = array (
19
+ $ buildFiles = [
20
20
'index.php ' => 'SMF ' ,
21
21
22
+ 'cron.php ' => 'Root ' ,
23
+ 'subscriptions.php ' => 'Root ' ,
24
+ 'proxy.php ' => 'Root ' ,
25
+ 'SSI.php ' => 'Root ' ,
26
+
22
27
// Sources
23
- 'SSI.php ' => 'Sources ' ,
24
- 'subscriptions.php ' => 'Sources ' ,
25
- 'Sources/*.php ' => 'Sources ' ,
28
+ 'Sources/* ' => 'Sources ' ,
26
29
27
- // Tasks (SMF 2.1+)
28
- 'Sources/tasks/*.php ' => 'Tasks ' ,
30
+ // Tasks.
31
+ 'Sources/Tasks/* ' => 'Tasks ' ,
29
32
30
33
// Themes.
31
34
'Themes/default/*.php ' => 'Default ' ,
32
35
'Themes/*/*.php ' => 'Template ' ,
33
36
34
37
// Languages (keep this last in the list!)
35
38
'Themes/default/languages/*.english.php ' => 'Languages ' ,
36
- );
39
+ ];
40
+
41
+ $ skipSourceFiles = [
42
+ 'minify/* ' ,
43
+ 'ReCaptcha/* ' ,
44
+ 'Tasks/* '
45
+ ];
37
46
38
47
// Read lengths
39
- $ readLengths = array (
48
+ $ readLengths = [
40
49
'SMF ' => 4096 ,
50
+ 'Root ' => 4096 ,
41
51
'Sources ' => 4096 ,
42
52
'Tasks ' => 4096 ,
43
53
'Default ' => 768 ,
44
54
'Template ' => 768 ,
45
55
'Languages ' => 768
46
- ) ;
56
+ ] ;
47
57
48
58
// Search strings.
49
- $ searchStrings = array (
59
+ $ searchStrings = [
50
60
'SMF ' => '~\*\s@version\s+(.+)[\s]{2}~i ' ,
61
+ 'Root ' => '~\*\s@version\s+(.+)[\s]{2}~i ' ,
51
62
'Sources ' => '~\*\s@version\s+(.+)[\s]{2}~i ' ,
52
63
'Tasks ' => '~\*\s@version\s+(.+)[\s]{2}~i ' ,
53
64
'Default ' => '~\*\s@version\s+(.+)[\s]{2}~i ' ,
54
65
'Template ' => '~\*\s@version\s+(.+)[\s]{2}~i ' ,
55
66
'Languages ' => '~(?://|/\*)\s*Version:\s+(.+?);\s*~i '
56
- ) ;
67
+ ] ;
57
68
58
69
// Ignorables.
59
- $ ignoreFiles = array (
70
+ $ ignoreFiles = [
60
71
'|\./*.php~|i ' ,
61
72
'|\./*.txt|i ' ,
62
- );
63
-
64
- // SMF 2.0?
65
- if ($ cliparams ['smf ' ] == '20 ' )
66
- unset($ buildFiles ['Sources/tasks/*.php ' ]);
73
+ ];
67
74
68
75
// Skipping languages?
69
76
if (!isset ($ cliparams ['include-languages ' ]))
86
93
$ count = 0 ;
87
94
foreach ($ buildFiles as $ globPath => $ location )
88
95
{
89
- // Get a list of files.
90
- $ files = glob ($ smfRoot . $ globPath );
96
+ // Lets be specail here.
97
+ if ($ globPath == 'Sources/* ' ) {
98
+ $ files = new RecursiveIteratorIterator (
99
+ new RecursiveDirectoryIterator (
100
+ 'Sources ' . DIRECTORY_SEPARATOR ,
101
+ RecursiveDirectoryIterator::SKIP_DOTS
102
+ )
103
+ );
104
+
105
+ // Someday we could simplify this?
106
+ foreach ($ files as $ shortname => $ file )
107
+ {
108
+ if ($ file ->getFilename () === 'index.php ' || $ file ->getFilename ()[0 ] === '. ' || $ file ->getExtension () !== 'php ' )
109
+ continue ;
110
+
111
+ $ basename = basename ($ file );
112
+ foreach ($ ignoreFiles as $ if )
113
+ if (preg_match ($ if , $ basename ))
114
+ continue 2 ;
115
+
116
+ foreach ($ skipSourceFiles as $ if )
117
+ if (preg_match ('~ ' . $ if . '~i ' , $ shortname ))
118
+ continue 2 ;
119
+
120
+ // Count this.
121
+ ++$ count ;
122
+
123
+ // Open the file, read it and close it.
124
+ $ fp = fopen ($ file , 'r ' );
125
+ $ header = fread ($ fp , $ readLengths [$ location ]);
126
+ fclose ($ fp );
127
+
128
+ $ filename = str_replace ('Sources/ ' , '' , $ shortname );
129
+ if (preg_match ($ searchStrings [$ location ], $ header , $ match ) == 1 )
130
+ $ version_info [$ location ][$ filename ] = $ match [1 ];
131
+ else
132
+ $ version_info [$ location ][$ filename ] = '??? ' ;
133
+ }
134
+ }
135
+ else {
136
+ // Get a list of files.
137
+ $ files = glob ($ smfRoot . $ globPath );
91
138
92
- if (!isset ($ version_info [$ location ]))
93
- $ version_info [$ location ] = array ();
139
+ if (!isset ($ version_info [$ location ]))
140
+ $ version_info [$ location ] = array ();
94
141
95
- foreach ($ files as $ file )
96
- {
97
- $ basename = basename ($ file );
98
-
99
- // Skip index files.
100
- if ($ basename == 'index.php ' && $ location != 'SMF ' )
101
- continue ;
102
- // Skip these files.
103
- foreach ($ ignoreFiles as $ if )
104
- if (preg_match ($ if , $ basename ))
105
- continue 2 ;
106
-
107
- // Count this.
108
- ++$ count ;
109
-
110
- // Open the file, read it and close it.
111
- $ fp = fopen ($ file , 'r ' );
112
- $ header = fread ($ fp , $ readLengths [$ location ]);
113
- fclose ($ fp );
114
-
115
- if (preg_match ($ searchStrings [$ location ], $ header , $ match ) == 1 )
116
- $ version_info [$ location ][$ basename ] = $ match [1 ];
117
- else
118
- $ version_info [$ location ][$ basename ] = '??? ' ;
142
+ foreach ($ files as $ file )
143
+ {
144
+ $ basename = basename ($ file );
145
+
146
+ // Skip index files.
147
+ if ($ basename == 'index.php ' && $ location != 'SMF ' )
148
+ continue ;
149
+ // Skip these files.
150
+ foreach ($ ignoreFiles as $ if )
151
+ if (preg_match ($ if , $ basename ))
152
+ continue 2 ;
153
+
154
+ // Count this.
155
+ ++$ count ;
156
+
157
+ // Open the file, read it and close it.
158
+ $ fp = fopen ($ file , 'r ' );
159
+ $ header = fread ($ fp , $ readLengths [$ location ]);
160
+ fclose ($ fp );
161
+
162
+ if (preg_match ($ searchStrings [$ location ], $ header , $ match ) == 1 )
163
+ $ version_info [$ location ][$ basename ] = $ match [1 ];
164
+ else
165
+ $ version_info [$ location ][$ basename ] = '??? ' ;
166
+ }
119
167
}
120
168
}
121
169
@@ -184,9 +232,9 @@ function prepareCLIhandler()
184
232
if (empty ($ cliparams ) || isset ($ cliparams ['help ' ]) || isset ($ cliparams ['h ' ]))
185
233
{
186
234
echo "SMF Generate Detailed Versions Tool " . "\n"
187
- . '$ php ' . basename (__FILE__ ) . " path/to/smf/ [--output=raw] [--include-languages] [--smf=[20|21 ]] \n"
235
+ . '$ php ' . basename (__FILE__ ) . " path/to/smf/ [--output=raw] [--include-languages] [--smf=[30 ]] \n"
188
236
. "--include-languages Include Languages Versions. " . "\n"
189
- . "--smf=[21|20 ] What Version of SMF. This defaults to SMF 21 . " . "\n"
237
+ . "--smf=[30 ] What Version of SMF. This defaults to SMF 30 . " . "\n"
190
238
. "-h, --help This help file. " . "\n"
191
239
. "--output=raw Raw output. " . "\n"
192
240
. "\n" ;
@@ -195,5 +243,5 @@ function prepareCLIhandler()
195
243
196
244
// Default SMF version.
197
245
if (!isset ($ cliparams ['smf ' ]))
198
- $ cliparams ['smf ' ] = '21 ' ;
246
+ $ cliparams ['smf ' ] = '30 ' ;
199
247
}
0 commit comments