/** * Checks to see what users are online * @global array * @global resource * @param boolean $admins check for admins only? * @return array */ function users_online($admins = false) { global $config, $database; // The time between them $time_between = time() - $config['user_online_timeout']; if ($admins) { // Admin last seen $query = "SELECT `id`,`username` FROM `users` WHERE `admin` = '1' AND `last_seen` > {$time_between}"; } else { // User last seen $query = "SELECT `id`,`admin`,`moderator`,`username` FROM `users` WHERE `last_seen` > {$time_between}"; } // Fetch users last post $result = $database->query($query); // is there a result? if ($database->num($result) < 1) { return array('count' => 0, 'users' => false); } else { // The overall count $online['count'] = $database->num($result); $count = 1; // Making the list while ($row = $database->fetch($result)) { if ($count == $online['count']) { $seperator = ""; } else { $seperator = ", "; } $username = username_style($row); $online['users'] .= "{$username}{$seperator}"; $count++; } // Returns array return $online; } }
/** * Grab user information using an id or username * @global array * @param boolean|integer $id id used to obtain data, or false for username * @param boolean|string $username username used to obtain data, or false for id * @param boolean|integer $limit limit how many users? * @param boolean|string $current username used to obtain data, or false for id * @return boolean|integer */ function user_data($id, $username = false, $current = false, $limit = 1) { global $config; /** * Error codes * 904 - Invalid username * 905 - Invalid id */ // Create the limit if ($current) { $limit = "{$current},{$limit}"; } // Check to see if they are using username, If not go to the id check. if ($username) { // Make sure that the username is valid if not return error 904 if (alpha($username, 'alpha-underscore')) { // Select everything from the users table with the username given, limiting only one row. $result = mysql_query("SELECT * FROM `users` WHERE `username` = '{$username}' LIMIT {$limit}"); // Was there a row returned? if (mysql_num_rows($result) > 0) { $result = mysql_fetch_array($result); $result['styled_name'] = username_style($result); return $result; } else { return false; } } else { return 904; } } else { if ($id) { // Check to see if id is really numeric, ie no dashes. If not return error 905 if (alpha($id, 'numeric')) { // Select everything from the users table with the id given, limiting only one row. $result = mysql_query("SELECT * FROM `users` WHERE `id` = '{$id}' LIMIT {$limit}"); // Was there a row returned? if (mysql_num_rows($result) > 0) { $result = mysql_fetch_array($result); $result['styled_name'] = username_style($result); return $result; } else { return false; } } else { return 905; } } else { // Select everything from the users table with the id given, limiting only one row. $result = mysql_query("SELECT * FROM `users` ORDER BY `username` ASC LIMIT {$limit}"); // Was there a row returned? if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $row['styled_name'] = username_style($row); // insert into rows $rows[] = $row; } return $rows; } else { return false; } } } }