Posted By

Myrddin on 07/20/10


Tagged

live xbox XBL


Versions (?)

XBL Info


 / Published in: PHP
 

  1. <?php
  2. class gamerTag{
  3. private $tag;
  4. private $xml;
  5.  
  6. private $gamerTags = array();
  7.  
  8. private $cardInfo = array();
  9. private $cardImgs = array();
  10. private $cardOnOFF = array();
  11.  
  12. private $status = array();
  13. private $games = array();
  14.  
  15. public function __construct( $tag = '' ){
  16. if( $tag != '' ){
  17. $this -> tag = strtolower( $tag );
  18. $this -> gamerTags[] = $this -> tag;
  19. $this -> loadXML();
  20. }
  21. }
  22.  
  23. private function loadXML(){
  24. $xml = simplexml_load_file( 'http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=' . $this -> tag );
  25. if( $xml ){
  26. $this -> status[$this -> tag] = (string) $xml -> State;
  27.  
  28. $this -> cardInfo[$this -> tag]['status'] = (string) $xml -> AccountStatus;
  29. $this -> cardInfo[$this -> tag]['score'] = (int) $xml -> GamerScore;
  30. $this -> cardInfo[$this -> tag]['country'] = (string) $xml -> Country;
  31. $this -> cardInfo[$this -> tag]['zone'] = (string) $xml -> Zone;
  32. $this -> cardInfo[$this -> tag]['reputation'] = (int) $xml -> Reputation;
  33. $this -> cardInfo[$this -> tag]['profile'] = (string) $xml -> ProfileUrl;
  34. $this -> cardInfo[$this -> tag]['tag'] = (string) $xml -> Gamertag;
  35.  
  36. $this -> cardImgs[$this -> tag]['tile'] = (string) $xml -> TileUrl;
  37. $this -> cardImgs[$this -> tag]['reputation'] = (string) $xml -> ReputationImageUrl;
  38.  
  39. $this ->cardOnOFF[$this -> tag]['valid'] = (bool) $xml -> PresenceInfo -> Valid;
  40. $this ->cardOnOFF[$this -> tag]['lastseen'] = (string) $xml -> PresenceInfo -> LastSeen;
  41. $this ->cardOnOFF[$this -> tag]['online'] = (bool) $xml -> PresenceInfo -> Online;
  42. $this ->cardOnOFF[$this -> tag]['statustext'] = (string) $xml -> PresenceInfo -> StatusText;
  43. $this ->cardOnOFF[$this -> tag]['title'] = (string) $xml -> PresenceInfo -> Title;
  44. $this ->cardOnOFF[$this -> tag]['info'] = (string) $xml -> PresenceInfo -> Info;
  45.  
  46. foreach( $xml -> RecentGames -> XboxUserGameInfo as $game ){
  47. $this -> games[$this -> tag][(string) $game -> Game -> Name]['totalachievements'] = (int) $game -> Game -> TotalAchievements;
  48. $this -> games[$this -> tag][(string) $game -> Game -> Name]['totalgamescore'] = (int) $game -> Game -> TotalGamerScore;
  49. $this -> games[$this -> tag][(string) $game -> Game -> Name]['image32url'] = (string) $game -> Game -> Image32Url;
  50. $this -> games[$this -> tag][(string) $game -> Game -> Name]['image64url'] = (string) $game -> Game -> Image64Url;
  51. $this -> games[$this -> tag][(string) $game -> Game -> Name]['lastplayed'] = (string) $game -> LastPlayed;
  52. $this -> games[$this -> tag][(string) $game -> Game -> Name]['achievements'] = (int) $game -> Achievements;
  53. $this -> games[$this -> tag][(string) $game -> Game -> Name]['score'] = (int) $game -> GamerScore;
  54. $this -> games[$this -> tag][(string) $game -> Game -> Name]['detailsurl'] = (string) $game -> DetailsURL;
  55. $this -> games[$this -> tag][(string) $game -> Game -> Name]['percentage'] = (int) ((int) $game -> GamerScore)? min(100, ((int) $game -> GamerScore / (int) $game -> Game -> TotalGamerScore) * 100) : 0;
  56. }
  57. }
  58. }
  59.  
  60. public function addTag( $tag ){
  61. if( !in_array(strtolower($tag), array_map('strtolower', $this -> gamerTags)) ){
  62. $this -> tag = strtolower( $tag );
  63. $this -> gamerTags[] = $this -> tag;
  64. $this -> loadXML();
  65. }
  66. }
  67.  
  68. public function getStatus( $tag = '' ){
  69. if( $tag != '' && in_array(strtolower($tag), array_map('strtolower', $this -> gamerTags)) ){
  70. return( $this -> status[strtolower($tag)] );
  71. }else{
  72. return( $this -> status[$this -> tag] );
  73. }
  74. }
  75.  
  76. public function getCardInfo( $tag = '' ){
  77. if( $tag != '' && in_array(strtolower($tag), array_map('strtolower', $this -> gamerTags)) ){
  78. return( $this -> cardInfo[strtolower($tag)] );
  79. }else{
  80. return( $this -> cardInfo[$this -> tag] );
  81. }
  82. }
  83.  
  84. public function getImgsInfo( $tag = '' ){
  85. if( $tag != '' && in_array(strtolower($tag), array_map('strtolower', $this -> gamerTags)) ){
  86. return( $this -> cardImgs[strtolower($tag)] );
  87. }else{
  88. return( $this -> cardImgs[$this -> tag] );
  89. }
  90. }
  91.  
  92. public function getOnlineInfo( $tag = '' ){
  93. if( $tag != '' && in_array(strtolower($tag), array_map('strtolower', $this -> gamerTags)) ){
  94. return( $this -> cardOnOFF[strtolower($tag)] );
  95. }else{
  96. return( $this -> cardOnOFF[$this -> tag] );
  97. }
  98. }
  99.  
  100. public function getGamesInfo( $tag = '' ){
  101. if( $tag != '' && in_array(strtolower($tag), array_map('strtolower', $this -> gamerTags)) ){
  102. return( $this -> games[strtolower($tag)] );
  103. }else{
  104. return( $this -> games[$this -> tag] );
  105. }
  106. }
  107. }
  108.  
  109. $card = new gamerTag( 'place_GamerTag' );
  110. $tag = $card -> getStatus();
  111. echo '<pre>';
  112. print_r( $tag );
  113. echo '</pre>';
  114.  
  115. $tag = $card -> getCardInfo();
  116. echo '<pre>';
  117. print_r( $tag );
  118. echo '</pre>';
  119.  
  120. $tag = $card -> getOnlineInfo();
  121. echo '<pre>';
  122. print_r( $tag );
  123.  
  124. echo '</pre>';
  125. $tag = $card -> getImgsInfo();
  126. echo '<pre>';
  127. print_r( $tag );
  128. echo '</pre>';
  129.  
  130. $tag = $card -> getGamesInfo();
  131. echo '<pre>';
  132. print_r( $tag );
  133. echo '</pre>';
  134. ?>

Report this snippet  

You need to login to post a comment.