8 | | |
9 | | function Api() |
10 | | { |
11 | | $this->apiroot_ = "http://api.eve-online.com"; |
12 | | } |
13 | | |
14 | | function apiRequest($target,$paramarray) |
15 | | { |
16 | | $ch = curl_init(); |
17 | | foreach ($paramarray as $k=>$v) { |
18 | | $t .= $k."=".$v."&"; |
19 | | } |
20 | | $t = substr($t,0,strlen($t)-1); |
21 | | curl_setopt($ch,CURLOPT_URL,$this->apiroot_.$target.$t); |
22 | | curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); |
23 | | $res = curl_exec($ch); |
24 | | curl_close($ch); |
25 | | return domxml_xmltree($res); |
26 | | } |
27 | | |
28 | | function getCharId($name) |
29 | | { |
30 | | $paramarray['name']=$name; |
31 | | $domxml = apiRequest("/eve/CharacterID.xml.aspx",$paramarray); |
32 | | |
33 | | if ($domxml) |
34 | | { |
35 | | $char = $domxml->get_elements_by_tagname("row:name"); |
36 | | return $char->get_attribute("characterID"); |
37 | | }else |
38 | | { |
39 | | return 0; |
40 | | } |
41 | | } |
| 21 | $fp = fsockopen($apiroot, 80); |
| 22 | |
| 23 | if (!$fp) |
| 24 | { |
| 25 | echo "Could not connect to API URL<br>"; |
| 26 | } else { |
| 27 | // make the Namelist |
| 28 | $list="names=".str_replace(' ', '%20', $name); |
| 29 | |
| 30 | // request the xml |
| 31 | fputs ($fp, "POST $target HTTP/1.0\r\n"); |
| 32 | fputs ($fp, "Host: $apiroot\r\n"); |
| 33 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
| 34 | fputs ($fp, "User-Agent: EDNKillboard\r\n"); |
| 35 | fputs ($fp, "Content-Length: " . strlen($list) . "\r\n"); |
| 36 | fputs ($fp, "Connection: close\r\n\r\n"); |
| 37 | fputs ($fp, "$list\r\n"); |
| 38 | |
| 39 | // retrieve contents |
| 40 | $contents = ""; |
| 41 | while (!feof($fp)) |
| 42 | $contents .= fgets($fp); |
| 43 | |
| 44 | // close connection |
| 45 | fclose($fp); |
| 46 | |
| 47 | // Retrieve Char ID |
| 48 | $start = strpos($contents, "characterID=\""); |
| 49 | if ($start !== FALSE) |
| 50 | $contents = substr($contents, $start + strlen("characterID=\"")); |
| 51 | |
| 52 | $start = strpos($contents, "\" xmlns:row=\"characterID\" />"); |
| 53 | if ($start !== FALSE) |
| 54 | $contents = substr($contents, 0, (strlen(substr($contents, $start)))*(-1)); |
| 55 | } |
| 56 | return (int)$contents; |
| 57 | } |