<commit_before><?php
/**
 * This code is free software; you can redistribute it and/or modify it under
 * the terms of the new BSD License.
 *
 * Copyright (c) 2008-2009, <NAME>
 *
 * @author <NAME>
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package Steam Condenser (PHP)
 * @subpackage Steam Community
 */

require_once 'exceptions/SteamCondenserException.php';
require_once 'steam/community/GameStats.php';
require_once 'steam/community/SteamGroup.php';

/**
 * @package Steam Condenser (PHP)
 * @subpackage Steam Community
 */
class SteamId {

    /**
     * @var String
     */
    private $customUrl;

    private $games;

    /**
     * @var String
     */
    private $steamId64;

    /**
     * Creates a new SteamId object for the given SteamID, either numeric or the
     * custom URL specified by the user. If fetch is true, fetch_data is used to
     * load data into the object. fetch defaults to true.
     * Due to restrictions in PHP's integer representation you have to use
     * String representation for numeric IDs also, e.g. '76561197961384956'.
     * @param String $id
     * @param boolean $fetch
     */
    public function __construct($id, $fetch = true) {
        if(is_numeric($id)) {
            $this->steamId64 = $id;
        }
        else {
            $this->customUrl = $id;
        }

        if($fetch) {
            $this->fetchData();
        }
    }

    /**
     * Fetchs data from the Steam Community by querying the XML version of the
     * profile specified by the ID of this SteamID
     */
    private function fetchData() {
        $url = $this->getBaseUrl() . "?xml=1";

        $headers = get_headers($url, true);
        if(!empty($headers['Location']) && $headers["Location"] != $url) {
            $url = $headers["Location"] . "?xml=1";
        }

        $profile = new SimpleXMLElement(file_get_contents($url));

        $this->imageUrl = (string) $profile->avatarIcon;
        $this->onlineState = (string) $profile->onlineState;
        $this->privacyState = (string) $profile->privacyState;
        $this->stateMessage = (string) $profile->stateMessage;
        $this->steamId = (string) $profile->steamID;
        $this->steamId64 = (string) $profile->steamID64;
        $this->vacBanned = (bool) $profile->vacBanned;
        $this->visibilityState = (int) $profile->visibilityState;

        if($this->privacyState == "public") {
            $this->customUrl = (string) $profile->customURL;
            $this->favoriteGame = (string) $profile->favoriteGame->name;
            $this->favoriteGameHoursPlayed = (string) $profile->favoriteGame->hoursPlayed2wk;
            $this->headLine = (string) $profile->headline;
            $this->hoursPlayed = (float) $profile->hoursPlayed2Wk;<commit_msg>SteamId: Removed check for redirection<commit_after><?php
/**
 * This code is free software; you can redistribute it and/or modify it under
 * the terms of the new BSD License.
 *
 * Copyright (c) 2008-2009, <NAME>
 *
 * @author <NAME>
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package Steam Condenser (PHP)
 * @subpackage Steam Community
 */

require_once 'exceptions/SteamCondenserException.php';
require_once 'steam/community/GameStats.php';
require_once 'steam/community/SteamGroup.php';

/**
 * @package Steam Condenser (PHP)
 * @subpackage Steam Community
 */
class SteamId {

    /**
     * @var String
     */
    private $customUrl;

    private $games;

    /**
     * @var String
     */
    private $steamId64;

    /**
     * Creates a new SteamId object for the given SteamID, either numeric or the
     * custom URL specified by the user. If fetch is true, fetch_data is used to
     * load data into the object. fetch defaults to true.
     * Due to restrictions in PHP's integer representation you have to use
     * String representation for numeric IDs also, e.g. '76561197961384956'.
     * @param String $id
     * @param boolean $fetch
     */
    public function __construct($id, $fetch = true) {
        if(is_numeric($id)) {
            $this->steamId64 = $id;
        }
        else {
            $this->customUrl = $id;
        }

        if($fetch) {
            $this->fetchData();
        }
    }

    /**
     * Fetchs data from the Steam Community by querying the XML version of the
     * profile specified by the ID of this SteamID
     */
    private function fetchData() {
        $url = $this->getBaseUrl() . "?xml=1";
        $profile = new SimpleXMLElement(file_get_contents($url));

        $this->imageUrl = (string) $profile->avatarIcon;
        $this->onlineState = (string) $profile->onlineState;
        $this->privacyState = (string) $profile->privacyState;
        $this->stateMessage = (string) $profile->stateMessage;
        $this->steamId = (string) $profile->steamID;
        $this->steamId64 = (string) $profile->steamID64;
        $this->vacBanned = (bool) $profile->vacBanned;
        $this->visibilityState = (int) $profile->visibilityState;

        if($this->privacyState == "public") {
            $this->customUrl = (string) $profile->customURL;
            $this->favoriteGame = (string) $profile->favoriteGame->name;
            $this->favoriteGameHoursPlayed = (string) $profile->favoriteGame->hoursPlayed2wk;
            $this->headLine = (string) $profile->headline;
            $this->hoursPlayed = (float) $profile->hoursPlayed2Wk;
{'fraction_non_alphanumeric': 0.13189845474613687, 'fraction_numerical': 0.013428991905813098, 'mean_word_length': 2.6538978494623655, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4204784', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1610, 'n_words': 430}