diff --git a/TODO b/TODO index 3f2d4b30..822b7a7e 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/config.php b/config.php index 415a9b0f..285c16b6 100644 --- a/config.php +++ b/config.php @@ -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' diff --git a/system/init.php b/system/init.php index 61d72352..21660880 100644 --- a/system/init.php +++ b/system/init.php @@ -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) // +//////////////////////////////////////////////