Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions check-smf-languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,33 @@
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 1
* @version 3.0 Alpha 3
*/

// Stuff we will ignore.
global $ignoreFiles, $currentVersion;

$ignoreFiles = [
'index\.php',
'\.(?!php)[^.]*$',
];

try {
if (($upgradeFile = fopen('./other/upgrade.php', 'r')) !== false) {
$upgradeContents = fread($upgradeFile, 1250);

// In production, only check index.english.php
if (!preg_match('~define\(\'SMF_VERSION\', \'([^\']+)\'\);~i', $upgradeContents, $versionResults)) {
throw new Exception('Error: Could not locate SMF_VERSION');
}
if (version_compare($versionResults[1], '2.1.0', '>')) {
$ignoreFiles[] = '^(?!index\.)';
}
if (($indexFile = fopen('./index.php', 'r')) === false) {
throw new Exception('Unable to open file ./index.php');
}

// We need SMF_LANG_VERSION, obviously.
if (!preg_match('~define\(\'SMF_LANG_VERSION\', \'([^\']+)\'\);~i', $upgradeContents, $versionResults)) {
throw new Exception('Error: Could not locate SMF_LANG_VERSION');
}
$currentVersion = $versionResults[1];
$indexContents = fread($indexFile, 1250);

if (!file_exists('./Languages')) {
checkLanguageDirectory('./Themes/default/languages', '~([A-Za-z]+)\.english\.php~i');
} else {
checkLanguageDirectory('./Languages/en_US', '~([A-Za-z]+)\.php~i');
// foreach (new DirectoryIterator('./Languages') as $dirInfo)
// if(!in_array($dirInfo->getFileName(), ['.', '..']) && is_dir($dirInfo->getPathname()))
// checkLanguageDirectory($dirInfo->getPathname());
}
} else {
throw new Exception('Unable to open file ./upgrade.php');
if (!preg_match('~define\(\'SMF_VERSION\', \'([^\']+)\'\);~i', $indexContents, $versionResults)) {
throw new Exception('Error: Could not locate SMF_VERSION');
}
}
catch (Exception $e) {

$currentVersion = $versionResults[1];
$ignoreFiles[] = '^(?!General\.)';

checkLanguageDirectory('./Languages/en_US', '~([A-Za-z]+)\.php~i');
} catch (Exception $e) {
fwrite(STDERR, $e->getMessage());
exit(1);
}
Expand Down Expand Up @@ -95,4 +81,4 @@ function checkLanguageDirectory($language_dir, $search)
}
}
}
}
}