Skip to content

Commit b94efc4

Browse files
committed
Update logic to build detailed versions for SMF 3.0
1 parent d183f2d commit b94efc4

File tree

1 file changed

+96
-48
lines changed

1 file changed

+96
-48
lines changed

generateDetailedVersion.php

+96-48
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,61 @@
1616
prepareCLIhandler();
1717

1818
// All the stuff we need to build and their versions.
19-
$buildFiles = array(
19+
$buildFiles = [
2020
'index.php' => 'SMF',
2121

22+
'cron.php' => 'Root',
23+
'subscriptions.php' => 'Root',
24+
'proxy.php' => 'Root',
25+
'SSI.php' => 'Root',
26+
2227
// Sources
23-
'SSI.php' => 'Sources',
24-
'subscriptions.php' => 'Sources',
25-
'Sources/*.php' => 'Sources',
28+
'Sources/*' => 'Sources',
2629

27-
// Tasks (SMF 2.1+)
28-
'Sources/tasks/*.php' => 'Tasks',
30+
// Tasks.
31+
'Sources/Tasks/*' => 'Tasks',
2932

3033
// Themes.
3134
'Themes/default/*.php' => 'Default',
3235
'Themes/*/*.php' => 'Template',
3336

3437
// Languages (keep this last in the list!)
3538
'Themes/default/languages/*.english.php' => 'Languages',
36-
);
39+
];
40+
41+
$skipSourceFiles = [
42+
'minify/*',
43+
'ReCaptcha/*',
44+
'Tasks/*'
45+
];
3746

3847
// Read lengths
39-
$readLengths = array(
48+
$readLengths = [
4049
'SMF' => 4096,
50+
'Root' => 4096,
4151
'Sources' => 4096,
4252
'Tasks' => 4096,
4353
'Default' => 768,
4454
'Template' => 768,
4555
'Languages' => 768
46-
);
56+
];
4757

4858
// Search strings.
49-
$searchStrings = array(
59+
$searchStrings = [
5060
'SMF' => '~\*\s@version\s+(.+)[\s]{2}~i',
61+
'Root' => '~\*\s@version\s+(.+)[\s]{2}~i',
5162
'Sources' => '~\*\s@version\s+(.+)[\s]{2}~i',
5263
'Tasks' => '~\*\s@version\s+(.+)[\s]{2}~i',
5364
'Default' => '~\*\s@version\s+(.+)[\s]{2}~i',
5465
'Template' => '~\*\s@version\s+(.+)[\s]{2}~i',
5566
'Languages' => '~(?://|/\*)\s*Version:\s+(.+?);\s*~i'
56-
);
67+
];
5768

5869
// Ignorables.
59-
$ignoreFiles = array(
70+
$ignoreFiles = [
6071
'|\./*.php~|i',
6172
'|\./*.txt|i',
62-
);
63-
64-
// SMF 2.0?
65-
if ($cliparams['smf'] == '20')
66-
unset($buildFiles['Sources/tasks/*.php']);
73+
];
6774

6875
// Skipping languages?
6976
if (!isset($cliparams['include-languages']))
@@ -86,36 +93,77 @@
8693
$count = 0;
8794
foreach ($buildFiles as $globPath => $location)
8895
{
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);
91138

92-
if (!isset($version_info[$location]))
93-
$version_info[$location] = array();
139+
if (!isset($version_info[$location]))
140+
$version_info[$location] = array();
94141

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+
}
119167
}
120168
}
121169

@@ -184,9 +232,9 @@ function prepareCLIhandler()
184232
if (empty($cliparams) || isset($cliparams['help']) || isset($cliparams['h']))
185233
{
186234
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"
188236
. "--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"
190238
. "-h, --help This help file.". "\n"
191239
. "--output=raw Raw output.". "\n"
192240
. "\n";
@@ -195,5 +243,5 @@ function prepareCLIhandler()
195243

196244
// Default SMF version.
197245
if (!isset($cliparams['smf']))
198-
$cliparams['smf'] = '21';
246+
$cliparams['smf'] = '30';
199247
}

0 commit comments

Comments
 (0)