Database towns table support for TFS 1.3

This commit is contained in:
tobi132 2019-12-03 01:11:52 +01:00
parent f85fad447e
commit 668387e372
3 changed files with 39 additions and 2 deletions

1
TODO
View File

@ -83,7 +83,6 @@ x.x - At any time between (version not specified)
* possibility to add extra cache engines with plugins
* preferably configurable (enable/disable) forum TinyMCE editor
* OTAdmin support in Admin Panel
* database towns table support for TFS 1.3
* two factor authentication for TFS 1.x
* support for .yml plugin file specification
* display password strength

View File

@ -159,6 +159,7 @@ $config = array(
'character_name_max_length' => 21,
// list of towns
// if you use TFS 1.3 with support for 'towns' table in database, then you can ignore this - it will be configured automatically (generated from your .OTBM map)
'towns' => array(
0 => 'No town',
1 => 'Sample town'

View File

@ -171,4 +171,41 @@ else {
}
}
*/
?>
////////////////////////////////////////
// load towns from database (TFS 1.3) //
////////////////////////////////////////
$towns = array();
if($cache->enabled() && $cache->fetch('towns', $tmp)) {
$towns = unserialize($tmp);
}
else {
if($db->hasTable('towns')) {
$query = $db->query('SELECT `id`, `name` FROM `towns`;')->fetchAll(PDO::FETCH_ASSOC);
foreach($query as $town) {
$towns[$town['id']] = $town['name'];
}
unset($query);
if($cache->enabled()) {
$cache->set('towns', serialize($towns), 600);
}
}
else if($cache->enabled()) {
$cache->set('towns', serialize(array()), 600);
}
}
$configTowns = config('towns');
if($configTowns !== null && (!isset($configTowns[1]) || $configTowns[1] !== 'Sample town')) {
$towns = array_replace(
$towns, $configTowns
);
}
config(['towns', $towns]);
//////////////////////////////////////////////
// END - load towns from database (TFS 1.3) //
//////////////////////////////////////////////