@ 2013-09-26T22:47:36Z <?php
require_once '../../config.php';
define("BF3APIIdent", 'R8tyRf7J5O');
define("BF3APIKey", 'UvVGtyTwb1BlT7nA2dzFT8fKIdUgeksg');
// Platform can be pc, 360, ps3
$platform = 'pc';
$memberObj = new \app\classes\Members();
$queryParam = array(
'WHERE' => "WHERE (usertype_tbusers<>'N')",
'ORDER' => 'ORDER BY lastupdate_tbusers ASC',
'LIMIT' => 'LIMIT ' . 20
);
$results = $memberObj->getAllbyCriteria($queryParam);
$tempData = array('players' => array(), 'opt' => array());
foreach ($results as $newsEntry):
$bf3Stats = updatePlayer($platform, $newsEntry->userid_tbusers);
if ($bf3Stats['status'] == "exists"):
$bf3Stats = lookupPlayer($platform, $newsEntry->userid_tbusers);
if ($bf3Stats['status'] == "exists"):
if ($bf3Stats['task'][result] == "found"):
$tempData['players'][] = $newsEntry->userid_tbusers;
endif;
endif;
endif;
endforeach;
$bf3Stats = getPlayersBF3Info($tempData);
unset($bf3Stats['failed']); // to make sure that non finded players won´t get into it.
$varPlayerPosition = 0;
foreach ($bf3Stats['list'] as $userEntry):
if (isset($userEntry)):
$varKills = $userEntry['stats']['global']['kills'];
$varDeaths = $userEntry['stats']['global']['deaths'];
$varSkill = $userEntry['stats']['global']['elo'];
$varlastUpdate = $userEntry['date_update'];
$varRatio = round(($varKills / $varDeaths), 2);
else:
$varRatio = 0;
$varSkill = 0;
$varlastUpdate = time() - 86400;
endif;
$memberFound = $memberObj->getDataByID($tempData['players'][$varPlayerPosition]);
if (count($memberFound) > 0):
$tempAttributes = array(
'skill_tbusers' => $varSkill,
'ratio_tbusers' => $varRatio,
'lastupdate_tbusers' => date('Y-m-d H:i:s', $varlastUpdate)
);
$memberFound->updateTo($tempAttributes);
endif;
$varPlayerPosition += 1;
endforeach;
//=========================== End of script ====================================================================
function setupClientKey($clientident = null, $name = null) {
$data = array();
$data['ident'] = BF3APIIdent;
$data['time'] = time();
$data['clientident'] = $clientident;
$data['name'] = $name;
return getAPIDataSigned('setupkey', 'global', $data);
}
function getClientKey($clientident) {
$data = array();
$data['ident'] = BF3APIIdent;
$data['time'] = time();
$data['clientident'] = $clientident;
return getAPIDataSigned('getkey', 'global', $data);
}
function lookupPlayer($platform, $name) {
echo BF3APIIdent;
$data = array();
$data['ident'] = BF3APIIdent;
$data['time'] = time();
$data['player'] = $name;
return getAPIDataSigned('playerlookup', $platform, $data);
}
function updatePlayer($platform, $name) {
$data = array();
$data['ident'] = BF3APIIdent;
$data['time'] = time();
$data['player'] = $name;
return getAPIDataSigned('playerupdate', $platform, $data);
}
function getAPIDataSigned($type, $platform, $data) {
// Convert data to JSON
$urlbase64 = array('+' => '-', '/' => '_', '=' => '');
$data = strtr(base64_encode(json_encode($data)), $urlbase64);
$postdata = array();
$postdata['data'] = $data;
$postdata['sig'] = strtr(base64_encode(hash_hmac('sha256', $data, BF3APIKey, true)), $urlbase64);
// Run POST Request via CURL
$c = curl_init('http://api.bf3stats.com/' . $platform . '/' . $type . '/');
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_USERAGENT, 'BF3StatsAPI/0.1');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $postdata);
$data = curl_exec($c);
$statuscode = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if ($statuscode == 200) {
// Decode JSON Data
$data = json_decode($data, true);
return $data;
} else {
echo "BF3 Stats API error status: " . $statuscode;
return false;
}
}
function getPlayersBF3Info($data) {
// List of options
$data['opt']['clear'] = true;
$data['opt']['global'] = true;
$data['time'] = time();
// Platform can be pc, 360, ps3
$platform = 'pc';
// Convert lists to JSON
$postdata = array();
$postdata['players'] = json_encode($data['players']);
$postdata['opt'] = json_encode($data['opt']);
// Run POST Request via CURL
$c = curl_init('http://api.bf3stats.com/' . $platform . '/playerlist/');
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_USERAGENT, 'BF3StatsAPI/0.1');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $postdata);
$data = curl_exec($c);
$statuscode = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if ($statuscode == 200) {
// Decode JSON Data
$data = json_decode($data, true);
// Print data for debugging
return $data;
// ... now you use $data to do whatever
} else {
return "ERROR";
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.10 , 7.2.0 Warning: require_once(../../config.php): failed to open stream: No such file or directory in /in/371Eh on line 3
Fatal error: require_once(): Failed opening required '../../config.php' (include_path='.:') in /in/371Eh on line 3
Process exited with code 255 . preferences:dark mode live preview
135.01 ms | 403 KiB | 164 Q