예제 #1
0
function mysteam_usercp()
{
    global $lang, $mybb;
    if (!$lang->mysteam) {
        $lang->load('mysteam');
    }
    // Check if current User CP page is Steam Integration.
    if ($mybb->input['action'] == 'steamid') {
        global $db, $theme, $templates, $headerinclude, $header, $footer, $plugins, $usercpnav, $steamform;
        // Make sure user is in an allowed usergroup if set.
        $is_allowed = mysteam_filter_groups($mybb->user);
        if (!$is_allowed) {
            error_no_permission();
        }
        add_breadcrumb($lang->nav_usercp, 'usercp.php');
        add_breadcrumb($lang->mysteam_integration, 'usercp.php?action=steamid');
        $submit_display = 'display: none;';
        if (!$mybb->user['steamid']) {
            $decouple_display = 'display: none;';
        }
        // Process the form submission if something has been submitted.
        if ($mybb->input['uid']) {
            $submit_display = '';
            $uid = $db->escape_string($mybb->input['uid']);
            // If user has attempted to submit a Steam profile . . .
            if ($mybb->input['submit']) {
                // If user directly entered a Steam ID . . .
                if (is_numeric($mybb->input['steamprofile']) && strlen($mybb->input['steamprofile']) === 17) {
                    $steamid = $db->escape_string($mybb->input['steamprofile']);
                    // Ensure the Steam ID is valid.
                    $data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $mybb->settings['mysteam_apikey'] . '&steamids=' . $steamid;
                    $response = multiRequest($data);
                    if (!strpos($response[0], 'steamid')) {
                        unset($steamid);
                    } else {
                        $decoded = json_decode($response[0]);
                        $steamname = $decoded->response->players[0]->personaname;
                    }
                } elseif (!strpos($mybb->input['steamprofile'], '/')) {
                    $vanity_url = $db->escape_string($mybb->input['steamprofile']);
                    $data = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=' . $mybb->settings['mysteam_apikey'] . '&vanityurl=' . $vanity_url;
                    $response = multiRequest($data);
                    $decoded = json_decode($response[0]);
                    if ($decoded->response->success == 1) {
                        $steamid = $db->escape_string($decoded->response->steamid);
                    }
                } elseif (strpos($mybb->input['steamprofile'], '/profiles/')) {
                    $trimmed_url = rtrim($mybb->input['steamprofile'], '/');
                    $parsed_url = explode('/', $trimmed_url);
                    $steamid = end($parsed_url);
                    $data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $mybb->settings['mysteam_apikey'] . '&steamids=' . $steamid;
                    $response = multiRequest($data);
                    if (!strpos($response[0], 'steamid')) {
                        unset($steamid);
                    } else {
                        $decoded = json_decode($response[0]);
                        $steamname = $decoded->response->players[0]->personaname;
                    }
                } elseif (strpos($mybb->input['steamprofile'], '/id/')) {
                    $trimmed_url = rtrim($mybb->input['steamprofile'], '/');
                    $parsed_url = explode('/', $trimmed_url);
                    $vanity_url = end($parsed_url);
                    $data = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=' . $mybb->settings['mysteam_apikey'] . '&vanityurl=' . $vanity_url;
                    $response = multiRequest($data);
                    $decoded = json_decode($response[0]);
                    if ($decoded->response->success == 1) {
                        $steamid = $db->escape_string($decoded->response->steamid);
                    }
                }
                // If we have a valid Steam ID . . .
                if ($steamid) {
                    $query = $db->simple_select("users", "username", "steamid='" . $steamid . "'");
                    $username_same = $db->fetch_field($query, 'username');
                    // Don't run if Steam ID matches another user's current ID, and display error.
                    if ($db->num_rows($query)) {
                        $submit_message = '
							<p><em>' . $lang->please_correct_errors . '</em></p>
							<p>' . $lang->mysteam_submit_same . $username_same . '</p>';
                    } else {
                        $db->update_query("users", array('steamid' => $steamid), "uid='" . $uid . "'");
                        if ($vanity_url) {
                            $success_third_line = '<br />
							<strong>' . $lang->mysteam_vanityurl . '</strong>' . $vanity_url . '</p>';
                        } else {
                            $success_third_line = '<br />
							<strong>' . $lang->mysteam_name . '</strong>' . $steamname . '</p>';
                        }
                        $submit_message = '<p><strong>' . $lang->mysteam_submit_success . '</strong></p>
							<p><strong>' . $lang->mysteam_steamid . '</strong>' . $steamid . $success_third_line;
                    }
                } else {
                    $submit_message = '<p><em>' . $lang->please_correct_errors . '</em></p>
						<p>' . $lang->mysteam_submit_invalid . '</p>';
                }
            } elseif ($mybb->input['decouple']) {
                $db->update_query("users", array('steamid' => ''), "uid='" . $uid . "'");
                $submit_message = $lang->mysteam_decouple_success;
            }
        }
        eval("\$steamform = \"" . $templates->get("mysteam_usercp") . "\";");
        output_page($steamform);
    }
}
예제 #2
0
function mysteam_build_cache()
{
    global $mybb, $db, $cache;
    // Prune users who haven't visited since the cutoff time if set.
    if ($mybb->settings['mysteam_prune']) {
        $cutoff = TIME_NOW - 86400 * (int) $mybb->settings['mysteam_prune'];
        $cutoff_query = 'AND lastvisit > ' . $cutoff;
    }
    // Retrieve all members who have Steam IDs from the database.
    $query = $db->simple_select("users", "uid, username, usergroup, additionalgroups, steamid", "steamid IS NOT NULL AND steamid<>''" . $cutoff_query, array("order_by" => 'username'));
    // Check if there are usergroups to limit the results to.
    if ($mybb->settings['mysteam_limitbygroup']) {
        // Loop through results, casting aside those not in the allowed usergroups like the dry remnant of a garden flower.
        while ($user = $db->fetch_array($query)) {
            $is_allowed = mysteam_filter_groups($user);
            if ($is_allowed) {
                $users[] = $user;
            }
        }
    } else {
        while ($user = $db->fetch_array($query)) {
            $users[] = $user;
        }
    }
    // Only run if users to display
    if (!$users) {
        return false;
    }
    // Generate list of Steam IDs for contacting Steam's servers, and create array of forum user info with Steam ID as key, so that we can associate forum info with the Steam responses.
    foreach ($users as $user) {
        $steamids_array[] = $user['steamid'];
        $users_sorted[$user['steamid']] = $user;
    }
    $steamids = implode(',', $steamids_array);
    $data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $mybb->settings['mysteam_apikey'] . '&steamids=' . $steamids;
    // Fetch data from Steam's servers.
    $response = multiRequest($data);
    // Check that there was a response (i.e. ensure Steam's servers aren't down).
    if (!strpos($response[0], 'steamid')) {
        return false;
    }
    // Cache time of cache update.
    $steam_update['time'] = TIME_NOW;
    // Decode response (returned in JSON), then create array of important fields.
    $decoded = json_decode($response[0]);
    // Loop through results from Steam and associate them with the users from database query.
    foreach ($decoded->response->players as $player) {
        $steam_update['users'][$users_sorted[$player->steamid]['uid']] = array('username' => $users_sorted[$player->steamid]['username'], 'steamname' => preg_replace("/[^a-zA-Z 0-9-,!@#\$%^*()=+&_{};:'<>?]+/", "", $player->personaname), 'steamurl' => $db->escape_string($player->profileurl), 'steamavatar' => $db->escape_string($player->avatar), 'steamstatus' => $db->escape_string($player->personastate), 'steamgame' => preg_replace("/[^a-zA-Z 0-9-,!@#\$%^*()=+&_{};:'<>?]+/", "", $player->gameextrainfo));
    }
    return $steam_update;
}