function getTopPowergamers($limit = 5) {
global $db;
$cache = Cache::getInstance();
if($cache->enabled()) {
$tmp = '';
if($cache->fetch('toppow_' . $limit . '_level', $tmp)) {
$players = unserialize($tmp);
}
}
if (!isset($players)) {
$deleted = 'deleted';
if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion';
$is_tfs10 = $db->hasTable('players_online');
$players = $db->query('SELECT `id`, `name`, `level`, `exphist1` as `experience`, `looktype`' . ($db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `lookhead`, `lookbody`, `looklegs`, `lookfeet`' . ($is_tfs10 ? '' : ', `online`') . ' FROM `players` WHERE `group_id` < ' . config('highscores_groups_hidden') . ' AND `id` NOT IN (' . implode(', ', config('highscores_ids_hidden')) . ') AND `' . $deleted . '` = 0 AND `account_id` != 1 ORDER BY `exphist1` DESC LIMIT ' . (int)$limit)->fetchAll();
if($is_tfs10) {
foreach($players as &$player) {
$query = $db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $player['id']);
$player['online'] = ($query->rowCount() > 0 ? 1 : 0);
}
unset($player);
}
$i = 0;
foreach($players as &$player) {
$player['rank'] = ++$i;
}
unset($player);
if($cache->enabled()) {
$cache->set('toppow_' . $limit . '_level', serialize($players), 120);
}
}
return $players;
}