public static function assignAsLoop($loopCodename, $loop) { if (is_array($loop)) { $l = new TPLLoop($loopCodename); foreach ($loop as $loopItem) { $item = new TPLLoopItem(); foreach ($loopItem as $key => $value) { if ($key != 'conds') { $item->add($key, $value); } else { foreach ($value as $key => $value) { $item->cond($key, (bool) $value); } } } $l->append($item); } $l->pack(); } }
public function getOnlineUsers($count = 0, $groups = array(), $loop_key = 'ONLINE_USERS') { $sql = new SQLObject(); $cfg = core::s('cfg'); $query = "\r\nSELECT\r\n\t" . $sql->table('auth_users') . ".user_id AS user_id,\r\n\t" . $sql->table('auth_users') . ".user_username AS user_username,\r\n\t" . $sql->table('auth_users') . ".user_group_main AS user_group_main,\r\n\t" . $sql->table('auth_users') . ".session_last_time AS session_last_time,\r\n\t" . $sql->table('auth_groups') . ".group_name AS group_name\r\nFROM " . $sql->table('auth_users') . "\r\nLEFT JOIN " . $sql->table('auth_groups') . "\r\n\tON " . $sql->table('auth_users') . ".user_group_main = " . $sql->table('auth_groups') . ".group_id\r\nWHERE (session_last_time >= " . (time() - $cfg['etc']['core']['online_offset']); if ($groups) { $query .= " AND ("; $i = 0; foreach ($groups as $group_id) { $query .= " user_groups LIKE '%" . $group_id . "%'"; if ($i != count($groups) - 1) { $query .= " AND"; } else { $query .= ")"; } $i++; } } $query .= ") ORDER BY session_last_time DESC"; if ($count) { $query .= " LIMIT 0," . (int) $count; } if (!$sql->query($query)) { TPL::cond($loop_key, false); core::s('tpl')->assignLoop($loop_key, array()); echo $sql->error; } else { TPL::cond($loop_key, true); $users = new TPLLoop($loop_key); foreach ($sql->fetch() as $user) { $item = new TPLLoopItem(); $item->add('USER_ID', $user->user_id); $item->add('USER_USERNAME', $user->user_username); $item->add('USER_GROUP', $user->user_group_main); $item->add('USER_SESSION_TIME_OFFSET', $this->getSessionTimeOffset($user->session_last_time)); $item->cond('ADMIN', in_array(1, (array) $groups) || (int) $user->user_group_main == 1); $users->append($item); } $users->pack(); } }