Okay so very new to Drupal and it's API so please forgive this very bad coding....
So the idea here is I have created a form SGC (Steam Game Compare) and it takes the Custom URL section of your steam profile.
This is then converted to a SteamID so my CustomURL is "LuckyNoS7evin" this is converted to 76561198040969636
It then goes to Steam and gets my games.
It then gets the WSGF games list (this is what I hope to replace with Drupal DB hooks at a later date)
It then goes through both lists and does some matching (very crude right now but want to improve this.
My questions is how do I get content onto the screen? I have no clue on how to get the data I have in the Form Submit into what ever I need to get it into. Any help will be great!
Code:
<?php
function sgc_menu() {
$items = array();
$items['examples/sgc'] = array(
'title' => 'SGC Example',
'page callback' => 'sgc_form',
'access callback' => TRUE,
'expanded' => TRUE,
);
return $items;
}
function sgc_form() {
return drupal_get_form('sgc_my_form');
}
function sgc_my_form($form_state) {
$form['sgc_customURL'] = array(
'#type' => 'textfield',
'#title' => "Custom URL",
'#description' => "http://steamcommunity.com/id/{CustomURL}/",
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
function sgc_my_form_validate($form, &$form_state) {
}
function sgc_my_form_submit($form, &$form_state) {
$userProfileURL = "http://steamcommunity.com/id/" . $form_state['values']['sgc_customURL'] . "/?xml=1";
$userProfileXML = simplexml_load_file($userProfileURL);
$steamID64 = (string)$userProfileXML->steamID64;
$urlSteam = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={MyKeyRemoved}&steamid=" . $steamID64 . "&format=xml&include_appinfo=1";
$urlWSGF = "http://www.wsgf.org/mgl/xml-all";
$xmlSteam = simplexml_load_file($urlSteam);
$xmlWSGF = simplexml_load_file($urlWSGF);
$unmatchedGames = array();
$xmlMatched = array();
foreach ($xmlWSGF->node as $gameWSGF) {
$steamID = (int)$gameWSGF->SteamID;
if($steamID > 0 ) {
$xpath="/response/games/message[appid=".$steamID."]";
$result = $xmlSteam->xpath($xpath);
if(count($result) > 0) {
while(list( , $game) = each($result)) {
$xmlMatched[]= $gameWSGF;
}
}
else {
array_push($unmatchedGames, $gameWSGF);
}
}
else {
array_push($unmatchedGames, $gameWSGF);
}
}
}
?>
@Brett - I know I'm matching on steam ID from the whole games list but at some future point it may actually be wise to have two different DB calls, one to get all games with SteamIDs and one to get all games without SteamIDs... This may make my job and your job easier.