forked from SimpleMachines/BuildTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-version.php
More file actions
executable file
·55 lines (46 loc) · 1.77 KB
/
Copy pathcheck-version.php
File metadata and controls
executable file
·55 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2021 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 RC3
*/
$versions = array();
$years = array();
foreach (array('./index.php', './SSI.php', './cron.php', './proxy.php', './other/install.php', './other/upgrade.php') as $path)
{
$contents = file_get_contents($path, false, null, 0, 1250);
if (!preg_match('/define\(\'SMF_VERSION\', \'([^\']+)\'\);/i', $contents, $versionResults))
fatalError('Error: Could not locate SMF_VERSION in ' . $path . "\n");
$versions[$versionResults[1]][] = $path;
if (!preg_match('/define\(\'SMF_SOFTWARE_YEAR\', \'(\d{4})\'\);/i', $contents, $yearResults))
fatalError('Error: Could not locate SMF_SOFTWARE_YEAR in ' . $path . "\n");
$years[$yearResults[1]][] = $path;
}
if (count($versions) != 1)
{
$errmsg = 'Error: SMF_VERSION differs between files.';
foreach ($versions as $version => $paths)
$errmsg .= ' "' . $version . '" in ' . implode(', ', $paths) . '.';
fatalError($errmsg);
}
if (count($years) != 1)
{
$errmsg = 'Error: SMF_SOFTWARE_YEAR differs between files.';
foreach ($years as $year => $paths)
$errmsg .= ' "' . $year . '" in ' . implode(', ', $paths) . '.';
fatalError($errmsg);
}
if (!preg_match('~^((\d+)\.(\d+)[. ]?((?:(?<= )(?>RC|Beta |Alpha ))?\d+)?)$~', key($versions)))
fatalError('Error: SMF_VERSION string is invalid: "' . key($versions) . '"');
if (($headyear = (int) substr(shell_exec('git show -s --format=%ci HEAD'), 0, 4)) > (int) key($years))
fatalError('Error: SMF_SOFTWARE_YEAR is ' . (int) key($years) . ', should be ' . $headyear . '.');
function fatalError($msg)
{
fwrite(STDERR, $msg);
die;
}