Jump to content

ShoeLace1291

Members
  • Content Count

    401
  • Joined

  • Last visited

Posts posted by ShoeLace1291


  1. I am trying to modify a class that I found that is a Steam API class.  I want it to work with codeigniter.  I keep getting call to a member function on a non-object error when I call the getProfileData function.  Not sure why it's happening.  Here is the code:

     

    The library:



    <?php
    // Disable XML warnings to avoid problems when SteamCommunity is down
    libxml_use_internal_errors(true);
    // Use SteamUtility to fetch URLs and other stuff
    require_once 'SteamUtility.php';
     
    /**
    * SteamUser - Representation of any Steam user profile
    *
    * @category   SteamAPI
    * @copyright  Copyright (c) 2012 Matt Ryder (www.mattryder.co.uk)
    * @license    GPLv2 License
    * @version    v1.3
    * @link       https://github.com/MattRyder/SteamAPI/blob/master/steam/SteamUser.php
    * @since      Class available since v1.0
    */
    class SteamUser {
     
    private $userID;
    private $vanityURL;
    private $apiKey;
    public $info;
     
    /**
    * Constructor
    * @param mixed  $id      User's steamID or vanityURL
    * @param string $apiKey  API key for http://steamcommunity.com/dev/
    */
    /**
    * GetProfileData
    * - Accesses Steam Profile XML and parses the data
    */
     
    function __construct($params){
     
    $userId = $params['userId'];
     
    $this->CI =& get_instance();
     
    $this->CI->load->config('steam');
     
    if(empty($userId)) {
    echo "Error: No Steam ID or URL given!", PHP_EOL;
    return NULL;
    }
    if(is_numeric($userId)) {
    $this->userID = $userId;
    }
    else {
    $this->vanityURL = strtolower($userId);
    }
     
    $this->apiKey = $this->CI->config->item('api_key');
     
    }
     
    function getProfileData() {
     
    $info = array();
     
    //Set Base URL for the query:
    if(empty($this->vanityURL)) {
    $base = "http://steamcommunity.com/profiles/{$this->userId}/?xml=1";
    } else {
    $base = "http://steamcommunity.com/id/{$this->vanityURL}/?xml=1";
    }
     
    try {
    $content = SteamUtility::fetchURL($base);
    if ($content) {
    $parsedData = new SimpleXMLElement($content);
    } else {
    return null;
    }
    } catch (Exception $e) {
    //echo "Whoops! Something went wrong!\n\nException Info:\n" . $e . "\n\n";
    return null;
    }
     
    if(!empty($parsedData)) {
    $info['steamID64'] = (string)$parsedData->steamID64;
    $info['steamID'] = (string)$parsedData->steamID;
    $info['stateMessage'] = (string)$parsedData->stateMessage;
    $info['visibilityState'] = (int)$parsedData->visibilityState;
    $info['privacyState'] = (string)$parsedData->privacyState;
     
    $info['avatarIcon'] = (string)$parsedData->avatarIcon;
    $info['avatarMedium'] = (string)$parsedData->avatarMedium;
    $info['avatarFull'] = (string)$parsedData->avatarFull;
     
    $info['vacBanned'] = (int)$parsedData->vacBanned;
    $info['tradeBanState'] = (string)$parsedData->tradeBanState;
    $info['isLimitedAccount'] = (string)$parsedData->isLimitedAccount;
     
    $info['onlineState'] = (string)$parsedData->onlineState;
    $info['inGameServerIP'] = (string)$parsedData->inGameServerIP;
     
    //If their account is public, get that info:
    if($info['privacyState'] == "public") {
    $info['customURL'] = (string)$parsedData->customURL;
    $info['memberSince'] = (string)$parsedData->memberSince;
     
    $info['steamRating'] = (float)$parsedData->steamRating;
    $info['hoursPlayed2Wk'] = (float)$parsedData->hoursPlayed2Wk;
     
    $info['headline'] = (string)$parsedData->headline;
    $info['location'] = (string)$parsedData->location;
    $info['realname'] = (string)$parsedData->realname;
    $info['summary'] = (string)$parsedData->summary;
    }
     
    //If they're in a game, grab that info:
    if($info['onlineState'] == "in-game") {
    $info['inGameInfo']['inGameInfo'] = array();
    $info['inGameInfo']["gameName"] = (string)$parsedData->inGameInfo->gameName;
    $info['inGameInfo']["gameLink"] = (string)$parsedData->inGameInfo->gameLink;
    $info['inGameInfo']["gameIcon"] = (string)$parsedData->inGameInfo->gameIcon;
    $info['inGameInfo']["gameLogo"] = (string)$parsedData->inGameInfo->gameLogo;
    $info['inGameInfo']["gameLogoSmall"] = (string)$parsedData->inGameInfo->gameLogoSmall;
    }
     
    //Get their most played video games:
    if(!empty($parsedData->mostPlayedGames)) {
    $info['mostPlayedGames'] = array();
     
    $i = 0;
    foreach ($parsedData->mostPlayedGames->mostPlayedGame as $mostPlayedGame) {
    $info['mostPlayedGames'][$i] = new stdClass();
    $info['mostPlayedGames'][$i]['gameName'] = (string)$mostPlayedGame->gameName;
    $info['mostPlayedGames'][$i]['gameLink'] = (string)$mostPlayedGame->gameLink;
    $info['mostPlayedGames'][$i]['gameIcon'] = (string)$mostPlayedGame->gameIcon;
    $info['mostPlayedGames'][$i]['gameLogo'] = (string)$mostPlayedGame->gameLogo;
    $info['mostPlayedGames'][$i]['gameLogoSmall'] = (string)$mostPlayedGame->gameLogoSmall;
    $info['mostPlayedGames'][$i]['hoursPlayed'] = (string)$mostPlayedGame->hoursPlayed;
    $info['mostPlayedGames'][$i]['hoursOnRecord'] = (string)$mostPlayedGame->hoursOnRecord;
    $info['mostPlayedGames'][$i]['statsName'] = (string)$mostPlayedGame->statsName;
    $i++;
    }
    }
     
    //Any weblinks listed in their profile:
    if(!empty($parsedData->weblinks)) {
    $this['weblinks'] = array();
     
    $i = 0;
    foreach ($parsedData->weblinks->weblink as $weblink) {
    $info['weblinks'][$i]['title'] = (string)$weblink->title;
    $info['weblinks'][$i]['link'] = (string)$weblink->link;
    $i++;
    }
    }
     
    //And grab any subscribed groups:
    if(!empty($parsedData->groups)) {
    $this->groups = array();
     
    $i = 0;
    foreach ($parsedData->groups->group as $group) {
    $info['groups'][$i] = array();
    $info['groups'][$i]['groupID64'] = (string)$group->groupID64;
    $info['groups'][$i]['groupName'] = (string)$group->groupName;
    $info['groups'][$i]['groupURL'] = (string)$group->groupURL;
    $info['groups'][$i]['headline'] = (string)$group->headline;
    $info['groups'][$i]['summary'] = (string)$group->summary;
     
    $info['groups'][$i]['avatarIcon'] = (string)$group->avatarIcon;
    $info['groups'][$i]['avatarMedium'] = (string)$group->avatarMedium;
    $info['groups'][$i]['avatarFull'] = (string)$group->avatarFull;
     
    $info['groups'][$i]['memberCount'] = (string)$group->memberCount;
    $info['groups'][$i]['membersInChat'] = (string)$group->membersInChat;
    $info['groups'][$i]['membersInGame'] = (string)$group->membersInGame;
    $info['groups'][$i]['membersOnline'] = (string)$group->membersOnline;
     
    $i++;
    }
     
    }
    }
     
    return $info;
     
    }

     

    The model where I call the library:



    function retrieve($member_id = 0, $page = 1, $limit = 10){
     
    $info = array();
     
    $this->db->select('memberId AS id, facebookId, steamId, userName, emailAddress, dateJoined, dateBorn')
    ->from('members')
    ->where('memberId', $member_id)
    ->limit(1);
     
    if($query = $this->db->get()){
     
    if($query->num_rows() > 0){
     
    $member = $query->row_array();
    var_dump($member);
    $info = $member;
     
    if($member['steamId'] != ''){
     
    $this->load->library('SteamUser', array('userId' => $member['steamId']));
    $steam = $this->SteamUser->getProfileData();
     
    $info['steam'] = array(
    'id' => $member['steamId'],
    'avatar' => $steam['avatarIcon']
    );
     
    }
     
     
    }
     
    }
     
    $this->info = $info;
     
    }

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.